Greedy Algorithms8 sections · 316 units
Open in Course

When Greedy Works

Recognizing the pattern

How do you know if greedy will work? Look for these signs:

1.1. The problem asks for maximum, minimum, or optimal something.

2.2. You can order or sort the input in a meaningful way.

3.3. Making the locally best choice does not block better future choices.

4.4. The problem has a natural "take it or leave it" structure. If all four apply, try greedy first. If you find a counterexample where greedy fails, switch to DP. Common bug: forgetting to check if your greedy choice leads to optimal results. Test on examples where greedy might fail.