CMSC351
Asymptotic Theory⌗
Big Notation⌗
Big-O⌗
We say \(f(x) = \mathcal{O}(g(x))\) if \(\exists x_{0}, C > 0\) such that \(\forall x \ge x_{0}, f(x) \le Cg(x)\)
Big-Omega⌗
We say \(f(x) = \Omega(g(x))\) if \(\exists x_{0}, D > 0\) such that \(\forall x \ge x_{0}, f(x) \ge Dg(x)\)
Big-Theta⌗
We say \(f(x) = \Theta(g(x))\) if \(\exists x_{0}, C, D > 0\) such that \(\forall x \ge x_{0}, Bg(x) \le f(x) \le Cg(x)\)
Caveats⌗
- \(f(x) = \mathcal{O}(g(x))\) does not imply \(g(x) = \Omega(f(x))\)
- It may not be intuitive, but there are functions that are not \(\Theta()\) of something, mostly non-polynomials
- \(f(x) = x^{2}sin(x)\) is \(\mathcal{O}(x^{2})\) but not \(\Omega(x^{2})\)
- When doing big notation, we are interested in the most-limiting bounding function, that is basically everything is \(\mathcal{O}(x!)\), but that’s not very helpful
Orders of Magnitude⌗
- \(1\)
- \(\log x\)
- \(x\)
- \(x \log x\)
- \(x^{2}\)
- \(x^{2}\log x\)
Limit Theorem⌗
If \(\lim_{n \rightarrow \infty} f(n)\) and \(\lim_{n \rightarrow \infty} g(n)\) exist:
- If \(\lim_{n \rightarrow \infty}\frac{f(n)}{g(n)} = r\) where \(r\) is some non-zero real number, then \(f(n) = \Theta(g(n))\)
- If \(\lim_{n \rightarrow \infty}\frac{f(n)}{g(n)} = 0\), then \(f(n) = \mathcal{O}(g(n))\)
- If \(\lim_{n \rightarrow \infty}\frac{f(n)}{g(n)} = \infty\), then \(f(n) = \Omega(g(n))\)
Master Theorem⌗
Suppose \(T(n)\) satisfies the recurrence relation \(T(n) = aT(\frac{n}{b}) + f(n)\).
- If \(f(n) = \mathcal{O}(n^{c})\) and \(\log_{b}a > c\), then \(T(n) = \Theta(n^{\log_{b}a})\)
- If \(f(n) = \Theta(n^{c})\) and \(\log_{b}a = c\), then \(T(n) = \Theta(n^{\log_{b}a}\lg n)\)
- If \(f(n) = \Theta(n^{c}\lg^{k}n)\) and \(\log_{b}a = c\), then \(T(n) = \Theta(n^{\log_{b}a}\lg^{k+1} n)\)
- If \(f(n) = \Omega(n^{c})\) and \(\log_{b}a < c\), then \(T(n) = \Theta(f(n))\)
Time Complexities⌗
Best Case | Worst Case | Average Case | Space | Stable? | |
---|---|---|---|---|---|
Bubble Sort | \(\Theta(n^{2})\) | \(\Theta(n^{2})\) | \(\Theta(n^{2})\) | \(\Theta(1)\) | T |
Selection Sort | \(\Theta(n^{2})\) | \(\Theta(n^{2})\) | \(\Theta(n^{2})\) | \(\Theta(1)\) | F |
Insertion Sort | \(\Theta(n)\) | \(\Theta(n^{2})\) | \(\Theta(n^{2})\) | \(\Theta(1)\) | T |
Binary Search | \(\Theta(1)\) | \(\Theta(\lg n)\) | \(\Theta(\lg n)\) | N/A | N/A |
Merge Sort | \(\Theta(n \lg n)\) | \(\Theta(n \lg n)\) | \(\Theta(n \lg n)\) | \(\Theta(n)\) | T |
Heap Sort | \(\Theta(n \lg n)\) | \(\Theta(n \lg n)\) | \(\Theta(n \lg n)\) | \(\Theta(1)\) | F |
Quick Sort | \(\Theta(n \lg n)\) | \(\Theta(n^{2})\) | \(\Theta(n \lg n)\) | \(\Theta(1)\) | F |
Counting Sort | \(\Theta(n + k)\) | \(\Theta(n + k)\) | \(\Theta(n + k)\) | \(\Theta(n + k)\) | T |
Radix Sort | \(\Theta(df)\) | \(\Theta(n + k)\) | \(\Theta(n + k)\) | \(f\) | T |
Shortest Path | \(\Theta(V)\) | \(\Theta(V+E)\) | N/A | \(\Theta(V)\) | N/A |
Dijkstra’s | \(\Theta(V)\) | \(\Theta(V^{2}+E)\) | N/A | \(\Theta(V)\) | N/A |
BFT | \(\mathcal{O}(V+E)\) | \(\mathcal{O}(V+E)\) | N/A | \(\Theta(V)\) | N/A |