O(n^k)
比O(n^k')
对全部k, k' >= 0
and k' > k
O(n^2)
会比O(n^2*logn)
请注意,您只能忽略常量,任何涉及输入大小的内容都不能被忽略。
因此,复杂度为T(n)=n^2 + n^2logn
会是两者中更糟糕的一个,即O(n^2logn)
.
Little-oh
宽松地说,“小哦”是有保证的上限。是的,这叫小,而且限制比较多。
n^2 = O(n^k)
for k >= 2 but n^2 = o(n^k)
for k > 2
实际上,它是Big-Oh
这占据了大部分的风头。
What about
T(n)= n^2.001 + n^2logn
?
We have n2.001 = n2*n0.001 and n2 * log(n).
To settle the question, we need to figure out what would eventually be bigger, n0.001 or log(n).
It turns out that a function of the form nk with k > 0
will eventually take over log(n)
for a sufficiently large n
.
Same is the case here, and thus T(n) = O
(n2.001)
.
Practically though, log(n)
will be larger than n0.001.
(103300)0.001 < log(103300) (1995.6 < 3300)
, and the sufficiently large n in this case would be just around 103650, an astronomical number.
Worth mentioning again, 103650. There are 1082 atoms in the universe.