Chan's Algorithm for Convex Hull Problem. Output Sensitive Algorithm. Takes O(n log h) time. Presentation for the final project in CS 6212/Spring/Arora.
2. Definition Of Convex HULL
Simply, given a set of points P in a plane, the convex hull of this set is the smallest convex polygon that
contains all points of it.
(A set of points and its convex hull)
2
3. We will introduce an O(nlogh) algorithm known as Chan’s
Algorithm, where h refers the number of points in the hull.
However, Chan’s Algorithm is based on other two
algorithms known as Jarvis’s Algorithm O(nh) and Graham’s
Algorithm O(nlogn).
So, we will talk about these two algorithms first.
3
4. Before Start…
• Counterclockwise and Clockwise
• It’s relative
• In this presentation
• Use function orient(p, q, i) to calculate the
relationship of pq and pi.
• Obviously, orient(p, q, i) = - orient(p, i, q)
• Extreme points
• There will be four extreme points
• All of them MUST be in the hull lastly
• Most algorithm choose to start with one of the
extreme points.
• In this presentation
• All algorithms will start will the left most point.
4
6. Jarvis’s Algorithm
• Perhaps the simplest algorithm for computing Convex Hull
• In the two-dimensional case the algorithm is also known as Jarvis march, after R. A. Jarvis, who
published it in 1973.
• It has a more visual name: ‘Gift Wrapping’.
6
7. HOW IT WORKS?
1. Start with the left most point, l.
2. Let p = l, find out the point q that
appears to be furthest to the
right to someone standing at p
and looking at other points. (by
comparing all others points)
That’s is: orient(p, q, i) < 0 is always
true for all other points.
3. Set q as p, and use p as the start
point and use the same method
to find the next q.
4. Keep doing step 3, until q is equal
to l.
O(n)
O(h)
Total: O(nh)
O(n)
7
9. GRAHAM’S ALGORITHM
• It is named after Ronald Graham, who published the original algorithm in 1972.
• Also know as Graham’s scan, first explicitly sorts the points and then scanning algorithm to finish
building the hull.
• Basically, sort + scan.
9
10. HOW IT WORKS?
1. Start with the left most point, l.
2. Sorts all other points in
counterclockwise order around l.
That’s is: orient(l, i, i+1) > 0 is always
true for all points i.
3. Start with l, let p = l, q = l +1, i = l +
2.
4. Check orient(p, q, i)
• If < 0, move forward, let p = q, q =i, i =
i +1;
• If > 0, remove q, let p = p-1, q = p ;
5. Keep doing step 4, until all points
have been checked.
O(nlogn)
O(n)
Total: O(nlogn)
O(n)
SORTSCAN
10
12. Chan’s Algorithm = Jarvis's + Graham’s + ...
• It was discovered by Timothy Chan in 1993.
• It’s a combination of divide-and-conquer, gift-wrapping and graham’s scan.
• it’s output-sensitive, which means its running time depends on the size of its output (or input).
12
13. HOW IT WORKS?
1. Find a magic value of ‘m’, which
divides all points into n/m subsets,
and each subset has m points,
approximately.
2. To each subset, use Graham’s
algorithm to compute its sub-hull.
3. To all sub-hulls, use Jarvis’s
algorithm to compute the final
convex hull.
• Choose one extreme point as the start
point, and compare the right tangents
of all sub-hulls.
• Choose the rightest one as the next
point.
• Start with the next point, and do it
again, until the next point is equal to
the start point
13
14. Find Magic ‘m’
• The core of Chan’s algorithm is how to figure out the value of m. (The object is to make m very close to
h, or equal)
• Chan proposed a amazing trick here:
• We set a parameter t = 1 and set m = 2^(2^t).
• Then use this m to execute Chan’s Algorithm, in step 3, we set a counter for the output number of points in the
hull. Once the counter reaches value m, it terminate the algorithm and increment t by 1, re-calculate the value
m, and do it again!
• By doing this, the time for running this algorithm will always be less than O(nlogm).
14
15. TIME COMPLEXITY
• We divided points into n/m parts, so each part has m
points.
• Since the algorithm will be terminated when it number
of output reaches m, so this step will at most cost
O(nlogm), when m is small.
• For step 2
• It’s O((n/m) * mlogm) = O(nlogm)
• For step 3
• Finding one extreme point, O(n).
• tangents
• Finding the right tangents of one sub-hull, O(logm).
• There are n/m sub-hulls, so O((n/m)logm)
• There are h points in the hull. O(h*(n/m)logm) = O(nlogh)
when h=m.
• Totally, it’s O(nlogh).
1. Find a magic value of ‘m’, which
divides all points into n/m subsets,
and each subset has m points,
approximately.
2. To each subset, use Graham’s
algorithm to compute its sub-hull.
3. To all sub-hulls, use Jarvis’s
algorithm to compute the final
convex hull.
• Choose one extreme point as the start
point, and compare the right tangents
of all sub-hulls.
• Choose the rightest one as the next
point.
• Start with the next point, and do it
again,until the next point is equal to
the start point
15