CS GATE Solution 2001-2010
CS GATE Solution 2001-2010
com
YEAR 2001
Question. 1
(C) 0 (n )
(B) 0 (n log n)
(D) 0 (n!)
SOLUTION
(D)
(i + 1)
2
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
2j = i
j =i
2
So
2j + 1 = i
j = i1
2
j = bi l
2
But g (n) =
Y 0 (f (n))
Hence (A) is correct option.
Question. 4
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
(C) n!
(D) 2
SOLUTION
Given n vertices the various cases which are possible, no. connection,
1 connection it can be selected nc2 ways, 2 connections & then (n 1)
connections to make complete graph.
(2)
c2
n (n 1)
2
=2
(D) Four
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Question. 7
(B)
k
(C) 3 log 2
(2k + 1 1)
2
k
(D) 2 log 3
SOLUTION
Given recursion
T (2k ) = 3T (2k 1) + 1 given T (1) = 1
Putting k = 1
T (2) = 3T (2c) + 1 = 3 # 1 + 1 = 4
k = 2 T (4) = 3T (2) + 1 = 3 # 4 + 1 = 13
k = 3 T (8) = 3T (4) + 1 = 39 + 1 = 40
This sequence of values can be obtained putting k = 1, 2 & 3 . in
(3k + 1 1)
T (k) =
2
Hence (B) is correct option.
Page 4
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Question. 8
(B) 3
(C) 4
(D) n 2 9n C + 2
2
SOLUTION
Consider a cycle.
Question. 9
(B) n
2
(D) n
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Question. 10
(D)
(n + 1) (n)
2
SOLUTION
n =4
4#3 = 6
2
Hence (B) is correct option.
Question. 11
The number of leaf nodes in a rooted tree of n nodes, with each node
having 0 or 3 children is :
(n 1)
(A) n
(B)
3
2
(C)
(n 1)
2
SOLUTION
Page 6
(D)
(2n + 1)
3
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
n =4
2n + 1 = 3
3
No. of leaf = 3
Hence (D) is correct option.
Question. 12
(D) n
2
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
If n <= 2 return (1) else return (A (^ n h));
Is best described by
(A) 0 (n)
(B) 0 (log n)
(C) 0 (loglog n)
(D) 0 (1)
SOLUTION
Question. 14
(B) log 43 n
(C) log 3 n
(D) log 23 n
SOLUTION
log 3 12 , 4
Page 8
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Height = 4
So
log 2 n
In this tree at every node no. of children nodes in left & right subtree
follows all properties required & height given by log 2 n .
Hence (A) is correct option.
Question. 15
(D) 1, 2 and 3
SOLUTION
correct
correct
Page 9
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(3)
(22 ) =
Y (2n)
incorrect
SOLUTION
DFS traversal takes the path to the end & then move to other branch.
Page 10
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
Binary search is efficient when the sorted sequence is there, but the
worst case scenario for insertion sort would not be sorted sequence
so even using binary search instead of linear search the complexity of
comparisons will remain (n2).
Question. 19
In a heap with n elements with the smallest element at the root, the
7th smallest element ban be found in time
Page 11
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(A) (n log n)
(B) (n)
(C) (log n)
(D) H (1)
SOLUTION
Here we can follow simple procedure, we can rum heap sort for 7
iterations. In each iteration the top most element is smallest, we note
& then replace it with the last element, then we run min heapify
algorithm, which brings next smallest element on top. This procedure
take 0 (log n) time.
We need to run it for 7 times. So tight bound (7 log n) = (log n)
Hence option (C) is correct.
(D) 2n [log2 n]
SOLUTION
n (n 1)
4
www.gatehelp.com
If n = 3 &
CS Topicwise 2001-2010
Algorithms
3 (3 1)
= [ 1. 5] , 2
4
What would be the worst case time complexity of the insertion Sort
algorithm, if the inputs are restricted to permutations of 1....n with
at most n inversions?
(B) (n log n)
(A) (n2)
(C) (n1.5)
(D) (n)
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
0 (log n) m since K < m, K > 0, m > 0.
m is the cube root, since we are doing in binary so we take K .
Hence (C) is correct option.
Question. 23
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(C) If (b, d) not present then G1 is not a clique.
(D) G1 cant be a tree since multiple connections between vertices.
Hence (B) is correct option.
Question. 24
(A) 29
(B) 31
(C) 38
(D) 41
SOLUTION
min = (a, c) = 1
min = (a, d) = 2
{(a, b), (a, e), (c, d), (b, d), (d, h)}
min = (b, d) = 3
min = (b, g) = 2
{(a, b), (a, e), (d, h), (g, h), (g, j), (g, i)}
(g, h) = 8
{(a, e), (d, h), (g, j), (g, i), (h, i), (h, f), (e, h)}
(h, i) = 4
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h) (e, i), (f, i), (j, i)}
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h), (f, i), (j, i), (e, f)}
{(a, e), (d, h), (g, j), (g, i), (e, h), (f, i), (j, i), (e, f)}
8
15 19 14
8
9
5 11
min = (e, i) = 2
=4
(j, i) = 5
Page 15
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Sum 1 + 2 + 3 + 2 + 8 + 4 + 2 + 4 + 5
= 31
Hence (B) is correct option.
Question. 25
(B) 4
(C) 5
(D) 6
SOLUTION
Sequence
as bs cs ae ds ce es fs be de gs ee fe hs ge he
No. of rooms 0 1 2 3 2 3 2 3 4 3 2 3 2 1 2 1 0
Maximum no. of rooms required at a time = 4 option (B).
Here the logic is very simple increase the no. of room if some activity
start & decrease by 1 if activity ends.
Question. 26
i k
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
R0 1 1V
W
S
S0 0 1W
SS0 0 0WW
X
T
We can see in this example
Hence (D) is correct option.
YEAR 2004
Question. 27
Level order traversal of a rooted tree can be done by stating from the
root and performing
(A) preorder traversal
Page 17
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
(B) 2 only
SOLUTION
Page 18
(D) n log2 n
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
Sorting worst case occurs when arrays are reverse sorted, we need to
select every element once & for every element min no. of comparison
might be log 2 n .
So overall min. complexity 0 (n log n)
Hence (C) is correct option.
Question. 30
(B) 2 and 3
(C) 3 only
(D) 4 only
SOLUTION
For a tree we not only require in order & preorder but also post order
traversal.
Preorder & post order help to determine the roots of binary subtrees,
inorder arranges those roots in order.
Hence (B) is correct option.
Question. 31
Page 19
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
SOLUTION
Membership & cardinality functions takes constt. time i.e. 0(1), but
union & intersection require emparison of 1 element with all the
other elements so these two would be slowest.
Hence (D) is correct option.
Question. 33
In what order do the nodes get included into the set of vertices ofr
which the shortest path distances are finalized?
(B) P, Q, R, U, S, T
(A) P, Q, R, S, T, U
Page 20
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(C) P, Q, R, U, T, S
(D) P, Q, T, R, U, S
SOLUTION
Vertex
I(P)
II
III
IV
VI
;
for
n;
{if
counter++
i
else{f(counter); counter ;}
}
The complexity of this program fragment is
(A) (n2)
(C) (n)
(D) o (n)
Page 21
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
Here the fragment of code contains for loop which goes from 1 to n .
Since due to given conditions m < n .
So complexity of code is 6 (n)
Hence (C) is correct option.
Question. 35
1));
(D) O (2n)
(C) O (n2)
SOLUTION
Question. 36
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
T (n) = 2T (n 1) + n, n # 2
evaluates to
(A) 2n + 1 n 2
(B) 2n n
(C) 2n + 1 2n 2
(D) 2n + n
SOLUTION
Given recurrence.
T (n) = 2T (n 1) + n for n $ 2
Initially T (1) = 1
T (2) = 2T (1) + 2
= 2:1+2 = 4
T (3) = 2T (2) + 3
= 2 : 22 + 3
= 2 : 4 + 3 = 11
T (n 1) = 2T (n 2) + n
= 2n (n 1) 2
So
T (n) = 2n + 1 n 2
Hence (A) is correct option.
Question. 37
(B) O (n log n)
(C) O (n) 2
(D) O (2n)
SOLUTION
The function g (x) calculates for a node x min no. of leaf noes whether
in left subtree or right subtree. The for balanced BST. The no. of
inner nodes = leaf nodes 1
So this loop will sun for max n-times so complexity is 6 (n)
Hence ( ) is correct option.
Page 23
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
YEAR 2005
Question. 38
So on.
Hence (C) is correct option.
Page 24
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Question. 39
(B) O (n log n)
(C) O (n3/2)
(D) O (n3)
SOLUTION
(B) 10, 8, 7, 2, 3, 1, 5
(C) 10, 8, 7, 1, 2, 3, 5
(D) 10, 8, 7, 3, 2, 1, 5
SOLUTION
Page 25
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
How many distinct binary search trees can be created out of 4 distinct
keys?
(A) 5
(B) 14
(C) 24
(D) 35
SOLUTION
The formulae for getting no. of different BST for n distinct keys is
given by.
1 2nC
n+1 n
Here
n =4
8
= 1 C4
5
= 1#8#7#6#5
5
4#3#2
= 14
So 14 distinct BST are possible
Hence (B) is correct option.
Question. 42
Page 26
(A) n k
(B) (n 1) k + 1
(C) n (k 1) + 1
(D) n (k 1)
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
SOLUTION
Given recurrence.
T (n) 2T (n/2) + n
Initially T (0) = T (1) = 1
Comparing with masters theorem
T (n) = aT (n/b) + f (n)
a = 2 b = 2 logb a = 1 f (n) = n
a
n logb = n
a
n logb = f (n)
So case II of Master theorem is applied which says.
T (n) = 6 (f (n) log n logba)
= 6 (n log n)
Hence (B) is correct option.
Question. 44
(B) O (| E |) +| V | log | V |)
(C) O (| V | log | V |)
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
Suppose there are log n sorted lists of n/ log n elements each. The
time complexity of producing a sorted list of all these elements is:
(Hint: Use a heap data structure)
(B) (n log n)
(A) O (n loglogn)
(C) (n log n)
(D) (n3/2)
SOLUTION
There are log n sorted lists, with n elements each, total elements
log n
n . We need to merge these heap & procedure sorted. Merging take.
log n time & soting takes 0 (n log n).
Overall to produce sorted result take 0 (n loglog n)
Hence (A) is correct option.
Page 28
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Question. 46
(B) O (n)
(C) O (n!)
(D) O (nn)
SOLUTION
We need to store largest variables double sum. The function foo() has
recursive calls n times.
For every recursion we need 1 sum variable, size of largest double
would be 1 : 2 : 3 : ........n = n!
So complexity 0 (n!)
This factorial is the no. of sub recursions in every recursion
Hence (C) is correct option.
Question. 47
The space complexity of the above function is foo O and store the
values of foo (i), 0 <= i < n, as and when they are computed. With
this modification, the time complexity for function fooO is significantly
reduced. The space complexity of the modified function would be:
(A) O (1)
2
(C) O (n )
(B) O (n)
(D) O (n!)
SOLUTION
Here we store values in foo(i ) only when they are completed then in
every recursion we require space to store 1 double.
So overall n calls we require 0 (n)
Hence (B) is correct option.
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Task
T1
T2
Profit
15
20
Deadline
T3
T4
T5
T6
T7
T8
T9
18
18
10
23
16
25
30
5
Question. 48
Are all tasks completed in the schedule that gives maximum profit?
(A) All tasks are completed
SOLUTION
Profi15t
23
Deadtime
Time
20 25 18 18
30
10
16
15
4
3
5
4
23
20
25
18
30
16
15
SUM
147
So here T4 & T6 not selected.
Hence (D) is correct option.
Question. 49
(B) 165
(C) 167
(D) 175
SOLUTION
Solving from the some algorithm solved in previous question the sum
Page 30
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
(B) 4
(C) 6
(D) 9
SOLUTION
P (x) a 0 + a1 x + a2 x2 + a 3 x3
We can reduce the no. of multiplications using Horners rule.
= a 0 + (a1 + (a 3 x + a2) x) x
P (x)
.
. .
(1) (2) (3)
So min = 3
Hence (A) is correct option.
Question. 51
(B) (log n)
(D) (1)
SOLUTION
Consider a weighted complete graph G on the vertex set {v1, v2,....... vn}
Page 31
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
such that the weight of the edge (vi, vj ) is 2 | i j |. The weight of a
minimum spanning tree of G is
(B) 2n 2
(A) n 1
(C) b n l
(D)
2
SOLUTION
(D) B-Tree
SOLUTION
www.gatehelp.com
(A) log2 n
(B) n
(C) 2n + 1
(D) 2n
CS Topicwise 2001-2010
Algorithms
SOLUTION
Right child & left child of element X [i] are shared in array at X [2i + 1]
& X [2i] respectively & index is at X [1] & X [2] & X [3] are its child.
So till index 3 we stored 3 elements & so on.
So we require the array of size n to store n elements.
Hence (B) is correct option.
Question. 55
SOLUTION
SOLUTION
Here after every iteration the value of i = i/2 , & j is the summation
Page 33
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
of these i till i reaches to 1.
n
In quick sort (divide & conquer) algorithm after every run we being
1 element at its right place i.e. all the elements in the left are smaller
& in the right are greater than it.
So we can apply quick sorts divide & conquer method of complexity
0 (n log n) to do this, to check whether all elements in right are smaller
than it or not.
Hence (C) is correct option.
Question. 58
Page 34
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
(B) (a-b), (d-f), (d-c), (d-f), (d-e), (d,c) & (b,f) has same weight so
correct.
(C) (d-f), (a-b), (d-c), (d-f), (d-e) possible
(D) (d-f), (a-b), (b-f), (d-e) (d-c).
(b-f) has weight = 2
(d-e) has weight = 3
(d-c) has weight = 2
So (d-e) cant be taken before (d-c)
So (d) is incorrect.
Hence (D) is correct option.
Question. 59
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
(D) (X Y) , (Y X)
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(x + y') , (x' + y)
This can be written as.
(x y) , (y x)
Hence (D) is correct option.
Question. 61
(C) T (n) = ( n )
SOLUTION
Given recurrence
T (n) = 2T ([ n ]) + 1
Initially
T (1) = 1
Solving it by method of change of variables
Let m = log n2
So
n = 2m
Putting in equation (1)
T (2m) = 2T (2m/2) + 1
This can be re-written as.
S(m) = 2T (m/2) + 1
Solving this by Masters method
Comparing T (n) = aT (n/b) + f (n)
a
2
So n logb = n log 2 = nc = 1 = f (n)
So case (2) applies.
5 (m) = log m
Putting m from equation (2)
T (n) = loglog n
T (n) = 0 (loglog n)
Hence (A) is correct option.
(1)
(2)
Question. 62
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(A) (n)
(B) (n log n)
(C) (n )
(D) (n3)
SOLUTION
In quick sort the piuot is found in log n time & this runs for n times.
So complexity of Quick sort is 0 (n log n) but since given the median
as piuot found in 0 (n)
So for n elements to sort this algorithm will take 0 (n2)
Hence (C) is correct option.
Question. 63
Given two arrays of numbers a1 .......an and b1,..... bn where each number
is 0 or 1, the fastest algorithm to find the largest span (i, j) such that
ai + + ai + 1 + ...... + aj = bi + bi + 1 + ...... + bj , or report that there is no
such span,
(A) Takes O (3n) and (2n) time if hashing is permitted
(B) Takes O (n3) and W (n2.5) time in the key comparison model
(C) Takes (n) time and space
(D) Takes O ( n ) time only if the sum of the 2n elements is an even
number
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
call swap
a
print*,ia, i
end
S1: The complier 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 1.1
S3: On execution the code will generate a runtime error on line 1.2
S4: The program will print 13 and 8
S5: The program will print 13 and-2
Exactly the following set of statement (s) is correct:
(A) S1 andS2
(B) S1 and S4
(C) S3
(D) S1 amd S5
SOLUTION
Question. 65
(B) 2h 1 1
(C)2h + 1 1
(D) 2h + 1
Page 39
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
Tree of height
0
1
1
3
3
15
Hence (C) is correct option.
22 1
23 1
2h + 1 1
Question. 66
The maximum number of binary trees that can be formed with three
unlabeled nodes is
(A) 1
(B) 5
(C) 4
(D) 3
SOLUTION
Mathematically
No of binary trees =
1 2nC
n+1 n
Here n = 3
6
= 1 # C3
4
= 1 # 6 # 5 # 4 = 5 trees
3#2
4
Hence (B) is correct option.
Page 40
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Question. 67
SOLUTION
The complexities of worst case when all the elements are reverse
sorted for all algorithms are.
Norge
0 (n log 2 n)
Quick
0 (n2)
Selection
0 (n2)
Bubble
0 (n2)
Merge no has no effect of input nature since it keeps on dividing into
2 problems of size 4/2 so complexity is lower then other three.
Hence (A) is correct option.
Question. 68
(B) edbgfca
(C) edbfgca
(D) defgbca
SOLUTION
In order d b e a f c g
preorder a b d e c f g
1st element of pre order is root
from inorder
in preorder b is before d e . & c is before f g .
Page 41
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
deb f gca
Hence (A) is correct option.
Question. 69
Consider the hash table of size seven, with starting index zero, and a
has function (3x + 4) and 7. Assuming the has 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
SOLUTION
Hash table
Inputs.
3X+4 mod 7
mod 7
10
13
mod 7
28
mod 7
10
34
mod 7
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
(D) 6
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
return m;
if
n
n m;
return gcd m n ;
}
How many recursive calls are made by this function?
(A) (log2 n)
(B) (n)
(D) ( n )
SOLUTION
n
return 1;
else
return(DoSomething(floor(sqrt(n))
)+
n);
}
(A) (n )
(B) (n log2 n)
(C) (log2 n)
SOLUTION
T (n) = T ( n ) + n
Here
eg n = 16
n = 4 n = 2 so
Recursion tree
Page 44
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Question. 74
(D) (n log2 n)
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(C) Every minimum spanning tree has an edge of weight w
(D) e is present in every minimum spanning tree
SOLUTION
One possible way to do this is we select first element as max & also
min. Then we compare it with all others. At most this would take 2n
comparisons during linear search.
But if we use divide & conquer as for merge sort we have.
T (n) 2T (n/2) + 2 for n > 2
Its solution
n logb a = nc = 1 f (n) > n logb a so case 3.
Page 46
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
T (n) = 3n 2
2
= 1.5n 2
Hence (B) is correct option.
Question. 77
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) + ( n )
(B) T (n) = O ( n ) and T (n) + (1)
(C) T (n) = O (n) and T (n) = ( n )
(D) None of these
SOLUTION
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Question. 78
.25
.25
.125
.0625
.01325
Page 48
www.gatehelp.com
a
b
c
d
e
CS Topicwise 2001-2010
Algorithms
=0
= 10
= 110
= 1110
= 1111
(B) 2.1875
(C) 2.25
(D) 1.781
SOLUTION
1/2
1/2
b"2
1/4
1/2
c"3
1/8
3/8
d"4
1/16
1/4
e"4
1/32
1/8
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
= 4+4+3+2+1
8
= 14
8
= 1.781
Hence (D) is correct option.
YEAR 2008
Question. 80
(B) (m)
(C) (m + n)
(D) (mn)
SOLUTION
The Breadth First Search algorithm has been implemented using the
queue data structure. One possible order of visiting the nodes of the
following graph is
Page 50
www.gatehelp.com
(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
CS Topicwise 2001-2010
Algorithms
SOLUTION
BFS : Here for every node we visit all its neighbours & then the
neighbours of its neighbours.
We use queue to find this.
Start from M" M " N " O " P " Q " R
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
(A) f (n) = O (g (n)); g (n) = O (h (n))
(B) f (n) = (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) = (f (n))
SOLUTION
The asymptotic order. 1 < loglog n < log n < ne < nc < n log n < cn < nn
n
< cc < n!
f (n) = 2n g (n) = nn h (n) = n logn from order h (n) < f (n) < g (n)
(B) (log n)
(C) (log * n)
(D) (1)
SOLUTION
Since all the elements are sorted so we can apply binary search here
efficiently. In BS the size of array required to compare reduces by n/2
in every iteration.
Here since the sequence is sorted so the same element would come
consecutively
Page 52
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
eg n = 10
=122222468
= 2 correct
= 2 correct
= 2 correct
6log 2 10@ = 3
(log n)
Hence (B) is correct option.
Question. 84
(D) 6
SOLUTION
In B tree the data is stored at leaves only a particular node can have
maximum. 3 keys, so when 4th insertion comes first split is required,
during 7th second split & so on, so for 10 insertions max. 3 splits are
required.
We can prove it mathematically.
No. of split # 1 + log m/2 an k
b
Here m order = 4 n = 10 b = 3
K # 1 + log 2 b10 l & 1 + log 24
3
K #B
Hence (A) is correct option.
Question. 85
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
2k 2 edges.
(B) The minimum cut in G has a least two edges
(C) There are two edges-disjoint paths between every pair of vertices
(D) There are two vertex-disjoint paths between every pair of vertices.
SOLUTION
min cent
has 3 edges.
Two edge & vertex disjoint paths are present can be seen in two
spanning trees but option (A) is false for K = 2 2K 2 = i.e 2 edges
should be there but it is not true.
Question. 86
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
Pivot element is found in Quick sort in every iteration all the elements
to its left are smaller than & all in the right are greater than it.
So if 1/5th of sorted sequence is the pivot. So sequence is divided into
1/5th & 4/5th of the sequence.
So recursion will be
T (n) = T (n/5) + T b 4n l + n
5
Hence (B) is correct option.
Question. 87
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Hence (B) is correct option.
Question. 88
Dijkstras single source shortest path algorithm when run from vertex
a in the above graph, computes the corrects shortest path distance to
SOLUTION
III
III
IV
VII
VI
Order a b e f c h g d
a"b=1
a"c=3
a"b=6
a " e = 2 a " f = 0
a"g=3
a " h = 2
Page 56
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
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) (log n)
(B) (n)
(C) (n log n)
(D) none of the above, as the tree cannot be uniquely determined.
SOLUTION
(B) (n)
(C) (n log n)
(D) (n2)
Page 57
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
(B) 59 and 59
SOLUTION
f1 (8)
n
Value
Return
122 + 60 = 182
40 + 21 = 61
14 + 6 = 20
4+3 = 7
1 1
0 0
0
f (1) (8) = 1640
Now
X [ 1] = 1
Y [ 1] = 2
Z [ 1] = 3
Iteration X[i]
Y[i]
Z[i]
2+0 = 2
4+3 = 7
14
21
14 + 6 = 20
40
60
40 + 21 = 61
122
183
122 + 60 = 182
364
546
Page 59
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
7
1094
1641
Page 60
(A) X [1, W]
(B) X [n, 0]
(C) X [n, W]
(D) X [n 1, n]
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
9"5 5
True
True
Page 61
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
0
5"3 3
True
True
3"2 2
True
True
2"1 1
True
True
True
True
0 1
1
2
True
True
It would never stop & we are looking for no. X >2 but we are moving
in wrong dir.
Hence (C) is correct option.
Question. 96
(B) (n log n)
(C) (n )
Page 62
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
In selection sort the worst case would be when the elements are
reverse sorted, here the algorithm selects the min element the first
element, and during linear scan if element found min then a swap
takes place.
So during n iterations maximum.
n swap can occur in each iteration.
No. of swaps = n [n + (n 1) + (n 2) ............1]
= (n2)
Hence (C) is correct option.
Question. 98
Which of the following statement(s) is/are correct regarding BellmanFord shortest path algorithm ?
P.
Q.
SOLUTION
Let A be a problem that belongs to the class NP. Then which one of
the following is TRUE ?
(A) There is no polynomial time algorithm for A
(B) If A can be solved deterministically in polynomial time, then
P = NP
(C) If A is NP-hard, then it is NP-complete
(D) A may be undecidable
Page 63
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
n#3
T (n) = * n
T a k + cn otherwise
3
Which one of the following represents the time complexity of the
algorithm ?
(A) (n)
(B) (n log n)
(C) (n2)
SOLUTION
For n # 3
T (n) = n
i.e (n)
For n > 3
T (n) = T (n/3) + Cn
This can be solved by Masters Theorem
a = 1 b = 2 logb a = log 3 1 = 0
f (n) = Cn
n logb a < f (n)
nc < f (n)
So,
case III
T (n) = (f (n))
= (Cn)
= (n)
Whole complexity 6n
T (n) = (n) + (n)
Page 64
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
= (n)
Hence (A) is correct option.
Question. 101
The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially
empty hash table of length 10 using open addressing with hash
function h (k) = k mod 10 and linear probing. What is the resultant
hash table ?
(A)
(B)
0
12
23
13
4
5
4
15
18
18
(C)
(D)
0
12
12, 2
13
13, 3, 23
23
18
15
9
Page 65
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
SOLUTION
1
2
12
13
23
18
15
Step 2
8
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
{2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6}
(A)
(B)
(C)
(D)
(A, C) cant be taken after (B, C).
Hence (D) is correct option.
Question. 103
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
case time complexity of the quick sort ?
(A) (n)
(B) (n log n)
(C) (n )
SOLUTION
Pivot in guide sort is the index which is sorted in that run, all the
elements in its left are smaller than it & elements greater than it are
on its right side.
So the recursion becomes.
T (n) = T (n/4) + T (3n/4) + n
Solution to this recursion is (n log n)
Hence (B) is correct option.
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
SOLUTION
During solution through dynamic programming option (B) & (C) are
incorrect since the solution is done in row major order. But not in
column major order.
(A) is true but not necessary.
(D) is correct eg.
L [4, 5] require
L [3, 4] L [3, 5] here (3, 4), (3, 5) & (4, 4)
L [4, 4] L [4, 5] need to be calculated before [4,5]
So L [p, q] required to be calculated before L [r, s] if p < r or q < s .
Hence (D) is correct option.
Page 69
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
YEAR 2010
Question. 106
(B) 10
(C) 6
(D) 5
SOLUTION
n
B = 10n log 10
(D) a 0 + Y/2
SOLUTION
(1)
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Y = a1 + a2 + a 32 + ............ ann 12
2 2
2
Dividing eq. (2) by 2
Y a1 + a2 + a 3 ............. an 1
2 2 22 2 3
2n 1
(2)
(3)
1
0
12
4
9
8
12
0
7
3
1
4
7
0
2
4N
O
9O
3O
O
2O
0O
P
Question. 108
(B) 8
(C) 9
(D) 10
SOLUTION
Page 71
CS Topicwise 2001-2010
Algorithms
www.gatehelp.com
Drawing spanning true using Prims Algorithms start
(A) & (a, b), (a, c), (a, d), (a, e)
(B) & (a, c), (a, d), (a, e), (b, c), (b, d), (b, e)
(D) & (a, c), (a, e), (b, c), (b, d), (b, e), (c, d)
(E)
& (a, c), (a, e), (b, c), (b, d), (b, e), (c, d), (c, e)
with a
(a, b) = 1
(a, d) = 1
(d, e) = 2
(c, e) = 3
Weight = 1 + 1 + 2 + 3
=7
Question. 109
(D) 10
SOLUTION
B " C = 12
B " A " C = 1+8 = 9
B " E " C = 9 + 3 = 12
Page 72
www.gatehelp.com
CS Topicwise 2001-2010
Algorithms
B "3" E " C = 4 + 2 + 3 = 9
B " A " E " C = 1+4+3 = 8
This is min path.
Hence (B) is correct option.
**********
Page 73
www.gatehelp.com
YEAR 2001
Question. 1
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
time.
(C) Linking is insecure
(D) Cryptographic procedures are not available for dynamic linking
SOLUTION
Question. 3
Assume that the SLR parser for a grammar G has n1 states and the
LALR parser for G has n2 states. The relationship between n1 and n2
is
(A) n1 is necessarily less than n2
(B) n1 is necessarily equal to n2
(C) n1 is necessarily greater than n2
(D) None of the above
Page 2
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
SOLUTION
SLR parsue is less range of context free languages than LALR but
still both n1 & n2 are same for SLR & LALR respectively.
Hence (B) is correct option.
Question. 5
(1) True for statically typed languages where each variable has fixed
type. Similarly (4) is also correct.
(2) True, in un-typed languages types of values are not defined.
But option (C) is false, since in dynamically typed language variables
have dynamically changing types but not that they have no type.
Hence (C) is correct option.
Page 3
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
Question. 7
Given grammar
S " EtSSl
Sl " eS
E "b
Terminals
N.T
S
S " iEtSSl
S"
Sl
Sl " eS
Sl "
Sl "
E
E"b
Predictive Parsing table.
So this table presents predictive parsing for dangling if else & shows
ambiguity
M [Sl, e] = {Sl " eS, Sl " }
M [Sl, $] = {Sl " }
Hence (D) is correct option.
Question. 8
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
Given grammar
S " CC
C " cC d
it cant be LL since C " cC is recursive. LR (1) also known as CLR
parser, and every CF grammar is CLR grammar.
So (A) is false but (C) & (D) can be correct.
This grammar is CLR and also reducible to LALR without any
conflicts. So (D) is false.
Only need to check for SLR (1) or LR (0)
This grammar is not SLR.
Hence (C) is correct option
Question. 9
(B) 9 5 + 2 +
(C) 9 5 2 ++
(D) ++ 9 5 2
SOLUTION
S " TR
R " + T {pr int (' + ');} R
T " num {print (num.val);}
Given string 9 + 5 + 2
S " TR
Page 5
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
T + TR
T+T+T
9+T+T
9+5+T
9+5+2
{print (+);}
{print (+);}
{print (9);}
{print (5);}
{print (2);}
So ++ 952 is printed
Hence (D) is correct option.
Question. 10
"
newtemp ();
gen(t
. place
. place;);
.place
t}
.place
.place;}
Here, gen is a function that generates the output code, and newtemp
is a function that returns the name of a new temporary variable on
every call. Assume that t1 s are the temporary variable names
generated by newtemp.
For the statement X: = Y + Z , the 3-address code sequence generated
by this definition is
(A) X = Y + Z
(B) t1 = Y + Z; X t1
(C) t1 = Y; t2 = t1 + Z; X = t2
(D) t1 = Y; t2 = Z; t3 + t2; X = t3
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
) }
Question. 11
SOLUTION
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
(C) 25, 15
SOLUTION
In dynamic scoping, the local values are considered & variables are
initialized at run time.
Since
x = i + j & in P (x)
i = 200 & j = 20
x = 200 + 20 = 220
& printing
(x + 10 )
x = i + j + 10
= 10 + 5 + 10 = 25
Hence (B) is correct option
Question. 13
Page 8
(D) 2 2 2
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
SOLUTION
1.
Px = newQ ();
2.
Qy = newQ ();
3.
Pz = newQ ();
4.
x : f (1); print 2 # i = 2
5.
((P) y) : f (1);
6.
z : f (1) print 2 # i = 2
but line 5. will print 2 because typecast to parent class cant prevent
over ridding. So function f (1) of class Q will be called not f (1) of
class P .
Hence (D) is correct option.
Question. 14
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
operator grammar? P, Q, R are non-terminals, and r, s, t are terminals
.
(i) P " QR
(ii) P " Q s R
(iii) P "
(iv) P " Q t R r
SOLUTION
(I)
Question. 16
(B) Compile-time
(C) Link-time
(D) Load-time
SOLUTION
The two modules needed to be linked since definition exist & M2 &
M1 refers it. So during linking phase M1 links to M2.
Hence (C) is correct option.
Question. 17
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
(D) 40
SOLUTION
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
YEAR 2005
Question. 19
(B) Left-recursive
(C) right-recurisve
(D) an operator-grammar
SOLUTION
The grammar is definitely left & right recursive but it is not suitable
for predictive parsing because it is ambiguous.
Hence (A) is correct option.
Question. 20
(B) n, E + n and E + E # n
(C) n, n + n and n + n # n
(D) n, E + n and E # n
SOLUTION
Given grammar
E " E+n
E " E#n
E "n
String = n + n # n
Right sentential so right most non terminal will be used.
E " E#n
{E " E # n}
E+n#n
{E " E + n}
n+n#n
{E " n}
So during reduction the order is reverse.
So
{E " n, E " E + n, E " E # n}
Hence (D) is correct option.
Question. 21
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
S " (S)| a
Let the number of states in SLR(1), LR(1) and LALR(1) parsers for
the grammar n1 n2 and n3 respectively. The following relationship
holds good
(B) n1 = n3 < n2
(A) n1 < n2 < n3
(C) n1 = n2 = n3
(D) n1 $ n3 $ n2
SOLUTION
The no. of states for SLR (1) & LALR (1) are equal so n1 = n 3 , but
CLR (1) or LR (1) will have no. of states greater than LALR & LR (0)
both.
Hence (B) is correct option.
Question. 22
There are no lexical errors for C because all the wrong spelled keywords
would be considered as identifiers until the syntax is checked.
So the compiler would give syntax errors.
Hence (C) is correct option.
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
number
E
E # E
;
Eval
E .val
E .val
number val
E .VAL E .val
E .VAL E .val
Question. 23
The above grammar and the semantic rules are fed to a yacc tool
(which is an LALR(1) parser generator) for parsing and evaluating
arithmetic expressions. Which one of the following is true about the
action of yacc for the given grammar?
(A) It detects recursion and eliminates recursion
(B) It detects reduce-reduce conflict, and resolves
(C) It detects shift-reduce conflict, and resolves the conflict in favor
of a shift over a reduce action
(D) It detects shift-reduce conflict, and resolves the conflict in favor
of a reduce over a shift action
SOLUTION
Yace tool is used to create a LALR (1) parser. This parser can detect
the conflicts but to resolve the conflicts it actually prefers shift over
reduce action.
Hence (C) is correct option.
Question. 24
Assume the conflicts part (a) of this question are resolved and an
LALR(1) parser is generated for parsing arithmetic expressions as
per the given grammar. Consider an expression 3 # 2 + 1. What
precedence and associativity properties does the generated parser
realize?
(A) Equal precedence and left associativity; expression is evaluated
to 7
(B) Equal precedence and right associativity, expression is evaluated
to 9
(C) Precedence of 'x' is higher than that of +, and both operators
are left associative; expression is evaluated to 7
Page 15
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
(D) Precedence of ' # ' is higher than that of # , and both operators
are left associative; expression is evaluated to 9
SOLUTION
" S*E
"E
" F+E
"F
" id
S " S * .E
(ii)
E " F. + E
(iii)
E " F + .E
Given the items above, which two of them will appear in the same set
in the canonical sets-of-items for the grammar?
(A) (i) and (ii)
SOLUTION
Page 16
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
Question. 26
SOLUTION
Non Terminal
id
S " FR
F " id
R ") S R "!
R "!
Question. 27
(D) 2 3 4 + *
SOLUTION
Input string 2 ) 3 + 4
Page 17
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
S " ER
FR
idR
{print (2)}
id ) ER
{print ())}
id ) F + ER {print (+)}
id ) id + ER {print (3)}
id ) id + FR
id ) id + idR {print (4)}
id ) id + id
So 2 )+ 3 4 are printed
Hence (B) is correct option.
Question. 28
for
for
if i
#i
}
}
}
Which one to the following false?
(A) The code contains loop-in variant computation
(B) There is scope of common sub-expression elimination in this code
(C) There is scope strength reduction in this code
(D) There is scope of dead code elimination in this code
SOLUTION
All the statements are true except option (D) since there is no dead
code to get eliminated.
Hence (D) is correct option.
Question. 29
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
L = (ai bi | i ! j}?
(A) S " AC | CB
C " aCb | a | b
A " aA |
B " Bb |
(B) S " aS | Sb | a | b
(D) S " AC | CB
C " aCb | !
A " aA | a
B " bB | b
SOLUTION
The grammar
S " AC CB
C " aCb !
A " aA a
B " bB b
Consider string aaabb
S " AC
AaCb
AaaCbb
Aaabb
aaabb
But string aabb
S " AC
And this string is not derivable.
Hence (D) is correct option.
Question. 30
SOLUTION
It is very clear from the previous solution that the no. of steps required
Page 19
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
depend upon the no. of a's & b's which ever is higher & exceeds by 2
due to S " AC CB & C "!
So max (l, m) + 2
Hence (A) is correct option.
YEAR 2007
Question. 31
SOLUTION
Clearly LR & LALR are not top down they are bottom up passers.
Also not operator precedence parser.
But yes recursive descent parser is top down parser. Starts from start
symbol & derives the terminal string.
Hence (A) is correct option.
Question. 32
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
Question. 33
SOLUTION
= a+b
= c+d
= e t2
= t1 t 2
Assume that all operands are initially in memory. The final value of
the computation should be in memory. What is the minimum number
of MOV instructions in the code generated for this basic block?
(A) 2
(B) 3
(C) 5
(D) 6
Page 21
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
SOLUTION
Question. 35
(B) aabbbb
(C) aabbab
(D) abbbba
SOLUTION
aabbab
S " aB
" aaBB
" aabSB
" aabbAB
" aabbab
Hence (C) is correct option.
Page 22
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
Question. 36
For the correct answer string to Q. 9 how many derivation trees are
there?
(A) 1
(B) 2
(C) 3
(D) 4
SOLUTION
Question. 37
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
SOLUTION
Handles are the part of sentential form, & they are identified as the
right side of any given production which will be used for reduction in
the net step.
Hence (D) is correct option.
Question. 38
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
SOLUTION
I.
CS Topicwise 2001-2010
Compiler Design
www.gatehelp.com
whose complex are less than (n3)
II
(B) I and IV
SOLUTION
I.
SOLUTION
Symbol table is used for storing the information about variables and
their attributes by compiler.
Hence (B) is correct option.
Question. 43
www.gatehelp.com
CS Topicwise 2001-2010
Compiler Design
SOLUTION
Given grammar
S " aSA
S " bS
S "c
This grammar is not ambiguous so it is LL (1) also LR (1) grammar
since all grammars are LR (1).
Hence (C) is correct option.
**********
Page 27
www.gatehelp.com
YEAR 2003
Question. 1
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
transport protocol over and above the network protocol ?
(A) Recovery from packet losses
(B) Detection of duplicate packets
(C) Packet delivery in the correct order
(D) End to end connectivity
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
10100001.00110111
161.55 00011111.00000000
00000001.00000000
Both belong to same network.
Hence (D) is correct option.
Question. 4
A 2 km long brodcast LAN has 107 bps bandwidth and uses CSMA/
CD. The signal travels along the wire at 2 # 108 m/s. What is the
minimum packet size that can be used on this network ?
(A) 50 bytes
SOLUTION
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
SOLUTION
= 1000 bytes
=5
= 5000 bytes.
= 200 s
= 50 s /Packet.
= 50 # 5 = 250s
= 250 + 200 = 450s
5000
Rate = Data =
Time
450 # 10 6
Group-2
Q. Network layer
R. Transport layer
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
Question. 7
Bridge is the device which work at data link layer whereas router
works at network layer. Both selectively forward packets, build routing
table & connect between LAN & WAN but since bridge works at data
link it uses MAC addresses to route whereas router uses IP addresses.
Option (B) is false.
Hence (B) is correct option.
Question. 8
(B) 800
(C) 876
(D) 1200
SOLUTION
Baud is the symbol which is sent over the link, baud = 9600 bits 18
bit character has baud size of 12 bits.
So no. of characters = 9600
12
= 800
Hence (B) is correct option.
Question. 9
A and B are the only two stations on an Ethernet. Each has a steady
queue of frames to send. Both A and B attempt to transmit a frame,
Page 5
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
collide, and A wins the first backoff race, At the end of this successful
transmission by A, both A and B attempt to transmit and collide.
The probability that A wins the second backoff race is
(A) 0.5
(B) 0.625
(C) 0.75
(D) 1.0
SOLUTION
A wins the first back off race the conditions are (0, 1)
After that during second back off four conditions (0, 1, 2, 3)
Probably = 1 # 3 # 1 # 1
2
2
2
4
=3+1
8 4
= 5 = 0.625
8
Hence (B) is correct option.
Question. 10
Subnet Mask
Interface
128.75.43.0
255.255.255.0
Eth 0
128.75.43.0
255.255.255.128
Eth 1
192.12.17.5
255.255.255.255
Eth 3
deraulf
Eth 2
SOLUTION
Given IP Address
128.75.43.16.
Eth 0 128.75.43.0.
Mask 255.255.255.0.
Page 6
(1)
(2)
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
Question. 11
Assuming that the packets are correctly delivered, how many bytes,
including headers, are delivered to the IP layer at the destination
for one application message, in the best case ? Consider only data
packets.
(A) 200
(B) 220
(C) 240
(D) 260
SOLUTION
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
This would require
20+80
20+80
Packets total 260 bytes.
These are transferred to C.
Hence (D) is correct option.
20+40
Question. 12
SOLUTION
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
The maximum window size for data transmission using the selective
reject protocol with n -bit frame sequence numbers is
(A) 2n
(B) 2n 1
(C) 2n 1
(D) 2n 2
SOLUTION
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
SOLUTION
(B) 255.255.64.0
(C) 255.255.128.0
(D) 255.255.255.0
SOLUTION
(B) 6
(C) 7
(D) 9
SOLUTION
Packet size 6
= 24 byte
=3
=4
= 4 3 = 1 byte only
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
Data = 6 3 = 3
Require 8 pakets.
Case 3
Packet size = 7
Data = 7 3 = 4
Require 24 = 4 packets.
4
Case 4
Packet size = 9
Data = 9 3 = 6
Require = 24 = 4 packets.
6
(D) 512
SOLUTION
For which one of the following reason: does Internet Protocol (IP) use
the time-to-live (TTL) field in the IP datagram header?
(A) Ensure packets reach destination within that time
(B) Discard packets that reach later than that time
Page 11
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
(C) Prevent packets from looping indefinitely
(D) Limit the time for which a packet gets queued in intermediate
routers
SOLUTION
(D) 320
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
C1
IP Addr 203.197. 2.53
Mask
255.255.128.0
N/W ID 203.197. 0.0
C2
203.197. 75.201
255.255.192.0
203.197. 64.0
C2
203.197. 75.201
255.255.128.0
203.197. 0.0
(D) 18
SOLUTION
Sender
Time
1
Packet no.
1
Receiver
Time Packet status
1
ACK
Page 13
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
2
2
3
3
4
4
5
5
6
6
7
5 resend
8
6
9
7
10
8
11
9
12
9 resend
Total time = 12
Hence (A) is correct option.
2
3
4
5
6
7
8
9
10
11
12
ACK
ACK
ACK
Lost
Discard
ACK
ACK
ACK
ACK
Lost
Question. 24
(B) B1,B3,B5,B2,B4
(C) B1,B5,B2,B3,B4
(D) B1.B3.B4.B5.B2
SOLUTION
Graph of bridge
Spinning tree
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
Question. 25
Consider the correct spanning tree for the previous question. Let host
H1 send out a broadcast ping packet. Which of the following options
represents the correct for forwarding table on B3?
(A)
(B)
Hosts
Ports
Hosts
Port
H1,H2,H3,H4
H1, H2
H5,H6,H9,H10
H3, H4
H7,H8,H11,H12
H5, H6
(D)
Hosts
Port
Hosts
Port
SOLUTION
From the given graphs spanning tree port 1, 2, 3 of bridge 3 are used
to access.
Port
H5
H6
H9
H10
H7
H8
H11
H12
H1
H2
H3
H4
YEAR 2007
Question. 26
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
SOLUTION
(D) SMTP
SOLUTION
HTTP & SMTP uses TCP to make calls. DNS which is used for
mapping names to IP addresses uses UDP to make function calls.
Hence (C) is correct option.
Question. 28
(D) 1 (1 p) n 1
SOLUTION
= np (1 p) n 1
Hence (A) is correct option.
Question. 29
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
SOLUTION
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
(C) 11001010
(D) 110010010011
SOLUTION
Message = 11001001
Polynomial = x7 + x6 + x3 + 1
CRC polynomial = x3 + 1
x 4 + x3 x
x 3 + 1 x7 + x 6 + x 3 + 1
x7
! x4
x6 x 4 + x3 + 1
x6
! x3
x4 + 1
! x4
"x
x+1
x + 1 is remained three bit binary CRC is 011
So CRC checked 11001001011
Hence (B) is correct option.
Question. 32
SOLUTION
Dist between
Propagation delay
Total delay
Frame size
Capacity of channel
RTT
Page 18
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
1. Application layer
Q. BGP
2. Transport layer
R. TCP
S.
4. Network layer
PPP
5. Physical layer
(A) P-2,Q-1,R-3,S-5
(B) P-1,Q-4,R-2,S-3
(C) P-1,Q-4,R-2,S-5
(D) P-2,Q-4,R-1,S-3
SOLUTION
What is the maximum size of data that the application layer can pass
on to the TCP layer below?
Page 19
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
(A) Any size
SOLUTION
In the slow start phase of TCP congesting control algorithm, the size
of the congestion window
(A) Does not increase
(B) Increases linearly
(C) Increases quadratically
(D) Increases exponentially
SOLUTION
Slow start is one of the algorithm that TCP uses to control congestion
inside the network, also known as exponential growth phase, here the
TCP congestion window size is increased.
Hence (D) is correct option.
Question. 36
(D) 2047
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
i.e 255.255.11111000.00000000
Since 5 bits used for subnetting so.
25 = 32 subnets possible
& 11 bits are used for host address.
211 hosts allowed = 2048 hosts.
But00000000 000 & 11111111 111
Address for host not allowed, 2046 hosts possible.
Hence (C) is correct option.
Question. 37
(B) 2 seconds
(C) 5 seconds
(D) 8 seconds
SOLUTION
Initially filled = 16 Mb
Bucket fill rate = 2 Mbps
Time (sec)
0
1
1.8
2
Bucket (Mbps)
16
16 10 + 2 = 8
8 8 + 1.6
1.6 2 + .4 = 0
At t = 0 16 Mb are there.
t = 1 10 Mb are transmitted but 2 Mb are filled in taken bucket
t = 1.8 8 Mb are transmitted but 2 # .8 = 1.6 Mb are filled.
t = 2 1.6 Mb are transmitted with 2 # .2 = .4 Mb.
Hence (B) is correct option.
Question. 38
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
executes a socket () system call followed by connect () system call to
connect to the server process S . The server process has not executed
any accept() system call. Which one of the following events could
take place?
(A) connect ( ) system call returns successfully
(B) connect ( ) system call blocks
(C) connect ( ) system call returns an error
(D) connect ( ) system call results in a core dump
SOLUTION
In the RSA public key cryptosystem, the private and the public keys
are (e, n) and (d, n) respectively, where n = p) and p and q are large
primes. Besides, n is public and p and q are private. Let M be an
integer such that 0 < M < n and (n) = (p 1) (q 1). Now consider
the following equations.
I.
M' = Me mod n
M = (M') d mod n
Page 22
www.gatehelp.com
II
CS Topicwise 2001-2010
Computer Network
ed / 1 mod n
(C) II and IV
SOLUTION
(B) 0.064/s
(C) 0.135/s
(D) 0.327/s
Page 23
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
SOLUTION
LetG (x) be the generator polynomial used for CRC checking. What is
the condition that should be satisfied by G (x) to detect odd number
of bits in error ?
(A) G (x) contains more than two terms
(B) G (x) does not divide 1 + xk , for any K not exceeding the frame
length
(C) 1 + x is a factor of G (x)
(D) G (x) has an odd number of terms
SOLUTION
Page 24
(A) l = 2
(B) l = 3
(C) l = 4
(D) l = 5
www.gatehelp.com
CS Topicwise 2001-2010
Computer Network
SOLUTION
Suppose that the sliding window protocol is used with the sender
window size of 2l , where l is the number of bits identified in the
earlier part and acknowledgements are always piggy backed. After
sending 2l frames, what is the minimum time the sender will have to
wait before starting transmission of the next frame ? (Identify the
closest choice ignoring the frame processing time)
(A) 16 ms
(B) 18 ms
(C) 20 ms
(D) 22 ms
SOLUTION
l = 5 here
2l = 32
Total 32 frames of 1000 bits each need to be sent.
Time = 32 # 1000
= 32 m sec
106
Time taken by first acknowledgement
= 2 # RTT
= 2 # 25 = 50 ms
Time to wait = 50 32
= 18 m sec
Hence (B) is correct option.
Page 25
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
YEAR 2010
Question. 44
Time to live field in IP datagram signifies the time stamp for which
that packet is valid, if it reaches to a particular hop late than this time
stamp it needed to be discorded. This prevents looping of packets.
Hence (D) is correct option.
Question. 45
(D) Ping
SOLUTION
www.gatehelp.com
(C) 255.255.255.192
CS Topicwise 2001-2010
Computer Network
(D) 255.255.255.224
SOLUTION
(A)
IP Addr
N/W Addr
A
10.105. 1.113
255.255.255.0
10.105. 1.0
B
10.105. 1.91
255.255.255.0
10.105. 1.0
(B)
N/W Addr
255.255.128
01110001
10000000
10.105.1.0
255.255.255.128
01011011
10000000
10.105. 1. 0
Same network
(C)
10.105. 1.01110001
255.255.255.11000000
10.105. 1.01000000
10.105. 1.01011011
255.255.255.11000000
10.105. 1.01000000
Same network
(D)
10.105. 1.01110001
255.255.255.11100000
10.105. 1.01100000
10.105. 1.01011011
255.255.255.11100000
10.105. 1.01000000
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
Question. 47
All the routers use the distance vector based routing algorithm
to update their routing tables. Each starts with its routing table
initialized to contain an entry for each neighbour with the weight of
the respective connecting link. After all the routing tables stabilize,
how many links in the network will never be used for carrying any
data ?
(A) 4
(B) 3
(C) 2
(D) 1
SOLUTION
R2
R3
R2 3 + 2 = 5
R1 2 + 3 = 5
R1 4 + 9 + 3 = 16
R3 3
R3 2
R2 4 + 1 + 7 = 12
R 4 3 + 2 + 7 = 12
R4 7
R 3 4 + 9 = 13
R5 3 + 9 = 12
R5 7 + 1 = 8
R4 4 + 1 = 5
R6 3 + 9 + 4 = 16
R6 7 + 1 + 4 = 12 R5 4
R4
R5
R6
R1 7 + 2 + 3 = 12 R1 9 + 3 = 12 R1 4 + 9 + 3 = 16
R2 7
R2 1 + 7 = 8
R2 4 + 1 + 7 = 12
R3 7 + 2 = 9
R3 9
R 3 4 + 9 = 13
R5 1
R4 1
R4 4 + 1 = 5
R6 4
R6 1 + 4 = 5
Edge R1 " R2 = 6
& R 4 " R6 = 8
Are never used
Page 28
R5 4
CS Topicwise 2001-2010
Computer Network
www.gatehelp.com
Hence (C) is correct option.
Question. 48
Suppose the weights of all unused links in the previous question are
changed to 2 and the distance vector algorithm is used again until all
routing tables stabilize. How many links will now remain unused ?
(A) 0
(B) 1
(C) 2
(D) 3
SOLUTION
R2
R1 2
R3 2
R4 7
R5 7 + 1 = 8
R6 7 + 2 = 9
R3
R1
R2
R4
R5
R6
3
2
2+7 = 9
9
9 + 1 + 2 = 12
R 4 R5
R5 1 R6 1 + 2 = 3
R6 2
So
R5 " R6 = 4 is never used.
Hence (B) is correct option.
**********
Page 29
www.gatehelp.com
YEAR 2001
Question. 1
Cache is the small memory which has a very less access time. So it is
used for temporal locality of reference whereas virtual memory is for
spatial locality of reference.
Hence (A) is correct option.
Question. 2
(B) RESET IN
(C) HOLD
(D) READY
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Hence (D) is correct option.
Question. 3
Suppose a processor does not have any stack pointer register. Which
of the following statements is true ?
(A) It cannot have subroutine call instruction
(B) It can have subroutine call instruction, but no nested subroutine
calls.
(C) Nested subroutine calls are possible, but interrupts are not.
(D) All sequences of subroutine calls and also interrupts are possible
SOLUTION
Stack pointer register holds the address of top of stack, which is the
location of memory at which the CPU should resume its execution
after servicing some interrupt or subroutine call.
So if SP register not available then no subroutine call instructions
are possible.
Hence (A) is correct option.
Question. 4
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
(B) Parsing
(C) Relocation
SOLUTION
(B) Cache
(D) Disk
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Question. 8
Which is the most appropriate match for the items in the first column
with the items in the second column
(X.) Indirect Addressing
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
SP ! SP 1
How many CPU clock cycles are needed to execute the push r
instruction ?
(A) 2
(B) 3
(C) 4
(D) 5
SOLUTION
Push r
Consist of following operations
M [SP] !r
SP ! SP 1
r is stored at memory at address stack pointer currently is, this take
2 clock cycles.
SP is then decremented to point to next top of stack.
So total cycles = 3
Hence (B) is correct option.
Question. 10
(B) Timer
SOLUTION
A device employing INTR line for device interrupt puts the CALL
instruction on the data bus while
(A) INTA is active
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
SOLUTION
Program counter is the register which has the next location of the
program to be executed next. JMP & CALL changes the value of PC.
PCHL instruction copies content of registers H & L to PC.
ADD instruction after completion increments program counter. So
program counter is modified in all cases.
Hence (D) is correct option.
Question. 13
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
Question. 14
SOLUTION
In the C language
(A) At most one activation record exists between the current
activation record and the activation record for the main.
(B) The number of activation records between the current activation
record and the activation record for the main depends on the
actual function calling sequence.
(C) The visibility of global variables depends on the actual function
calling sequence.
(D) Recursion requires the activation record for the recursive function
to be saved on a different stack before the recursive fraction can
be called.
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
inside the instruction
(D) The location of the operand is implicit
SOLUTION
Horizontal microprogramming
(A) Does not require use of signal decoders
(B) Results in larger
microprogramming
sized
microinstructions
than
vertical
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
YEAR 2003
Question. 19
SOLUTION
Case 1
(D) (n2)
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Question. 21
Z:
Page 10
MOV
MOV
CMP
JZX
SUB
B, # 0
C, # 8
C, # 0
C, # 1
;
;
;
;
;
B!0
C!8
compare C with 0
jump to X if zero flag is set
C!C1
www.gatehelp.com
RRC A, # 1
Y:
CS Topicwise 2001-2010
Computer Organization &
Architecture
JCY
JMP Z
ADD B, # 1
JMP Z
X:
Question. 22
no operation
(C) LRC A, # 1
(D) ADD A, # 1
Page 11
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
SOLUTION
Question. 24
(B) 1 and 2
(C) 2 and 3
SOLUTION
Page 12
(A) R to X, 1 to Y, T to Z
(B) T to X, R to Y, T to Z
(C) T to X, R to Y, 0 to Z
(D) R to X, 0 to Y, T to Z
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
SOLUTION
We require f = T + R
We have MUX equation
f = Z'x + zy
Now if we make following ckt
Truth table
R T F Z
0 0
0 1
1 0
1 1
So X = R Y = 1 Z = T
f
= T'R + T
= (T + T') (T + R)
= T+R
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Instruction
Operation
Instruction Size
(in words)
2
MOV R1,5000
;R1!Memory[5000]
MOV R2,R3
;R2!R2+R3
ADD R2,R3
;R2!R2+R3
MOV 6000,R2
;Memory[6000]!R2
HALT
;Machine halts
Question. 26
Consider that the memory is byte addressable with size 32 bits, and
the program has been loaded starting from memory location 1000
(decimal). If an interrupt occurs while the CPU has been halted after
executing the HALT instruction, the return address (in decimal)
saved in the stack will be
(A) 1007
(B) 1020
(C) 1024
(D) 1028
SOLUTION
Address range
1000-1007
1008-1011
1012-1015
1016-1023
1024-1027
3 clock cycles
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
ADD with both operands in register:
1 clock cycle
(B) 24
(C) 23
(D) 20
SOLUTION
3#2+2
1#3+2
1 (add only)
3#2+2
Total
24
(B) 3
(C) 4
(D) 5
SOLUTION
Page 15
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
After than 12 & 8 are referred but this does not cause any miss
So no. of miss = 3
This stars ()) shows the misses.
Hence (B) is correct option.
Question. 29
How many bits are there in the X and Y fields, and what is the size
of the control memory in number of words?
(A) 10, 3, 1024
(B) 8, 5, 256
(C) 5, 8, 2048
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
(D) 0.1%
SOLUTION
Transfer rate = 10 MB ps
Data = 20 KB
10
Time = 20 # 220 = 2 # 10 3
10 # 2
= 2 ms
Processor speed = 600 MHz
= 600 cycles/sec.
Cycles required by CPU = 300 + 900
For DMA = 1200
So time = 1200 6 = .002 ms
600 # 10
% = .002 # 100
2
= 0.1%
Hence (D) is correct.
Question. 31
A 4-stage pipeline has the stage delays as 150, 120, 160 and 140
nanoseconds respectively. Registers that are used between the stages
have a delay of 5 nanoseconds each. Assuming constant clocking rate,
the total time taken to process 1000 data items on this pipeline will
be
(A) 120.4 microseconds
(B) 160.5 microseconds
(C) 165.5 microseconds
SOLUTION
Delay = 5 ns/stage
Total delay in pipline.
Page 17
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
= 150 + 120 + 160 + 140 = 570
Delay due to 4 stages.
Stage 1 delay 1 stage 2 delay 2 stage 3 stage 4
5 # 3 = 15
Total = 570 + 15 = 585
Total time = 1000 data items
585 ns
= 165.5 microseconds.
Hence (C) is correct option
YEAR 2005
Question. 32
Which one of the following is true for a CPU having a single interrupt
request line and a single interrupt grant line?
(A) Neither vectored interrupt nor multiple interrupting devices are
possible
(B) Vectored interrupts are not possible but multiple interrupting
devices are possible
(C) vectored interrupts and multiple interrupting devices are both
possible
(D) vectored interrupt is possible but multiple interrupting devices
are not possible
SOLUTION
Here multiple request can be given to CPU but CPU interrupts only
for highest priority interrupt so option (A) & (D) are wrong.
But here in case of single interrupt lines definitely vectored interrupts
are not possible.
Hence (B) is correct option.
Page 18
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
Question. 33
Normally user programs are prevented from handing I/O directly by I/O
instructions in them. For CPUs having explicit I/O instructions, such
I/O protection is ensured by having the I/O instructions privileged. In
a CPU with memory mapped I/O, there is no explicit I/O instruction.
Which one of the following is true for a CPU with memory mapped
I/O?
(A) I/O protection is ensured by operating system routine(s)
(B) I/O protection is ensured by a hardware trap
(C) I/O protection is ensured during system configuration
(D) I/O protection is not possible
SOLUTION
Swap space is the memory pre allowed to store processs data. This
can be compared with virtual memory. The data required to complete
process is kept here.
Hence (B) is correct option.
Question. 35
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
(C) Fewer page faults occur
(D) Fewer segmentation faults occur
SOLUTION
Due to increase in RAM size all the pages required by CPU are
available in RAM so page fault chance are less, so virtual memory
access chances are less and latency is reduced for secondary memory.
Hence (C) is correct option.
Question. 36
(B) 4
(C) 5
(D) 6
SOLUTION
ADD A [R 0], @B
This is instruction has 3 computational parts. ADD instruction
requires 1 machine cycle, A [R 0] here R 0 is index register which has
starting address of index then this index has the block address.
This whole operation require 3 machine cycles. Now @ B is indirect
addressing. This takes 2 machine cycles. So overall 1 + 3 + 2 = 6
machine cycles.
Hence (D) is correct option.
Page 20
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
Question. 37
Match List-I with List-II and select the correct answer using the
codes given below the lists:
List-I
List-II
A. A [1] = B [j];
1. Indirect addressing
B. while [* A ++];
2. Indexed addressing
C. int temp=*x ;
3. Auto increment
Codes:
A
(A)
(B)
(C)
(D)
SOLUTION
LIST-I
A. A [1] = B [J];
B. While [) A ++]
3.
Auto
increment
the
memory locations is A are
automatically incriminated.
1.
C. int temp = ) X
LIST-II
Indexed addressing here the
indexing is used
A2
B3
C1
Hence (C) is correct option.
Question. 38
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
(C) 15,17
(D) 5,17
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
(A) 8
(B) 10
(C) 12
(D) 15
SOLUTION
10
R 0 ! M [LOC] IF RD EX MA WB
R0 ! R0 + R0
IF
RD EX
R2 ! R2 R0
MA WB
IF
RD
EX MA WB
(D) 45
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Hence (B) is correct option.
Question. 41
(B) 25
(C) 40
(D) 50
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
The, ALU, the bus and all the registers in the data path are of
identical size. All operations including incrementation of the PC and
the GPRs are to be carried out in the ALU. Two clock cycle are
needed for memory read operation-the first one for loading data from
the memory but into the MDR.
Question. 42
(D) 5
SOLUTION
R 0 ! R 0 + R1
First cycle require to fetch operands two cycles required for this.
The next cycle required to use ALU to perform ADD operation.
So total cycles required = 3
Hence (D) is correct option.
Question. 43
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
The minimum number of CPU clock cycles needed during the
execution cycle of this instruction is
(A) 2
(B) 3
(C) 4
(D) 5
SOLUTION
Rn ! PC + 1
PC = M [PC]
Program outer is itself a register so incremented in 1 cycle.
Now fetching the memory at PC & the value of at address stored in
PC takes 2 cycles.
So total 1 + 2 = 3 cycles.
Hence (B) is correct option.
Question. 44
(D) 700
SOLUTION
A CPU has a cache with block size 64 bytes. The main memory has
k banks, each bank being c bytes wide. Consecutive c-bute chunks
are mapped on consecutive banks with warp-around. All the k banks
can be accessed in parallel, but two accesses to the same bank must
be serialized. A cache block access may involve multiple iterations of
parallel bank accesses depending on the amount of data obtained by
accessing all the k banks in parallel. Each iteration requires decoding
Page 26
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
(D) 184 ns
SOLUTION
SOLUTION
Given that 80% of 109 instruction require single cycle i.e. no conditional
branching & for 20% an extra cycle required.
Time taken by 1 cycle = 10 9 sec.
Page 27
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
Total time = 10 9 b 80 # 109 + 20 # 2 # 109 l
100
100
= 10 9 # 109 b 4 + 2 l
5 5
= 6 = 1.2 seconds.
5
Question. 47
SOLUTION
Given instruction
bbs reg, pos, Label
Here pos bit decided whether to jump to label. So all other bits in
temp set to 0.
Temp ! reg and mask.
So of temp is not zero branch to label.
So shifting left over.
Mask ! 0 # 1 << pos
Hence (D) is correct option.
Data for Q. 48 & Q. 49 are given below. Solve the problem and
choose the correct answers.
Consider two cache organizations: The first one is 32 KB 2-way set
associative with 32-bytes block size. The second one is of the same
Page 28
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
size but direct mapped. The size of an address is 32 bits in both cases
A2-to-1 multiplexes has latency of 0.6 ns where a k -bit comparator
has a latency of k/10ns . The hit latency of the set associative
organization is h1 while that of the direct mapped one is h2 .
Question. 48
The value of h1 is
(A) 2.4ns
(B) 2.3ns
(C) 1.8ns
(D) 1.7ns
SOLUTION
h1 = 18 + 0.6 ns
10
= 2.4 ns.
Hence (A) is correct option.
Question. 49
The value of h2 is
(A) 2.4ns
(B) 2.3ns
Page 29
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
(C) 1.8ns
(D) 1.7ns
SOLUTION
The value of M1 is
Page 30
www.gatehelp.com
(A) 0
(B) 2048
(C) 16384
(D) 262144
CS Topicwise 2001-2010
Computer Organization &
Architecture
SOLUTION
Given loop P1 accesses array A row wise & P2 access column wise.
M1 = ?
Cache Capacity = 215 B.
1 element = 23 B
Total elements 512 # 512
Total data = 512 # 512 # 8 B
= 221 B
Block size = 128 B
1 block can have = 128 = 16 elements
8
So total blocks require = 512 # 512
16
= 1638 blocks
Since the memory is initially empty so all blocks are required at least
once.
So,
M1 = 16384
Hence (C) is correct option.
Question. 51
(B) 1/16
(C) 1/8
(D) 16
SOLUTION
Now
M2 = ?
In the case (P2 loop) the array is accessed column wise, so even the
block brought for A [0] [0] A [0] [15] would not be used for second
column wise access i.e. A [1] [0] So new block need to swap, similarly
for A [3] [0] & So on. This would continue for every element, since
memory is contiguous.
So
M2 = 512 # 512 = 262144
Page 31
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
&
M1 = 16384 = 1
262144 16
M2
Question. 52
(B) 7,7,6
(C) 7,5,8
(D) 9,5,6
SOLUTION
Consider a disk pack with 16 surfaces, 128 tracks per surface and 256
sectors per track. 512 bytes of data are stored in a bit serial manner
in a sector. The capacity of the disk pack and the number of bits
required to specify a particular sector in the disk are respectively
Page 32
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
SOLUTION
Surface = 6
Tracks = 16 # 128
Sectors = 16 # 128 # 256
= 2 4 # 27 # 28 = 219
So 19 lines are required to address all sectors.
Bytes = 219 # 512 B
= 219 # 29
B = 228
= 256 MB
Hence (A) is correct option.
Question. 54
Instruction Fetch
Instruction Decode and Operand Fetch
Execute
Write Bank
The IF, ID and WB stages take one clock cycle each to complete
the operation. The number of clock cycles for the EX stage depends
on the instruction. The ADD and SUB instructions need 1 clock
cycle and the MUL instruction need 3 clock cycles in the EX stage.
Operand forwarding is used in the pipelined processor. What is the
number of clock cycles taken to complete the following sequence of
instructions?
ADD
R2,
R1,
R0
R2 ! R1+R0
MUL
R4,
R3,
R2
R4 ! R3*R2
SUB
R6,
R5,
R4
R6 ! R5R4
(A) 7
(B) 8
(C) 10
(D) 14
SOLUTION
8
Page 33
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
R2 ! R1 ! R 0 IF ID EX WB
R 4 ! R3 ! R2
IF ID
R6 ! R5 ! R 4
IF
EX EX EX WB
ID
EX WB
Operation
R1!M[3000]
Instruction size
(no. of words)
2
R2!M[R3]
R2!R1+R2
M(R3]!R2
R3!R3+1
R1!R1-1
Branch on not zero
Stop
1
1
1
1
1
2
Page 34
(A) 10
(B) 11
(C) 20
(D) 21
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
SOLUTION
(B) 101
(C) 102
(D) 110
SOLUTION
Program stores results from 2000 to 2010. It stores 110, 109, 108......100
at 2010 location.
DEC R1
Hence (A) is correct option.
Question. 57
Assume that the memory is byte addressable and the word size is 32
bits. If an interrupt occurs during the execution of the instruction
INC R3, what return address will be pushed on to the stack?
(A) 1005
(B) 1020
(C) 1024
(D) 1040
SOLUTION
Words Location
1000-1007
MOV R2, R1
1008-1011
ADD R2, R1
1012-1015
Page 35
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
MOV (R3), R2
1016-1019
INC R3
1020-1023
DEC R1
1
1024-1027
Interrupt occurs during execution of INC R3, So CPU will complete
the execution of this instruction and then Push the next address 1024
to the stack, so after interrupt service the program can be resumed
from next instruction.
Hence (C) is correct option.
(D) 59
SOLUTION
Page 36
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
Question. 59
Which of the following lines of the data cache will be replaced by new
blocks in accessing the array
(A) line 4 to line 11
(B) line 4 to line 12
(C) line 0 to line 7
SOLUTION
For a magnetic disk with concentric circular track, the latency is not
linearly proportional to the seek distance due to
(A) non-uniform distribution of requests
(B) arm starting and stopping inertia
(C) higher capacity of tracks on the periphery of the platter
(D) use of unfair arm scheduling policies.
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
additional ALU is required for effective address calculation
3.
The amount of increment depends on the size of the data item
accessed.
(A) 1 only
(B) 2 only
(C) 3 only
SOLUTION
In auto increment addressing mode the address where next data block
to be stored is generated automatically depending upon the size of
single data item required to store. So statement 3 is correct.
Statement says that this mode is used for self relocating code, but
this is false since self relocating code, takes always some address in
memory.
Statement 2 is also incorrect since no additional ALV is required.
Hence (C) is correct option.
Question. 62
Which of the following must be true for the RFE (Return from
Expectation) instruction on a general purpose processor.
1.
It must be a trap instruction
2.
It must be a privileged instruction
3.
An exception can not be allowed to occur during execution of
an RFE instruction.
(A) 1 only
(B) 2 only
(C) 1 and 2 only
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
3.
The associativity of L2 must be greater that of L1
4.
The L2 cache must be at least as large as the L1 cache
(A) 4 only
(B) 1 and 2 only
(C) 1, 2 and 4 only
(D) 1, 2, 3 and 4
SOLUTION
Level 1 (L1) & Level 2 (L2) cache are placed between CPV & they
can be both write through cache but this is not necessary.
Associativity has no dependence but L2 cache must be at least as
large as L1 cache, since all the words in L1 are also is L2.
Hence (A) is correct option.
Question. 64
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
3. Instruction fetches
(A) 1 only
(B) 2 only
(C) 3 only
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
(D) 68 kbits
SOLUTION
= 32 bits
= 64 KB
= 32 KB
= 32 15 = 17
= 16 bytes
= 4 bits are required
Index = block + word
Block = 15 4 = 11
17
11
CPV address
Size of tags = There are 217 bytes of tags in every set of cache.
So total = 17 # 2 # 1024
= 34 KB.
Hence (B) is correct option.
Question. 68
Which of the following array elements has the same cache index as
APR [0][0]?
(A) APR[0][4]
(B) APR[4][0]
(C) APR[0][5]
(D) APR[5][0]
SOLUTION
Elements stored in row major order. Two elements should have same
cache index (15 bits) & their tags may be different (17 bits).
So APR [%] [%] the MSB 17 bits will be changed.
Page 41
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
(B) 25%
(C) 50%
(D) 75%
SOLUTION
No. of hits
Total accesses
1024
= 1 = 0.5
1024 + 1024 2
or
= 50%
Hence (C) is correct option.
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
SOLUTION
(B) 12
(C) 13
(D) 14
SOLUTION
(B) 32
(C) 64
(D) 128
Page 43
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
SOLUTION
= 26
= 64
Hence (C) is correct option.
Question. 73
Page 44
S1
S2
S3
S4
I1
I2
I3
www.gatehelp.com
I4
CS Topicwise 2001-2010
Computer Organization &
Architecture
(B) 23
(C) 28
(D) 30
SOLUTION
We can see a single iteration of given for loop according to the cycles
required.
Cycle S1
S2
I1
I1
I2
I1
I3
I2
I3
I2
I4
I2
S3
S4
Completion
I1
I1
I1
I3
I2
I4
I2
I4
I3
I2
10
I4
I2
11
I4
I3
12
I3
13
I3
14
I4
15
I4
I2
I3
I4
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
0, 255, 1, 4, 3, 8, 133, 159, 216, 129, 63, 8, 48, 32, 73, 92, 155
Which one of the following memory block will NOT be in the cache
if LRU replacement policy is used ?
(A) 3
(B) 8
(C) 129
(D) 216
SOLUTION
Set 0
Set 1
48
mod 4 = 0 )
32
255
mod 4 = 3 )
mod 4 = 1 )
216
92
mod 4 = 0 )
mod 4 = 3 )
133
133
mod 4 = 0 )
129
129
133
mod 4 = 1 )
73
73
159
mod 4 = 3 )
216
mod 4 = 0 )
129
mod 4 = 1 )
63
mod 4 = 3 )
mod 4 = 0 )
Set 2
Set 3
255
155
98
mod 4 = 0 )
32
mod 4 = 0 )
159
159
73
mod 4 = 1 )
63
63
92
mod 4 = 0 )
155
mod 4 = 3 )
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
(B) 505036
(C) 505037
(D) 505038
SOLUTION
(B) 0, 16, 30
(C) 0, 16, 31
(D) 0, 17, 31
SOLUTION
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
YEAR 2010
Question. 78
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
R2 ! R 0)R1
I1 : DIV R5, R 3, R 4
R5 ! R 3 /R 4
R2 ! R5 + R2
R5 ! R2 R6
(A) 13
(B) 15
(C) 17
(D) 19
SOLUTION
A = (R 3 /R 4) + R2, R6
(D) 6
Page 49
CS Topicwise 2001-2010
Computer Organization &
Architecture
www.gatehelp.com
SOLUTION
Replacement
R1
R2 R3
f
e
d
So all the operations done using 3 registers only.
Hence (B) is correct option.
Question. 81
(B) 20 nanoseconds
(C) 22 nanoseconds
(D) 88 nanoseconds
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Computer Organization &
Architecture
required.
4 # 2 + 4 # 20
8 + 80
88 ns
Hence (D) is correct option.
Question. 82
SOLUTION
Miss in both L1 & L2. Cause main memory to transfer that block in
both cache.
1 block of Main memory has 16 words but data bus of L2 has only 4
words. So 4 access of Main memory & 4 access of L2 Cache required
to update L2
4 # 20 + 4 # 200
80 + 800 = 880 ns
Now L2 updates L1, this takes 4 access to L1 & 4 access to L2
4 # 2 + 4 # 20
8 + 80 = 88 ns
Total time = 880 + 88
= 968 ns
Hence (D) is correct option.
**********
Page 51
www.gatehelp.com
YEAR 2000
Question. 1
Question. 2
Y Z
CS Topicwise 2001-2010
Database
www.gatehelp.com
Which of the following functional dependencies are satisfied by the
instance ?
(A) XY " Z and Z " Y
(B) YZ " X and Y " Z
(C) YZ " X and X " Z
SOLUTION
Question. 3
Given relations r (w, x) and s (y, z), the result of select distinct w, x
from r, s :
is guaranteed to be same as r, provided :
(A) r has no duplicates and s is non empty
(B) r and s have no duplicates
(C) s has no duplicates and r is non empty
(D) r and s have the same number of tuples
YEAR 2001
Question. 4
R (A, B, C, D)
R1 (AB) & A " B , C " D
R1 (AB) & R2 (CD).
So dependencies are preserved during decomposition.
But for lossless join.
R1 (AB) + R2 (CD) " R1 (AB)
Page 2
www.gatehelp.com
CS Topicwise 2001-2010
Database
Given query performs natural join between r & s , & then project
attribute A where A = a .
This same result is produced by the query A = a (r) A s .
This query selects attribute A = a from r & then performs join
operation results are same.
Hence (C) is correct option.
Question. 7
CS Topicwise 2001-2010
Database
www.gatehelp.com
lossless join, dependency preserving BCNF decomposition ?
(A) A " B, B " CD
(B) A " B, B " C, C " D
(C) AB " C, C " AD
SOLUTION
R (A, B, C, D)
In option (A) & (B) there exists transitive functional dependency, so
incorrect for BCNF .
In option (C)
AB " C C " AD
So
AB " AD
B "D
In option (D) all attributes depend upon same key so in BCNF .
Hence (D) is correct option.
Question. 8
primary key Ib
foreign key (ub) references geq on delete cascade):
Page 4
www.gatehelp.com
CS Topicwise 2001-2010
Database
Page 5
CS Topicwise 2001-2010
Database
www.gatehelp.com
SOLUTION
(B) 42
(C) 43
(D) 44
SOLUTION
So
Page 6
www.gatehelp.com
CS Topicwise 2001-2010
Database
(B) Lossless-join
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
value for same values of B for every corresponding tuple.
In given database.
A
B is 3.
So B is functionally determined by A.
But this relationship is not true for any other pair.
Hence (B) is correct option.
YEAR 2003
Question. 15
www.gatehelp.com
CS Topicwise 2001-2010
Database
Question. 16
(r1 # r2 # ......rm)
a1, a2,... an
a1, a2,... an
a1, a2,... an
a1, a2,... an
SOLUTION
Age"Eligibility
Name"Roll_number
Roll_number"Name
Course_number"Course_name Course_number"Instructor
(Roll_number,Course_number)"Grade
The relation(Roll)number,Name,Date_of_brith,Age)is
(A) in second normal normal form but not in third normal form
(B) in third normal form but not in BCNF
(C) in BCNF
(D) in none of the above
Page 9
CS Topicwise 2001-2010
Database
www.gatehelp.com
SOLUTION
Consider the set of relations shown below and the SQL query that
follow:
Students:(Roll_number,Name,Date_of_birth)
Courses:(Course_number,Course_name,Instructor)
Grades:(Roll_number,Course_number,Grade)
select distrinct Name
from Students, Courses, Grades
Where Students,Roll_number=Grades. Toll_number
and Courses. Instructor=Korth
and Courses. Course_number=Grades. Course_number
and Grades.grade=A
Which of the following sets is computed by the above query?
(A) Names of students who have got an A grade in all courses taught
by Korth
(B) Names of students who have got an A grade in all courses
(C) Name of students who have got an A grade in at least one of the
courses taught by Korth
(D) None of the above
Page 10
www.gatehelp.com
CS Topicwise 2001-2010
Database
SOLUTION
Names are unique since selected distinct, so one person will be selected
only once, inspite of the has grade A in any no. of courses taught by
korth.
So if a name appearing, it is not necessary that he had grade A in all
the courses, but it has A in at least 1 course.
Hence (C) is correct option.
Question. 5
Consider three data items D1,D2 and D3 and the following execution
schedule of transactions T1, T2 and T3. In the diagram, R (D) and
W (D) denote the actions reading and writing the data item D
respectively.
T1
T2
T3
R(D3);
R(D2);
R(D2);
R(D2);
R(D3);
R(D1);
R(D1);
W(D2);
W(D3);
R(D1);
R(D2);
W(D2);
W(D1);
(A) The schedule is serializable as T2; T3;T1;
(B) The schedule is serializable as T2; T1;T3;
(C) The schedule is serializable as T3; T2; T1;
(D) The schedule is not serializable
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
dependency in between them.
So we draw the graph.
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Database
Student(rollno,name,address)
Enroll(rollno,courseno, coursename)
where the primary keys are shown underlined. The number of tuples
in the student and Enroll tables are 120 and 8 respectively. What are
the maximum and minimum number of tuples that can be present in
(Student*Enroll), where * denotes natural join?
(A) 8,8
(B) 120,8
(C) 960,8
(D) 960,120
SOLUTION
The boundary cases are when either all the tuples of Enroll table
belong to one roll no. , so there can be at most 8 roll no & courses
no. combinations or the other case is when all the tuples belong to
different roll no. this also has 8 tuples.
So
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
CS Topicwise 2001-2010
Database
www.gatehelp.com
(B) (i),(iv),(vii)
(C) (i),(iii),(v),(vi),(viii)
(D) (ii),(v),(viii)
SOLUTION
(D) 4 NF
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
Hence (A) is correct option.
Question. 10
Consider the relation Student (name, sex, marks), where the primary
key is shown underlined, pertaining to students in a class that has at
least one boy and one girl. What does the following relational algebra
expression produce?
name (rsex = females (Student)) Pname (Student
(sex = female
/ x = male
/ marks # m)
rn, x, m (student))
This query first computes join where marks are less than or equal to
marks are less than or equal to max marks, & then selects the name
of all the girl students with more marks than all the boys students.
Hence (D) is correct option.
Question. 11
(B) 25
(C) 26
(D) 27
SOLUTION
Page 15
CS Topicwise 2001-2010
Database
www.gatehelp.com
P 1 search fields.
= 512
= 512
= 526
P 526
20
, 26
Hence (C) is correct option.
Question. 12
www.gatehelp.com
CS Topicwise 2001-2010
Database
YEAR 2005
Question. 13
B+ trees each node size is kept almost same to the block size of the
system this cause on record data transfer from disk to memory one
block at a time.
Hence (D) is correct option.
Question. 14
CS Topicwise 2001-2010
Database
www.gatehelp.com
Question. 15
(B) r 1 s = r
(C) r 1 s
(D) r * s = s
SOLUTION
r 2 r1 & r 2 r2
s = r1 ) r2 ) denotes natural join.
So here s would have all the combinations of r1 = A, B, C(r) & r2 = A, D(r)
product & certainly have more tuples than original r .
So
r 1s
Since s would have all the tuples of r but also has some extra.
Hence (C) is correct option.
Question. 16
Let E1 and E2 be two entities in an E/R diagram with simple singlevalued attributes. R1 and R2 are two relationships between E1 and E2
where R1 is one-to-many and R2 is many-to-many. R1 and R2 do not
have any attributes of their own. What is the minimum number of
tables required to represent this situation in the relational model?
(A) 2
(B) 3
(C) 4
(D) 5
SOLUTION
Page 18
www.gatehelp.com
CS Topicwise 2001-2010
Database
C
4
4
3
2
2
5
4
(D) 1
SOLUTION
The relation book (title, price) contains the titles and prices of
different books. Assuming that no two books have the same price,
what does the following SQL
select title
from book as B
Page 19
CS Topicwise 2001-2010
Database
www.gatehelp.com
where (select count(*)
from book as T
where T. price>B.Price)<5
(A) Titles of the four most expensive books
(B) Title of the fifth most inexpensive book
(C) Title of the fifth most expensive book
(D) Titles of the five most expensive books
SOLUTION
It selects all those book titles where the price of the book has difference
than most expensive book not more than 5.
So it selects five most expensive books.
Hence (D) is correct option.
Question. 19
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Database
CS Topicwise 2001-2010
Database
www.gatehelp.com
rank customers according to decreasing balance. The customer with
the largest balance gets rank 1. Ties are not broken but ranks are
skipped: if exactly two customers have the largest balance they each
get rank 1 and rank 2 is not assigned.
Query 1 : Select A. customer, count (B. customer) from account A,
account B where A. customer
Query 2 : Select A. customer, 1+count(B. customer)from account
A, accountB where A, balance<B, balance 7 group by A.
customer
Consider these statements about Query 1 and Query 2.
1.
Query 1will produce the same row set as Query 2 for some but
not all databases
2.
3.
4.
5.
Assigning rank with a pure relational Query takes less time than
scanning in decreasing balance order the assigning ranks using
ODBC
(B) 1 and 3
(C) 1 and 4
(D) 3 and 5
SOLUTION
Consider an example
Customer Balance Correct Rank Query 1 (Rank) Query 2 (Rank)
A
40
36
36
44
44
incorrect
correct
www.gatehelp.com
CS Topicwise 2001-2010
Database
statement 1 is correct.
Statement 4 is also correct.
So option (C) is also correct.
More effective query.
Select A : customer , 1 + count (B : customer) from amount A,
account B where A balance < B : balance group by A : balance
Question. 22
Query 1
CS Topicwise 2001-2010
Database
www.gatehelp.com
repeating, so even when one student enrolled in one course only then
Query 1 and Query 2 results in some rows otherwise their result is
always same.
Query 3 cant return few rows than Query 2 in any case.
Hence (B) is correct option.
Question. 23
A disk seek takes 4 ms . disk data transfer bank width is 300 MB/s
and checking a tuple to see if amount is greater x takes 10 s . Which
of the following statements is correct?
(A) Plan 1 and Plan 2 will not output identical row sets for all
databases
(B) A course may be listed more than once int the output of Plan 1
for some databases
(C) For x = 5000, Plan 1 executes faster than Plan 2 for all databases
(D) For x = 9000, Plan 1 executes slower than Plan 2 for all databases
Page 24
www.gatehelp.com
CS Topicwise 2001-2010
Database
SOLUTION
Plan 1 selects some tuples which are greater than x , this is best
strategy for query evaluation to perform selection as early as possible,
to reduce size of the relation.
So plane 1 will execute faster than plan 2 for x = 5000 .
Since all the tuples required gets selected.
Hence (C) is correct option.
Question. 24
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
(C) Courses in which only male students are enrolled
(D) None of the above.
SOLUTION
The sub-query finds employees who are male & have supervisors.
So sub-query results all male employers with at least 1 supervisor
and whole query results all those employee names with no immediate
female subordinates.
Hence (C) is correct option.
Question. 27
www.gatehelp.com
CS Topicwise 2001-2010
Database
Page 27
CS Topicwise 2001-2010
Database
www.gatehelp.com
SOLUTION
(B) 64
(C) 67
(D) 68
SOLUTION
6 + (P 1) # 9 + P # 7 = 1024
16P 3 = 1024
16P = 1027
P = 1027
16
, 64
Hence (B) is correct option.
Question. 30
www.gatehelp.com
CS Topicwise 2001-2010
Database
Consider S1 schedule
S1
r1 (X) " read X process 1
r1 (Y) " read Y process 1
r2 (X) " read X process 2
r2 (Y) " read Y process 2
w2 (Y) " but this write cause r1 (Y)
w1 (X) Value obsolete, so not conflict serializable.
S2
r1 (X) X read by 1
r2 (X) X read by 2
r2 (Y) Y read by 3
w2 (Y) Here also no problem since only
r1 (X) Transaction 2 has read Y &
w1 (X) It is manipulating
r1 (Y) is after that so conflict serializable.
Hence (C) is correct option.
YEAR 2008
Question. 31
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
So indexing is done by ordering all the instances of attribute &
clustering the same values, so index entry for only the first item is
needed only.
This attribute has repeating values.
So cant be primary key, so non key.
Hence (A) is correct option.
Question. 32
P (D S)
II
P (R) D P (S)
III
IV
SOLUTION
II
Selects P from R & P from S & then join so may have same
tuples as I.
www.gatehelp.com
CS Topicwise 2001-2010
Database
II.
III.
Assume {Author, Title} is the key for both schemes: which of the
following statements is true?
(A) Both Book and Collection are in BCNF
(B) Both Book and Collection are in 3NF only
(C) Book is in 2NF and Collection is in 3NF
(D) Both Book and Collection are in 2NF only
SOLUTION
In relation collection
Title Author " Catalog_no.
So non key attribute Catalog_no. is fully dependent upon key
attributes.
So it is in 3NF .
Relation Book is in 2NF
Publisher and year attributes are transitively dependent upon title
Author, so 3NF is not there.
Hence (C) is correct option.
Question. 34
Consider a file of 1684 records. Each record is 32 bytes long and its
key field is of size 6 bytes. The file is ordered on a non-key field, and
the file organization is unspanned. The file is stored in a file system
with block size 1024 bytes, and the size of a block pointer is 10
bytes. If the secondary index is built on the key field of the file, and
a multi-level index scheme is used to store the secondary index, the
number of first-level and second-level blocks in the multi-level index
are respectively
(A) 8 and 0
(B) 128 and 6
(C) 256 and 4
Page 31
CS Topicwise 2001-2010
Database
www.gatehelp.com
SOLUTION
Question. 35
(B) 3
(C) 4
(D) 5
SOLUTION
Which of the following is a correct attribute set for one of the tables
for the correct answer to the above question?
Page 32
(A) {M1,M2,M3,P1}
(B) {M1,P1,N1,N2}
(C) {M1,P1,N1}
(D) {M1,P1}
www.gatehelp.com
CS Topicwise 2001-2010
Database
SOLUTION
Two tables in the scenario will be M1, M2, M 3, P1 which is for relation
R1 & N1, N2, P1, P2 with P1 as primary key N1 is a weak entity set.
This is for relation R2 .
Hence (A) is correct option.
YEAR 2009
Question. 37
Consider two transactions T1 and T2 and four schedules S1, S2, S3, S4 of
T1 and T2 as given below :
T1: R1 [x] W1 [x] W1 [y]
T2: R2 [x] R2 [y] W2 [y]
S1: R1 [x] R2 [x] R2 [y] W1 [x] W1 [y] W2 [y]
S2: R1 [x] R2 [x] R2 [y] W1 [x] W2 [y] W1 [y]
S3: R1 [x] W1 [x] R2 [x] W1 [y] R2 [y] W2 [y]
S4: R2 [x] R2 [y] R1 [x] W1 [x] W1 [y] W2 [y]
Which of the above schedules are conflict-serializable?
(A) S1 and S2
(B) S2 and S3
(C) S3 only
(D) S4 only
SOLUTION
Schedule S2
T1
T1
R (x)
T2
T2
R (x)
Page 33
CS Topicwise 2001-2010
Database
www.gatehelp.com
No cycle
Schedule S 4
T1
T2
No cycle
Cycle exists
In S2 & S 3 no cycle exists, so conflict serializable.
Hence (B) is correct option.
Question. 38
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
Page 34
www.gatehelp.com
CS Topicwise 2001-2010
Database
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
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
SOLUTION
Order = 3 so any node can have 3 child nodes i.e 3 pointer values.
10, 3, 6, 8, 4, 2, 1
Page 35
CS Topicwise 2001-2010
Database
www.gatehelp.com
Total 4 splits
Hence (C) is correct option.
Question. 39
II.
III.
IV.
From R, S
Where R.c = S.c
Which of the above queries are equivalent?
(A) I and II
(B) I and III
(C) II and IV
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Database
The sub-query results all those parts which are not blue.
The sub-query returns all those suppliers which have the blue parts.
And final return from the query are the supplier ids of all those
suppliers which supplied a non blue part.
Question. 41
Assume that, in the suppliers relation above, each supplier and each
street within a city has a unique name, and (same, city) forms a
candidate key. No other functional dependencies are implied other
than those implied by primary and candidate keys. Which one of the
following is TRUE about the above schema ?
(A) The schema is in BCNF.
(B) The schema is in 3NF but not in BCNF.
Page 37
CS Topicwise 2001-2010
Database
www.gatehelp.com
(C) The schema is in 2NF but not in 3NF.
(D) The schema is not in 2NF.
SOLUTION
(D) 4
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Database
Table : passenger
pid
pname
Age
Sachin 65
Rahul 66
Sourav 67
Anil
69
Table : Reservation
pid class
tid
AC
8200
AC
8201
SC
8201
AC
8203
SC
8204
AC
8202
What pids are returned by the following SQL query for the above
instance of the tables ?
SELECT pid
FROM Reservation
WHERE class= AC AND
EXISTS (SELECT)
FROM Passenger
WHERE age>65 AND
Passenger.pid = Reservation.pid)
(A) 1,0
(B) 1, 2
(C) 1, 3
(D) 1, 5
SOLUTION
CS Topicwise 2001-2010
Database
www.gatehelp.com
Question. 44
2-phase locking
II
Time-stamp ordering
(A) I only
(B) II only
SOLUTION
T2
T3
Read (Y)
Read (Y)
Write (X)
Write (X)
Read (X)
Write (X)
Which one of the schedules below is the correct serialization of the
above ?
(A) T1 " T3 " T2
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Database
(B) 200
(C) 300
(D) 2000
SOLUTION
R has 200 tuples & has 100 tuples, the common attribute for natural
join is B in both relations consider a condition cohen all tuples in
S has distinct value of B , So a natural join can have maximum 100
tuples.
Hence (A) is correct option.
**********
Page 41
www.gatehelp.com
YEAR 2001
Question. 1
(A) xy + y'z
(B) wx'y' + xy + xz
(D) xz + y
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
SOLUTION
Question. 2
Page 2
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
SOLUTION
Question. 3
(B) DBC
(C) DE5
(D) 9E7
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Binary
: 0010 0001 1011
2's comp
: 1101 1110 0101
Hexadecimal D
E
5
(DES) 16
Hence (C) is correct option.
Question. 4
Consider the circuit shown below. The output of a 2:1 Mux is given
by the function (ac' + bc).
(D) f = x1 + x2
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
Which one of the following is the correct state sequence of the circuit
?
(A) 1, 3, 4, 6, 7, 5, 2
(B) 1, 2, 5, 3, 7, 6, 4
(C) 1, 2, 7, 3, 5, 6, 4
(D) 1, 6, 5, 7, 2, 3, 5
SOLUTION
Q0
Q1
Q2
Clk
Initially
YEAR 2002
Question. 6
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(A) xz + y'z
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
SOLUTION
(B) 11111
(C) 111111
(D) 10001
SOLUTION
Given ( 15) 10
Binary of 15 = (01111) 2
2s complement of 15 would represent ( 15).
0 1111
(10001) 2
Hence (D) is correct option.
Question. 9
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Question. 10
SOLUTION
Consider the following logic circuit whose inputs are functions f1, f2, f3
and output is f
Given that
f1 (x, y, z) = (0, 1, 3, 5)
f2 (x, y, z) = (6, 7), and
f (x, y, z) = (1, 4, 5)
f3 is
(A) (1, 4, 5)
(B) (6, 7)
(C) (0, 1, 3, 5)
SOLUTION
f1 (x, y, z) = (0, 1, 3, 5)
Page 8
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
= xy
f (x, y, z) = (1, 4, 5)
= xy' + y'z
f (x, y, z) = f1 f2 : f3
= f1 : f2 + f3
= xy (x'y' + y'z + x'z) + (xy' + y'z)
f3 = xy'z + xy'z' + xy'z + x'y'z
f3 = (1, 4, 5)
Hence (A) is correct option.
Question. 12
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(B) xy + z
(C) x + y
SOLUTION
A1 A 0 EN (MUX) work
0
do not
(MUX) Work
do not
(B) xyz
(C) xy' + z
SOLUTION
f (x + y, y) = (x + y) ' + y
& x+y+y
f (f (x + y, y), z) = x + y + y + z
& (x + y : y ) + z
[(x + y) : y ] + z
Page 10
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
[xy + yy ] + z
xy + z
Hence (C) is correct option.
Question. 14
What are the states of the Auxiliary Carry (AC) and Carry Flag
(CY) after executing the following 8085 program ?
MIV H,
5DH
MIV L,
6BH
MOV A,
ADD L
(A) AC = 0 and CY = 0
(B) AC = 1 and CY = 1
(C) AC = 1 and CY = 0
(D) AC = 0 and CY = 1
SOLUTION
0 is the carry so CY = 0
(1) is auxillary carry AC = 1
Hence (C) is correct option.
Question. 15
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(A) Outputs the sum of the present and the previous bits of the
input.
(B) Outputs 01 whenever the input sequence contains 11
(C) Outputs 00 whenever the input sequence contains 10
(D) None of the above.
SOLUTION
0(A)
00
0(A)
1(B)
01
1(B)
0(A)
01
1(B)
1(C)
10
1(C)
1(C)
10
1(C)
0(A)
01
(B) 11100100
(C) 11010111
(D) 11011011
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
(A)
11100111 " 00011001 = 25
(B)
11100100 " 00011100 = 28
(C)
11010111 " 00101001 = 41
(D)
11011011 " 00100101 = 37
From all only option (A) is divisible by 5.
Shortcut : To convert 2s complement no. directly into original binary,
we should complement all the digits from MSB till the last one (1).
Keep the last 1 from the LSB as it is. Observe in the example.
Question. 17
(D) 231
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Question. 18
(D) 8
SOLUTION
op 1 op 2
State
Intial
nK zK = 2
zK nK = 2
Not applicable
Initial
nK zK = 2
zK nK = 2
is correct
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
(A) (11,9)
(B) (9,13)
(C) (9,10)
(D) (11,11)
SOLUTION
Sum of product
= wy + w'y' + z'wx' + xyz'
12 34 567 8910
Literal count =10
Product of sum
= (y' + z') (z' + y) (w' + z')
(x + z + w)
Lateral count =9
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Question. 20
Consider the following circuit composed of XOR gates and noninverting buffers.
(A) 1
(B) 2
(C) 3
(D) 4
SOLUTION
Transition
II
Transition
III
Transition
So total 3 transitions
Hence (C) is correct option.
YEAR 2004
Question. 21
www.gatehelp.com
(A) x' + y'
(B) x + y
(C) x + y'
(D) x' + y
CS Topicwise 2001-2010
Digital Logic
SOLUTION
x'y' + xy + xy'
x' (y + y') + xy
(A + A') = 1
x' + xy
(A + AB) = (A + A) : (A + B)
(x' + x) : (x' + y)
1 : (x' + y)
x' + y
Hence (D) is correct option.
Question. 22
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Question. 23
If 73x (in base-x number system) is equal to 54, (in base-y number
system), the possible values of x and y are
(A) 8, 16
(B) 10, 12
(C) 9, 13
(D) 8, 11
SOLUTION
(73) x = (54) y
7x + 3 = 5y + 4
(x', y)
7x + 3
8, 16
59
10, 12
73
9, 13
64
8, 11
59
Hence (D) is correct option.
5y + 4
84
64
69
59
Question. 24
SOLUTION
Expression 1
(113.0 + ( 111.) + 7.51
(113.0 111.0) + 7.51
2.0 + 7.51
9.51
rounded off
10
Expression 2
113.0 + ( 111.0 + 7.51)
113.0 + ( 103.49)
113.0 103.00
10.0
rounded off
Hence (D) is correct option
Page 18
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
Question. 25
(D) 5
SOLUTION
1 digit = 5
0 otherwise
Here for 0 to 4 we have 0 output, from 5 to 9 1 output & for 10 to 15
dont care. 1 octed & 2 pounds.
a + bd + bc
a + b (d + c)
Two OR gates
One AND gate
Total 3
Hence (B) is correct option.
Question. 26
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(C) a'c only
SOLUTION
(B) Q2 + Q1
(D) Q1 5 Q2
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
A 4-bit carry look ahead adder, which adds two 4-bit numbers, is
designed using AND, OR, NOT, NAND, NOR gates only. Assuming
that all the inputs are available in both complemented and
uncompensated forms and the delay of each gate is one time unit,
what is the overall propagation delay of the adder? Assume that the
carry network has been implemented using two-level AND-OR logic.
(A) 4 time units
SOLUTION
Carry of any higher order bit is dependent upon previous order bit
addition generated carry.
C out = g 0 + p 0 C in
P3 P2 P1 P0
g 3 g 2 g1 g 0
c 3 c 2 c1 c 0
c 3 g 3 + P3 g2 + P3 P2 g1 +| P3 P2 P1 g 0 + P3 P2 P2 P0 C in
This is 4 bit look ahead adder equation total gate delay
= 1+1+2+2
=6
Hence (B) is correct option.
Question. 29
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
SOLUTION
So
B = 00001010
MSB is 0 so + ve no. decimal 10.
B = 10
A # B = 6 # 10
= 60
Binary of 60 = 00111100
2s complement 11000100
Hence (A) is correct option.
YEAR 2005
Question. 30
Page 22
(A) f is independent of X
(B) f is independent of Y
(C) f is independent of Z
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
SOLUTION
f = X:Y:Y:Z
= X:Y+Y:Z
= X:Y+Y:Z
For redundant check we need to draw K map to min terms.
XY (Z + Z ) + (X + X ) : YZ
XY Z + XY Z + XYZ + X YZ
X Y + YZ + XZ
Hence (D) is correct option.
Question. 31
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Using 4 bits.
1 1 1 1,. . . . . .0 0 0 0, . . . . .01 1 1
7
+7
This would be the range.
So (2n 1 1) to + (2n 1 1)
Hence (B) is correct option.
Question. 32
(B) D78
(C) D71
(D) 32F
SOLUTION
(657) 8 = (?) 16
Making binary
0 0 01A BB
0 1 01 1 1 1 = (IAF) 16
S BCS
Hence (A) is correct option.
Question. 33
SOLUTION
Page 24
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
BC D + A C D + A B D
So min terms are
B C D + A C D + AB D
Hence (A) is correct option.
Question. 34
(B) A0 A1 A2 'A3 A4
(C) A1 A2 A2 'A3 A4
(D) A1 A2 'A3 A4 A5
SOLUTION
Q 0 = 0 Q1 = 1 A i
Y
Page 25
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
0
A0 '
A0 '
A1 '
A0 '
A2 '
A1 '
A3 '
A1 '
A4 '
A3 '
A5 '
A4 '
Q0
Q0
Q1
Q1
Q1
Q1
Q1
So the FSM takes input from LSB side it doesnt change state till the
first 1 comes from LSB side, after that it complement all the bits.
This is logic for 2s complement.
Hence (B) is correct option.
Page 26
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
Question. 36
Qn + 1
Action
Qn
No change
Reset
Set
D here AX + X'Q'
Truth table for ckt
and so on.
Hence (D) is correct option.
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Solve the problems and choose the correct answers.
Consider the following floating point format
(B) 0D 4D
(C) 4D 0D
(D) 4D 3D
SOLUTION
Sign bit 0
Exponent = 13
Excess 64 = 13 + 64 = 77 = 1001101
Binary of 239
www.gatehelp.com
0
1001101
0100
1101
0011
1101
CS Topicwise 2001-2010
Digital Logic
00111101
(D) 4A E8
SOLUTION
Point
Format
1001010
11101000
0100
1010
1110
1000
GAE8
Hence (D) is correct option.
Page 29
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
YEAR 2006
Question. 39
You are given a free running clock with a duty cycle of 50% and a
digital waveform f which changes only at the negative edge of the
clock. Which one of the following circuits (using clocked D flip flops)
will delay the phase of f by 180c ?
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(A) xz + xy + yz
(C) xz + xy + yz
(B) xz + xy + yz
(D) xz + xy + yz
SOLUTION
MVXI
Selects X when Z = 0
Y' when Z = 0
MVX II
Selects (XZ' + Y'Z) when y = 0
X
when y = 0 so (XZ' + YZ) Y' + XY
Simplifying = xz'y' + zy'y' + xy
= xz'y' + xy (z + z') + zy'
= xz'y' + xyz + xyz' + zy' (x + x')
= xz'y' + xyz + xyz' + xy'z + x'y'z
= y'z + xy'z + xyz' + xyz + xyz' [a + a = a]
= y'z + xz' (y + y') + xy (z + z')
= y'z + xz' + xy
Page 31
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Hence (A) is correct option.
Question. 41
Given two three bit numbers a2 a1 a0 and b2 b1 b0 and c, the carry in, the
function that represents the carry generate function when these two
numbers are added is
(A) a2 b2 + a1 a1 b1 + a2 a1 a0 b0 + a2 a0 b1 b0 + a1 b2 b1 + a1 a0 b2 b0 + a0 b2 b1 b0
(B) a2 b2 + a2 b1 b0 + a2 a1 b1 b0 + a1 a0 b21 b1 + a1 a0 b2 + a1 a0 b2 b0 + a2 a0 b1 b0
(C) a2 + b2 + (a2 5 b2)[ a1 + b1 + (a1 5 b1)( a0 + b0)]
(D) a2 b2 + a2 a1 b1 + a2 a1 a0 b0 + a2 a0 b1 b0 + a1 b2 b1 a1 a0 b2 b0 + a0 b2 b1 b0
SOLUTION
a 2 a1 a 0 b 2 b 1 b 0 C
0
Case I
Question. 42
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
, we would like the function to remain true as the input changes from
i1 to i2 (i1 and i2 differ in exactly one bit position), without becoming
false momentarily. Let f (w, x, y, z) = / (5,, 711, 12, 13, 15). Which of
the following cube covers of f will ensure that the required property
is satisfied?
(A) wxz, wxy, xyz, xyz, wyz
SOLUTION
Given function f (w, x, y, z) = (5, 7, 11, 12, 13, 15) draw K-map of the
above function.
(B) an 1 bn 1 cn 1 + an 1 bn 1 cn 1
(C) cout 5 cn 1
(D) an 1 5 bn 1 5 cn 1
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
1 C in
0 1
0 a
1 1
1 b
1 1
1 C out 1
1 1
Page 34
Binary h
h 3 h2 h1 h 0 (n + 1)
mod 16
g 3 g 2 g1 g 0
0000
0000
0001
0001
0001
0011
0010
0011
0010
0011
0010
0110
0100
0110
0111
0101
0111
0101
0110
0101
0100
0111
0100
1100
1000
1100
1101
www.gatehelp.com
1001
1101
10
1111
1010
10 1111
11
1110
1011
11 1110
12
1010
1100
12 1010
13
1011
1101
13 1011
14
1001
1110
14 1001
15
1000
1111
15 1000
0000
CS Topicwise 2001-2010
Digital Logic
(D) 2n
SOLUTION
0 or 1, so for expression
terms 2n . These 2n terms
and nos., suppose 2n = M .
n
or 22 ways.
Question. 46
How many 3-to-8 line decoders with an enable input are needed to
construct a 6-to-64 line decoder without using any other logic gates?
(A) 7
(B) 8
(C) 9
(D) 10
SOLUTION
Page 35
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
But we need one more decoder i.e for combining result.
8 + 1 = 9 decoders.
Hence (C) is correct option.
Question. 47
2 qlead
xz'
1st qlead
nd
x'z
2 qlead
xz' + x'z xz' + x'z
So independent of 2 variables.
Hence (B) is correct option.
Question. 48
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
SOLUTION
xz + w'y'z' + wx'y'
Hence (B) is correct option.
Question. 49
SOLUTION
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
= XZ + X'Z'
= X (Y + Y') Z + X' (Y + Y') Z'
= XYZ + XY'Z + X'YZ' + X'Y'Z' valid
R: X ) Y ) Z = 1
(XY + X'Y') ) Z & (XZ + X'Y') Z + (XY + X'Y') Z'
& XYZ + X'Y'Z + [(XY : X'Y') Z']
& XYZ + X'Y'Z + [(X + Y ) : (X + Y)] Z'
& XYZ + X'Y'Z + X'YZ' + XY'Z' =
Y 1
So invalid
Hence (A) is correct option.
Question. 50
Suppose only one multiplexer and one inverter are allowed to be used
to implement any Boolean function of n variables. What is the
minimum size of the multiplexer needed?
(B) 2n + 1 line to 1 line
(A) 2n line to 1 line
(C) 2n 1 line to 1 line
SOLUTION
www.gatehelp.com
(A) 6,3
(B) 10,4
(C) 6,4
(D) 10,5
CS Topicwise 2001-2010
Digital Logic
SOLUTION
The control signal functions of 4-bit binary counter are given below
(where X is dont care)
Clear Clock Load Count Function
1
Clear to 0
No change
Load input
Count next
Assume that the counter and gate delays are negligible. If the counter
starts at 0, then it cycles through the following sequence
(A) 0,3,4
(B) 0,3,4,5
(C) 0,1,2,3,4
(D) 0,1,2,3,4,5
Page 39
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
SOLUTION
From the truth table for the counter ckt we can see that when counter
= 1. & load = 0 , count next is the function.
So it would count from 0 to 4 & then clear to 0 & again start if clock
input is increasing.
Hence (C) is correct option.
YEAR 2008
Question. 53
SOLUTION
In the karnaugh map shown below, X denoted a dont care term. What
is the nominal form of the function represented by the karnaugh map
Page 40
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
SOLUTION
Given K-map is
quad 1 " a b
quad 2 " b d
pair 1 " a c d
So
a b + b d + a d (c + c )
a b+b d+a d
Hence (D) is correct option.
Question. 55
Let a denote number system radix. The only value(s) of r that satisfy
the equation 121 + 11, is/are
(A) decimal 10
(B) decimal 11
(C) decimal 10 and 11
SOLUTION
(121) r = (11) r
If r = 10 it is true it cant be 2 since bit value cant be 2 then. It is
not true for r = 11
It is true for 3 to 10.
So it is true for
r>2
Hence (D) is correct option.
Page 41
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
Question. 56
Give f1, f3 and f in canonical sum of products form (in decimal) for the
circuit
f1 = /m (4, 5, 6, 7, 8)
f3 = /m (1, 6, 15)
f = /m (1, 6, 8, 15)
Then f2 is
(A) /m (4, 6)
(B) /m (4, 8)
(C) /m (6, 8)
(D) /m (4,6,8)
SOLUTION
(A) P.Q
Page 42
(B) P.R
www.gatehelp.com
(C) P.Q + R
CS Topicwise 2001-2010
Digital Logic
(D) P.R + Q
SOLUTION
= (P + Q ) : (P Q + PR) : (P R + Q)
= (PPQ + PPR + PQ Q + PQR) (P R + Q )
= (P Q + PR + PQ + PQR) (P R + Q)
= (PQ + PR + PQR) (P R + Q )
= [PQ (1 + R) + PR] (P R + Q)
= P (Q + R) (P R + Q )
= (P P R + PQ ) (Q + R)
= PQ : (Q + R)
= PQ + PQR
= PQ (1 + R)
= PQ
Hence (A) is correct option.
YEAR 2009
Question. 58
(1217) 8 is equivalent to
(A) (1217) 16
(B) (028F) 16
(C) (2297) 10
(D) (0B17) 16
SOLUTION
= (1217) 8
= 001010001111
SSS
= (028F) 16
Hence (B) is correct option.
Question. 59
(B) 3
(C) 4
(D) 5
Page 43
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
SOLUTION
(D) m2 + m 3 + m 4 + m5
SOLUTION
Given expression is
f (P, Q, R) = PQ + QR + PR
For min term expansion we add the remaining variables in the
expression.
= PQ (R + R ) + (P + P ) QR + P (Q + Q ) R
= PQR + PQR + PQR + PQR + PQR + PQR
= PQR + PQR + PQR + PQ R
= m7 + m 6 + m2 + m 4
= 111 + 110 + 010 + 100
So = m2 + m 4 + m6 + m7
Page 44
www.gatehelp.com
CS Topicwise 2001-2010
Digital Logic
(D) (987B) 16
SOLUTION
Ps 2s complement.
= (F87B) 16
Is complement = F87B 1
= (F87A) 16
In base 16 complement is done by subtracting from 15 i.e F.
P = (0785) 16
= (0000 0111 1000 0101) 2
= 1 # 2c + 1 # 22 + 1 # 27 + 1 # 28 + 1 # 29 + 1 # 210
P = 1925
8 # P = 8 # 1925 = 15400
Its binary
0011110000101000
SSSS
For hexadecimal make pairs of 4 i.e. (3C28) 16
2s complement P = 1100 0011 1101 1000
C
3
D
8
2s complement of P = (C3D8) 16
Hence (A) is correct option.
Question. 62
(A) P 5 Q 5 R
(B) P 5 Q 5 R
Page 45
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(D) P + Q + R
(C) P + Q + R
SOLUTION
S1 & so are the select bits which are used to select any 1 of the 4
inputs.
Selection table
S1 (P) S 0 (Q) Input
0
0R
1R
2R
3R
Page 46
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
(A) Q + R
(B) P + Q
(C) P + R
(D) P + Q + R
SOLUTION
After 1 stage
P+Q
Q+R
Q+R
P+R
After 2 stage
P+Q+Q+R
P+R+Q+R
After 3 stage
= P+Q+Q+R+P+R+Q+R
"A + B = A : B
= (P + Q + Q + R ) : (P + R + Q + R )
"A = A
= (P + Q + Q + R ) : (P + R + Q + R )
"A + B = A : B
= (P + Q) : (Q + R) : (P + R) : (Q + R)
= Q + PR : R + PQ
= Q + PR + R + PQ
= R (P + 1) + Q (P + 1)
= (Q + R)
Hence (A) is correct option.
Question. 64
In the sequential circuit shown below, if the initial value of the output
Q1 Q 0 is 00, what are the next four values of Q1 Q 0 ?
SOLUTION
There are 2 T-toggle flip flops in the ckt. Truth table for TFF.
Page 47
CS Topicwise 2001-2010
Digital Logic
www.gatehelp.com
CP
Qn + 1
Qn
Qn previous state
Qn
CP clock pulse
Qn
Qn + 1 next state
T toggle input
Since initially Q, Q 0 = 00, so during 1st clock cycle both T & clock
signals in ckt are 1. After Q 0 = 1 this fed to 2nd TFF which invert
previous state Q1 = 1 so Q1 Q 0 = 11
11 when fed to next cycle clock = 1 so Q 0 = 0 Q1 = 1 since no inversion
Q, Q 0 = 10
In next cycle clock = 1 Q 0 = 1 inverse, Q1 = 0 in the end Q1 Q 0 = 00
So order 11, 10, 01, 00
Hence (A) is correct option.
**********
Page 48
www.gatehelp.com
YEAR 2001
Question. 1
(B) Shortest-Job-First
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
(C) Highest-Response-Ratio-Next (D) First-come-First-Served
SOLUTION
Here the running times r1 ....rn are already known, single processor
system. In this scenario, throughput i.e. CPU is maximum utilized in
shortest job first scheduling.
Hence (B) is correct option.
Question. 3
(B) Disk
(C) ROM
SOLUTION
Swap space is the memory space where the part of the program not
currently in main memory for execution is stored, this program part
can be swapped into memory when required.
This space is generally in disk.
Hence (B) is correct option.
Question. 4
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
Question. 5
(D) 24 MB
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
the while loop should be
(A) flag [j]= true and turn =j
SOLUTION
While loop if true predicate then the program enters into critical
region. This program enters into critical region of flag [i]=true act
as semaphore, & true =j, the requirement of resource is by some
other process.
Hence (B) is correct option.
YEAR 2002
Question. 7
Round robin is preemptive since processes are cycled for CPU time,
& run for a particular time stamp in one cycle. Multilevel queue
scheduling maintains various quenes, each having different priorities.
But in FIFO scheme, only the process which enters once, would be
completed first, so no. preemption.
Hence (B) is correct option.
Question. 8
The optimal page replacement algorithm will select the page that
(A) Has not been used for the longest time in the past.
(B) Will not be used for the longest time in the future.
(C) Has been used least number of times.
(D) Has been used most number of times
Page 4
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
(B) A and B
(C) A and C
(D) A, B and C
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
SOLUTION
When indexes are created, the maximum no. of blocks given to a file
are totally dependent upon size of the index which tells how many
blocks can be there, & size of each block.
Hence (B) is correct option.
YEAR 2003
Question. 11
Using a larger block size in a fixed block size file system leads to
(A) better disk throughput but poorer disk space utilization
(B) better disk throughput and better disk space utilization
(C) poorer disk throughput but better disk space utilization
(D) poorer disk throughput and poorer disk space utilization
SOLUTION
Using larger block size in a fixed block size system lead to poor disk
space utilization due to data items which are very small comparable
to block size cause fragmentation. But it leads to better disk through
put since no. of blocks needs to fetch & replace become less.
Hence (A) is correct option.
Question. 12
32 bit virtual address, i.e. 232 kB of virtual memory & 1 kB page size.
So total pages = 232 .
So. we need to maintain a page table of 232 rows, this require 4
GB main memory which is quite impractical due to large memory
Page 6
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
overhead.
Hence (C) is correct option.
Question. 13
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
is also 1ns .
Question. 14
Assuming that no page faults occur, the average time taken to access
a virtual address is approximately (to the nearest 0.5 ns )
(B) 2 ns
(A) 1.5 ns
(C) 3 ns
(D) 4 ns
SOLUTION
TLB is successfully 96% of total request & for remaining 4%. RAM
is accessed twice.
So average time taken.
= .96 (1 + (0.9 # 1) + 0.1 # (1 + 10))
+ .04 (21 + (.9 # .1)) + 0.1 # (1 + 10)
= .96 (1 + .9 + 1.1) + 0.4 (21 + .09 + 1.1)
= .96 # 3 + 0.4 # 23
= 2.88 + .92
= 3.80 , 4 ns (Nearest .5)
Hence (D) is correct option.
Question. 15
Suppose a process has only the following pages in its virtual address
space; two contiguous code pages starting at virtual address
0 # 0000000, two contiguous data pages starting at virtual address
0 # 00400000,and a stack page starting at virtual address
0 # FFFFF000. The amount of memory required for storing the page
tables of this process is
(A) 8 KB
(B) 12 KB
(C) 16 KB
(D) 20 KB
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
Which of the following will ensure that the output string never
Page 9
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
contains a substring of the form 0.1 or 101 where n is odd?
(A) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
(B) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
(C) P(S) at W, V(S) at X, P(T) at Y, V(S) at Z, S initially 1
(D) (S) at W, V(T) at X, P(T) at Y, P(S) at Z, S and T initially 1
SOLUTION
SOLUTION
(I)
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
(B) 40%
(C) 25%
(D) 0%
SOLUTION
Page frames are allocated in main memory, for virtual memory pages.
This no. of page frames depends upon the instruction set architecture.
Hence (A) is correct option.
Question. 21
Consider the following set of processes, with the arrival times and the
CPU-burst times given in milliseconds
Process
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
P1
P2
P3
P4
0
1
2
4
5
3
3
1
(B) 5.75
(C) 6.00
(D) 6.25
SOLUTION
= 12 0 = 12
= 41 = 3
= 82 = 6
= 54 = 1
= 22
Avg turn around time = 22
4
T.A time for P1
P2
P3
P4
Total
= 5.5
Hence (A) is correct option.
Question. 22
Page 12
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
SOLUTION
:
while true do{
:......
:.....
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
access X & Y . So at L1 P (Sx ) which means now Sx = wait at L2 P (Sy)
Sy wait, this prevents process P2 to start access X & Y .
V (Sx ) & V (Sy) in the end of P1 makes Sx & Sy signal so that at L 3 &
L 4 P (Sx ) & P (Sy) can start.
Hence (D) is correct option.
Question. 24
A Unix-style I-node has 10 direct pointers and one single, one double
and one triple indirect pointers. Disk block size is 1 Kbyte, disk block
address is 32 bits, and 48-bit integers are used. What is the maximum
possible file size?
(A) 224 bytes
(B) 232 bytes
(C) 234 bytes
(D) 2 48 bytes
SOLUTION
Size of 1 block = 1 kB
Block addresses size 1 pointer size = 32 bit
= 4 bytes.
10
So no. of pointers in = 2 2 B
2B
1 block
So direct pointer will have
Double will have
Triple will have
= 256
= 10 # 1kB = 10kB
= 256 # 256 # 1 kB
= 256 # 256 # 256 # 1 kB
= 28 # 28 # 28 # 210 B
= 234 B
(C)
Page 14
/ si < (m + n)
i=1
(D)
/ si < (m * n)
i=1
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
/ Si
i=1
< (m + n)
(D) u + 10 = x and v ! y
SOLUTION
Initial value of a is let 10 and its address & a would be different for
both parent & child process so.
(A) & (B) are incorrect also parent process executes a = a 5 = 5 = u
& child executes a = a + 5 = 15 = x so u + 10 = x
Hence (D) is correct option.
YEAR 2006
Question. 27
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
(C) 3
(D) 4
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
If there are more than two processes and context & switching processes
is disabled in P then this implementation doesnt work properly and
cant synchronize the processes.
Hence (A) is correct option.
Question. 29
A CPU generates 32-bit virtual addresses. The page size is 4 KB. The
processor has a translation look-aside buffer (TLB) which can hold a
total of 128 page table entries and is 4-way set associative.
The minimum size of the TLB tag is
(A) 11 bits
(B) 13 bits
(C) 15 bits
(D) 20 bits
SOLUTION
TLB has 128 page table enteries, each page table would have. 64 bits
i.e. 32 + 32 virtual addresses.
So total memory required.
27 # 2 6
But 4 way set associative.
27 # 26 = 211
22
So 11 bits are required.
Hence (A) is correct option.
Question. 30
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
SOLUTION
Since both virtual and physical memory has 32 bit addresses, so there
is no need for address translation hardware is required.
Hence (C) is correct option.
Question. 31
(D) 16 units
SOLUTION
Process id
0
1
2
CPU burst 2
4
8
So we draw Gantt chart for scheduler
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
The operating system uses a shortest remaining compute time first
scheduling algorithm and schedules a new process either when the
running process get blocked on I/O or when the running process
finishes its compute burst. Assume that all I/O operations can be
overlapped as much as possible. For what percentage of time does the
CPU remain idle?
(A) 0%
(B) 10.6%
(C) 30.0%
(D) 89.4%
SOLUTION
Total
10
14
20
21
30
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
i has placed a request for an additional y , instances while holding the
xi instances it already has, There are exactly two processes p and q
such that yp = yq = 0 : Which one of the following can serve as a
necessary condition to guarantee that the system is not approaching
a deadlock?
(B) xp + xq # maxk ! p'q yk
(A) min(xp, xq) < maxk ! p, q yk
(C) min(xp, xq) < 1
SOLUTION
barrier(void) {
:
P(S)
:
Process_arrived++;
:
V (S) :
:
while (process_arrived=3);
:
P(S);
:
Precess_left++;
:
if(process_left==3)
:
process_arrived=0;
:
process_left+0;
:
}
:
V(S);
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
SOLUTION
Group-2
P. Gang Scheduling
1. Guaranteed Scheduling
2. Real-time Scheduling
3. Thread Scheduling
(A) P-3;Q-2;R-1
(B) P-1;Q-2;R-3
(C) P-2;Q-3;R-1
(D) P-1;Q-3;R-2
SOLUTION
Consider the following statements about user level threads and kernel
level threads. Which one of the following statements is FALSE?
(A) Context switch time is longer for kernel level threads than for
user level threads
(B) User level threads do not need any hardware support
(C) Related kernal level thread can be scheduled on different
processors in a multiprocessor system
Page 22
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
(D) Blocking one kernel level thread blocks all related threads
SOLUTION
Execution time
Arrival time
P1
20
P2
25
15
P3
10
30
P4
15
45
(B) 15
(C) 40
(D) 55
SOLUTION
P2 came at t = 15
Scheduled first time at t = 20 wait = 5 .
Wait between t = 30 & t = 40 due to short remaining time of new
process P3 .
Wait now = 5 + 10 = 15
Then complete at t = 55
Page 23
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
Hence (B) is correct option.
Question. 39
P0
P1
P2
Page 24
alloc
XYZ
121
201
221
request
XYZ
103
012
120
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
(A) P0
(B) P1
(C) P2
(D) None of the above, since the system is in a deadlock
SOLUTION
Initially.
Process
P0
P1
P2
Allow
XYZ
121
121
221
Request/need
XYZ
103
012
120
Available
XYZ
012
/* P1 */
while (true) {
while (true) {
wants1=true;
wants2 = true;
while(wants2==true);
/*
/*
Critical
Critical
Section*/
Section*/
wants 1 = false;
wants 2 = false;
/* Remainder section*/
/*Remainder section*/
Here, wants 1 and wants 2 are shared variables, Which are initialized
to false. Which one of the following statements is TRUE about the
Page 25
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
above construct?
(A) It does not ensure mutual exclusion.
(B) It does not ensure bounded waiting.
(C) It requires that processes enter the critical section in strict
alternation.
(D) It does not prevent deadlocks, but ensures mutual exclusion
SOLUTION
(B) 8
(C) 9
(D) 10
SOLUTION
Reference string 1, 2, 1, 3, 7, 4, 5, 6, 3, 1
Using optimal replacement policy, we will replace that page in memory
which either will not be used or latest used in future.
Page 26
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
(B) 1
(C) 2
(D) 3
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
YEAR 2008
Question. 44
(D) connect
SOLUTION
SYN packets are used for synchronization between sender & receiver,
these packets are sent by sender during connect system call for
synchronous connection.
Hence (D) is correct option.
Question. 45
The data block 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
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
}
else
s
s s
if s
(D) 1 and 1
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
(D) In the case of synchronous I/O, the process waiting for the
completion of I/O is woken up by the ISR that is invoked afterr
the completion of I/O
SOLUTION
Page 30
(D) 2n + 1 1
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
The loop is called for n times. The first process is parent process so
this should not be counted in child process. But after that every child
process has its own child created so after every loop.
20, 2', ........2n total threads.
But subtracting the parent.
Hence (B) is correct option.
Question. 50
SOLUTION
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
cannot be completely satisfied. Three processes P1, P2, P3 request
the resources as follows if executed independently.
Process P2:
requests 2 units of R2 t=0 : request 2 units of R3
t=2 ; request 1 units of R4
request 1 units of R3
t=4 ; request 1 units of R1
request 2 units of R1
t=6 ; release 1 units of R3
release 1 unit of R2 t=8 ; Finishes
and 1 units of R1
Process P1:
t=0;
t=0;
t=0;
t=5;
Process P3
t=0 ; request 1 units of R4
t=2 ; request 2 units of R1
t=5 ; release 2 units of R1
t=8 ; request 1 units of R3
t=9 ; Finishes
Total resources = 3 2 3 2
Process 1 Process 2 Process 3 Available
Time 1 2 3 4
1234
1234
1234
0200
0020
0001
3011
0210
0020
0001
3001
0210
0021
2001
1000
0210
0021
2001
1000
0210
1021
2001
0000
1110
1021
0001
1100
1110
1011
0001
1110
1100
1011
0101
1020
1100
0000
0111
2021
1102
0000
0000
2130
10 0 0 0 0
0000
0000
3232
All process computed without deadlock
Hence (A) is correct option.
Page 32
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
Question. 52
(B) Optimal
(C) LRU
(D) MRU
SOLUTION
Consider a disk system with 100 cylinders. The requests to access the
cylinders occur in following sequence :
4, 34, 10, 7, 19, 73, 2, 15, 6, 20
Assuming that the head is currently at cylinder 50, what is the time
taken to satisfy all requests if it takes 1 ms to move from one cylinder
to adjacent one and shortest seek time first policy is used ?
(A) 95 ms
(B) 119 ms
(C) 233 ms
(D) 276 ms
Page 33
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
SOLUTION
Arranging in order.
Total = 16 + 14 + 1 + 4 + 5 + 3 + 1 + 2 + 2 + 71
= 119 ms
Hence (B) is correct option.
Question. 55
(D) II and IV
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
II
III Is also correct since if one blocked it stop running so other can
run.
IV Is not correct.
Hence (C) is correct option.
Question. 56
(D) IV only
SOLUTION
I
Is true since
II & III
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
IV
Since I true so it is false.
Hence (A) is correct option.
Question. 57
Single level page table is not preferred since it requires the no. of
page table enteries equal to the no. of virtual memory addresses, but
a multilevel page table has smaller no. of enteries so reduce the size
of page table needed.
Hence (B) is correct option.
YEAR 2010
Question. 58
Method used by P2
While (S1==S2);
Critical Section
S1=S2;
While (S1!=S2);
Critical Section
S2=not (S1)
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
SOLUTION
A system uses FIFO policy for page replacement. It has 4 page frames
with no pages loaded to begin with . The system first accesses 100
distinct pages in some order and then accesses the same 100 pages
but now in the reverse order .How many page faults will occur ?
(A) 196
(B) 192
(C) 197
(D) 195
SOLUTION
In FIFO page replacement policy, the pages which entered first are
replaced first so for first 100 accesses, 100 page faults will occur. Now
in memory there are last 4 pages 97, 98, 99 & 100th page.
So during reverse access there 4 pages would not create any page
fault & other 97 page faults.
So total 100 + 96 = 196 page faults.
Hence (A) is correct option.
Question. 60
II
(A) I only
SOLUTION
II
CS Topicwise 2001-2010
Operating System
www.gatehelp.com
in some cases, it may cause starvation when one process doesnt
block due to I/O so others have to wait.
III It is quite obvious that due to preemption involvement round
orbit is better than FCFS, in case of response time.
All are true
Hence (D) is correct option.
Question. 61
Process P1
Process P2
wait (S2 )
release (S 0 );
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Operating System
if (i%2==0){
if(i<n)request
if(i+2<n)request
i + 2;
}
else {
if (i<n)request
if (i+2<n)request
;
;
n i 2
}
In which one of the following situations is a deadlock possible ?
(A) n = 40, k = 26
(B) n = 21, k = 12
(C) n = 20, k = 10
(D) n = 41, k = 19
SOLUTION
Page 39
www.gatehelp.com
YEAR 2001
Question. 1
)
x;
y;
}
func1(x,y,z)
{
y=y+4
z=x+y+z;
}
(A) 10, 3
(B) 31, 3
(C) 27, 7
SOLUTION
Since the function fun 1 doesnt return the values of x & y and x
& y are not passed by reference. So in program P1( ) would print
x = 10 & y = 3 . So 10, 3
Hence (A) is correct option.
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Question. 2
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Var n:int:
procedure W (var x:int)
begin
X=X+1
Print x;
end
Procedure D
Begin
var n:int;
n=3;
W(n);
End
Begin
\\begin P2
n=10;
D;
end
If the language has dynamic scooping and parameters are passed by
reference, what will be printed by the program ?
(A) 10
(B) 11
(C) 3
SOLUTION
Question. 4
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
SOLUTION
(D) 5050
SOLUTION
g a [0] [99]
g
h
g
h
g
h
g a [99] [99]
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
{
p)=x/i;
s+=p;
}
return s;
}
For large values of y, the return value of the function f best
approximates
(B) ex
(A) xy
(C) In(1 + x)
(D) xx
SOLUTION
1+x
x ) x/2 : 1 = x2 /2 : 1
1 + x + x2 /2
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Of the following expressions
(1) A[2]
(2) A[2][3]
(3) B[1]
(4) B[2][3]
Which will not give compile-time errors if used as left hand sides of
assignment statements in a C program ?
(A) 1, 2, and 4, only
(D) 4 only
SOLUTION
Page 6
/ T (k 1) T (x), where x
k=1
is
(A) n k + 1
(B) n k
(C) n k 1
(D) n k 2
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
SOLUTION
Binary search tree has a root node & its 2 subtrees. So for every node
other than the leaves, all the elements smaller than the node are its
left subtree & all the nodes which have value equal to or greater than
that node are at right subtree.
/T (k 1) T (X)
K=1
Figure
n (B) = no. of nodes in left subtree
n (C) " no. of nodes in right subtree
T (n) = n (B) + n (C) + 1
T (n) =
/T (X) T (k 1)
K=1
K=1
1 444444444 2 444444444 3
/T (n k + 1) T (k 1)
n=1
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
transversal sequence of the resultant tree ?
(A) 7 5 1 0 3 2 4 6 8 9
(B) 0 2 4 3 1 6 5 9 8 7
(C) 0 1 2 3 4 5 6 7 8 9
(D) 9 8 6 4 2 3 0 1 5 7
SOLUTION
Page 8
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Both the tasks can be performed by both the data structures but heap
Page 9
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
is a data structure where to perform these function every element has
to be checked so O (n) complexity.
But the balance binary search tree is efficient data structure since
at every decision it selects one of its subtree to no. of elements to be
checked are reduced by a factor of 1/2 every time.
n =x
2!
x = log n
Hence (B) is correct option.
Question. 11
(D) Y + 2X
SOLUTION
Here each of PURSH & POP operation take X seconds & Y seconds
are elapsed between two consecutive stack operations.
m is the life time of element in stack.
So
m X is time for push.
m X is time for pop.
m Y is time for intermediate
So total m (2X + Y)
m (2X + Y)
Average stack life =
m
= 2X + Y
= Y + 2X
Hence (D) is correct option.
Question. 12
Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree
Page 10
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
2-3-4 B-tree means the min degree of a node is two & it can be max
4 So maximum of 3 elements can be there in a node.
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Since the adjacent child has no. of element # n = 4 = 2 so we apply
2
2
a right rotation.
So here.
(D) {m | m # n, m is odd}
SOLUTION
Question. 14
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Q(x);)y=x-1;
print(x);
}
main (void){
x=5;
p(&x);
print(x);
}
The output of this program is
(A) 12 7 6
(B) 22 12 11
(C) 14 6 6
(D) 7 6 6
SOLUTION
Figure
Here X is the global variable so still 5.
Figure
Here this is global X whose xy has been changed to 6 so 6 is printed
12 66
Hence (A) is correct option.
First x=5
Then by function p(&x)
X =5+2=7
Then by function Q(x)
z =z+x
=7+5=12
Here x is global variable so still it is 5.
Return to function p(&x)
Y =7-1=6
print
x =7
return to main
Print
x =6
Here this is global x whose *y ahs been changed to
6 so 6 is printed.
Page 13
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Question. 15
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
SOLUTION
(int a, int b)
temp;
=a;
=b;
=temp;
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
1 and top 2 (top 1<top 2) point to the location of the topmost
element in each of the stacks. If the space is to be used efficiently, the
condition for stack full is
(A) (top 1=MAXSIZE/2) and (top 2=MAXSIZE/.2+1)
(B) top 1+top2=MAXSIZE
(C) (top 1=MAXSIZE/2) or (top2=MAXSIZE)
(D) top 1=top 2 1
SOLUTION
Here the stack will be fuel if both top 1 & top 2 are at the adjacent
index values i.e. their difference is 1.
So top 1 = top 2 - 1
Here (D) is correct option.
Question. 19
The following numbers are inserted into an empty binary search tree
in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the
binary search tree (tree height is the maximum distance of a leaf node
from the root) ?
(A) 2
(B) 3
(C) 4
(D) 6
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
(B) stack
(C) tree
(D) list
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Hence (B) is correct option.
Question. 21
(B) 6
(C) 7
(D) 8
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
n=n/10;
}
The loop invariant condition at the end of the ith iteration is
(A) n = d1 d2 ......dm i and rev = dm dm 1 ......dm i + 1
(B) n = dm i + 1 .....dm 1 dm or rev = dm i .....d2 d1
(C) n =
Y rev
(D) n = d1 d2 ....dm or rev = dm ......d2 d1
SOLUTION
Here after every iteration one digit is reduced from n since n = n/10
so unit place is removed.
This unit place is then added into the previous reverse sum (rev)
after multiplying rev by 10. So 1 digit is incremented every iteration.
So at the ith iteration n should have m i digits d1 d2 .....dm i & rev
have dm dm 1 ..........dm i + 1
i
n
rev
1
dm
d1 d2 ....dm 1
2
d1 d2 ......dm 2
dm dm 1
So on.
Hence (A) is correct option.
Question. 23
(B) string
(C) gnirt
SOLUTION
In line 8
p[i]=S[length-i];
Here p is a character pointer variable so we cant assign the value of
a pointer variable into character variable so no output is printed.
Page 19
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
The block of code shown here is actually outputs the reversal of
string given in S. Which is a char type pointer. But the mistake
during the loop execution is done. The statement is accessing the
s [length - i] & loop starts from 0
When i = 0, s [length - 0] & s [length].
So this value for string is always P will start with null pointer. So
the string p will start with null pointers and nothing will be printed.
Hence (D) is correct option.
Question. 24
Here due to circular connection the rear & front are connected. Here
if we point P to rear the P "next point to front node & P " data
will point to rear value while inserting at rear following sequence of
operations done.
P " data = inserted value
)
P " next = P " next " next
These operation done is 0 (1) time
So constant complexity.
Hence (A) is correct option.
Page 20
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Question. 25
The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the
given order into a maxHeap. The resultant maxHeap is
SOLUTION
Here n = 7 .
This is the heap of elements.
Now for max heap property is that every root node should be larger
than its child nodes. The root node on the tope is largest of all.
Step 1 take ^n/2h node for start ^7/2h = 4 if it is at right place i.e it is
smaller than its parent & greater than its children then OK otherwise
swap them.
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Question. 26
(D) +a#bc^^def
SOLUTION
Given expression a + b ) c d / e / f
parenthesizing the expression as per given rules.
= ((a + (b ) c)) (d / (e / f)))
= ((a + (bc ))) (d / (ef /)))
= ((abc ) +) (def //))
= (abc ) + def //)
So option (A) is correct
You can also solve using stack.
Hence (A) is correct option.
Question. 27
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
(B) m2
(C) m1/2
(D) m1/3
SOLUTION
X
(16 + 1)
=8
2
Y
16 = 2
8
Page 23
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
2
8+2 = 5
2
16 = 3
5
5+3 = 4
2
16 = 4
4
Here X = Y
Then take X . which is 4.
(m) 1/2 = 4 = (16) 1/2
Hence (C) is correct option.
Question. 29
Value initialized by 0
If any root node has left child then it adds 1 to the value & move to
Page 24
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
left child & if any mode has right child also then also calculated the
value using recursion & take maximum of both left & right value is
taken.
So we know that height is the largest distance between root node &
leaf.
So this program calculates heights.
Hence (D) is correct option.
Question. 30
Group-2
P. Functional
Q. Logic
R. Object-oriented
S. Imperative
1. Command-based, procedural
2. Imperative, abstract data types
3. Side-effect free, declarative, expression
evaluation
4. Declarative, clausal representation,
theorem proving
SOLUTION
p.
r.
YEAR 2005
Question. 31
int
Page 25
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
(A) A function that takes an integer pointer as argument and returns
an integer
(B) A function that takes an integer pointer as argument and returns
an integer pointer
(C) A pointer to a function that takes an integer pointer as argument
an returns
(D) A function that takes an integer pointer as argument returns a
function pointer
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Question. 33
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Question. 35
Here the no. readable are range 0 to 100 but the output of the program
is interested in scores above 50 so there are 50 values (51 to 100) in
this range.
So only an array 50 integers required as we get any no. we increment
the value stored at index.
Array [x 50] by 1.
Hence ( ) is correct option.
Question. 36
Page 28
(A) 8, 4,0, 2, 14
(B) 8, 4, 0, 2, 0
(C) 2, 0, 4, 8, 14
(D) 2, 0, 4, 8, 0
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
SOLUTION
2048
-8
204
204
-4
20
20
12
- print 0
12
- print 2
14
" return
Here n = 0 so return
2 0 4 8 are printed then
Print sum. Sum = 14 but in foo function only the sum variable in
main is still 0.
So 2 0 4 8 0 printed.
Hence (D) is correct option.
Question. 37
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
SOLUTION
When we are given any no elements & even any order (preorder or
post order) & we need to calculate inorder, then inorder is simply
sorted sequence of the elements.
Here 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
Hence (A) is correct option.
YEAR 2006
Question. 39
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
if (stack-empty (S1))then{
print(Q is empty);
return;
}
else while (! (stack-empty)(S1)){
x=pop(S1);
push(S2,x);
}
x=pop(S2);
}
Let n insert and m (# n) delete operations be performed in an
arbitrary on an empty queue Q, Let x and y be the number of push
and pop operations performed respectively in the processes. Which
one of the following is true for all m and n ?
(A) n + m # x < 2n and 2m # n + m
(B) n + m # x < 2n and 2m # y # 2n
(C) 2m # x < 2n and 2m # y # n + m
(D) 2m # x < 2n and 2m # y # 2n
SOLUTION
Question. 40
Consider the following C-function in which a[n] and b[n] are two
sorted integer arrays and c[n+m] be another integer array.
void xyz (int a[],int b[],int c[]){
int i, j, k;
i=j=k=0;
while((i<n))&&(j<m)
if (a[i]<b[j]c[k++]=a[i++];
else c[k++]=b[j++];
}
Which of the following condition (s) hold (s) after the termination of
the while loop ?
I
j<m, k=n+j-1, and a [n-1]<b[j] if i=n
II
i<n, k=m+j-1, and b[m-1]#a[i] if j=m
(A) only (I)
(B) only (II)
Page 31
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
(C) either (I) or (II) but not both
(D) neither (I) nor (II)
SOLUTION
S1:
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Consider the C code to swap two integers and these five statements:
the code
void swap(int
)
px,int
py){
px= px py;
py=)px+)py;
)px=)py)px;
)
}
S1 :
S2 :
S3 :
S4 :
S5 :
(A)
(C) S2 and S 4
(D) S2 and S5
SOLUTION
Here pointers are used without initialization also the address pointed
by then may be out of segment of program, so segmentation.
" Fault may be there so. S2 correct.
" Here no compiler error S1 false.
" Correctly done swap procedure but not all valid import pointers
so S 4 also true.
S2 & S 4 are correct.
Hence (C) is correct option.
Page 33
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Data for Q. 43 & 44 are given below.
A 3-ary max heap os like a binary max heap, but instead of 2 children,
nodes have 3 children, A 3-ary heap can be represented by an array
as follows: The root is stored in the first location, a [0], nodes in the
next level, from left to right, is stored form a[1] to a[3]. The nodes
from the second level of the tree from left to right are stored from a[4]
location onward.
An item x can be inserted into a 3-ary heap containing n items by
placing x in the location a [n] and pushing it up the tree to satisfy
the heap property.
Question. 43
(D) 9, 5, 6, 8, 3, 1
SOLUTION
Here in option (A), (B) and (C), value present at node is not greater
Page 34
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Suppose the elements 7, 2, 10, and 4 are inserted, in that order, into
the valid 3-ary max heap found in the above question, Q. 33. Which
on of the following is the sequence of items in the array representing
the resultant heap ?
(A) 10, 7, 9, 8, 3, 1, 5, 2, 6, 4
(B) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
(C) 10, 9, 4, 5, 7, 6, 8, 2, 1, 3
(D) 10, 8, 6, 9, 7, 2, 3, 4, 1, 5
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
n = 10 = 5
2
2
3 is at right position
4 is at right position
Figure
Figure
Figure
Order
10 7 9 8 3 1 5 2 6 4
Hence (A) is correct option.
YEAR 2007
Question. 45
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
(B) n
(C) [log2 n]
(D) 6log2 n @ + 1
SOLUTION
Iteration
Initially 0
1=2
2 = 21
4 = 22
8 = 23
Comparison
0
=n
i = log 2 n
i + 1 = ^log 2 nh + 1
Hence (A) is correct option.
Question. 46
(B) 5, 7
(C) 3, 2
(D) 1, 5
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Stack contain 5, 7
Hence (B) is correct option.
Question. 47
(B) 7
(C) 9
(D) 18
SOLUTION
Given f (5) = ?
Page 38
Recursion
r
0"5
Return
Final Return
f (3) + 2
16 + 2 = 18
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
(D) the height of the tree
SOLUTION
Here the structure cell Node represents a binary tree. Here the
function Get value return 1 if for any node both left & right children
are NULL or we can say if that node is a leaf node.
A variable value initialized to 0 is there to count these leaf nodes.
Hence (C) is correct option
YEAR 2008
Question. 49
(B) x = 6, y = 5, z = 3
(C) x = 6, y = 3, z = 5
(D) x = 5, y = 4, z = 5
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
Question. 50
(D) 22
SOLUTION
Let
c=4c
b
a
Call f (4, 1000, 2000)
ppz
=4
= & c = 1000
& b = 2000
= 2000 py = 1000 X = 4
)) ppz = )) ppz + 1
)) ppz = 4 + 1 = 5 z = 5
(2)
) py = ) py + 2
= 5+2 = 7 y = 7
(3)
X = X+3 = 4+3 = 7 x = 7
Return (x + y + z) & 7 + 7 + 5 = 19
Since both )) ppz and ) py point to same memory location 1000
where C is stored.
Hence (B) is correct option.
(1)
Question. 51
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
string is terminated by a newline character.
void reverse (void) {
int c;
if(?1) reverse();
?2
}
main () {
printf(Enter Text); printf("\n");
reverse(); printf("\n");
}
(A) ?1 is (getchar () ! = '\n')
?2 is getchar (c);
(B) ?1 is (getchar ()) ! = '\n')
?2 is getchar (c);
(C) ?1 is (c ! = '\n')
?2 is putchar (c);
(D) ?1 is (( c = getchar ()) ! = '\n')
?2 is putchar (c);
SOLUTION
Here if and if the string comes we print the letter & do it recursively.
If C is not end to string then we move to next character in the string.
?1 should be to getchar in C & check if it is end of string.
Hence (C=getchar ()!= \n )
?2 should be when\n reached so print. putchar (C);
Hence (D) is correct option.
Question. 52
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
(B) 2,1,4,3,6,5,7
(C) 1,3,2,5,4,7,6
(D) 2,3,4,5,6,7,1
SOLUTION
Here the code scans the whole list & exchanges two consecutive
elements which are the nodes p & q. and then move to next two
elements or 2 * 1 4 * 6 * 5 7
Thus 2 1 4 3 6 5 7 is the output.
Hence (B) is correct option.
YEAR 2009
Question. 53
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
printf(%d\n,fun(5,&x));
return 0;
}
The value printed is:
(A) 6
(B) 8
(C) 14
(D) 15
SOLUTION
Here the table column I, II, & III are during the forward calls of the
recursive function fun &
The part after arrow in column III is updated value during return
calls & column IV & V are the returned values.
In the end 8 is returned so only this will be printed
Hence (B) is correct option.
Question. 54
(B) 3
(C) 4
(D) 5
SOLUTION
AVL tree is a partially balanced tree with the weights assigned to the
nodes can be only 1, 0 or 1. This weight is assigned on the basis of
difference of the no. of children in the left subtree & right subtree. If
some other weight is there then we rotate the tree to balance it.
Page 44
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
This is balanced.
If the value presented at any node is greater then all its children then
the tree is called the max heap.
Page 45
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Here we need to draw heap for all options
Question. 56
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}
SOLUTION
Page 46
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
(A) 19
(B) 21
(C) 20
(D) 10
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Here
So
}
int i=0,j=1;
int main(){
f(&i,&j);
printf(%d%d\n,i,j);
return 0;
}
(A) 22
(B) 21
(C) 01
(D) 02
SOLUTION
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
P. Requirement Capture
1.
Module Development
Integration
Q. Design
2.
Domain Analysis
R. Implementation
3.
S.
4.
Performance Tuning
Maintenance
and
SOLUTION
All of these steps are part of a simple software development life cycle
(SWDLC)
P. Requirement Capture : Considered as first step where we analyze
the problem scenario, domain of input, range of output and
effects.
P
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
int main()
{
int a[]={12, 7, 13, 4, 11, 6};
printf(%d,f(a,6));
return 0;
}
(A) 9
(B) 5
(C) 15
(D) 19
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
while(p->next!=NULL){
q=p;
p=q->next;
}
________________________
return head;
}
Choose the correct alternative to replace the blank line.
(A) q=NULL;p->next=head;head=p;
(B) q->next=NULL;head=p;p->next=head;
(C) head=p;p->next=q;q->next=NULL;
(D) q->next=NULL;p-next=head;head=p;
SOLUTION
Here the program wants to make the last node of the list, the first
node.
Here q is the second last node and p is the last node
The second last nodes next should be now NULL so
"
q->next=NULL.
p->next should below head node.
"
so p->next=head
Now the head node is p.
"
So head = p.
Hence (D) is correct option.
Question. 62
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
T2 : a, b, c and d are all distinct
T3 : a = b and c! = d
T4 : a! = b and c = d
Which of the test suites given below ensures coverage of statements
S1, S2, S3 and S4 ?
(A) T1, T2, T3
(B) T2, T4
(C) T3, T4
SOLUTION
Page 52
42
23
34
52
46
33
www.gatehelp.com
CS Topicwise 2001-2010
Programming & Data
Structure
8
9
Question. 63
Which one oft he 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
SOLUTION
Here for hashing Linear probing is used, i.e. it finds the hash key
value through hash function and maps the key on particular position
In Hash table. In case of key has same hash address then it will find
the next address then it will find the next empty position in the Has
Table.
Here we check all options:
(A) Here 42 will be inserted at the 2nd position in the array next 52,
also has same hash address 2. But it already occupied so it will search
for the next free place which is 3rd position. So here 52 is misplaced
and it is not possible key values.
Table 3 table
(B) Here 46 is misplaced so it is not possible value.
(C) This is same as given hash table.
So correct order is 46, 34, 42, 23, 52, 33
Hence (C) is correct option.
Question. 64
How many different insertion sequences of the key values using hte
same hash function and linear probing will result in the hash table
shown above ?
(A) 10
(B) 20
(C) 30
(D) 40
SOLUTION
Here the given order of insertion is 46, 34, 42, 23, 52, 33
Page 53
CS Topicwise 2001-2010
Programming & Data
Structure
www.gatehelp.com
Figure
Here 42, 23, 34, 46 are inserted direct using hash function
"
But to insert 52 we have 6 vacant places.
"
After insertion of 52 at any of the 6 places, we have 5 places
"
remaining for 33.
So total combination.
6 # 5 = 30 possible ways
Hence (C) is correct option.
**********
Page 54
www.gatehelp.com
YEAR 2001
Question. 1
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
(D) The complement of a context free language is context free
SOLUTION
(D) N!
SOLUTION
In DFA the no. of states are always more than NFA, so if NFA has
N states DFA will have 2N states.
Hence (C) is correct option.
Question. 4
(D) 48
SOLUTION
Page 2
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
No. of states = 9
9 + 7 1 = 15
Total
L4 = {0i i is an integer}
Which of the languages are regular ?
(B) Only L2, L3 and L4
(A) Only L1 and L2
(C) Only L3 and L4
(D) Only L3
SOLUTION
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
q ?
Which of the following statements about x is correct ?
(A) x is decidable
(B) x is undecidable but partially decidable
(C) x is undecidable and not even partially decidable
(D) x is not a decision problem
SOLUTION
(B) 3 states
(C) 4 states
(D) 5 states
SOLUTION
Start & end are same (A) so the minimum no. of states required are
3.
Option (B) is correct
If string traversal doesnt stop at (A) then string length is not divisible
by 3.
Question. 8
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
recursively enumerable.
(C) The complement of a recursive language is either recursive or
recursively enumerable.
(D) The complement of a context-free language is context-free.
SOLUTION
The C language is :
(A) A context free language
(B) A context sensitive language
(C) A regular language
(D) Parsable fully only by a Turing machine
SOLUTION
(B) Regular
(D) Recursive
SOLUTION
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
YEAR 2003
Question. 11
Ram and Shyam have been asked to show that a certain problem
is NP-complete. Ram shows a polynomial time reduction from the
3-SAT problem to , and Shyam shows a polynomial time reduction
from to 3-SAT. Which of the following can be inferred from these
reduction?
(A) is NP-hard but not NP-complete
(b) is in NP, but is not NP-complete
(C) is NP-complete
(D) is neither Np-hard, nor in NP
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
Question. 14
Let S denote the set of seven bit binary strings in which the first, the
fourth, and the last bits are 1. The number of strings in S that are
accepted by M is
Page 7
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
(A) 1
(B) 5
(C) 7
(D) 8
SOLUTION
(A) Incorrect since the production has same non terminal in both
sides, so definitely ambiguous.
(B) Since S " SS this leads to conjunction of every possible string to
make a valid string in L (G).
(C) Context free languages are accepted by push down automata so
true.
Page 8
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
f : "
So
f : "
Bijection
(6 : X) : X ! L1 iff f (x) ! L2
So L1 is undecidable & L2 is decidable L1 depends on L2 & L2
dependent upon f 1 .
Hence (C) is correct option.
1
Question. 10
q0
q1, 1,R
Q1, 1,R
Halt
q1
q1, 1,R
q0, 1,L
qH0, B, L
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
transitions to state q1 .
Which of the following statements is true about M ?
(A) M does not halt on any string in (0 + 1) +
(B) M dies not halt on any string in (00 + 1)*
(C) M halts on all string ending in a 0
(D) M halts on all string ending in a 1
SOLUTION
L = L 0 VL , =< M, w, {0, 1}
L = (L 0 , L1) c
= L 0 + L1 = so a regular language, so it is recursively
enumerable.
Page 10
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
So a
L = L 0 , L , it is not. RE
Hence (B) is correct option.
Question. 12
(C) L1 3 L
(D) L1 = L
SOLUTION
So this accept L1 .
L1 will accept not only L but also substrings of L.
So
L1 3 L
Hence (A) is correct option.
Page 11
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
YEAR 2004
Question. 13
The following finite state machine accepts all those binary strings in
which the number of 1s and 0s are respectively
SOLUTION
Due to the 3 ones in the upper edges & 3 ones in lower edges to
reach to final state the no of 1s is always divisible by 3 & 0s are
always in pair in forward & back edge so, no of zeros is divisible by 2.
Hence (A) is correct option.
Question. 15
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
(A) regular
(B) context-free but not regular
(C) context sensitive but not context free
(D) type-0 but not context sensitive
SOLUTION
S " bS aA b
A " bA aB
B " bB aS a
Let Na (w) & Nb (w) denote of a's & b's in strings.
Some valid strings are
1. S " bS " bbS " bbb (any no. of b)
2.
3.
From (2) option (D) is false also from (1), (2) & (3) (a), (b) & (d)
are false.
So only (C) satisfy.
Page 13
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Hence (C) is correct option.
Question. 17
Question. 18
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
P1 " decidable
P2 " undecidable
If P1 or P2 is reducible to P3 then P3 also has same properties as P1
& P2 .
So if P2 is reducible to P3 then P3 is also undecidable.
Hence (C) is correct option.
Question. 19
From the given FSM , it is clear that a not necessity followed by only
2b due to self loop at final state. But at least 2b's are there.
abb substring not always, Similarly aa not always.
Hence (B) is correct option.
Question. 20
Let Nf and Np denote the classes of languages accepted by nondeterministic finite automata and non-deterministic push-down
automata, respectively. let Df and DP denote the classes of languages
accepted by deterministic finite automata and deterministic pushPage 15
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
down automata, respectively. Which one of the following is TRUE?
(A) Df 1 Nf and DP 1 NP
(B) Df 1 Nf and DP = NP
(C) Df = Nf and DP = NP
(D) Df = Nf and DP 1 NP
SOLUTION
L1 = {an bn cm n, m > 0}
L2 = {an bm cm n, m > 0}
Here L1 + L2 may not be CFL since CFL is not closed for intersection
operation.
L1 + L2 would be context sensitive (A) is false.
Hence (A) is correct option.
Question. 22
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
: Given G (V, E), does G have an independent set of size | V | 4 ?
: Given G (V, E), does G have an independent set of size 5?
Which one of the following is TRUE?
(A) is in the P and is NP-complete
(B) is NP-complete and is P
(C) Both and are NP-complete
(D) Both and are in P
SOLUTION
YEAR 2006
Question. 25
(B) R is NP -hard
(C) Q is NP -complete
(D) Q is NP -hard
SOLUTION
Page 18
(A) L1 only
(B) L3 only
(C) L1 and L2
(D) L2 and L3
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
To accept CFL we require PDA & PDA accept CFG using stack
L1 can be accepted using PDA firstly 0n + m are pushed into stack then
1n & 0m times stack is poped. If stack empty then string accepted.
But for L2 & L 3 0m & 0n + m are extra to accept by PDA.
Hence (D) is correct option.
Question. 27
Option (A), (B) & (D) can be accepted by DFA, & there is no linear
relationship between the no. of 0's & 1's in the string but in (C)
n 0 (S) n1 (S) # 4 cant be accepted by DFA, we require a PDA.
So not regular.
Hence (C) is correct option.
Question. 28
For s ! (0 + 1)* let d (s) denote the decimal value of s (e.g.d (101) = 5)
Let L = {s ! (0 + 1)*| d (s) mod 5=2 and d (s) mod 7 ! 4}
Which one of the following statements is true?
(A) L is recursively enumerable, but not recursive
(B) L is recursive, but not context-free
(C) L is context_free, but not regular
(D) Lis regular
SOLUTION
S ! (0 + 1))
Page 19
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
d (S) decimal value of S
d (S) nod 5 = 2
2, 12, 7, 17, 22, 27, 32
d (S) mod 7 =
Y 4
d (S) =
Y 4, 11, 18, 25, 32
So from the rules deterministic.
So it is regular can be accepted by DFA.
Hence (D) is correct option.
Question. 29
Question. 30
3.
(D) 1, 2 and 3
SOLUTION
Due to S " SS this Grammar is ambiguous right hand side has two
Non terminals.
Page 20
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
Also the strings like aaabbb have equal no. of a's & b's but cant be
produced by this grammar. So 2 is false.
Statement 3 is true since it is a CFG so accepted by PDA.
Hence (B) is correct option.
Question. 31
L1 is regular language
L2 is CFL.
L 3 is recursively enumerable but not REC .
(A) L1 + L2 is CFL is true
(B) L 3 + L1 is recursive, not necessary so false.
(C) & (D) are also true.
Hence (B) is correct option.
Question. 32
(B) 5
(C) 8
(D) 9
SOLUTION
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Question. 33
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
(D) 9 states
SOLUTION
Total states = 15
Page 23
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Hence (A) is correct option.
Question. 36
Option (C) is a regular language since it starts & ends with same
symbol w # wR .
The regular expression (1 (0 + 1) + 1) + (0 (0 + 1) + 0) satisfy this
regular language.
Hence (C) is correct option.
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
Question. 38
(B) (a + b)*
(C) b * a (a + b)*
(D) b * ab * ab *
SOLUTION
From the given FSA to reach to find state b)a is necessary in REX
remaining part is option.
REX b)a (a + b)) followed by FSA.
Hence (C) is correct option.
Question. 39
The minimum state automaton equivalent to the above FSA has the
following number of states
(A) 1
(B) 2
(C) 3
(D) 4
SOLUTION
Page 25
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
So only 2 states.
Hence (B) is correct option.
YEAR 2008
Question. 40
{a p P is a prime no.}
This prime no. is extra constraint so this language is neither LFG
nor RG but it can be accepted by turing machine.
Hence (D) is correct option.
Question. 41
2.
3.
4.
(A) 1 and 2
(B) 1 and 4
(C) 2 and 3
(D) 2 and 4
SOLUTION
Page 26
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
Question. 42
(B) context-free
(C) context-sensitive
(D) recursive
SOLUTION
L & L are recursively enumerable i.e. they can accept any element
through some finite algorithm.
All algorithms are finite step procedures so these both has to be
recursive.
Hence (D) is correct option.
Question. 43
Given below are two finite state automata("indicates the start and
F indicates a final state)
Page 27
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Y:
Z:
a
"
2F
(A)
"
2F
(B)
a
-P
-P
R(F)
R(F)
(C)
(D)
a
-P
-P
R(F)
R(F)
SOLUTION
Z & Y each has 2 states so ZXY will have 2 states {(1, 1), (1, 2),
(2, 1), (2, 2)}
Page 28
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
2.
3.
4.
(A) 1, 2, 3 and 4
(B) 2, 3 and 4 only
(C) 1, 3 and 4 only
(D) 1, 2 and 4 only
SOLUTION
Yes, every left recursive grammar can be converted into right recursive
grammar but all ! period cant be removed only CFL that has
-free CFL's can be removed.
So this statement is false.
3 & 4 are also true.
Hence (C) is correct option.
Page 29
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Question. 46
Match List-I with List-II and select the correct answer using the
codes given below the lists:
List-I
A. Checking that identifiers are declared before their use
B. Number of formal parameters in the declaration to a function
agress with the number of actual parameters in a use of that
function
C. Arithmetic expressions with matched pairs of parentheses
D. Palindromes
List-II
1.
L = {a"b"c"d"| n # 1, m # 1}
2.
3.
L = {wcw | w ! (a | b)*}
4.
Codes:
A
(A)
(B)
(C)
(D)
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
Question. 47
Match List I with List II and select the correct answer using the
codes given below the lists:
Page 31
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Code:
a
(A)
(B)
(C)
(D)
SOLUTION
Page 32
1.
{an b2m | n # 0, m # 0}
2.
{an bm | n = 2m}
3.
{an bm | n ! m}
4.
(C) 1 only
(D) 4 only
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
I.
II. & III. Not regular since there exists linear relationship between
m & n , neither they can be represented by DFA or REX .
IV. Also regular language, (a + b)) c (a + b)) REX is possible & no
linear relationship between m & n that require PDA.
Hence (A) is correct option.
YEAR 2009
Question. 49
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
(B) The set of all strings containing at most two 0s
(C) The set of all strings containing at least two 0s
(D) The set of all strings that being and end with either 0 or 1
SOLUTION
SOLUTION
(A) true, since minimal DFA for every regular language is possible.
(B) true , NFA can be converted into an equivalent PDA.
(C) CG'S are not recursive but their complements are.
(D) false, since non deterministic PDA represents, non deterministic
CFG , since NDCFG and CFG are proper subsets so conversion
required.
Hence (D) is correct option.
Question. 52
Match all items in Group I with correct options from those given in
Group 2
Page 34
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
Group 2
Group 1
P. Regular expression
1.
Syntax analysis
Q. Pushdown automata
2.
Code generation
3.
Lexical analysis
S.
4.
Code Optimization
Register allocation
SOLUTION
Given the following state table of an FSM with two states A and B
, one input and one output :
Present
State A
Present
State B
Input
Next State
A
Next State
B
Output
(B) 4
Page 35
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
(C) 5
(D) 6
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
The following DFA accept the set of all string over {0, 1} that
SOLUTION
From the DFA it is clear that to reach to the end state two zeros
would be there.
So all the strings that are accepted will end with 00.
Hence (C) is correct option.
YEAR 2010
Question. 56
CS Topicwise 2001-2010
Theory of Computation
www.gatehelp.com
SOLUTION
L1 " recursive
L2, L 3 " recursively enumerable but not recursive.
So L1 can be recursive enumerable.
RE RE = RE
So L1 L 3 is recursively enumerable.
Hence (B) is correct option.
Question. 57
SOLUTION
www.gatehelp.com
CS Topicwise 2001-2010
Theory of Computation
SOLUTION
Let by any string of length n in{0, 1}). Let L be the set of all
substring so . What is the minimum number of states in a nondeterministic finite automation that accepts L ?
(A) n 1
(B) n
(C) n + 1
(D) 2n + 1
SOLUTION
Here n = 4
So to accept all the substrings the no. of states required are
n+1 = 4+1 = 5
Hence (C) is correct option.
**********
Page 39