Convex hull (Graham scan, Jarvis march)

hip-hop, educational

Listen on 93

Lyrics

[Verse 1]
Points scattered like stars across the plane
Need to find the boundary that contains
Outermost vertices forming a shell
Convex hull algorithms tell the tale
Start with lowest point, that's your base
Y-coordinate minimal, break ties with x-space
Graham scan begins with polar sort
Angles from the base, mathematical sport

[Chorus]
Sort by angle, stack them high
Pop when turning right, that's the Graham way
Jarvis wraps around the sky
Gift wrap method, hull by hull we stay
Convex means no dents inside
Every interior angle less than one-eighty
Two approaches, both collide
On the same result, geometrically

[Verse 2]
Graham uses stack manipulation
Push and pop with angle calculation
Three points form a turn direction
Cross product gives you the detection
Positive means counterclockwise bend
Keep that point, the algorithm's friend
Negative means clockwise rotation
Pop the middle, stack deflation

[Chorus]
Sort by angle, stack them high
Pop when turning right, that's the Graham way
Jarvis wraps around the sky
Gift wrap method, hull by hull we stay
Convex means no dents inside
Every interior angle less than one-eighty
Two approaches, both collide
On the same result, geometrically

[Verse 3]
Jarvis march takes different route
Start from leftmost absolute
Find the next point on the hull
Most counterclockwise pull
Check each candidate in the set
Smallest polar angle you get
Wrap around like gifting paper
Hull emerges, point by point, no caper

[Bridge]
Graham's faster when points are dense
N log N time complexity hence
Jarvis shines when hull is small
N times H, that's the call
Both deliver same solution
Convex boundary, no confusion

[Outro]
Two algorithms, same destination
Hull computed through iteration
Choose your method, know the cost
In computational geometry, nothing's lost

← Max-flow min-cut theorem | Line intersection →