Greedy Algorithms8 sections · 316 units
Open in Course

How to Find Counterexamples

Systematic approach

When you suspect greedy might fail:

1.1. Start with n=2n = 2 or n=3n = 3 items.

2.2. Try inputs where greedy's first choice is different from intuition.

3.3. Compute greedy's answer and brute-force the optimal.

4.4. If they differ, you found a counterexample. For 00/11 knapsack, I tried several examples before finding one where greedy fails. Small examples make verification easy since you can try all possibilities. Systematically testing small cases catches errors early.