• edited by
15,995 views
40 40 votes

The subset-sum problem is defined as follows. Given a set of $n$ positive integers, $S = \{ a_1, a_2, a_3, \dots , 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 $\text{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, \dots, a_i\}$ 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]$

4 Answers

Best answer
28 28 votes

ANSWER is C.

If LAST ROW and LAST COLUMN entry is $1$, then there exists a subset whose elements sum to $W$.

• edited by
1 1 vote
The answer should be A, C.

The recerruence of subset problem is: X[i,j] = X[i-1,j] or X[i-1, j-ai]. From this it is very clear that X[n,W](which repersents the existence of a subset with sum to W) is always true if X[i,W] is true for any 0 < i < n.

Hence Option A implies Option C. Both are correct answers.
Answer:
Position:
Show:

Related questions

74 74 votes
4 answers 4 answers
35.9k
35.9k views
Kathleen asked Sep 12, 2014
35,855 views
Which of the following are NOT true in a pipelined processor?Bypassing can handle all RAW hazardsRegister renaming can eliminate all register carried WAR hazardsControl h...
61 61 votes
6 answers 6 answers
18.2k
18.2k views
Kathleen asked Sep 12, 2014
18,242 views
The subset-sum problem is defined as follows. Given a set of $n$ positive integers, $S = \{ a_1, a_2, a_3, \dots , a_n \}$, and positive integer $W$, is there a subset of...
30 30 votes
3 answers 3 answers
11.8k
11.8k views
go_editor asked Apr 23, 2016
11,789 views
Consider the following C program that attempts to locate an element $x$ in an array $Y[ \ ]$ using binary search. The program is erroneous. f (int Y[10] , int x) { int i,...
43 43 votes
6 answers 6 answers
22.0k
22.0k views
go_editor asked Apr 23, 2016
21,955 views
Consider the following C functions:int f1 (int n) { if(n == 0 || n == 1) return n; else return (2 * f1(n-1) + 3 * f1(n-2)); } int f2(int n) { int i; int X[N], Y[N], Z[N];...