Question

Suppose we want to make change for n cents, using the least number of coins of...


Suppose we want to make change for n cents, using the least number of coins of denominations 1, 10, and 25 cents. Consider the following greedy strategy: suppose the amount left to change is m; take the largest coin that is no more than m; subtract this coin's value from m, and repeat. Either give a counter example, to prove that this algorithm can output a non-optimal solution or prove that this algorithm always outputs an optimal solution.
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

This algorithm does not always give the optimal solution.

Consider we have to make change for 30 cents, using the least number of coins of denominations 1,10 and 25 cents. According to the given strategy, we first take a 25 cents coin and subtract it from 30 cents. Now, we have to make 5 cents which we can make only from 5 one-cent coins. So, the total number of coins required is 6 according to the given greedy strategy. But we can simply use 3 ten-cent coins to make change of 30 cents. So, this example proves that the given strategy is not an optimal one.

Add a comment
Know the answer?
Add Answer to:
Suppose we want to make change for n cents, using the least number of coins of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • A checkerboard has a certain number of coins on it. A robot starts in the upper-left...

    A checkerboard has a certain number of coins on it. A robot starts in the upper-left corner, and walks to the bottom left-hand corner - The robot can only move in two directions: right and down - The robot collects coins as it goes You want to collect all the coins using the minimum number of robots. Do you see a greedy algorithm for doing this? Does the algorithm guarantee an optimal solution? Can you prove it? Can you find...

  • Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we...

    Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we wish to make change for an amount A using as few coins as possible. Assume that vi’s and A are integers. Since v1= 1 there will always be a solution. Formally, an algorithm for this problem should take as input:  An array V where V[i] is the value of the coin of the ith denomination.  A value A which is the amount...

  • Write a program that tells what coins to give out for as change from 1 cent...

    Write a program that tells what coins to give out for as change from 1 cent to 99 cents. Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies) only. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Solution Demo Hello I am the coin machine! I will give you the least number of coins for your change....

  • 5. (3 points) Consider a hypothetical country Binary Land where they only use coins. There are...

    5. (3 points) Consider a hypothetical country Binary Land where they only use coins. There are n types of coins of denominations 1, 21, 22, 2,..., 2-1. Suppose you are a bank teller in Binary Land and your job is to give money to customers for any requested value V that is an integer. You should minimize the number of coins while paying V units of money. Design an algorithm that takes V as input and outputs the payment method...

  • Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 <...

    Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 < d2 < ··· < dk, and infinitely many coins of each denomination, find the minimum number of coins needed to make exact change for n zonks. Here we ask a different problem. Each coin has a weight, the weight of each coin with denomination di being wi > 0. We want to make exact change while minimizing the total weight of the coins used....

  • Design an O(n)-time non-losing strategy for the first player, Alice, in the coins in-a-line game. Your...

    Design an O(n)-time non-losing strategy for the first player, Alice, in the coins in-a-line game. Your strategy does not have to be optimal, but it should be guaranteed to end in a tie or better for Alice. Coins in a Line 12.4.1 The first game we consider is reported to arise in a problem that is sometimes asked during job interviews at major software and Internet companics (probably because it is so tempting to apply a greedy strategy to this...

  • 2. (10%) Suppose that among n identical-looking coins, one is fake. With a balance scale, we...

    2. (10%) Suppose that among n identical-looking coins, one is fake. With a balance scale, we can compare any two sets of coins. That is, by tipping to the left, to the right, or staying even, the balance scale will tell whether the two sets weight the same, or which of the two sets is heavier than the other but not by how much. Please use the prune and search strategy to design an efficient algorithm for detecting the fake...

  • Suppose you are given n ropes of different lengths, you need to connect these ropes into...

    Suppose you are given n ropes of different lengths, you need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. You want to find the minimum cost way to do this. For example: Suppose you have three ropes with lengths 2, 5, and 8. If you chose first to connect the length 5 and 8 ropes, then connect the length 2 and 13 ropes, the total cost would be...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT