Algorithms: Sequential, Parallel and Distributed, Second Edition 7-5
Section 7.3 The Knapsack Problem
7.6 For a knapsack of capacity C = 1, consider the three objects whose value, weight pairs (v,w)
are (5,5), (4,2) and (1,1). If you place the objects in the knapsack in decreasing order of
7.7 a) For a knapsack of capacity C = 6, consider the three objects whose value, weight pairs
(v,w) are (8,4), (5,3) and (5,3). The greedy solution for the 0/1 knapsack problem would
place the first object into the knapsack, yielding the value of 8. On the other hand, the
optimal solution places the 2nd the 3rd object into the knapsack, yielding a value of 10.
b) Given any ε > 0, consider a knapsack of capacity C = 1, and two objects with profits p1 =
Section 7.4 Huffman Codes
7.8 We show that the Huffman tree is optimal by induction on the number of symbols (leaf
nodes in the tree).
sn-1. Assume without loss of generality that the symbols s0, s1, … , sn-1 are ordered by their
sn-1. Now suppose T is any optimal binary tree for the symbols s0, s1, … , sn-1. Consider two
leaf nodes at the deepest level of T. By interchanging (if necessary) these two leaf nodes
with leaf nodes containing s0, s1, respectively, we see that the value of WLPL does not
decrease. Hence, in particular, we can assume that there are optimal binary trees T having L