Recursion Flashcards
1
Q
What is recursion
A
Recursion is when a method calls itself!
* A recursive method calls itself with a simpler
version of the original problem until the problem
is so simple that the answer is trivial (easy).
* Then a series of return statements is activated –
one for each recursive call.
2
Q
Fibonacci
A
Fibonacci Numbers
public static long fib(long index) {
if (index == 0) // Base case
return 0;
else if (index == 1) // Base case
return 1;
else // Reduction and recursive calls
return fib(index - 1) + fib(index - 2);
}