title: Calculating Standard Deviation of Array Recursively
body: <p>My assignment is to use recursion to calculate the standard deviation of an Arraylist. I understand how to calculate standard deviation as I have done it without recursion I just need help implementing recursion. I would like to use a helper function if possible.</p>
  
  <p><strong>This is the recursive method and helper method i use to calculate the average:</strong></p>
  
  <pre><code>public static double calcAvg( ArrayList &lt;Integer&gt; list ) {
      double sum = calcSum(list, 0);
      return sum / list.size();
  }
  
  private static int calcSum( ArrayList &lt;Integer&gt; list, int i ) {
      if( i &lt; list.size() ){
          return list.get(i) + calcSum(list, i + 1);
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>This is my Standard Deviation method that needs recursion:</strong></p>
  
  <pre><code>public static double calcStd (ArrayList &lt;Integer&gt; list){
      int sum = 0;
      double average = calcAvg(list);
  
      for ( int i : list){
          sum += Math.pow((i - average), 2);
      }
      return Math.sqrt( sum / ( list.size() - 1 ));
  }
  </code></pre>
  
  <p><strong>Attempt:</strong></p>
  
  <pre><code>public static double calcStd( ArrayList &lt;Integer&gt; list){
      double avg = calcAvg(list);
      double sum = sumSquareDiffs(list, avg, 0);
      return Math.sqrt( sum / ( list.size() - 1 ));
  }
  private static double sumSquareDiffs(ArrayList &lt;Integer&gt; list, double avg, int i){
      if (i &lt; list.size()){
          return Math.pow((list.get(i) - avg), 2) + sumSquareDiffs(list, avg, i + 1);
      }
      return 0;
  }
  </code></pre>