7

for the relation

T(n) = T(n-1) + T(n/2) + n

can I first solve the term (T(n-1) + n) which gives O(n^2), then solve the term T(n/2) + O(n^2) ?

according to the master theorem which also gives O(n ^ 2) or it is wrong?

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
adnanmuttaleb
  • 3,388
  • 1
  • 29
  • 46
  • 1
    One thing you can always do if you have a "guess" at the complexity is trying to prove things directly using induction. If your guess is wrong this approach might not help you find the right solution but if your guess was right then you get the proof you wanted without needing to memorize any special methods – hugomg May 22 '15 at 17:20

2 Answers2

2

I don't think your approach is correct in the general case. When you throw away the T(n/2) term to calculate the complexity of the T(n-1) term you end up underestimating the size of the T(n-1) term.

For a concrete counterexample:

 T(n) = T(n-1) + T(n-2) + 1

Your technique is also going to come up with T(n) = O(n^2) for this but the real complexity is exponential.

hugomg
  • 68,213
  • 24
  • 160
  • 246
2

No, you cannot solve it using Mater-theorem.

You need to solve it using Akra–Bazzi method, a cleaner generalization of the well-known master theorem.

  1. Master-theorem assumes that the sub-problems have equal size.

  2. The master theorem concerns recurrence relations of the form

T(n) = a T(n/b) + f(n) , where a>=1, b>1.


I am not deriving here the steps for the solution so that you work out on it. If you have further problem while solving the same, please comment below. Good luck...

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73