In accord to Master Theorem this recurrece is θ(n^2), but if we solve this with tree recurrence the solution is θ(n^2*logn). Am I doing something wrong?
Asked
Active
Viewed 1,324 times
2
-
1How can the complexity be less than n^2 if right from the first execution you have a n^2 complexity? – Marco Luzzara Feb 01 '21 at 09:47
-
Your application of Master Theorem is incorrect – Abhinav Mathur Feb 01 '21 at 10:19
-
Can you be clearer what the recurrence relation is? Is it T(n) = 2T(n/2) + n^2? – Paul Hankin Feb 01 '21 at 10:30
1 Answers
2
If the recurrence relation is T(n) = 2T(n/2) + n^2, then you're in the third case of the master theorem, and the regularity condition applies, so T(n) = Theta(n^2). [c_crit is log_2(2) = 1, n^2 = Omega(n), 2(n/2)^2 = (n^2)/2 (so k<1, specifically k=1/2)]
If you expand out the recurrence relation by hand, then you get:
T(n) = n^2 + 2(n/2)^2 + 4(n/4)^2 + 8(n/8)^2 + ...
= n^2 ( 1 + 1/2 + 1/4 + 1/8 + ...)
<= 2n^2
So this method too gives you T(n) = Theta(n^2).
The method of inputting the recurrence relation into Wolfram Alpha and seeing what it says gives T(n) ~ 2n^2, so again Theta(n^2).

Paul Hankin
- 54,811
- 11
- 92
- 118
-
@AlfredoMungari if you found the answer helpful and it answered your question, you can consider upvoting the answer and accepting it. – Paul Hankin Feb 01 '21 at 15:31
-
-
I think I can't upvote this answer because my reputation is less then 15 @PaulHankin – Feb 01 '21 at 20:33