computation

Definition

Max-Value Knapsack Problem

The max-value knapsack problem is a maximisation problem:

Given items , where each has a positive integer value and size , and a knapsack size , find a subset of items whose size is bounded by and total value maximised.

Approaches

For a subset of items, write

Greedy Highest Value per Size First

Greedy Highest Value per Size First

Repeatedly add a remaining item with maximum value-to-size ratio

as long as the size bound is not exceeded.

Greedy by value-to-size ratio is not optimal

Let the knapsack size be . Consider the following items.

item value size ratio

Sorting by ratio yields

The greedy construction is then:

  • choose , so the used size is and the value is ;
  • does not fit, since ;
  • does not fit, since ;
  • choose , so the used size is and the value is ;
  • choose , so the used size is and the value is .

Hence greedy returns

with value .

But

is feasible because , and it has value .

Therefore this greedy strategy is not always an optimal solution for the max-value knapsack problem.

Best-of-Two Approach

Best-of-Two Approach

Sort the items by decreasing ratio . Let be the smallest index with

Define

Return the more valuable of and .

[!intuition] Visual idea

After sorting by ratio, contains the longest prefix that still fits, while is the first single item that would make the prefix overflow.

Approximation guarantee

The best-of-two approach is a factor- approximation algorithm.

and at most a fraction of . Hence its value is at most

Every integral solution is also feasible for the fractional relaxation, so

Therefore at least one of and has value at least , and returning the better of the two gives the claimed approximation ratio.

Polynomial-time Approximation Scheme

ModGreedyKnapsack

Fix and let

Enumerate every subset of at most items.

For each feasible choice of , greedily fill the remaining capacity with items from in decreasing order of value-to-size ratio. Let be the set of greedily added items.

Return the set

of maximum value over all branches.

[!intuition] Visual idea

The PTAS first guesses a small set of at most items, then fills the remaining capacity greedily with a set .

PTAS guarantee

ModGreedyKnapsack is a PTAS for the max-value knapsack problem.

be an optimal solution. If , then one branch guesses , so the algorithm returns an optimal solution.

Now assume . Consider the branch in which is chosen as the most valuable items of . Let the remaining items of be ordered by decreasing ratio, and let be the first of them that the greedy completion does not take.

Let be the items added by greedy that are not in . The items of missing from all have ratio at most , while the items in have ratio at least this large. Moreover, when is first rejected, the remaining capacity is smaller than . Hence

Since contains the most valuable items of , the solution contains at least items of value at least . Therefore

so

Combining both inequalities gives

Because , we obtain

The algorithm checks branches, and each branch performs only polynomial work. For fixed , this is polynomial in the input size. Hence the algorithm is a PTAS.

Better schemes

The exponent still depends on . By scaling values and using dynamic programming, one can obtain a fully polynomial-time approximation scheme.