Asymptotic Practices - algorithm

I try to find Big-O, Big-Ω and Big-Θ of the following equations:
1. n + 5n^0.5
2. 3n^2 + 5n + 1
If I correctly understood the difference between them, then my results came out like this.
1. n + 5n^0.5
Big-O: let g(n)=6n, then f(n)<=c*g(n), n+5n^0.5<=c*6n,
f(n)=O(n).
Big-Ω: f(n)>=c*g(n), then n + 5n^0.5>=c*n, f(n)=Ω(n).
Big-Θ: c1*g(n)<=f(n)<=c2*g(n), c1*n<=n+5n^0.5<=c2*6n,
f(n)=Θ(n) and c1=1, c2=6.
2. 3n^2 + 5n + 1
Big-O: 3n^2+5n+1<=c*n^2, 3n^2+5n^2+n^2<=c*n^2, 3n^2+5n+1<=9*n^2, f(n)=O(n^2).
Big-Ω: f(n)>= c*g(n), 3n^2+5n+1>=c*n^2, f(n)=Ω(n^2).
Big-Θ: c1*g(n)<=f(n)<=c2*g(n), 3n^2+5n+1<=c2*n^2, n^2<=3n^2+5n+1<=9n^2, f(n)=Θ(n^2) and c1=1, c2=9.
Please tell me if I'm on the right way? Any advice is very important to me. Thank you.

Related

Solve the recurrence relations using the guess and check method

I've got a problem where I forgot how to do recurrence relations and I'm not really sure what the guess and check method is. Does anyone know how to solve them using that method and if so a nice explanation would be appreciated.
2. Solve the following recurrence relation from guess and check method.
a. T(n) = T(n/2) + T(n/3) + T(n/10) + c n where c is a constant.
T(small number) = another small number.
b. T(n) = T(n/2) + T(n/3) + T(n/4) + T(n/5) + d n where d is a constant
T(small number) = another small number.
The guess method works by figuring out a possible answer and testing it. For a., if the function T does not grow too slowly, the T on the left could follow the last, linear term. So we try T(n) = an.
an = an/2 + an/3 + an/10 + cn
which indeed gives the solution
a = 15c.
For b., this fails as we get a negative coefficient, and we are a little stuck. We can try a larger power of n to increase the growth, and try an^α:
an^α = an^α/2^α + an^α/3^α + an^α/4^α + an^α/5^α + cn
After simplification,
1 = 1/2^α + 1/3^α + 1/4^α + 1/5^α + c/a n^(1-α)
Now by numerical resolution, we observe that with α = 1.2348, we have
0 ~ c/a n^(1-α)
which gives us an asymptotic solution.

Computational Complexity - 1^n + n^4 + 4n + 4

Could someone please explain what the correct answer should be:
Question = What is the complexity of 1^n + n^4 + 4n + 4?
Options = Exponential, Polynomial, Linear, Constant
My interpretation:
Answer should be exponential, because law of addition for O() is that the answer is the dominant term, which imo would be 1^n aka c^n (c = constant) aka exponential. But the answer is wrong and I don't get it :(
Well 1^n is always 1. Therefore, 1^n + n^4 + 4n + 4 can be simplified to 1 + n^4 + 4n + 4. Consequently, O(n^4).
So the correct answer is Polynomial.

How to prove using big-O

Im currently having a problem with big O notation. I have the following question which I am trying to figure out.
I currently have the formula: T(n) is O(f(n)) and I must use this to prove directly from the definition of big O that 3n^2+11n+6 is O(n^2).
I was wondering if anybody could possibly help me figure out this problem as I am having trouble working it out.
I think this may help:
For n≥k, there is a constant, let's name it "c" which satisfies 3n^2 + 11n + 6 ≤ c∗n^2.
Let's say we pick k = 1.
We know that n^2 ≥ n^2 ≥ n ≥ 1
So :
3n^2 + 11n + 6 ≤ 3n^2 + 11n^2 + 6n^2 =>3n^2 + 11n + 6 ≤ 20n^2
Now, let c = 20.
=>complexity is O(n2).

Recurence related to master theorem T(n)=T(n^(1/2))+1

In masters theorem were given a "plug-in" formula to find the big O, given it satisfies some condition.
However, what if we have problems like the following below? Can anyone show me how to do a step by step formula. And what topics would help me to know more about these types of questions. Assume that the person asking this question knows nothing about induction.
T(n)=T(n^(1/2))+1
T(n)=T(n-1) + 1
T(n)=T(n-1) + n^c , c is a natural number >1
T(n)= T(n-1) C^n, c is a natural number >1
You'll need to know a little math to do some of these. You can figure out what the recursion looks like when you expand it out all the way to the base case, e.g. for T(n) = T(n-1) + n^c you get T(n) = 1^c + 2^c + ... + n^c, but then you need to know some math in order to know that this is O(n^(c+1)). (The easiest way to see this is by bounding the sum above and below in terms of integrals of x^c). Similarly for T(n) = T(n-1) + c^n you easily get T(n) = c^1 + c^2 + ... + c^n but you again need to use some calculus or something to figure out that this is T(n) = O(c^n).
For T(n) = T(n^(1/2)) + 1 you need to count how many times you apply the recurrence before you get to the base case. Again math helps here. When you take square-root, the logarithm gets cut in half. So you want to know how many times you can cut the logarithm in half until you get to the base case. This is O(log log n).
You can expand upon the formula and work on it:
For example:
T(n) = T(n-1) + 1
T(n) = [T(n-2) + 1] + 1
...
T(n) = 1 + 1 + 1 ... (n times)
So T(n) = O(n).

Substitution method for solving recurrences

First of all sorry for asking such a basic question.
But I am having difficulties understanding substitution method for solving recurrences.I am following Introduction to Algo.s -CLRS. As I am not able to find enough examples and ambiguity is the main concern.Especially the induction step.In the text books we have to prove f(n) implies f(n+1) but in CLRS this step is missing or may be I am not getting the example. Please explain step by step how to prove that O(n^2) is the solution for recurrence function T(n)=T(n-1)+n
Its the general steps of substitution method that I want to understand. If you could shed some light on strong mathematical induction and provide links to material on substitution method that'll be helpful also.
In substitution method, simply replace any occurance of T(k) by T(k-1) + k, and do it iteratively.
T(n) = T(n-1) + n =
= (T(n-2) + (n-1)) + n =
= T(n-3) + (n-2) + (n-1) + n =
= ... =
= 1 + 2 + ... + n-1 + n
From sum of arithmetic progression, you can get that T(n) is in O(n^2).
Note that substitution method is usually used to get an intuition on what the complexity is, to formally prove it - you will probably need a different tool - such as mathematical induction.
The formal proof will go something like that:
Claim: T(n) <= n^2
Base: T(1) = 1 <= 1^2
Hypothesis: the claim is true for each `k < n` for some `n`.
T(n) = T(n-1) + n <= (hypothesis) (n-1)^2 + n = n^2-2n + 1 < n^2 (for n > 1)

Resources