问题
I have come across some of the difficulties during doing this question. The question is: rank the following by growth rate:
n, √n, log n, log(log n), log2 n, (1/3)n, n!
What is the order for the above question? I would also like to know if is there any easy way to determine that (in general)?
My answer to this question is
(1/3)n ⋞ log(log n) ⋞ log n ⋞ log2 n ⋞ √n ⋞ n ⋞ n!
Is it correct?
回答1:
You have to learn big O notation.
it's all about exponentiation ranking... you can have:
- 1 constant (exp n^0)
- 2 logarithmic (exp n=1/c)
- 3 linear (exp n^1)
- 4 polinomial (exp n^c)
- 5 exponential (exp c^n)
- 6 factorial (exp n!)
that's the basic rule. On the long run each one "wins" against the lower ones (e.g. rule 5 wins over 4,3,2 and 1)
Using this principle, it is easy to order the functions given from asymptotically slowest-growing to fastest-growing:
- (1/3)^n - this is bound by a constant! O(1)
- log(log n) - log of a log must grow slower than log of a linear function.
- log n
- log^2 n
- √n - n^(1/3), sub-linear, but faster than any log
- n - linear is a 1st degree polynomial
- n! - factorial grows faster than any exponential.
来源:https://stackoverflow.com/questions/22813551/order-the-growth-rate-of-a-function