Problem of making change for n cents

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Change
In summary, the conversation discusses a problem of making change for a given amount using the fewest number of coins. A greedy algorithm is proposed and it is proven that it yields an optimal solution. The algorithm works by choosing the highest value coin and repeating until the amount to change is 0. The conversation also discusses the optimal substructure and the greedy choice property. The latter states that the first choice can only be a penny, nickel, dime, or quarter, and the amount to change is determined based on this first choice.
  • #1
evinda
Gold Member
MHB
3,836
0
Hello! (Wave)

I am looking at the following exercise.

Consider the problem of making change for $n$ cents using the fewest number of
coins. Assume that each coin’s value is an integer.
Describe a greedy algorithm to make change consisting of quarters, dimes,
nickels, and pennies. Prove that your algorithm yields an optimal solution.Could you give me a hint what we could do? (Thinking)
 
Technology news on Phys.org
  • #2
evinda said:
Hello! (Wave)

I am looking at the following exercise.

Consider the problem of making change for $n$ cents using the fewest number of
coins. Assume that each coin’s value is an integer.
Describe a greedy algorithm to make change consisting of quarters, dimes,
nickels, and pennies. Prove that your algorithm yields an optimal solution.Could you give me a hint what we could do? (Thinking)

The algorithm works by choosing the coin with the highest value, subtract that value from the amount to change, and repeat until the amount to change is 0. To prove this greedy algorithm yields an optimal solution, we must show optimal substructure and the greedy choice property. Optimal substructure:
Assume to make changes for n cents, the first coin chosen by the greedy algorithm is a c1 coin with value of n1. Let C be the optimal solution to change n cents. Then C – {c1} is an optimal solution to change n-n1 cents. Otherwise, let the optimal solution be B. Then B U{c1} contains fewer coins than C and yet both makes up n cents, so C cannot be the optimal solution making change for n cents, which is a contradiction. Greedy choice property:
If our first choice is a penny, then the amount to change is at most 4 cents. Optimal choice cannot make the change without using a penny, since any other coin makes too much change. If our first choice is a nickel, then the amount to change is between 5 cents and 9 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins, contracting that it is an optimal solution. Otherwise, the optimal choice can only change 4 cents, not enough to make the change. If our first choice is a dime, then the amount to change is between 10 cents and 24 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins. Otherwise, if it uses 2 nickels, we can turn it to a dime. Otherwise, it can only make change for at most 9 cents, not enough to make the change. If our first choice is a quarter, then the amount to change is at least 25 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins. Otherwise, if the optimal solution uses at most 2 dimes, it must use enough pennies to make up at least 25 cents, and we can turn it to a quarter and use fewer coins. Otherwise, the optimal solution uses at least 3 dimes, we can turn it to a quarter and a nickel and use fewer coins.
Therefore the greedy choice property is satisfied.
 
Last edited:
  • #3
phymat said:
The algorithm works by choosing the coin with the highest value, subtract that value from the amount to change, and repeat until the amount to change is 0. To prove this greedy algorithm yields an optimal solution, we must show optimal substructure and the greedy choice property. Optimal substructure:
Assume to make changes for n cents, the first coin chosen by the greedy algorithm is a c1 coin with value of n1. Let C be the optimal solution to change n cents. Then C – {c1} is an optimal solution to change n-n1 cents. Otherwise, let the optimal solution be B. Then B U{c1} contains fewer coins than C and yet both makes up n cents, so C cannot be the optimal solution making change for n cents, which is a contradiction.

I see... (Nod)

phymat said:
Greedy choice property:
If our first choice is a penny, then the amount to change is at most 4 cents. Optimal choice cannot make the change without using a penny, since any other coin makes too much change. If our first choice is a nickel, then the amount to change is between 5 cents and 9 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins, contracting that it is an optimal solution. Otherwise, the optimal choice can only change 4 cents, not enough to make the change. If our first choice is a dime, then the amount to change is between 10 cents and 24 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins. Otherwise, if it uses 2 nickels, we can turn it to a dime. Otherwise, it can only make change for at most 9 cents, not enough to make the change. If our first choice is a quarter, then the amount to change is at least 25 cents. If the optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer coins. Otherwise, if the optimal solution uses at most 2 dimes, it must use enough pennies to make up at least 25 cents, and we can turn it to a quarter and use fewer coins. Otherwise, the optimal solution uses at least 3 dimes, we can turn it to a quarter and a nickel and use fewer coins.
Therefore the greedy choice property is satisfied.

Could you explain to me what we are supposed to show? :confused:
Why do we say how high the amount to change is, based on out first choise? :confused:
 

Related to Problem of making change for n cents

1. How can we make change for n cents using the least amount of coins?

The problem of making change for n cents involves finding the most efficient way to use a combination of coins to add up to n cents. This can be achieved by using a greedy algorithm, where we start with the highest value coin and continue adding it to our solution until we reach n cents. Then, we move on to the next highest value coin and repeat this process until we have accounted for all n cents.

2. Can the problem of making change for n cents be solved using dynamic programming?

Yes, the problem of making change for n cents can be solved using dynamic programming. This involves breaking down the problem into smaller subproblems and storing the solutions to these subproblems in a table. This allows for a more efficient solution, as we can avoid repeating calculations for the same subproblems.

3. How does the availability of different coin denominations affect the solution to the problem of making change for n cents?

The availability of different coin denominations can greatly impact the solution to the problem of making change for n cents. If there are a limited number of coin denominations available, it may not be possible to make change for certain values of n. Additionally, the combination of coin denominations can also affect the efficiency of the solution.

4. Are there any other factors besides the number of coins used that should be considered when solving the problem of making change for n cents?

Yes, there are other factors that should be considered when solving the problem of making change for n cents. One important factor is the availability of different coin denominations, as mentioned earlier. Another factor is the value of the coins, as using higher value coins can result in a more efficient solution. Additionally, the order in which coins are used can also impact the solution.

5. Can the problem of making change for n cents be extended to other currencies besides the US dollar?

Yes, the problem of making change for n cents can be extended to other currencies. The basic principles and strategies used to solve this problem can be applied to any currency, as long as the currency has different coin denominations available.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
1
Views
4K
  • Set Theory, Logic, Probability, Statistics
2
Replies
45
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
3K
  • Programming and Computer Science
Replies
7
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
9
Views
900
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
Back
Top