t8ans - CS3230 Tutorial 8 1 Give an argument to show why...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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

Page1 / 3

t8ans - CS3230 Tutorial 8 1 Give an argument to show why...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online