Skip to content
Part IA Lent Term

Asymptotic Notation: Big-O, Big-Ω, and Big-Θ

Big-O: Asymptotic Upper Bound

f(n)=O(g(n))f(n) = O(g(n)) if there exist positive constants cc and n0n_0 such that for all nn0n \ge n_0:

0f(n)cg(n)0 \le f(n) \le c \cdot g(n)

In words: ff grows at most as fast as gg, ignoring constant factors and small inputs. OO is pronounced “big-O”.

Big-Ω\Omega: Asymptotic Lower Bound

f(n)=Ω(g(n))f(n) = \Omega(g(n)) if there exist positive constants cc and n0n_0 such that for all nn0n \ge n_0:

0cg(n)f(n)0 \le c \cdot g(n) \le f(n)

In words: ff grows at least as fast as gg. The purple circles (worst-case cost) must be above the curve cg(n)c \cdot g(n).

Big-Θ\Theta: Asymptotically Tight Bound

f(n)=Θ(g(n))f(n) = \Theta(g(n)) iff f(n)=O(g(n))f(n) = O(g(n)) and f(n)=Ω(g(n))f(n) = \Omega(g(n)). In words: ff and gg grow at the same rate, within constant factors.

Formal Definition

There exist c1,c2>0c_1, c_2 > 0 and n0n_0 such that for all nn0n \ge n_0:

0c1g(n)f(n)c2g(n)0 \le c_1 \cdot g(n) \le f(n) \le c_2 \cdot g(n)

Examples

FunctionBig-OBig-Ω\OmegaBig-Θ\Theta
3n2+2n+13n^2 + 2n + 1O(n2)O(n^2) ✓, O(n3)O(n^3)Ω(n2)\Omega(n^2) ✓, Ω(n)\Omega(n)Θ(n2)\Theta(n^2)
nlognn \log nO(n2)O(n^2) ✓, O(nlogn)O(n \log n)Ω(n)\Omega(n)Θ(nlogn)\Theta(n \log n)
n2n^2O(n2logn)O(n^2 \log n)Ω(n2)\Omega(n^2)Cannot say n2=O(nlogn)n^2 = O(n \log n)

Proving 3n2+2n+1=O(n2)3n^2 + 2n + 1 = O(n^2)

We need cc and n0n_0 such that 3n2+2n+1cn23n^2 + 2n + 1 \le c \cdot n^2 for all nn0n \ge n_0.

For n1n \ge 1: 2n2n22n \le 2n^2 and 1n21 \le n^2, so 3n2+2n+13n2+2n2+n2=6n23n^2 + 2n + 1 \le 3n^2 + 2n^2 + n^2 = 6n^2.

Choose c=6c = 6, n0=1n_0 = 1. ✓

Common Growth Rates

Ranked from slowest to fastest:

O(1)<O(logn)<O(n)<O(n)<O(nlogn)<O(n2)<O(n3)<O(2n)<O(n!)O(1) < O(\log n) < O(\sqrt{n}) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)

The base of the logarithm is irrelevant: log2n\log_2 n and log10n\log_{10} n differ by a constant factor (log2n=log210log10n\log_2 n = \log_2 10 \cdot \log_{10} n), which big-O absorbs.

Practical Interpretation

  • O(1)O(1): constant time, e.g. array access, arithmetic
  • O(logn)O(\log n): binary search depth, divide-and-conquer recursion depth
  • O(n)O(n): single pass over all elements
  • O(nlogn)O(n \log n): efficient comparison-based sorting
  • O(n2)O(n^2): nested loops, insertion sort worst case
  • O(2n)O(2^n): enumerating all subsets

Θ\Theta, OO, and Ω\Omega are Sets

Formally, O(g(n))O(g(n)) is a set of functions. Writing f(n)=O(g(n))f(n) = O(g(n)) means f(n)O(g(n))f(n) \in O(g(n)). This set perspective makes the notation transitive: if fO(g)f \in O(g) and gO(h)g \in O(h), then fO(h)f \in O(h). Likewise for Θ\Theta and Ω\Omega. In addition, fΘ(g)f \in \Theta(g) iff gΘ(f)g \in \Theta(f) (symmetry).

Summary

NotationMeaningMnemonic
O(g(n))O(g(n))Upper bound”at most”
Ω(g(n))\Omega(g(n))Lower bound”at least”
Θ(g(n))\Theta(g(n))Tight bound”exactly” (within constants)
Rule of thumbDrop constants and lower-order terms3n2+4nO(n2)3n^2 + 4n \to O(n^2)