Greedy Algorithms8 sections · 316 units
Open in Course

Example - Coin Change (Greedy Fails)

Non-standard denominations

Make change for 66 cents using coins (11, 33, 44). Minimize the number of coins. Greedy approach: take 44 first (22 left), then take 11, take 11. Total: 33 coins. But wait: 33 + 33 = 66 using only 22 coins! Greedy gave the wrong answer.

What went wrong? The coin values are not "canonical." Taking the locally best coin (44) blocked the globally best solution (33 + 33). That's exactly when you need DP instead. The 44 cent coin breaks the canonical property. Taking it first blocks the globally optimal pair. This is why you need to verify greedy choice property before coding.