算法时间复杂度的混淆

时间:2017-07-22 14:01:55

标签: time-complexity

我正在阅读一本书,其中log(n!)的增长率比log(n)快。

Since,
log(n!) = log((n)*(n-1)*.....(1)) = log(n)+log(n-1)+....+log(1) <---(i)
taking the worst case eq.(i), which should be log(n).

which is effectively same as log(n),
therefore log(n) should have same growth rate as log(n!).

那么log(n!)如何比log(n)更好?

1 个答案:

答案 0 :(得分:1)

让我们尝试不同的方法

<强> 1

n! = n*(n-1)*(n-2)*...*1 &lt; n*n*n.....*n

n! < n^n
log(n!) < log(n^n)
log(n!) < nlogn
** log(n!) = O(nlogn)

<强> 2

n! = 
n*(n-1)*(n-2)*....*n/2*(n/2-1)*...*1 > (n/2)*(n/2)*(n/2)*...*(n/2)
                                       ---------------------------
                                                  n/2 times

这是因为:

n > n/2
n-1 > n/2
n-2 > n/2
.
.
n/2 == n/2

现在我们知道:log(n!) > log((n/2)^(n/2)

log(n!) > n/2*log(n/2)
*** log(n!) = Ω(nlogn)

*****我们得到:
log(n!) = θ(nlogn)

因此log(n) = O(log(n!))