What is the base case in a recursive Fibonacci function?
The base case returns the first two Fibonacci numbers directly, usually when n is 0 or 1, returning n itself to stop further recursion.
Click to reveal answer
beginner
Explain how recursion works in calculating Fibonacci numbers.
Recursion breaks the problem into smaller parts by calling the Fibonacci function for (n-1) and (n-2), then adds their results to get the nth Fibonacci number.
Click to reveal answer
intermediate
What is the time complexity of the naive recursive Fibonacci algorithm?
The time complexity is exponential, specifically O(2^n), because it recalculates the same Fibonacci numbers multiple times.
Click to reveal answer
intermediate
Why can recursion be inefficient for Fibonacci calculation without optimization?
Because it repeats calculations for the same inputs many times, leading to a large number of function calls and slow performance.
Click to reveal answer
beginner
Show the TypeScript function signature for a recursive Fibonacci function.
function fibonacci(n: number): number
Click to reveal answer
What does the recursive Fibonacci function return when n is 0?
A0
B1
Cn
D-1
✗ Incorrect
The base case for n=0 returns 0 as the first Fibonacci number.
Which two previous Fibonacci numbers does the recursive function add to get the nth number?
An and n-1
Bn-1 and n-2
Cn-2 and n-3
Dn-3 and n-4
✗ Incorrect
The function calls fibonacci(n-1) and fibonacci(n-2) and adds their results.
What is a major drawback of the naive recursive Fibonacci approach?
ADoes not work for n=0
BUses too much memory
CExponential time complexity
DReturns wrong results
✗ Incorrect
The naive recursion has exponential time complexity due to repeated calculations.
Which technique can improve recursive Fibonacci efficiency?
AMemoization
BSorting
CLoop unrolling
DBinary search
✗ Incorrect
Memoization stores results of previous calls to avoid repeated work.
What is the output of fibonacci(3) using recursion?