Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a skyline consisting of n points (x_i, y_i), 1 lessthanorequalto i

ID: 3883531 • Letter: Y

Question

You are given a skyline consisting of n points (x_i, y_i), 1 lessthanorequalto i lessthanorequalto n. The points are the endpoints of the skyline segments, as shown in the figure below. The points are given in the order they are encountered when traversing the skyline starting at leftmost lowest point. A point p of the skyline has a clear-left (resp. clear-right) view if a horizontal line through p does not intersect any part of the skyline to the left (resp. right) of point p. Describe and analyze an O(n) time algorithm for determining the endpoints of the vertical segments on the skyline representing the clear-left and clear-right view segments. The figure above shows the five clear view segments of the given skyline. The segments can be returned in any order. Given is a parameter k. A point p of the skyline has a k-left (resp. k-right) view if a horizontal line through p does not intersect any part of the skyline to the left (resp. right) of point p for a distance of at least k. The figure above shows the four 5-left and four 5-right segments of the skyline. Describe and analyze an efficient algorithm for determining the endpoints of the vertical segments on the skyline containing the points that have either a k-left or k-right view. The segments can be returned in any order.

Explanation / Answer

(i) int arr[] : stores the heights of the points

int max : It will store the max height value point reached in the current traversal

Start a loop from the leftmost point till the right most point and initially keep the value of max as arr[0]. For every point, check if the value is greater than the max value. If so, then that point can be added to a array which stores the points which has clear left view and also update max to the current point value. If not, then the current point doesn't have a clear left view.

Similarly, you can apply the same algorithm for finding clear right view but in this case you need to start the traversing the points from the right most point to the left most point.

(ii) int arr[][]: This array stores the coordinates of points

For clear k-left view, Start a loop from the left most point to the right most point. For every point, check if the difference between the x coordinates of the current point and the previous point is greater than or equal to k. If so, then the current point can be added to the array which stores the points which have clear k-left view. Similary, one can work for clear k-right view.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote