Greedy
Greedy proofs, exchange arguments, interval scheduling, Huffman coding.
- Chapters
- 5
- Hours
- 2
- Difficulty
- Intermediate to Advanced
- 10.0intermediate
Greedy thinking: when local choices win, and when they don't
When the locally-best choice provably aggregates to the globally-best answer. The exchange-argument proof technique and the failure modes where greedy looks right and isn't.
- 10.1intermediate
Interval scheduling: the comparator is the algorithm
Sort by end time and you've picked the maximum non-overlapping subset. The comparator (not the DP, not the heap) is the entire algorithm.
- 10.2intermediate
Activity selection and the task-scheduler family
A max-heap of remaining tasks paired with a cooldown queue. The same skeleton solves LC 621 Task Scheduler, room booking, and conference assignment.
- 10.3intermediate
Huffman encoding
Build the optimal prefix-free code bottom-up by repeatedly merging the two least-frequent symbols. The optimality proof and why this construction wins where top-down construction fails.
- 10.4intermediate
Jump games and gas station
Two array problems that look O(n^2), both solved by a single linear pass that maintains one running quantity. LC 55 Jump Game and LC 134 Gas Station.