Académique Documents
Professionnel Documents
Culture Documents
d. bubble sort
10. Which of the following is true regarding the efficiency of the shell sort ?
a. It is slower than O(n2).
b. It is faster than O(n*log2 n).
c. It is not as efficient as the insertion sort.
d. It has not been established theoretically, i.e. as a single function of n.
11. The __________________ sort is good for almost-sorted files, operating in O(n) time
if not too many items are out of place.
a. insertion b. bubble
c. selection
quicksort
12. Which of the following sorts does not operate in O(n*log2 n) time?
a. quicksort b. mergesort c. heapsort d. hashsort
13. Which of the following sorts is not efficient in use of storage because it requires an
extra array?
a. quicksort b. mergesort c. heapsort d. insertion sort
14. Which of the following sorts may deteriorate to O(n2) time if the data is partitioned
into a subarray of 1 element and a subarray of n-1 elements?
a. insertion sort
b. mergesort c. heapsort d. quicksort
15. Which of the following sorts is efficient in time but requires a considerable amount
of extra storage space?
a. shell sort
b. mergesort c. heapsort d. quicksort
16. If the rightmost element is selected as the pivot in the quicksort
a. when the data is truly random, that value is a good choice.
b. when the data is sorted, that value is a good choice.
c. when the data is in reverse order, that value is a good choice.
d. that value is never a good choice.
(left) 44 _ _ _ _ ..._ _ _ _ 86 _ _ _ _ --- _ _ _ _ 29 (right)
17. Applying the median-of-three method to the above array in the quicksort, which of
the following would be selected as the pivot to partition the array.
18.
19.
a. 44
b. 86
c. 29
d. 53
90 100 20 60 80 110 120 40 10 30 50 70
0
1 2 3 4 5 6
7 8 9 10 11
Apply one partition to the above array in the quicksort with 70 as the pivot and
show the position of each item in the array immediately after that partition.
Arrange the following functions, often used to represent complexity of algorithms
in order from slowest to fastest.
O(1), O(n), O(n*log2 n), O(log2 n), O(n2), O(2n)
64 21 33 70 12 85 44 3 97 24 51 40
0
1 2 3 4 5 6 7 8 9 10 11
Show each subarray as it is ordered. (Hint: 10 subarrays of lengths 2,3 and 6 are sorted
and merged.)
21. Starting with h = 1, generate the gap sequence for the shellsort using the recursive
expression: h = 3*h + 1, for an array of 1000 elements.
22.
12 13 11 16 14 15 18 19 17 20
0
1 2 3 4 5 6 7 8 9
The shellsort has been applied to the above array but is not completed!
Has the array been "4-sorted"? If yes, prove your answer by exhaustion.
If no, prove your answer by counterexample.
23. In computer science a graph is a data structure where vertices (nodes) represent
objects which in turn represent real world data, and edges represent references to objects:
how objects are related. T/F
Refer to this graph for nos. 24 - 27
15
8 1
12 18
25
35
35
20
30
40
80 60 70 40 30 20 50 10
0 1 2 3 4 5 6 7
m n o
t u
x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
and all of the resulting numbers are summed. The hash value is then formed by
taking this intermediate result modulo the hash table length: h(word) =
sum(lettercode) % tablesize
The length of the table to be used is 17 and the key fields of the objects to be stored in the
table are:
BROWN,COLE,DAVIS,FOX,BAKER,ADAMS,GALO,JONES,FARMER,BROCK
53.
54.
55.
35. 8 5 1 30 12 15 18 20 25 10 35
36. 8 1 5 12 18 15 30 25 35 10 20
37
25
15
35
10 20
30 40
18
38
20
or
15
10 18
39. b
40. b
35
15
30
41. d
40
10
42. d
43
+
/
-
*
c
a b
44 c
45 b
46 d
47 a
50
48 a
80
60
40
10
51. c
52. b
53
30
0/
1 cole
2 galo
3 baker
4 brown
5 davis
6 adams
7/
8/
9/
10 farmer
11 fox
12 jones
13 /
14 /
70
30
20
50
49 d
20
18
35
40
15 brock
16 /
54.
0 --> /
1 --> cole -->galo -->/
2 --> /
3 --> baker --> /
4 --> brown --> davis --> adams --> /
5 --> /
6 --> /
7 --> /
8 --> /
9 --> /
10 --> farmer --> /
11 --> fox --> /
12 --> jones --> /
13 --> /
14 --> /
15 --> brock --> /
16 --> /
55.
0 /
1 cole
2/
3 baker
4 brown
5/
6 adams
7/
8/
9 davis
10 farmer
11 fox
12 jones
13 /
14 /
15 brock
16 galo