Presentation on theme: "Jarvis March Graham Scan Chan’s Algorithm"— Presentation transcript:
1 Jarvis March Graham Scan Chan’s Algorithm Convex Hulls (2D)Jarvis MarchGraham ScanChan’s Algorithm
2 What is a convex hull?Wikipedia: “the minimal convex set containing X, where X is a set of points in a real vector space V”In 2D: Convex polygon of smallest area containing all given pointsIn 3D: Convex polyhedron of smallest volume containing all given points
3 Output-sensitive algorithms Any algorithm with a runtime dependent not only on the input size, but on the output size as wellOccasionally pop up in problems where you can compute parts of the output one by one
4 Jarvis marchStart at the leftmost point in the set (if there are multiple, take the closest to the bottom)For all other points, compute the angle measured ccw with down being 0oTake point with smallest angleRepeat, except for further steps, measure angles ccw with the line segment from current to previously selected point being 0o
6 Can we do better?Jarvis performs reasonably well if output size is smallCalculate angles for every point each time it progresses to a new point, and it progressed to a new point once for every point in the outputRuntime O(nh), where n = # of points, h = # of output points.If k is large (read: O(lg n)), Jarvis is slow, can be as bad as O(n2)
7 Graham scanTake starting point to be bottom-most point (if tied, take left-most)Sort all points by angle with right (+x) being 0oIterate over points in orderIf the next point forms a “left turn” with the previous two, add it to the list and continueIf “right turn”, remove the previous point until the angle becomes a left turn
9 Can we do even better? Graham scan Jarvis march O(n lg n) O(nh) O(n lg h) ?
10 Yup.The “ultimate convex hull algorithm” published by Kirkpatrick and Seidel in 1986 achieves O(n lg h)Uses reversal of divide-and-conquer, referred to as “marriage-before-conquest” by authorsRequires median-finding in O(n)Chan’s algorithm, published in 1996, also achieves O(n lg h), but more simpleAs a lazy CS major, I’ll use this
11 Chan’s Algorithm Uses both Graham scan and Jarvis march as subroutines Partitions points into smaller chunks, then derives an overall convex hull by exploiting the smaller precomputed hulls
12 Chan’s Algorithm Suppose we know h, the size of the output We can partition (arbitrarily) n points into 1+n/h subsets, each with h or h-1 pointsUse Graham scan on each of subsets; must be done 1 + n/h times, and each takes O(h lg h), so overall runtime = (1+n/h)O(h lg h) = O(n lg h)Finish computing convex hull from parts…
14 Chan’s AlgorithmProblem: In general, we don’t know the size of the convex hull before we compute, so h is unknown; thus, this algorithm will not workInstead, iterate over the algorithm with different guesses for h to converge to the answer
15 Chan’s Algorithm For step t, let the guess for h be m = min(22t, n) If hull is not completed in m steps, abortThus, each step takes O(n lg m) = O(n∙2t)Starting t at 0, we are guaranteed to find the solution by t =Thus, total runtime is
16 Chan’s Algorithm Looks complicated But, we know Thus, So we have a working O(n lg h) algorithm, yay
17 Other optimizationsDiscard points found to be inside smaller convex hulls prior to merge step on each iteration of algorithm (if a point lies in any convex polygon, it cannot be in convex hull)Alternatives to 22t
Your consent to our cookies if you continue to use this website.