Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jarvis March Graham Scan Chan’s Algorithm

Similar presentations


Presentation on theme: "Jarvis March Graham Scan Chan’s Algorithm"— Presentation transcript:

1 Jarvis March Graham Scan Chan’s Algorithm
Convex Hulls (2D) Jarvis March Graham Scan Chan’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 points In 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 well Occasionally pop up in problems where you can compute parts of the output one by one

4 Jarvis march Start 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 0o Take point with smallest angle Repeat, except for further steps, measure angles ccw with the line segment from current to previously selected point being 0o

5 Jarvis march

6 Can we do better? Jarvis performs reasonably well if output size is small Calculate 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 output Runtime 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 scan Take starting point to be bottom-most point (if tied, take left-most) Sort all points by angle with right (+x) being 0o Iterate over points in order If the next point forms a “left turn” with the previous two, add it to the list and continue If “right turn”, remove the previous point until the angle becomes a left turn

8 Graham scan

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 authors Requires median-finding in O(n) Chan’s algorithm, published in 1996, also achieves O(n lg h), but more simple As 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 points Use 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…

13 Chan’s Algorithm

14 Chan’s Algorithm Problem: In general, we don’t know the size of the convex hull before we compute, so h is unknown; thus, this algorithm will not work Instead, 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, abort Thus, 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 optimizations Discard 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


Download ppt "Jarvis March Graham Scan Chan’s Algorithm"

Similar presentations


Ads by Google