GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 80

Subset-sum dynamic-programming recurrence

Algorithms · Dynamic Programming · Full GATE CSE 2008 paper

GATE 2008, Q80 2 marks · MCQ
Report issue

Dynamic Programming

Question 80, GATE 2008: Given positive integers S={a₁,…,aₙ} and target W>0, a subset-sum dynamic program uses Boolean X with n rows and W+1 columns. X[i,j] is true iff some subset of {a₁,…,aᵢ} sums to j, for 1≤i≤n and 0≤j≤W. Which recurrence is valid for 2≤i≤n and aᵢ≤j≤W?

(A) X[i,j]=X[i−1,j]∨X[i,j−aᵢ]
(B) X[i,j]=X[i−1,j]∨X[i−1,j−aᵢ]
(C) X[i,j]=X[i−1,j]∧X[i,j−aᵢ]
(D) X[i,j]=X[i−1,j]∧X[i−1,j−aᵢ]
Question 80, GATE 2008: Given positive integers S={a₁,…,aₙ} and target W>0, a subset-sum dynamic program uses Boolean X with n rows and W+1 columns. X[i,j] is true iff some subset of {a₁,…,aᵢ} sums to j, for 1≤i≤n and 0≤j≤W. Which recurrence is valid for 2≤i≤n and aᵢ≤j≤W?

(A) X[i,j]=X[i−1,j]∨X[i,j−aᵢ]
(B) X[i,j]=X[i−1,j]∨X[i−1,j−aᵢ]
(C) X[i,j]=X[i−1,j]∧X[i,j−aᵢ]
(D) X[i,j]=X[i−1,j]∧X[i−1,j−aᵢ]
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Consider whether the chosen subset contains aᵢ. If not, the first i−1 elements alone must sum to j, represented by X[i−1,j].
2. If aᵢ is included, remove it once; the remaining subset of the first i−1 elements must sum to j−aᵢ, represented by X[i−1,j−aᵢ].
3. Either alternative suffices, so combine with OR, giving B. Using row i in the second term allows repeated copies of aᵢ; AND incorrectly requires both choices.

Original paper, page 17