Problem Solving

Knapsack Problem

An open backpack sits next to items of different sizes.

Knapsack Problem definition

The 0–1 knapsack problem chooses whole items to maximize total value without exceeding a capacity.

In Spanish
problema de la mochila
Topic
Optimization and decision models

Knapsack Problem in a picture

Knapsack Problem diagramA capacity of 5 can hold two items of weights 2 and 3, whose values are added.Capacity: 5The total selected weight must fitChoose weights 2 and 3Their combined weight is 5Add their valuesCompare this total with other feasible choices
A capacity of 5 can hold two items of weights 2 and 3, whose values are added.

How it works

Each item has a weight and a value. A binary decision selects or omits it. Add the selected weights to test capacity, and add their values to compare feasible choices. In the fractional variant, parts of an item can be selected.

Worked examples

Items have weights 2, 3, 4 and values 3, 5, 6. What is best with capacity 5?

Choose weights 2 and 3 for value 8.

Can the items of weights 3 and 4 fit together?

No. Their weight is 7.

Can you take half of an item in the 0–1 problem?

No. A binary choice takes the whole item or omits it.

Common mistake

The highest individual value or value-to-weight ratio may fail to give the best 0–1 combination.

Quick check

With capacity 5, which set of weights fits exactly?

What is maximized?

Show answer

Total selected value.

How many times can a given item be taken in the 0–1 version?

Show answer

At most once.

Sources

Flashcard

Knapsack Problem

Reveal the definition

The 0–1 knapsack problem chooses whole items to maximize total value without exceeding a capacity.

Effortless Math. “Knapsack Problem.” Math Dictionary.