Question Bank

Recursion Trace Challenge

Difficulty: Medium

Five Python tracing prompts on recursive call counts, return values, stack-frame depth, and a base-case bug hunt.

Question Bank
/

Recursion Trace Challenge

Recursion Trace Challenge

Five Python tracing prompts on recursive call counts, return values, stack-frame depth, and a base-case bug hunt.

Question Bank
Medium
Python
5 questions
recursion
algorithms
interview-prep

470 views

6

What does f(4) return for the function below? Walk the call tree.

Examples

Example 1:

Input: f(4)
Output: 3
Explanation: f(4) -> f(3) + f(2). f(3) -> f(2) + f(1) = 1 + 1 = 2. f(2) -> f(1) + f(0) = 1 + 0 = 1. Final: 2 + 1 = 3 (the 4th Fibonacci number). Note f(2) is computed twice, motivating memoization.