4.3: The Big “Oh” and Little “Oh” Notations
Let \(f:\mathbb{N} \rightarrow \mathbb{R}\) and \(g:\mathbb{N} \rightarrow \mathbb{R}\) be functions. We write \(f=\mathcal{O}(g)\), and say \(f\) is “ Big Oh ” of \(g\), when there is a constant \(c\) and an integer \(n_0\) so that \(f(n)≤cg(n)\) whenever \(n>n_0\). Although this notation has a long history, we can provide a quite modern justification. If \(f\) and \(g\) both describe the number of operations required for two algorithms given input size \(n\), then the meaning of \(f=\mathcal{O}(g)\) is that \(f\) is no harder than \(g\) when the problem size is large.
We are particularly interested in comparing functions against certain natural benchmarks, e.g., \(\log \log n, \log n, \sqrt{n}, n^{\alpha}\) where \(\alpha<1, n, n^2, n^3, n^c\) where \(c>1\) is a constant, \(n^{\logn}\), \(2n, n!, 2^{n^2}\), etc.
For example, in Subsection 3.5.2 we learned that there are sorting algorithms with running time \(\mathcal{O}(n \log n)\) where \(n\) is the number of integers to be sorted. As a second example, we will learn that we can find all shortest paths in an oriented graph on \(n\) vertices with non-negative weights on edges with an algorithm having running time \(\mathcal{O}(n^2)\). At the other extreme, no one knows whether there is a constant \(c\) and an algorithm for determining whether the chromatic number of a graph is at most three which has running time \(\mathcal{O}(n^c)\).
It is important to remember that when we write \(f=\mathcal{O}(g)\), we are implying in some sense that \(f\) is no bigger than \(g\), but it may in fact be much smaller. By contrast, there will be times when we really know that one function dominates another. And we have a second kind of notation to capture this relationship.
Let \(f: \mathbb{N} \rightarrow \mathbb{R}\) and \(g: \mathbb{N} \rightarrow \mathbb{R}\) be functions with \(f(n) > 0\) and \(g(n) > 0\) for all \(n\). We write \(f = \mathcal{o}(g)\), and say that \(f\) is “ Little oh ” of \(g\), when \(\lim_{n \to \infty} f(n)/g(n) = 0\). For example, \(\ln n = \mathcal{o}(n^{.2})\); \(n^{\alpha} = \mathcal{o}(n^{\beta})\) whenever \(0 < \alpha < \beta\); and \(n^{100} = \mathcal{o}(c^n)\) for every \(c > 1\). In particular, we write \(f(n) = \mathcal{o}(1)\) when \(\lim_{n \to \infty} f(n) = 0\).