DSATime ComplexityRecurrence

Recursion Tree Method Visualizer

What is the Recursion Tree Method

A recursion tree unrolls T(n) = a T(n/b) + f(n) into levels. The root does f(n) work, each child does f(n/b), and so on until size 1. Add the work level by level. A geometric series on those level-costs is the closed form.

  • Level cost L(i) = ai · f(n / bi)
  • Height is logb n — how many times you divide by b to reach 1.
  • Read the series: shrinking levels → root wins; equal levels → n log n; growing levels → leaves win.

How this visualizer works

Pick a classic recurrence. Each Step opens one deeper level, shows that level’s cost, then sums the tree. This is the picture Master Theorem later classifies in one line.

Interactive recursion tree

recursion_tree.svg

Current level
Already expanded
Not yet opened

current_action

Choose a recurrence, then Step through each level.

live_trace.txt

level_costs

Speed Ready

Pseudocode & Complexity

method.txt

1Write T(n) = a T(n/b) + f(n)
2Root does f(n) work
3Level i has a^i nodes, each f(n/b^i)
4Level cost L(i) = a^i · f(n / b^i)
5Height h = log_b n
6T(n) = Σ L(i) from i = 0 … h
7Read the sum: geometric → closed form

complexity.md

OperationTime
Merge sort 2T(n/2)+nO(n log n)
Binary search T(n/2)+1O(log n)
Tree walk 2T(n/2)+1O(n)
3T(n/2)+nO(n^{log₂ 3})
Space—