CS3230
Tutorial 6
1. Consider the greedy algorithm for coinchange 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 “nonincreasing” value (rather than nonincreasing 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.
 Fall '10
 sanjay
 Algorithms, Dynamic Programming, Greedy algorithm, David A. Huffman

Click to edit the document details