Big-O/Big-Oh Notation Problem - big-o

I am going over the Big-Oh notation, and I have a problem understanding the solution to this question:
Is 2n + 10 ≡ O(n)?
Can we find c and n0?
2n + 10 <= cn
(c-2)n >= 10
n >= 10/(c-2)
Pick c = 3 and n0 = 10
There is also a graph used in this example:
I am confused as to how c = 3 and how n0 = 10? Can somebody please enlighten me?

I would solve 2n + 10 <= cn differently.
2n + 10 <= cn
2 + 10/n <= c //divide by n
c >= 2 + 10/n
Clearly c has to be bigger than 2. Now take your favorite number bigger than 2. Uhm. c=2.718. This gives
2n + 10 <= 2.718*n
10 <= 0.718*n //subtract 2n
13.93 <= n
Thus, 2n + 10 <= c*n. If we take c=2.718 and n bigger than 15. (15 because it's bigger than the limit, 13.93, and I like 15.)
Any c bigger than 2 works, c=100000000000000000000000 is fine too (but, it costs much ink and paper to write down.)
It might have been easier to take c=3. That would give
2n + 10 <= 3*n
10 <= n //subtract 2n
This makes 3 the most logical / natural solution.

To say a function f(n) is O(n) means you can find c and n0 such that for all n >= n0, f(n) <= cn.
To verify this in your case: if n >= 10, then:
f(n) = 2n + 10
<= 3n // because 10 <= n
= cn
So f(n) <= cn for all n >= 10, so f(n) is an O(n) function.
Note that other values for c and n0 work; you just need to find one pair.

In Big-O notation you drop numbers added and multiplied.
And also use the largest power.
10*N^3+ 23*N^2 + 43*N + 154 = O(N^3)

let f(n) = 2n+10
as per the Big-Oh notation,
f(n)<= c*g(n) ----->eq1(let)
2n+10 <= 2n+n
2n+10 <= 3n for n>=10 //here the constant 10 is replaced by n ---->eq2
comparing eq1 with eq2
c=3 and g(n)=n for value of n=10
f(n)= O(g(n)) = O(n)

Related

Is it always possible to find a constant K to prove big O or big Omega?

So I have to figure out if n^(1/2) is Big Omega of log(n)^3. I am pretty sure that it is not, since n^(1/2) is not even in the bounds of log(n)^3; but I do not know how to prove it without limits. I know the definition without limits is
g(n) is big Omega of f(n) iff there is a constant c > 0 and an
integer constant n0 => 1 such that f(n) => cg(n) for n => n0
But can I really always find a constant c that will satisfy this?
for instance for log(n)^3=>c*n^(1/2) if c = 0.1 and n = 10 then we get 1=>0.316.
When comparing sqrt(n) with ln(n)^3 what happens is that
ln(n)^3 <= sqrt(n) ; for all n >= N0
How do I know? Because I printed out sufficient samples of both expressions as to convince myself which dominated the other.
To see this more formally, let's first assume that we have already found N0 (we will do that later) and let's prove by induction that if the inequality holds for n >= N0, it will also hold for n+1.
Note that I'm using ln in base e for the sake of simplicity.
Equivalently, we have to show that
ln(n + 1) <= (n + 1)^(1/6)
Now
ln(n + 1) = ln(n + 1) - ln(n) + ln(n)
= ln(1 + 1/n) + ln(n)
<= ln(1 + 1/n) + n^(1/6) ; inductive hypethesis
From the definition of e we know
e = limit (1 + 1/n)^n
taking logarithms
1 = limit n*ln(1 + 1/n)
Therefore, there exits N0 such that
n*ln(1 + 1/n) <= 2 ; for all n >= N0
so
ln(1 + 1/n) <= 2/n
<= 1
Using this above, we get
ln(n + 1) <= 1 + n^(1/6)
<= (n+1)^(1/6)
as we wanted.
We are now left with the task of finding some N0 such that
ln(N0) <= N0^(1/6)
let's take N0 = e^(6k) for some value of k that we will are about to find. We get
ln(N0) = 6k
N0^(1/6) = e^k
so, we only need to pick k such that 6k < e^k, which is possible because the right hand side grows much faster than the left.

What is the proper way to prove the following question on asymptotic notation?

I have to prove that f(n)= 5n+2=O(n^2) and I know that it is true for O(n) so obviously, it will be true for a higher degree of n but how to prove this?
OK. Here is a simple way of proving this. I'm including it here in the hope that it could be useful for others with similar problems
5n + 2 <= 5n + 2n ; n >= 1
= 7n ; always
<= n*n ; n >= 7
= n^2 ; always
Therefore, there exists a constant c, in this case c=1, and an integer N, in this case N=7, such that
5n + 2 <= c*n^2 for all n >= N
Then, by definition
5n + 2 = O(n^2).
Note also that the first two lines
5n + 2 <= 5n + 2n ; n >= 1
= 7n ; always
are enough to show that 5n + 2 = O(n). In this case, c=7 and N=1.

Proving Big O notation

Prove 5n^2+ 2n -1 = O(n^2).
This is what I have attempted so far:
5n^2 + 2n -1 <= 5n^2 + 2n^2 -n2 for n>1
5n^2+ 2n -1 <= 6n^2 for n>1
5n^2+ 2n -1 = O(n^2) [ c = 6n^2, n0 = 1 ]
Is this the right way of proving Big O notation?
To prove that your expression is O(n^2), you need to show that it is bounded by M*n^2, for some constant M and some minimum n value. By inspection, we can show that your expression is bounded by 10*n^2, for n=10:
For n = 10:
5n^2 + 2n -1 <= 10*n^2
500 + 20 - 1 <= 1000
519 <= 1000
We can also show that the expression is bounded by 10*n^2 for any value n greater than 10:
For n > 10:
5n^2 + 2n -1 <= 10*n^2
5*(10+i)^2 + 2*(10+i) -1 <= 10*(10+i)^2
5*(i^2 + 20i + 100) + 2i + 19 <= 10*(i^2 + 20i + 100)
2i + 19 <= 5*(i^2 + 20i + 100)
2i + 19 <= 5i^2 + 100i + 500
5i^2 + 98i + 481 >= 0, which is true for `i > 0`
Here is a link to the Wikipedia article on Big-O notation:
https://en.m.wikipedia.org/wiki/Big_O_notation
Update:
Note that in practice in order to label your expression O(n^2) we won't resort to such an ugly written proof. Instead, we will just recognize that the n^2 term will dominate the expression for large n, and that the overall behavior will be O(n^2). And your expression is also O(n^3) (and O(n^4), etc.).
it looks fine , I'm thinking that if you are doing it for your assignment work or other formal work then you can also do it in more formal way like for selecting the value of constant ( c ) such as by f(n)/g(n).Otherwise it looks correct.
We have f(n) = 5*n^2+2*n-1 and g(n) = n^2
In order to prove f(n) = O(g(n)), we just need to find 2 constants, namely c > 0 and n_0, s.t. f(n) <= c.g(n) for all n >= n0.
Let's choose some value of c = 5.5 say. Let's evaluate and plot f(n) and c*g(n). As we can see from the plot and we can also show it theoretically since n^2/2 - 2*n + 1 = (n^2-4*n+2)/2 = ((n-2)^2-2)/2 >= 0 for all n >= 4, it implies that 5*n^2+2*n-1 <= 5.5*n^2 for all n >= n0 = 4. Hence, f(n) = O(g(n)). (proved)

Unable to udnerstand Big O notation examples

How they are calculating Big O notation?
Big O notation examples:
Question:
Find upper bound for f(n) = n⁴ + 100n² + 50
Solution:
n⁴ + 100n² + 50 <= 2n⁴, for all n >= 11
n⁴ + 100n² + 50 = O(n⁴) with c = 2 and n0 = 11
I am unable to understand - how they are calculating Big O notation?
How come c = 2 and n0 = 11
Question:
Find upper bound for f(n) = 2n³ - 2n²
Solution:
2n³ - 2n² <= 2n³ , for all n >= 1
2n³ - 2n² = O(2n³) with c = 2 and n0 =1
How come n >= 1?
Question:
f(n) = n
Solution :
n <= n , for all n >= 1
N = O(n) with c = 1 and n0 = 1
Question 1:
Definition of big O notation is (note that the wikipedia definition uses x0 and M, there is no real difference, just different signs for the same things).
f(n) is said to be in O(g(n)) if there are constants n0 and c such that for all n>n0 - f(n) <= c*g(n).
In your example, since n^4+100n^2+50 <= 2n^4 for all n>11, it is basically same as saying the above with c=2,n0=11 - thus, by definition of big O notation, you could say n^4+100n^2+50 is in O(n^4)
Question 2:
In here, n>=1 because the claim is true for all positive values of n - note that 2n^3-2n^2 will always be smaller than 2n^3 - for all positive values of n.

Problems solving - Asymptotic analysis

I am new with running time. I couldn't solve this one.
Given
f(n) = log n^2 and g(n) = log n + 5
prove
f(n) = theta(g(n)).
can anyone help me?
This is trivial. From basic logarithm properties
f(n) = log(n^2) = 2*log(n)
You need
C1*g(n) <= f(n) <= C2*g(n)
i.e.
C1*(log(n) + 5) <= 2*log(n) (1)
and
2*log(n) <= C2*(log(n) + 5) (2)
If you rewrite (1) as
C1*log(n) + C1*5 <= log(n) + log(n)
it looks like C1 == 1 would be a good choice, so we get:
log(n) + 5 <= log(n) + log(n)
5 <= log(n)
n >= 32
So we get for C1 == 1 and for each n >= 32, (1) holds.
For (2), it's obvious that you can choose C2 == 2. At the end you get
for each n >= 32
g(n) <= f(n) <= 2*g(n)
QED.

Resources