← BACK TO KNOWLEDGE
KNOWLEDGE
Fibonacci Call Stack: Visualizing Tree Recursion
— views— comments
Understanding how runtime call stacks allocate frames, suspend execution contexts, and unwind return values during recursion.
INTERACTIVE ALGORITHM WORKBENCH
Fibonacci Call Stack Visualizer
EasyRecursion & Call StackTime O(2^n)Space O(n)
Runtime Execution Call Stack (Depth: 1)fib(3)
n = 3
▲ STACK POINTER (SP)
Active Functionfib(3)
Stack Depth1
Current Frame Statusactive
Evaluation StateAllocating frame
▶1def fib(n: int) -> int:2 if n <= 1:3 return n4 return fib(n - 1) + fib(n - 2)WHY THIS STEP WORKS
Each recursive call pushes an execution context containing parameters and local state onto the runtime call stack.
- 1Push frame fib(3)
- 2Call stack depth: 1
- 3Evaluate base condition (n <= 1)
Comments