Skip to main content

Factorial estimates

Let us start with a simple question:

There are nn students in class. Each student is assigned a random number in {1,,n}\{1,\ldots, n\} What is the probability that no two students are assigned the same number?

In other words, pick a random function f:[n][n]f: [n] \rightarrow [n]. What is the probability that ff is a permutation? We should now know that this is n!/nnn!/ n^n. But what exactly is this number? Does it converge to zero, or is it closer to one? Let us start with a simple lemma.

Lemma 14 (Gauß)

nn/2n!(n+12)nn^{n/2} \leq n! \leq \left(\frac{n+1}{2}\right)^n

Proof:

We work with the square of n!n! (and will be taking the square root later). Rewrite (n!)2=(12n)(n(n1)1)(n!)^2 = (1\cdot 2 \cdots n)(n \cdot (n-1) \cdots 1), so we have two groups of the products. We pair 11 (from the first group) with nn (from the second group), 22 with (n1)(n-1) and so on; more generally, we pair ii with (ni+1)(n-i+1). This implies that

n!=(i=1n(i(ni+1)))1/2n! = \left(\prod_{i=1}^n (i \cdot (n-i+1))\right)^{1/2}

Now we analyze the two directions of the inequality:

  • To prove the upper bound, by AM-GM, we have i(ni+1)(n+1)/2\sqrt{i (n-i+1)} \leq (n+1)/2, so this implies that n!((n+1)/2)nn! \leq \left((n+1)/2\right)^n.
  • To see the lower bound, notice that i(ni+1)ni (n-i+1) \geq n for all i=1,,ni=1,\ldots, n. (do you see why? maybe try to prove this before reading the footnote 😊)1

Now let us return to the probability p=n!/nnp=n!/n^n. Plugging in the above estimates,

nn/2p12n(1+1/n)nn^{-n/2} \leq p \leq \frac{1}{2^n}(1+1/n)^n

Using Lemma 13, we have that (1+1/n)e1/n(1+1/n)\leq e^{1/n}, so pe/2np \leq e/2^n. This simple estimate implies that the probability term converges to zero at exponential rate. Notice that we still have a very large gap between the lower and the upper bounds. Let us try to get a better estimate.

Theorem 28

e(n/e)nn!en(n/e)ne(n/e)^n \leq n! \leq en (n/e)^n

Notice that the ratio between the upper and lower bounds is exactly nn (which is a very low order term compared to (n/e)n(n/e)^n). Therefore, this bound is considered relatively tight and the proof is quite elementary. Now, using this theorem, the probability pp becomes already nicely estimated:

1/en1pn/en1 1/e^{n-1} \leq p \leq n/e^{n-1}

Exercise 79

Prove the upper bound side of Theorem 28. Use induction on nn.

Theorem 29 (Stirling's formula)

n!(n/e)n2πnn! \sim (n/e)^n \sqrt{2 \pi n}

The Stirling formula is a very tight estimate of factorials (recall the meaning of asymptotic equality, that when nn is large, the two sides of the equation are practically the same). For instance, when n=8n= 8, the error of this estimate is already less than 11 percent.

Footnotes

  1. A simple argument: When i=1i=1 or i=ni=n, this is obvious. Otherwise, when i2i \geq 2, this is a product between two numbers. The smaller number is always at least 22 and the bigger number is at least n/2n/2.