Update: Sorry I forgot to put n^n inside the O()
My attempt was to solve this recurrence relation:
T(n) = nT(n-1) +1
T(0) = 1;
Using the iteration method I got the n^n but Im not sure if this is the way to prove it.
Update: Sorry I forgot to put n^n inside the O()
My attempt was to solve this recurrence relation:
T(n) = nT(n-1) +1
T(0) = 1;
Using the iteration method I got the n^n but Im not sure if this is the way to prove it.
It is not true that n! = n^n, and therefore you will not be able to prove that. Furthermore, the solution to your recurrence relation is neither n! or n^n. (It satisfies T(1) = 1*1+1 = 2, which is neither 1! nor 1^1.)
What exactly are you trying to do, and why?
Remark: The following is an answer to the original Question which was: "Prove that n! = n^n"
I can prove that it's not true pretty easily: take n = 5.
n! != n^n
. However, theT(n)
sequence defined above is notn!
. But does it equaln^n
? Forn=1
,T(1)
=1*T(0) + 1
=1*1 + 1
=2
butn^n
=1^1
=1
. However, assuming you also meantT(1) = 1
, then they're equal forn=1
. Going a step further, forn=2
, thenT(2) = 2*T(1) + 1
=2*1 + 1
=3
!=2^2
. So I'm honestly not sure what you're trying to ask.I assume that you want to prove that the function
n!
is an element of the setO(n^n)
. This can be proven quite easily:Definition: A function
f(n)
is element of the setO(g(n))
if there exists ac>0
such that there exists am
such that for allk>m
we have thatf(k)<=c*g(k)
.So, we have to compare
n!
againstn^n
. Let's write them one under another:As you can see, the first line (
n!
) and the second line (n^n
) have both exactlyn
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. Thusn! <= n^n
(at least for n>5).So, we can - look at the definition - say, that there exists
c=1
such that there existsm=5
such that for allk>5
we have thatk! < k^k
, which proves thatn!
is indeed an element ofO(n^n)
.for
n==2
,n! = 2 != 4 = n^n
.for
n!=2
,(n-1)
dividesn!
butn-1
does not dividen^n
(n^n mod n-1 == 1
)The actual stirling approximation is
n! ~ sqrt(2 Pi n) (n/e)^n
What is your mathematical background? Do you want a complex analytic proof or something more combinatorial in nature?