Understanding Recursion





Puzzle: Pirates & Gold





Quick Review of Nuts & Bolts





Example: Fibonacci Numbers

int fib(int n) { if (n <= 1) return 1; // base case return fib(n-1) + fib(n-2) ; // two recursive calls! }





Euclid's GCD Algorithm

int gcd(int m, int n) { int r = m % n ; if (r == 0) return n ; return gcd(n,r) ; }





Memoization

Note: "memoization" (no r) not "memorization"





Coin Changing Problem