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.
Asked
Active
Viewed 171 times
2 Answers
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