Recursive Definitions of Mathematical Formulas
- Factorial
- Fibonacci
- x^n
- Greatest Common Divisor
gcd (m, n) = n if n is a divisor of m
gcd (m, n) = gcd(n, m % n) otherwise
Recursion Pitfalls
Advantages of Recursion
- Often, the code is easier to write
- Often, the code is easier to understand
- Recursion is a more powerful problem solving technique than iteration
Advantages of Iteration
- There is no method call overhead
- Sometimes, the natural iterative solution has a better
time complexity than the natural recursive solution
Class Code