if the keys are stored in the binary search tree shown in the
figure on the far right? (The cost of looking up a key is the
number of comparisons of the key against keys stored in the
binary tree.)
A
0.1
B
0.2
C
0.3
D
0.4
B
A
D
C
3. [4 points] Suppose we are sorting the following array using insertion sort. In each part you are given
a pair of values. Indicate whether the two values get compared against each other by answering YES if
they get compared, NO if they do not get compared.
9
13
5
11
7
17
10
0
1
2
3
4
5
6
(a) 5 and 11
(b) 10 and 13
(c) 9 and 13
(d) 11 and 17
4. [6 points] Suppose we are running quicksort, as presented and analyzed in class. Our input is the
following array, rearranged in some random order. Assume that each of the 10! possible permutations
is equally likely to be the input.
63
0
17
1
18
2
42
3
52
4
20
5
84
6
2
7
103
8
47
9
(a) What is the probability that the values 42 and 84 will be compared?
(Your answer should be a
number.)
(b) What is the probability that the values 2 and 103 will be compared?
(Your answer should be a
number.)
-1-
Form 2A

5.
[9 points] This question concerns the algorithm for counting sort discussed in class.
Recall that

#### You've reached the end of your free preview.

Want to read both pages?

- Spring '08
- HIRSCHBERG
- Algorithms