In mathematics, Stirling's approximation (or Stirling's formula) is an asymptotic approximation for factorials. It is a good approximation, leading to accurate results even for small values of . It is named after James Stirling, though a related but less precise result was first stated by Abraham de Moivre.[1][2][3]
One way of stating the approximation involves the logarithm of the factorial:
where the big O notation means that, for all sufficiently large values of , the difference between and will be at most proportional to the logarithm of . In computer science applications such as the worst-case lower bound for comparison sorting, it is convenient to instead use the binary logarithm, giving the equivalent form
The error term in either base can be expressed more precisely as , corresponding to an approximate formula for the factorial itself,
Here the sign means that the two quantities are asymptotic, that is, that their ratio tends to 1 as tends to infinity. The following version of the bound holds for all , rather than only asymptotically:
^Cite error: The named reference dutka was invoked but never defined (see the help page).
^Cite error: The named reference LeCam1986 was invoked but never defined (see the help page).
^Cite error: The named reference Pearson1924 was invoked but never defined (see the help page).