Professional Documents
Culture Documents
Functions
1/8
Functions Used
I Constant Function:
f (n) = c where n ∈ N and c is fixed.
I Logarithmic Function:
f (n) = logb n where n > 0 and b > 1.
3/8
Functions Used
I Linear Function:
f (n) = n, n ∈ N.
– this is the best time we can hope for when n elements are not
in memory yet. Need at least linear time to “read in” the input.
I N-log-N Function:
f (n) = n log n where n > 0
– This function grows a little faster than the linear and much
slower than the quadratic!
– There are O(n log n) sorting algorithms (mergesort, heapsort).
4/8
Functions Used
I Quadratic Function:
f (n) = n2
– Usually models the behavior of two nested for-loops where the
loop-control variables increase to n.
– For example if the number of operations in the inner loop
increases by 1 at each iteration, then we have:
1 + 2 + 3 + ... + (n − 1) + n = n(n + 1)/2 operations
I Cubic Function:
f (n) = n3
– Appears rather infrequently but it does. Classic example:
All-Pairs Shortest Paths.
5/8
Functions Used
I Polynomials:
f (n) = a0 + a1 n + a2 n2 + a3 n3 + · · · + ad nd
where a0 , a1 , a2 . . . ad are constants, with ad 6= 0, termed
coefficients
– A computation that takes at most polynomial time in the
input size is termed efficient.
– d indicates the degree of polynomial.
– All previous functions are bounded by a polynomial.
I Exponential Function:
f (n) = b n where b > 1 is the base and n the exponent
– Hallmark of inefficiency, infeasible computation already for
small n.