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
1. Plain recursion fib(6)
25 calls · lots of repeats
2. Memoized fib(6)
each value computed once
3. Memoized fib(12)
recursion depth 12 · only 13 values
1. Tree traversals
2. Binary Search Tree
3. Hash table · linear probing
4. STL unordered_map
5. First non-repeating char
6. Reconstruct binary tree
7. BST insert 15/90/65
8. Tower of Hanoi
9. Fibonacci recursion
10. Reverse a string with a stack
11. Reverse the first K of a queue
12. Stack · editor Undo
13. Stack · palindrome checker
14. Queue · clinic line
15. Linear search
16. Binary search
17. Bubble sort
18. Insertion sort
19. Shell sort
20. Quick sort
21. Selection sort
22. Heap sort
23. Merge sort
24. Radix sort
25. Bubble sort · names
26. Exam cram · outcome2
27. Merge sort · recursion tree
28. Min-stack
29. std::set operations
🌳 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
⏮ Reset
◀ Back
▶ Play
Next ▶
⏭ Result
Speed
Shortcuts:
Space
play/pause ·
←
→
step ·
R
reset ·
E
result