1. Engineering
  2. Computer Science
  3. pick a random set of 10 integers ranging from 3...

Question: pick a random set of 10 integers ranging from 3...

Question details

Notation: If L is a list of positive integers from S (i.e. a sub-list) and x is member of S, then we let L+x denote the augmented sub-list derived from L by adding (i.e., appending) x to the set L For example, if L = {4, 1, 7} then L + 2-4, 1,7, 2} sum(L) wll mean the sum of elements in set L. So, sum(14,1,7-12 Col will be some collection of sub-lists. For example, if S-(4, 1,7), Col might be (0,(4, 1), (4,7))(we count the empty subset, as a list in the collection if we want it there). An exact, but not particularly fast, algorithm to find the subset L with the sum(L) as large as possible but less than or equal to t is as follows: Initialize the collection Col with one sub-list: the empty sub-list. ·Loop over all elements x in S Loop over all subsets, L, that are already members of Co if sum(L)+xs t, add the sub-list L +x to Col - if sum(L)+xt, break from both loops! Of all the subsets that end up in Col, find the sub-list L with the largest sum) The set L in the last step is the subset which has the largest sum, without going over the target, t.

Pick a random set of 10 integers ranging from 3 to 20. Use the algorithm above to Solve the subset sum problem for your set and the target 37. JAVA

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution