Divide and conquer recurrence T(n) = T(n/2) + 2 solved step by step
A recursion that halves n: T(n) = T(n/2) + 2 with n = 2ᵏ, solved by backward substitution, forward chaining and the characteristic polynomial. Answer 2 log₂ n ∈ Θ(log n).
The question
Consider the recursive algorithm below. Algorithm Count (n) IF n <= 1 RETURN 0 ELSE: RETURN Count(n / 2) + 1 END Count the arithmetic operations. Take n as a power of 2. Part 1: Write the recurrence for the worst case and solve it by backward substitution, forward chaining and the characteristic polynomial (Big O). Part 2: Find the best case (Big Ω). Part 3: Find Big Θ.
The recurrence and backward substitution
Count the arithmetic with a recurrence. Direct solution: when n <= 1, it returns 0 with no arithmetic.
Divide: one division, n / 2.
Conquer: one call on half the size: T(n/2).
Combine: one addition, + 1.
So T(n) = T(n/2) + 2, T(1) = 0. To keep every n/2 a whole number (no decimal points), take n as a power of 2: n = 2^k.
Step 1 · Draft: the recurrence for n/2, n/2^2, n/2^3: each divides by 2 once more.
The drafts to plug in.
Step 2 · Applying: replace T(n/2):
Again:
And again:
Step 3 · General equation: after k steps, T(n) = T(n/2^k) + 2k.
Reach the base case: n/2^k = 1, so n = 2^k and k = log2 n.
T(n) = T(1) + 2 log2 n = 2 log2 n. So ∈ O(log n).
The rest
Next: the same recurrence solved by forward chaining and by the characteristic polynomial, then Big Ω and Big Θ, with a free account.