AlgoFrames

Why iterate in reverse

Warm-up · Multiple choice · about 3 min

One-row 0/1 knapsack updates dp[c] = max(dp[c], dp[c − w] + v) with c running from capacity down to w.

Why must c go downwards?

Learn the idea first: Space optimization: rolling rows and variables, a visual lesson.

More Space optimization: rolling rows and variables problems