TITLE: "$O$" notation in Stirling approximation
QUESTION [8 upvotes]: In the Stirling approximation the formula as typically used in applications is
$$\ln n! = n\ln n - n +O(\ln(n))$$
I'm confused about the last term "$O$" . What does it mean actually, and when do we apply it in a equation?

REPLY [2 votes]: In this specific context I recon the best understanding would be the following:
Imagine that in addition to the three terms above you have $k \in \mathbb{Z}^{+}$ more asymptotically smaller terms, e.g. $\log n + \log \log n + \log \log \log n+\ldots$. They are dominated by the asymptotically largest term here, i.e.:
$$
R(n) = \log n + \log \log n +\log \log \log n  + \ldots \leq k \log n \\
\Leftrightarrow \lim_{n \to \infty}\frac{R(n)}{\log n}=k
$$
In this case we use the big-O notation that $R(n)=O(\log n)$
By the way $-O(\log n)=+O(\log n)$, for details see the last chapter in Concrete Mathematics (1995) by Graham, Knuth and Patashnik