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)
Related
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).
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
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 4 years ago.
Improve this question
Given the equation T(n)=sqrt(2)T(n/2)+log(n).
The solution points to case 1 of the M.T. with a complexity class of O(sqrt(n)). However after my understanding log(n) is polynomial greater then sqrt(n). Am I missing something?
I used the definition as following: n^e = log_b(a) where a = sqrt(2) and b = 2. This would give me e = 1/2 < 1. log n is obviously polynomial greater then n^e.
No. logx n is not greater than √n.
Consider n=256,
√n = 16,
and
log2 256 = 8 (let us assume base x=2, as with many of the computational problems).
In your recurrence,
T(n)= √2 T(n/2) + log(n)
a = √2, b = 2 and f(n) = log(n)
logb a = log2 √2 = 1/2.
Since log n < na, for a > 0, We have Case 1 of Master Theorem.
There for T(n) = Θ(√n).
Using the masters theorem you get: a=sqrt(2), b = 2 and therefore c = logb(a) = 1/2. Your f(n) = log(n) and therefore you fall into the first case.
So your complexity is O(sqrt(n))
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.
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).