Running Time
Announcements
Where we’re going
How long does it take?
How long does it take?
What does it depend on?
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 32 | 11 | 73 | 21 | 29 | 86 | 81 | 92 | 57 | 61 | 64 | 15 | 79 | 44 | 7 | 45 |
How many times does line 3 run if \(q\) is 32? If \(q\) is 45? If \(q\) is 100?
For an array of size \(n\):
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 11 | 73 | 21 | 29 | 86 | 81 | 92 | 57 | 61 | 64 | 15 | 79 | 44 | 7 | 45 |
Best case
Worst case
How many lines are executed in the worst case?
\(T(n) =\)
Does the ___ matter?
Does the ___ matter?
\(T(n) = O(f(n))\) if there are positive constants \(c\) and \(n_0\) such that
\[T(n) \le c \cdot f(n) \quad \text{for all } n \ge n_0\]
We typically use \(f(n)\) to describe …
| growth | name | |
|---|---|---|
| \(O(1)\) | constant | |
| \(O(\log n)\) | logarithmic | |
| \(O(\log^k n)\) | poly-log | |
| \(O(n)\) | linear | |
| \(O(n \log n)\) | log-linear | |
| \(O(n^{1+c})\) | superlinear | \(c > 0\) |
| \(O(n^2)\) | quadratic | |
| \(O(n^3)\) | cubic | |
| \(O(n^k)\) | polynomial | “tractable” |
| \(O(c^n)\) | exponential | “intractable” |
In the worst case, \(T(n) =\)
Which should we use to describe it? \(o \quad O \quad \omega \quad \Omega \quad \theta \quad \Theta\)
CPSC 221