Asymptotic Notation
Asymptotic Notation
Asymptotic Notation
Running time of an algorithm, order of growth
Worst case
Running time of an algorith increases with the size of the input in the limit as the size
of the input increases without bound.
Big-theta notation
Example
n >= 1, c2 >= 1/2
n >= 7, c1 <= 1/14
choose c1 = 1/14, c2 = ½, n0 = 7.
O-notation
Asymptotic upper bound
f(n) = O(g(n)) some constant multiple of g(n) is an asymptotic upper bound of f(n),
no claim about how tight an upper bound is.
Example
2 2
The running time is O(n ) means there is a function f(n) that is O(n ) such that for
any value of n, no matter what particular input of size n is chosen, the running time of
that input is bounded from above by the value f(n).
Big-Omega notation
Asymptotic lowerbound
Theorem
When we say that the running time (no modifier) of an algorithm is Ω(g(n)), we
mean that no matter what particular input of size n is chosen for each value of n,
the running time on that input is at least a constant times g(n), for sufficiently
large n
Interpretation
In other words, the right-hand side of an equation provides a coarser level of detail
than the left-hand side.
o-notation
w-notation
Properties
Modular arithmetic
a is equivalent to b, modulo n. in other words, a and b have the same remainder when
divided by n. Or n is a divisor of b – a.
Polynomials
Exponentials
Thus, any exponential function with a base strictly greater than 1 grows faster than
any polynomial function.
when
Logarithms
Changing the base of a logarithm from one constant to another only changes the value
of the logarithm by a constant factor, and so we shall often use the notation “lg n”
when we don’t care about constant factors.
polylogarithmic bound
for any constant a > 0. Thus, any positive polynomial function grows faster than
any polylogarithmic function.
Factorials
n >= 0
n
A weak upper bound on the factorial function is n! ≤ n , since each of the n
terms in the factorial product is at most n. Stirling’s approximation,
Function iteration
Fibonacci numbers
Homework