Evaluating Algorithms

Nathan Sprague

1/31/24

Limit Definition of Big-O,Big-\(\Omega\), Big-\(\Theta\)

\[ \begin{align} \text{if} \;\;\; \lim_{n \to \infty} \frac{f(n)}{g(n)} \begin{cases} \in [0, \infty) , \;\;\; &f(n) \in O(g(n))\\ \in (0, \infty) , \;\;\; &f(n) \in \Theta(g(n))\\ \in (0, \infty] , \;\;\; &f(n) \in \Omega(g(n))\\ \end{cases} \end{align} \]

(Notice that multiple cases may be true.)

L’Hôpital’s Rule

If \(\displaystyle \lim_{n \to \infty} f(n) = \lim_{n \to \infty} g(n) = \infty\) and \(f'(n)\) and \(g'(n)\) exist, then

\[\lim_{n \to \infty} \frac{f(n)}{g(n)} = \lim_{n \to \infty} \frac{f'(n)}{g'(n)}\]

Applying Limit Definitions

The limit definitions often provide the easiest way to formally demonstrate the asymptotic relationship between two functions…

Using algebra and basic limit rules:

Applying Limit Definitions

The limit definitions often provide the easiest way to formally demonstrate the asymptotic relationship between two functions…

Using L’Hôpital’s rule

Average Case Analysis

public static boolean contains(int target, int[] numbers) {
  for (int number : numbers) {
    if (number == target) {
      return true;
    }
  }
  return false;
}