Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Find the tight asymptotic bound:
T(n) = 1 if n = 1
2T(n/4) + T(n/2) + n2 if n > 1
I tried drawing a recurrence tree. First row I had n2, second row I had (3/8)(n4), third row I had (27/1024)(n8).. Don't know how to continue from there.
Thanks in advance.
I think the Master Theorem can be applied in this problem. It is much easier to understand than recurrence tree.
Write the recurrence formula in another form. Add T(n/2) to both the left and right side.
T(n) + T(n/2) = + 2T(n/4) + 2T(n/2) + n2
T(n) + T(n/2) = + 2[ T(n/4) + T(n/2) ] + n2
Define G(n) = T(n) + T(n/2), then
G(1) = Θ(1)
G(n) = 2G(n/2) + n2, if n > 1
Apply the Master Theorem to the above new recurrence formula
G(n) = Θ(n2)
that is
T(n) + T(n/2) = Θ(n2)
for n > 1
T(n) = 2 * T(n/4) + T(n/2) + n2
= T(n/4) + [ T(n/2) + T(n/4) ] + n2
= T(n/4) + Θ(n2/4) + n2
= T(n/4) + Θ(n2)
Apply the Master Theorem to the above new recurrence formula
T(n) = Θ(n2)
Related
I watched a video where they prove T(n)= T(n-1) + n is O(n^2)
I have the following expressions which are:
T(1) = 4
T(N) = T(N – 1) + N + 3, N > 1
My question is, is the expression above solved the same way, even though there is a +3 after N.
The question is a bit messed up, but i hope you get the point. If there are questions i will try to explain better.
In a word is T(N) = T(N – 1) + N + 3 = O(n^2)
T(n) = T(n-1) + n-1 + 4 => given equation by adding 1 and subtracting 1
T(n) = T(n-1) + n-1 + T(1) ...(1)
Now, T(1) = constant.
Therefore, from eq(1),
T(n) = T(n-1) + (n-1) ...(2)
Eq(2) reduces to T(n) = T(n-k) + n*k - k*(k+1)/2 ...(3)
Upon substituting (n-k)=1 or k=(n-1) in eq(3),
we get,
T(n) = T(1) + n*(n-1) - (n-1)(n)/2
T(n) = n*(n-1)/2 => O(n^2)
PS: If we won't neglect T(1) in eq(1), final equation we get is T(n) = n*(n-1)/2 + T(1) + 4*k => T(n) = n*(n-1)/2 + 4 + 4*(n-1) which still gives O(n^2) as final answer.
next days I will have my exam on algorithms, the professor asked us to learn how to find O(n) of equations at this form:
T(n) = T(n/3) + T(n/4) + 5n
T(n) = T(n/3) + 2T(n/4) + 5n
T(n) = T(n/3) + T(n/4) + 15n
T(n) = 2T(n/3) + T(n/4) + 4n
I know how to use master theorem but I doubt I can use it somehow here. My professor also hasn't showed us even one example on how to solve this, on google I couldn't find much (or didn't know how to find a solution - how to search for it) so is it possible someone show me how to solve the aboves step by step?
Thanks in advance.
PS: Sorry about the probably wrong title, as I said, I don't know how exactly to present what I want.
As mentioned in the comment, because T(n/3) > T(n/4) you can find an upper bound for each of the above equations (this condition is true for increasing T(n)).
T(n) = T(n/3) + T(n/4) + 5n => T(n) < 2T(n/3) + 5n =>(using master theorem) T(n) = O(n)
Also, we can say T(n) = \Theta(n) as because of 5n we can say T(n) = \Omega(n).
T(n) = T(n/3) + 2T(n/4) + 5n => T(n) < 3T(n/3) + 5n =>(using master theorem) T(n) = O(nlog(n))
T(n) = T(n/3) + T(n/4) + 15n => T(n) < 2T(n/3) + 15n =>(using master theorem) T(n) = O(n)
T(n) = 2T(n/3) + T(n/4) + 4n => T(n) < 3T(n/3) + 4n =>(using master theorem) T(n) = O(nlog(n))
How do I determine the running time (in terms of Big-Theta) for the algorithm of input size n that satisfies recurrence relation T(n) = T(n-1)+n where n >= 1 and with initial condition T(1) = 1?
Edit: I was practicing a past exam paper. Got stuck on this question. Need guidance
Look at it this way: T(n) = T(n-1) + n = T(n-2) + (n-1) + n = T(n-3) + (n-2) + (n-1) + n. Which means if n >= 1 then you will get something like T(n) = 1 + 2 + 3 + ... + n. If you work out the pattern of this series you will see that (n+1)n/2. Therefore, Ө(n^2)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
See title. I'm trying to apply the method from this question: Easy: Solve T(n)=T(n-1)+n by Iteration Method. What I have so far is this, but I don't know how to proceed from here on:
T(n) = T(n-1) + n2
T(n-1) = T(n-2) + (n-1)2 = T(n-2) + n2 - 2n + 1
T(n-2) = T(n-3) + (n-2)2 = T(n-3) + n2 - 4n + 4
T(n-3) = T(n-4) + (n-3)2 = T(n-4) + n2 - 6n + 9
Substituting the values of T(n-1), T(n-2) and T(n-3) into T(n) gives:
T(n) = T(n-2) + 2n2 - 2n + 1
T(n) = T(n-3) + 3n2 - 6n + 5
T(n) = T(n-4) + 4n2 - 12n + 14
Now I have to find a pattern but I don't really know how to do that. What I got is:
T(n) = T(n-k) + kn2 - ...???
I'd start with a guess that since each T (n) is equal to the previous one plus a square, T (n) is something cubic.
Write T (n) = an^3 + bn^2 + cn + d.
Substitute this into T (n) = T (n - 1) + n^2 and solve for a, b, c.
And obviously T (0) = d.
If you combine the equations you yourself write:
T(n)=
=n^2+T(n-1)=
=n^2+(n-1)^2+T(n-2)=
=n^2+(n-1)^2+(n-2)^2+T(n-3)=
=n^2+(n-1)^2+(n-2)^2+(n-3)^2+...+2^2+1^2+T(0)=
=n(n+1)(2n+1)/6+T(0) //based on well known formula for S(x^2, x=1..n)
I have been trying to solve a recurrence relation.
The recurrence is T(n) = T(n/3)+T(2n/3)+n^2
I solved the the recurrence n i got it as T(n)=nT(1)+ [ (9/5)(n^2)( (5/9)^(log n) ) ]
Can anyone tell me the runtime of this expression?
I think this recurrence works out to Θ(n2). To see this, we'll show that T(n) = Ω(n2) and that T(n) = O(n2).
Showing that T(n) = Ω(n2) is pretty straightforward - since T(n) has an n2 term in it, it's certainly Ω(n2).
Let's now show that T(n) = O(n2). We have that
T(n) = T(n / 3) + T(2n / 3) + n2
Consider this other recurrence:
S(n) = S(2n / 3) + S(2n / 3) + n2 = 2S(2n / 3) + n2
Since T(n) is increasing and T(n) ≤ S(n), any upper bound for S(n) should also be an upper-bound for T(n).
Using the Master Theorem on S(n), we have that a = 2, b = 3/2, and c = 2. Since logb a = log3/2 2 = 1.709511291... < c, the Master Theorem says that this will solve to O(n2). Since S(n) = O(n2), we also know that T(n) = O(n2).
We've shown that T(n) = Ω(n2) and that T(n) = O(n2), so T(n) = Θ(n2), as required.
Hope this helps!
(By the way - (5 / 9)log n = (2log 5/9)log n = 2log n log 5/9 = (2log n)log 5/9 = nlog 5/9. That makes it a bit easier to reason about.)
One can't tell about runtime from the T(n) OR the time complexity!It is simply an estimation of running time in terms of order of input(n).
One thing which I'd like to add is :-
I haven't solved your recurrence relation,but keeping in mind that your derived relation is correct and hence further putting n=1,in your given recurrence relation,we get
T(1)=T(1/3)+T(2/3)+1
So,either you'll be provided with the values for T(1/3) and T(2/3) in your question OR you have to understand from the given problem statement like what should be T(1) for Tower of Hanoi problem!
For a recurrence, the base-case is T(1), now by definition its value is as following:
T(1) = T(1/3) + T(2/3) + 1
Now since T(n) denotes the runtime-function, then the run-time of any input that will not be processed is always 0, this includes all terms under the base-case, so we have:
T(X < 1) = 0
T(1/3) = 0
T(2/3) = 0
T(1) = T(1/3) + T(2/3) + 1^2
T(1) = 0 + 0 + 1
T(1) = 1
Then we can substitute the value:
T(n) = n T(1) + [ (9/5)(n^2)( (5/9)^(log n) ) ]
T(n) = n + ( 9/5 n^2 (5/9)^(log n) )
T(n) = n^2 (9/5)^(1-log(n)) + n
We can approximate (9/5)^(1-log(n)) to 9/5 for asymptotic upper-bound, since (9/5)^(1-log(n)) <= 9/5:
T(n) ~ 9/5 n^2 + n
O(T(n)) = O(n^2)