Greedy Algorithm & Optimal Coin Change

  • Thread starter CRGreathouse
  • Start date
  • Tags
    Algorithm
In summary, the conversation discusses the problem of making change using coins and the optimal approach to do so. The greedy algorithm is introduced and its optimality is questioned and explored. The conversation also mentions a paper and a counterexample to a conjecture about the necessary and sufficient conditions for the greedy algorithm to be optimal. The conversation ends with the mention of a potential counterexample with a total of three coins.
  • #1
CRGreathouse
Science Advisor
Homework Helper
2,844
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
  • #2
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:
  • #3
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!
 
  • #4
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:

Related to Greedy Algorithm & Optimal Coin Change

1. What is a greedy algorithm?

A greedy algorithm is a problem-solving method that makes the best possible choice at each step in order to find an optimal solution. It is a simple, intuitive approach that works well for many problems, but it may not always produce the most optimal solution.

2. How does a greedy algorithm work?

A greedy algorithm works by making the best possible choice at each step, without considering the overall optimal solution. This means that it does not backtrack or reconsider previous choices, which can lead to suboptimal solutions. However, in some cases, a greedy algorithm can produce the optimal solution.

3. What is the optimal coin change problem?

The optimal coin change problem is a classic problem in computer science that involves finding the minimum number of coins needed to make a given amount of change. It is often used as an example to demonstrate the effectiveness of greedy algorithms.

4. How does a greedy algorithm solve the optimal coin change problem?

A greedy algorithm solves the optimal coin change problem by always choosing the largest coin denomination possible at each step. This ensures that the minimum number of coins is used to make the required amount of change. However, this may not always be the most optimal solution, as some coin combinations may result in a smaller total number of coins.

5. What are the limitations of greedy algorithms in solving the optimal coin change problem?

The main limitation of greedy algorithms in solving the optimal coin change problem is that they do not consider the overall optimal solution, and may therefore produce a suboptimal solution. This is because the optimal solution may require a combination of smaller denominations, rather than just the largest denomination at each step. As a result, it is important to carefully analyze the problem and determine whether a greedy algorithm is the most appropriate approach.

Similar threads

Replies
2
Views
7K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
1K
Replies
13
Views
1K
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
1K
  • General Math
Replies
6
Views
2K
  • General Math
Replies
1
Views
1K
Back
Top