3.9 Common Misunderstandings

Asymptotic analysis is one of the most intellectually difficult topics that undergraduate computer science majors are confronted with. Most people find growth rates and asymptotic analysis confusing and so develop misconceptions about either the concepts or the terminology. It helps to know what the standard points of confusion are, in hopes of avoiding them.

One problem with differentiating the concepts of upper and lower bounds is that, for most algorithms that you will encounter, it is easy to recognize the true growth rate for that algorithm. Given complete knowledge about a cost function, the upper and lower bound for that cost function are always the same. Thus, the distinction between an upper and a lower bound is only worthwhile when you have incomplete knowledge about the thing being measured. If this distinction is still not clear, then you should read about analyzing problems. We use Θ\Theta-notation to indicate that there is no meaningful difference between what we know about the growth rates of the upper and lower bound (which is usually the case for simple algorithms).

It is a common mistake to confuse the concepts of upper bound or lower bound on the one hand, and worst case or best case on the other. The best, worst, or average cases each define a cost for a specific input instance (or specific set of instances for the average case). In contrast, upper and lower bounds describe our understanding of the growth rate for that cost measure. So to define the growth rate for an algorithm or problem, we need to determine what we are measuring (the best, worst, or average case) and also our description for what we know about the growth rate of that cost measure (big-Oh, Ω\Omega, or Θ\Theta).

The upper bound for an algorithm is not the same as the worst case for that algorithm for a given input of size nn. What is being bounded is not the actual cost (which you can determine for a given value of nn), but rather the growth rate for the cost. There cannot be a growth rate for a single point, such as a particular value of nn. The growth rate applies to the change in cost as a change in input size occurs. Likewise, the lower bound is not the same as the best case for a given size nn.

Another common misconception is thinking that the best case for an algorithm occurs when the input size is as small as possible, or that the worst case occurs when the input size is as large as possible. What is correct is that best- and worse-case instances exist for each possible size of input. That is, for all inputs of a given size, say ii, one (or more) of the inputs of size ii is the best and one (or more) of the inputs of size ii is the worst. Often (but not always!), we can characterize the best input case for an arbitrary size, and we can characterize the worst input case for an arbitrary size. Ideally, we can determine the growth rate for the characterized best, worst, and average cases as the input size grows.

3.9.1 Practice questions: Common misunderstandings

Answer TRUE or FALSE.

For all algorithms, if we completely understand the running time analysis, then the upper bound and lower bound will be the same.

  • Upper and lower bounds are only different when we do not completely understand the cost for the algorithm.

Answer TRUE or FALSE.

The upper bound and lower bounds of the sequential search algorithm is in O(n)O(n) and Ω(n)\Omega(n) respectively.

  • Is this statement complete?
  • To make this statement correct, you need to add in which case you are measuring the lower and upper bounds.
  • This would be true for the worst case, but not the best case.

Answer TRUE or FALSE.

The worst case for sequential search occurs when the last element of the array is the value being searched for.

  • Worst case cost refers to the most expensive problem instance AS THE INPUT GETS BIG.
  • Since, for any given array (regardless of size), the most expensive problem instance occurs when the search value is in the last position of the array, this is indeed the worst case.

Answer TRUE or FALSE.

The lower bound for the cost of sequential search is Ω(1)\Omega(1) since this is the running time of the algorithm in the best case.

  • Upper/lower bounds define the growth rate in a particular situation (such as worst or best case).
  • So the statement is badly worded.
  • Proper wording: The lower bound for the cost of sequential search in the best case is Ω(1)\Omega(1).

Answer TRUE or FALSE.

The best case for the sequential search algorithm occurs when the array has only a single element.

  • Best case cost refers to a best problem instance AS THE INPUT GETS BIG.
  • So it makes no sense to talk about a growth rate or a best case of a fixed input size.
  • The best case for sequential search occurs when the first element of the array (for whatever size) is the value being searched for.

Answer TRUE or FALSE.

The worst case for the sequencial search algorithm occurs when the array size tends to infinity.

  • Worst case cost refers to the most expensive problem instance AS THE INPUT GETS BIG.
  • That is, worst case does not refer to what the input size it.
  • It refers to which input of a particular size is the worst one.
  • The worst case for sequential search occurs when the last element of the array (for whatever size) is the value being searched for.