Daniel Sutantyo, Department of Computing, Macquarie University
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation
no of operations
size of input
Algorithm A is
1.3 - Complexity Notation
\[\left(\frac{c_5}{2}+\frac{c_6}{2}+\frac{c_7}{2}\right)n^2 + \left(c_1+c_2+c_4+\frac{c_5}{2}-\frac{c_6}{2}-\frac{c_7}{2}+c_8\right)n - (c_2+c_4+c_5+c_8)\]
Algorithm B is
\[\left(c_4+c_6\right)n^2 + (c_1+c_2+c_5)n + (c_3+c_8) \]
which one is better?
1.3 - Complexity Notation
\[T(n) = c_1 n^2 + c_2 n - c_3\]
1.3 - Complexity Notation
\(n\) \(n^2\) \(n^{20}\) \(2^n\) \(2^{n+3}\)
\(100\)
\(200\)
\(1 \times 10^4\)
\(1 \times 10^{40}\)
\(1.26 \times 10^{30}\)
\(4 \times 10^4\)
\(1.05 \times 10^{46}\)
\(1.61 \times 10^{60}\)
\(300\)
\(9 \times 10^4\)
\(3.49 \times 10^{49}\)
\(2.04 \times 10^{90}\)
\(400\)
\(1.6 \times 10^5\)
\(1.10 \times 10^{52}\)
\(2.58 \times 10^{120}\)
\(1.01 \times 10^{31}\)
\(1.28 \times 10^{61}\)
\(1.63 \times 10^{91}\)
\(2.07 \times 10^{121}\)
1.3 - Complexity Notation
1.3 - Complexity Notation
COMP1010/125
COMP2010/225
COMP3010
\[O(n)\]
\[O(n^2)\]
\[O(\log n)\]
\[O(n\log n)\]
\[O(|V||E|)\]
\[O(1)\]
\[O(|E|\log|V|)\]
\[O(2^n)\]
\[O(n!)\]
\[O(n\sqrt{n})\]
\[O(2^{\log{n}})\]
\[O(n^2\log{n})\]
\[O(\log\log{n})\]
1.3 - Complexity Notation
\(T(n) = O(n^2)\)
\(f(n)\)
\(g(n)\)
1.3 - Complexity Notation
\(f(n) = O(g(n))\) means there exists a positive constant \(c\) such that for all \(n > n_0\), \(f(n) \le c\cdot g(n) \)
Skiena Figure 2.3, page 36
1.3 - Complexity Notation
\(T(n)\)
\(g(n)\)
\(\le\)
\( 3n^2 + 100n + 25\)
\( n^2\)
\(f(n) = O(g(n))\) means there exists a positive constant \(c\) such that for all \(n > n_0\), \(f(n) \le c\cdot g(n) \)
\( 6\)
\(n=1\)
\(128\)
\(6\)
\(n=10\)
\(1325\)
\(600\)
\(n=100\)
\(40025\)
\(60000\)
1.3 - Complexity Notation
\(3n^2 + 100n + 25 \le 100n^2 + 100n^2 + 100n^2 = 300n^2\)
for all \(n \ge 1\)
i.e. use \(c = 300\) and \(n_0 = 1\)
1.3 - Complexity Notation
1.3 - Complexity Notation
these are all correct, but are they useful?
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation
Skiena Figure 2.3, page 36
\(c\cdot g(n)\)
\( f(n)\)
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation
Skiena Figure 2.3, page 36
\(f(n)\)
\(c_2\cdot g(n)\)
\(c_1\cdot g(n)\)
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation
Skiena, Figure 2.2, page 35
1.3 - Complexity Notation
1.3 - Complexity Notation
1.3 - Complexity Notation