I have the following recursion: T(n) = 2*T(n/4) + T(n/2) + n and I need to know the exact equation, I know Master theorem won’t help me, and the iteration seems to be wrong…
Please tell me how to do it in general for such recursions.
Thanks in advance.
Hey all, thanks for replying I need complexity. I need to understand how to solve such problems.
T(n) = O(nlogn)andW(nlogn)To prove that, by definition of
O, we need to find constantsn0andcsuch that:for every
n>=n0,T(n)<=cnlogn.We will use induction on
nto prove thatT(n)<=cnlognfor alln>=n0Let’s skip the base case for now… (we’ll return later)
Hipothesis: We assume that for every
k<n,T(k)<=cklogkThesis: We want to prove that
T(n)<=cnlognBut,
T(n)=2T(n/4)+T(n/2)+nUsing the hipothesis we get:
T(n)<=2(c(n/4)log(n/4))+c(n/2)log(n/2)+n=cnlogn + n(1-3c/2)So, taking
c>=2/3would prove our thesis, because thenT(n)<=cnlognNow we need to prove the base case:
We will take
n0=2because if we taken0=1, thelognwould be0and that wouldn’t work with our thesis. So our base cases would ben=2,3,4. We need the following propositions to be true:T(2) <= 2clog2T(3) <= 3clog3T(4) <= 4clog4So, by taking
c=max{2/3, T(2)/2, T(3)/3log3, T(4)/8}andn0=2, we would be finding constantscandn0such that for every naturaln>=n0,T(n)<=cnlognThe demonstration for
T(n) = W(nlogn)is analog.So basically, in these cases where you can’t use the Masther Theorem, you need to ‘guess’ the result and prove it by induction.
For more information on these kind of demonstrations, refer to ‘Introduction to Algorithms’