Let
- a fixed
, - a finite set of items
, - a size function
, - a value function
, and - a knapsack capacity of
.
Consider the following algorithm
- Enumerate all
of at most size , i.e., enumerate all combinations. - Discard the branch if
. Otherwise, scan the items in in descending order of the ratio and add an item whenever it fits, i.e., whenever . The set of those greedily-selected items is denoted by . - Each branch constructs a (possibly non-optimal) solution
. - At the end, choose an
of highest value.
To prove that the described algorithm is a PTAS, we have to show the following two properties:
. , with being the running time.
Approximation guarantee
Let
: The branch is enumerated. Its candidate has value at least , so the algorithm outputs an optimal solution. : The optimal solution isn’t fully covered by the all-enumeration, which requires special treatment.
Consider the branch in which
where
How does
- Optimal items: Items from
that were selected before . - Missed items: Items from
that were not selected before . In particular, . - Non-optimal items: Items outside
that were selected before .
The first missed optimal item
Let
Consider the missing items first. Since
Equivalently:
Therefore, we found an upper bound for the first term already:
Next, we want to find a lower bound for
Equivalently,
Therefore:
Equivalently:
Putting them together yields
What’s
Hence, we can infer from the feasibility of
Equivalently:
The right-hand side is precisely the free capacity immediately before
The two knapsacks below compare the same shared prefix
Therefore,
It remains to relate
Equivalently,
The reason for the denominator
Putting both bounds together yields
By the choice
Consequently,
Since the algorithm returns the most valuable candidate among all enumerated branches, its output has at least the value of this particular
which proves the approximation condition.
Running-time
The density order can be computed once and reused by every branch. Sorting the
The number of enumerated subsets is
For each subset
Consequently,
For every fixed
is constant with respect to the input. Moreover,
so the running time simplifies to
Since
and obtain
Arithmetic on binary-encoded sizes and values contributes only another factor
Thus, for every fixed