Big O in LaTeX (O(n))

O(n)O(n)
LaTeX command
O(n)
Package
No package needed: built into LaTeX
Mode
Text and math mode

Where it is used

Asymptotic upper bound: f(n) = O(n) means f grows no faster than a constant multiple of n for large n.

Big O is the workhorse of algorithm analysis: linear search runs in O(n), merge sort in O(n \log n), naive matrix multiplication in O(n^3). Strictly, O(g) is a set of functions, so f \in O(g) is the precise form, though f(n) = O(g(n)) is the near-universal convention. Some authors prefer a calligraphic \mathcal{O}(n) to separate the operator from a variable named O; pick one and stay consistent across the paper. Write the argument with the real cost inside, such as O(n^2 \log n), rather than O(n^2) \cdot \log n, and remember that O only bounds from above, so it does not claim the bound is tight.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

T(n)=2T(n/2)+O(n)  ⟹  T(n)=O(nlog⁡n)T(n) = 2T(n/2) + O(n) \implies T(n) = O(n \log n)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Big O: $O(n)$

\[ T(n) = 2T(n/2) + O(n) \implies T(n) = O(n \log n) \]
\end{document}

Related symbols

All علوم الحاسوب →

Frequently asked questions

How do I write Big O in LaTeX?
Type O(n) in math mode, for example $T(n) = 2T(n/2) + O(n) \implies T(n) = O(n \log n)$. It works in plain LaTeX without loading any package.
Which package do I need for O(n)?
None. O(n) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use O(n) in text mode, or only in math mode?
Both. O(n) compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.
Math poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث