컴퓨터 과학

Big-O 표기법, 논리 연산자 및 알고리즘 기호.

Computer science symbols in LaTeX: Big O, floor and algorithm notation

Most computer science symbols in LaTeX are ordinary math commands. Big O notation in LaTeX is O(n \log n) or, in many papers, the calligraphic \mathcal{O}(n); its relatives are \Omega(n), \Theta(n) and little-o o(n). Floor and ceiling are \lfloor x \rfloor and \lceil x \rceil, XOR is \oplus, assignment in pseudocode is \gets, and a definition with := is cleanest as \coloneqq from mathtools. The table lists the computer science symbols people use most, with the package each one needs; the full list follows below.

Quick reference: complexity, rounding and algorithms

SymbolCommandUsePackageCopy
O(nlog⁡n)O(n \log n)
O(n \log n)Big O (upper bound)built in
O(n)\mathcal{O}(n)
\mathcal{O}(n)Big O, calligraphic stylebuilt in
Ω(n)\Omega(n)
\Omega(n)Big Omega (lower bound)built in
Θ(n2)\Theta(n^2)
\Theta(n^2)Big Theta (tight bound)built in
o(n)o(n)
o(n)Little-obuilt in
⌊log⁡2n⌋\lfloor \log_2 n \rfloor
\lfloor \log_2 n \rfloorFloor of log base 2built in
⌈n/2⌉\lceil n/2 \rceil
\lceil n/2 \rceilCeilingbuilt in
a mod na \bmod n
a \bmod nModulo as a binary operatorbuilt in
⊕\oplus
\oplusXORbuilt in
x←x+1x \gets x + 1
x \gets x + 1Assignment in pseudocodebuilt in
≔\coloneqq
\coloneqqDefined as (:=)mathtools
{0,1}∗\{0,1\}^*
\{0,1\}^*All binary strings (Kleene star)built in

For pseudocode itself, use the algorithm and algpseudocode packages, which provide \State, \If and \For and use \gets for assignment, rather than building it from math symbols. Logic operators are listed on the Boolean algebra symbols page.

Frequently asked questions about computer science symbols

How do I write Big O notation in LaTeX?
Type O(n) in math mode: $O(n \log n)$. Many authors prefer the calligraphic form $\mathcal{O}(n)$, which needs no package. Big Omega and Big Theta use the Greek capitals \Omega(n) and \Theta(n), and little-o is o(n). Write \log, not log, so the function name is upright.
How do I write floor and ceiling in LaTeX?
Use the built-in delimiters \lfloor x \rfloor for ⌊x⌋ and \lceil x \rceil for ⌈x⌉. For tall content put \left and \right in front, as in \left\lfloor \frac{n}{2} \right\rfloor, or define \floor and \ceil with \DeclarePairedDelimiter from mathtools.
How do I write mod in LaTeX?
Use \bmod for the binary operator, a \bmod n, and \pmod{n} for a congruence, as in a \equiv b \pmod{n}, which prints (mod n) with the correct spacing. Both are built in; amsmath adds \mod{n} and \pod{n} for other spacing styles.
O(n)O(n)

Big O

O(n)
Ω(n)\Omega(n)

Big Omega

\Omega(n)
Θ(n)\Theta(n)

Big Theta

\Theta(n)
o(n)o(n)
ω(n)\omega(n)

Little omega

\omega(n)
↦\mapsto

Maps To

\mapsto
:=:=
≜\triangleq

Definition

\triangleq
≡\equiv
≠\neq
⊕\oplus

XOR

\oplus
∧\land
∨\lor
¬\neg
⌊x⌋\lfloor x \rfloor

Floor

\lfloor x \rfloor
⌈x⌉\lceil x \rceil

Ceiling

\lceil x \rceil
 mod \bmod

Modulo

\bmod
∣\mid
∤\nmid
∗\ast
⋆\star

Star

\star
log⁡\log
ln⁡\ln