Purpose: Compute a 2D convex hull in output-sensitive time, where is the number of hull vertices — beating the of Graham scan when the hull is small.
The Idea: guess , then combine
Chan’s algorithm marries two hull algorithms:
- Graham scan — , good on small groups;
- Jarvis march (gift wrapping) — , output-sensitive but slow per step.
The combination:
- Guess a value for .
- Partition the points into groups of size . Compute each group’s hull with Graham scan: .
- Run a Jarvis march on the whole point set, but find each next hull vertex by binary searching the tangent from the current point to each small hull — per group, so per step.
- Stop after steps. If the hull closed, output it. If not, : double and restart.
The doubling trick
Start at and square it each round: . The total cost is dominated by the last round, where :
Squaring rather than doubling is what makes the geometric series collapse to rather than .
Complexity
- Time: — optimal for output-sensitive hull computation
- Space:
Convex hull algorithms compared
| Algorithm | Time | Notes |
|---|---|---|
| Jarvis march (gift wrapping) | output-sensitive but slow; fine when is tiny | |
| Graham scan | sort by angle; classic | |
| Andrew’s monotone chain | sort by ; write this — simpler, no angles, no precision headaches | |
| QuickHull | avg, worst | divide and conquer |
| Kirkpatrick-Seidel | the “ultimate” hull; complicated | |
| Chan | much simpler than Kirkpatrick-Seidel | |
| Melkman | for a simple polyline input only |
In a contest
Andrew’s monotone chain, every time. with is nothing, and the code is 20 lines with only integer arithmetic if the coordinates are integers. Chan’s algorithm is worth knowing for the technique, not the constant.
The transferable technique
“Guess the output size, run a doubling search, and pay only for the last guess” is a general pattern. It also gives:
- output-sensitive 3D hulls,
- -th smallest / selection with unknown -dependent bounds,
- any algorithm whose cost is with unknown but verifiable.
Variants / Use Cases
- Convex Hull — the topic page
- 3D convex hull — Chan’s technique extends to in three dimensions
- Rotating calipers — what you do after building the hull (diameter, width, closest pair of hulls)
- Kirkpatrick-Seidel — the other optimal output-sensitive hull