disagreement between recursion tree method and master theorem - algorithm

My solution:
I am trying to find running time of T(n) = T(n/2) + T(n/4) + Θ(n) but I have different answers using recursion tree and master theorem. Was I wrong from the recursion tree diagram part or did I use wrong asymptotic notation?

You can't use the master theorem (not match to any cases). You should use the Akra-Bazzi theorem (a general case of the master theorem).

Related

Master theorem for worst case quicksort

I know how to calculate the master theorem and I managed to calculate it for best and average case.
T(n) = 2T(n/2) + Theta(n)
The worst case equation is
T(n) = T(n-1) + Theta(n)
If I am correct a is 1, b is n/(n-1) and f(n) is n.
But how do I choose the right case of the master theorem and get a worst-case time complexity of Theta(n^2)?
Thanks!
As #DavidEisenstat pointed out in the comments, the Master Theorem doesn’t apply to the recurrence you’ve come up with here.
To give some context as to why this is - the Master Theorem is specifically designed for the case where
the number of subproblems is a constant, and
the sizes of the subproblems decays geometrically.
In this case, that second requirement doesn’t hold, since your recurrence has the problem size decay linearly rather than geometrically.
You are correct, however, that the recurrence solves to Θ(n2). To see why, note that if you unroll the recurrence, you get that the cost is
Θ(n + (n-1) + (n-2) + ... + 2 + 1)
= Θ(n(n+1)/2)
= Θ(n2).
Hope this helps!

Algorithms : Master Theorem

Master theorem can be used to solve recurrence relations like
T(n)= aT(n/b)+f(n).
So, if f(n)=O(n) or if f(n)=cn are both the values same?
can I use master theorem for f(n)=cn also?
Asumming that c is a constant and that I understand your question correctly, the solution will be the same for both f(n) = O(n) and f(n) = cn, since cn = O(n) and thus the Master theorem can be applied to solve the recurrance.
If I understood the question correctly, f(n)=cn (where c is a constant) is in O(n); the master theorem can be applied.

Applying Master's Theorem with f(n) = 2^n

I am trying to apply the Master's Theorem to a recurrence of this type:
T(n) = T(n/2) + 2^n
However, f(n) = 2^n doesn't seem to fit any of the three cases described in the master's theorem, which all seem to have base n instead of base 2. How can I solve a recurrence of this type, could anyone please help ? Thanks.
If none of the cases of the theorem applies, then the theorem won't solve your recurrence. It can't solve every single recurrence out there.
To address your issue: what you get by repeatedly substituting the recursive case is T(n) = 2^n + 2^(n/2) + 2^(n/4) + ... + 2, and since there are log n many terms to add up, you end up with something below 2^(n+1), so in total you're in Θ(2^n).
We can take log on both sides and solve. It will fall in case 3 of Master's theorem.

asymptotic complexity based off running time?

How do you go about finding the asymptotic complexity based off a running time? For example:
If the run time of a recursive algorithm is given as
T(n) = 2 T(n/2) + O(n)
considering the Master Theorem, what is its asymptotic complexity?
Could someone explain the steps on how to figure this out?
For the Master Theorem, there are 3 different cases to solve.
First step is to understand which case applies.
For questions involving Master Theorem, our general formula is T(n) = aT(n/b) + f(n)
So first thing to do is compare n^(logb a) with f(n).
Simply whichever is bigger that's the complexity of it(these are Cases 1 and 3) and if they are equal then you multiply the result with lgn, such as if you have a case like T(n) = 16 T(n/4) + O(n^2) then
n^(logb a) would make n^2 as well as f(n) = n^2 so the answer would be Θ(n^(2)*lgn), which is by using the case #2 of the Master Theorem.

Master theorem - second case issue

Given the following recursive equations:
T(n) = 5T(n/5)+(5sin^5(5n^5)+5)*n
T(n) = T(n/4)+2sin^2(n^4)
I can easily see that both equations fit the 2nd case of the master theorem,
but due to the fact that sin is a circular function, it seems that a large enough N
might bring it really close to zero.
So, we will always be able to find an N > N0 for two constants c1,c2 (By theta definition)
which will disapprove it..
Is it really possible solving it with the master theorem?
thanks
I think you're right, the Master Theorem does not apply here. The reason for this is that the difference between f(n) and n^(log_b(a)) has to be polynomial. (See Master Theorem Recurrences: What is exactly polynomial difference?)
In your case:
((5sin^5(5n^5)+5)*n)/(n^(log_5(5)))=(5sin^5(5n^5)+5and
(2sin^2(n^4))/(n^(log_4(1)))= 2sin^2(n^4), which is not polynomial, so Master Theorem is invalid in this case.

Resources