Question

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 of change we are asked to make
The algorithm should return an array C where C[i] is the number of coins of value V[i] to return as change and m the minimum number of coins it took. You must return exact change so

71
The objective is to minimize the number of coins returned or:


a) Describe and give pseudocode for a dynamic programming algorithm to find the minimum number of coins to make change for A.
b) What is the theoretical running time of your algorithm?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

a)

M(j) = the minimum number of coins required to make change for an amount of money j

                         M(j) = min{M(j − vi )} + 1

The smallest number of coins required to make j , is the smallest number required to make j − vi , plus one.

Algorithm Minimum-Change(C,v)

   //all of vi and C are positive integers.

   Input: n types of coin denominations of values v1 < v2 < ... < vn

Output: The minimum number of coins required to make change for an amount of money j

       M[0]ß0

        {M[j]← ∞ where i<0}

    for jß1 to C do

          Min← ∞

          for iß1 to |V| do

              if M[j-v[i]] +1< min then

                    minßM[j-v[i]] +1

              end if

           end for

                  return M[C]

   end for

b)

The theoretical running time of the above algorithm is O(n * A)

Please provide your valuable feedback.

Add a comment
Know the answer?
Add Answer to:
Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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....

  • The post office sells stamps of a variety of different denominations (values), and different sizes. Consider...

    The post office sells stamps of a variety of different denominations (values), and different sizes. Consider a set of n stamps, where each stamp i has a specific denomination di and a size si . All denominations are distinct. All input numbers are positive integers. We can use stamp denominations multiple times. When buying stamps that total to a given postage amount P, we want to minimize the total size of the stamps (to leave the most addressing space on...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

  • 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.

  • Consider the problem of finding change using as few coins as given coins: lc, 2c, 5c....

    Consider the problem of finding change using as few coins as given coins: lc, 2c, 5c. The goal is to determine the minimum number of coins that add up possible. Formally we are input non-negative integer n, and we have unlimited quantities of 3 types of as a. to nc. Your task is to design programming (a) [6 marks] Clearly define your DP states (subproblems) O(n) time algorithm for solving this problem using dynamic an (base and recursive cases) (b)...

  • 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...

  • In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maxim...

    In a Knapsack problem, given n items {I1, I2, · · · , In} with weight {w1, w2, · · · , wn} and value {v1,v2, ···, vn}, the goal is to select a combination of items such that the total value V is maximized and the total weight is less or equal to a given capacity W . i-1 In this question, we will consider two different ways to represent a solution to the Knapsack problem using . an...

  • 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....

  • 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...

  • Given a value V in cents, you need to make change using a minimum number of...

    Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply of quarters, nickels, dimes, and pennies. Find the minimum number of coins. Display the quantity of each coin and the total number of coins, similar to the example output below. Use global constant identifiers, of type unsigned int, for the values of quarters, nickels, dimes, and pennies. Example: const unsigned int QUARTER = 25: Do not use...

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