GATE CS 2008 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0124

The subset-sum problem is defined as follows. Given a set of n positive integers, S={\(a_{1},a_{2},...,a_{n}\)} and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this problem uses a 2-dimensional Boolean array, X, with n rows and W+1 columns. X[i,j], \(1\leq i\leq n\), \(0\leq j \leq W\), is TRUE if and only if there is a subset of {\(a_{1},a_{2},...,a_{i}\)}whose elements sum to j. Which of the following is valid for \(2\leq i\leq n\) and \(a_{i} \leq j \leq W\)?
  1. A
    \(X[i,j]=X[i-1,j]\vee X[i,j-a_{i}]\)
  2. B
    \(X[i,j]=X[i-1,j]\vee X[i-1,j-a_{i}]\)
  3. C
    \(X[i,j]=X[i-1,j]\wedge X[i,j-a_{i}]\)
  4. D
    \(X[i,j]=X[i-1,j]\wedge X[i-1,j-a_{i}]\)

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionOfficial GATE Answer Key: Option B.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/498/gate2008-80

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com