A greedy algorithm makes a locally attractive choice and continues without revisiting that decision. Before relying on that strategy, look for a small instance where the local choice prevents the best complete result.
Worked example
Consider making a total of six with coin values one, three, and four. Repeatedly choosing the largest available coin produces four plus one plus one, using three coins. Choosing three plus three uses two coins. This counterexample shows that the largest-coin rule does not minimize the number of coins for every denomination system.
What to check
Keep the problem contract precise. The example assumes unlimited coins and asks for the fewest coins. A greedy rule may still be correct for a different problem or for a denomination system with a suitable proof. Search small inputs to challenge a proposed rule, then use a correctness argument to establish the conditions where it works. Passing many examples alone does not establish that a local decision is always safe.
Continue with the book
Explore the full treatment, worked examples, and exercises in Algorithms Made Simple.
Companion article for Algorithms Made Simple, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
