Practice free →
HomeGATE CSEcomputerscienceAlgorithms › The 0/1 knapsack recurrence (max value using fir…

The 0/1 knapsack recurrence (max value using first i items, capacity c) is

AK[i][c] = K[i-1][c-w_i]
BK[i][c] = K[i-1][c] + v_i (always take)
CK[i][c] = max(K[i-1][c], v_i + K[i-1][c - w_i])
DK[i][c] = K[i][c-1] + K[i-1][c]
Answer & Solution
Correct answer: C. K[i][c] = max(K[i-1][c], v_i + K[i-1][c - w_i])
Each item has two options: skip (value unchanged) or take (gain v_i, capacity drops by w_i). The recurrence is the max of the two: K[i][c] = max(K[i-1][c], v_i + K[i-1][c - w_i]), only taking when w_i ≤ c. Always-taking ignores capacity overflow; the other forms confuse table dimensions.
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions