Activity selection

lo-fi, ambient, dreamy, relaxed

Listen on 93

Lyrics

[Verse 1]
Got a conference room, activities lined up neat
Each one's got a start time, finish time complete
Greedy algorithm, that's the golden key
Sort by finish early, maximize what we see
Calendar's a battlefield, conflicts everywhere
Can't attend two meetings when they overlap and share
Pick the shortest first? Nah, that logic's flawed
Earliest completion gets the selection nod

[Chorus]
Sort by finish, pick the earliest done
Activity selection, optimal solution
No overlap allowed, that's the iron rule
Greedy choice property, algorithmic jewel
Sort by finish, pick the earliest done
Maximum activities under the sun

[Verse 2]
Lecture hall scenario, classes need the space
Physics ends at two, chemistry takes its place
Math runs nine to noon, biology's three to five
Which combinations keep the schedule most alive?
Proof by contradiction shows the greedy wins
Optimal substructure, that's where magic begins
If you picked wrong early, whole solution breaks
Perfect local choices, global optimum makes

[Chorus]
Sort by finish, pick the earliest done
Activity selection, optimal solution
No overlap allowed, that's the iron rule
Greedy choice property, algorithmic jewel
Sort by finish, pick the earliest done
Maximum activities under the sun

[Bridge]
Linear time complexity once the sorting's through
N log N for ordering, then one pass will do
Compatible activities, chain them end to end
Dynamic programming? Greedy's simpler, friend

[Verse 3]
Machine scheduling, resource allocation tight
Earliest deadline first, optimize your fight
Interval graphs dancing, maximum weight you seek
But classic selection keeps the method sleek
Sports tournaments, job interviews to book
Theater showtimes, anywhere you look
Greedy stays unbeaten when the goal is count
Maximum selection, that's the paramount

[Chorus]
Sort by finish, pick the earliest done
Activity selection, optimal solution
No overlap allowed, that's the iron rule
Greedy choice property, algorithmic jewel
Sort by finish, pick the earliest done
Maximum activities under the sun

[Outro]
From the west coast wisdom, algorithms reign
Activity selection, lodged inside your brain
Greedy beats them all when counting is the game
Sort by finish time, remember the refrain

← Closest pair of points | Huffman coding →