Problem setup
- A knapsack of capacity
W, andnitems with weightsw₁…wₙand valuesv₁…vₙ3:45. - Goal: pick a subset with total weight ≤
Wmaximizing total value3:45.
The starting point: pseudo-polynomial DP
- There is an exact dynamic program running in
O(nV), whereV = Σᵢ vᵢ4:28,4:58. - This is not polynomial time: the running time depends on the magnitude of the numbers, not their bit-length. Writing
Vtakes onlylog Vbits, so the input can be exponentially smaller thanV4:58. - Fix: make
Vsmall by rounding5:17,3:14.
The algorithm
- Define rounded values
vᵢ′ = ⌊ (n/ε) · vᵢ / v_max ⌋— i.e. scale byα = n / (ε·v_max)and floor to an integer5:17,5:47. - Run the exact
O(nV′)DP on the rounded instance; it returns a setA5:47. - Output
Aas the solution to the original instance6:16.
Running-time bound
V′ ≤ n · maxᵢ vᵢ′, and sincevᵢ ≤ v_max, eachvᵢ′ ≤ n/ε6:41.- So
V′ ≤ n²/ε, giving total timeO(nV′) = O(n³/ε)— polynomial in bothnand1/ε, hence an FPTAS6:41.
Why the value is preserved
- Pure scaling by a constant changes nothing: every set's value scales by the same factor, so the optimum is unchanged
8:36. - The floor is the only source of loss: each item loses at most 1 unit of rounded value, so any set
Sloses at most|S| ≤ n8:17,9:00. OPT′ ≥ v′_max ≥ n/ε, because the item achievingv_maxalone contributes that much7:20,7:47.- Hence the loss of at most
nis at mostε · OPT′9:00.
Formal claim and proof sketch
Claim. If the DP on the rounded instance returns A ⊆ [n], then v(A) ≥ (1 − ε)·OPT for the original valuation 9:34.
Key inequalities, for every set S and scaling factor α = n/(ε·v_max) 10:13, 10:48:
α·v(S) − |S| ≤ v′(S) ≤ α·v(S)
Chain of the proof, with A* an optimal set for the original instance 10:48, 11:34:
v(A) ≥ (1/α)·v′(A)— from the upper inequality11:34.≥ (1/α)·v′(A*)—Ais optimal for the rounded values11:51.≥ (1/α)·(α·v(A*) − |A*|) = OPT − |A*|/α ≥ OPT − n/α11:51,12:32.n/α = ε·v_maxby definition ofα, andOPT ≥ v_max, so the result is≥ (1 − ε)·OPT13:14.