Asymptotic notation (O, o, Ω, Θ)

Level UniversityDifficulty ★★★★★Concept⌖ Open in the map

What is it?

Landau's symbols compare functions up to constant factors: f=O(g)f = O(g) (grows no faster), f=Ω(g)f = \Omega(g) (no slower), f=Θ(g)f = \Theta(g) (same rate), f=o(g)f = o(g) (strictly slower). Born in number theory, adopted by computer science to classify algorithms, and by numerical analysis to measure errors.

Why does it exist?

Exact running times depend on the machine, the compiler and the input. What survives every change of hardware is the shape of the growth: doubling the input quadruples the time of an O(n2)O(n^2) algorithm on any computer. Asymptotic notation captures exactly that and throws the rest away.

Intuition

f=O(g)f = O(g): beyond some point, the graph of ff stays under a stretched copy C gC\,g. Big-O is an upper bound, Ω a lower bound, Θ a sandwich. Little-o says the ratio f/gf/g goes to zero — in numerical analysis, e(h)=o(h)e(h) = o(h) means "the error vanishes faster than the step".

Formal definition

For n→∞n \to \infty (or x→ax \to a):

  • f=O(g)  ⟺  ∃C,n0: ∣f(n)∣≤C ∣g(n)∣f = O(g) \iff \exists C, n_0:\ |f(n)| \le C\,|g(n)| for n≥n0n \ge n_0
  • f=Ω(g)  ⟺  g=O(f)f = \Omega(g) \iff g = O(f)
  • f=Θ(g)  ⟺  f=O(g)f = \Theta(g) \iff f = O(g) and f=Ω(g)f = \Omega(g)
  • f=o(g)  ⟺  lim⁡f(n)/g(n)=0f = o(g) \iff \lim f(n)/g(n) = 0

Formulas

3n2+10nlog⁡n+7=Θ(n2)3n^2 + 10 n \log n + 7 = \Theta(n^2)
T(n)=2T(n/2)+Θ(n)  ⟹  T(n)=Θ(nlog⁡n)T(n) = 2T(n/2) + \Theta(n) \implies T(n) = \Theta(n \log n)
merge sort, via the master theorem
sin⁡x=x+O(x3)(x→0)\sin x = x + O(x^3) \quad (x \to 0)
the same symbol for small quantities

Example

Is nlog⁡n=O(n1.1)n \log n = O(n^{1.1})? Yes: nlog⁡nn1.1=log⁡nn0.1→0\frac{n\log n}{n^{1.1}} = \frac{\log n}{n^{0.1}} \to 0, so it is even o(n1.1)o(n^{1.1}). But the crossover is huge: log⁡n=n0.1\log n = n^{0.1} near n≈1015n \approx 10^{15}. Asymptotics tell you who wins eventually, not when.

Why does it matter?

It is the vocabulary of algorithm design ("this is O(nlog⁡n)O(n \log n)"), of numerical methods ("Runge–Kutta 4 has error O(h4)O(h^4)"), of Monte Carlo ("error O(N−1/2)O(N^{-1/2})") and of machine learning theory (generalization bounds). One notation, three communities.

Where it shows up in computing

  • Algorithm analysis and complexity★★★★★fundamentalScientific computing and algorithms

    The standard language for running time and memory: O(n)O(n), Θ(nlog⁡n)\Theta(n\log n), Ω(n)\Omega(n) lower bounds.

  • Scientific computing★★★★★frequentScientific computing and algorithms

    Discretization errors are stated as O(hp)O(h^p): halve the step, divide the error by 2p2^p.

  • Monte Carlo methods★★★★★frequentScientific computing and algorithms

    Monte Carlo error is O(N−1/2)O(N^{-1/2}) in any dimension — 100 times more samples for one more digit.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Order by growth: n3/2n^{3/2}, 2n2^{\sqrt n}, nlog⁡2nn \log^2 n, (log⁡n)10(\log n)^{10}, nlog⁡nn^{\log n}.

Solution

(log⁡n)10≪nlog⁡2n≪n3/2≪nlog⁡n≪2n(\log n)^{10} \ll n\log^2 n \ll n^{3/2} \ll n^{\log n} \ll 2^{\sqrt n} (compare logarithms: 10log⁡log⁡n10\log\log n, log⁡n\log n, 1.5log⁡n1.5\log n, log⁡2n\log^2 n, n\sqrt n).

2Computing

An algorithm takes 1 s for n=1000n = 1000. Estimate the time for n=106n = 10^6 if it is Θ(n2)\Theta(n^2), and if it is Θ(nlog⁡n)\Theta(n\log n).

Solution

Θ(n2)\Theta(n^2): factor 10610^6 → about 11.6 days. Θ(nlog⁡n)\Theta(n\log n): factor 1000⋅log⁡106log⁡103=20001000 \cdot \frac{\log 10^6}{\log 10^3} = 2000 → about 33 minutes.

↑ ↓ to navigate · ↵ · Esc