Question: What is the corresponding dynamic program in c language that uses the following pseudocode? Make-Change(d,n) For i 1 to n Do c[i] infinity For j

What is the corresponding dynamic program in c language that uses the following pseudocode?

Make-Change(d,n)

  1. For i 1 to n
  2. Do c[i] infinity
  3. For j 1 to k
  4. Do if i>=d
  5. Then if 1+c[i-dj]
  6. Then c[i] 1+c[i-dj]
  7. Denom[i] dj
  8. Return c and denom

Line 8 returns two arrays c and denom. c[n] gives the minimum number of coins require to represent the n cents. Using denom and tracing the array backward from the index n, the denominations of the coins used to represent the n cents, can be obtained.

The outer for loop runs n times and the inner for loop runs k times, so the total running time is O(nk).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!