6

I am quite frustrated over this.

In CLRS 3rd edition, page 95 (chapter 4.5), it mentions that recurrences like

T(n) = 2T(n/2) + n lg n

cannot be solved with the Master Theorem because the difference

f(n)/n^(log_b(a)) = (n lg n)/n^1 = lg n

is not polynomial.

But then I come across pages like this this where, at the bottom of the page, it mentions the exact same recurrence and says that it CAN be solved with the Master Theorem because it falls into an "extended case 2" even though the difference is non-polynomial. It becomes n lg^2 n (incrementing the log factor on f(n) by one).

Then I come across pages like this where in example (e) seems like a clear application of Extended Case 2 (the recurrence is T(n) = 4T(n/2) + n^2 lg n), but then the solution is not n^2 log^2 n, but rather n^2 log n! Am I wrong or is the paper wrong?

Can anyone please clear up the contradictions and make it very clear exactly when Master Theorem can be used and when it cannot? When does the polynomial-difference check matter, and when does it not? Is the extended case 2 usable, or does it actually violate something?

EDIT:

I tried solving recurrence (e) directly from the second paper and I get:

T(n) = n^2 lg^2(n)/2 + n^2 lg(n)/2

Is this not big theta n^2 lg^2 n?

AJJ
  • 1,794
  • 3
  • 22
  • 34
  • Note that case 2 of the Master Theorem in the book differs from the generalised form you encounter elsewhere (including your examples). Where did the generalised form come from? Exercise 4.6-2 in the book, it's actually fairly easy to prove it yourself. :-) – Michael Foukarakis Jan 03 '16 at 19:06
  • @MichaelFoukarakis Would you say then that the polynomial difference rule only applies to cases 1 and 3? – AJJ Jan 03 '16 at 19:09
  • The polynomial difference "rule" is a stricter statement than the polylogarithmic case. It applies on all 3 cases. In case #2, it is simply allowed to be relaxed. – Michael Foukarakis Jan 03 '16 at 19:48

1 Answers1

3

The book states that it cannot be solved using Case 3:

even though it appears to have the proper form: ... You might mistakenly think that case 3 should apply


However, this recurrence formula can be solved using master theorem, case 2.

T(n) = 2T(n/2) + nlgn:

We define:

a = 2, b = 2, f(n) = nlgn

Using Master theorem case 2:

c = log_2(2) = 1
k = 1

And f(n) is indeed in Theta(nlogn).

So, all conditions to master theorem case 2 apply, and we can deduce:

T(n) is in Theta(n^c * log(n)^(k+1)) = Theta(n*log(n)^2)


Long story short, Master theorem have 3 cases. Each case have it's prerequisites to be applied. Case 3 have more complicated prerequisites, because it also requires convergence.
Since the prerequisites for case 3 does not apply for this formula, you cannot use case 3. However, the prerequisites of case 2 - do apply, and you can use it.

amit
  • 166,614
  • 24
  • 210
  • 314
  • 1
    It does mention that Case 3 does not apply, but a few lines prior it says that the Master Theorem as a whole does not apply to it ("The master method does not apply to the recurrence..."), and then shortly thereafter says "You might mistakenly think that case 3 should apply...". On page 96, it claims that the recurrence "falls into the gap between case 2 and case 3". Is the book wrong? – AJJ Jan 03 '16 at 18:47
  • How about this: Would you agree with the following statements: CLRS is wrong, Master Theorem case 2 applies to `T(n) = 2T(n/2) + n lg n` and has big Theta `n lg^2 n`, the second paper I linked is wrong and `T(n) = 4T(n/2) + n^2 lg n` is also case 2, therefore big Theta `n^2 lg^2 n`, and the "polynomial difference" concept only applies when dealing with cases 1 and 3? – AJJ Jan 03 '16 at 18:52
  • (1) CLRS does not determine this is not case 2, it's actually pointing you to the proof of case 2 as a solution to this problem. I do agree the phrasing in the book is somewhat misleading however. (2) Only case 3 requires the "polynomial difference", case 1 and case 2 do not. – amit Jan 03 '16 at 18:57
  • Where in the book does it point to case 2 as the solution to the problem? Do you have a different edition of CLRS where this is mentioned? In my book it refers to the recurrence as unsolvable with Master Theorem and uses case 3 as an example of something you might try, but would be incorrect due to the polynomial difference rule. It doesn't mention or even hint that case 2 applies instead. It outright claims it's unsolvable with Master Theorem (which I disagree with). – AJJ Jan 03 '16 at 19:00
  • 1
    It says `(See Exercise 4.6-2 for a solution.)`. and this exercise is the proof of case 3... (3rd edition) – amit Jan 03 '16 at 19:01
  • You are right, and Exercise 4.6.-2 does suggest extended case 2 applies. I think the wording was misleading on page 95, but you are right. What about your point about the polynomial difference? See the bottom of page 94 and top of page 95: "In the first case, not only must f(n) be smaller than n^(log_b(a)), it must be polynomially smaller [...] in the third case, not only must be f(n) be larger than n^(log_b(a)), it also must be polynomially larger...". Doesn't this suggest the polynomial difference rule applies to cases 1 and 3 alike? – AJJ Jan 03 '16 at 19:04
  • (please note I am not referencing the case-3-only rule about the regularity condition, which is a separate condition) – AJJ Jan 03 '16 at 19:06
  • @ArukaJ Ok, I see your confusion. Yes, cases 1+3 requires polynomial difference (hence the usage of O(n^(x-eps))/ Omega(n^(x+eps)). Case 2 doesn't "need it". – amit Jan 03 '16 at 19:17
  • And yes, `T(n)=4T(n/2) + n^2lgn` is indeed in `Theta(n^2 log(n)^2)` with the same case. – amit Jan 03 '16 at 19:19