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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly