title: Applying Recursion for Subset Sum
body: <p>I'm trying to make a code that adds all the integers in a subset to see if they add up to zero. Here's what I've got so far </p>
  
  <pre><code>  /**
     * Solve the subset sum problem for a set of integer values.
     * 
     * @param t
     *          a set of integer values
     * @return &lt;code&gt;true&lt;/code&gt; if there exists a non-empty subset of
     *         &lt;code&gt;t&lt;/code&gt; whose elements sum to zero.
     */
    public static boolean subsetSum(Set&lt;Integer&gt; t) {
      return subsetSum(new ArrayList&lt;Integer&gt;(t), null);
    }
  
    /**
     * Computes the sum of two Integers where one or both references are null. If
     * both references are null then the result is null; otherwise the result is
     * an integer equal to &lt;code&gt;a + b&lt;/code&gt; where null references are treated as
     * being equal to zero.
     * 
     * @param a
     * @param b
     * @return the sum of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;
     */
    private static Integer add(Integer a, Integer b) {
      if (a == null &amp;&amp; b == null) {
        return null;
      } else if (a == null) {
        return b;
      } else if (b == null) {
        return a;
      }
      return a + b;
    }
  
    /**
     * Recursive solution for the subset sum problem.
     * 
     * &lt;p&gt;
     * &lt;code&gt;currentSum&lt;/code&gt; holds the value of the subset under consideration;
     * it should be &lt;code&gt;null&lt;/code&gt; if the current subset is empty.
     * 
     * @param t
     *          a list containing unique integer values (a set of integers)
     * @param currentSum
     *          the current subset sum so far
     * @return &lt;code&gt;true&lt;/code&gt; if there exists a subset of &lt;code&gt;t&lt;/code&gt; such
     *         that the sum of the elements in the subset and
     *         &lt;code&gt;currentSum&lt;/code&gt; equals zero.
     */
  
  ******** THIS IS THE PART I HAD TO EDIT *************
    private static boolean subsetSum(List&lt;Integer&gt; t, Integer currentSum) {
        currentSum = 0;
        for (int i = 0; i &lt; t.size(); i++) {
            currentSum = currentSum + (Integer)(t.get(i));
        }
        if (Lab9W.add(currentSum, t.get(0)) == 0) {
            return true;
        }
        else if (Lab9W.add(currentSum, t.get(1)) == 0) {
            return true;
        } else if (Lab9W.add(-t.get(0),t.get(0)) == 0) {
            return true;
        }
        else {
            return false;
        }
  
    }
  
  }
  </code></pre>
  
  <p>here what tip I have received about making this code : </p>
  
  <blockquote>
    <p>consider the first element of the set first is there a subset sum of
    zero with first and the rest of the set? is there a subset sum of zero
    without first and the rest of the set? if either of 2 or 3 is true
    then return true, otherwise return false</p>
  </blockquote>
  
  <p>Any help please I've been trying all day i can not get it to work for the life of me, well in recursion i cant figure out how to call the method on itself.</p>
  
  <p>So my question is how would I write this method in recursion? The whole method is supposed to add the sum of subsets and see if they equal to zero.</p>