PROJECTENGRAM

RECURSION TREE METHOD

Recursion Tree Method

Tags: #◇CCDSALG #◇Algorithms #◇Computer Science #◇Computational Complexity #◇Efficiency #◇Algorithm Design Paradigms #◇Recursion #◇Recursion and Iteration #◇Analysis of Algorithms #◇Data Structures #◇Time Complexity #◇Space Complexity


◇Overview

The Recursion Tree Method is a visual technique for solving recurrences by drawing the recursive calls as a tree and summing costs at each level.

◇Key Concepts

Visualizing recursive calls as a tree Summing costs level by level Determining tree depth and number of leaves Often used to "guess" the solution, then verify with the ◇Substitution Method

◇Details / Theory

How It Works

  1. Draw the recursion tree — each node represents the cost of a single recursive call (excluding its children’s costs).
  2. Determine cost per level — sum all node costs at each depth level.
  3. Count the number of levels — the tree has depth log⁡bn\log_b n for a recurrence that divides by bb.
  4. Sum across all levels to get the total cost T(n)T(n).

Worked Example: T(n)=2T(n/2)+nT(n) = 2T(n/2) + n

Per-Level Cost Accounting:

  • Level 0: 1 node with cost cncn   ⟹  \implies Total = cncn
  • Level 1: 2 nodes, each with cost c(n/2)c(n/2)   ⟹  \implies Total = cncn
  • Level 2: 4 nodes, each with cost c(n/4)c(n/4)   ⟹  \implies Total = cncn
  • Level kk: 2k2^k nodes, each with cost c(n/2k)c(n/2^k)   ⟹  \implies Total = cncn

Depth: The tree has log⁡2n\log_2 n levels (since the input size halves at each recursive descent).
Leaves: At level log⁡2n\log_2 n, there are 2log⁡2n=n2^{\log_2 n} = n base-case leaves, each with cost Θ(1)\Theta(1), contributing Θ(n)\Theta(n).

Total Cost Summation:
T(n)=∑k=0log⁡2n−1cn+Θ(n)=cnlog⁡2n+Θ(n)=Θ(nlog⁡n)T(n) = \sum_{k=0}^{\log_2 n - 1} cn + \Theta(n) = cn \log_2 n + \Theta(n) = \Theta(n \log n)

Recurrence Tree Taxonomy & Behavior

Worked Example: T(n)=3T(n/4)+cn2T(n) = 3T(n/4) + cn^2

  • Level 0: cost cn2cn^2
  • Level 1: 3 nodes, each cost c(n/4)2=cn2/16c(n/4)^2 = cn^2/16   ⟹  \implies Total = 316cn2\frac{3}{16} cn^2
  • Level 2: 9 nodes, each cost c(n/16)2c(n/16)^2   ⟹  \implies Total = (316)2cn2\left(\frac{3}{16}\right)^2 cn^2
  • Level kk: Total cost = (316)kcn2\left(\frac{3}{16}\right)^k cn^2

This is a strictly decreasing geometric series with common ratio r=3/16<1r = 3/16 < 1. Sum of infinite geometric series yields:
T(n)≤cn2∑k=0∞(316)k=cn2⋅11−3/16=1613cn2=O(n2)T(n) \le cn^2 \sum_{k=0}^{\infty} \left(\frac{3}{16}\right)^k = cn^2 \cdot \frac{1}{1 - 3/16} = \frac{16}{13} cn^2 = O(n^2)

The root level dominates (top-heavy tree) — directly consistent with Master Theorem Case 3.

When to Use This Method

When you want a visual/intuitive understanding of the recurrence. To generate a "guess" for the ◇Substitution Method. When the ◇Master Theorem doesn’t directly apply.

◇Common Pitfalls

Forgetting to account for the cost at the leaf level. Incorrectly computing the number of nodes per level (it multiplies by aa each level, not bb). Not recognizing geometric series patterns when summing across levels.

◇Summary

TL;DR — The Recursion Tree Method draws out recursive calls as a tree, sums costs per level, and totals them to solve the recurrence. It’s especially useful for intuition and as a precursor to formal proofs.

Related: ◇Master Theorem — ◇Substitution Method — ◇Divide and Conquer — ◇Asymptotic Notation — ◇Recursion Source / Reference: Handout 03

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

What is the Recursion Tree Method used for?

Q2

In a recursion tree for T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n), what does each node represent?

Q3

For a recurrence that divides the input by bb at each step, what is the total depth of the recursion tree?

Q4

In the worked example T(n)=2T(n/2)+nT(n) = 2T(n/2) + n, what is the total cost at level 1?

Q5

In the worked example T(n)=2T(n/2)+nT(n) = 2T(n/2) + n, how many leaves does the tree have at the final level?

Q6

In the worked example T(n)=3T(n/4)+cn2T(n) = 3T(n/4) + cn^2, what does the geometric series indicate about the tree?

Q7

Which method is the Recursion Tree Method often used to help or generate a "guess" for?

Q8

What is a common pitfall when drawing a recursion tree?

Q9

When computing the number of nodes per level, by what factor does it increase each time?

Q10

Why might someone choose to use the Recursion Tree Method over the Master Theorem?