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)
- For i 1 to n
- Do c[i] infinity
- For j 1 to k
- Do if i>=d
- Then if 1+c[i-dj]
- Then c[i] 1+c[i-dj]
- Denom[i] dj
- 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
Get step-by-step solutions from verified subject matter experts
