announcements‎ > ‎

2016-02-05 Prime?

posted Feb 5, 2016, 7:12 AM by Samuel Konstantinovich   [ updated Feb 5, 2016, 8:44 AM ]
Goal: Optimal Prime // Recursion day 3. 
  1. Base case
  2. Tail Recursion
    • No pending operations.  A pending operation happens after the recursive call completes,   e.g. 1 + foo(n-1)  //the 1 + has to wait for the foo, so it would be pending.
    • Partially computed answer is stored as a parameter 
    • Java does not have tail recursion optimization: tail recursion still blows the stack after less than 11,000 calls, much less if you have more parameters.
Today We will develop some algorithms together:

int sumDigits(int n)      
-tail recursive

boolean isPrime(int n)