Data Structures · Recursion

Fibonacci Recursion — the recursive call tree

fib(n) = fib(n−1) + fib(n−2) · what the recursion tree looks like + repeated work vs memoization

🌳 The fib() recursion call tree

called, waiting for children computing right now return value known (number in green) memo hit: returns at once, no expansion (memoized mode)

📊 How often each n is called

💬 Current step

💻 C++ recursive implementation

Yellow = current line. Every circle is one fib() call; the small text under a circle is that call's final return value.

🥞 Recursion call stack the chain of calls waiting to return

Speed
Shortcuts: Space play/pause · ←→ step · R reset · E result