I got this interview question the other day. ON a plane, there are many horizontal lines, what is the best algorithm to draw a vertical line that intersects with the most number of horizontal lines on that plane?
Suppose the line segment array is arr[n] which contains start point and end point
Sort the arr[n] based on start point,
For each line segment L, use end point L.E to do binary search on the sorted arr[n] (if L.E>arr[i].S, which means two line segments overlap) to find the overlap segments, use a MAX value to keep the line segment which has max overlapping line segments. O(nlogn)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment