Recall & Review
beginner
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): numberClick to reveal answer
What does the recursive Fibonacci function return when n is 0?
✗ 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?
✗ 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?
✗ Incorrect
The naive recursion has exponential time complexity due to repeated calculations.
Which technique can improve recursive Fibonacci efficiency?
✗ Incorrect
Memoization stores results of previous calls to avoid repeated work.
What is the output of fibonacci(3) using recursion?
✗ Incorrect
fibonacci(3) = fibonacci(2) + fibonacci(1) = 1 + 1 = 2.
Describe how a recursive function calculates the nth Fibonacci number.
Think about how the function calls itself with smaller inputs.
You got /3 concepts.
Explain why naive recursion for Fibonacci is inefficient and how to improve it.
Consider what happens when the function calls overlap.
You got /3 concepts.