Greedy Algorithm & Optimal Coin Change

  • Context: Undergrad 
  • Thread starter Thread starter CRGreathouse
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary

Discussion Overview

The discussion revolves around the optimality of the greedy algorithm for making change with various coin denominations. Participants explore the conditions under which the greedy algorithm yields the least number of coins, examining specific examples and counterexamples related to different sets of coin values.

Discussion Character

  • Exploratory
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reflects on their past attempts to prove that the greedy algorithm always provides optimal change for certain coin values, noting that it fails for the set {5, 4, 1} when making 8 cents.
  • Another participant mentions that finding a necessary and sufficient condition for the greedy algorithm's optimality is complex, suggesting that while there are sufficient conditions, they are not straightforward.
  • A later reply indicates that a paper discusses the polynomial time complexity of determining whether a set of coin values can be solved optimally with the greedy algorithm, despite the NP-hard nature of finding the least number of coins needed.
  • One participant provides a counterexample to their earlier conjecture regarding superincreasing sequences, citing the set {2001, 1000, 1} for a total of 3000, which does not yield an optimal solution using the greedy algorithm.
  • Another participant identifies a potential least superincreasing counterexample as {6, 4, 1} for a total of 8, further complicating the discussion on optimality.

Areas of Agreement / Disagreement

Participants express differing views on the conditions for the greedy algorithm's optimality, with no consensus reached on a definitive characterization. Multiple competing examples and counterexamples are presented, indicating ongoing debate.

Contextual Notes

The discussion highlights limitations in establishing a clear set of conditions for the greedy algorithm's optimality, with participants acknowledging the complexity of the problem and the presence of counterexamples that challenge initial assumptions.

CRGreathouse
Science Advisor
Homework Helper
Messages
2,832
Reaction score
0
I'm not sure that this is the right place for this post, but I couldn't find a better.

Many years ago I considered the problem of making change with (say) quarters, dimes, nickels, and pennies. I tried to prove to myself that what I now call the greedy algorithm (pick the most valuable coin that doesn't take you over your limit) always made optimal change -- that no solutions with fewer coins existed. At the time I wasn't able to find a proof of the specific case {25, 10, 5, 1} but I could see that the general result failed -- consider {5, 4, 1} to make a total of 8 cents. The greedy algorithm gives (5, 1, 1, 1) but (4, 4) is better.

I was wondering if there's a good characterization of what combination of coin values make the greedy algorithm always optimal. Back then I could see that being in a geometric series was a sufficient, but unnecessary, condition. Briefly reconsidering the problem, it seems that the greedy algorithm should be optimal for superincreasing sequences -- but is this necessary for optimality? Any thoughts, counterexamples, or reading/references?
 
Mathematics news on Phys.org
This is certainly a classical problem. A quick search turns up this:

http://mathforum.org/wagon/spring04/p1009.html

(but I can't seem to follow the link contained in it. I don't think you could get the text easily from there anyways)

which makes it sound like a necessary and sufficient condition won't be simple to write. I know there are some nice, simple, sufficient conditions, but I can't remember the usual one, and I think my only hard reference is at work.


edit: I think this is the paper on it. (You can grab it from the "cached: ... PDF" link in the top-right corner) It doesn't seem terribly clear, but maybe I'm just tired. :smile:
 
Last edited:
Hurkyl said:
edit: I think this is the paper on it. (You can grab it from the "cached: ... PDF" link in the top-right corner) It doesn't seem terribly clear, but maybe I'm just tired. :smile:

Thanks a bunch, that's exactly what I was hoping for I'll read through it and see how much I get. I appreciate it!
 
Well, I read the paper. It shows that it can be decided in polynomial time (O(n^2)) if a certain combination of coin values can always be solved optimally with the greedy algorithm, even though determining the least number of coins needed for a given set of coin values and total x is NP-hard.

Also, I was able to find a counterexample to my 'conjecture' above. Not all superincreasing sequences are solved optimally by the greedy algorithm; consider coins {2001, 1000, 1} and total 3000. I'll see if I can find the least superincreasing counterexample now -- clearly, it has exactly 3 coins.

Edit: I think it's {6, 4, 1} with a total of 8.
 
Last edited:

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
9
Views
3K