Greedy
Make the locally best choice, and know how to prove it is safe.
5 pages, free to read
- 1
When greedy works (exchange argument)
IntermediateA greedy algorithm makes the locally best choice at every step and never looks back; it is correct only when you can prove that some optimal answer agrees with that choice.
10 min read - 2
Activity selection
IntermediateTo fit the most non-overlapping activities, sort by end time and keep every activity that starts after the last one you kept ends.
9 min read - 3
Reachability (jump game)
IntermediateTrack the farthest index you can reach so far; if you ever stand beyond it you are stuck, and counting how often you must extend that frontier gives the minimum number of jumps.
9 min read - 4
Circular routes (gas station)
IntermediateIf total gas covers total cost a valid start exists, and it is the station right after the last point where the running tank went negative.
9 min read - 5
Cheapest merging (Huffman-style)
AdvancedWhen combining two items costs their total size and you must combine everything, always merge the two smallest first, using a min-heap.
10 min read