One of the most commonly used notations for growth rate is O-notation. Let f and g be two functions of n. (In this discussion, we'll assume we're only dealing with functions whose domain is the nonnegative integers. Also, we'll always assume that f assumes only nonnegative values.) Formally, when we write g(n) = O(f(n)) this means that
|
there exists some positive constant c, and |
|
there exists some value n0, such that |
| for all n ≥ n0, |g(n)| ≤ c f(n). |
Informally this means that f(n) gives an upper bound on g(n), provided that we ignore constant factors (this is what the c does for us), we ignore finitely many values of n (this is what the n0 does for us), and we ignore the sign of the function g (because of the absolute value signs).
As an example of the formal use of this notation, let's show that 3n2 + 7n = O(n2). Note that in view of the formal definition, this means we will need to show that there exist values of c > 0 and n0 such that for all n ≥ n0, 3n2+7n ≤ c n2. Note that we don't have any hope of making this true unless we pick c to be greater than 3, so let's try 4. Then we'll need to show that (for large n) 3n2 + 7n ≤ 4n2, which is equivalent to 7n ≤ n2, which is certainly true if n ≥ 7. So, putting it all together, we have that if we pick c=4 > 0 and n0=7, then for all n ≥ n0, we have
There are certain types of statements we might like to make which are difficult to make with O-notation. For example, we might want to say that a certain type of sorting algorithm must, in the worst case, use an amount of time at least proportional to n log n. Saying that the worst-case time is "at least O(n log n)" is not appropriate, since O-notation only provides an upper bound. Ω-notation provides a solution to this problem. When we write g(n)=Ω(f(n)) this means that
Finally, it is often useful to be able to make both statements of the sort described above at once, i.e., that g is both at least proportional to f and that it is at most proportional to f. When we write g(n) = Θ(f(n)), this means that
As an example of the use of this notation, suppose we wanted to describe the growth rate of ∑i =1 to n( i4 ). It probably isn't obvious how to obtain an exact formula for this, but if we will be satisified with correct Θ-notation the solution is relatively easy. In view of the definition of Θ-notation, we need to find c1, c2, and n0 such that
| ∑i =1 to n( i4 ) | ≥ ∑i =[(n+1)/2] to n( i4 ) |
| ≥ ∑i =[(n+1)/2] to n( [(n+1)/2]4 ) | |
| ≥ [ (n+1)/2 ]5 | |
| ≥ n5/25 = n5/32. |
One final bit of notation is more accurate in that it indicates the appropriate value of the proportionality constant for large n. We write g(n) ~ f(n) if limn to ∞ ( g(n)/f(n) ) = 1. If you review the definition of a limit, you will see that (assuming f(n) > 0 for all n beyond some point) this is equivalent to
Note that O-notation (as well as Ω- and <Θ-notation) has a serious problem. Ordinarily if x=z and y=z we can conclude that x=y. But this clearly doesn't work when we are dealing with O-notation. For example, we have n=O(n) and 2n+9=O(n), but obviously it is not true that n=2n+9. The problem is that the common use of the equality symbol with O-notation is not really correct. A better way to think about it (as in Knuth) is to interpret O(f(n)) as referring to a set of functions, namely, all those g which satisfy the definition. Thus it would be better to write n is a member of O(n) and 2n+9 is a member of O(n). Now you see the above problem goes away: we are just saying that both n and 2n+9 are in the set O(n). Unfortunately, many books and articles (including our text) use the equality notation, so I will follow that convention in class.
The use of these notations varies somewhat from book to book; the definitions we are using are based on Knuth.
Acknowledgement. This discussion is derived from a handout developed by Professor G. Lueker.