Question: In Java Subsets of a set can be generated using a mask. A good description of the method is presented at http://compprog.wordpress.com/2007/10/10/generating-subsets/. The page also

In Java Subsets of a set can be generated using a mask.In Java

Subsets of a set can be generated using a mask. A good description of the method is presented at http://compprog.wordpress.com/2007/10/10/generating-subsets/. The page also contains a link to the code in C (sub.c) We will use subset generation in order to solve the following problem. Given a set of integers S and a number N, find all nonempty subsets of S whose sum is N. For example, given the set S-11,2, -1, 3} and the number N-3, there are three subsets of S whose sum is 3. The subsets are {1, 2) (since 1+2-3), {1, -1, 3} (since 1+(-1)+3-3), and {3) program should do the following 1) Prompt the user to enter the size of set S, elements of S, and the number N. Assume that Your the size of S is no more than 10. Store the elements of S in an array. 2) Generate all subsets of S using a mask. 3) For each nonempty subset generated in 2), compute the sum of elements in the subset. If the sum of elements in the subset is equal to N then output the subset. 4) Output total number of subsets of S that have the sum of elements equal to N. If none of the subsets of S have sum N, then output that they do not exist. Dialog with the user may look like the following: Please enter the size ofS: 3 Please enter S: 5 2 3 Please enter the number N: 5 Subsets with sum 5 23 There are 2 subsets with sum 5 Another example of Dialog with the user: Please enter the size of S: 4 Please enter Please enter the number N: 5 Subsets with sum 5: do not exist S: 10 20 30 40

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!