Next: Dynamic Programming for 0-1 Up: CSE 2320: Algorithms and Previous: Dynamic Programming for Activity

# 0-1 Knapsack Problem

• The thief wants to steal n items
• The ith item weighs wi and has value vi
• Take the most valuable load, limit of W pounds
• This is called the 0-1 version of the problem because there are no fractions.
The thief must take the whole item or leave it behind.
• Both the 0-1 Knapsack Problem and the Fractional Knapsack Problem have optimal substructure. If we remove item j from the optimal load, the remaining problem must be optimal for the remaining W - wj pounds for the overall solution to be optimal.
• The greedy solution for the Fractional Knapsack Problem work here.

Example:

 Item Value Weight Val/Weight 1 60 10 6 2 100 20 5 3 120 30 4

W = 50

The greedy solution would select 1, leaving 40 pounds.

At this point if we pick items 1 and 2 the total value is 160.

If we pick items 1 and 3 the total value is 180.

The optimal solution is to pick items . The total value of this solution is .

Next: Dynamic Programming for 0-1 Up: CSE 2320: Algorithms and Previous: Dynamic Programming for Activity