Processing math: 100%
Close
Close Window

OpenDSA Modules Collection with Slides

Chapter 8 Algorithm Analysis

Show Source |    | About   «  8.6. Asymptotic Analysis and Upper Bounds   ::   Contents   ::   8.8. Calculating Program Running Time  »

8.7. Lower Bounds and Θ Notation

8.7.1. Lower Bounds and Theta Notation

8.7.1.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 n (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 n.

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 T(n) a non-negatively valued function, T(n) is in set Ω(g(n)) if there exist two positive constants c and n0 such that T(n)cg(n) for all n>n0. [1]

Example 8.7.1

Assume T(n)=c1n2+c2n for c1 and c2>0. Then,

c1n2+c2nc1n2

for all n>1. So, T(n)cn2 for c=c1 and n0=1. Therefore, T(n) is in Ω(n2) by the definition.

It is also true that the equation of the example above is in Ω(n). 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 Ω(n2).

Recall the sequential search algorithm to find a value K within an array of integers. In the average and worst cases this algorithm is in Ω(n), because in both the average and worst cases we must examine at least cn values (where c is 1/2 in the average case and 1 in the worst case).

[1]

An alternate (non-equivalent) definition for Ω is

T(n) is in the set Ω(g(n)) if there exists a positive constant c such that T(n)cg(n) for an infinite number of values for n.

This definition says that for an "interesting" number of cases, the algorithm takes at least cg(n) time. Note that this definition is not symmetric with the definition of big-Oh. For g(n) to be a lower bound, this definition does not require that T(n)cg(n) for all values of n greater than some constant. It only requires that this happen often enough, in particular that it happen for an infinite number of values for n. Motivation for this alternate definition can be found in the following example.

Assume a particular algorithm has the following behavior:

T(n)={nfor all odd n1n2/100for all even n0

From this definition, n2/1001100n2 for all even n0. So, T(n)cn2 for an infinite number of values of n (i.e., for all even n) for c=1/100. Therefore, T(n) is in Ω(n2) by the definition.

For this equation for T(n), it is true that all inputs of size n take at least cn time. But an infinite number of inputs of size n take cn2 time, so we would like to say that the algorithm is in Ω(n2). Unfortunately, using our first definition will yield a lower bound of Ω(n) because it is not possible to pick constants c and n0 such that T(n)cn2 for all n>n0. The alternative definition does result in a lower bound of Ω(n2) 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.

8.7.1.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 n) 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 n). 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 Θ(h(n)) if it is in O(h(n)) and it is in Ω(h(n)). 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 f(n) is Θ(g(n)), then g(n) is Θ(f(n)).

Because the sequential search algorithm is both in O(n) and in Ω(n) in the average case, we say it is Θ(n) 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))
    n = 3 * n + 1;
   else
     n = n / 2;

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.

8.7.1.3. Classifying Functions

Given functions f(n) and g(n) 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 n grows towards infinity,

limnf(n)g(n).

If the limit goes to , then f(n) is in Ω(g(n)) because f(n) grows faster. If the limit goes to zero, then f(n) is in O(g(n)) because g(n) grows faster. If the limit goes to some constant other than zero, then f(n)=Θ(g(n)) because both grow at the same rate.

Example 8.7.2

If f(n)=n2 and g(n)=2nlogn, is f(n) in O(g(n)), Ω(g(n)), or Θ(g(n))? Since

n22nlogn=n2logn,

we easily see that

limnn22nlogn=

because n grows faster than 2logn. Thus, n2 is in Ω(2nlogn).

1 / 10 Settings
<<<>>>

A mistake that people can make is to confuse the lower bound and the best case. In general, people find lower bounds confusing, in part because for simple algorithms, they look just like the upper bound. Let's try to figure this out.

Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

8.7.1.4. Summary Exercise

   «  8.6. Asymptotic Analysis and Upper Bounds   ::   Contents   ::   8.8. Calculating Program Running Time  »

nsf
Close Window