Recursive Runtime of T(n-k) - recursion

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.

Related

Big-Oh Comparison (mathematically)

I have this exercise to solve:
EX) You have 2 algorithms. The first one is O(n) on best case, and O(n^3) on the worst case, and the another one is O(n^2) on both cases. Suppose that the best case happens 90% of the time. Which one would you choose?
I know that from some n, 90%*O(n) + 10%*O(n^3) > 100%*O(n^2). But, how can I prove that mathematically?
Thanks in advance!
To have a basic impression, try solving the equation 0.9*n+0.1*n^3>n^2.
thanks for answering.
To compare algorithms we must analyze the 'often case', or 'medium case', if you prefer. So, we can reach formulas for both, that is:
a) 0.9n + 0.1n^3
b) 0.5n^2 + 0.5n^2.
Now we can compare both. If there is any n>0 that 0.9n + 0.1n^3 > n^2, b algorithm is better.
Thanks!

solving a recurrence: T(n) = 4T(n/2) + n(logn)^2

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

How to calculate complexity from special Mergesort

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 .

Having issues dealing with T(n) runtime problems

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.

Write a function to solve a simple linear equation

I need to know how to write a function to solve a simple linear equation like 2x +1 = 5. How would one do this? If anyone can show some code or point me to a site, it would be much appreciated.
How is the equation entered? In text-form? As coefficients?
ax + b = c of course has the solution x = (c - b) / a.
For parsing, you could use regular expressions.
Parse the expression into a simple tree, then use basic math to solve it. I'd start by converting it to postfix notation and then evaluating that.

Resources