How to denote Big O notation in LaTeX?

Big O notation is a standard mathematical concept used in computer science and mathematics. It’s represented by a capital O, slightly slanted to the right.

Big O notation.

In most cases, you will notice the use of O symbols instead of Inline big o notation. in various books or documents.

Symbol Big O notation
Type asymptotic
Package mismath, physics
Commands O(arg), \mathcal{O}(arg)
Example O(log n)O(log n)
\documentclass{article}
\begin{document}
   \[ O(n^2) \]
   \[ O(n^c) \]
   \[ O(g(x)) \]
   \[ O(\max(g_1,g_2)) \]
\end{document}

Output :

Big O notation.

You’ve probably noticed that a backslash is typically placed before command names, but in this case, it’s not necessary.

When you use \mathcal{o}, it generates the Big O symbol. However, the top-left part of the capital O stays open in terms of its design.

\documentclass{article}
\begin{document}
   \[ \mathcal{O}(\log n) \]
   \[ \mathcal{O}(\log n^c) \]
   \[ \mathcal{O}(n\log n) \]
   \[ \mathcal{O}(n!) \]
\end{document}

Output :

Use \mathcal{O}(arg) command for big o.

The methods mentioned above don’t require any additional packages. But now, let’s explore two more ways to represent this symbol using the mismath and physics packages.

\bigo and \big0 commands in mismath package

Not many people are familiar with the mismath package. However, it offers the \bigo and \bigO commands, which can also represent this asymptotic notation.

\documentclass{article}
\usepackage{mismath}
\begin{document}
   \[ \bigo(m^n) \]
   \[ \bigo(1) \]
   \[ \bigO(n^3) \]
   \[ \bigO(2^n) \]
\end{document}

Output :

\bigo and \big0 commands in mismath package.

Just like Big O, little o is also used as an asymptotic notation. For example:

\documentclass{article}
\usepackage{mismath}
\begin{document}
   \[ f(n)=\lito(g(n)) \]
   \[ f\in \lito(g) \]
   \[ \lito \le f(n) <c*g(n) \]
\end{document}

Output :

Little o is used as an asymptotic notation.

Physics package for \order{arg} command

The benefit of using the \order command is that the size of the symbol automatically adjusts based on the size of the argument.

\documentclass{article}
\usepackage{physics}
\begin{document}
   \[ \order{<n} \]
   \[ \order{c^n} \]
   \[ \order{n\log n} \]
   \[ \order{\order{h(n)}} \]
   \[ \order{\frac{n}{k}} \]
\end{document}

Output :

\order command for big o notation.

If you want to manually change the size of the parentheses, you can use the \big command right after the \order command.

\documentclass{article}
\usepackage{physics}
\begin{document}
   \[ \order\big{\log_b n} \]
   \[ \order\big{\log_c n} \]
   \[ \order\big{f(x)} \]
   \[ \order\Big{\frac{n}{q}} , \order\bigg{\frac{n_i}{q_k}} , \order\Bigg{\frac{n_{ij}}{q_{kj}}} \]
\end{document}

Output :

\order and \big commands for big o notation.

One important thing to note is that the size of the symbol can be fixed by using the * symbol with each command in the physics package.

\documentclass{article}
\usepackage{physics}
\begin{document}
   \[ \order*{n^{\frac{5}{2}}} \]
   \[ \order*{\frac{n}{k}} \]
   \[ \order*{f(x)} \]
\end{document}

Output :

Size of big O symbol is fixed by using the * sign with each command in the physics package.

Share tutorial

Leave a Comment

Your email address will not be published. Required fields are marked *