300+ Algorithms MCQ PDF
300+ Algorithms MCQ PDF
Net
GATE Questions
2 GATE Questions
GATE Questions 3
(iii) Into the same tree given in 7(ii) above, insert the integer 13 and show the new
balance factors that would arise if the tree is no rebalanced. Finally, carry the
required rebalancing of the tree and show the new tree with the balance factors on
each mode. (6)
08. GATE (CSE) 1988, Q.13(iv)
Solve the recurrence equations (2)
T(n) = T(n/2) + 1
T(1) = 1
09. GATE (CSE) 1989, Q.1(vii)
A hash table with ten buckets with one slot per bucket is shown in Figure 1, with the
symbols S1 to S7 entered into it using some hashing function with linear probing. The
worst case number of comparison required when the symbol being searched is not in the
table is ……………………… (2)
Figure 1
For More Quality Study Material: www.ErForum.Net
4 GATE Questions
GATE Questions 5
6 GATE Questions
(viii) (2)
(A) Heap construction (p) W(nlog10 n)
(B) Constructing hash table with linear probing (q) O(n)
(C) AVL tree construction (r) O(n2)
(D) Digital trie construction (s) O(n log2 n)
18. GATE (CSE) 1990, Q.3
Choose the correct alternatives (more than one may be correct):
(iii) The number of rooted binary trees with n nodes is: (2)
(A) Equal to the number of ways of multiplying (n + 1) matrices.
(B) Equal to the number of ways of arranging n out of 2n distinct elements.
1 Ê 2 nˆ
(C) Equal to
(n + 1) ÁË n ˜¯
(D) Equal to n!
(v) The complexity of comparison based sorting algorithm is: (2)
(A) q (n log n) (B) q (n)
(C) q (n2) (D) q (n n )
19. GATE (CSE) 1990, Q.13
(a) Consider the height balanced tree T1, with values stored at only the leaf nodes shown
in the given figure
(i) Show how to merge to the tree T1 elements from tree T2 shown in the given
figure using the node D of tree T1: (3)
For More Quality Study Material: www.ErForum.Net
GATE Questions 7
(ii) What is the time complexity of a merge operation on balanced trees T1 and T2
where T1 and T2 are of height h1 and h2 respectively, assuming rotation scheme
are given. Give reasons. (3)
(b) Consider a hash table with chaining scheme for overflow handling:
(i) What is the worst-case timing complexity of inserting n elements into such a
table? (2)
(ii) For what type of instances does this hashing scheme take the worst case time
for insertion? (2)
20. GATE (CSE) 1990, Q.16
The following algorithm (written in pseudo-Pascal) works on a undirected graph G
Program Explore (G)
procedure Visit (u)
begin
if Adj (u) is not empty
{ comment : Adj (u) is the list of edges incident to u}
then
begin
select an edge from Adj (u);
Let an edge e = (u, v);
remove e from Adj (u) and Adj (v);
Visit (v);
end
else
mark u as a finished vertex and remove u from LIST;
{Comment : LIST is the set of vertices in the graph}
end;
begin
while LIST is not empty
do
begin
Let v Œ LIST;
Visit (v);
end
end
Note: Initially Adj (u) is the list of all edges incident to u and LIST is the set of all
vertices in the graph. They are globally accessible.
What kinds of sub-graphs are obtained when this algorithm traverses the graphs G1 and
G2 shown in Figure 1 and Figure 2, respectively? (5)
Figure 1 Figure 2
For More Quality Study Material: www.ErForum.Net
8 GATE Questions
(a) What is the commonly known traversal of graphs that can be obtained from the sub-
graphs generated by Program Explore? (2)
(b) Show that the time complexity of the procedure is O(v + e) for a graph with v
vertices and e edges, given that each vertex can be accessed and removed from LIST
in const time. Also show that all the edges of the graph are traversed. (3)
21. GATE (SEA: Computational Method) 1990
I.1 Choose the correct alternatives (Exactly one choice is correct) and write the
corresponding letters only:
1.1 The maximum number of nodes in a binary tree of level k, k ≥ 1 is (2)
(A) 2k + 1
(B) 2k – 1
(C) 2k–1
(D) 2k–1 – 1
1.16 The average case complexity of quick sort algorithm for sorting n elements is
(2)
(A) (n log log n)
(B) (n2)
(C) (n log n)
(D) (n log2 n)
I.3 Construct a binary tree whose preorder and inorder sequences are A B M H E O
C P G J D K L I N F and H M C O E B A G P K L D I N J F respectively, where
A, B, C, D, E, ………. are the labels of the tree nodes. Is it unique? (3)
I.4 Give the necessary number of passes and interchanges to sort the sequence 7, 21,
6, 8, 30, 18, 4, 12 in increasing order by using bubble sort method. (4)
I.8 The following incomplete Pascal procedure merges two sorted lists
(x[l], x[l+1], ……., x[m], m > l and
(y[i], y[i+1], ……., y[j], j > i where
x[l].key £ x[l+1].key £ ………….. £ x[m].key
and
y[i].key £ y[i+1].key £ ………….. £ y[j].key and it obtains in a sorted list
(z[1], z[2], ………. z[k] where k = m + j – l – i + 2.
Complete the procedure by replacing each ‘?’ by the appropriate operator from the
procedure set {>, <, =>, <=, <>, or, and, not}
procedure MERGE (var x, y, z: a file; l, m, i, j: integer); var k, s, t, u: integer;
begin
s: = l;
For More Quality Study Material: www.ErForum.Net
GATE Questions 9
k: = 1;
u: = I;
while[(s?m)?(j?u)] do
begin
if x[s].key?y[u].key
then
begin
z[k]: = x[s];
s: = s+1
end
else
begin
z[k]: = y[u];
u: = u+1
end
k: = k+1;
end
if s ? m
then
for t: = u to j do
z[k + t – u]: = y[t]
else
for t: = s to m do
z[k + t – s]: = x[t]
end;
22. GATE (CSE) 1991, Q.1
Fill in the blanks:
(vii) The minimum number of comparisons required to sort 5 elements is
_____________. (2)
(viii) The weighted external path length of the binary tree in the given figure is
_____________. (2)
For More Quality Study Material: www.ErForum.Net
10 GATE Questions
(ix) If the binary tree in the following figure is traversed in inorder, then the order in
which the nodes will be visited is _____________. (2)
(R) ( )
2n
C. The number of even permutations of n objects n
D. The number of binary string of length 6n
GATE Questions 11
A. (n2)
B. (m n)
C. (m + n)
D. (m log n)
E. (m2)
(vii) The following sequence of operations is performed on a stack: (2)
PUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP, POP, POP, PUSH (20),
POP.
The sequence of values popped out is:
A. 20, 10, 20, 10, 20
B. 20, 20, 10, 10, 20
C. 10, 20, 20, 10, 20
D. 20, 20, 10, 20, 10
E. None of the above
25. GATE (CSE) 1991, Q.14
Consider the binary tree in the given figure:
(a) What structure is represented by the binary tree? (1)
(b) Give the different steps for deleting the node with key 5 so that the structure is
preserved. (2)
(c) Outline a procedure in the pseudo-code to delete an arbitrary node from such a
binary tree with n nodes that preserves the structure. What is the worst case
complexity of your procedure? (3)
12 GATE Questions
I1.1 The number of different ordered trees with 3 nodes labelled Y, Y, Z are (2)
(A) 16
(B) 8
(C) 12
(D) 24
I1.16 The worst-case time complexity of mergesort for sorting n elements is (2)
(A) (n ) 2
(B) (n log n)
(C) (n2 log n)
(D) (log n)
I3(b) Let A[1: n, 1:n] be a n × n matrix such that A [I, j] = 0 if | i – j | > 1. The entries
A [i, j] for which | i – j | £ 1 are stored in a one-dimensional array B [1: 3n–2]
row-wise. Thus, A[1, 1] is stored in B[1], A[1, 2] in B[2], and so on. Give the
formula for computing the index K in array B of an element A[i, j] in terms of
i and j. (4)
I4(a) If a tree has n1 nodes of degree 1, n2 nodes of degree 2, …. nm nodes of degree
m, give a formula for the number of terminal nodes n0 of the tree in terms of n1,
n2, …., nm. (4)
I5(a) Consider three pegs A, B, C and four disks of different sizes. Initially, the four
disks are stacked on peg A, in order of decreasing size. The task is to move all
the disks from peg A to peg C with the help of peg B. The moves are to be made
under the following constraints:
[i] In each step, exactly one disk is moved from one peg to another.
[ii] A disk cannot be placed on another disk of smaller size. If we denote the
movement of a disk from one peg to another by y Æ y, where y, y are A,
B or C, then represent the sequence of the minimum number of moves to
accomplish this as a binary tree with node labels of the form (y Æ y) such
that the inorder traversal of the tree gives the correct sequence of the moves.
If there are n disks, derive the formula for the total number of moves required
in terms of n: (4)
27. GATE (CSE) 1992, Q.1
Fill in the blanks.
(ix) Complexity of Kruskal’s algorithm for finding the minimum spanning tree of a
undirected graph containing n vertices and m edges, if the edges are sorted is,
__________. (2)
(x) Maximum number of edges in a planner graph with n vertices is __________.
(2)
28. GATE (CSE) 1992, Q.2
Choose the correct alternatives (more than one may be correct) and write the
corresponding letters only:
For More Quality Study Material: www.ErForum.Net
GATE Questions 13
14 GATE Questions
F = F1
end
[n is positive integer greater than zero].
(a) Derive a recurrence relation for F(n). (4)
(b) Solve the recurrence relation for a closed form solution of F(n). (6)
31. GATE (CSE) 1992, Q.9
Suggest a data structure for representing a subset S of integers from 1 to n. Following
operations on the set S are to be performed in constant time (independent of cardinality
of S) (10)
(iii) MEMBER (Y): Check whether Y is in the set S or not
(iv) FIND-ONE (S): If S is non-empty, return one element of the set S (any arbitrary
element will do)
(v) ADD(Y): Add integer y to set S
(vi) DELETE(Y): Delete integer y from S
Give pictorial examples of your data structure. Give routines for these operations in an
English-like language. You may assume that the data structure has been suitably
initialized. Clearly state your assumptions regarding initialization. (10)
32. GATE (SEA: Computational Method) 1992
Choose the correct alternatives (exactly one choice is correct) and write the
corresponding letters only:
I1.(a) Suppose one character at a time comes as an input from a string of letters. There
is an option either to (i) print the incoming letter or to (ii) put the incoming letter
on to a stack. Also a letter from top of the stack can be popped out at any time
and printed. The total number of total distinct words that can be formed out of
a string of three letters in this fashion, is (2)
(A) 3
(B) 4
(C) 5
(D) 6
I2.(d) A K-ary tree is such that every node has either K sons or no sons. If L and I are
the number of leaves and internal nodes respectively, then express L in terms of
K and I. (2)
I8. Consider three pegs A, B, C and four disks of different sizes. Initially, the four
disks are stacked on peg A, in order of decreasing size. The task is to move all
the disks from peg A to peg C with the help of peg B. The moves are to be made
under the following constraints: (5)
(i) In each step, exactly one disk is moved from one peg to another.
(ii) A disk cannot be placed on another disk of smaller size.
For More Quality Study Material: www.ErForum.Net
GATE Questions 15
16 GATE Questions
GATE Questions 17
n( n + 1)
(D)
2
1.17 Linked lists are not suitable for data structures for which one of the following
problems?
(A) Insertion sort
(B) Binary search
(C) Radix sort
(D) Polynomial manipulation
1.19 Which of the following algorithm design techniques is used in the quicksort
algorithm?
(A) Dynamic programming
(B) Backtracking
(C) Divide and conquer
(D) Greedy method.
1.22 Which one of the following statements is false?
(A) Optimal binary search tree construction can be performed efficiently using
dynamic programming
(B) Breadth-first search cannot be used to find converted components of a graph
(C) Given the prefix and postfix walks over a binary tree, the binary tree cannot
be uniquely constructed
(D) Depth-first search cannot be used to find converted components of a graph
1.23 Consider the following two functions:
Ï n3 for 0 £ n £ 10,000
g1 (n) = Ì
Ón for n ≥ 10,000
Ïn for 0 £ n £ 100
g1 (n) = Ì 3
Ón for n > 100
Which of the following is true?
(A) g1 (n) is O(g2 (n))
(B) g1 (n) is O(n3)
(C) g2 (n) is O(g1 (n))
(D) g2 (n) is O(n)
38. GATE (CSE) 1994, Q.2.5
Fill in the blanks: (2)
The number of edges in a regular graph of degree d and n vertices are …………….
39. GATE (CSE) 1994, Q.5
A 3-ary tree is a tree in which every internal node has exactly three children. Use the
induction to prove that the number of leaves in a 3-ary tree with n internal nodes is
2(n – 1) + 3. (5)
For More Quality Study Material: www.ErForum.Net
18 GATE Questions
(b) For a B+-tree of order d with n leaf nodes, the number of nodes accessed during a
search is 0 (-——). (2)
For More Quality Study Material: www.ErForum.Net
GATE Questions 19
20 GATE Questions
GATE Questions 21
22 GATE Questions
(A) 1
(B) 3
(C) 7
(D) 8
1.15 Which of the following sequences denotes the post-order traversal sequence of the
tree of question 1.14?
(A) f e g c d b a
(B) g c b d a f e
(C) g c d b f e a
(D) f e d g c b a
54. GATE (CSE) 1996, Q.2
Write in your answer book the correct or the most appropriate answer to the following
multiple choice questions by writing the corresponding letter A, B, C or D against the
sub-question number. (Each carrying 2 marks)
2.11 The minimum number of interchanges needed to convert the array
89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70
into a heap with the maximum element at the root node is
(A) 0
(B) 1
(C) 2
(D) 3
For More Quality Study Material: www.ErForum.Net
GATE Questions 23
24 GATE Questions
GATE Questions 25
26 GATE Questions
Ê Í n ˙ˆ
4.6 Let T(n) be the function defined by T(1) = 1, T(n) = 2T Á Í ˙˜ + n for n ≥ 2.
Ë Î 2 ˚¯
Which of the following statements is true?
(A) T(n) = O( n ) (B) T(n) = O(n)
(C) T(n) = O(log n) (D) None of the above
4.7 A priority queue Q is used to implement a stack S that stores characters. PUSH(C)
is implemented as INSERT(Q, C, K) where K is an appropriate integer key chosen
by the implementation. POP is implemented as DELETEMIN(Q). For a sequence
of operations, the keys chosen are in
(A) non-increasing order (B) non-decreasing order
(C) strictly increasing order (D) strictly decreasing order
62. GATE (CSE) 1997, Q.6
Let G be a graph with 100 vertices numbered 1 to 100. Two vertices i and j are adjacent
iff |i – j| = 8 or |i – j| = 12. The number of connected components in G is
(A) 8 (B) 4
(C) 12 (D) 25
63. GATE (CSE) 1997, Q.9
Consider a graph whose vertices are points in the plane with integer co-ordinates (x,y)
such that 1 £ x £ n and 1 £ y £ n, where n ≥ 2 is an integer. Two vertices (x1, y1)
and (x2, y2) are adjacent iff |x1 – x2| £ 1v |y1 – y2| £ 1. The weight of an edge {(x1, y1),
(x2, y2)} is ( x1 - x2 )2 + ( y1 - y2 )2 .
For More Quality Study Material: www.ErForum.Net
GATE Questions 27
(a) What is the weight of a minimum weight spanning tree in this graph? Write only the
answer without any explanations. (2)
(b) What is the weight of a maximum weight spanning tree in this graph? Write only
the answer without any explanations. (3)
64. GATE (CSE) 1997, Q.12
Consider a hash table with n buckets, where external (overflow) chaining is used to
resolve collisions. The hash function is such that the probability that a key value is
1
hashed to a particular bucket is . The hash table is initially empty and K distinct values
n
are inserted in the table.
(a) What is the probability that bucket number 1 is empty after the Kth insertion? (1)
(b) What is the probability that no collision has occurred in any of the K insertions?
(2)
(c) What is the probability that the first collision occurs at the Kth insertion? (2)
65. GATE (CSE) 1997, Q.15
Consider the following function.
Function F(n, m: integer): integer;
begin
if(n <= 0) or (m <= 0) then
F:= 1
else
F:= F(n–1, m) + F(n, m–1);
end
Ê nˆ Ê n - 1ˆ Ê n - 1ˆ
Use the recurrence relation Á ˜ = Á + to answer the following questions.
Ë k ¯ Ë k ¯˜ ËÁ k - 1¯˜
Assume n, m are positive integers. Write only the answer without any explanation.
(a) What is the value of F(n, 2)? (2)
(b) What is the value of F(n, m)? (2)
(c) How many recursive calls are made to the function F, including the original call,
when evaluating F(n, m)? (1)
66. GATE (CSE) 1997, Q.16
A size balanced binary tree is a binary tree in which for every node, the difference
between the number of nodes in the left and right sub-tree is at most 1. The distance of
a node from the root is the length of the path from the root to the node. The height of
a binary tree is maximum distance of a leaf node from the root.
(a) Prove, by using induction on h, that a size-balanced binary tree of height h contains
at least 2h nodes. (3)
(b) In a size-balanced binary tree of height h ≥ 1, how many nodes are at distance h – 1
from the root? Write only the answer without any explanation. (2)
For More Quality Study Material: www.ErForum.Net
28 GATE Questions
if(t1.val != t2.val) S1
}
t2 = t2 Ænext;
}
t1Ænext = NULL;
return head;
}
GATE Questions 29
(b) What is the maximum number of internal nodes in a B+ -tree of order 4 with 52
leaves? (1)
(c) What is the minimum number of leaves in a B -tree of order d and height h (h ≥ 1)?
+
(2)
69. GATE (CSE) 1998, Q.1
The question consists of 35 (Thirty five) multiple choice questions, each carrying 1
mark. The answers to the multiple choice questions MUST be written only in the boxes
corresponding to the questions in the first page of the answer book.
1.21 Which of the following algorithm design techniques is used in finding all pairs of
shortest distances in a graph?
(a) Dynamic programming (b) Backtracking
(c) Greedy (d) Divide-and-Conquer
1.22 Give the correct matching for the following pairs.
(A) O (log n) (P) Selection
(B) O (n) (Q) Insertion sort
(C) O (n log n) (R) Binary search
(D) O(n2) (S) Merge sort
(a) A – R, B – P, C – Q, D – S (b) A – R, B – P, C – S, D – Q
(c) A – P, B – R, C – S, D – Q (c) A – P, B – S, C – R, D – S
1.23 How many substrings of different lengths (non-zero) can be formed from a
character string of length n?
(a) n (b) n2
(c) 2 n (d) n(n+1)/2
1.24 Which of the following statements is false?
(a) A tree with n nodes has (n – 1) edges.
(b) A labelled rooted binary tree can be uniquely constructed given its post-order
and pre-order traversal results.
(c) A complete binary tree with n internal nodes has (n + 1) leaves.
(d) The maximum number of nodes in a binary tree of height h is (2h+1 – 1).
70. GATE (CSE) 1998, Q.2
The question consists of 20 (Twenty) multiple choice questions, each carrying 2 marks.
The answers to the multiple choice questions MUST be written only in the boxes
corresponding to the questions in the second page of the answer book.
2.11 A complete n-ary tree is one in which every node has 0 or n sons. If x is the
number of internal nodes of a complete n-ary tree, the number of leaves in it is
given by
(a) x(n – 1) + 1 (b) xn – 1
(c) xn + 1 (d) x(n + 1)
For More Quality Study Material: www.ErForum.Net
30 GATE Questions
2.12 What value would be the following function return for the input x = 95?
Function fun(x: integer):integer;
begin
if x > 100 then fun:= x – 10
else fun:= fun(fun (x + 11))
end;
(a) 89 (b) 90
(c) 90 (d) 92
2.11 Let A be a two-dimensional array declared as follows:
A: array [1 … 10] [1 … 15] of integer;
Assuming that each integer takes one memory locations the array is stored in row-
major order and the first element of the array is stored at location 100, what is the
address of element A[i][j]?
(a) 15i + j + 84 (b) 15j + i + 84
(c) 10i + j89 (d) 10j + i + 89
71. GATE (CSE) 1998, Q.6(a)
Solve the recurrence relation (2)
xn = 2xn – 1, n>1
x1 = 2
72. GATE (CSE) 1998, Q.17
(a) Let p be a pointer as shown in the figure in a singly linked list. (2)
GATE Questions 31
(A) 0 (B) 1
(C) 2 (D) 3
1.16 If n is a power of 2, then the minimum number of multiplications needed to
compute an is:
(A) log2 n (B) n
(C) n – 1 (D) n
For More Quality Study Material: www.ErForum.Net
32 GATE Questions
GATE Questions 33
(b) Write a constant time algorithm to insert a node with data D just before the node
with address p of a singly linked list. (2)
78. GATE (CSE) 1999, Q.CS12
(a) In a binary tree, a full node is defined to be a node with 2 children. Use the induction
on the height of the binary tree to prove that the number of full nodes plus one is
equal to the numbers of leaves. (3)
(b) Draw the min-heap that results from insertion of the following elements in order into
an initially empty min-heap: 7, 6, 5, 4, 2, 3, 1. Show the result after the deletion of
the root of this heap. (2)
79. GATE (CSE) 2000, Q.1
The question consists of 23 (Twenty three) multiple choice questions, each carrying 1
mark. For each question, four options are provided out of which exactly one is correct.
Write only the correct option for each question ONLY in the box provided for the
question in the first sheet of the answer book.
1.13 The most appropriate matching for the following pairs
(X):Depth-first search 1: heap
(Y):Breadth-first search 2: queue
(Z): Sorting 3: stack
(A) X – 1, Y – 2, Z – 3
(B) X – 3, Y – 1, Z – 2
(C) X – 3, Y – 2, Z – 1
(D) X – 2, Y – 3, Z – 1
1.14 Consider the following nested representation of binary trees: (X Y Z) indicates Y
Z are the left and right subtrees, respectively, of node X. Note that Y and Z may
be NULL, or further nested. Which of the following represents a valid binary tree?
(A) (1 2 (4 5 6 7))
(B) (1 ( ( 2 3 4) 5 6) 7)
(C) (1 (2 3 4) (5 6 7))
(D) (1 (2 3 NULL) (4 5))
For More Quality Study Material: www.ErForum.Net
34 GATE Questions
1.15 Let s be a sorted array of n integers. Let t(n) denote the time taken for the most
efficient algorithm to determine if there are two elements with sum less than 1000
in s. Which of the following statements is true?
(A) T(n) is O(1)
(B) n £ t(n) £ n log2 n
Ê nˆ
(C) n log2 n £ t(n) < Á ˜
Ë 2¯
Ê nˆ
(D) t(n) = Á ˜
Ë 2¯
80. GATE (CSE) 2000, Q.2
The question consists of 26 (Twenty six) multiple choice questions, each carrying 2
marks. For each question, 4 options are provided out of which only one is correct. Write
the correct options for each question ONLY in the box provided for the question in the
second sheet of the answer book.
2.15 Suppose you are given an array s[1 .. n] and a procedure reverse(s, i, j) which
reverses the order of elements in s between positions i and j (both inclusive). What
does the following sequence do, where 1 £ k < n
reverse(s, 1, k);
reverse(s, k+1, n);
reverse(s, 1, n);
(A) Rotates s left by k positions
(B) Leaves s unchanged
(C) Reverses all elements of s
(D) None of the above
2.16 Let LASTPOST, LASTIN and LASTPRE denotes the last vertex visited in a
postorder, inorder and preorder traversal respectively, of a completely binary tree.
Which of the following is always true?
(A) LASTIN = LASTPOST
(B) LASTIN = LASTPRE
(C) LASTPRE = LASTPOST
(D) None of the above
2.17 Consider the following functions
n
f(n) = 3n
g(n) = 2 n log2 n
h(n) = n!
Which of the following is always true?
(A) h(n) is O(f(n))
(B) h(n) is O(g(n))
For More Quality Study Material: www.ErForum.Net
GATE Questions 35
36 GATE Questions
iset (i) {
if (p[i] £ 0 or p[i] >count)
return false;
if (q[p[i]] π i)
return false;
return true;
}
(a) Fill in the boxes with expressions/statements to make fib() store and reuse computed
Fibonacci values. Write the box number and the corresponding contents in your
answer book. (3)
(b) What is the time complexity of the resulting program when computing fib(n)? (2)
84. GATE (CSE) 2000, Q.CS17
An array contains four occurrences of 0, five occurrences of 1 and three occurrences of
2 in any order. The array is to be stored using swap operations (elements that are
swapped need not be adjacent).
(a) What is the minimum number of swaps needed to sort such an array in the worst
case? (2)
(b) Give an ordering of elements in the above array so that the minimum number of
swaps needed to sort the array is the maximum. (3)
For More Quality Study Material: www.ErForum.Net
GATE Questions 37
38 GATE Questions
GATE Questions 39
40 GATE Questions
1.25 The maximum number of edges in a n-node undirected graph without self
loops is
(A) n2 (B) n(n – 1)/2
(C) n – 1 (D) (n+1)(n)/2
92. GATE (CSE) 2002, Q.CS2
The question consists of 25 (Twenty five) multiple choice questions, each carrying 2
marks. For each question, four options are provided out of which exactly one is correct.
Answer each sub-question by darkening the bubble on the ORS using soft HB pencil.
Do not darken more than one bubble. Do not use ORS for rough work. You may like
to use the answer book for any rough work if needed.
2.8 Consider the following declaration of a two-dimensional array in C:
Char a[100][100];
Assuming that the main memory is byte addressable and that the array is stored
starting from address 0, the address of a[40][50] is
(A) 4040 (B) 4050
(C) 5040 (D) 5050
2.9 The number of leaf nodes in a rooted tree of n nodes, with each node having 0
or 3 children is:
(A) n/2 (B) (n – 1)/3
(C) (n – 1)/2 (D) (2n + 1)/3
2.10 Consider the following algorithm for searching a given number x in an unsorted
array A[1...n] having n distinct values:
1. Choose an i uniformly at random from 1 ... n;
2. If A[i] = x then Stop else Goto 1;
Assuming that x is present in A, what is the expected number of comparisons
made by the algorithm before it terminates?
(A) n (B) n – 1
(C) 2n (D) n/2
2.11 The running time of the following algorithm
Procedure A(n)
( ( ))
If n <= 2 return(1) else return A È n ˘ ;
Í ˙
is best described by
(A) O(n) (B) O(log n)
(C) O(log log n) (D) O(1)
2.12 A weight balanced tree is a binary tree in which for each node, the number of
nodes in the left sub-tree is at least half and at most twice the number of nodes
in the right sub-tree. The maximum possible height (number of nodes on the path
from the root to the furthest leaf) of such a tree on n nodes is best described by
which of the following:
For More Quality Study Material: www.ErForum.Net
GATE Questions 41
42 GATE Questions
B-tree B+-tree
Successful Unsuccessful Successful Unsuccessful
Search Search Search Search
X1 X2 X3 X4
A successful search means that the key exists in the database and unsuccessful
means that it is not present in the database. Each of the entries X1, X2, X3, and X4
can have a value of either constant or variable: Constant means that the search time
is the same, independent of the specific key value, whereas variable means that it
is depend on the specific key value chosen for the search
Give the correct values for the entries X1, X2, X3, and X4 (for example, X1 =
Constant, X2 = Constant, X3 = Constant, X4 = Constant).
[GATE questions of 2003 and onwards are of MULTIPLE CHOICE QUESTION types.
Q.1 – Q.30/25/20 each carrying one mark and the rest carrying two marks. Negative
marking 25%]
(A) n – k + 1 (B) n – k
(C) n – k – 1 (D) n – k – 1
99. GATE (CSE) 2003, Q.8
Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from
G, the number of components in the resultant graph must necessarily lie between
(A) k and n (B) k – 1 and k + 1
(C) k – 1 and n – 1 (D) k + 1 and n – k
For More Quality Study Material: www.ErForum.Net
GATE Questions 43
44 GATE Questions
GATE Questions 45
(A) (B)
46 GATE Questions
(A) 29 (B) 31
(C) 38 (D) 41
115. GATE (CSE) 2003, Q.69
Let G = (V, E) be a directed graph with n vertices. Path from vi to vj in G is a sequence
of vertices (vi, vi+1, … vj) such that (vk, vk+1) Œ E for all k in I through j – 1. A simple
path is the path in which no vertex appears more than once.
For More Quality Study Material: www.ErForum.Net
GATE Questions 47
48 GATE Questions
GATE Questions 49
(A) (B)
(C) (D)
50 GATE Questions
y = m / x
}
print (x);
(A) log m (B) m2
(C) m1/2 (D) m1/3
129. GATE (CSE) 2004, Q.43
Consider the following C program segment:
struct CellNode{
struct CellNode *leftChild;
int element;
struct CellNode *rightChild;
};
int Dosomething(struct CellNode *ptr)
{
int value = 0;
if(ptr != NULL)
{ if(ptr -> leftChild != NULL)
value = 1 + DoSomething (ptr -> leftChild);
if(ptr -> rightChild != NULL)
value = max(value, 1 + DoSomething (ptr -> rightChild);
}
}
The value returned by the function DoSomething when a pointer to the root of a non-
empty tree is passed as argument is:
(A) The number of leaf nodes in the tree
(B) The number of nodes in the tree
(C) The number of internal nodes in the tree
(D) The height of the tree
130. GATE (CSE) 2004, Q.44
Suppose we run Dijkstra’s single source shortest path algorithm on the following edge-
weighted directed graph with vertex P as the source.
For More Quality Study Material: www.ErForum.Net
GATE Questions 51
In what order do the nodes get included into the set of vertices for which the shortest
path distances are finalized?
(A) P, Q, R, S, T, U (B) P, Q, R, U, S, T
(C) P, Q, R, U, T, S (D) P, Q, T, R, U, S
131. GATE (CSE) 2004, Q.52
The order of an internal node in a B+ tree index is the maximum number of children it
can have. Suppose that a child pointer takes 6 bytes, the search field takes 14 bytes, and
the block size is 512 bytes. What is the order of the internal node?
(A) 24 (B) 25
(C) 26 (D) 27
132. GATE (CSE) 2004, Q.77
The minimum number of colours required to colour the following graph, such that no
two adjacent vertices are assigned the same colour, is
(A) 2 (B) 3
(C) 4 (D) 5
133. GATE (CSE) 2004, Q.78
Two n bit binary strings S1 and S2, are chosen randomly with uniform probability. The
probability that the hamming distance between these strings (the number of positions
where the two strings differ) is equal to d is
n n
Cd Cd
(A) (B)
2 n
2d
d 1
(C) n (D)
2 2d
134. GATE (CSE) 2004, Q.79
How many graphs on n-labelled vertices exist which have at least (n2 – 3n)/2) edges?
( n^2-3n) / 2
(A) (n^2–n)/2C
(n^2–3n)/2 (B) Â ( n^2-n )
Ck
k =0
n
(C) (n^2–n)/2C
n (D) Â ( n^2-n) / 2
Ck
k =0
For More Quality Study Material: www.ErForum.Net
52 GATE Questions
GATE Questions 53
54 GATE Questions
(A) (B)
(C) (D)
Using Prim’s algorithm to construct a minimum spanning tree starting with node A,
which one of the following sequences of edges represents a possible order in which the
edges would be added to construct the minimum spanning tree?
(A) (E, G), (C, F), (F, G), (A, D), (A, B), (A, C)
(B) (A, D), (A, B), (A, C), (C, F), (G, E), (F, G)
(C) (A, B), (A, D), (D, F), (F, G), (G, E), (F, C)
(D) (A, D), (A, B), (D, F), (F, C), (F, G), (G, E)
For More Quality Study Material: www.ErForum.Net
GATE Questions 55
56 GATE Questions
GATE Questions 57
Í n ˙
Suppose there are Èlog n˘ sorted lists of Í ˙ elements each. The time complexity of
Î log n ˚
producing a sorted list of all these elements is: (Hint: Use a heap data structure)
(A) O(n log log n) (B) Q(n log n)
(C) W(n log n) (D) W(n3/2)
161. GATE (CSE) 2005, Q.81
Statement for Linked Answer Questions 81a & 81b:
Consider the following C function:
double foo (int n) {
int i;
double sum;
if (n = = 0) return 1.0;
else {
sum = 0.0;
for(i = 0; I < n; i++)
sum += foo(i);
return sum;
}
}
58 GATE Questions
having the minimum weight amongst all those edges that have one vertex in X and one
vertex in Y.
(a) The edge e must definitely belong to:
(A) The minimum weighted spanning tree of G
(B) The weighted shortest path from s to t
(C) Each path from s to t
(D) The weighted longest path from s to t
(b) Let the weight of an edge e denote the congestion on that edge. The congestion on
a path is defined to be the maximum of the congestions on the edges of the path.
We wish to find the path from s to t having minimum congestion. Which of the
following paths is always such a path of minimum congestion?
(A) A path from s to t in the minimum weighted spanning tree
(B) A weighted shortest path from s to t
(C) An Euler walk from s to t
(D) A Hamiltonian path from s to t
163. GATE (IT) 2005, Q.12
The numbers 1, 2, …, n are inserted in a binary search tree in some order. In the resulting
tree, the right subtree of the root contains p nodes. The first number to be inserted in the
tree must be
(A) 134 (B) 133
(C) 124 (D) 123
164. GATE (IT) 2005, Q.13
A function f defined on stacks of integers satisfies the following properties.
f(f) = 0 and
f(push(S, i) = max(f(S), 0) + i for all stacks S and integers i.
If a stack S contains the integers 2, –3, 2, –1, 2 in order from bottom to top, what is f(S)?
(A) 6 (B) 4
(C) 3 (D) 2
165. GATE (IT) 2005, Q.14
In depth-first traversal of a graph G with n vertices, k edges are marked as tree edges.
The number of connected components in G is
(A) k (B) k + 1
(C) n – k – 1 (D) n – k
166. GATE (IT) 2005, Q.15
In the following table, the left column contains the names of standard graph algorithms
and the right column contains the time complexities of the algorithms. Match each
algorithm with its time complexity.
For More Quality Study Material: www.ErForum.Net
GATE Questions 59
(A) 1 Æ C, 2 Æ A, 3 Æ B, 4 Æ D
(B) 1 Æ B, 2 Æ D, 3 Æ C, 4 Æ A
(C) 1 Æ C, 2 Æ D, 3 Æ A, 4 Æ B
(D) 1 Æ B, 2 Æ A, 3 Æ C, 4 Æ D
167. GATE (IT) 2005, Q.16
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key
values are integers and the hash function used is key % 10. If the values 43, 165, 62,
123, 142 are inserted in the table, in what location would the key value 142 be inserted?
(A) 2 (B) 3
(C) 4 (D) 6
168. GATE (IT) 2005, Q.50
In a binary tree, for every node the difference between the number of nodes in the left
and right subtrees is at most 2. If the height of the tree is h . 0, then the minimum number
of nodes in the tree is
(A) 2h–1 (B) 2h–1 + 1
(C) 2h–1 – 1 (D) 2h
169. GATE (IT) 2005, Q.51
Let T(n) be a function defined by the recurrence
T(n) = 2T(n/2) + n for n ≥ 2 and
T(1) = 1
Which of the following statements is TRUE?
(A) T(n) = Q(log n) (B) T(n) = Q( n )
(C) T(n) = Q(n) (D) T(n) = Q(n log n)
170. GATE (IT) 2005, Q.52
Let G be a weighted undirected graph and e be an edge with maximum weight in G.
Suppose there is minimum weight spanning tree in G containing edge e. Which of the
following statements is always true?
(A) There exists a cutest in G having all edges of maximum weight.
(B) There exists a cycle in G having all edges of maximum weight.
(C) Edge e can be contained in a cycle.
(D) All edges in G have the same weight.
For More Quality Study Material: www.ErForum.Net
60 GATE Questions
(A) 1, 2, 3, 4, 5, 6, 7 (B) 2, 1, 4, 3, 6, 5, 7
(C) 1, 3, 2, 5, 4, 7, 6 (D) 2, 3, 4, 5, 6, 7, 1
174. GATE (IT) 2005, Q.55
A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed
in preorder and the values in each node printed out, the sequence of values obtained
is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in postorder, the sequence obtained would
be
(A) 8, 7, 6, 5, 4, 3, 2, 1 (B) 1, 2, 3, 4, 8, 7, 6, 5
(C) 2, 1, 4, 3, 6, 7, 8, 5 (D) 2, 1, 4, 3, 7, 8, 6, 5
175. GATE (IT) 2005, Q.56
Let G be a directed graph whose vertex set is the set of number from 1 to 100. There
is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3i. The minimum number
of edges in a path in G from vertex 1 to 100 is:
(A) 4 (B) 7
(C) 23 (D) 99
176. GATE (IT) 2005, Q.58
Let a be an array containing n integers in increasing order. The following algorithm
determines whether there are two distinct numbers in the array whose difference is a
specified number S > 0.
i = 0; j = 1;
while(j < n) {
if (E) j++;
For More Quality Study Material: www.ErForum.Net
GATE Questions 61
62 GATE Questions
GATE Questions 63
Which one of the following cannot be the sequence of edges added, in that order, to a
minimum spanning tree using Kruskal’s algorithm?
(A) (a-b), (d-f), (b-f), (d-c), (d-e) (B) (a-b), (d-f), (d-c), (b-f), (d-e)
(C) (d-f), (a-b), (d-c), (b-f), (d-e) (D) (d-f), (a-b), (b-f), (d-e), (d-c)
188. GATE (CSE) 2006, Q.48
Let T be a depth-first search tree in an undirected graph G. Vertices u and v are leaves
of this tree T. The degrees of both u and v in G are at least 2. Which one of the following
statements is true?
(A) There must exist a vertex w adjacent to both u and v in G
(B) There must exist a vertex w whose removal disconnects u and v in G
(C) There must exist a cycle in G containing u and v
(D) There must exist a cycle in G containing u and v and all its neighbours in G
189. GATE (CSE) 2006, Q.49
An implementation of queue Q, using stacks S1 and S2 is given below:
void insert (Q, x) {
push (S1, x);
}
void delete (Q) {
if (stack-empty (S2)) then
if (stack-empty (S1)) then {
print (“ Q is empty”);
return;
}
else while (! (stack-empty (S1))) then {
x = pop (S1);
push (S2, x);
}
x = pop (S2);
}
64 GATE Questions
Ï1 if i Œ X
x[i] = Ì
Ó0 otherwise
Consider the following algorithm in which x, y and z are boolean arrays of size n:
Algorithm zzz (x[ ], y[ ], z[ ]) {
int I;
for (i = 0; i< n; ++i)
z[i] = x[i] ^ ~ y[i] v (~ x[i] ^ y[i])
}
( )
T(n) = 2T ÈÍ n ˘˙ +1, T(1) = 1
GATE Questions 65
S1: The transformation from work1 to work2 is valid, i.e. for any program state and
input arguments, work2 will compute the same output and have the same effect on
program state as work1
S2: All transformations applied to work1 to get work2 will always improve the
performance (i.e. reduce CPU time) of work2 compared to work1
(A) S1 is false and S2 is false (B) S1 is false and S2 is true
(C) S1 is true and S2 is false (D) S1 is true and S2 is true
For More Quality Study Material: www.ErForum.Net
66 GATE Questions
S1: The compiler will generate code to allocate a temporary nameless cell, initialize it
to 13, and pass the address of the cell to swap
S2: On execution the code will generate a runtime error on line L1
S3: On execution the code will generate a runtime error on line L2
S4: The program will print 13 and 8
S5: The program will print 13 and
(A) S1 and S2 (B) S1 and S4
(C) S3 (D) S1 and S5
197. GATE (CSE) 2006, Q.57
Consider this C code to swap two integers and these five statements: The code
GATE Questions 67
68 GATE Questions
(A) {P, Q, R, S}, {T}, {U}, {V} (B) {P, Q, R, S, T, V}, {U}
(C) {P, Q, S, T, V}, {R}, {U} (D) {P, Q, R, S, T, U, V}
208. GATE (IT) 2006, Q. 47
Consider the depth-first search of an undirected graph with 3 vertices P, Q and R. Let
discovery time d(u) represent the time instant when the vertex u is first visited, and finish
time f(u) represent the time instant when the vertex u is last visited. Given that
d(P) = 5 units f(P) = 12 units
d(Q) = 6 units f(Q) = 10 units
d(R) = 14 units f(R) = 18 units
Which of the following statements is TRUE about the graph?
(A) There is only one connected component
(B) There are connected components, and P and R are connected
For More Quality Study Material: www.ErForum.Net
GATE Questions 69
(A) a = 0, b = 3 (B) a = 3, b = 0
a = 0, b = 3 a = 12, b = 9
(C) a = 3, b = 6 (D) a = 6, b = 3
a = 3, b = 6 a = 15, b = 12
210. GATE (IT) 2006, Q. 51
Which one of the choices given below would be printed when the following program is
executed?
#include<stdio.h>
int a1[] = {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x[] = {a1, a2, a3};
void print( int *a[])
{
For More Quality Study Material: www.ErForum.Net
70 GATE Questions
printf(“%d,”, a[0][2]);
printf(“%d,”, *a[2]);
printf(“%d,”, *++a[0]);
printf(“%d,”, *(++a)[0]);
printf(“%d,”, a[-1][+1]);
}
main( )
{
print(x);
}
(A) 8, –12, 7, 23, 8 (B) 8, 8, 7, 23, 7
(C) –12, –12, 27, –31, 23 (D) –12, –12, 27, –31, 56
211. GATE (IT) 2006, Q. 52
Ê mˆ
The following function computes the value of Á ˜ correctly for all legal values m and
Ë n¯
n (m ≥ 1, n ≥ 0 and m > n)
int func( int m, int n)
{
if (E) return 1;
else return (func(m-1, n) + func(m-1, n-1));
}
GATE Questions 71
72 GATE Questions
The number of comparisons made in the execution of the loop for any n > 0 is:
(A) Èlog2 n˘ + 1 (B) n
(C) Èlog2 n˘ (D) Îlog2 n˚ + 1
221. GATE (CSE) 2007, Q.38
The following postfix expression with single digit operands is evaluated using a stack:
823^/23*+51*–
Note that ^ is the exponentiation operator. The top two elements of the stack after the
first *is evaluated are:
(A) 6, 1 (B) 5, 7
(C) 3, 2 (D) 1, 5
222. GATE (CSE) 2007, Q.39
The inorder and preorder traversal of a binary tree are
d b e a f c g and a b d e c f g, respectively.
The postorder traversal of the binary tree is
(A) d e b f g c a (B) e d b g f c a
(C) e d b f g c a (D) d e f g b c a
223. GATE (CSE) 2007, Q.40
Consider a hash table of size seven, with starting index zero, and a hash function (3x +
4) mod 7. Assuming the hash table is initially empty, which of the following is the
contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed
hashing? Note that – denotes an empty location in the table.
(A) 8, –, –, –, –, –, 10 (B) 1, 8, 10, –, –, –, 3
(C) 1, –, –, –, –, –, 3 (D) 1, 10, 8, –, –, –, 3
224. GATE (CSE) 2007, Q.41
In an unweighted, undirected connect graph, the shortest path from a node S to every
node is computed most efficiently, in terms of time complexity, by
(A) Dijkstra’s algorithm starting from S.
(B) Warshall’s algorithm.
(C) Performing a DFS starting from S.
(D) Performing a BFS starting from S.
225. GATE (CSE) 2007, Q.42
Consider the following C function:
int f(int n)
{
static int are = 0;
If (n < = 0) return 1;
If (n > 3)
{ r = n;
For More Quality Study Material: www.ErForum.Net
GATE Questions 73
return f (n – 2) + 2;
}
return f(n – 1) + r;
}
74 GATE Questions
The value returned by GetValue when a pointer to the root of a binary tree is passed as
its argument is:
(A) The number of nodes in the tree
(B) The number of internal nodes in the tree
(C) The number of leaf nodes in the tree
(D) The height of the tree.
230. GATE (CSE) 2007, Q.47
Consider the process of inserting an element into a Max Heap, where the Max Heap is
represented by an array. Suppose we perform a binary search on the path from the new
leaf to the root to find the position for the newly inserted element, the number of
comparisons performed is:
(A) Q(log2 n) (B) Q(log2 log2 n)
(C) Q(n) (D) Q(n log2 n)
231. GATE (CSE) 2007, Q.49
Let w be the minimum weight among all edge weights in an undirected connected graph.
Let e be a specific edge of weight w. Which of the following is FALSE?
(A) There is a minimum spanning tree containing e.
(B) If e is not in a minimum spanning tree T, then in the cycle formed by adding e to
T, all edges have the same weight.
(C) Every minimum spanning tree has an edge of weight w.
(D) e is present in every minimum spanning tree.
232. GATE (CSE) 2007, Q.50
An array of n numbers is given, where n is an even number. The maximum as well as
the minimum of these n numbers needs to be determined. Which of the following is
TRUE about the number of comparisons needed?
(A) At least 2n – c comparisons, for some constant c, are needed.
(B) At least 1.5n – 2 comparisons are needed.
(C) At least n log2 n comparisons are needed.
(D) None of the above.
For More Quality Study Material: www.ErForum.Net
GATE Questions 75
Let T(n) denote the number of times the for loop is executed by the program on input
n. Which of the following is TRUE?
(A) T(n) = O ( n ) and T(n) = W ( n )
(B) T(n) = O ( n ) and T(n) = W(1)
(C) T(n) = O(n) and T(n) = W ( n )
(D) None of the above.
Statement for Linked Answer Questions 84 & 85
Suppose that a robot is placed on the Cartesian plane. At each step it is allowed to move either
one unit up or right, i.e., if it is at (i, j) then it can move to either (i + 1, j) or (i, j +1).
234. GATE (CSE) 2007, Q.84
How many distinct paths are there for the robot to reach the point (10, 10) starting from
the initial position (0,0)?
Ê 20 ˆ
(A) Á ˜ (B) 220
Ë10 ¯
(C) 210 (D) None of the above
235. GATE (CSE) 2007, Q.84
Suppose that the robot is not allowed to traverse the line segment from (4, 4) to (5, 4).
With this constraint, how many distinct paths are there for the robot to reach (10, 10)
starting from (0, 0)?
(A) 29 (B) 219
Ê 8 ˆ Ê 11ˆ Ê 20 ˆ Ê 8 ˆ Ê11ˆ
(C) Á ˜ ¥ Á ˜ (D) Á ˜ - Á ˜ ¥ Á ˜
Ë 4¯ Ë 5 ¯ Ë 10 ¯ Ë 4¯ Ë 5 ¯
76 GATE Questions
where Ti is the completion time of job Ji. Assuming that there is only one processor
available, in what order must the job be executed in order to minimize the weighted
mean completion time of the jobs?
(A) Non-decreasing order of ti
(B) Non-increasing order of wi
(C) Non-increasing order of witi
(D) Non-increasing order of with/ti
238. GATE (IT) 2007, Q.27
The function f is defined as follows:
int f(int n) {
if (n <= 1) return 1;
else if (n % 2 = =) return f(n/2));
else return f(3n – 1);
}
Assuming that arbitrarily large integers can be passed as a parameter to the function,
consider the following statements.
(i) The function f terminates for finitely many different values of n ≥ 1.
(ii) The function f terminates for infinitely many different values of n ≥ 1.
(iii) The function f does not terminate for finitely many different values of n ≥ 1.
(iv) The function f does not terminate for infinitely many different values of n ≥ 1
Which one of the following options is true of the above?
(A) (i) and (iii) (B) (i) and (iv)
(C) (ii) and (iii) (D) (ii) and (iv)
239. GATE (IT) 2007, Q.28
Consider a hash function that distributes keys uniformly. The hash table size is 20. After
hashing of how many keys will the probability that any new key hashed collides with
an existing one exceed 0.5.
(A) 5 (B) 6
(C) 7 (D) 10
240. GATE (IT) 2007, Q.29
When searching for the key value 60 in a binary search tree, nodes containing the key
values 10, 20, 40, 50, 70, 80, 90 are traversed, not necessarily in the order given. How
For More Quality Study Material: www.ErForum.Net
GATE Questions 77
many different orders are possible in which these key values can occur on the search
path from the root node containing the value 60?
(A) 35 (B) 64
(C) 128 (D) 5040
241. GATE (IT) 2007, Q.30
Suppose you are given an implementation of a queue of integers. The operations that can
be performed on the queue are:
isEmpty(Q) — returns true if the queue is empty, false otherwise.
delete(Q) — deletes the element at the front of the queue and returns its value.
insert(Q, i) — inserts the integer i at the rear of the queue.
Consider the following function:
void f(queue Q)
{
int i;
if(!isEmpty (Q)) {
i = delete(Q);
f(Q)
insert(Q, i);
}
}
78 GATE Questions
push(r);
}
else if (c != ‘ ‘)
flagError( );
}
printf(“%c”, pop( ));
}
GATE Questions 79
(A) 1 (B) 2
(C) 3 (D) 4
245. GATE (IT) 2007, Q.85
Now the keys K50 are deleted from the B+ tree resulting after the two insertions made
earlier. Consider the following statements about the B+ tree resulting after this deletion.
(i) The height of the tree remains the same.
80 GATE Questions
(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
249. GATE (CSE) 2008, Q.20
The data blocks of a very large file in the Unix file system are allocated using
(A) contiguous allocation
(B) linked allocation
(C) indexed allocation
(D) an extension of indexed allocation
250. GATE (CSE) 2008, Q.23
Which of the following statements is true for every planar graph on n vertices?
(A) The graph is connected.
(B) The graph is Eulerian.
(C) The graph has a vertex-cover of size at most 3n/4.
(D) The graph has an independent set of size at least n/3.
251. GATE (CSE) 2008, Q.27
Aishwarya studies either computer science or mathematics everyday. If she studies
computer science on a day, then the probability that she studies mathematics the next day
is 0.6. If she studies mathematics on a day, then the probability that she studies computer
science the next day is 0.4. Given that Aishwarya studies computer science on Monday,
what is the probability that she studies computer science on Wednesday?
(A) 0.24
(B) 0.36
(C) 0.40
(D) 0.60
252. GATE (CSE) 2008, Q.39
Consider the following functions:
f(n) = 2n
g(n) = n!
h(n) = nlog n
For More Quality Study Material: www.ErForum.Net
GATE Questions 81
Which of the following statements about the asymptotic behaviour off(n), g(n), and h(n)
is true?
(A) f(n) = O(g(n)); g(n) = O(h(n))
(B) f(n) = W(g(n)); g(n) = O(h(n))
(C) g(n) = O(f(n)); h(n) = O(f(n))
(D) h(n) = O(f(n)); g(n) = W(f(n))
253. GATE (CSE) 2008, Q.40
The minimum number of comparisons required to determine if an integer appears more
than n/2 times in a sorted array of n integers is
(A) Q(n)
(B) Q(log n)
(C) Q(log* n)
(D) Q(1)
254. GATE (CSE) 2008, Q.41
A B-tree of order 4 is built from scratch by 10 successive insertions. What is the
maximum number of node splitting operations that may take place?
(A) 3
(B) 4
(C) 5
(D) 6
255. GATE (CSE) 2008, Q.42
G is a graph of n vertices and 2n – 2 edges. The edges of G can be partitioned into two
edge-disjoint spanning trees. Which of the following is NOT true for G?
(A) For every subset of k vertices, the induced subgraph has at most 2k – 2 edges.
(B) The minimum cut in G has at least two edges.
(C) There are two edge-disjoint paths between every pair of vertices.
(D) There are two vertex-disjoint paths between every pair of vertices.
256. GATE (CSE) 2008, Q.43
Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot
element which splits the list into two sub-lists each of which contains at least one-fifth
of the elements. Let T(n) be the number of comparisons required to sort n elements. Then
(A) T(n) £ 2T(n/5) + n
(B) T(n) £ T(n/5) + T(4n/5) + n
(C) T(n) £ 2T(4n/5) + n
(D) T(n) £ 2T(n/2) + n
For More Quality Study Material: www.ErForum.Net
82 GATE Questions
Dijkstra’s single source shortest path algorithm when run from vertex a in the above
graph, computes the correct shortest path distance to
(A) only vertex a
(B) only vertices a, e, f, g, h
(C) only vertices a, b, c, d
D) all the vertices
258. GATE (CSE) 2008, Q.46
You are given the postorder traversal, P, of a binary search tree on the n elements
1, 2, ..., n. You have to determine the unique binary search tree that has P as its
postorder traversal. What is the time complexity of the most efficient algorithm for doing
this?
(A) Q(log n)
(B) Q(n)
(C) Q(n log n)
(D) none of the above, as the tree cannot be uniquely determined.
259. GATE (CSE) 2008, Q.47
We have a binary heap on n elements and wish to insert more elements (not necessarily
one after another) into this heap. The total time required for this is
(A) Q(log n)
(B) Q(n)
(C) Q(n log n)
(D) Q(n2)
260. GATE (CSE) 2008, Q.62
The following C function takes a singly-linked list of integers as a parameter and
rearranges the elements of the list. The function is called with the list containing the
integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after
the function completes execution?
struct node {
int value;
struct node *next;
};
void rearrange (struct node *list) {
For More Quality Study Material: www.ErForum.Net
GATE Questions 83
84 GATE Questions
GATE Questions 85
(A) 2
(B) 3
(C) 4
(D) 5
269. GATE (IT) 2008, Q.12
Which of the following is TRUE?
(A) The cost of searching an AVL tree is q (log n) but that of a binary search tree is O(n).
(B) The cost of searching an AVL tree is q (log n) but that of a complete binary tree is
q (n log n).
(C) The cost of searching a binary search tree is O(log n) but that of an AVL tree is q(n).
(D) The cost of searching an AVL tree is q(n log n) but that of a binary search tree is
O(n).
270. GATE (IT) 2008, Q.23
What is the probability that in a randomly chosen group of r people at least three people
have the same birthday?
For More Quality Study Material: www.ErForum.Net
86 GATE Questions
(A) n (log n + 1)
(B) n log n
(C) n log n
(D) n log n
274. GATE (IT) 2008, Q.45
For the undirected, weighted graph given below, which of the following sequences of
edges represents a correct execution of Prim’s algorithm to construct a Minimum
Spanning Tree?
For More Quality Study Material: www.ErForum.Net
GATE Questions 87
(A) (a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
(B) (c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
(C) (d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
(D) (h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
275. GATE (IT) 2008, Q.46
The following three are known to be the preorder, inorder and postorder sequences of
a binary tree. But it is not known which is which.
I. MBCAFHPYK
II. KAMCBYPFH
III. MABCKYFPH
Pick the true statement from the following.
(A) I and II are preorder and inorder sequences, respectively.
(B) I and III are preorder and postorder sequences, respectively.
(C) II is the inorder sequence, but nothing more can be said about the other two
sequences.
(D) II and III are the preorder and inorder sequences, respectively.
276. GATE (IT) 2008, Q.47
Consider the following sequences of nodes for the undirected graph given below.
I. a b e fdgc
II. a b e fcgd
III. a d g ebcf
IV. a d b cgef
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they
are first visited. Which all of the above is (are) possible output(s)?
For More Quality Study Material: www.ErForum.Net
88 GATE Questions
GATE Questions 89
90 GATE Questions
GATE Questions 91
Which one of the following is NOT the sequence of edges added to the minimum
spanning tree using Kruskal’s algorithm?
(A) (b, e) (e, f) (a, c) (b, c) (f, g) (c, d)
(B) (b, e) (e, f) (a, c) (f, g) (b, c) (c, d)
(C) (b, e) (a, c) (e, f) (b, c) (f, g) (c, d)
(D) (b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
291. GATE (CS&IT) 2009, Q.39
In quick sort, for sorting n elements, the (n/4)th smallest element is selected as pivot
using an O(n) time algorithm. What is the worst case time complexity of the quick sort?
(A) q(n)
(B) q(n log n)
(C) q(n2)
(D) q(n2 log n)
292. GATE (CS&IT) 2009, Q.44
The following key values are inserted into a B+-tree in which order of the internal nodes
is 3, and that of the leaf nodes is 2, in the sequence given below. The order of internal
nodes is the maximum number of tree pointers in each node, and the order of leaf nodes
is the maximum number of data items that can be stored in it. The B+-tree is initially
empty.
10, 3, 6, 8, 4, 2, 1
For More Quality Study Material: www.ErForum.Net
92 GATE Questions
The maximum number of times leaf nodes would get split up as a result of these
insertions is
(A) 2
(B) 3
(C) 4
(D) 5
Statement for Linked Answer Questions 59 and 60:
Consider a binary max-heap implemented using an array.
293. GATE (CS&IT) 2009, Q.59
Which one of the following array represents a binary max-heap?
(A) {25, 12, 16, 13, 10, 8, 14}
(B) {25, 14, 13, 16, 10, 8, 12}
(C) {25, 14, 16, 13, 10, 8, 12}
(D) {25, 14, 12, 13, 10, 8, 16}
294. GATE (CS&IT) 2009, Q.60
What is the content of the array after two delete operations on the correct answer to the
previous question?
(A) {14, 13, 12, 10, 8}
(B) {14, 12, 13, 8, 10}
(C) {14, 13, 8, 12, 10}
(D) {14, 13, 12, 8, 10}
295. GATE (CS&IT) 2010, Q.01
GATE Questions 93
94 GATE Questions
GATE Questions 95
96 GATE Questions
Which one of the following choices gives a possible order in which the key values could
have been inserted in the table?
(A) 46, 42, 34, 52, 23, 33
(B) 34, 42, 23, 52, 33, 46
(C) 46, 34, 42, 23, 52, 33
(D) 42, 46, 33, 23, 34, 52
306. GATE (CS&IT) 2010, Q.53
How many different insertion sequences of the key values using the same hash function
and linear probing will result in the hash table shown above?
(A) 10
(B) 20
(C) 30
(D) 40