K AVAILABLE
← BACK TO KNOWLEDGE

KNOWLEDGE

Fibonacci Call Stack: Visualizing Tree Recursion

Understanding how runtime call stacks allocate frames, suspend execution contexts, and unwind return values during recursion.

Updated Sep 4, 20265 min readFoundationalData Structures & Algorithms

INTERACTIVE ALGORITHM WORKBENCH

Fibonacci Call Stack Visualizer

EasyRecursion & Call StackTime O(2^n)Space O(n)
Runtime Execution Call Stack (Depth: 1)fib(3)
fib(3)ACTIVE
n = 3
▲ STACK POINTER (SP)
Active Functionfib(3)
Stack Depth1
Current Frame Statusactive
Evaluation StateAllocating frame
solution.py
▶1def fib(n: int) -> int:
2 if n <= 1:
3 return n
4 return fib(n - 1) + fib(n - 2)
Step 1 of 15
WHY THIS STEP WORKS

Each recursive call pushes an execution context containing parameters and local state onto the runtime call stack.

  1. 1Push frame fib(3)
  2. 2Call stack depth: 1
  3. 3Evaluate base condition (n <= 1)