3.6 Lower Bounds and Notation
3.6.1 Lower Bounds
Big-Oh notation describes an upper bound. In other words, big-Oh notation 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 (typically the worst such input, the average of all possible inputs, or the best such input).
Similar notation is used to describe the least amount of a resource that an algorithm needs for some class of input. Like big-Oh notation, this is a measure of the algorithm’s growth rate. Like big-Oh notation, it works for any resource, but we most often measure the least amount of time required. And again, like big-Oh notation, we are measuring the resource required for some particular class of inputs: the worst-, average-, or best-case input of size .
The lower bound for an algorithm (or a problem, as explained later) is denoted by the symbol , pronounced “big-Omega” or just “Omega”. The following definition for is symmetric with the definition of big-Oh.
For a non-negatively valued function, is in set if there exist two positive constants 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-Oh 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 average and worst cases this algorithm is in , because in both the average and worst cases we must examine at least values (where is 1/2 in the average case and 1 in the worst case).
3.6.1.1 Alternative definition for
An alternate (non-equivalent) definition for is
is in the set if there exists a positive constant 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-Oh. For to be a lower bound, this definition does not require that for all values of 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 behavior:
From this definition, for all even . So, for an infinite number of values of (i.e., for all even ) for . 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 behavior 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 behavior of algorithms.
3.6.2 Theta Notation
The definitions for big-Oh 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 average case, we say it is in the average 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 behavior. 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-Oh and analyses. Even some “simple” programs are hard to analyze. Nobody currently knows the true upper or lower bounds for the following code fragment.
while n > 1:
if ODD(n):
= 3 * n + 1
n else:
= n / 2 n
While some textbooks and programmers will casually say that an algorithm is “order of” or “big-Oh” of some cost function, it is generally better to use notation rather than big-Oh notation whenever we have sufficient knowledge about an algorithm to be sure that the upper and lower bounds indeed match. OpenDSA modules use notation in preference to big-Oh notation whenever our state of knowledge makes that possible. Limitations on our ability to analyze certain algorithms may require use of big-Oh or notations. In rare occasions when the discussion is explicitly about the upper or lower bound of a problem or algorithm, the corresponding notation will be used in preference to notation.
3.6.3 Classifying Functions
Given functions and whose growth rates are expressed as algebraic equations, we might like to determine if one grows faster than the other. The best way to do this is to take the limit of the two functions as grows towards infinity,
If the limit goes to , then is in because grows faster. If the limit goes to zero, then is in because grows faster. If the limit goes to some constant other than zero, then because both grow at the same rate.
Example: Comparing two functions
If and , is in , , or ? Since
we easily see that
because grows faster than . Thus, is in .
3.6.4 Practice questions: Lower bounds
Answer TRUE or FALSE.
Big-Theta notation () defines an equivalence relation on the set of functions.
- An equivalence relation is a relation that is reflexive, symmetric, and transitive.
- Big-Theta notation is like .
- is an equivalence relation.
Answer TRUE or FALSE.
The Sequential Search algorithm is .
- Recall that means that all program inputs (beyond a certain, small size) run within a constant factor of .
- Theta means that the program is not growing too much slower, nor too much faster, than the claimed growth rate.
- Sequential search grows much slower than .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- is
- is in
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Determine the proper relationship between the following pair of functions.
- if , then is in .
- if constant, then is .
- if , then is in .
Which of these is the best lower bound for a growth rate of ?
- The simplifying rules tell us that we can drop constants and lower order terms from a polynomial that defines the growth rate.
For what value of is ? (Answer in decimals, not fractions)
If we know that algorithm X is in the average case, then what can we say about its TIGHTEST upper bound?
- What is the definition of ?
- Being means that we know a tight bound (both the upper and the lower bounds match).
- If X is , then it is both and .