Wednesday 21 January 2015

Big O notation

I wrote Stirling's formula as
$$
\log\left(\frac{n!e^n}{n^{n+1/2}}\right)=\log\sqrt{2\pi}+O(1/n)
$$ and thought later that maybe you do not know what $O(1/n)$ means (which is read as "Big O of $1/n$").

Jacqueline Kennedy Onassis was known to her friends as "the Big O". That is not what we mean here.

We say $f(n)=O(g(n))$ if there exists some $B$ such that $|f(n)| \leq B|g(n)|$ for all $n$ sufficiently large. We proved that $A<d_n<A+1/(12n)$, so
$$
0<\log\left(\frac{n!e^n}{n^{n+1/2}\sqrt{2\pi}}\right)<\frac{1}{12n}
$$ is consistent with this, with $B=1/12$.

There is also a notation for lower bounds. We say $f(n)=\Omega(g(n))$ if there exists some $B'$ such that $|f(n)| \geq B'|g(n)|$ for all $n$ sufficiently large. This is the same as saying $g(n)=O(f(n))$.

And $g(n)=\Theta(g(n))$ if both $f(n)=O(g(n))$ and $f(n)=\Omega(g(n))$ are true. Since
$$
\log\left(\frac{n!e^n}{n^{n+1/2}\sqrt{2\pi}}\right) > \frac{1}{12n+1}>\frac{1}{13n}
$$ we may actually claim that
$$
\log\left(\frac{n!e^n}{n^{n+1/2}\sqrt{2\pi}}\right)=\Theta(1/n).
$$ Because this tells how how fast is the convergence to $0$ it is stronger than just saying
$$
\lim_{n\to \infty}\log\left(\frac{n!e^n}{n^{n+1/2}\sqrt{2\pi}}\right)=0.
$$ Read more about "Big O", "Big omega" and "Big theta" notations. They are very commonly used in theoretical computer science.