2. ANSWER EITHER THIS QUESTION OR QUESTION 3
Consider the problem of taking a set of n items with sizes s1,...,Sn, and values 1,..n respectively. We assume si,E N for all 1 i n. Suppose we are also given a knapsack capacity" C e N. The knapsack problem is the problem of finding a subset S {1,...,n} such that Lies Si C and such that Lies Ui is maximized subject to the first constraint. We write Pn,c to denote the value Lies ; of the maximum-value knapsack on the set of all items. For any k < n, and any C< C,C e Nwe can consider the same problem on the first k items in regard to capacity C. We denote the maximum-value knapsack for such a subproblem by P,c.
a) Prove that the following recurrence holds:
0
if k=0 if k>0 but sk>C
P-1,C
[10 marks] (b Use the recurrence above to develop a On C dynamic programming al- gorithm to compute the optimal knapsack wrt. the original n items and capacity C. Justify the O(n C) runtime of your algorithm. [15 marks]