This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS3230 Tutorial 8 1. Give an argument to show why dynamic programming algorithm gives optimal solution for coin changing problem. Ans: By induction on k , we show that C [ n k,j ] is optimal (that is, it gives the optimal number of coins using denominations d [ i ], i ≥ n k ). Clearly, for k = 0, C [ n,j ] is optimal, for j ≤ S . Suppose C [ n k + 1 ,j ] is optimal, for j ≤ S . We then show that C [ n k,j ] is optimal for j ≤ S , by induction on j . Clearly, this holds if j = 0. Suppose C [ n k,j ] is optimal for j ≤ m . Then, consider C [ n k,m +1]. Consider two cases, when optimal change contains d [ n k ] or not. In the first case, the optimal change contains 1 + C [ n k,m + 1 d [ n k ]] coins (by induction). In the latter case, the optimal change contains C [ n k + 1 ,m + 1] coins (by induction). As the algorithm chooses the minimal of these two cases, we have that C [ n k,m + 1] as the correct optimal answer....
View
Full
Document
 Fall '10
 sanjay
 Algorithms, C Programming

Click to edit the document details