Concept
The knapsack family covers choosing items under a capacity: 0/1 (each item once), unbounded (any number of times) and subset sum. The same table, with the inner loop running in a different direction, handles each.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Knapsack patterns doing its job.
def knapsack_01(weights, values, capacity):
best = [0] * (capacity + 1)
for w, v in zip(weights, values):
for cap in range(capacity, w - 1, -1): # backwards: use once
best[cap] = max(best[cap], best[cap - w] + v)
return best[capacity]
def unbounded(weights, values, capacity):
best = [0] * (capacity + 1)
for w, v in zip(weights, values):
for cap in range(w, capacity + 1): # forwards: reuse
best[cap] = max(best[cap], best[cap - w] + v)
return best[capacity]Running the 0/1 inner loop forwards over capacity. Each item is then counted more than once, and you have quietly solved the unbounded problem instead.
Your roadmap puts these before Knapsack patterns, unless you already know them.
Once a session shows you understand Knapsack patterns, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.