5.2 Lower bounds and tight bounds
Big- notation describes an upper bound. In other words, big- states a claim about the greatest amount of some resource (usually time) that is required by an algorithm for some class of inputs of size . A similar notation is used to describe the least amount of a resource that an algorithm needs for some class of input. This is denoted by the symbol , pronounced “big-Omega” or just “Omega”.
The definition for big- allows us to greatly overestimate the cost for an algorithm. But sometimes we know a tight bound – that is, a bound that truly reflects the cost of the algorithm or program with a constant factor. In that case, we can express this more accurate state of our knowledge using the tight bound instead of using big-.
However, it is usually much more difficult to reason about the tight bound, for example, the simplifying rules for addition and multiplication do not hold for . Furthermore, we are very rarely interested in the lower bound when we analyse algorithms, so therefore we will almost exclusively use the upper bound big- notation.
In this section we assume that all functions are monotonically increasing, just as we did in the previous section. If we didn’t assume this, the definitions would be slightly more complicated. But, as discussed in the previous section, the runtime of all algorithms never decreases, so it is a safe assumtion.
5.2.1 Lower bounds: the notation
Big- notation describes an upper bound. In other words, big- states a claim about the greatest amount of some resource (usually time) that is required by an algorithm for some class of inputs of size .
A similar notation is used to describe the least amount of a resource that an algorithm needs for some class of input. Like big-, this is a measure of the algorithm’s growth rate. And like big-, it works for any resource (usually time), and for some particular class of inputs of size . The lower bound for an algorithm (or a problem, as we will discuss in Section 5.3) is denoted by the symbol , pronounced “big-Omega” or just “Omega”. The following definition for is symmetric with the definition of big-.
- Lower bound
-
iff there exist positive numbers and such that for all
Example: Quadratic algorithm
Assume for and . Then,
for all . So, for and . Therefore, is in by the definition.
It is also true that the equation of the example above is in . However, as with big- notation, we wish to get the “tightest” (for notation, the largest) bound possible. Thus, we prefer to say that this running time is in .
Recall the sequential search algorithm to find a value within an array of integers. In the worst case this algorithm is in , because in the worst case we must examine at least values.
Alternative definition for
An alternate (non-equivalent) definition for is
- Lower bound (alt.)
-
iff there exists a positive number such that for an infinite number of values for .
This definition says that for an “interesting” number of cases, the algorithm takes at least time. Note that this definition is not symmetric with the definition of big-. For to be a lower bound, this definition does not require that for all greater than some constant. It only requires that this happen often enough, in particular that it happen for an infinite number of values for . Motivation for this alternate definition can be found in the following example.
Assume a particular algorithm has the following behaviour:
From this definition, for all even , for any . So, for an infinite number of values of . Therefore, is in by the definition.
For this equation for , it is true that all inputs of size take at least time. But an infinite number of inputs of size take time, so we would like to say that the algorithm is in . Unfortunately, using our first definition will yield a lower bound of because it is not possible to pick constants and such that for all . The alternative definition does result in a lower bound of for this algorithm, which seems to fit common sense more closely. Fortunately, few real algorithms or computer programs display the pathological behaviour of this example. Our first definition for generally yields the expected result.
As you can see from this discussion, asymptotic bounds notation is not a law of nature. It is merely a powerful modeling tool used to describe the behaviour of algorithms.
5.2.2 Tight bounds: the notation
The definitions for big- and give us ways to describe the upper bound for an algorithm (if we can find an equation for the maximum cost of a particular class of inputs of size ) and the lower bound for an algorithm (if we can find an equation for the minimum cost for a particular class of inputs of size ). When the upper and lower bounds are the same within a constant factor, we indicate this by using (big-Theta) notation. An algorithm is said to be if it is in and it is in . Note that we drop the word “in” for notation, because there is a strict equality for two equations with the same . In other words, if is , then is .
Because the sequential search algorithm is both in and in in the worst case, we say it is in the worst case.
Given an algebraic equation describing the time requirement for an algorithm, the upper and lower bounds always meet. That is because in some sense we have a perfect analysis for the algorithm, embodied by the running-time equation. For many algorithms (or their instantiations as programs), it is easy to come up with the equation that defines their runtime behaviour. The analysis for most commonly used algorithms is well understood and we can almost always give a analysis for them. However, the class of NP-Complete problems all have no definitive analysis, just some unsatisfying big- and analyses. Even some “simple” programs are hard to analyse. Nobody currently knows the true upper or lower bounds for the following code fragment.
while n > 1:
if n is odd:
= 3 * n + 1
n else:
= n / 2 n
But even though is a more accurate description of the behaviour of an algorithm, we have chosen to almost exclusively use the upper bound big- notation. The reason for this because it is more difficult to reason about the tight bound than about big-. For example, the simplifying rules for addition and multiplication do not hold for . Another reason is that most other textbooks, research papers, and programmers will usually say that an algorithm is “order of” or “big-” of some cost function, implicitly meaning that this is the tightest possible bound.
5.2.3 Strict bounds
The upper and lower bounds are not strict, meaning that a function is in its own class, and . We can also define strict versions of upper and lower bounds:
- Strict upper bound (little-)
-
iff and
- Strice lower bound ()
-
iff and
5.2.4 Asymptotic notation and comparing complexity classes
We can summarise the different asymptotic notations (, , , , and ) in the following table:
Name | Bound | Notation | Definition |
---|---|---|---|
Little-O | Strict upper bound | ||
Big-O | Upper bound | ||
Theta | Tight bound | ||
Big-Omega | Lower bound | ||
Little-Omega | Strict lower bound |
All these different bounds correspond to comparison operators between complexity classes:
Comparison | Complexity class |
---|---|
Using these correspondences and the simplifying rules we can infer the following hierarchy of complexity classes:
Zooming in on the very efficient (sub-linear) complexity classes we have:
And if we instead look closer on the extreme other end of the scale:
5.2.5 Classifying functions using limits
There are alternative definitions of the upper, lower and tight bounds. Instead of finding constants and , we can see how the quotient between the two functions behave in the limit.
Given functions and , we can take the limit of the quotient of the two as grows towards infinity:
We have the following possibilities:
Name | Notation | Limit, |
---|---|---|
Little-O | ||
Big-O | ||
Theta | ||
Big-Omega | ||
Little-Omega |
Example: Comparing two functions
Assume and . Is in , , or ? To answer this we can calculate the limit of the quotient when grows:
because grows faster than . Thus, (or equivalently, ).