A country has coins with k denominations 1 = d1 < d2 < ... < dk, and you want to make change for n cents using the smallest number of coins. For example, in the United States we have d1 = 1, d2 = 5, d3 = 10, d4 = 25, and the change for 37 cents with the smallest number of coins is 1 quarter, 1 dime, and 2 pennies, which are a total of 4 coins. To solve for the general case (change for n cents with k denominations d1 ... dk), we refer to dynamic programming to design an algorithm. 1. We will come up with sub-problems and recursive relationship for you. Let be the minimum number of coins needed to make change for n cents, then we have:   Explain why the above recursive relationship is correct. [Formal proof is not required]   2. Use the relationship above to design a dynamic programming algorithm, where the inputs include the k denominations d1 ... dk and the number of cents n to make changes for, and the output is the minimum number of coins needed to make change for n. Provide the pseudocode of your algorithm and briefly justify the runtime of your algorithm using big-O notation.   3.  Adapt your algorithm above by tracking some useful information during the DP procedure, so that it returns the actual method (i.e., the number of coins for each denomination) to change for n cents, not just the minimum number of denominations.

New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter14: Exploring Object-based Programming: Designing An Online Poker
Section14.1: Visual Overview: Custom Objects, Properties, And Methods
Problem 7QC
icon
Related questions
Question

A country has coins with k denominations 1 = d1 < d2 < ... < dk, and you want to make change for n cents using the smallest number of coins.

For example, in the United States we have d1 = 1, d2 = 5, d3 = 10, d4 = 25, and the change for 37 cents with the smallest number of coins is 1 quarter, 1 dime, and 2 pennies, which are a total of 4 coins.

To solve for the general case (change for n cents with k denominations d1 ... dk), we refer to dynamic programming to design an algorithm.

1. We will come up with sub-problems and recursive relationship for you. Let be the minimum number of coins needed to make change for n cents, then we have:

 

Explain why the above recursive relationship is correct. [Formal proof is not required]

 

2. Use the relationship above to design a dynamic programming algorithm, where the inputs include the k denominations d1 ... dk and the number of cents n to make changes for, and the output is the minimum number of coins needed to make change for n.

Provide the pseudocode of your algorithm and briefly justify the runtime of your algorithm using big-O notation.

 

3.  Adapt your algorithm above by tracking some useful information during the DP procedure, so that it returns the actual method (i.e., the number of coins for each denomination) to change for n cents, not just the minimum number of denominations.

C[n] =
(minimum{C[n
disn
0,
− d¡] + 1}, if n>0
if n = 0
Transcribed Image Text:C[n] = (minimum{C[n disn 0, − d¡] + 1}, if n>0 if n = 0
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Single source shortest path
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning