Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started