liveBook · Manning

Capacity

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

Knapsack capacity is the maximum total weight that the selected items may occupy.

Capacity is the maximum total weight that selected items may occupy. In the 0/1 knapsack problem, each item is either taken once or left behind; no item may be split. section 8.1

Dynamic programming treats capacity as a sequence of subproblems. A table evaluates capacities from 0 through the limit for progressively larger sets of items, avoiding the exponential cost of checking every subset. section 8.1

A three-pound capacity

For a 3 lb. knapsack, the table compares capacities 0, 1, 2, and 3. With Matches, Flashlight, and Book, the best values are 0, 15, 20, and 25 respectively. section 8.1

Figure 8.1. The robber must carefully decide what items to steal because the capacity of the knapsack is limited.

Use the figure to visualize capacity as the limited space forcing a choice among competing items. section 8.1

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines capacity and develops it as a linear dynamic-programming dimension, stopping short of formal proof.
Examples
Uses a three-item table and a robber’s 75-pound selection of household items to demonstrate capacity choices.
What it assumes
Assumes item weights and values while developing the capacity-based table incrementally.
What you can do after
Apply capacity as the limit in a Swift knapsack function and recover the selected items.
How it connects
Connects capacity with dynamic programming, memoization, powersets, and the 0/1 knapsack problem.

Also explained in

Compare how 5 books explain capacity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.