Data Structure For GATE
Data Structure For GATE
______________________________________________________________________________
INSTRUCTIONS: Attempt all the 25 questions. Each question carry two marks.
n
T n 2T n
n
(II) Suppose you write a program that frequently sorts arrays whose size varies between 5 and 10. You should
do this using merge sort instead of insertion sort since the running time of merge sort n log n while insertion
sort is O n 2 .
Which of the above is correct.
(a) I (b) II (c) I, II (d) None of these
4. Minimum number of comparisions for finding second minimum out of n-elements is
(a) 2(n–1) (b) n + log + 2 (c) n + log n (d) n + log n–2
5. Consider the following statements
(I) Quicksort depends upon whether the partition is balanced or unbalanced. If partition is balanced running
time is n log n , however when the partition is unbalanced the running time is n 2 .
n
6. If T n 2 n /2 T 2n then T n ?
2
(a) n log n (b) 2n (c) 2n log n (d) n 2
(I) f n O f n
2
(II) f n O f n f n
(III) f n g n and f n O g n
Which of the above is correct.
(a) I (b) II (c) I, III (d) II, III
9. If T n T n 2 log n then T n ?
H.O.: 28-A/11, Jia Sarai, Near-IIT, New Delhi-16 , Ph : 011-26851008, 26861009 www.careerendeavour.com
B.O.: 48, First Floor, Mall Road, G.T.B. Nagar (Metro Gate No. 3), Delhi-09, Ph: 011-65462244, 9540292991
3
} }
xy uv
print ; print
2 2
The above program print respectively.
(a) GCD(X, Y) and LCM (X, Y) (b) GCD (X, Y) and GCD ( X, Y)
(c) LCM (X, Y) and GCD (X, Y) (d) LCM (X, Y) and LCM (X, Y)
13. Avg number of comparision for successful search for the following tree.
X
Y C
D
Z
A B E F
G
(a) 3.6 (b) 3.2 (c) 3.7 (d) none of these
14. Consider the following program code
int d = 0;
for (int a = 1; a < 11; ++a)
for (int b = 1; b < 11; ++b)
for (int c = 1; c < 11; ++c)
[body]
Consider the 2 body of the program
body 1 body 2
if a b c %3 0 if a%2 0 || b%3 0 || c%4 0
d d 1 d d 1
H.O.: 28-A/11, Jia Sarai, Near-IIT, New Delhi-16 , Ph : 011-26851008, 26861009 www.careerendeavour.com
B.O.: 48, First Floor, Mall Road, G.T.B. Nagar (Metro Gate No. 3), Delhi-09, Ph: 011-65462244, 9540292991
4
20. Suppose a hash table has 20 elements and collision is resolved using linear probing then how many element
must be there in hash table so that the probability of collision is more than 0.5
(a) 5 (b) 8 (c) 10 (d) 11
21. Key values 8, 3, 1, 5, 11, 6, 7, 9 are inserted into a BST in above order. The preorder traversal for the BST.
Which is not possible.
(a) 3, 1, 6, 7, 5, 8, 11, 9 (b) 8, 3, 1, 6, 5, 7, 11, 9
(c) 8, 5, 3, 1, 6, 7, 11, 9 (d) 8, 3, 1, 5, 6, 7, 11, 9
22. Suppose we are sorting an array of 8 integers using quicksort and we have just finished the first partitioning with
array looking as follows 2, 5, 1, 7, 9, 12, 11, 10
Then which can be pivot.
(a) 7 or 9 (b) 7 but not 9 (c) 9 but not 7 (d) neither 7 nor 9
23. How many maxheap tree possible with 4 distinct node?
(a) 2 (b) 3 (c) 4 (d) None of these
24. Given a sorted array A[n] and an integer X. If we write a function that counts the occurence of X in array A.
What is the time complexity.
(a) O(1) (b) O(log n) (c) O(n) (d) none of these
25. Given array of n integers which is initially increasing and then decreasing find the maximum value in the array.
How much time it will take?
(a) O(1) (b) O(log n) (c) O(n) (d) none of these
H.O.: 28-A/11, Jia Sarai, Near-IIT, New Delhi-16 , Ph : 011-26851008, 26861009 www.careerendeavour.com
B.O.: 48, First Floor, Mall Road, G.T.B. Nagar (Metro Gate No. 3), Delhi-09, Ph: 011-65462244, 9540292991
5
H.O.: 28-A/11, Jia Sarai, Near-IIT, New Delhi-16 , Ph : 011-26851008, 26861009 www.careerendeavour.com
B.O.: 48, First Floor, Mall Road, G.T.B. Nagar (Metro Gate No. 3), Delhi-09, Ph: 011-65462244, 9540292991