The subset-sum problem is defined as follows. Given a set of positive integers, , and positive integer , is there a subset of whose elements sum to ? A dynamic program for solving this problem uses a Boolean array, , with rows and columns. , is TRUE, if and only if there is a subset of whose elements sum to .
Which of the following is valid for , and ?
View worked solution
Answer: B
To find the recurrence relation for , we analyze the choices available for the element when trying to form a subset of the first elements, , that sums to :
-
Exclude :
If we do not include in the subset, we must form the sum using only the first elements.
This is possible if and only if:
-
Include :
If we include in the subset (which is allowed since ), the remaining sum to be formed is . This remaining sum must be formed using the first elements.
This is possible if and only if:
Since the subset-sum problem allows each element to be chosen at most once, and the overall problem is solvable if either of the two choices is successful, we combine them using the logical OR () operator:
Thus, Option B is the correct recurrence relation.
Free practice · Your answers on this page are not saved.
