big-O and little-o
The definitions of big-O and little-o are quite similar, but little-o has an alternative definition in terms of taking a limit. In this post we explore building up a similar definition for big-O. We will be thinking of big-O and little-o from the perspective of asymptotic anaysis in computer science, so we don’t lose anything by assuming all or our functions are positve. Let’s start with the standard definitions of big-O and little-o. We say that, is or (by a slight abuse of notation) that , if there exist positive constants and , such that for all , \[f(n) \leq cg(n)\] Contrast this with the definition of little-o,
if for all , there exist , such that for all , \[f(n) \leq cg(n)\]
The difference is that this inequality must hold for all , so we can pick to be arbitrarily small (Note that in the definition of little-o, may depend on the choice of ). An equivalent definition of little-o is,
if
It is easy to see using the definition of limit that these two definitions of little-o are equivalent. This second definition is the one most often used for checking if is , since we can apply the tools of calculus, including e.g. l’hospital’s rule, to calculate the limit instead of trying to find an for each , which is usually more difficult. Do we have a similar definition for big-O? It may seem at first that the following is an equivalent to the one above, i.e. that a necessary and sufficient condition for to be is,
Unfortunately, this is not a valid definition of big-O. The problem is that the limit is not guaranteed to exist. This was not a problem in our definition of little-o, since if the limit is equal it must exit.
Here is an example of the trouble we could run into. Take to be the function on the positive integers such that:
and let . Then the limit as of does not exist. The function oscillates between and forever. On the other hand is clearly , since
This demonstrates that if the definition of big-O is satisfied it may not be the case that the above limit exists. What about the other direction, i.e. if the limit exists, does this imply big-O, after all, we are usually trying to prove that some function is big-O of some other function. Let’s see, if the limit exists it is finite by definition, and hence equal to some constant so we have,
This means that there must be a and an such that, for all
Voila, that’s the definition of big-O, so in fact if the limit exits then big-O is implied. That’s good, it means that if we can calculate the limit, then we can prove big-O and if the limit turns out to be zero then we have little-o as well. Still it would be nice to have a definition that worked even when the limit doesn’t exist like in our oscillating function from before.
to the rescue
We need something more general than , something that always exists. That’s where the comes in. Unlike , which must always be finite, we allow to be . OK, so just what is the otherwise known as the limit superior. Here is the formal definition,
Let’s take this piece by piece. First, what does mean in . Easy, means least upper bound. is similar to , so is like the maximum value of on the set of all integers . The reason we can’t use is that it does not always exist, whereas the least upper bound () will always exist even if it is infinite.
For example suppose is the function , has a horizontal asymptote at . This function does not have a , if you give me any number, say I’ll give you an integer making bigger, . On the other hand is always less than and there is no smaller number for which this is true, so is the . Nice, using guarantees we don’t get into trouble with cases where the maximum is not attained.
Now that we understand what the supremum is, let’s replace the limit with it’s definition and see what it means for the to be finite. If something is finite it must be equal some constant . That is,
is equivalent to the statement that there exists a positive constant such that for all ,
observe that is the same as saying that all values of on the set of integers are less than – since if the is less than all values are. Finally, we arrive at the statement, there exist positive constants and such that for all ,
I like to think of the as saying that eventually. All we have to do now is replace with to arrive at
and we have the definition of big-O, proving that a finite implies big-O. The proof in the other direction, i.e. that big-O implies that the is finite is pretty much the same proof in reverse. Hence we have shown that the two definitions are equivalent! That is, an alternative definition of is
The only difference between this result and our naive guess is that we had to use instead of to handle cases where the limit does not exist. By the way, when the limit exists it is equal to the . So we can summarize what we have so far by saying that if the of is 0 then is , if it is finite but not zero is .