Sub topic 16
Uneven Splits: The Akra-Bazzi Method
The master theorem handles recurrences where every subproblem has the same size, n/b. Many real algorithms break that pattern. Deterministic linear-time selection (median of medians) recurses on about n/5 and 7n/10 elements. A quicksort that always splits 1:2 recurses on n/3 and 2n/3. The master theorem cannot solve either recurrence. The Akra-Bazzi method can, and it also covers every recurrence the master theorem solves.
This chapter assumes you are comfortable with Big-Theta notation, the master theorem's three cases, recursion trees, and basic integration of power functions such as ∫ u^k du.
The Form Akra-Bazzi Accepts
Akra-Bazzi applies to recurrences of this shape:
T(x) = a_1 T(b_1 x + h_1(x)) + ... + a_k T(b_k x + h_k(x)) + g(x)
The conditions below must hold for large x.
| Symbol | Requirement | Why it matters | Column | Column |
|---|---|---|---|---|
| `k` | A fixed constant number of terms | The number of terms cannot grow with `n` | ||
| `a_i` | Constant, `a_i > 0` | Each term contributes a constant number of calls | ||
| `b_i` | Constant, `0 < b_i < 1` | Each subproblem is a constant fraction smaller | ||
| `g(x)` | Nonnegative, with polynomial growth | Rules out driving functions like `2^x` | ||
| `h_i(x)` | ` | h_i(x) | = O(x / log² x)` | Absorbs floors, ceilings, and small offsets |
"Polynomial growth" means, roughly, that g changes by at most a constant factor when x changes by a constant factor. Functions like n^d, n^d log^k n, and √n qualify. Exponentials do not.
The h_i terms are what let you write T(⌊n/5⌋) or T(⌈7n/10⌉ + 6) without special treatment. A floor shifts the argument by less than 1, and a constant offset of 6 is still far smaller than x / log² x.
The Recipe
Solving with Akra-Bazzi takes two steps.
- Find the unique real number
pthat satisfiesa_1 b_1^p + a_2 b_2^p + ... + a_k b_k^p = 1. - Compute
T(x) = Θ( x^p · (1 + ∫_1^x g(u) / u^(p+1) du) ).
Exactly one such p exists. Each b_i is below 1, so each b_i^p decreases strictly as p grows, and the left-hand side moves continuously from infinity down to 0. The lower limit of the integral can be any positive constant, because changing it alters the result by only a constant.
How it relates to the master theorem
With a single term a T(n/b), the equation becomes a · b^(-p) = 1, which gives p = log_b a. That is the master theorem's critical exponent. The integral then reproduces the three cases. If g(u) grows more slowly than u^p, the integral converges to a constant and T = Θ(n^p), which is case 1. If g(u) = Θ(u^p), the integrand is 1/u and the integral is ln x, which is case 2. If g grows polynomially faster than u^p, the integral is dominated by its upper end and T = Θ(g(n)), which is case 3. Akra-Bazzi never needs the regularity condition, because the polynomial-growth requirement on g already guarantees the same behavior.
Worked Examples
A 1:2 split with linear work
T(n) = T(n/3) + T(2n/3) + n
Step 1: (1/3)^p + (2/3)^p = 1. Trying p = 1 gives 1/3 + 2/3 = 1, so p = 1.
Step 2: ∫_1^x u / u² du = ∫_1^x 1/u du = ln x.
So T(n) = Θ(n (1 + ln n)) = Θ(n log n). An unbalanced constant-ratio split costs only a constant factor compared to an even split.
Median of medians
T(n) = T(n/5) + T(7n/10) + n
Step 1: (1/5)^p + (7/10)^p = 1. At p = 1 the sum is 0.9, which is less than 1, so p < 1. You don't need the exact value. Numerically it is about 0.84.
Step 2: ∫_1^x u / u^(p+1) du = ∫_1^x u^(-p) du = (x^(1-p) - 1) / (1 - p). Because p < 1, this is Θ(x^(1-p)).
So T(n) = Θ(n^p · n^(1-p)) = Θ(n). The intuition: the subproblem sizes add up to 0.9n, so the work at each level of the recursion tree shrinks geometrically and the root's linear work dominates.
Several terms with a log factor
T(n) = 2T(n/4) + 3T(n/6) + n log n
Step 1: at p = 1, 2/4 + 3/6 = 1, so p = 1.
Step 2: ∫_1^x (u ln u) / u² du = ∫_1^x (ln u)/u du = (ln x)² / 2.
So T(n) = Θ(n log² n). This matches the extended case 2 pattern, but here it comes from two unequal terms.
Computing p and Checking Numerically
When p has no closed form, bisection finds it. The left-hand side Σ a_i b_i^p strictly decreases in p, so bisection is guaranteed to converge. The script below also evaluates the median-of-medians recurrence directly, with floors, and shows that T(n)/n levels off at a constant, which agrees with Θ(n).
from functools import lru_cache
def akra_bazzi_p(terms, iterations=200):
"""terms: list of (a_i, b_i) with a_i > 0 and 0 < b_i < 1.
Returns p with sum(a_i * b_i**p) == 1."""
for a, b in terms:
if a <= 0 or not (0 < b < 1):
raise ValueError("need a_i > 0 and 0 < b_i < 1")
def f(p):
return sum(a * b ** p for a, b in terms) - 1
lo, hi = -1.0, 1.0
while f(lo) < 0: # f decreases in p, so move lo left until f(lo) >= 0
lo *= 2
while f(hi) > 0: # move hi right until f(hi) <= 0
hi *= 2
for _ in range(iterations):
mid = (lo + hi) / 2
if f(mid) > 0:
lo = mid
else:
hi = mid
return (lo + hi) / 2
print("1:2 split p =", round(akra_bazzi_p([(1, 1/3), (1, 2/3)]), 6))
print("median of med. p =", round(akra_bazzi_p([(1, 1/5), (1, 7/10)]), 6))
print("2T(n/4)+3T(n/6) p =", round(akra_bazzi_p([(2, 1/4), (3, 1/6)]), 6))
@lru_cache(maxsize=None)
def T(n):
# Median of medians with floors: T(n) = T(n//5) + T(7n//10) + n
if n <= 1:
return 1
return T(n // 5) + T(7 * n // 10) + n
for n in [10**3, 10**4, 10**5, 10**6, 10**7]:
print(n, round(T(n) / n, 4))The first block prints p = 1 for the first and third recurrences and a value near 0.84 for median of medians. The ratios in the second block grow slowly and stay below 10, since n · (1 + 0.9 + 0.81 + ...) = 10n. That fits a Θ(n) bound. The floors in n // 5 and 7 * n // 10 are covered by the h_i terms, so they do not change the answer.
Where Akra-Bazzi Fails
The method is general, but it has hard limits.
| Recurrence | Problem | Use instead |
|---|---|---|
| `T(n) = T(n-1) + n` | `b = 1`, not a constant fraction | Unrolling: `Θ(n²)` |
| `T(n) = T(n-1) + T(n-2) + 1` | Subtractive terms | Characteristic equation: `Θ(φ^n)` |
| `T(n) = 2T(√n) + log n` | `√n` is not `b·n` for a constant `b` | Substitute `m = log n`, then apply the master theorem |
| `T(n) = 2T(n/2) + 2^n` | `g` lacks polynomial growth | Direct argument: `Θ(2^n)` |
| `T(n) = n·T(n/2) + 1` | `a` depends on `n` | Unrolling or a recursion tree |
Why the Integral Appears
Picture the recursion tree. A node of size u contributes g(u), and the parameter p acts as a weight that keeps the total "mass" Σ (size)^p the same from one level to the next. The number of nodes whose size is near u is therefore proportional to (x/u)^p per unit of log u. Summing g(u) · (x/u)^p over all scales turns into the integral x^p ∫ g(u)/u^(p+1) du, because du/u is the continuous version of stepping one level down in the tree. The extra 1 + term counts the leaves, which contribute Θ(x^p) in total. Leighton's note "Notes on Better Master Theorems for Divide-and-Conquer Recurrences" gives the rigorous version, including the h_i perturbations.
Exercise
Solve T(n) = T(n/2) + T(n/3) + n² with the Akra-Bazzi method. You do not need the exact value of p, only a bound on it.
Show answer
At p = 1, (1/2) + (1/3) = 5/6 < 1, so p < 1 (numerically about 0.79). The integral is ∫1^x u² / u^(p+1) du = ∫1^x u^(1-p) du = Θ(x^(2-p)), since 1 - p > -1. Multiplying by x^p gives T(n) = Θ(n²). The root's quadratic work dominates.
Exercise
Solve T(n) = 4T(n/2) + T(n/4) + n with the Akra-Bazzi method, and state whether the driving function or the leaves dominate.
Show answer
Solve 4(1/2)^p + (1/4)^p = 1. Let y = (1/2)^p, so y² + 4y - 1 = 0, giving y = -2 + √5 ≈ 0.236. Then p = -log2(0.236) ≈ 2.08 > 1. The integral ∫_1^x u / u^(p+1) du = ∫ u^(-p) du converges to a constant because p > 1. So T(n) = Θ(n^p) ≈ Θ(n^2.08), and the leaves dominate.
Exercise
Can Akra-Bazzi solve T(n) = T(⌈n/2⌉) + T(⌊n/2⌋ - 1) + n? Justify, then give the bound.
Show answer
Yes. Both terms have b = 1/2 and a = 1, and the ceiling, floor, and -1 offset are each O(1), well within O(n / log² n). Then (1/2)^p + (1/2)^p = 1 gives p = 1, the integral of 1/u is ln n, and T(n) = Θ(n log n).