Approximation Algorithms for Knapsack Problems Tsvi Kopelowitz 1
Approximation Algorithms for Knapsack Problems Tsvi Kopelowitz 1
Knapsack Given: a set S of n objects with weights and values, and a weight bound: ◦ w 1, w 2, …, wn, B (weights, weight bound). ◦ v 1, v 2, …, vn (values - profit). Find: subset of S with total weight at most B, and maximum total value. Problem is known to be NP-hard 2
Assumptions . . Values, weights, and bound are all integers. Note: This is a maximum problem. Define: OPT = The optimal solution. We will see a ½ approximation for two versions of knapsack. 3
Uniform Knapsack (value=weight) ½-approximation algorithm: ◦ Sort the items such that v 1 ≥ v 2 ≥ … ≥ vn. ◦ Pick such that. and 4
Uniform Knapsack Claim: . Proof: ◦ Assume (by contradiction): . ◦ => =>contradiction. (Since items were sorted) . 5
½-approximation (general knapsack) Define: Sort Pick items such that r 1 ≥ r 2 ≥ … ≥ rn. such that. and If( ) return else return A. 6
½-approximation (general knapsack) Claim: Proof: Consider fractional knapsack – the optimal solution is A’= A and a fraction of vj+1. ◦ ◦ . . ◦ 7
A DP algorithm for knapsack A 1 2 3 j n vmax Upper bound on optimal profit i n A(i, j) = Smallest weight subset of objects 1, …, i with a total value of j. 8
A DP algorithm for knapsack The result is: max j such that A(n, j) ≤ B. The runtime is: O(n 2 vmax) Pseudo-polynomial 9
Definitions Definition: Pseudo-polynomial If input of integers is given in unary form, runs in polynomial time. Definition: Fully Polynomial Time Approximation Scheme (FPTAS) Given ε, delivers a solution with a ratio of (1 - ε) for maximum and a ratio of (1+ ε) for minimum, and runs in time polynomial in the size of the input and (1/ε) 10
FPTAS for knapsack The Idea – use scaling!! Given error bound For each object i, define . . Use DP to find optimal solution OPT’ for the rounded values. Return the set OPT’ with the original values. 11
Correctness Claim: Proof: For every i: . (1) => (3) (2) (4) 12
Correctness Proof continued: (1) (3) (2) (4) � 13
Complexity and Notes Time: algorithm is a FPTAS. 14
- Slides: 14