LatexNotes

Big O notation in LaTeX

Big O describes how fast a function grows; in LaTeX write O(n^2) with a plain capital O, or \mathcal{O}(n^2) for the calligraphic O many textbooks use.

LaTeX command

\mathcal{O}(n \log n)

Not the symbol you meant? Draw it to find the command →

Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →

Both forms are common. A plain O is an ordinary italic letter, which is how many computer science texts set it. \mathcal{O} gives a rounded calligraphic O that stands out from a variable called O. Pick one and use it throughout; a short command, defined once, keeps every occurrence the same.

The rest of the family are Greek capitals and small letters: \Theta(n) for a tight bound, \Omega(n) for a lower bound, little o(n) and \omega(n) for strict bounds. Inside, write functions with their commands, \log n and \sqrt{n}, so they are upright and spaced.

Brackets can grow with the expression inside, as in \mathcal{O}\left(\frac{n}{\log n}\right). For a set of functions, some writers use f \in \mathcal{O}(g) rather than f = \mathcal{O}(g); both are seen.

One \bigO command for the whole document

Define it once in the preamble and write \bigO(n) everywhere; switching between the calligraphic and the plain O is then a one-line change.

\newcommand{\bigO}{\mathcal{O}}
$\bigO(n \log n)$

Other forms

O(n^2)a plain italic O
\Theta(n)big Theta
\Omega(n)big Omega
o(n)little o

Examples

$T(n) = \mathcal{O}(n \log n)$

a running time with calligraphic O

$O(n^2)$

a plain O

$\Theta(n), \quad \Omega(\log n)$

tight and lower bounds

$f(n) = o(g(n))$

little o

$\mathcal{O}\left(\frac{n}{\log n}\right)$

brackets that grow

Tips and common mistakes

Working from handwritten notes?

LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.

See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).

Convert your maths to LaTeX →

FAQ

How do I write big O notation in LaTeX?

Write O(n) with a plain O, or \mathcal{O}(n) for the calligraphic O, for example \mathcal{O}().

How do I write big Theta and big Omega?

Use the Greek capitals: \Theta(n) and \Omega(n).

Should I use O or \mathcal{O}?

Both are standard. \mathcal{O} stands apart from a variable named O; a plain O is common in computer science. Be consistent.

Does \mathcal need a package?

No. \mathcal is built into LaTeX and KaTeX.

See also