{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

t6ans - CS3230 Tutorial 6 1 Consider the greedy algorithm...

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

CS3230 Tutorial 6 1. Consider the greedy algorithm for coin-change problem. Suppose the coin denominations are d 1 > d 2 > . . . > d n = 1. Suppose that d i +1 is a factor of d i , for 1 i < n . Then, show that the greedy algorithm is optimal. Ans: (i) Due to the constraint given in the problem, in the optimal algorithm, one has < d i /d i +1 coins of denomination d i +1 . (ii) Fact (i) implies that sum of values of coins of denomination d j , j > i , is < d i . (This can be shown by induction) (iii) Using (ii), it follows that the greedy algorithm and optimal algorithm must have the same number of coins of each denomination. 2. (a) Suppose we modify the greedy algorithm for fractional knapsack problem to con- sider the objects in order of “non-increasing” value (rather than non-increasing ratio of value/weight as done in class). Is the modified algorithm still optimal? If so, give an argument for its optimality. If not, give a counterexample. Ans: No. Counterexample: item 1: value=5, weight = 10 item 2: value=4, weight = 5 item 3: value=4, weight = 5

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

t6ans - CS3230 Tutorial 6 1 Consider the greedy algorithm...

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

View Full Document
Ask a homework question - tutors are online