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 Sains 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 penyelidik dari 15+ universiti menulis kertas penyelidikan dengan lebih cepat menggunakan AI
- Jana diagram TikZ yang cantik menggunakan AI
- Muat naik imej dan tukar ke LaTeX dengan lancar
- Dapatkan bantuan segera untuk menulis dan memformat kertas penyelidikan