Chapter 3: Convex Hull
Source files used: Convex_hull (Lecture 2 notes, pages 1 to 7A and Example A), MIT6_046JS15_pset1 (Problem 1-2 as practice); textbook Section 33.3 (sec33.3) as support. No worked examples are included.
1. Big Picture
Convex hull is the lecture’s first full divide-and-conquer algorithm.
The Master Theorem guide asked: how do you solve ? This guide asks: how do you design the merge step so that instead of ?
New ideas:
- brute force is ,
- the merge step is “find the upper and lower tangents, then cut and paste”,
- the two-finger tangent search makes the merge linear,
- the textbook adds Graham’s scan and Jarvis’s march as alternatives.
2. Core Ideas
2.1 Problem Statement
Given points in the plane:
For convenience the lectures assume no two points share an coordinate, no two share a coordinate, and no three are on a line.
Convex hull : the smallest polygon containing all points in .
Picture: the points are nails, and is the shape of a rubber band stretched around all of them.
2.2 Representation
The lectures represent as the sequence of boundary points in clockwise order, stored as a doubly linked list:
The textbook algorithms output vertices in counterclockwise order. Follow the lectures’ clockwise convention in exam answers unless told otherwise.
2.3 Divide and Conquer Plan
- Sort points by coordinate once and for all: .
- Divide into a left half and a right half by coordinate.
- Recursively compute and .
- Merge the two hulls.
All the difficulty is in step 4.
2.4 Tangents
The merged hull keeps part of , part of , and two new bridging edges:
- upper tangent : the bridge across the top,
- lower tangent : the bridge across the bottom.
An upper tangent does not mean or is the highest point of its hull (Example A in the notes shows this).
2.5 Why the Two-Finger Search Works (Intuition Only)
is the rightmost point of and is the leftmost point of . The search moves anticlockwise from and clockwise from . If is a pair where moving either finger decreases , then no points lie above the line through and .
The lectures state that the formal proof is involved and is not covered.
3. Main Governing Equations and Formulas
3.1 Brute Force
Test every segment between two points: it is a hull edge if all other points lie on one side of it.
Use as the baseline that divide and conquer beats.
3.2 Tangent Criterion
Let be the vertical line separating and . Define
Claim from the lectures:
If is not maximal, there are points on both sides of , so it cannot be a tangent. The lower tangent minimizes .
3.3 Naive Tangent Search
Check all pairs: per merge.
Use to explain why the merge step must be linear.
3.4 Two-Finger Upper Tangent:
with of maximum ; with of minimum .
i = 1
j = 1
while (y(i, j+1) > y(i, j) or y(i-1, j) > y(i, j)):
if y(i, j+1) > y(i, j): # move right finger
j = j + 1 (mod q)
else: # move left finger
i = i - 1 (mod p)
return (a_i, b_j) as upper tangent
Each finger only moves forward around its hull, so the loop runs times.
The lower tangent is found the same way, minimizing with the fingers moving the other way.
3.5 Cut and Paste Merge:
With upper tangent and lower tangent :
- Link to .
- Go down the list until you see , and link to .
- Continue along the list until you return to .
Lecture example: , , upper tangent , lower tangent , merged hull .
3.6 Divide and Conquer Running Time
by case 2 of the master theorem. The one-time sort is also , so the total is .
3.7 Textbook Alternative: Graham’s Scan,
- Let be the point with minimum (leftmost on a tie). It is a hull vertex.
- Sort the rest by polar angle counterclockwise around (keep only the farthest point for equal angles).
- Push onto a stack.
- For each next point : while next-to-top, top, makes a nonleft turn, pop. Then push .
The stack ends with the hull in counterclockwise order. Sorting is . The loop is total by aggregate analysis: each point is pushed once, so it is popped at most once.
3.8 Textbook Alternative: Jarvis’s March,
Gift wrapping: start at the lowest point; the next vertex has the smallest polar angle from the current one. Build the right chain up to the highest point, then the left chain back down.
Faster than Graham’s scan when .
4. Problem-Solving Workflow
- State the input assumptions (distinct , distinct , no three collinear) and the output format (clockwise linked list).
- Pre-sort by once: .
- Divide at the median into and .
- Recurse on both halves.
- Find the upper tangent with the two-finger search (Section 3.4).
- Find the lower tangent the same way.
- Cut and paste the two hulls (Section 3.5).
- Write and solve it with the master theorem.
- If asked about correctness, use the criterion (Section 3.2) and the intuition in Section 2.5.
Practice: Problem Set 1, Problem 1-2 (radio stations within distance 1) uses the same pattern: presorted lists and , divide and conquer, and an target, so the combine step has to be linear.
5. Decision Rules / Decision Trees
5.1 Which Hull Algorithm?
Need the lecture algorithm or a D&C design? → divide and conquer,
Need a simple stack-based method? → Graham’s scan,
Hull is known to have very few vertices ()? → Jarvis’s march,
Only asked for a baseline? → brute force,
5.2 Moving the Fingers (Upper Tangent)
? → move right finger:
Else ? → move left finger:
Neither increases ? → stop, is the upper tangent
5.3 Merge Cost Decides the Total
Merge is (try all pairs)? →
Merge is (two fingers)? →
6. Important Tables / Correlations Needed
6.1 Algorithm Summary
| Method | Idea | Time | Source |
|---|---|---|---|
| Brute force | test all segments | lecture | |
| D&C, naive merge | all tangent pairs | lecture | |
| D&C, two-finger merge | linear tangent search | lecture | |
| Graham’s scan | polar sort + stack | textbook | |
| Jarvis’s march | gift wrapping | textbook | |
| Prune-and-search | discard a constant fraction | textbook (mentioned only) |
6.2 Merge Step Costs
| Step | Cost |
|---|---|
| Find upper tangent | |
| Find lower tangent | |
| Cut and paste | |
| Whole merge |
7. Key Takeaways
- is the smallest polygon containing all points: the rubber band around the nails.
- The lectures store the hull clockwise in a doubly linked list; the textbook outputs counterclockwise.
- Brute force is edges times tests .
- D&C: sort by once, split into halves, recurse, merge with two tangents.
- Upper tangent maximizes , the crossing height on the dividing line .
- The upper tangent’s endpoints need not be the highest points.
- Two-finger search: right finger , left finger , stop when neither raises .
- Merge is , so .
- A merge would make the whole algorithm .
- Textbook alternatives: Graham’s scan , Jarvis’s march .