The knapsack problem is a problem that asks “Given a set of items, each with a weight and a value, determine which items to include in the collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.” The 0-1 knapsack problem is a version of the knapsack problem where each item can only be added once.

Mathematical Representation

Mathematically put, the 0-1 knapsack problem is: Given a set of items labelled 1 to , where is the number of copies of the item, is the weight of the item, and is the value of the item, and is the weight limit of the knapsack,

Complexity Class

The 0-1 knapsack problem is NP-Complete, and so currently there are no known polynomial-time solutions to the problem.

Solutions

  • Brute force yields time complexity.
  • Dynamic programming yields the optimal solution in time, where is the number of items and is the backpack capacity.