Two ways to make a sequence of choices
Many problems are a chain of decisions. Two strategies:
- Greedy: at each step take what looks best right now, never reconsider.
Fast, short, and sometimes wrong.
- Dynamic programming: work out the best answer for every smaller
subproblem, store it, and build up. Slower, always right when the problem fits.
The skill being tested is knowing which applies. Greedy is not "the easy one" - it is the one that needs a proof.
Worked example 1: activity selection, where greedy is correct
You have n events with start and finish times. Attend the maximum number that do not overlap. This is the classic hall-scheduling problem.