Part 10 of 14

Greedy

Greedy proofs, exchange arguments, interval scheduling, Huffman coding.

Chapters
5
Hours
2
Difficulty
Intermediate to Advanced
  1. 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.

    20 min
  2. 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.

    15 min
  3. 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.

    15 min
  4. 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.

    20 min
  5. 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.

    25 min