Time Complexity via Divide-and-Conquer Recurrences (Two Worked Examples)

Time Complexity via Divide-and-Conquer Recurrences (Two Worked Examples)

Verified Sources
Sep 12, 2026

This section teaches how to compute asymptotic running time for two recurrences—one “variable-size divide-and-conquer” and one “incremental” recurrence.

We will solve:

  1. (i)T(n)=n T(n)+n,n>2(i)\quad T(n)=\sqrt{n}\,T(\sqrt{n})+n,\quad n>2
  2. (ii)T(n)=T(n−1)+1n,n>1(ii)\quad T(n)=T(n-1)+\frac{1}{n},\quad n>1

We’ll use a standard “recurrence tree / unfolding” strategy for (i) and summation (telescoping / series) for (ii).

type="tip" title="Pro Tip" content="When the subproblem size changes nonlinearly (like n\sqrt{n}), switch from Master Theorem to recurrence-tree/unrolling and track how many levels occur and what each level costs."

Key keywords you’ll use

  • Recurrence
  • Recurrence tree
  • Unrolling
  • Base case

(Next, we do the full derivations.)

Solve (i) T(n)=√n·T(√n)+n via recurrence-tree unrolling

  1. 1
    Step 1

    Let n0=nn_0=n and define ni+1=nin_{i+1}=\sqrt{n_i}, so ni=n(1/2i)n_i=n^{(1/2^i)}.

  2. 2
    Step 2

    At level ii, the recurrence contributes a factor of ni\sqrt{n_i} in front of the next T(⋅)T(·). Since ni=n1/2in_i=n^{1/2^i}, we get ni=n1/2i+1\sqrt{n_i}=n^{1/2^{i+1}}.

  3. 3
    Step 3

    At each level, the additive term contributes +ni+n_i (because the '+n' in T(n)T(n) becomes '+(current subproblem size)' when unfolded).

  4. 4
    Step 4

    Stop when ni≤2n_i \le 2 (or any constant). Solve n1/2i≤cn^{1/2^i} \le c → 12iln⁡n≤ln⁡c\frac{1}{2^i}\ln n \le \ln c → 2i≥Θ(ln⁡n)2^i \ge \Theta(\ln n), hence i=Θ(log⁡log⁡n)i=\Theta(\log\log n).

  5. 5
    Step 5

    Total cost is approximately ∑i=0Θ(log⁡log⁡n)(∏j=0i−1nj)⋅ni\sum_{i=0}^{\Theta(\log\log n)} \left(\prod_{j=0}^{i-1} \sqrt{n_j}\right)\cdot n_i Using ∏j=0i−1nj=∏j=0i−1n1/2j+1=n∑j=0i−11/2j+1=n1−1/2i.\prod_{j=0}^{i-1} \sqrt{n_j}=\prod_{j=0}^{i-1} n^{1/2^{j+1}}=n^{\sum_{j=0}^{i-1} 1/2^{j+1}}=n^{1-1/2^i}. Thus the level-ii term becomes n1−1/2i⋅n1/2i=nn^{1-1/2^i}\cdot n^{1/2^i}=n.

  6. 6
    Step 6

    Each level contributes Θ(n)\Theta(n), and there are Θ(log⁡log⁡n)\Theta(\log\log n) levels, so T(n)=Θ(nlog⁡log⁡n).T(n)=\Theta(n\log\log n).

Result for (i)

T(n)=n T(n)+nLongrightarrowquadT(n)=Θ(nloglogn).T(n)=\sqrt{n}\,T(\sqrt{n})+n \quad \\Longrightarrow \\quad T(n)=\Theta(n\\log\\log n).

Why this happens (intuition):
Unrolling produces about loglogn\\log\\log n levels because each step takes a square root, so the exponent 1/2i1/2^i shrinks geometrically. Meanwhile, although the subproblem sizes shrink, the multiplicative factor from sqrtn\\sqrt{n} expands in exactly the right way so that the effective cost per level stays on the order of nn.

type="warning" title="Common Pitfall" content="Do NOT apply the standard Master Theorem directly here: the subproblem size is n\sqrt{n} but the number of subproblems is effectively variable (the multiplier is n\sqrt{n}, not a constant aa). That’s why recurrence-tree accounting/unrolling is safer."

Solve (ii) T(n)=T(n-1)+1/n using telescoping unrolling

  1. 1
    Step 1

    "For n>1n>1 iterate: T(n)=T(n−1)+1n=T(n−2)+1n−1+1n=⋯=T(1)+∑k=2n1k.T(n)=T(n-1)+\frac{1}{n} = T(n-2)+\frac{1}{n-1}+\frac{1}{n}=\cdots= T(1)+\sum_{k=2}^{n}\frac{1}{k}.

  2. 2
    Step 2

    "Let Hn=∑k=1n1kH_n=\sum_{k=1}^{n}\frac{1}{k}. Then ∑k=2n1k=Hn−1.\sum_{k=2}^{n}\frac{1}{k}=H_n-1.

  3. 3
    Step 3

    A standard fact is Hn=Θ(log⁡n)H_n=\Theta(\log n), so T(n)=T(1)+Θ(log⁡n)=Θ(log⁡n).T(n)=T(1)+\Theta(\log n)=\Theta(\log n).

Result for (ii)

T(n)=T(n−1)+frac1nLongrightarrowquadT(n)=Theta(logn).T(n)=T(n-1)+\\frac{1}{n} \quad \\Longrightarrow \\quad T(n)=\\Theta(\\log n).

Intuition:
You add 1/n1/n each step. Summing 1/k1/k from k=2k=2 to nn yields the harmonic series, which grows logarithmically.

Asymptotic running time comparison

Two different recurrence styles yield distinct growth rates.

Learning roadmap for these recurrence types

Identify recurrence structure

Step A

Check whether coefficients/subproblem sizes are constant or variable (e.g., n\sqrt{n} multiplier)."

Choose the right method

Step B

Use unrolling/recurrence tree for variable divide-and-conquer; use telescoping/sums for linear recurrences."

Count levels and sum per level

Step C

For n\sqrt{n}-style recurrences, levels are about Θ(log⁡log⁡n)\Theta(\log\log n)."

Convert sums to known series

Step D

For ∑1/k\sum 1/k, use harmonic growth Θ(log⁡n)\Theta(\log n)."

FAQs and edge cases

Knowledge Check

Question 1 of 4
Q1Single choice

For T(n)=n T(n)+nT(n)=\sqrt{n}\,T(\sqrt{n})+n, the number of recurrence-tree levels is approximately: