Finding constant C in Big-Oh notation - algorithm

I'm having trouble finding a constant C that works for the following problems:
18 n2 + 122 n = O( n2) find a C ≤ 50
11 n2 + 132 n + 390 = O( n2) find a C ≤ 20
"Using the definition of O, prove each part. Choose an explicit positive integer constant C within theindicated range and solve for a positive integer K which is as small as possible."
I understand that 18 n2 + 122 n <= c n2 , n >= k

Might as well just increment the coefficient on the dominant power, and use 19 and 12. Then:
18k² + 122k <= 19k²
⇔ 122k <= k²
⇔ k >= 122 or k <= 0
11k² + 132k + 390 <= 12k²
⇔ k² - 132k - 390 >= 0
You could use the quadratic formula for that one, but I would just start at k=133 and count upwards

Related

Asymptotic Notation: Finding two constants such that n >= n0

Here is an asymptotic notation problem:
Let g(n) = 27n^2 + 18n and let f(n) = 0.5n^2 − 100. Find positive constants n0, c1 and c2 such that c1f(n) ≤ g(n) ≤ c2f(n) for all n ≥ n0.
Is this solving for theta? Do I prove 27n^2 + 18n = Ω(0.5n^2 − 100) and then prove (27n^2 + 18n) = O(0.5n^2 − 100)?
In that case wouldn't c1 and c2 be 1 and 56 respectively, and n0 would be the higher of the two n0 that I find?
There are infinitely many solutions. We just need to fiddle with algebra to find one.
The first thing to note is that both g and f are positive for all n≥15. In particular, g(15) = 6345, f(15) = 12.5. (All smaller values of n make f<0.) This implies n0=15 might work fine as well as any larger value.
Next note g'(n) = 54n + 18 and f'(n) = n.
Since f(15) < g(15) and f'(n) < g'(n) for all n >= 15, choose c1 = 1.
Proof that this is a good choice:
0.5n^2 − 100 ≤ 27n^2 + 18n <=> 26.5n^2 + 18n + 100 ≥ 0
...obviously true for all n≥15.
What about c2? First, we want c2*f(n) to grow at least as fast as g: c2f'(n)≥g'(n), or c2*n ≥ 54n + 18 for n ≥ 15. So choose c2 ≥ 56, which obviously makes this true.
Unfortunately, c2=56 doesn't quite work with n0 = 15. There's the other criterion to meet: c2*f(15)≥g(15). For that, 56 isn't big enough: 56*f(15) is only 700; g(15) is much bigger.
It turns out by substitution in the relation above and a bit more algebra that c2 = 508 does the trick.
Proof:
27n^2 + 18n ≤ 508 * (0.5n^2 − 100)
<=> 27n^2 + 18n ≤ 254n^2 − 50800
<=> 227n^2 - 18n - 50800 ≥ 0
At n=15, this is true by simple substitution. For all bigger values of n, note the lhs derivative 454n - 18 is positive for all n≥15, so the function is also non-decreasing over that domain. That makes the relation true as well.
To summarize, we've shown that n0=15, c1=1, and c2=508 is one solution.

Proving Big-Omega Function

I am trying to prove that a function is in Ω(𝑛^3), however the constant C is fixed to 3.
The function is:
𝑓(𝑛) = 3𝑛^3 − 39𝑛^2 + 360𝑛 + 20
In order to prove that 𝑓 is Ω(𝑛^3), we need constants 𝑐, 𝑛_0 > 0 such that
|𝑓(𝑛)| ≥ C|𝑛^3|
for every 𝑛 ≥ 𝑛_0.
When plugging in C = 3, you would get the inequality
3𝑛^3 − 39𝑛^2 + 360𝑛 + 20 ≥ 3𝑛^3
which would equal
−39𝑛^2 + 360𝑛 + 20 ≥ 0
I'm stuck here, because I can't find an n_0 that satisfies the equation for every 𝑛 ≥ 𝑛0.
Also, if c = 2.25 fixed, how do I find the smallest integer that satisfies n_0 ?
How to prove it in general
Proving 𝑓 in Ω(𝑛^3) with 𝑓(𝑛) = 3𝑛^3 − 39𝑛^2 + 360𝑛 + 20 is pretty simple.
The exact definition (from Wikipedia) is:
In words you need to find a constant c such that c * g will always be smaller than f (from a given n_0). You are of course allowed to choose this c small and the n_0 big.
We first drop some unnecessary stuff in order to estimate f:
−39𝑛^2 is greater than -n^3 for all n >= 39
360𝑛 is obviously greater than 0
20 is also greater than 0
Okay, putting that together we receive:
f(n) >= 3n^3 - n^3 + 0 + 0
= 2n^3
for n >= 39.
We choose C = 2 (or something smaller), n_0 = 39 (or something greater) and follow that
C * |g(n)| = 2 * |n^3| <= |2 * n^3| <= |f(n)|
<=> C * |g(n)| <= |f(n)|
for all n > n_0. By definition this means 𝑓 in Ω(𝑛^3).
Your specific scenario
For C = 3 fixed this is obviously not possible since 3 * n^3 is always greater than 3𝑛^3 − 39𝑛^2 + 360𝑛 + 20 (for some n_0). This is due to the second summand −39𝑛^2.
Take a look at the plot:
You see that 3n^3 grows beyond f, for all n >= n_0 with n_0 at about 9.286. The exact value is:
n >= (2 / 39) * (90 + 8295^(0.5))
Here is the query at Wolfram Alpha.
But it is possible for a fixed C = 2.25 as you can see at this query. It is true for all n >= 40.

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)

Is my explanation about big o correct in this case?

I'm trying to explain to my friend why 7n - 2 = O(N). I want to do so based on the definition of big O.
Based on the definition of big O, f(n) = O(g(n)) if:
We can find a real value C and integer value n0 >= 1 such that:
f(n)<= C . g(n) for all values of n >= n0.
In this case, is the following explanation correct?
7n - 2 <= C . n
-2 <= C . n - 7n
-2 <= n (C - 7)
-2 / (C - 7) <= n
if we consider C = 7, mathematically, -2 / (C - 7) is equal to negative infinity, so
n >= (negative infinity)
It means that for all values of n >= (negative infinity) the following holds:
7n - 2 <= 7n
Now we have to pick n0 such that for all n >= n0 and n0 >= 1 the following holds:
7n - 2 <= 7n
Since for all values of n >= (negative infinity) the inequality holds, we can simply take n0 = 1.
You're on the right track here. Fundamentally, though, the logic you're using doesn't work. If you are trying to prove that there exist an n0 and c such that f(n) ≤ cg(n) for all n ≥ n0, then you can't start off by assuming that f(n) ≤ cg(n) because that's ultimately what you're trying to prove!
Instead, see if you can start with the initial expression (7n - 2) and massage it into something upper-bounded by cn. Here's one way to do this: since 7n - 2 ≤ 7n, we can (by inspection) just pick n0 = 0 and c = 7 to see that 7n - 2 ≤ cn for all n ≥ n0.
For a more interesting case, let's try this with 7n + 2:
7n + 2
≤ 7n + 2n (for all n ≥ 1)
= 9n
So by inspection we can pick c = 9 and n0 = 1 and we have that 7n + 2 ≤ cn for all n ≥ n0, so 7n + 2 = O(n).
Notice that at no point in this math did we assume the ultimate inequality, which means we never had to risk a divide-by-zero error.

Big-O/Big-Oh Notation Problem

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)

Resources