Algorithms · Growth Rates, Comparing Functions and Asymptotic Notation Tricks
Ten fully worked GATE-style ordering questions
In each, arrange in increasing order of growth (slowest first). Every step is shown.
Q1. n,logn,nlogn,n2,2n,loglogn,1
Compare pairwise using the ladder. loglogn grows without bound but slower than logn (since loglogn/logn→0). 1 is constant. Chain:
1≺loglogn≺logn≺n≺nlogn≺n2≺2n.
Check the two nontrivial links: n/(logn)→∞ ✓; nlogn/n2=logn/n→0 ✓.
Q2. n,log3n,n0.1,2logn
All four are sub-linear or near-linear; compare via exponents base 2.
n=n1/2=221logn.
log3n=23loglogn.
n0.1=20.1logn.
2logn=2(logn)1/2.
Compare exponents: 3loglogn vs (logn)1/2 vs 0.1logn vs 0.5logn.
3loglogn=o((logn)1/2): ratio =(logn)1/23loglogn→0 (log grows slower than any positive power). So log3n≺2logn.
(logn)1/2=o(logn), and 0.1logn<0.5logn, so 2logn≺n0.1≺n.
Order:
log3n≺2logn≺n0.1≺n.
(Sanity: log3n is polylog; 2logn is "quasi-polylog", bigger than any polylog; n0.1 and n0.5 are polynomial.)
Q3. nlogn vs 2n vs nloglogn
Rewrite base 2:
nlogn=2(logn)2.
2n=2n.
nloglogn=2logn⋅loglogn.
Compare exponents: (logn)2 vs lognloglogn vs n.
lognloglogn=o((logn)2) (ratio =loglogn/logn→0). So nloglogn≺nlogn.
(logn)2=o(n) (polylog vs linear). So nlogn≺2n.
Order: nloglogn≺nlogn≺2n.
Q4. 2logn vs (logn)logn vs n
2logn=2(logn)1/2.
(logn)logn=2logn⋅loglogn.
n=2logn.
Exponents: (logn)1/2 vs lognloglogn vs logn. Since (logn)1/2=o(logn) and logn=o(lognloglogn):
2logn≺n≺(logn)logn.
Note (logn)logn is super-polynomial (bigger than nk for every fixed k) yet sub-exponential (smaller than 2ne for every e>0). Good trap.
Q5. n1/logn vs logn vs 1
Rewrite: n1/logn=2(1/logn)⋅logn=21=2. So n1/logn=Θ(1), a constant (equal to 2 if the logs share a base; in general it equals the base, hence Θ(1) regardless). Therefore:
n1/logn=Θ(1)≺logn.
This is the classic "looks scary, is constant" question.
Q6. log(n!) vs nlogn vs n2 vs 2n
Stirling: log(n!)=Θ(nlogn). So log(n!) and nlogn are Θ-equal (write them as one class). Then nlogn≺n2≺2n. Order:
log(n!)≈nlogn≺n2≺2n.
If the question forces a strict order between log(n!) and nlogn: log(n!)=nlogn−nloge+O(logn), so log(n!) is slightly smaller but same Θ class — GATE treats them as equal.
Q7. n! vs 2n vs nn vs 22n
n!/2n=∏i=1n(i/2). For i≥3 each factor >1, so the product →∞: 2n≺n!.
n!/nn=∏i=1n(i/n)≤1 and in fact →0 (Stirling: n!≈(n/e)n2πn, ratio to nn is 2πn/en→0): n!≺nn.
22n vs nn: take logs. log(22n)=2n. log(nn)=nlogn. Since nlogn=o(2n), we get nn≺22n.
Order: 2n≺n!≺nn≺22n.
Q8. log∗n vs loglogn vs logn
log∗n = number of times to apply log2 before the value drops to ≤1. For n=216=65536: log265536=16, log216=4, log24=2, log22=1 — four applications, so log∗65536=4 (books differ by an additive constant in the convention; this never changes the Θ class). Since log∗n grows slower than loglogn (applying log repeatedly reaches 1 far sooner than one loglog), and loglogn≺logn:
log∗n≺loglogn≺logn.
Q9. ∑i=1ni2 vs ∑i=1n2i vs ∑i=1nlogi vs ∑i=1ni1
∑i2=Θ(n3) (power rule, k=2).
∑2i=2n+1−1=Θ(2n).
∑logi=log(n!)=Θ(nlogn).
∑i1=Hn=Θ(logn).
Order: Θ(logn)≺Θ(nlogn)≺Θ(n3)≺Θ(2n), i.e.
∑i1≺∑logi≺∑i2≺∑2i.
Q10. Mixed bag: n0.5,2logn,nlogn,log(n!),n1.5,22n
2logn=n (since 2log2n=n; with another base it is n1/log2b, still Θ(n) only if base is 2 — careful: 2logn with log=log2 equals n; with log=ln it equals nln2≈n0.693). GATE's default is base 2, so treat 2logn=n.