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 poweredAI로 LaTeX 작성

최고의 AI LaTeX 편집기, Overleaf 대안

Octree는 15개 이상의 대학의 연구자들이 AI를 사용하여 논문을 더 빠르게 작성하도록 도움

  • AI로 아름다운 TikZ 다이어그램 생성
  • 이미지를 업로드하고 LaTeX로 원활하게 변환
  • 논문 작성 및 서식에 대한 즉각적인 지원 받기