Master Theorem Case 2 (balanced recurrence, the merge-sort case)
When the work to split/combine, f(n), exactly matches the leaf cost nlogba, the recurrence T(n)=aT(n/b)+f(n) solves to Θ(nlogbalogn) — every level costs the same, and there are Θ(logn) levels.
کارت قضیه کنکور ارشد علوم کامپیوتر
اهمیت
۰/۵
The Master Theorem
Many divide-and-conquer algorithms split a problem of size n into a subproblems of size n/b, then spend f(n) extra work splitting and combining. This gives the recurrence
T(n)=aT(bn)+f(n),a≥1,b>1.
The outcome is decided by comparing f(n) against the watershed functionnlogba — the total cost of the leaves of the recursion tree.
Case
Condition on f(n)
Solution
1
f(n)=O(nlogba−ε) (leaves dominate)
Θ(nlogba)
2
f(n)=Θ(nlogba) (balanced)
Θ(nlogbalogn)
3
f(n)=Ω(nlogba+ε) + regularity (root dominates)
Θ(f(n))
Case 2 — the balanced case
Case 2. If f(n)=Θ(nlogba), then T(n)=Θ(nlogbalogn).
Intuition from the recursion tree: at depth i there are ai nodes, each doing f(n/bi) work. When f(n)=Θ(nlogba), every level does the same total amount of work, Θ(nlogba). The tree has height logbn=Θ(logn), so summing identical work over all levels multiplies by a logn factor:
The extra logn is the signature of Case 2 — it is what separates it from Cases 1 and 3, where one end of the tree dominates and no log appears.
How to apply (recipe)
Read off a (number of recursive calls), b (shrink factor), and f(n) (non-recursive work per call).
Compute the watershed exponent logba and form nlogba.
Compare f(n) to nlogba. If they are the same order (Θ of each other), you are in Case 2.
Answer: Θ(nlogbalogn).
Mini-example — merge sort and friends
Merge sort:T(n)=2T(n/2)+Θ(n). Here a=2, b=2, so nlog22=n1=n. Since f(n)=Θ(n) matches, Case 2 gives the famous
T(n)=Θ(nlogn).
The konkur question with f2(n) = f2(n/2) + f1(n) + f2(n/2) is exactly this shape: two half-size calls plus Θ(n) work from f1, i.e. T(n)=2T(n/2)+Θ(n)⇒Θ(nlogn).
Binary search of a different flavor:T(n)=2T(n/2)+Θ(1) is not Case 2 — here f(n)=Θ(1) but nlog22=n, so leaves dominate (Case 1) and T(n)=Θ(n). Matching f(n) to nlogba is the whole game.
Exam trick: Case 2 is the only case that produces a logn factor. The instant you see two half-size calls plus linear work — 2T(n/2)+Θ(n) — answer Θ(nlogn) on sight. Do not be fooled when the linear term is hidden inside a helper function (like an O(n) loop): it still counts as f(n)=Θ(n).
فرمولهای کلیدی
Master Theorem recurrence
T(n)=aT(bn)+f(n),a≥1,b>1
General divide-and-conquer recurrence: a subproblems of size n/b plus f(n) split/combine work.
Watershed (leaf-cost) function
nlogba
The benchmark you compare f(n) against; equals the total cost of the leaves of the recursion tree.
Case 2 condition and result
f(n)=Θ(nlogba)⟹T(n)=Θ(nlogbalogn)
When split/combine work balances the leaf cost, every level costs the same and the answer gains a log n factor.
Merge-sort instance
T(n)=2T(2n)+Θ(n)=Θ(nlogn)
The canonical Case 2 example: a=2, b=2, log_b a = 1, f(n)=Theta(n).