See recursion
in motion.
Follow the Fibonacci calls, watch them return, and see how memoization changes the tree.
Plain recursion15
Memoized9
6 fewer calls for fib(5).
Fibonacci visualizer
Call tree
fib(5) → 5 Active Returned From cache Ahead
Current step
1 / 38Call stack oldest to newest
Function
Where does the extra work go?
Try fib(6). Follow one branch to a base case, then find another call with the same input. Switch to Memoized and look for the first cache hit.
Work through the Fibonacci recursion tree guide →Fibonacci Recursion Visualizer | Revursion
Step through the Fibonacci recursion tree and call stack. Compare plain recursion with memoization, one function call at a time.
What you can do on revursion.org
- Fibonacci visualizer
- Where does the extra work go?
- Input
- Plain
- Memoized
- Trace step
Reference guides & documentation
- The Fibonacci recursion tree — Trace the Fibonacci recursion tree for fib(5), count function calls, and see which repeated branches memoization removes.