Prove that n! = O(n^n)
How开发者_JAVA技巧 can I prove that n! = O(n^n)?
I assume that you want to prove that the function n!
is an element of the set O(n^n)
. This can be proven quite easily:
Definition: A function f(n)
is element of the set O(g(n))
if there exists a c>0
such that there exists a m
such that for all k>m
we have that f(k)<=c*g(k)
.
So, we have to compare n!
against n^n
. Let's write them one under another:
n! = n * (n-1) * (n-2) * (n-3) * ... * 3 * 2 * 1
n^n = n * n * n * n * ... * n * n * n
As you can see, the first line (n!
) and the second line (n^n
) have both exactly n
items on the right side. If we compare these items, we see that every item is at most as large as it's corresponding item in the second line. Thus n! <= n^n
.
So, we can - look at the definition - say, that there exists c=1
such that there exists m=5
such that for all k>5
we have that k! < k^k
, which proves that n!
is indeed an element of O(n^n)
.
精彩评论