Skip to content
Part IA Michaelmas Term

Big O Notation

Formal definition

f(n)=O(g(n))f(n) = O(g(n)) means there exist constants cc and n0n_0 such that:

f(n)cg(n)for all nn0|f(n)| \leq c \cdot |g(n)| \quad \text{for all } n \geq n_0

In plain English: f(n)|f(n)| is bounded above by some constant multiple of g(n)|g(n)| for all sufficiently large n.

What Big O captures

The notation abstracts away details that do not affect asymptotic growth:

  • Constant factors: 100n2100n^2 will beat n3n^3 in the long run. Constants depend on hardware, OS, and language — ignoring them makes comparisons broadly valid.
  • Insignificant terms: If cost is n2+99n+900n^2 + 99n + 900, the n2n^2 term eventually dominates. The 99n99n term is bigger for n<99n < 99, but n2n^2 overtakes it.
  • Small values of n: The role of n0n_0 in the definition is to ignore finitely many exceptions where the bound does not hold.

Simple facts

Constant factors and insignificant terms disappear:

O(2g(n)) is the same as O(g(n))O(2g(n)) \text{ is the same as } O(g(n)) O(log10n) is the same as O(lnn)O(\log_{10} n) \text{ is the same as } O(\ln n) O(n2+50n+36) is the same as O(n2)O(n^2 + 50n + 36) \text{ is the same as } O(n^2)

For the last one: n2+50n+362n2n^2 + 50n + 36 \leq 2n^2 for n51n \geq 51, so we can double the constant factor and drop the lower-order terms.

Containment relationships

If cc and dd are constants with 0<c<d0 < c < d, then:

  • O(nc)O(nd)O(n^c) \subset O(n^d)
  • O(cn)O(dn)O(c^n) \subset O(d^n)
  • O(logn)O(nc)O(\log n) \subset O(n^c)

The notation O(f(n))O(g(n))O(f(n)) \subset O(g(n)) means that if a function is O(f(n))O(f(n)), it is also O(g(n))O(g(n)) — the former gives a tighter bound. For example, if f(n)=O(2n)f(n) = O(2^n) then trivially f(n)=O(3n)f(n) = O(3^n), but the converse does not hold.

Why constant factors are ignored

  • They seldom make a difference asymptotically: 100n2100n^2 beats n3n^3 for large n
  • They are unstable: different hardware, operating system, or language changes them
  • Ignoring them allows comparisons that remain valid across many circumstances

Limitations of Big O

Even ignoring constant factors, measurement units matter. Multiplication may be treated as one unit of cost, but multiplying two n-digit numbers for large n is itself expensive (relevant for cryptography). Few things are truly O(1): storing the number n requires O(log n) bits. An O(1) cost usually assumes operations fit within standard hardware arithmetic capacity.