COP3530 Recitation Exercises 3/11/03

advertisement
COP3530 Recitation Exercises 3/11/03
(all taken from the text ppg 282-3, with slight modifications)
1) (C-5.10) Solve the subset-sum problem using recursion. If you are given an array A of
size n, determine if any subset of the values in that array add up to a given target T. (The
solution to this problem can be found at the CS2 website. It is part of the solution for
homework assignment #3.) A java prototype for the method to solve this problem is
below:
public static boolean subsetSum(int [] values, int target);
// Returns true if a subset of the values in the array adds up to target only using values
// in the array from index startindex or higher.
public static boolean subsetSumHelp(int[] values, int target, int startindex);
2) (C-5.10) Using the recursive solution in question 1, solve the subset sum problem
using dynamic programming. The total time used should be O(nT). Just use the first
prototype listed above here.
Download