AlgoViz

Unbounded knapsack

medium 20 min

The knapsack where every item can be taken as many times as you like.

Where it shows up

The same pattern appears across everyday software.

  • Making change and cash dispensing

    ATMs, vending machines and point-of-sale systems pay out an amount using unlimited coins or notes of fixed values. For standard currencies greedy works, but for unusual denominations, or when some dispensers are cheaper to use, the coin change table gives the true minimum.

  • Cutting stock and rod cutting

    Steel bars, timber, paper rolls and cable are cut from standard lengths into pieces with different prices or demands. Choosing how to cut one stock length to maximise value is the unbounded knapsack over piece lengths, and it is the inner step of the column-generation method for the full cutting-stock problem.

  • Filling a budget with repeatable purchases

    Ad slots, cloud instance types or bulk packaging sizes can be bought any number of times. Picking the mix that maximises value under a fixed budget, or reaches an exact quantity with the fewest packages, is the same table.

  • Counting compositions in combinatorics

    How many ways a number can be written as a sum of allowed parts (partitions with restricted parts) is coin change II. The ordered version counts compositions and is the climbing-stairs recurrence with more step sizes.

  • Resource packing in schedulers

    Fitting repeated jobs of a few standard sizes into a time window or a machine's memory, to maximise throughput or reward, is an unbounded knapsack when each job type can be run again.