Convex Hull Part II
- A divide and conquer plan.
- Sort the points by the x coordinate, breaking ties by the y coordinate.
- The leftmost point and the rightmost point must be on the convex hull. (P1,Pn).
- Use this line to divide the data into two sets, the set below the line and the set above the line.
- If we are careful, we can partition the two sets to maintain order.
- Points on the line can be discarded.
- We then construct the "Upper" hull and "Lower" hull.
- To construct the "Upper" hull
- Find the point Pmax in the upper set furthest from the line (P1,Pn).
- Pmax is on the convex hull.
- Any points below P1,Pmax or PmaxPn are not on the convex hull.
- Repeat the process for points above P1Pmax and points above PmaxPn
- We can sort in O(n lg (n))
- We can split in O(n) , using the cross product
- Calculating the furthest point is a constant (but expensive) time operation (See this page).
- So finding Pmax is O(n) maximum. Probably O(n/2) or better.
- T(n)= 2T(n/2) + O(n) (Yes/No?)