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 O, Ω, Θ 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) be functions from N to non-negative reals (all functions in GATE questions are eventually positive, so we ignore sign issues).
Notation
Formal definition
Reading
Intuition
f=O(g)
∃c>0,∃n0,∀n≥n0:f(n)≤cg(n)
f is O(g)
g is an upper bound up to a constant
f=Ω(g)
∃c>0,∃n0,∀n≥n0:f(n)≥cg(n)
f is Ω(g)
g is a lower bound up to a constant
f=Θ(g)
f=O(g)andf=Ω(g)
f is Θ(g)
same growth up to constants
f=o(g)
∀c>0,∃n0,∀n≥n0:f(n)<cg(n)
f is o(g)
f grows strictly slower; f/g→0
f=ω(g)
∀c>0,∃n0,∀n≥n0:f(n)>cg(n)
f is ω(g)
f grows strictly faster; f/g→∞
Symbols: c = positive constant (the "hidden constant"), n0 = threshold beyond which the inequality holds, n = input size.
Key logical difference.O says some constant works (existential over c). o says every constant works (universal over c). That single quantifier flip is the source of most GATE traps.
1.1 The limit test (the workhorse)
Compute L=limn→∞g(n)f(n) (use L'Hôpital, or divide by the dominant term, or take logs). Then:
Value of L
Conclusion
L=0
f=o(g), hence f=O(g) but f=Θ(g)
0<L<∞
f=Θ(g) (also O and Ω)
L=∞
f=ω(g), hence f=Ω(g) but f=Θ(g)
limit oscillates / does not exist
limit test inconclusive; fall back to the definition
The last row matters: for functions like f(n)=n and g(n)=n1+sinn 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,h be eventually positive.
Property
Statement
Holds for
Reflexive
f=Θ(f), f=O(f), f=Ω(f)
O,Ω,Θ
Transitive
f=O(g) and g=O(h)⇒f=O(h)
O,Ω,Θ,o,ω
Symmetric
f=Θ(g)⟺g=Θ(f)
Θ only
Transpose symmetry
f=O(g)⟺g=Ω(f); f=o(g)⟺g=ω(f)
O/Ω, o/ω
Not symmetric
f=O(g) does not imply g=O(f)
O,Ω,o,ω
"Transpose symmetry" is the formal name for the O↔Ω mirror. Note O and Ω are reflexive and transitive but not symmetric — they are preorders, not equivalence relations. Only Θ is an equivalence relation.
1.3 What is NOT true (exam favourites)
f=O(g)⇒2f=O(2g). Counterexample: f(n)=2n, g(n)=n. Then f=O(g) (with c=2), but 2f=4n and 2g=2n, and 4n/2n=2n→∞, so 2f=ω(2g). Exponentiation destroys the constant: a factor c in the exponent becomes a factor 2c in the value.
Logs preserve O only in one direction, and only when g→∞. If f≥1, g→∞ and f≤cg, then logf≤logc+logg=O(logg). The converse is false: f=n2, g=n give logf=2logn=Θ(logg), yet n2=O(n). So logf=Θ(logg) does not mean f=Θ(g), and logs do not preserve Θ or o in general (f=n, g=n2: f=o(g) but logf=Θ(logg)). The correct log tool is the ratio rule of Section 3 (Trick A).
O(n)=o(n).f(n)=n is O(n) but not o(n) (ratio is 1, not 0). o(n) is the strict class; O(n) includes it plus everything Θ(n).
f=O(g) and f=Ω(g) together give Θ, but f=O(g) and g=O(f) also give Θ — same fact, two phrasings.
Constants do not matter inside Θ but do matter for the base of an exponent.3n2=Θ(n2); but 2n and 3n are notΘ-equal (3n/2n=(3/2)n→∞). Base of a polynomial is irrelevant; base of an exponential is decisive.
log base is irrelevant inside Θ: logan=logbn/logba, a constant factor. So log2n=Θ(log10n)=Θ(lnn). Write lgn for log2 when you want to be explicit; GATE accepts any base.
The standard growth ladder
From slowest to fastest (each entry is Θ 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!)=Θ(nlogn) — sits between n and n2, same class as nlogn.
nlogn — bigger than any nk (since logn→∞) but smaller than 2n (see Q3).
2logn — bigger than any power of logn, smaller than any ne (see Q4).
log∗n (iterated log: number of times you apply log to get ≤1) — grows slower than loglogn; it is ω(1) but o(loglogn).
22n — astronomically larger than 2n; 22n=ω(2n).
n1/logn — actually Θ(1)! (see Q5).
Why the ladder is ordered (one-line reasons):
Step
Reason
1<loglogn
loglogn→∞
loglogn<logn
log of a growing quantity grows slower than it
logn<(logn)k
a higher power of logn beats logn for k>1
(logn)k<ne
ne(logn)k→0 (L'Hôpital k times)
ne<n
e<1
n<nlogn
ratio logn→∞
nlogn<n2
ratio n/logn→∞
nk<2n
exponential beats any polynomial
2n<n!
n!/2n=∏i=1n(i/2)→∞
n!<nn
n!/nn=∏(i/n)≤1 and →0
Trick A — take logs of both sides
Write f/g=2logf−logg (base-2logs). If f,g→∞ and L=limlogglogf exists, then L<1⇒f=o(g) and L>1⇒f=ω(g); L=1 is inconclusive (compare logf−logg directly: n2 vs n both have L=1). Example: to compare nlogn with 2n, compare log(nlogn)=(logn)2 with log(2n)=n. Here L=lim(logn)2/n=0<1, so nlogn=o(2n).
Caution: use the ratio rule only when both sides tend to infinity. Never take logs term by term of a sum or difference, and never conclude f=Θ(g) from logf=Θ(logg).
Trick B — base change
logan=logbalogbn. The denominator is a constant, so base never affects Θ. But base does affect exact values in exponent identities: nlog2n=2(log2n)2, because n=2log2n, so nlogn=(2logn)logn=2(logn)2. This rewriting is the single most useful identity for these problems.
Trick C — rewrite everything as 2(⋅) or n(⋅)
Every function in these questions is either a power of n or a power of 2 (or a factorial). Convert to a common shape:
nk=2klogn
cn=2nlogc
nlogn=2(logn)2
(logn)logn=2logn⋅loglogn
n1/logn=2(1/logn)⋅logn=21=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
Sum
Closed form / Θ
Note
∑i=1n1
n=Θ(n)
∑i=1ni
2n(n+1)=Θ(n2)
arithmetic series
∑i=1nik
Θ(nk+1) for k>−1
integral test: ∫0nxkdx=k+1nk+1
∑i=1ni1
Hn=Θ(logn)
harmonic; Hn=lnn+γ+o(1)
∑i=1nlogi
log(n!)=Θ(nlogn)
Stirling
∑i=0n2i
2n+1−1=Θ(2n)
geometric, ratio 2
∑i=0nri, r>1
Θ(rn)
dominated by last term
∑i=0nri, 0<r<1
Θ(1)
dominated by first term
∑i=0niri, r>1
Θ(nrn)
last term times n
Rule of thumb for geometric series: if ratio >1, the last term dominates; if ratio <1, the first term dominates; if ratio =1, you get n terms.
Nested sums.∑i=1n∑j=1i1=∑i=1ni=Θ(n2). In general, evaluate the inner sum first (it becomes a function of the outer index), then sum again. ∑i=1n∑j=1n1=n2. ∑i=1n∑j=1i∑k=1j1=∑i∑jj=∑iΘ(i2)=Θ(n3).
Stirling's approximation (the version GATE needs):
n!=2πn(en)n(1+O(n1)),log(n!)=Θ(nlogn).
Symbols: e≈2.718, π≈3.1416. The 2πn factor is polynomial, so it never changes the Θ class; only (n/e)n matters.