1. Gyanastra
  2. Algorithms
  3. Growth Rates, Comparing Functions and Asymptotic Notation Tricks
  4. The five notations, formally
Free lesson, no account needed 10 min read
Asked in past papers4 times
  • GATE CSE20151989
  • UGC NET20232014

Algorithms · Growth Rates, Comparing Functions and Asymptotic Notation Tricks

The five notations, formally

This chapter is the "second pass" over asymptotic notation. The first pass (see Algorithm Analysis and Asymptotic Notation) told you what OO, Ω\Omega, Θ\Theta mean. Here we do the thing GATE actually asks: given a pile of functions, order them, and decide which asymptotic statements are true. We build the machinery (limit test, log-of-both-sides, base change, series sums), then grind through ten fully worked ordering questions with every arithmetic step shown.


Let f(n),g(n)f(n), g(n) be functions from N\mathbb{N} to non-negative reals (all functions in GATE questions are eventually positive, so we ignore sign issues).

NotationFormal definitionReadingIntuition
f=O(g)f = O(g)∃c>0, ∃n0, ∀n≥n0: f(n)≤c g(n)\exists c>0,\ \exists n_0,\ \forall n\ge n_0:\ f(n) \le c\,g(n)ff is O(g)O(g)gg is an upper bound up to a constant
f=Ω(g)f = \Omega(g)∃c>0, ∃n0, ∀n≥n0: f(n)≥c g(n)\exists c>0,\ \exists n_0,\ \forall n\ge n_0:\ f(n) \ge c\,g(n)ff is Ω(g)\Omega(g)gg is a lower bound up to a constant
f=Θ(g)f = \Theta(g)f=O(g)f=O(g) and f=Ω(g)f=\Omega(g)ff is Θ(g)\Theta(g)same growth up to constants
f=o(g)f = o(g)∀c>0, ∃n0, ∀n≥n0: f(n)<c g(n)\forall c>0,\ \exists n_0,\ \forall n\ge n_0:\ f(n) < c\,g(n)ff is o(g)o(g)ff grows strictly slower; f/g→0f/g\to 0
f=ω(g)f = \omega(g)∀c>0, ∃n0, ∀n≥n0: f(n)>c g(n)\forall c>0,\ \exists n_0,\ \forall n\ge n_0:\ f(n) > c\,g(n)ff is ω(g)\omega(g)ff grows strictly faster; f/g→∞f/g\to\infty

Symbols: cc = positive constant (the "hidden constant"), n0n_0 = threshold beyond which the inequality holds, nn = input size.

Key logical difference. OO says some constant works (existential over cc). oo says every constant works (universal over cc). That single quantifier flip is the source of most GATE traps.

1.1 The limit test (the workhorse)

Compute L=lim⁡n→∞f(n)g(n)L=\lim_{n\to\infty} \dfrac{f(n)}{g(n)} (use L'Hôpital, or divide by the dominant term, or take log⁡s\log s). Then:

Value of LLConclusion
L=0L = 0f=o(g)f = o(g), hence f=O(g)f=O(g) but f≠Θ(g)f\ne\Theta(g)
0<L<∞0 < L < \inftyf=Θ(g)f = \Theta(g) (also OO and Ω\Omega)
L=∞L = \inftyf=ω(g)f = \omega(g), hence f=Ω(g)f=\Omega(g) but f≠Θ(g)f\ne\Theta(g)
limit oscillates / does not existlimit test inconclusive; fall back to the definition

The last row matters: for functions like f(n)=nf(n)=n and g(n)=n1+sin⁡ng(n)=n^{1+\sin n} the ratio does not settle, and you must argue from the definition. GATE rarely does this, but know it exists.

1.2 Properties

Let f,g,hf,g,h be eventually positive.

PropertyStatementHolds for
Reflexivef=Θ(f)f=\Theta(f), f=O(f)f=O(f), f=Ω(f)f=\Omega(f)O,Ω,ΘO,\Omega,\Theta
Transitivef=O(g)f=O(g) and g=O(h)⇒f=O(h)g=O(h)\Rightarrow f=O(h)O,Ω,Θ,o,ωO,\Omega,\Theta,o,\omega
Symmetricf=Θ(g)  ⟺  g=Θ(f)f=\Theta(g)\iff g=\Theta(f)Θ\Theta only
Transpose symmetryf=O(g)  ⟺  g=Ω(f)f=O(g)\iff g=\Omega(f); f=o(g)  ⟺  g=ω(f)f=o(g)\iff g=\omega(f)O/ΩO/\Omega, o/ωo/\omega
Not symmetricf=O(g)f=O(g) does not imply g=O(f)g=O(f)O,Ω,o,ωO,\Omega,o,\omega

"Transpose symmetry" is the formal name for the O↔ΩO\leftrightarrow\Omega mirror. Note OO and Ω\Omega are reflexive and transitive but not symmetric — they are preorders, not equivalence relations. Only Θ\Theta is an equivalence relation.

1.3 What is NOT true (exam favourites)

  1. f=O(g)⇏2f=O(2g)f=O(g)\not\Rightarrow 2^{f}=O(2^{g}). Counterexample: f(n)=2nf(n)=2n, g(n)=ng(n)=n. Then f=O(g)f=O(g) (with c=2c=2), but 2f=4n2^{f}=4^{n} and 2g=2n2^{g}=2^{n}, and 4n/2n=2n→∞4^n/2^n=2^n\to\infty, so 2f=ω(2g)2^f=\omega(2^g). Exponentiation destroys the constant: a factor cc in the exponent becomes a factor 2c2^{c} in the value.
  2. Logs preserve OO only in one direction, and only when g→∞g\to\infty. If f≥1f\ge1, g→∞g\to\infty and f≤cgf\le cg, then log⁡f≤log⁡c+log⁡g=O(log⁡g)\log f\le\log c+\log g=O(\log g). The converse is false: f=n2f=n^2, g=ng=n give log⁡f=2log⁡n=Θ(log⁡g)\log f=2\log n=\Theta(\log g), yet n2≠O(n)n^2\ne O(n). So log⁡f=Θ(log⁡g)\log f=\Theta(\log g) does not mean f=Θ(g)f=\Theta(g), and log⁡s\log s do not preserve Θ\Theta or oo in general (f=nf=n, g=n2g=n^2: f=o(g)f=o(g) but log⁡f=Θ(log⁡g)\log f=\Theta(\log g)). The correct log tool is the ratio rule of Section 3 (Trick A).
  3. O(n)≠o(n)O(n)\ne o(n). f(n)=nf(n)=n is O(n)O(n) but not o(n)o(n) (ratio is 11, not 00). o(n)o(n) is the strict class; O(n)O(n) includes it plus everything Θ(n)\Theta(n).
  4. f=O(g)f=O(g) and f=Ω(g)f=\Omega(g) together give Θ\Theta, but f=O(g)f=O(g) and g=O(f)g=O(f) also give Θ\Theta — same fact, two phrasings.
  5. Constants do not matter inside Θ\Theta but do matter for the base of an exponent. 3n2=Θ(n2)3n^2=\Theta(n^2); but 2n2^n and 3n3^n are not Θ\Theta-equal (3n/2n=(3/2)n→∞3^n/2^n=(3/2)^n\to\infty). Base of a polynomial is irrelevant; base of an exponential is decisive.
  6. log⁡\log base is irrelevant inside Θ\Theta: log⁡an=log⁡bn/log⁡ba\log_a n = \log_b n/\log_b a, a constant factor. So log⁡2n=Θ(log⁡10n)=Θ(ln⁡n)\log_2 n=\Theta(\log_{10} n)=\Theta(\ln n). Write lg⁡n\lg n for log⁡2\log_2 when you want to be explicit; GATE accepts any base.

The standard growth ladder

From slowest to fastest (each entry is Θ\Theta of the class):

1  <  log log n  <  log n  <  (log n)^k (k>1)  <  n^e (0<e<1)  <  n
   <  n log n  <  n^2  <  n^k (k>2)  <  2^n  <  n!  <  n^n

Also worth memorising, inserted where they belong:

  • log⁡(n!)=Θ(nlog⁡n)\log(n!) = \Theta(n\log n) — sits between nn and n2n^2, same class as nlog⁡nn\log n.
  • nlog⁡nn^{\log n} — bigger than any nkn^k (since log⁡n→∞\log n\to\infty) but smaller than 2n2^n (see Q3).
  • 2log⁡n2^{\sqrt{\log n}} — bigger than any power of log⁡n\log n, smaller than any nen^e (see Q4).
  • log⁡∗n\log^* n (iterated log: number of times you apply log⁡\log to get ≤1\le 1) — grows slower than log⁡log⁡n\log\log n; it is ω(1)\omega(1) but o(log⁡log⁡n)o(\log\log n).
  • 22n2^{2^n} — astronomically larger than 2n2^n; 22n=ω(2n)2^{2^n}=\omega(2^n).
  • n1/log⁡nn^{1/\log n} — actually Θ(1)\Theta(1)! (see Q5).

Why the ladder is ordered (one-line reasons):

StepReason
1<log⁡log⁡n1 < \log\log nlog⁡log⁡n→∞\log\log n\to\infty
log⁡log⁡n<log⁡n\log\log n < \log nlog⁡\log of a growing quantity grows slower than it
log⁡n<(log⁡n)k\log n < (\log n)^ka higher power of log⁡n\log n beats log⁡n\log n for k>1k>1
(log⁡n)k<ne(\log n)^k < n^e(log⁡n)kne→0\dfrac{(\log n)^k}{n^e}\to 0 (L'Hôpital kk times)
ne<nn^e < ne<1e<1
n<nlog⁡nn < n\log nratio log⁡n→∞\log n\to\infty
nlog⁡n<n2n\log n < n^2ratio n/log⁡n→∞n/\log n\to\infty
nk<2nn^k < 2^nexponential beats any polynomial
2n<n!2^n < n!n!/2n=∏i=1n(i/2)→∞n!/2^n=\prod_{i=1}^n (i/2)\to\infty
n!<nnn! < n^nn!/nn=∏(i/n)≤1n!/n^n=\prod (i/n)\le 1 and →0\to 0

Trick A — take log⁡s\log s of both sides

Write f/g=2log⁡f−log⁡gf/g=2^{\log f-\log g} (base-2log⁡s2 \log s). If f,g→∞f,g\to\infty and L=lim⁡log⁡flog⁡gL=\lim \dfrac{\log f}{\log g} exists, then L<1⇒f=o(g)L<1\Rightarrow f=o(g) and L>1⇒f=ω(g)L>1\Rightarrow f=\omega(g); L=1L=1 is inconclusive (compare log⁡f−log⁡g\log f-\log g directly: n2n^2 vs nn both have L=1L=1). Example: to compare nlog⁡nn^{\log n} with 2n2^n, compare log⁡(nlog⁡n)=(log⁡n)2\log(n^{\log n})=(\log n)^2 with log⁡(2n)=n\log(2^n)=n. Here L=lim⁡(log⁡n)2/n=0<1L=\lim (\log n)^2/n=0<1, so nlog⁡n=o(2n)n^{\log n}=o(2^n).

Caution: use the ratio rule only when both sides tend to infinity. Never take log⁡s\log s term by term of a sum or difference, and never conclude f=Θ(g)f=\Theta(g) from log⁡f=Θ(log⁡g)\log f=\Theta(\log g).

Trick B — base change

log⁡an=log⁡bnlog⁡ba\log_a n=\dfrac{\log_b n}{\log_b a}. The denominator is a constant, so base never affects Θ\Theta. But base does affect exact values in exponent identities: nlog⁡2n=2(log⁡2n)2n^{\log_2 n}=2^{(\log_2 n)^2}, because n=2log⁡2nn=2^{\log_2 n}, so nlog⁡n=(2log⁡n)log⁡n=2(log⁡n)2n^{\log n}=(2^{\log n})^{\log n}=2^{(\log n)^2}. This rewriting is the single most useful identity for these problems.

Trick C — rewrite everything as 2(⋅)2^{(\cdot)} or n(⋅)n^{(\cdot)}

Every function in these questions is either a power of nn or a power of 22 (or a factorial). Convert to a common shape:

  • nk=2klog⁡nn^k = 2^{k\log n}
  • cn=2nlog⁡cc^n = 2^{n\log c}
  • nlog⁡n=2(log⁡n)2n^{\log n}=2^{(\log n)^2}
  • (log⁡n)log⁡n=2log⁡n⋅log⁡log⁡n(\log n)^{\log n}=2^{\log n\cdot\log\log n}
  • n1/log⁡n=2(1/log⁡n)⋅log⁡n=21=2n^{1/\log n}=2^{(1/\log n)\cdot\log n}=2^{1}=2

Then comparing two functions reduces to comparing their exponents. This is the fastest reliable method and is what the worked solutions below use.


Series and sums you must know

SumClosed form / Θ\ThetaNote
∑i=1n1\sum_{i=1}^n 1n=Θ(n)n=\Theta(n)
∑i=1ni\sum_{i=1}^n in(n+1)2=Θ(n2)\dfrac{n(n+1)}{2}=\Theta(n^2)arithmetic series
∑i=1nik\sum_{i=1}^n i^kΘ(nk+1)\Theta(n^{k+1}) for k>−1k>-1integral test: ∫0nxkdx=nk+1k+1\int_0^n x^k dx=\frac{n^{k+1}}{k+1}
∑i=1n1i\sum_{i=1}^n \dfrac{1}{i}Hn=Θ(log⁡n)H_n=\Theta(\log n)harmonic; Hn=ln⁡n+γ+o(1)H_n=\ln n+\gamma+o(1)
∑i=1nlog⁡i\sum_{i=1}^n \log ilog⁡(n!)=Θ(nlog⁡n)\log(n!)=\Theta(n\log n)Stirling
∑i=0n2i\sum_{i=0}^n 2^i2n+1−1=Θ(2n)2^{n+1}-1=\Theta(2^n)geometric, ratio 2
∑i=0nri\sum_{i=0}^n r^i, r>1r>1Θ(rn)\Theta(r^n)dominated by last term
∑i=0nri\sum_{i=0}^n r^i, 0<r<10<r<1Θ(1)\Theta(1)dominated by first term
∑i=0ni ri\sum_{i=0}^n i\,r^i, r>1r>1Θ(nrn)\Theta(n r^n)last term times nn

Rule of thumb for geometric series: if ratio >1>1, the last term dominates; if ratio <1<1, the first term dominates; if ratio =1=1, you get nn terms.

Nested sums. ∑i=1n∑j=1i1=∑i=1ni=Θ(n2)\sum_{i=1}^n\sum_{j=1}^{i} 1=\sum_{i=1}^n i=\Theta(n^2). In general, evaluate the inner sum first (it becomes a function of the outer index), then sum again. ∑i=1n∑j=1n1=n2\sum_{i=1}^n\sum_{j=1}^{n} 1 = n^2. ∑i=1n∑j=1i∑k=1j1=∑i∑jj=∑iΘ(i2)=Θ(n3)\sum_{i=1}^{n}\sum_{j=1}^{i}\sum_{k=1}^{j}1=\sum_i\sum_j j=\sum_i \Theta(i^2)=\Theta(n^3).

Stirling's approximation (the version GATE needs): n!=2πn(ne)n(1+O ⁣(1n)),log⁡(n!)=Θ(nlog⁡n).n! = \sqrt{2\pi n}\left(\frac{n}{e}\right)^n\left(1+O\!\left(\tfrac1n\right)\right),\qquad \log(n!)=\Theta(n\log n). Symbols: e≈2.718e\approx 2.718, π≈3.1416\pi\approx 3.1416. The 2πn\sqrt{2\pi n} factor is polynomial, so it never changes the Θ\Theta class; only (n/e)n(n/e)^n matters.


Pages 1–2 of 2