title: How to adress elements of a recursive function?
body: <p>Take a recursive function, say:</p>
  
  <pre><code>public static long rekurs(long n) {
      if (n == 0) {
          return 1;
      } else if (n == 1) {
          return 1;
      } else {
          return rekurs(n - 1)*(rekurs(n - 2)+4;
      }
  }
  </code></pre>
  
  <p>When n=20, the function has to find all the values S(n) for n=2,...,19 first.<br>
  When I let n go from 20 to 21, it does the same thing again (plus finding S(20)).</p>
  
  <p>Now I want to create an array, in which the found values S(n) for n=2,...,19 are filled into, so that the function for n=21 does not have to do the same thing again, but how do I get those elements?</p>
  
  <hr>
  
  <p>This is the solution I figured out, it's a little bit different from the lecture example.
  The keyword that helped me is "dynamic programming".</p>
  
  <pre><code>import java.util.Arrays;
  
  public class Bsp13 {
  
  public static final int N = 0;
  public static final int Ende = 20;
  
  public static long[] schroe = new long[N + Ende + 1];
  
  public static void main(String[] args) {
  
      schroe[0] = 1;
      schroe[1] = 1;
  
      for (int n = 2; n &lt;= Ende + N; n++) {
          schroe[n] = ((6 * n - 3) * (schroe[n-1]) - (n - 2) * (schroe[n-2])) / (n + 1);
      }
  
      System.out.println(schroe[N]);
      System.out.println(Arrays.toString(schroe));
      System.out.println(schroe[N+Ende]);
      }
  }
  </code></pre>