Checking a Greedy Choice on a Counterexample

A greedy algorithm chooses a locally preferred candidate at each step. An example can refute a rule, while a proof must cover all allowed cases.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Try a coin system
  2. Look for the actual proof obligation
  3. Make the local winner block a better combination
  4. Qualify the claim by the feasible input model

Try a coin system

With coin values 1, 3, and 4, the largest-first rule for six chooses 4, 1, and 1. Two coins of value 3 do better. A worked algorithm test can expose failure before implementation.

Look for the actual proof obligation

If a different greedy choice is claimed safe, find an argument that transforms an optimal solution to start with it without raising cost. See greedy exchange.[1]

Make the local winner block a better combination

With coin values one, three and four and target six, choosing the largest remaining coin gives four plus one plus one. Taking two threes uses fewer coins. The local choice can be implemented perfectly and still fail the global objective. See counterexamples in code.

Greedy:     6 → take 4 → 2 → take 1 → 1 → take 1 → 0
Alternative 6 → take 3 → 3 → take 3 → 0
Counts: 3 versus 2

Qualify the claim by the feasible input model

A greedy method needs a correctness argument tied to its objective and allowed inputs. An exchange argument can show that some optimal solution agrees with the local choice, where such an argument exists. Use exhaustive search on small targets to find counterexamples.

References

  1. Jeff Erickson, Algorithms ↩