Recursion Trees and Level Costs
Expand a recurrence by level and account for both the per-level work and the number of leaves.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Group identical subproblems
For merge sort with input size \(n=2^k\), each level \(j\) contains \(2^j\) nodes of size \(n/2^j\). If a merge at size \(s\) takes \(cs\) work, every internal level costs \(cn\). There are \(k\) such levels. A constant work cost \(d\) per leaf contributes another \(dn\), so
\[ T(n)=cn\log_2 n+dn . \]
This calculation depends on balanced splitting. The same tree argument explains the equal-contribution case in the master theorem.
Watch for leaves at different depths
For a split into sizes \(n/3\) and \(2n/3\), total active mass at each level is at most \(n\). Some leaves appear much earlier than others. The longest path has logarithmic depth, giving a logarithmic-times-linear upper bound for linear work per node. To obtain the matching lower bound, use the first logarithmically many levels over which even the faster-shrinking path has no leaves. A substitution proof gives another way to certify a bound when the tree is hard to sum.[1][2]