Count calls separately from stack depth
Distinguish a chain, a branching tree, and divide-and-conquer work.
Understand the idea
Maximum simultaneously active calls determine stack depth. Total calls and work inside each call determine running time. A binary decision tree of depth n can have 2^n leaves while using only O(n) active stack frames during depth-first traversal.
Trace a small example
Naive Fibonacci recomputes overlapping states and has exponential work, despite linear maximum depth. Splitting an array in half and merging the results performs O(n) work per level across O(log n) levels, yielding O(n log n). Recursive binary search keeps only one half and takes O(log n) calls.
Conditions and cost
Printing every length-n binary string alone requires Ω(n × 2^n) output work. Small depth does not imply fast execution. Very deep linear recursion may exhaust the process stack even when its arithmetic is safe.
Growth explorer
Idealized operation counts show growth. Actual runtime also depends on the implementation and machine.
O(1)1O(log n)7O(n)100O(n log n)665O(n²)10,000Bar lengths use a logarithmic scale. Logarithms use base 2.
Guided simulation · Change the inputs to test your understanding.
A traversal has 2^n leaves but follows one branch at a time. What can its stack depth be?
Turn the idea into code
Compare recursive binary search and a full take-or-skip subset search on n positions.
Give me a hint
Ask how many child branches are explored from each state.
Show the explained solution
Binary search explores one half per step, giving O(log n) calls. Subset search explores both choices and has 2^n leaves, with O(n) maximum depth.
Your notes
Mark complete when you can explain it yourself.