Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Title: Subset Sum Problem Find all subsets S1, S2, S3, ...., Sn for a given set

ID: 3775775 • Letter: T

Question

Title: Subset Sum Problem Find all subsets S1, S2, S3, ...., Sn for a given set S = { e1, e2,......, en} of n positive integers whose sum is equal to a positive integer D. For an example, S={2, 6, 8, 5, 1, 10} and D = 9, there are two subsets (solutions): S1={2, 6, 1} and S2={8, 1}.   In our search tree, every path from root node to ithlevel represents a subset of S. If sum of the element values that are included in a path is equal to D, then we have a solution to the problem. If the subset sum becomes greater than D, then we should not further explore that path (pruning!!). Any Java code to accomplish this would be appreciated!

Explanation / Answer

#include int n, d, w[10], x[10], count=0; void subset(int cs, int k, int r) { int i; x[k] = 1; if(cs + w[k] == d) //if the first element is equivalent to the sum that is required { std::cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote