The master theorem for divide-and-conquer recurrences #
Nat.DivideConquerBound T a b n₀ T₀ f says that T satisfies the divide-and-conquer inequality
T n ≤ a T(⌈n/b⌉) + f n above the threshold n₀, with T n ≤ T₀ up to n₀. The recurrence is
stated in a form that cost functions satisfy directly. For every n > n₀, every S that bounds
T on [0, ⌈n/b⌉] gives T n ≤ a S + f n. Floors, ceilings and several subproblems of
different sizes up to ⌈n/b⌉ are therefore covered. T need not be monotone or satisfy an
equality.
The general bound unrolls the recursion: for a ≥ 1, monotone f and n ≤ n₀ b ^ k,
T n ≤ a ^ k T₀ + ∑ i < k, a ^ i f (n₀ b ^ (k - i))
(Nat.DivideConquerBound.le_sum). For f n = c n ^ d the sum is geometric with ratio a / b ^ d,
and the three cases of the master theorem follow with explicit constants.
DivideConquerBound itself imposes no condition on a, b or n₀. Every bound below assumes
a ≥ 1, and the bounds in terms of n also assume b ≥ 2 and n₀ ≥ 1. Without them the
conclusions can fail. For example, T n = n with a = b = n₀ = T₀ = 1 and c = d = 0 satisfies
DivideConquerBound, because ⌈n/1⌉ = n, yet the second bound would give T 2 ≤ 1. Write
K = ⌈log_b n⌉.
a > b ^ d:(a - b ^ d) T n ≤ ((a - b ^ d) T₀ + c n₀ ^ d b ^ d) a ^ K.a = b ^ d:T n ≤ (b n) ^ d (T₀ + c n₀ ^ d K)forn ≠ 0.a < b ^ d:(b ^ d - a) T n ≤ ((b ^ d - a) T₀ + c n₀ ^ d b ^ d) (b n) ^ dforn ≠ 0.
The first and third bounds hold for all a ≥ 1. They are trivial outside their case, where the
left factor is zero. The n-forms use b ^ ⌈log_b n⌉ ≤ b n (Nat.pow_clog_le_mul).
CslibFrontier.Foundations.Data.Nat.MasterTheoremAsymptotics converts them into
O(n ^ log_b a), O(n ^ d log n) and O(n ^ d), and also proves matching Θ bounds across all
three cases (including case 3 under the general regularity condition).
For case 3 with a general monotone driving function f, Nat.RegularityCondition f a b n₀ p q
states the integer regularity condition p < q and q a f(⌊n/b⌋) ≤ p f(n) for n > n₀.
Unrolling along the exact ceiling chain ⌈n / b ^ i⌉ avoids overshooting n to n₀ b ^ k
(which would fail for super-polynomial f such as 2 ^ n), yielding the explicit bound
(q - p) f(n₀ + 1) T n ≤ ((q - p) a ^ 2 T₀ + (q - p + a q) f(n₀ + 1)) f n for n > n₀
(Nat.DivideConquerBound.sub_mul_le_of_regular).
Nat.DivideConquerLower T a b n₀ T₀ f is the dual lower recurrence a T(⌊n/b⌋) + f n ≤ T n for
n > n₀ with T₀ ≤ T n on [1, n₀], allowing subproblems of any size in [⌊n/b⌋, ⌈n/b⌉].
Nat.DivideConquerEq T a b n₀ Tmin Tmax f bundles matching upper and lower recurrences, with
constructors of_div and of_ceilDiv for exact floor and ceiling recurrences.
Nat.add_mul_two_pow_le_mul_pow_of_halving (CslibFrontier.Foundations.Data.Nat.HalvingRecurrence)
remains the sharper tool for b = 2: it carries a subtracted lower-order term through the
induction, which some clients need.
Main definitions #
Nat.DivideConquerBound: the divide-and-conquer upper inequality with threshold and base bound.Nat.RegularityCondition: integer regularity conditionq a f(⌊n/b⌋) ≤ p f(n)withp < q.Nat.DivideConquerLower: the divide-and-conquer lower inequality with threshold and base bound.Nat.DivideConquerEq: matching upper and lower divide-and-conquer recurrences.
Main results #
Nat.DivideConquerBound.le_sum: the unrolled recursion;Nat.DivideConquerBound.le_geom_sumforf n = c n ^ d.Nat.DivideConquerBound.sub_mul_le_pow,Nat.DivideConquerBound.le_pow_mul,Nat.DivideConquerBound.pow_sub_mul_le_pow: the three polynomial cases forn ≤ n₀ b ^ k.Nat.DivideConquerBound.sub_mul_le_pow_clog,Nat.DivideConquerBound.le_mul_pow_mul_clog,Nat.DivideConquerBound.pow_sub_mul_le_mul_pow: the three polynomial cases in terms ofn.Nat.DivideConquerBound.sub_mul_le_of_regular: case 3 under the general regularity condition.Nat.DivideConquerLower.sum_le,Nat.DivideConquerLower.pow_mul_le,Nat.DivideConquerLower.pow_log_mul_le,Nat.DivideConquerLower.mul_pow_mul_le,Nat.DivideConquerLower.le_of_lt: lower bounds for all three cases.
References #
- Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, Theorem 4.1 (the master theorem, Section 4.5), Lemmas 4.2–4.4 and Section 4.6.2 (floors and ceilings).
T satisfies the divide-and-conquer inequality T n ≤ a T(⌈n/b⌉) + f n above n₀, with
T n ≤ T₀ up to n₀. The recursive step quantifies over every bound S of T on
[0, ⌈n/b⌉], so subproblems of any size up to ⌈n/b⌉ may be used.
The base case:
T n ≤ T₀forn ≤ n₀.The recursive step:
T n ≤ a S + f nwheneverSboundsTup to⌈n/b⌉.
Unrolling the recursion. For monotone f and n ≤ n₀ b ^ k,
T n ≤ a ^ k T₀ + ∑ i < k, a ^ i f (n₀ b ^ (k - i)).
Geometric sums #
The three cases #
Master theorem, case 1 (a > b ^ d), for n ≤ n₀ b ^ k:
(a - b ^ d) T n ≤ ((a - b ^ d) T₀ + c n₀ ^ d b ^ d) a ^ k. The bound holds for every a ≥ 1
and is trivial when a ≤ b ^ d.
Master theorem, case 3 (a < b ^ d), for n ≤ n₀ b ^ k:
(b ^ d - a) T n ≤ ((b ^ d - a) T₀ + c n₀ ^ d b ^ d) (b ^ d) ^ k. The bound holds for every
a ≥ 1 and is trivial when a ≥ b ^ d.
Bounds in terms of n #
Master theorem, case 2 with K = ⌈log_b n⌉: if a = b ^ d and n ≠ 0, then
T n ≤ (b n) ^ d (T₀ + c n₀ ^ d K).
Master theorem, case 3 in terms of n: if n ≠ 0, then
(b ^ d - a) T n ≤ ((b ^ d - a) T₀ + c n₀ ^ d b ^ d) (b n) ^ d.
Raising the base threshold of DivideConquerBound from n₀ to any n₁ ≥ n₀.
Case 3 under the general regularity condition #
The regularity condition for case 3 of the master theorem, in integer form: p < q,
f is monotone, and q * a * f (n / b) ≤ p * f n for every n > n₀ (expressing
a f(⌊n/b⌋) ≤ (p / q) f(n) with contraction ratio p / q < 1).
Master theorem, case 3 (general regularity condition): under
RegularityCondition f a b n₀ p q, for every n > n₀,
(q - p) f(n₀ + 1) T n ≤ ((q - p) a ^ 2 T₀ + (q - p + a q) f(n₀ + 1)) f n.
Lower bounds and matching recurrences #
T satisfies the divide-and-conquer lower inequality a T(⌊n/b⌋) + f n ≤ T n above n₀,
with T₀ ≤ T n for 1 ≤ n ≤ n₀. The recursive step quantifies over every lower bound S of T
on [⌊n/b⌋, ⌈n/b⌉], so subproblems of any size between ⌊n/b⌋ and ⌈n/b⌉ are covered.
Unrolling the lower recursion. For monotone f, b ≤ n₀ + 1, and n₀ b ^ k ≤ n,
a ^ k T₀ + ∑ i < k, a ^ i f (n₀ b ^ (k - i)) ≤ T n.
Master theorem lower bound, case 1, for n₀ b ^ k ≤ n: a ^ k T₀ ≤ T n. Requires no
monotonicity or polynomial assumption on f.
Master theorem lower bound, case 2 (a = b ^ d), for n₀ b ^ k ≤ n:
c * k * (n₀ * b ^ k) ^ d ≤ T n.
Master theorem lower bound, case 3: f n ≤ T n for every n > n₀.
Matching upper and lower divide-and-conquer recurrences above n₀, with base bounds
Tmin ≤ T n (for 1 ≤ n ≤ n₀) and T n ≤ Tmax (for n ≤ n₀).
- upper : DivideConquerBound T a b n₀ Tmax f
The upper recurrence bound
T n ≤ a T(⌈n/b⌉) + f n. - lower : DivideConquerLower T a b n₀ Tmin f
The lower recurrence bound
a T(⌊n/b⌋) + f n ≤ T n.
Build DivideConquerEq from an exact floor recurrence T n = a * T (n / b) + f n.
Build DivideConquerEq from an exact ceiling recurrence
T n = a * T ((n + b - 1) / b) + f n.