Introduction

The exact running time of a program depends on the machine, the compiler and the input. To compare algorithms rather than programs, we describe how the running time grows as the input size nn grows, ignoring constant factors and small inputs. Asymptotic notation is the language for this: it lets us say that merge sort takes "Θ(nlg⁡n)\Theta(n \lg n) time in the worst case" and mean something precise.

There are five notations: OO, Ω\Omega, Θ\Theta, oo and ω\omega. Each is a statement about two functions for all sufficiently large nn. They are used for running time, space, number of comparisons, or any other cost measure, and in any case (worst, best or average).

Throughout, lg⁡n\lg n means log⁡2n\log_2 n, and functions are asymptotically non-negative (non-negative for all large nn), as running times are.

Prerequisites

  • Limits: limits at infinity and L'Hopital's rule, used in the limit test.
  • Laws of logarithms and exponents: alog⁡bc=clog⁡baa^{\log_b c} = c^{\log_b a}, log⁡bn=lg⁡n/lg⁡b\log_b n = \lg n / \lg b.

Core concepts

The five definitions

Let ff and gg be functions from the positive integers to the reals. Each notation defines a set of functions, so "f(n)=O(g(n))f(n) = O(g(n))" really means f(n)∈O(g(n))f(n) \in O(g(n)). The definitions below are those of CLRS 3e, Section 3.1.

NotationDefinitionInformal reading
f(n)=O(g(n))f(n) = O(g(n))there exist constants c>0c > 0 and n0>0n_0 > 0 with 0≤f(n)≤c g(n)0 \le f(n) \le c\,g(n) for all n≥n0n \ge n_0ff grows no faster than gg (upper bound)
f(n)=Ω(g(n))f(n) = \Omega(g(n))there exist constants c>0c > 0 and n0>0n_0 > 0 with 0≤c g(n)≤f(n)0 \le c\,g(n) \le f(n) for all n≥n0n \ge n_0ff grows at least as fast as gg (lower bound)
f(n)=Θ(g(n))f(n) = \Theta(g(n))there exist constants c1,c2>0c_1, c_2 > 0 and n0>0n_0 > 0 with 0≤c1g(n)≤f(n)≤c2g(n)0 \le c_1 g(n) \le f(n) \le c_2 g(n) for all n≥n0n \ge n_0ff grows at the same rate as gg (tight bound)
f(n)=o(g(n))f(n) = o(g(n))for every constant c>0c > 0 there is an n0>0n_0 > 0 with 0≤f(n)<c g(n)0 \le f(n) < c\,g(n) for all n≥n0n \ge n_0ff grows strictly slower than gg
f(n)=ω(g(n))f(n) = \omega(g(n))for every constant c>0c > 0 there is an n0>0n_0 > 0 with 0≤c g(n)<f(n)0 \le c\,g(n) < f(n) for all n≥n0n \ge n_0ff grows strictly faster than gg

The difference between OO and oo is the quantifier on cc. For OO it is enough that some constant works; for oo every positive constant must work, however small. So 2n2=O(n2)2n^2 = O(n^2) but 2n2≠o(n2)2n^2 \ne o(n^2), while 2n=o(n2)2n = o(n^2).

Theorem (CLRS 3e, Theorem 3.1). f(n)=Θ(g(n))f(n) = \Theta(g(n)) if and only if f(n)=O(g(n))f(n) = O(g(n)) and f(n)=Ω(g(n))f(n) = \Omega(g(n)).

Graphical meaning of Theta, O and Omega
Figure 1. Three panels. Theta: beyond n0n_0, f(n)f(n) stays between c1g(n)c_1 g(n) and c2g(n)c_2 g(n). O: beyond n0n_0, f(n)f(n) stays on or below c g(n)c\,g(n). Omega: beyond n0n_0, f(n)f(n) stays on or above c g(n)c\,g(n). The behaviour to the left of n0n_0 does not matter.

Analogy with comparing numbers

FunctionsNumbers
f=O(g)f = O(g)a≤ba \le b
f=Ω(g)f = \Omega(g)a≥ba \ge b
f=Θ(g)f = \Theta(g)a=ba = b
f=o(g)f = o(g)a<ba < b
f=ω(g)f = \omega(g)a>ba > b

The analogy breaks in one place: trichotomy fails. For real numbers exactly one of a<ba < b, a=ba = b, a>ba > b holds. Two functions can be incomparable. Take g(n)=n2g(n) = n^2 and

f(n)={nn evenn3n odd.f(n) = \begin{cases} n & n \text{ even} \\ n^3 & n \text{ odd.} \end{cases}

On even nn, f(n)/g(n)=1/n→0f(n)/g(n) = 1/n \to 0, so f≠Ω(g)f \ne \Omega(g). On odd nn, f(n)/g(n)=n→∞f(n)/g(n) = n \to \infty, so f≠O(g)f \ne O(g). Neither bound holds.

Properties

For asymptotically positive ff, gg, hh:

  • Transitivity (all five): f=O(g)f = O(g) and g=O(h)g = O(h) imply f=O(h)f = O(h); likewise for Ω\Omega, Θ\Theta, oo, ω\omega.
  • Reflexivity: f=O(f)f = O(f), f=Ω(f)f = \Omega(f), f=Θ(f)f = \Theta(f). Never f=o(f)f = o(f) or f=ω(f)f = \omega(f).
  • Symmetry: f=Θ(g)f = \Theta(g) if and only if g=Θ(f)g = \Theta(f).
  • Transpose symmetry: f=O(g)  ⟺  g=Ω(f)f = O(g) \iff g = \Omega(f), and f=o(g)  ⟺  g=ω(f)f = o(g) \iff g = \omega(f).
  • Strictness: o(g)⊂O(g)o(g) \subset O(g) and o(g)∩Ω(g)=∅o(g) \cap \Omega(g) = \emptyset; similarly ω(g)⊂Ω(g)\omega(g) \subset \Omega(g) and ω(g)∩O(g)=∅\omega(g) \cap O(g) = \emptyset.
  • Sum rule: f(n)+g(n)=Θ(max⁡(f(n),g(n)))f(n) + g(n) = \Theta(\max(f(n), g(n))), because max⁡≤f+g≤2max⁡\max \le f + g \le 2 \max. So lower-order terms can be dropped: 3n2+10n+5=Θ(n2)3n^2 + 10n + 5 = \Theta(n^2).
  • Product rule: O(f)⋅O(g)=O(fg)O(f) \cdot O(g) = O(f g); the same holds for Ω\Omega and Θ\Theta.
  • Constant factors: c f=Θ(f)c\,f = \Theta(f) for any constant c>0c > 0.

The limit test

If g(n)>0g(n) > 0 for large nn and the limit L=lim⁡n→∞f(n)/g(n)L = \lim_{n \to \infty} f(n)/g(n) exists (allowing L=∞L = \infty), then:

Value of LLConclusion
L=0L = 0f=o(g)f = o(g), hence also f=O(g)f = O(g)
0<L<∞0 < L < \inftyf=Θ(g)f = \Theta(g)
L=∞L = \inftyf=ω(g)f = \omega(g), hence also f=Ω(g)f = \Omega(g)

For oo and ω\omega the test is also necessary: f=o(g)f = o(g) exactly when the limit is 0. For Θ\Theta it is only sufficient: f(n)=n(2+sin⁡n)f(n) = n(2 + \sin n) is Θ(n)\Theta(n) (it lies between nn and 3n3n), yet f(n)/nf(n)/n has no limit. When the limit does not exist, go back to the definitions.

Standard growth rates

For constants k>2k>2, 0<ε<10<\varepsilon<1 and a>1a>1, each function below is oo of the next:

1  ≺  lg⁡lg⁡n  ≺  lg⁡n  ≺  (lg⁡n)k  ≺  nε  ≺  n  ≺  nlg⁡n  ≺  n2  ≺  nk (k>2)  ≺  an  ≺  n!  ≺  nn,1 \;\prec\; \lg \lg n \;\prec\; \lg n \;\prec\; (\lg n)^k \;\prec\; n^{\varepsilon} \;\prec\; n \;\prec\; n \lg n \;\prec\; n^2 \;\prec\; n^k\ (k > 2) \;\prec\; a^n \;\prec\; n! \;\prec\; n^n,

where ≺\prec means "is little-o of". The three facts doing the work are:

  • Polylogarithms lose to polynomials. (lg⁡n)k=o(nε)(\lg n)^k = o(n^{\varepsilon}) for every k>0k > 0, ε>0\varepsilon > 0, however large kk and small ε\varepsilon.
  • Polynomials lose to exponentials. nk=o(an)n^k = o(a^n) for every k>0k > 0 and a>1a > 1.
  • Exponentials with different bases differ. For 1<a<b1 < a < b, an=o(bn)a^n = o(b^n). So 2n=o(3n)2^n = o(3^n) and 2n=o(4n)2^n = o(4^n).

Useful identities and estimates:

  • Base of a logarithm does not matter. log⁡bn=lg⁡n/lg⁡b=Θ(lg⁡n)\log_b n = \lg n / \lg b = \Theta(\lg n) for any constant b>1b > 1. That is why we write O(lg⁡n)O(\lg n) without a base. The base of an exponential does matter.
  • Exponent of a logarithm. lg⁡(nk)=klg⁡n=Θ(lg⁡n)\lg(n^k) = k \lg n = \Theta(\lg n), but (lg⁡n)k(\lg n)^k is a different, larger class for k>1k > 1.
  • Swapping base and argument. alog⁡bc=clog⁡baa^{\log_b c} = c^{\log_b a}. For example 2lg⁡n=n2^{\lg n} = n, 4lg⁡n=n24^{\lg n} = n^2 and nlg⁡3=3lg⁡nn^{\lg 3} = 3^{\lg n}.
  • Factorials (Stirling). n!=2πn (n/e)n(1+Θ(1/n))n! = \sqrt{2\pi n}\,(n/e)^n (1 + \Theta(1/n)). Consequences: lg⁡(n!)=Θ(nlg⁡n)\lg(n!) = \Theta(n \lg n), n!=o(nn)n! = o(n^n) and n!=ω(2n)n! = \omega(2^n).
  • Shifts. (n+a)b=Θ(nb)(n + a)^b = \Theta(n^b) for constants aa and b>0b > 0; 2n+1=2⋅2n=Θ(2n)2^{n+1} = 2 \cdot 2^n = \Theta(2^n); but 22n=4n≠O(2n)2^{2n} = 4^n \ne O(2^n).
Growth-rate comparison of common functions
Figure 2. Growth of lg⁡n\lg n, n\sqrt{n}, nn, nlg⁡nn \lg n, n2n^2 and 2n2^n for 1≤n≤201 \le n \le 20, with the points where n2=2nn^2 = 2^n (n=2n = 2 and n=4n = 4) marked; 2n>n22^n > n^2 for every n≥5n \ge 5.

Worked examples

Example 1: proving a Theta bound with explicit constants

Claim: f(n)=3n2+10n+5=Θ(n2)f(n) = 3n^2 + 10n + 5 = \Theta(n^2).

  • Lower bound. 3n2≤3n2+10n+53n^2 \le 3n^2 + 10n + 5 for all n≥1n \ge 1. Take c1=3c_1 = 3.
  • Upper bound. Try c2=4c_2 = 4: we need 3n2+10n+5≤4n23n^2 + 10n + 5 \le 4n^2, that is n2−10n−5≥0n^2 - 10n - 5 \ge 0. The positive root is 5+30≈10.485 + \sqrt{30} \approx 10.48, so the inequality holds for every integer n≥11n \ge 11 and fails at n=10n = 10 (−5<0-5 < 0).

So c1=3c_1 = 3, c2=4c_2 = 4, n0=11n_0 = 11 witness the bound. Other choices work too: c2=18c_2 = 18 works from n0=1n_0 = 1, since 3n2+10n+5≤3n2+10n2+5n23n^2 + 10n + 5 \le 3n^2 + 10n^2 + 5n^2 for n≥1n \ge 1. The constants are not unique; only their existence matters.

Example 2: showing a bound fails

Claim: n3≠O(n2)n^3 \ne O(n^2). Suppose n3≤c n2n^3 \le c\,n^2 for all n≥n0n \ge n_0. Dividing by n2n^2 gives n≤cn \le c for all n≥n0n \ge n_0, which is false for n>max⁡(c,n0)n > \max(c, n_0). The same argument shows 22n≠O(2n)2^{2n} \ne O(2^n): it would need 2n≤c2^n \le c for all large nn.

Example 3: ranking functions

Arrange in increasing order of growth: 2n2^n, nlg⁡nn \lg n, nlg⁡nn^{\lg n}, (lg⁡n)10(\lg n)^{10}, n!n!, n\sqrt{n}, 4n4^n, lg⁡(n!)\lg(n!), n1.01n^{1.01}.

Rewriting each function, or taking its lg⁡\lg, is a quick way to compare those that grow faster than any polynomial:

FunctionRewrite or logarithmClass
(lg⁡n)10(\lg n)^{10}10lg⁡lg⁡n10 \lg \lg npolylogarithmic
n\sqrt{n}12lg⁡n\tfrac{1}{2} \lg npolynomial, degree 1/21/2
nlg⁡nn \lg n and lg⁡(n!)\lg(n!)lg⁡(n!)=Θ(nlg⁡n)\lg(n!) = \Theta(n \lg n) by StirlingΘ(nlg⁡n)\Theta(n \lg n) (same class)
n1.01n^{1.01}1.01lg⁡n1.01 \lg npolynomial, degree 1.011.01
nlg⁡nn^{\lg n}(lg⁡n)2(\lg n)^2quasi-polynomial
2n2^nnnexponential
4n4^n2n2nexponential, larger base
n!n!lg⁡(n!)=Θ(nlg⁡n)\lg(n!) = \Theta(n \lg n)factorial

Answer: (lg⁡n)10≺n≺nlg⁡n≍lg⁡(n!)≺n1.01≺nlg⁡n≺2n≺4n≺n!(\lg n)^{10} \prec \sqrt{n} \prec n \lg n \asymp \lg(n!) \prec n^{1.01} \prec n^{\lg n} \prec 2^n \prec 4^n \prec n!, where ≍\asymp means Θ\Theta of each other.

Two cautions about the log trick:

  • If lg⁡f=o(lg⁡g)\lg f = o(\lg g) and lg⁡g→∞\lg g \to \infty, then f=o(g)f = o(g). This settles nlg⁡nn^{\lg n} versus 2n2^n: (lg⁡n)2=o(n)(\lg n)^2 = o(n).
  • If only lg⁡f=Θ(lg⁡g)\lg f = \Theta(\lg g), nothing follows: lg⁡(n2)=2lg⁡n=Θ(lg⁡n)\lg(n^2) = 2\lg n = \Theta(\lg n), yet n2≠O(n)n^2 \ne O(n). Similarly lg⁡(2n)=n\lg(2^n) = n and lg⁡(4n)=2n\lg(4^n) = 2n are Θ\Theta of each other, but 4n=ω(2n)4^n = \omega(2^n). Compare the functions themselves in such cases.

Note also that n1.01n^{1.01} beats nlg⁡nn \lg n only for very large nn: at n=220n = 2^{20}, n0.01=20.2≈1.15n^{0.01} = 2^{0.2} \approx 1.15 while lg⁡n=20\lg n = 20. Asymptotic order says nothing about where the crossover occurs.

Example 4: disguised functions

Several functions look exotic but become simple once written as a power of 2. Put n=2mn = 2^m, so m=lg⁡nm = \lg n:

FunctionAs a power of 2Class
n1/lg⁡nn^{1/\lg n}212^{1}Θ(1)\Theta(1), the constant 2
(2)lg⁡n(\sqrt{2})^{\lg n}2m/22^{m/2}n\sqrt{n}
2lg⁡n2^{\sqrt{\lg n}}2m2^{\sqrt{m}}faster than every polylog, slower than every nεn^{\varepsilon}
(lg⁡n)lg⁡n(\lg n)^{\lg n}2mlg⁡m2^{m \lg m}equal to nlg⁡lg⁡nn^{\lg \lg n}: superpolynomial, subexponential
nlg⁡7n^{\lg 7}2mlg⁡72^{m \lg 7}n2.807…n^{2.807\ldots}, so o(n2.81)o(n^{2.81}) but ω(n2.8)\omega(n^{2.8})

The third row is the one to watch. Against a polylog (lg⁡n)k=2klg⁡m(\lg n)^k = 2^{k \lg m}, the exponent m\sqrt{m} beats klg⁡mk \lg m; against nε=2εmn^{\varepsilon} = 2^{\varepsilon m}, the exponent εm\varepsilon m beats m\sqrt{m}. Since the exponent differences tend to infinity, the log trick applies in both directions. Crossovers can be far out: m>10lg⁡m\sqrt{m} > 10 \lg m fails for every integer mm from 2 to 20,519 and holds from m=20,520m = 20{,}520 on, so 2lg⁡n2^{\sqrt{\lg n}} overtakes (lg⁡n)10(\lg n)^{10} only beyond n=220520n = 2^{20520}.

The last row matters for Strassen's Θ(nlg⁡7)\Theta(n^{\lg 7}): lg⁡7≈2.8074\lg 7 \approx 2.8074, so "O(n2.81)O(n^{2.81})" is a correct upper bound and "O(n2.8)O(n^{2.8})" is false.

Notation versus cases

Asymptotic notation and the case of analysis are independent choices.

  • The case fixes a function: the worst-case running time Tworst(n)T_{\text{worst}}(n) is the maximum over inputs of size nn; the best case is the minimum; the average case is an expectation under a stated input distribution.
  • The notation then bounds that function.

So "the worst case of insertion sort is Θ(n2)\Theta(n^2)" and "the best case of insertion sort is Θ(n)\Theta(n)" are both precise. "The running time of insertion sort", with no case, is not a single function; the strongest correct statements about it are O(n2)O(n^2) and Ω(n)\Omega(n). It is not Θ(n2)\Theta(n^2) on every input.

Common misreadings to avoid:

  • "OO means worst case and Ω\Omega means best case." False. A worst case can have a lower bound (the worst case of merge sort is Ω(nlg⁡n)\Omega(n \lg n)), and a best case can have an upper bound.
  • "O(n2)O(n^2) means the algorithm takes about n2n^2 steps." False. OO is only an upper bound; a Θ(n)\Theta(n) algorithm is also O(n2)O(n^2). Use Θ\Theta when the bound is tight.
  • In an equation such as T(n)=2n2+Θ(n)T(n) = 2n^2 + \Theta(n), the Θ(n)\Theta(n) stands for some anonymous function in that set.

Important properties and observations

  • f=O(g)f = O(g) does not imply 2f=O(2g)2^{f} = O(2^{g}). Counterexample: f(n)=2nf(n) = 2n, g(n)=ng(n) = n; then 22n=4n≠O(2n)2^{2n} = 4^n \ne O(2^n).
  • f=O(g)f = O(g) does not imply g=O(f)g = O(f): n=O(n2)n = O(n^2) but n2≠O(n)n^2 \ne O(n).
  • f(n)=O(f(n)2)f(n) = O(f(n)^2) fails when f(n)→0f(n) \to 0, for example f(n)=1/nf(n) = 1/n. It holds when f(n)≥1f(n) \ge 1 for large nn.
  • f(n)=Θ(f(n/2))f(n) = \Theta(f(n/2)) holds for polynomials (n2n^2 versus n2/4n^2/4) but fails for 2n2^n, since 2n/2n/2=2n/2→∞2^n / 2^{n/2} = 2^{n/2} \to \infty.
  • f(n)+o(f(n))=Θ(f(n))f(n) + o(f(n)) = \Theta(f(n)).
  • Asymptotic order is about large nn only. An algorithm with cost 100n100 n is o(n2)o(n^2) yet slower than one with cost n2n^2 for every n<100n < 100.
  • For polynomials: adnd+⋯+a0=Θ(nd)a_d n^d + \dots + a_0 = \Theta(n^d) when ad>0a_d > 0.

GATE examination perspective

  • True/false statements on pairs of functions. For each pair, decide which of OO, Ω\Omega, Θ\Theta, oo, ω\omega hold, using the limit test where the limit exists and the definitions otherwise.
  • Ranking functions by growth rate. Rewrite each function as a power of 2 or of nn, compare logarithms with the cautions above, and remember lg⁡(n!)=Θ(nlg⁡n)\lg(n!) = \Theta(n \lg n) and alog⁡bc=clog⁡baa^{\log_b c} = c^{\log_b a}.
  • Traps. Bases of exponentials matter (2n2^n versus 4n4^n); bases of logarithms do not. lg⁡(nk)\lg(n^k) is Θ(lg⁡n)\Theta(\lg n) but (lg⁡n)k(\lg n)^k is not Θ(lg⁡n)\Theta(\lg n) for fixed k>0k>0, k≠1k\ne1. nlg⁡nn^{\lg n} is superpolynomial but subexponential. A function can be in neither O(g)O(g) nor Ω(g)\Omega(g). 2lg⁡n2^{\sqrt{\lg n}} lies strictly between polylogarithmic and polynomial.
  • Disguised constants and powers. n1/lg⁡n=2n^{1/\lg n} = 2; (lg⁡n)lg⁡n=nlg⁡lg⁡n(\lg n)^{\lg n} = n^{\lg \lg n}; 4lg⁡n=n24^{\lg n} = n^2. Convert to a power of 2 before comparing.
  • Precision of language. A statement can turn on OO versus Θ\Theta and on which case (worst or best) is meant. Read both.

Summary

Sources

  1. T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein, Introduction to Algorithms, 3rd ed., MIT Press, 2009: Chapter 3 "Growth of Functions" (Section 3.1 asymptotic notation and Theorem 3.1; Section 3.2 standard notations, logarithms, factorials and Stirling's approximation).
  2. GATE 2027 Computer Science and Information Technology syllabus, IIT Madras, Section 5 "Algorithms": (consulted 2026-11-09).

Next steps