Some Properties of $O,\Theta,\Omega$
- Let f and g be two functions such that $\lim\limits_{n \to \infty} \frac{f(n)}{g(n)} = c$ for some constant $c > 0$, then $f(n) \in \Theta(g(n))$
- if $f \in O(g)$ and $g \in O(h) $ then $f \in O(h)$
- Proof
$$\begin{eqnarray}
f \in O(g) => \exists c_1 >0, n_0 > 0 \ni f(n) \le c_1g(n) \forall n > n_0 \\
g \in O(h) => \exists c_2 >0, n_0' > 0 \ni g(n) \le c_2h(n) \forall n > n_0' \\
\textrm{let} ~~ n_0'' = max(n_0, n_0') \\
\textrm{it follows that } g(n) \le c_2h(n) ~\forall n > n_0'' \\
c_1 g(n) \le c_2c_1 h(n) \forall n > n_0'' \textrm{ since } c_1 > 0 \\
\textrm{so} f(n) \le c_2c_1 h(n) \forall n > n_0'' \\
\textrm{and thus} f \in O(h)
\end{eqnarray}$$
- if $f \in \Omega(g)$ and $g \in \Omega(h) $ then $f \in \Omega(h)$
- if $f \in \Theta(g)$ and $g \in \Theta(h) $ then $f \in \Theta(h)$
- This follows directly from the previous two proofs.
- If $f \in O(h) $ and $ g \in O(h) $ then $ f + g \in O(h) $
- Proof
$$\begin{align*}
f \in O(h) => \exists c_1 >0, n_0 > 0 \ni f(n) \le c_1h(n) \forall n > n_0 \\
g \in O(h) => \exists c_2 >0, n_0' > 0 \ni g(n) \le c_2h(n) \forall n > n_0' \\
\textrm{let} ~~ n_0'' = max(n_0, n_0') \\
f(n) + g(n) \le c_1h(n) + c_2h(n) \forall n > n_0''\\
f(n) + g(n) \le (c_1 + c_2)h(n) \forall n > n_0''\\
\textrm{let} c_3 = c_1 + c_2 \\
f(n) + g(n) \le c_3h(n) \forall n > n_0''\\
\textrm{thus} f + g \in O(h).
\end{align*}$$
- By the way, what this says is that if you have two loops of O(g(n)) sequentually in your code, the combination is O(g(n)).
- If k is a constant, let $f_1, f_2, ... f_k$ and $h$ be functions such that $f_i \in O(h)$, then $f_1 + f_2 + ... + f_k \in O(h)$
- This follows directly from the previous as well.
- So we can have as many of the same order functions sequentially and it doesn't change the analysis.