Greedy Algorithms8 sections · 316 units
Open in Course

Counterexample - The Classic

When fractional thinking fails

Here is the classic counterexample: Items: (weight= P0, value= P1), (weight= P2, value= P3), (weight= P4, value= P5). Capacity = 5050. Ratios: 66, 55, 44. Greedy takes item 11 (ratio P11), then item 22 (ratio P13). Total weight: 3030, total value: 160160. Item 33 does not fit (need P17 more, only P18 left).

But items 22 + 33: weight = 5050, value = 220220. Much better! Greedy got 160160, optimal is 220220. That's why 00/11 knapsack needs DP. This example shows greedy's local choice blocks a better global solution.