Question: Question 4 : Recall the problem Subset Sum which we solved in class using a dynamic programming algorithm. The problem was as follows: INPUT: set
Question :
Recall the problem Subset Sum which we solved in class using a dynamic programming algorithm. The problem was as follows:
INPUT: set dots, of nonnegative integers, positive integer OUTPUT: subset subeS such that or no solution" if no such exists. In English, the problem takes in a set of nonnegative integers and a positive integer and returns some subset of the set that sums to or no solution" if this is impossible We solved this problem with the following method:
The DP Steps for Subset Sum
a What values are we trying to compute in the table :
TRUE if there exists a subset subedots, such that
b What is the DPrelation:
is TRUE if:
Tij TRUE dont use OR
and TRUE use and some other numbers OR
use only
c How do we initialize the table:
TRUE
FALSE for all
d What do we return at the end:
Return
Subset Sum Pseudocode
TRUE
FALSE for
For to
For to
TRUE :
TRUE,
and TRUE
Else set FALSE
Else set FALSE
Return
We will now examine a related problem: Subset Sum of a specific size. The formal problem statement is as follows:
INPUT: set dots, of nonnegative integers, positive integer target size where is an integer in the range
OUTPUT: subset subS such that AND or FALSE if no such exists.
Example:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
