Dynamic Programming with a Capacity: Knapsack · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Packing the best bag by table

Computing · Algorithms & Data Structures · ages 20-22
Name ______________________   Date ____________
  1. What question does each cell answer?

    • Buy or sell the shop
    • Paint the bag red
    • Take this item or skip it
  2. What is the knapsack table indexed by?

    • Item and remaining capacity
    • Color and brand
    • Price and shop name
  3. Why is the method called pseudo-polynomial?

    • It never finishes
    • It uses no tables
    • Its cost follows the numbers in the input
  4. Same items, capacity 5. Which items does the traceback take?

    • The third item alone
    • The first two items
    • All three items
  5. Weights 2, 3, 4 with values 3, 4, 5 and capacity 5. Give the best value.

    Answer: ______________

  6. The same item can be worth taking at one capacity and wrong at another.

    Circle one:   True   False

  7. Reading the corner value alone tells you which items were taken.

    Circle one:   True   False

  8. All weights double but items stay three. A friend says the work stays the same. What is wrong?

    • Nothing, counts decide alone
    • Doubled weights double the columns and the work
    • Tables shrink when numbers grow
LightMySky · lightmysky.comW1-mt_T5pbU_DpdC-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Packing the best bag by table W1-mt_T5pbU_DpdC-s1

  1. Take this item or skip it · Each cell compares taking against skipping at that capacity.
  2. Item and remaining capacity · Rows add items, columns track room left.
  3. Its cost follows the numbers in the input · Bigger weights mean more columns, even with the same item count.
  4. The first two items · Weight 5 exactly, value 7, which the corner confirms.
  5. 7 · Items one and two weigh 5 and value 7, beating any other fit.
  6. True · Room left changes the trade, which is why capacity is an axis.
  7. False · The corner gives the value; only the traceback names the items.
  8. Doubled weights double the columns and the work · Table size follows the numbers, so larger weights cost more.
Worksheet · LightMySky