Chapter 22 Developing Efficient Algorithms
Section 22.2 Measuring Algorithm Efficiency Using Big O Notation
1. Analyzing algorithm efficiency is .
a. to measure their actual execution time
b. to estimate their execution time
c. to estimate their growth function
#
2. An input that results in the shortest execution time is called the .
a. best-case input
b. worst–case input
c. average-case input
#
3. Why is the analysis often for the worst case?
a. Best–case is not representative.
b. Worst–case is not representative, but worst–case analysis is very useful. You can show that the algorithm will never
be slower than the worst–case.
c. Average–case analysis is ideal, but difficult to perform, because it is hard to determine the relative probabilities and
distributions of various input instances for many problems.
#
4. Which of the following complexity is O(nlogn)?
a. 300n + 400n*n
b. 23nlogn + 50
c. 45n + 45nlogn + 503
d. n*n*n + nlogn
#
5. On an average, if an element is in the list, linear search searches
a. the whole list
b. half of the list
c. just one element in the list
d. one fourth of the list
#
Section 22.3 Examples: Determining Big O
6. What is the number of iterations in the following loop:
int count = 5;
while (count < n) {
count = count + 3;
}
a. n – 5
b. n – 3
c. n / 3 – 1