Professional Documents
Culture Documents
Answer Keys
1. D 2. C 3. B 4. C 5. C 6. A 7. D 8. B 9. D 10. A
11. C 12. B 13. A 14. A 15. B 16. C 17. B 18. C 19. D 20. C
21. D 22. C 23. D 24. C 25. D
B = 1 × 4, Brute Force
(iv)
C = 4 × 3, 5 + 5 + 5 + 5 +1
D = 3 × 6. Choice (C) ⇒ 5 coins. Choice (D)
1 20. Amortized time is q (log n)
17. a = = 0.02
36 Worst case time is q (n log n). Choice (C)
1 21. • Computing a median of ‘n’ elements takes q(n)
b = = 0.02
36 time as it has to traverse ‘n’ elements.
1 • The shortest path between 2 vertices need not be
c = = 0.08 same in the Minimum spanning tree and in graph.
12
Consider following graph G
1
d = = 0.11 A• 1
•B
9
5 1 1
1
e = = 0.13
36
D• C
Huffman tree: 1
1
e 0.23
0 1 D• •C
0.13 1
d 0.12
The shortest path from A to C is 1 in graph ‘G’ where
0.11 0 1
as, it is 2 in MST. Choice (D)
0.04 c
22. 12 39 2 94 23 77 52 9
0 1 0.08
2 12 39 94 23 77 52 9
a b 2 12 39 94 23 77 52 9
0.02 0.02 2 12 23 39 94 77 52 9
Huffman codes 2 12 23 39 77 94 52 9
a = 1100, b = 1101, c = 111, d = 10, e = 0. Choice (B)
2 12 23 39 77 52 9
18. 7 5 6 3 8 12 9 13 14 10 11 2 12 23 39 52 77 94 9
12 + 11 + 22 + 21 = 66
\ 2 9 12 23 39 52 77 94
7 5 6 3 8 12 9 13 14 10 11
\ Insertion sort. Choice (C)
11 + 20 + 27 + 11 = 69. Choice (C)
19. Coin values 1, 5, 6. 23. Given elements 12 39 02 94 23 77 52 09
Value = 20 First sort elements based on least significant digit
Greedy Algorithm 12 02 52 23 94 77 39 09.
(i)
6 + 6 + 6 +1+1 Sort the above elements based on second least signifi-
cant digit.
⇒ 5 coins
02 09 12 23 39 52 77 94
Brute-Force
(ii) \ The above sorting algorithm is ‘Radix–Sort’.
5+5+5+5
Choice (D)
⇒ 4 coins
Value = 21 24. The available elements are [0, 1, 2, ..., n2 – 1]
Greedy Algorithm There are n2 elements.
(iii)
6 + 6 + 6 +1+1+1 Separate chaining has unlimited space, it can save all
⇒ 6 coins the n2 elements.
Algorithms Test 4 | 3.101
Linear probing: 14 5 21 4 16 31 17 8 11
It will have ‘n’ slots, so maximum we can store ‘n’ val-
ues. 5 14 21 4 16 31 17 8 11
Quadratic probing:
5 14 4 21 16 31 17 8 11
Like linear probing, it will also have ‘n’ slots.
We can store only ‘n’ values. 5 14 4 16 21 31 17 8 11
Choice (C)
5 14 4 16 21 17 31 8 11
25. Bubble sort, compares adjacent elements, if not in
order swaps them. 5 14 4 16 21 17 8 31 11
5 14 4 16 21 17 8 11 31.
Choice (D)