Algorithms

Knapsack problem

Choosing which items, each with a weight and a value, to put in a knapsack of limited capacity so the total value is as high as possible.

Example

With capacity 4 and items of weight 1, 2 and 3 worth 5, 11 and 15, the best is to take the weight-1 and weight-3 items: value 20.

Test yourself: Knapsack problem

0-1 knapsack

It is called 0-1 knapsack because each item is taken 0 or ___ time.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.