Greedy Algorithms8 sections · 316 units
Open in Course

The Greedy Mindset

How to think

When you see an optimization problem, ask yourself:

1.1. Can I sort the input meaningfully?

2.2. At each step, is there an obvious best choice?

3.3. Does that choice ever block a better global solution? If you answer yes, yes, no, try greedy. Build the solution, test on examples. If it works, prove it (or at least convince yourself). If you find a counterexample, do not force greedy. Switch to DP or another technique. If you find a counterexample, stop trying to fix greedy. Switch immediately to DP or brute force. Forcing greedy on wrong problems wastes time.