Chapter 11 Questions
Multiple Choice Questions
1. In the worst case, a binary search is ______.
a. O(n)
b. O(1)
c. O(log2 n)
d. O(n2)
2. The selection sort continues until ______ of the n items in an array have been swapped.
a. n/2
b. n – 2
c. n – 1
d. n
3. Given the following array:
4 15 8 3 28 21
which of the following represents the array after the second swap of the selection sort?
a. 4 3 8 15 21 28
b. 4 15 8 3 21 28
c. 3 4 8 15 21 28
d. 21 4 3 8 15 28
4. Given the fact that a selection sort of n items requires n2/2 + 5 * n/2 – 3 major operations, the selection sort is
______.
a. O(1)
b. O(n)
c. O(n2)
d. O(log2 n)
5. The ______ compares adjacent items and exchanges them if they are out of order.
a. selection sort
b. binary search
c. bubble sort
d. quicksort
6. A bubble sort requires at most ______ passes to sort an array of n items.
a. n/2
b. n – 2
c. n – 1
d. n
7. In the worst case, the insertion sort’s comparison occurs ______ times.
a. n
b. n – 1
c. (n – 1) / 2
d. n * (n – 1)/2
8. Each merge step of the mergesort requires ______ major operations.