Big-O

Also known as: Big O notation, O notation, Asymptotic notation

Big-O notation writes an asymptotic upper bound: $f(n) = O(g(n))$ means for large $n$, $f$ grows at most as fast as a constant times $g$ (formally $\exists c, n_0$ such that $f(n) \le c\,g(n)$ for $n \ge n_0$).

Coders use it for time and space of algorithms. $O$ alone is an upper bound; $\Theta$ is tight; $\Omega$ is a lower bound. Saying “this sort is $O(n^2)$” is true of merge sort but not informative; prefer $\Theta(n \log n)$ when you know it.

Drop lower-order terms and constant factors: $3n^2 + 100n = O(n^2)$. Compare algorithms by the dominant term for the $n$ you care about, not only the letter.

← Back to CS Glossary