Big O in LaTeX (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.
\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 Ilmu Komputer →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.
Editor LaTeX AI Terbaik, Alternatif Overleaf
Octree membantu peneliti dari 15+ universitas menulis makalah penelitian lebih cepat menggunakan AI
- Hasilkan diagram TikZ yang indah menggunakan AI
- Unggah gambar dan konversi ke LaTeX dengan mulus
- Dapatkan bantuan instan untuk menulis dan memformat makalah penelitian