← chapter

Greedy algorithms

Make the locally-best choice, never look back. Works only for the RIGHT criterion — which needs a proof.

Interval scheduling: which greedy?

Watch the earliest-finish sweep

Sorted by finish time; dashed line = last taken finish (room free to its right). Take if it starts after the line; skip if it overlaps. → 4 activities, the max.

The criterion is everything

Earliest-finish: optimal. Earliest-start: ~40% worse. Shortest: 13.0 vs 13.1 — looks right, isn't.

Prove it, don't benchmark it

Takeaway

Simplest to write, easiest to get subtly wrong. A greedy that's usually right is still a bug. Next: dynamic programming — for the overlapping-subproblem cases greedy can't touch.