Greedy Algorithms8 sections · 316 units
Open in Course

Counterexample - 0/1 Knapsack

Greedy ratio fails

00/11 knapsack: items have weight and value, capacity is limited, items are indivisible. Maximize value. Greedy by value/weight ratio seems natural. But it fails.

Items: (weight= P0, value= P1), (weight= P2, value= P3), (weight= P4, value= P5). Capacity = 55. Ratios: 55, 44, 44. Greedy takes item 11 (ratio P11), weight 22 used. Remaining capacity 33. Item 33 does not fit. Item 22 fits. Total value: 1010 + 1212 = 2222. But taking just item 33 gives value 2020 with weight 55. Wait, that is less. Let me try again..