Greedy Algorithms8 sections · 316 units
Open in Course

Finding Counterexamples

When greedy fails

Sometimes greedy is wrong. How do you find out? Look for small inputs where greedy gives the wrong answer. Strategies:

1.1. Test small cases: : Try all inputs of size 22, 33, 44 by hand.

2.2. Edge cases: : All values equal? All different? Extreme ratios?

3.3. Adversarial construction: : Build an input where greedy makes a bad first choice. One counterexample is enough to prove greedy fails. Then you need DP or another technique. Finding a counterexample saves you from submitting a wrong solution.