35-7 An approximation algorithm for the 0-1 knapsack problem

Recall the knapsack problem from Section 16.2. There are nn items, where the iith item is worth viv_i dollars and weighs wiw_i pounds. We are also given a knapsack that can hold at most WW pounds. Here, we add the further assumptions that each weight wiw_i is at most WW and that the items are indexed in monotonically decreasing order of their values: v1โ‰ฅv2โ‰ฅโ‹ฏโ‰ฅvnv_1 \ge v_2 \ge \cdots \ge v_n.

In the 0-1 knapsack problem, we wish to find a subset of the items whose total weight is at most WW and whose total value is maximum. The fractional knapsack problem is like the 0-1 knapsack problem, except that we are allowed to take a fraction of each item, rather than being restricted to taking either all or none of each item. If we take a fraction xix_i of item ii, where 0โ‰คxiโ‰ค10 \le x_i \le 1, we contribute xiwix_iw_i to the weight of the knapsack and receive value xivix_iv_i. Our goal is to develop a polynomial-time 22-approximation algorithm for the 0-1 knapsack problem.

In order to design a polynomial-time algorithm, we consider restricted instances of the 0-1 knapsack problem. Given an instance II of the knapsack problem, we form restricted instances IjI_j, for j=1,2,โ€ฆ,nj = 1, 2, \dots, n, by removing items 1,2,โ€ฆ,jโˆ’11, 2, \dots, j - 1 and requiring the solution to include item jj (all of item jj in both the fractional and 0-1 knapsack problems). No items are removed in instance I1I_1. For instance IjI_j, let PjP_j denote an optimal solution to the 0-1 problem and QjQ_j denote an optimal solution to the fractional problem.

a. Argue that an optimal solution to instance II of the 0-1 knapsack problem is one of {P1,P2,โ€ฆ,Pn}\{P_1, P_2, \dots, P_n\}.

b. Prove that we can find an optimal solution QjQ_j to the fractional problem for instance IjI_j by including item jj and then using the greedy algorithm in which at each step, we take as much as possible of the unchosen item in the set {j+1,j+2,โ€ฆ,n}\{j + 1, j + 2, \dots, n\} with maximum value per pound vi/wiv_i / w_i.

c. Prove that we can always construct an optimal solution QjQ_j to the fractional problem for instance IjI_j that includes at most one item fractionally. That is, for all items except possibly one, we either include all of the item or none of the item in the knapsack.

d. Given an optimal solution QjQ_j to the fractional problem for instance IjI_j, form solution RjR_j from QjQ_j by deleting any fractional items from QjQ_j. Let v(S)v(S) denote the total value of items taken in a solution SS. Prove that v(Rj)โ‰ฅv(Qj)/2โ‰ฅv(Pj)/2v(R_j) \ge v(Q_j) / 2 \ge v(P_j) / 2.

e. Give a polynomial-time algorithm that returns a maximum-value solution from the set {R1,R2,โ€ฆ,Rn}\{R_1, R_2, \dots, R_n\}, and prove that your algorithm is a polynomial-time 22-approximation algorithm for the 0-1 knapsack problem.

(Omit!)