Sub topic 3
Comparing Growth Rates
Prerequisites and the Main Idea
Assume you know logarithms, exponents, basic algebra, and the meanings of \(O\), \(\Omega\), and \(\Theta\). This chapter compares how functions grow as the input size \(n\) becomes very large.
For algorithm analysis, constant factors and lower-order terms usually matter less than the dominant growth term. For example,
\[ 3n^2 + 10n + 7 = \Theta(n^2). \]
The \(n^2\) term eventually grows faster than \(n\) and the constant term. Therefore, it determines the asymptotic growth.
Common Growth Order
From slowest growth to fastest growth, a useful ordering is:
\[ 1 < \log n < \sqrt n < n < n\log n < n^2 < n^3 < 2^n < n!. \]
If \(f(n)\) grows more slowly than \(g(n)\), then
\[ f(n) = o(g(n)). \]
This means that
\[ \lim_{n\to\infty}\frac{f(n)}{g(n)}=0. \]
For example, \(\log n=o(n)\), because \(\log n/n\) approaches zero.
How to Compare Two Functions
The limit of their ratio gives a precise comparison.
| Limit of \(f(n)/g(n)\) | Meaning |
|---|---|
| \(0\) | \(f\) grows more slowly than \(g\) |
| positive finite constant | \(f\) and \(g\) have the same order |
| infinity | \(f\) grows faster than \(g\) |
For instance,
\[ \lim{n\to\infty}\frac{n\log n}{n^2} = \lim{n\to\infty}\frac{\log n}{n} =0. \]
Thus \(n\log n=o(n^2)\), and consequently \(n\log n=O(n^2)\).
A common mistake is to compare values only for small inputs. For example, \(2^n\) can be smaller than \(n^3\) for some small \(n\), but \(2^n\) eventually grows faster.
Useful Simplification Rules
- \(\loga n=\Theta(\logb n)\) for any fixed bases \(a,b>1\).
- \(n^c=o(n^d)\) when \(0<c<d\).
- Every polynomial \(n^c\) grows more slowly than \(a^n\) for fixed \(a>1\).
- \(a^n\) grows more slowly than \(n!\).
- Multiplying by a constant does not change the asymptotic class.
Exercise
Arrange \(n^2\), \(\log n\), \(n\log n\), \(2^n\), and \(\sqrt n\) from slowest to fastest growth.
Show answer
\(\log n < \sqrt n < n\log n < n^2 < 2^n\).