Start learning →

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.
Practise this question with Quill — GATE CSE →

Keep practising Algorithms

Browse all Algorithms questions for GATE CSE, or explore more Computer Science topics.

Start a Algorithms lesson →
Related questions