Recurrence T(n) = 2T(n/2) + n (merge sort style) solved step by step
Solve T(n) = 2T(n/2) + n with n = 2ᵏ by backward substitution, forward chaining and the characteristic polynomial (repeated root): n log₂ n ∈ Θ(n log n).
The question
Consider the recursive algorithm below. Algorithm Split (A, n) IF n <= 1 RETURN ELSE: Split(first half of A, n / 2) Split(second half of A, n / 2) FOR i <— 1 to n DO visit A[i] END FOR END Count the visits. 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
The basic operation is visit A[i], the line that runs most. Recurrence, part by part. Direct solution: n <= 1 visits nothing.
Conquer: two calls, each on half the array: 2T(n/2).
Combine: the loop visits all n elements once.
So T(n) = 2T(n/2) + n, T(1) = 0, with n a power of 2: n = 2^k.
Step 1 · Draft: the recurrence at n/2 and n/2^2.
The drafts to plug in.
Step 2 · Applying: replace T(n/2). The 2 in front doubles n/2 back into n.
Replace T(n/2^2): the 2^2 in front turns n/2^2 into n again.
Step 3 · General equation: after k steps, T(n) = 2^kT(n/2^k) + kn.
Base case: n/2^k = 1, so 2^k = n and k = log2 n.
T(n) = n·T(1) + n log2 n = n log2 n. So ∈ O(n 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.