Download
last time n.
Skip this Video
Loading SlideShow in 5 Seconds..
Last time PowerPoint Presentation

Last time

150 Vues Download Presentation
Télécharger la présentation

Last time

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Last time • Several convex hull algorithms. • Lower bound of O(n log n) • O(n log h) for output sensitive. • Today: • Chan’s Algorithm: An optimal O(n log h) algorithm.

  2. More specific reprise • Jarvis March: O(n h) • Grahams Scan: O(n log n) • Sort: O(n log n) • Create the Hull: O(n)

  3. Chan’s Algorithm • Not such a complicated algorithm. • Somewhat sophisticated analysis. • Came out 10 years after the first optimal algorithm • Much simpler than the first optimal algorithm.

  4. Algorithm • Idea 1, Break the point set into groups. • Run one algorithm on each group • Run different algorithm to put them together. • Idea 2, Pretend we know “h” • At first, pretend you know the best size in which to break up the group. • Cute trick exists to fix the fact that you don’t know the size.

  5. Algorithm Break the point set into (n/m) groups of size m • Within each group, we’ll use Graham’s scan. • (n/m) groups, O(m log m) for each • O(n/m m log m) time. Then do Jarvis march on the “n/m” hulls. • Usually O(nh). • But with (n/m) hulls of size m, time is (n/m * h*log(m)), (as well see on the next slide). • O(nh/m log m) time. • If (m = h), life is good! = n/h h log h = n log h = nh/h log h = n log h

  6. Arbitrarily partition the points. Graham’s scan on each group.

  7. Jarvis March Around groups. Choose the smallest angle, then continue.

  8. Lie # 1: This isn’t done by sweeping line up. Key part of last routine is the problem:Given a convex polygon P, and a point outside that polygon q, find the tangent of that polygon: P q

  9. q “clockwise tangent and counterclockwise tangent” HW problem 1. Given a point q, and and polygon given by an ordered array of n vertices going ccw around the polygon, find the ccw tangent of the polygon with respect to the point q in O(log n) time. Hint, this can be done similar to a binary search, using orientation tests. Hint #2, it will feel more complicated than a binary search. P

  10. h h P ( ( P ( ( ( ( ( ) ) ) ( ) ) ) ( ( ) ) ) ( ( ( ) ) ( ( ) ) ( ) n n n n h l l l l l l l h l l h ! h l h h l h ¤ O O O O O O O O O 3 4 + + + ¼ ¼ m n o o g o g m g m m n o o g g o m m g o g m o g m n o g n o g n o g = = = 3 3 : : : m m = = m m m m Life is only good if (m = h?). Graham’s scan Jarvis march on the “n/m” hulls. Idea, lets try m = 3, 4, 5, 6, 7, until we get to h? …spending way too much time trying values of h, too worried about going “over”? • If jarvis march doesn’t stop after m steps, quit and try next value of m.

  11. ( ( ) ) l l h 1 2 3 ( ( ) ) l l h 1 2 3 o g o g ( ( ( ( ( ) ) ) ) ) 2 2 2 2 l l h h O O O o g o g ( ( ( ) ( ) ( ) ( ) ) ) 2 2 2 2 2 l l l l O + + + 2 2 2 2 + + + n n n o g o g = = = n o g o g o g o g = : : : : : : Idea, lets try m = 4, 16, 256, 65536,… until we get to h?

  12. Part II • Theorem: If n points are sampled from a uniform distribution in a square, then there are O(log n) points on the convex hull. • Uniform distribution in a square means that for each point, its (x,y) coordinates are each chosen with a constant probability density function (as opposed to, for example, a Gaussian distribution).

  13. First, break hull into 4 parts, top-right, top-left, bottom-right, bottom-left. Use top, bottom, left and right points to break. Now, we will bound the number of points on the top right hull. Hard? Instead, let’s bound a larger number: the number of “un-dominated points”. A point is dominated if there is any point both above and to the right of it. No “dominated” point is on the upper right convex hull (it is left of two lines :from right-most point to the dominating point and from the dominating point to the top most point.) So # of dominating points >= # of convex hull points.

  14. How many dominating points? Sort the points by descending x-coordinate. (Not an algorithm, just organizing things for a proof). Let pi = (xi,yi), then if i>j, xi<xj. pi is dominating if it has larger y-coordinate than p1…pi-1. The y-coordinates are random, so the chance that pi>p1…pi-1 is 1/i. So the expected number of dominating points is: Si=1..n (1/i) = (1/1 + ½ + 1/3 + ¼ + 1/5 + 1/n) = log(n) 5 3 6 8 4 2 1 7

  15. Summary • Jarvis March: O(nh) • Grahams’ Scan: O(n log n) • Random points in a square: h is about log n, • So O(nh) = O(n log n). • Merge Hull/ Quick Hull: O(n log n) • Bound (under comparison model) is O(n log h), by reduction to sorting.