Big-Oh ascending order of some functions f(n) - algorithm

Put these function in the ascending order of their growth in terms of n:
2^((log n)^0.5), 2^n, 2^(n/2), n^(4/3), n(log n)^3, n^(log n), 2^(n^2), n!

The way you solve this problem is by seeing which function approaches infinity fastest as n approaches infinity. Suppose you have some functions:
f(n) = n!
g(n) = n
h(n) = 3^n
You can compare any two functions by evaluating their ratio as n approaches infinity. For example:
Lim f(n) /
n->∞ / g(n)
If the result is greater than 1, then f(n) is asymptotically greater than g(n). If the result is 1, then they are asymptotically the same. If the result is less than one, then f(n) is asymptotically less than g(n).
You may find that some are easy to solve, like f(n) and g(n), and you can simplify the expression to get a definite value at the limit.
f(n) / = n! / = n (n-1)! / = (n-1)!
/ g(n) / n / n
The limit as n goes to infinity of this expression is infinity, which means that f(n) is asymptotically greater than g(n).
Other expressions are not as simple. If evaluating the limit gives you an indeterminite form, you need to use L'Hôpital's rule.
Lim g(n) / = Lim n / = ∞ /
n->∞ / h(n) n->∞ / 3^n / ∞
According to L'Hôpital's rule, we can evaluate a limit by substituting g'(n) and h'(n).
Lim g'(n) / = Lim 1 / = 1 /
n->∞ / h'(n) n->∞ / 3^n ln(3) / ∞
This limit is clearly less than 1, so we can say that g(n) is asymptotically less than h(n).

Partial answer: 2^((log n)^0.5), 2^(n/2), 2^n, n!, 2^(n^2).
Need to put these as well: n^(4/3), n(log n)^3, n^(log n)

Related

Which pair of functions satisfy f(N) ∼ g(N)?

a. f(N) = N and g(N) = N + N2
b. f(N) = 2N and g(N) = √N
c. f(N) = NlogN + N and g(N) = 2NlogN + N
d. f(N) = 2√N + N and g(N) = √N + N
What is the best way of calculating these functions, I have tried putting values into them, but some of them are very close in values and I am not sure which one to pick.
Calculate f(N)/g(N) in the limit N➡Infinity.
If f(N)/g(N) approaches a positive constant 𝛼 in the limit N➡Infinity, then f(N) ~ 𝛼 g(N).

determine Big-Oh / Big-Theta or Big-Omega

Given f(n) = n^[(1+sin(n*pi/2))/2] and g(n) = n^0.5
, how do I prove that f(n) = O(g(n)) / f(n) = Omega(g(n)) / f(n) = Theta(g(n)).
I have worked out that f(n) doesn't seem to have a bound as the function grows bigger and smaller as n grows big.... (i plotted the graph here)
https://www.desmos.com/calculator/xtrh124rjb
So How would one justify which does it belong to ?
Or does it belong to neither of them since it doesn't have a bound at all....?
Consider the sequence 1, 5, 9, …, 4k + 1, … For these values of n, (1 + sin(n * pi / 2)) / 2 = 1. Therefore, for these values of n, your function is identical to the function A(n) = n^1 = n. Note that A(n) = n is NOT O(g(n)) = O(n^0.5); n grows asymptotically faster than n^0.5.
Consider the sequence 3, 7, 11, …, 4k + 3, … For these values of n, (1 + sin(n * pi / 2)) / 2 = 0. Therefore, for these values of n, your function is identical to the function B(N) = n^0 = 1. Note that B(n) = 1 is NOT Omega(g(n)) = Omega(n^0.5); n^0.5 grows asymptotically faster than the constant 1 (which doesn't grow at all).
Either f(n) not being O(g(n)) OR f(n) not being Omega(g(n)) would have already disqualified f(n) from being Theta(g(n)).
Note: f(n) = O(A(n)) and f(n) = O(B(n)). f(n) = Theta(h(n)) where h(n) is any function which oscillates like f(n) and which grows at least as fast and which has a constant lower bound.

How to prove the complexity of a logarithmic function?

Let's say you were given two logarithmic functions like
and you were asked to find if f(n) is O(g(n)) Ω(g(n)) or Θ(g(n)), how would you go about it? I found questions like these easier when you were comparing two exponential equations, because for example with x(n) = n^2 and p(n) = n^2 you could find a c > 0 (ex 3) where x(n) <= cp(n) for all n greater than some n>0 and that would prove that x(n) = O(p(n)). However, comparing two logarithmic functions seems much more difficult for some reason. Any help is appreciated, thanks!
f(n) is O(g(n)) iff there is a constant c and n_0 such that f(n) <= c * g(n) for each n >= n_0.
f(n) is Ω(g(n)) iff there is a constant c and n_0 such that f(n) >= c * g(n) for each n >= n_0.
Now, f(n) is Θ(g(n)) iff f(n) is O(g(n)) and f(n) is Ω(g(n)).
So, in your cases, we have:
f(n) = log (n^2) = 2logn
which means, g(n) is logn and c = 2, which means f(n) <= 2 * logn and f(n) >= 2 * logn, which makes it Ω(logn).
Btw. its also f(n) <= n and f(n) >= 1, so f(n) can be O(n), but we don't use it, since we can find a better O(g(n)). In this case we don't have the same function in both notations, to for those values we don't have Ω. However, we just need one option for g(n) to declare Ω. In cases we can't find it, we say its not Ω. Note the word "we say".
In second case, we care only for "highest growing value", logn part. Now, c = 1, and g = log(n), so in this case, its also Ω(logn).

if log n^2 is big theta of log n , is (logn)^2 also big theta of logn?

log n^2 is equivalent to 2logn which grows at the same rate as logn, as I disregard the factors and constants. but if I was to square the whole term so that I end up with (logn)^2 is it also big theta of logn?
No. If f is any unbounded function then f(n)^2 is not O(f).
Because f(n)^2 = O(f) means there's a c and N such that n > N implies f(n)^2 <= cf(n). Which implies f(n) <= c, and so f is bounded.
log(n) is unbounded, so log(n)^2 is not O(log(n)).
log (n^2) = 2 log(n)
and as you know x^2 is not in thetha(x).
Think this way: let N=log(n). Then f1(N)=N^2 where f2(N)=N, obviously,
N=o(N^2)!=theta(N^2), i.e., log(n)=o((log(n))^2)!=theta((log(n))^2).
Also, lim {n->inf} f2(n) / f1(n) = lim {n->inf} 1 / log(n) = 0, by definition of small o (https://en.wikipedia.org/wiki/Big_O_notation) it implies f2(n)=o(f1(n)).

Proving if g(n) is o(f(n)), then f(n) + g(n) is Theta(f(n))

So I'm struggling with proving (or disproving) the above question. I feel like it is true, but I'm not sure how to show it.
Again, the question is if g(n) is o(f(n)), then f(n) + g(n) is Theta(f(n))
Note, that is a little-o, not a big-o!!!
So far, I've managed to (easily) show that:
g(n) = o(f(n)) -> g(n) < c*f(n)
Then g(n) + f(n) < (c+1)*f(n) -> (g(n) + f(n)) = O(f(n))
However, for showing Big Omega, I'm not sure what to do there.
Am I going about this right?
EDIT: Everyone provided great help, but I could only mark one. THANK YOU.
One option would be to take the limit of (f(n) + g(n)) / f(n) as n tends toward infinity. If this converges to a finite, nonzero value, then f(n) + g(n) = Θ(f(n)).
Assuming that f(n) is nonzero for sufficiently large n, the above ratio, in the limit, is
(f(n) + g(n)) / f(n)
= f(n) / f(n) + g(n) / f(n)
= 1 + g(n) / f(n).
Therefore, taking the limit as n goes to infinity, the above expression converges to 1 because the ratio goes to zero (this is what it means for g(n) to be o(f(n)).
So far so good.
For the next step, recall that in the best case, 0 <= g(n); this should get you a lower bound on g(n) + f(n).
Before we begin, lets first state what little-o and Big-Theta notations means:
Little-o notation
Formally, that g(n) = o(f(n)) (or g(n) ∈ o(f(n))) holds for
sufficiently large n means that for every positive constant ε
there exists a constant N such that
|g(n)| ≤ ε*|f(n)|, for all n > N (+)
From https://en.wikipedia.org/wiki/Big_O_notation#Little-o_notation.
Big-Θ notation
h(n) = Θ(f(n)) means there exists positive constants k_1, k_2
and N, such that k_1 · |f(n)| and k_2 · |f(n)| is an upper bound
and lower bound on on |h(n)|, respectively, for n > N, i.e.
k_1 · |f(n)| ≤ |h(n)| ≤ k_2 · |f(n)|, for all n > N (++)
From https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-big-theta-notation.
Given: g(n) ∈ o(f(n))
Hence, in our case, for every ε>0 we can find some constant N such that (+), for our functions g(n) and f(n). Hence, for n>N, we have
|g(n)| ≤ ε*|f(n)|, for some ε>0, for all n>N
Choose a constant ε < 1 (recall, the above holds for all ε > 0),
with accompanied constant N.
Then the following holds for all n>N
ε(|g(n)| + |f(n)|) ≤ 2|f(n)| ≤ 2(|g(n)| + |f(n)|) ≤ 4*|f(n)| (*)
Stripping away the left-most inequality in (*) and dividing by 2, we have:
|f(n)| ≤ |g(n)| + |f(n)| ≤ 2*|f(n)|, n>N (**)
We see that this is the very definition Big-Θ notation, as presented in (++), with constants k_1 = 1, k_2 = 2 and h(n) = g(n)+f(n). Hence
(**) => g(n) + f(n) is in Θ(f(n))
Ans we have shown that g(n) ∈ o(f(n)) implies (g(n) + f(n)) ∈ Θ(f(n)).

Resources