Multiple choice

The subset-sum problem is defined as follows. Given a set of n positive integers, S = {a1, a2, a3, …, an}, 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$\le$i $\le$ n,0 $\le$j $\le$ W, is TRUE if and only if there is a subset of {a1, a2, …, a} whose elements sum to j.

Which entry of the array X, if TRUE, implies that there is a subset whose elements sum to W?

  1. X[1, W]

  2. X[n, 0]

  3. X[n, W]

  4. X[n - 1, n]

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation