What is an algorithm?
- A step by step process that solves a problem
- Gives the correct output for all inputs
- Complete the process in finite time
Real time: Can be measured by having a virtual stopwatch to count how long a program takes to run. Will get different results on different machines.
Scale/Growth Rate: Count the amount of iterations the loops take. Will get same results on different machines.
We can categorize the growth rate into an asymptotic complexity class:
| Name | Function | |
|---|---|---|
| Constant | Slower growth rate | |
| Logarithmic | ||
| Linear | ||
| Poly-logarithmic | ||
| Quadratic | ||
| Cubic | ||
| Exponential | Higher growth rate |
Big O notation
Consider the equation:
In this case, has the meaning of .
Thus, it translates to:
is in the set of all functions whose growth rate is at most .
In order to determine the validity of that statement, prove that:
can be any function, but it is proper to use one of the asymptotic complexity classes.
Examples
Prove or disprove the following statements.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
Big Ω Notation
Recall that represents an upper bound.
represents a lower bound.
In order to prove if :
Examples
Prove or disprove the following statements.
(h)
(i)
(j)
(k)
Big Θ Notation
Recall that represents an upper bound and represents a lower bound.
represents an exact bound. In other words,
Examples
Prove or disprove the following statements.
(l)
(m)
(n)
Comparing Growth Rates
In order to compare the growth rate of two functions, we can also use limits.
This is a more matematical and precise method.
Recall
If the limit of an expression results in an indeterminate form:
Then you may take the derivative of the numerator and denominator and attempt to find the limit again:
Examples
Prove or disprove the following statements.
(o)
(p)
(q)
Logarithms
Consider the equation .
Typically, implies a base of .
Is this still true?
Recall
The base of a log can be changed via the formula:
Therefore, contains all log functions of any base, since we can easily convert from one to another.