by William Shoaff with lots of help
You can download a postscript version of this file (which is prettier) at
We need to formalize the ideas that an algorithms has running time or storage requirements that are ``never more than,'' ``always greater than,'' or ``exactly'' some amount. Recall that we use T(n) for the running time or time complexity and S(n) for the storage requirements or space complexity of an algorithm on an instance of size n. And recall that the time and space may vary for different instances of the same size, e.g., it may take less time to sort an already sorted list.
The phrase ``never more than'' expresses an upper bound on T(n)or S(n). There are several ways you could choose to express this:
The phrase ``always greater than'' expresses a lower bound on T(n)or S(n). There are several ways you could choose to express this:
There are certain technical features which much be placed on this function referred to above. We won't try to state all of them. Let's give the function a name, call it f (n).
A proper complexity functions (or running time function) has the following properties:
You are familiar with the common functions that will be useful complexity functions.
| growth rate | n = 1 | n = 10 | n = 100 | n = 1000 |
| lg n | 0 | 3.32 | 6.64 | 9.96 |
| n | 1 | 10 | 100 | 1000 |
| nlg n | 0 | 33.2 | 664 | 9966 |
| n2 | 1 | 100 | 10000 | 106 |
| n3 | 1 | 1000 | 106 | 109 |
| 2n | 2 | 1024 | 1030 | 10300 |
| nn | 1 | 1010 | 10200 | 103000 |
O-notation is used to denote upper bounds. We write
``T(n) is in the order of f (n)'', or ``T(n) is big-O of f (n)''We need to make this informal notion more precise.
``T grows slower than a constant time f for all sufficiently large n'', or
``The graph of T lies below the graph of a constant time f for all sufficiently large n.''
The notation O(f (n)) actually denotes a set; the set of all functions with growth rate less than or equal to f (n).
-notation is used to denote lower bounds. We write
``T(n) isWe need to make this informal notion more precise.of f (n)''
``T grows faster than a constant time f for all sufficiently large n'', or
``The graph of T lies above the graph of a constant time f for all sufficiently large n.''
The notation
(f (n)) actually denotes a set; the set of all functions with
growth rate less than or equal to f (n).
-notation is used to denote both upper and lower bounds. We write
``T(n) isWe need to make this informal notion more precise.of f (n)''
``T grows at the same rate as some constant time f for all sufficiently large n'', or
``The graph of T lies between the graphs of df and cf for all sufficiently large n.''
The notation
(f (n)) actually denotes a set; the set of all functions with
growth rate less than or equal to f (n).
The O,
, and
notations are called asymptotic
notations since they apply for large values of n.
Below the bound N, the inequalities stated in the definitions need not hold.
Limits play an important role in working with asymptotic relations.
We need to find a constant c > 0 and an natural number N > 0 such that 5ncn for all n
N. Clearly this is not hard, one choice is c = 5 and N = 1.
We need to find a constant c > 0 and a natural number N > 0 such that 6n2 + 3n - 2cn2 for all n
N. There are several ways to approach this problem.
- 1.
- Solution 1. For for 3
n, we know 3n
n2 and -2
n2. Therefore
6n2 + 3n - 2for all n6n2 + n2 + n2 = 8n2
3. So we can pick c = 8 and N = 3.
- 2.
- Solution 2. The inequality 6n2 + 3n - 2
cn2 is equivalent to (c - 6)n2 - 3n + 2
0. Picking c = 7 allows us to simply factor the quadratic as (n - 2)(n - 1) which will be greater than 0 provided n
2.
We need to find a constant c > 0 and a natural number N > 0 such that lnnc
for all n
N. This looks a little more intimidating, so we appeal to some theorems.
l'Hôpital's rule looks promising. Recall,
Thereforeln n =
and
=
Therefore, appealing to Theorem 2,=
=
= 0.
lnn = O() but
![]()
O(ln n).
We need to find constants c, d > 0 and a natural number N > 0 such that dlogbnlogan
clogbn for all n
N.
The simple trick is to know the conversion formula
logan =which is obvious once you rename things, say,
x = logan and y = logbn.Then, by the definition of logarithmsax = n = byor, taking logarithms (base b) of the left and right side of the equationlogb(ax) = xlogb(a) = ybor, going back to original namesloganlogba = logbn,from which the conversion formula is immediate What this says is, we can pick d = c =and N = 1.
| lg(lg(n)) | 2lg(n) | ( |
n2 | n! |
| (3/2)n | n3 | lg2n | nlg n | log(log(n)) |
| n*2n | lg n | 1 | ln n | 2lg n |
| en | 5n3 + 4n2 | lg(2n) | 2ln n | |
| 4lg n | (n + 1)! | n2 + n + 3 | n | 2n |
Is an =Justify your answer.(bn) for all a, b
1?