Directions For Questions 1 To 30: Select The Correct Alterna
Directions For Questions 1 To 30: Select The Correct Alterna
Directions For Questions 1 To 30: Select The Correct Alterna
151
Test
17. The following program computes n! 22. Consider the binary search tree
Find the complexity?
31
Input: A non-negative integer
Output: Value of n! 6 40
If n = 0 return 1
Else return F(n – 1) θ n 3 36 81
(A) θ (n) (B) θ (n log n)
(C) θ (n2) (D) θ (n3) Delete node ‘31’, what would be the parent node in the
new binary search tree?
18. Which of the following functions are often referred as (A) 36
‘exponential growth function’? (B) 40
(A) 2n, log n (B) 2n, n! (C) 81
(C) n!, n log n (D) n!, log n (D) 6
19. Consider the following code 23. Consider the given array [4, 6, 7, 8, 21, 9, 3, 10, 13, 16,
sort (a, n) 31] after performing ‘1’ delete max operation, on the
{ max heap. What would be the sequence of elements in
the array?
for i = 1 to n do
(A) 9, 21, 13, 16, 3, 7, 10, 8, 4, 6
{ (B) 21, 9, 13, 16, 7, 3, 10, 8, 4, 6
j = i; (C) 21, 9, 13, 16, 3, 7, 10, 8, 4, 6
for k = i + 1 to n do (D) 21, 9, 13, 16, 7, 3, 10, 4, 8, 6
if (a[k] < a [j]) then j = k; 24. Consider the given Di-graph
t = a[i];
a[i] = a[j]; 1 2 3
a[j] = t;
} How many strongly connected components does the
above graph contain?
}
(A) 1 (B) 2
The above code implements which sorting? (C) 3 (D) many
(A) Merge sort
25. Consider the given graph
(B) selection sort
(C) Insertion sort
(D) Radix sort A
F
20. Assume that the number of disks in a ‘Towers of B C E
Hanoi problem’ is ‘n’, with ‘3’ towers, Initially all G
disks are placed on tower 1, to get the largest disk D H
are placed on tower 1, to get the largest disk to the
bottom of 2nd tower, How many moves are required?
(∴ n = 3) Which of the following shows the adjacency matrix of
(A) n the above graph?
(B) (n – 1)
(C) (n + 1) A B C D E F G H
(D) 2n
A 0 1 1 0 0 0 0 0
21. Each new term in Fibonacci sequence is obtained B 1 0 1 0 0 0 0 0
by taking the sum of the two previous terms. The
C 1 1 0 1 1 0 0 0
first term of the sequence is f0 = 0, and the second
term f1 = 1. Which of the following gives Fibonacci D 0 0 1 0 0 0 0 0
(A)
sequence? E 0 0 1 0 0 1 1 0
(A) fn = fn+1 + fn – 2, n ≥ 2 F 0 0 0 0 1 0 0 0
(B) fn = fn–1 + fn–2, n ≥ 2
G 0 0 0 0 1 0 0 1
(C) fn = fn–1 + fn+1, n ≥ 2
(D) All the above H 0 0 0 0 0 0 1 0
Test | 3.153
A B C D E F G H 1 5
A 0 1 1 0 0
0 0 0
6
B 1 0 1 0 0
0 0 0 (A) 3 2
7
C 1 1 0 1 0
1 0 0
4 8
(B) D 0 0 1 0 0
0 0 0
E 0 0 1 0 0
0 1 1
5
F 0 0 0 0 1 0 0 0 1
G 0 0 0 0 1 0 0 1 6
(B) 2 4
H 0 0 0 0 1 0 1 0 7
3 8
A B C D E F G H
1 5
A 0 1 1 0 0
0 0 0
B 1 0 1 0 0
0 0 0 (C) 3 2 6
C 1 1 0 1 0
1 0 0 7
D 0 0 1 0 0
0 0 0 4 8
(C)
E 0 0 1 0 0
0 1 1
F 0 0 0 0 1
0 0 0 1 5
G 0 0 0 0 0 1 0 1
(D) 2 4 6
H 0 0 0 0 0 0 1 0
7
3 8
A B C D E F G H
27. Which of the following is FALSE?
A 0 1 1 0 0 0 0 0 (A) In dynamic programming an optimal sequence of
B 1 0 1 0 0 0 0 0 decisions is obtained by making explicit appeal to
C 1 1 0 1 1 0 0 0 the principle of optimality
(B) In greedy method only one decision sequence is
(D) D 0 0 1 0 0 0 0 0 generated.
E 0 0 1 0 0 1 1 0 (C) In dynamic programming, many decision se-
F 0 0 0 0 1 0 0 0 quences may be generated.
G 0 0 0 0 1 0 0 1 (D) In greedy method many decision sequences are
generated.
H 0 0 0 0 1 1 0 1
28. Consider an array a[n] of ‘n’ numbers that has ‘n/2’
26. Consider the given adjacency list distinct elements and ‘n/2’ copies of another element,
to identify that repeated element, how many steps are
required in the worst case?
1 3 2 (A) n/2 (B) n/2 + 1
2 4 1 6 (C) n/2 + 2 (D) n
3 1 4 29. Match the following, for a very large value of ‘n’
4 2 3
I. 36n3 + 2n2
5 6
II. 5n2 – 6n
6 2 7 5
III. n1.001 + n log n
7 7 8
P. θ (n2)
8 7
Q. Ω (n3)
R. θ (n1.001)
The above list is representation of which of the follow-
(A) I – P, II – Q, III – R (B) I – Q, II – P, III – R
ing graph?
(C) I – R, II – Q, III – P (D) I – R, II – P, III – R
3.154 | Unit 3 • Algorithms
Answers Keys
1. A 2. C 3. B 4. C 5. A 6. A 7. B 8. D 9. D 10. D
11. C 12. D 13. C 14. B 15. B 16. A 17. A 18. B 19. A 20. C
21. B 22. A 23. B 24. B 25. A 26. C 27. D 28. C 29. B 30. C