Does for all k, n^k is O(2^n)? [closed] - algorithm

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is it true that for all k, n^k is O(2^n)?
What I actually want to know whether this upper bound is correct. Like we can say n^2 is O(n^3) since it's true that n^2 < c * n^3, where c is a constant. SO similarly can I say that n^k < c * 2^n, for all value of k?

To show that there is always a constant c for any constant k such that n^k < c * 2^n, consider this: (n+1)^k / n^k = ((n+1)/n)^k. As n increases, (n+1)/n tends to 1, thus ((n+1)/n)^k tends to 1. This implies that the relative increase between values decreases as n increases.
Now consider 2^(n+1) / 2^n. This is clearly 2. Thus the relative increase stays the same as n increases. Thus there will be a c for every k such that n^k < c * 2^n

Related

What is the Order of Growth of sorting M elements N times, where M can differ? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I have a situation where I am looping N times to sort M elements using merge sort. M can differ, i.e., depend on which N iterations we're at.
I came up with O(nmlog(m)), where n is the number of outer elements, and m is the average number of inner elements, but this doesn't sound right.
All you can say is n times the average of mi log(mi), for which there is no simple formula. You could express this as nm*log(m*) where m* is the value that solves m*log(m*) = avg(mi log(mi)), but this is even less tractable.
As the function x log(x) is upward concave, m* will be somewhat above M:= avg(mi).
If the coefficient of variation of the mi is small, you can use the decomposition mi = M + δi and take the average of (M + δi) (log M + log(1 + δi/M)) ~ (M + δi) (log M + δi/M). By averaging, the terms in δi cancel out and what remains is the average of M log M + δi²/M = M log M + σ²/M. Hence O(NM log M + Nσ²/M), which is O(NM log M).

What is greater : O(mn) OR O((m^2)/n)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have an algorithm with this order:
O((m^2)/n) + O(mn)
I want to know: Is it equal to O(mn)?
O((m^2)/n) > O(mn) OR O((m^2)/n) < O(mn) ???
You should just say the complexity is O(m^2/n + mn).
Let's see when they're equal:
(m^2)/n = mn
m^2 = m(n^2)
m = n^2
So, if m = n^2, they are equal,
when m > n^2, m^2/n is dominant,
when m < n^2, mn is dominant.
Thus neither is always greater than the other, thus we can't cancel out either.
Dimensionally speaking, they cannot be compared. If unit of m and n is same say UNIT
But (m^2)/n is measured in UNIT and mn in UNIT^2 or UNIT-Squared.
(m^2)/n < mn
if you take m = n, then m^2/n will be n.
It means m and n are of same order (or of same magnitude), then complexity is O(mn).
If the order of m and n are different,
if m^2 < n, then it will be O(mn)
if m^2 > n, then it will be O(m^2/n)

Whats the number of steps this algorithm will take for the general case where the input is of size n? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Here's the algorithm:
Let a = 30, i = 1
While i < n
For j = i+1 to n
If ABS[(j*i)+20] < a then a = ABS[(j*i)+20]
i = i + 1
Return k
Whats the number of steps this algorithm will take for the general case where the input is of size n? How do you work that out?
Also does this algorithm come under the quadratic complexity class?
I think this is with O(n^2)
we have
n+(n-1)+(n-2)+(n-3)......[total n] ....3.2.1
if we calculate it, it would be
0.5( (n^2) + n) = C (n^2 + n)
and it is quadratic complexity class.
Let f(i) denote the number of times the inner for loop runs assuming that j goes from i+1 to n. For example f(5) = n - 5 + 1, since j goes through 6,7,...,n. So we want f(1) + f(2) + f(3) + ... + f(n - 1). Compute what each f(i) and then sum them to see the exact answer.
In general there is an outer loop that runs n times, then the inner loop runs at most n times, for a complexity upper bounded by ???
If I was a compiler, I would notice that this code only changes i, j, and a, local variables; and the only variable whose value is subsequently used is k. So I would gradually optimize away everything but this:
Return k
and the computation would be all constant time, just a few machine instructions. Therefore also within quadratic time.

Show that n^2 is not O(n*log(n))? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Using only the definition of O()?
You need to prove by contradiction. Assume that n^2 is O(n*log(n)). Which means by definition there is a finite and non variable real number c such that
n^2 <= c * n * log(n)
for every n bigger than some finite number n0.
Then you arrive to the point when c >= n /log(n), and you derive that as n -> INF, c >= INF which is obviously impossible.
And you conclude n^2 is not O(n*log(n))
You want to calculate the limit of
(n * log(n)) / (n ^ 2) =
= log(n) / n =
= 0 if n approaches infinity.
because log(n) grows slower than n.

Lower bound : resource required by an algorithm for some class of input size n [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've been asked to find the lower bound of the following :
T(n)= 23n^3-n^2-n.
So here is how i proceeded and i don't know whether I'm tackling it the proper way:
T(n)>=c(23n^2-n^2) for all n greater than n>=n0
23n^3-n^2-n >=(22n^2) for all n>=2.
T(n)>=c|n^2| for all n>=2
c=22 n0=22.
T(n) is in Big Omega n^2
HELP PLEASE!
Note that n^3 >= n^2 for n >= 1. So, -n^3 <= -n^2 for n >= 1.
Note that n^3 >= n for n >= 1. So, -n^2 <= -n for n >= 1.
So
23n^3 - n^2 - n >= 23n^3 - n^3 - n^3 = 21n^3.
Thus, 21n^3 is a decent lower bound.
Intuitively this makes sense as 23n^3 - n^2 - n is clearly cubic in nature, and thus should have lower bound and upper bound of cn^3 for some c (different c for the lower bound from the c for the upper bound).

Resources