2

According to Wikipedia on Stirling's approximation : $$ \ln(n!) = n\ln(n)-n+O(\ln(n))$$ I was able to derive the first part pretty easily : $$\ln(n!) = \sum_{i=1}^n \ln(i) \approx \int_1^n \ln(x) dx = [x\ln(x)-x]_1^n = n\ln(n)-n+1$$ I understand that $1 \in O(\ln(n))$ but why would you write the big-$O$ term ? I am surely missing something but I do not understand what? Thanks for reading.

Sebastiano
  • 8,290
BrockenDuck
  • 243
  • 1
  • 7

2 Answers2

1

It is explained in this question from 2011. Specifically, you might find this proof helpful. I believe your approximation of $\ln(n!)$ is too loose to give the precise error term.

Hope this helps,

Gareth

ketsi
  • 3,904
0

The point is that you are not using the same Stirling's approximation. As the approximation is $n! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^n$, you can get the following:

$$ \log(n!) \approx \log\left(\sqrt{2\pi n}\left(\frac{n}{e}\right)^n\right) = \log\left(\sqrt{2\pi n}\right) + \log\left(\left(\frac{n}{e}\right)^n\right) \\= \log(\sqrt{2\pi}) + 0.5 \log(n) + n\log(n) - n = O(\log(n)) + n\log(n) - n $$

By the way, you can find the detail of obtaining Stirling's formula in Wikipedia as well.

OmG
  • 3,142