How do you solve this recurrence relation using the recursion tree? - algorithm

I am having a difficult time understanding and solving recurrence relations. Can someone please help me with this particular one?
T(n)=T(n/3)+T(2n/3)+n

Look at this image:
Which is a recursion tree you can continue.
Also, it's like this one I have found in the URL: Recursion tree T(n) = T(n/3) + T(2n/3) + cn
Which may help you for further help. It's almost like your question, just use c=1 instead of c.
The shortest path to a leaf occurs when we take the heavy branch each time.
Consider k as the height of the tree results: (pow(n*(1/3),k) ≤ 1) meaning k ≥ lg3 n.
The longest path to a leaf occurs when we take the light branch each time.
Consider k as the height of the tree results: (pow(n*(2/3),k) ≤ 1) meaning k ≥ lg3/2 n.
Now look at this image:
This means on any full level, the sum of the additive terms to n.
Now, let's look at what we have.
If you pick height to be
log3 n
The result would be:
T(n) ≥ nlog3 n --> T(n) ≥ Ω (nlogn)
If you pick height to be
log3/2 n
The result would be:
T(n) ≥ nlog3/2 n --> T(n) ≤ O(nlogn)
And this two (1 & 2) will leads us to T(n) = Θ(nlogn)
Other sources : help

Related

Recursive algorithm time complexity (maximum independent set)

I have an assignment to analyse and implement an algorithm for finding the maximum independent set of a graph, and I've come to the time complexity part of said algorithm. I've deduced it is as follows:
T(n) = T(n-1) + T(n-3) + O(n^3) + O(n^2)
I've figured some other similar recursive algorithms out before, but I got stuck several times with this one. I think it's supposed to turn out to be ~O(2^n).
Can someone help me get the solution?
Edit: I just double checked it the solution is supposed to be O(1.8^n). Any way to get to that solution?
Since O(n³) + O(n²) = O(n³) = O(f(n)) where f(n) = n³ − 12n² + 30n − 28,
there exists some constant γ > 0 such that we can overestimate the
original recurrence T as a concrete linear non-homogeneous recurrence
T′:
T′(n) = T′(n−1) + T′(n−3) + γf(n).
We follow the usual playbook, focusing on the homogeneous part first
(same recurrence but without γn³). The characteristic polynomial is x³ −
x² − 1. Letting α be any zero of this polynomial, the function
αn satisfies
αn = αn−1 + αn−3,
Assuming that the base case values are positive, the growth rate of the
homogeneous part will be Θ(αn) where α = 1.46557… is the zero
of maximum argument.
We also have to deal with the non-homogeneous part, but it turns out not
to matter asymptotically. By design we have f(n) = (n−1)³ + (n−3)³ − n³,
so letting U(n) = βαn − γn3, we can verify that
U(n−1) + U(n−3) + γn³ = β(αn−1 + αn−3) −
γ((n−1)³ + (n−3)³ − f(n)) = βαn − γn³ = U(n)
is a solution for T′, keeping us in the same asymptotic class.
If we draw the recursion tree, it will look something like this, For simplicity, lets every node has 2 child nodes and the height of this tree is n until it reaches the base case. As it's a binary tree the number of nodes will be (2^n)-1.
So the complexity for T(n) = T(n-1) + T(n-3) is O(2^n).
Now the overall complexity is O(2^N) + O(n^3) + O (n^2) = O(2^N)

Solve recurrence relation using Master's method -> T(n) = 2T(n/2) + n^2 when n is even and T(n) = 2T(n/2) + n^3 when n is odd

T(n) ={ 2T(n/2) + n^2 when n is even and T(n) = 2T(n/2) + n^3 when n is odd
I solved this separately and i am getting the solution as theta(n^2) if n is even and theta(n^3) if n is odd from case 3 of master's theorem. But i am not supposed to solve this problem separately.
How to solve a recurrence relation like this together?
T(n) ={ 2T(n/2) + n^2 when n is even and T(n) = 2T(n/2) + n^3 when n is odd
Is it solvable by master's theorem or master's theorem does not apply?
Kindly help me with this.
Suppose n = 2^k for some integer k, so n equals to 100...00. Then you can apply master method the even part of the recurrence. and obtain theta(n^2).
Now suppose there is also 1 not in the most significant bit, e.g. 100100..00. So, you will have at least one level in your recursion-tree all nodes of which add up to n^3 * constant, and by this you obtain theta(n^3).
Thus, the answer is theta(n^2) if n is a power of two and theta(n^3) otherwise. But if we first encounter odd n and it is equal to a base case then it might not be cubic.
After some chatting with kelalaka it came to me that if first 1 is k-th from the right in n then if k > (2/3)(1/lg 2)lg n, we don't care any more about (n/2^k)^3. It is still O(n^2).

Is CLRS completely accurate to state that max-heapify running time is described by the recurrence `T(n) = T(2n/3) + O(1)`?

In CLRS on page 155, about max-heaps, the running time of max-heapify is described as T(n) = T(2n/3) + O(1).
I understand why the first recursive call is on a subproblem of size 2n/3 in the case where we have a nearly complete binary tree (always the case with heaps) in which the deepest level of nodes is half full (and we are recursing on the child that is the root of the subtree that contains these nodes at the deepest level). A more in depth explanation of this is here.
What I don't understand is: after that first recursive call, the subtree is now a complete binary tree, so the next recursive calls will be on problems of size n/2.
So is it accurate to simply state that the running time of max-heapify is described by the recurrence T(n) = T(2n/3) + O(1)?
Converting my comment to an answer: if you assume that T(n), the time required to build a max-heap with n nodes, is a nondecreasing function of n, then we know that T(m) ≤ T(n) for any m ≤ n. You're correct that the ratio of 2n / 3 is the worst-case ratio and that after the first level of the recurrence it won't be reached, but under the above assumption you can safely conclude that T(n / 2) ≤ T(2n / 3), so we can upper-bound the recurrence as
T(n) ≤ T(2n / 3) + O(1)
even if strict equality doesn't hold. That then lets us use the master theorem to conclude that T(n) = O(log n).

Solving T (n) = √2*T(n/2) + log n using master theorem

The question is :
T(n) = √2*T(n/2) + log n
I'm not sure whether the master theorem works here, and kinda stuck.
This looks more like the Akra-Bazzi theorem: http://en.wikipedia.org/wiki/Akra%E2%80%93Bazzi_method#The_formula with k=1, h=0, g(n)=log n, a=(2)^{1/2}, b=1/2. In that case, p=1/2 and you need to evaluate the integral \int_1^x log(u)/u^{3/2} du. You can use integration by parts, or a symbolic integrator. Wolfram Alpha tells me the indefinite integral is -2(log u + 2)/u^{1/2} + C, so the definite integral is 4 - 2(log x + 2)/x^{1/2}. Adding 1 and multiplying by x^{1/2}, we get T(x) = \Theta(5x^{1/2} - 2 log x - 4).
Master theorem have only constrains on your a and b which holds for your case. The fact that a is irrational and you have log(n) as your f(n) has no relation to it.
So in your case your c = log2(sqrt(2)) = 1/2. Since n^c grows faster than your log(n), the complexity of the recursion is O(sqrt(n)).
P.S. solution of Danyal is wrong as the complexity is not nlogn and the solution of Edward Doolittle is correct, also it is an overkill in this simple case.
As per master theorem, f(n) should be polynomial but here
f(n) = logn
which is not a polynomial so it can not be solved by master theorem as per rules. I read somewhere about the fourth case as well. I must mention that as well.
It is also discussed here:
Master's theorem with f(n)=log n
However, there is a limited "fourth case" for the master theorem, which allows it to apply to polylogarithmic functions.
If
f(n) = O(nlogba logk n), then T(n) = O(nlogba log k+1 n).
In other words, suppose you have T(n) = 2T (n/2) + n log n. f(n) isn't a polynomial, but f(n)=n log n, and k = 1. Therefore, T(n) = O(n log2 n)
See this handout for more information: http://cse.unl.edu/~choueiry/S06-235/files/MasterTheorem-HandoutNoNotes.pdf

Algorithm complexity, solving recursive equation

I'm taking Data Structures and Algorithm course and I'm stuck at this recursive equation:
T(n) = logn*T(logn) + n
obviously this can't be handled with the use of the Master Theorem, so I was wondering if anybody has any ideas for solving this recursive equation. I'm pretty sure that it should be solved with a change in the parameters, like considering n to be 2^m , but I couldn't manage to find any good fix.
The answer is Theta(n). To prove something is Theta(n), you have to show it is Omega(n) and O(n). Omega(n) in this case is obvious because T(n)>=n. To show that T(n)=O(n), first
Pick a large finite value N such that log(n)^2 < n/100 for all n>N. This is possible because log(n)^2=o(n).
Pick a constant C>100 such that T(n)<Cn for all n<=N. This is possible due to the fact that N is finite.
We will show inductively that T(n)<Cn for all n>N. Since log(n)<n, by the induction hypothesis, we have:
T(n) < n + log(n) C log(n)
= n + C log(n)^2
< n + (C/100) n
= C * (1/100 + 1/C) * n
< C/50 * n
< C*n
In fact, for this function it is even possible to show that T(n) = n + o(n) using a similar argument.
This is by no means an official proof but I think it goes like this.
The key is the + n part. Because of this, T is bounded below by o(n). (or should that be big omega? I'm rusty.) So let's assume that T(n) = O(n) and have a go at that.
Substitute into the original relation
T(n) = (log n)O(log n) + n
= O(log^2(n)) + O(n)
= O(n)
So it still holds.

Resources