Convex hull (Graham scan, Jarvis march)

symphonic, cinematic, dramatic, orchestral

Listen on 93

Lyrics

[Verse 1]
Got a scatter of points across the plane tonight
Need to wrap them tight in the smallest sight
Convex hull's the boundary, rubber band stretched clean
Around the outer edges, tightest shape you've seen
Two algorithms battle for the fastest route
Graham scan's got sorting, Jarvis march pursuit
Counter-clockwise motion, eliminate the bends
Geometric warfare where efficiency transcends

[Chorus]
Graham sorts by angle, sweep around the stack
Pop the right turns, never looking back
Jarvis walks the perimeter, gift wrap style
Find the leftmost starting point, march each mile
Convex hull surrounds them, boundary so tight
Both algorithms hunting for the edge tonight

[Verse 2]
Graham needs his preprocessing, polar angle sort
From the lowest y-coordinate, build his cohort
Push three points initial, scan the remaining set
Cross product calculation, left turn or right bet
Negative means right turn, pop that vertex clean
Positive keeps building, sharpest hull machine
Stack manipulation, growing outer shell
O of n log n runtime, Graham does it well

[Chorus]
Graham sorts by angle, sweep around the stack
Pop the right turns, never looking back
Jarvis walks the perimeter, gift wrap style
Find the leftmost starting point, march each mile
Convex hull surrounds them, boundary so tight
Both algorithms hunting for the edge tonight

[Verse 3]
Jarvis march steps different, gift wrapping approach
Start with leftmost vertex, systematic coach
From current to all others, measure every angle
Find the most clockwise, geometric tangle
That becomes your next point, add it to the chain
Repeat until returning to the start again
O of n times h runtime, h vertices on hull
Simple but slower when point sets are full

[Bridge]
Cross products determine which direction bends
Orientation testing, where geometry transcends
Stack for Graham's method, linear for Jarvis walk
Choose your weapon wisely when the datasets talk

[Outro]
Two masters of the boundary, wrapping point arrays
Graham sorts then sweeps, Jarvis gift-wrap ways
Convex hulls computed, outer shells revealed
Computational geometry, algorithms sealed

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