Question: Design a dynamic programming algorithm to solve the sum of subsets problem: There are n positive integers, p 1 , p 2 , . .
Design a dynamic programming algorithm to solve the sum of subsets problem:
There are n positive integers, p p pn and a positive integer sum S Is there a subset A of the n integers A p pn such that the sum of the integers in the subset is SpiApiS If there is such a subset the output of the program is true otherwise it is false.
Example: p p p and S In this case the output is true since p p
Example: p p p and S In this case there is no solution, and the output is false.
The problem can be solved with dynamic programming.
A Boolean matrix B with rows to n and columns to S is generated. For the examples above the matrix has rows to and columns to
Bi s is true if a subset of the first i integers sums to s otherwise it is false.
The solution to the original problem is true if Bn S true, otherwise it is false.
Write the recurrence relation for the solution.
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
