A supercomputer running at 1015 ops/sec would handle n=106 with Insertion Sort (n2) in about 1 second, and MergeSort (nlogn) instantly. The algorithm matters far more than the hardware.
Using Limits to Compare Growth
To determine the asymptotic relationship between f(n) and g(n), compute:
limn→∞g(n)f(n)
Limit
Conclusion
0
f(n)=o(g(n)), so f(n)=O(g(n)) but not Θ(g(n))
c∈(0,∞)
f(n)=Θ(g(n))
∞
f(n)=ω(g(n)), so f(n)=Ω(g(n)) but not Θ(g(n))
Example: Compare nlogn and n2
limn→∞n2nlogn=limn→∞nlogn=0(by L’Hoˆpital)
So nlogn=o(n2); the n2 function dominates.
Example: Compare 3n2+2n+1 and n2
limn→∞n23n2+2n+1=3
The limit is finite and non-zero, so 3n2+2n+1=Θ(n2).
L’Hôpital’s Rule
If limf(n)=limg(n)=∞, then:
limg(n)f(n)=limg′(n)f′(n)
This is essential for ratios like nlogn or lognn where the asymptotic behaviour is not obvious from inspection.
Practice: Rank by Growth Rate
Rank these functions from slowest to fastest growth:
2log3n,n2,n,log(n!),2n,nlog3,nlogn,(logn)logn
Solution: 2log3n=nlog32≈n0.63; log(n!)=Θ(nlogn); nlog3≈n1.59. The rank: n<2log3n<nlogn≈log(n!)<nlog3<n2<(logn)logn<2n.