Model a recursive algorithm's cost as a recurrence, then read its asymptotic order off the Master Theorem — or, when the shape doesn't fit, via variable substitution, Akra–Bazzi, or a recursion tree.
کارت قضیه کنکور ارشد مهندسی کامپیوتر
اهمیت
۰/۵
A recurrence expresses an algorithm's cost T(n) in terms of its cost on smaller inputs. Every divide-and-conquer algorithm that breaks a size-n problem into a subproblems of size n/b and spends f(n) extra work to split and combine obeys
T(n)=aT(bn)+f(n),a≥1,b>1.
Solving it means finding the asymptotic order of T(n).
The Master Theorem
Compare f(n) against the watershed functionnlogba (the number of leaves in the recursion tree). Let c∗=logba.
Case 3 additionally needs the regularity condition af(n/b)≤cf(n) for some constant c<1. The workhorse is Case 2 with k=0: aT(n/b)+Θ(nc∗)=Θ(nc∗logn) — exactly merge sort, 2T(n/2)+n=Θ(nlogn).
Recipe
Read off a, b, and f(n).
Compute c∗=logba and the watershed nc∗.
Decide whether f is polynomially smaller (Case 1), the same order up to logs (Case 2), or polynomially larger (Case 3).
Mini-example.T(n)=3T(n/2)+n: here c∗=log23≈1.58 and f(n)=n=O(n1.58−ϵ), so Case 1 gives T(n)=Θ(nlog23).
When the Master Theorem doesn't apply
Situation
Tool
Non-polynomial gap (e.g. f=n/logn)
recursion tree / substitution
Argument is n
variable substitutionn=2m
Unequal subproblem sizes T(αn)+T(βn)+f
Akra–Bazzi
Subtract-and-conquer T(n)=aT(n−b)+f
unroll the sum directly
Square-root recurrences. For T(n)=aT(n)+f(n), substitute n=2m (so m=logn) and set S(m)=T(2m); then n=2m/2 turns the square root into a halving:
T(n)=2T(n)+logn⟹S(m)=2S(2m)+m=Θ(mlogm),
and back-substituting m=logn gives T(n)=Θ(lognloglogn). A floor such as ⌊n⌋ never changes the asymptotics.
Subtract-and-conquer & halving.T(n)=T(n−1)+Θ(n)=Θ(n2) (insertion/selection-sort worst case); T(n)=2T(n−1)+Θ(1)=Θ(2n); and the pure halving searchT(n)=T(n/2)+Θ(1)=Θ(logn) — e.g. shrinking a region of 16 down to 1 by comparing halves takes log216=4 steps.
Setting up the recurrence is half the battle. Naming the true subproblem sizes matters more than the algebra: a quicksort whose pivot is the median of a Θ(n) sample guarantees at least n elements on each side, so its worst-case split is the lopsidedT(n)+T(n−n)+Θ(n) — not the balanced 2T(n/2) that the word "median" might suggest.
Exam trick: Reach for the Master Theorem only once the recurrence already has the exact shape aT(n/b)+f(n). A n argument means substitute n=2m; two different subproblem sizes mean Akra–Bazzi or a recursion tree; an n−b argument (not n/b) means subtract-and-conquer, so unroll the sum instead.
فرمولهای کلیدی
Divide-and-conquer recurrence
T(n)=aT(bn)+f(n)
a subproblems of size n/b, plus f(n) work to split and combine (a >= 1, b > 1).
Compare f(n) with the watershed n^{log_b a}: leaves win (Case 1), tie up to logs (Case 2), or root wins (Case 3, which also needs the regularity condition).
Square-root substitution
n=2m,S(m)=T(2m)
Substitute n = 2^m to turn T(n) = a·T(sqrt(n)) + f into a halving recurrence in m = log n, then translate the answer back.