I'm trying to understand how to determine the runtime complexity given such a recurrence relation: T(n) = 2T(n-1) - T(n-2) + 8n + 7
I'm clueless about the minuses in the T's and all I know that it has nothing to do with master's theorem. I didn't find any explanation so far so any help would be appriciated.
Related
I need to solve the recursion problem:
T(n) = T(n/2) + log^2(n)
when we call for n element we have log^2(n) actions (except the recursive actions) and so on until we call for 2 element and we have 1 action.
how do I calculate the T(n) running time?
this is SO, it's not the place to put a runtime question.
however, since it's already here, i'm gonna answer that, and probably get -5
the running time is O(log(n)). that's because calculating log^2(n) will take O(1), so that's insignificant for the run time. so we have
T(n) = T(n/2)
and that's a classic O(log(n))
I am trying to find the runtime of the equation;
T(n) = T(n-2) + n³.
When I am solving it I arrive at the summation T(n) = T(n-k) + Σk = 0,...,n/2(n-2k)³.
Solving that sum I get 1/8(n²)(n + 2)². Solving this I would get the runtime to be Θ(n⁴).
However, I think I did something wrong, does anyone have any ideas?
Why do you think that it is wrong? This equation is clearly Theta(n^4)
The more detailed solution can be obtained from WolframALpha (did you know it solves recurrence equations?)
https://www.wolframalpha.com/input/?i=T%28n%29%3DT%28n-2%29%2Bn%5E3
You can also add some border cases, like T(0)=T(1)=1
https://www.wolframalpha.com/input/?i=T%28n%29%3DT%28n-2%29%2Bn%5E3%2C+T%281%29%3D1%2C+T%282%29%3D1
and finally: asymptotic plot, showing that it truly behaves like n^4 function
Here is an attempt to show your recursive recursive recurrence with steps:
With WolframAlpha engine solving the summation.
I'm trying to solve this recursive function but i reached a dead end:
T(n) = 4T(n/2) + n(logn)^2
I tried the master rule (with the 3 cases) and non of the cases applied. I also tried iteration method and got a complex equation...
Can anybody give me a final solution or a method how to solve it?
Thank you
i try to calculate the complexity from Mergesort.
Standard Mergesort has the recursion T(n) = T(n/2)+T(n/2)+n
So its easy to calculate with the Master-theorem.
But my question is, how to calculate a Mergesort with T(n) = T(2n/3) + T(n/3) + n
and T(n) = T(n-100) + T(100) ?
Can you help me guys?
Thanks =)
this two examples are the textbook examples of calculating the recursive equations .
for solving them you need to use "The Recursion Tree" method .
I know that the answer to the first condition is theta(nlogn) and the answer to the second one is theta(n^2) . now to find the solutions , I think you can get a pretty good perspective of The recursion tree in the Introduction to algorithms , CLRS .
I was going to meet with my TA today but just didn't have the time. I am in an algorithms analysis class and we started doing recurrence relations and I'm not 100% sure if I am doing this problem correct. I get to a point where I am just stuck and don't know what to do. Maybe I'm doing this wrong, who knows. The question doesn't care about upper or lower bounds, it just wants a theta.
The problem is this:
T(n) = T(n-1) + cn^(2)
This is what I have so far....
=T(n-2) + (n-1)^(2) + cn^(2)
=T(n-3) + (n-2)^(2) + 2cn^(2)
=T(n-4) + (n-3)^(2) + 3cn^(2)
So, at this point I was going to generalize and substitute K into the equation.
T(n-k) + (n-k+1)^(2) + c(K-1)^(2)
Now, I start to bring the base case of 1 into the picture. On a couple of previous, more simple problems, I was able to set my generalized k equation equal to 1 and then solve for K. Then put K back into the equation to get my ultimate answer.
But I am totally stuck on the (n-k+1)^(2) part. I mean, should I actually foil all this out? I did it and got k^(2)-2kn-2k+n^(2) +2n +1 = 1. At this point I'm thinking I totally must have done something wrong since I've never see this in previous problems.
Could anyone offer me some help with how to solve this one? I would greatly appreciate it.
What you have isn't fully correct even at the first line of "what I have so far".
Go ahead and do the full substitutions, to see that:
T(n-1) = T(n-2) + c(n-1)^2
so
T(n) = T(n-2) + c(n-1)^2 + c(n)^2
T(n) = T(n-3) + c(n-2)^2 + c(n-1)^2 + c(n)^2
Overall running time looks like adding "c(n-i)^2" for each value of i from 0 to your base case. Hopefully that puts you on the right track.