Evaluating Algorithms

Nathan Sprague

2/6/23

Limit Definition of Big-O

\(f(n) \in O(g(n))\) if

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

where \(c\) is some constant (possibly 0)

Limit Definition of Big-\(\Omega\)

\(f(n) \in O(g(n))\) if

\[\lim_{n \to \infty} \frac{f(n)}{g(n)} = c > 0\]

where \(c\) is some constant (possibly \(\infty\))

Limit Definition of Big-\(\Theta\)

\(f(n) \in \Theta(g(n))\) if

\[\lim_{n \to \infty} \frac{f(n)}{g(n)} = c, \;\;\;0 < c < \infty\]

where \(c\) is some constant.

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;
}