Вы находитесь на странице: 1из 410

www.gatehelp.

com

GATE CS Topic wise Questions Algorithms

YEAR 2001 Question. 1

Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort ? (A) 0 (n) (C) 0 (n )
SOLUTION
2

(B) 0 (n log n) (D) 0 (n!)

In randomized quicksort pivot is chosen randomly, the case complexity of sorting n . In that case the worst case 0 (n2) of quicksort become 0 (n log n) of randomize quicksort. Hence (B) is correct option.
Question. 2

Consider any array representation of an n element binary heap where the elements are stored from index 1 to index n of the array. For the element stored at index i of the array (i # n), the index of the parent is (B) : i D (A) i 1 2 (C) b i l 2 (D) (i + 1) 2

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

For an element at index j its children are at 2j & 2j + 1 index let 2j = i j =i 2 2j + 1 = i j = i1 2

So

j = bi l 2

Hence (B) is correct option.


Question. 3

Let f (n) = n2 log n and g (n) = n (log n) 10 be two positive functions of n . Which of the following statements is correct ? (A) f (n) = 0 (g (n)) and g (n) = Y 0 (f (n)) (B) g (n) = 0 (f (n)) and f (n) = Y 0 (g (n)) (C) f (n) = Y 0 (g (n)) and g (n) = Y 0 (f (n)) (D) f (n) = 0 (g (n)) and g (n) = 0 (f (n))
SOLUTION

f (n) = n2 log n & g (n) = n (log n) 10 Since f (n) is polynomially greater than g (n) So f (n) = 0 (g (n))

But g (n) = Y 0 (f (n)) Hence (A) is correct option.


Question. 4

Consider the undirected unweighted graph G. Let a breadth-first traversal of G be done starting from a node r . Let d (r, u) and d (r, v)
Page 2

www.gatehelp.com
be the lengths of the shortest paths form r to u and v respectively in G. If u is visited before v during the breadth-first traversal, which of the following statements is correct ? (A) d (r, u) < d (r, v) (B) d (r, u) > d (r, v) (C) d (r, u) # d (r, v)
SOLUTION

CS Topicwise 2001-2010 Algorithms

(D) None of the above

In BFS if u is visited before v then either u is some levels before v or u & v are at the same level but u is leftmost in v . d (r, u) # d (r, v) Hence (C) is correct option
Question. 5

How many undirected graphs (not necessarily connected) can be constructed out of a given set V = {V1, V2, .......Vn} of n vertices ? n (n 1) (B) 2n (A) 2 (C) n!
SOLUTION

(D) 2

n (n 1) 2

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)
n

c2

=2

n (n 1) 2

Hence (D) is correct option.


Question. 6

What is the minimum number of stacks of size n required to implement a queue to size n ? (A) One (B) Two (C) Three
SOLUTION

(D) Four

To implement a queue of size n using stacks each of size n require minimum 2 stacks.
Page 3

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com

Two stacks to implement queue.

Hence (B) is correct option.


YEAR 2002

Question. 7

The solution to the recurrence equation T (2k ) = 3T (2k 1) + 1, T (1) = 1 is (A) 2k (C) 3 log 2
SOLUTION
k

(B)

(2k + 1 1) 2
k

(D) 2 log 3

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
Question. 8

CS Topicwise 2001-2010 Algorithms

The minimum number of colours required to colour the vertices of a cycle with n nodes in such a way that no two adjacent nodes have same colour is. (A) 2 (C) 4
SOLUTION

(B) 3 (D) n 2 9n C + 2 2

Consider a cycle.

So total no. of colours required to color all vertices of cycle = 3 Hence (B) is correct option.

Question. 9

In the worst case, the number of comparisons needed to search a single linked list of length n for a given element is (A) log n (C) log n 2 1
SOLUTION

(B) n 2 (D) n

Worst case of searching occurs when the element to be searched is at the end of the list so no. of comparisons required to search complete list would be n . Hence (D) is correct option
Page 5

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
Question. 10

Maximum number of edges in a n -node undirected graph without self loops is n (n 1) (A) n2 (B) 2 (C) (n 1)
SOLUTION

(D)

(n + 1) (n) 2

Total no. of nodes = n For an edge of n nodes we select any 2 which make a graph. n (n 1) edges So nc2 = 2

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 (D) (2n + 1) 3

SOLUTION

Page 6

www.gatehelp.com

CS Topicwise 2001-2010 Algorithms

Consider following rooted trees.

n =4 2n + 1 = 3 3 No. of leaf = 3 Hence (D) is correct option.


Question. 12

Consider the following algorithm for searching for a given number x in an unsorted array A [1.....n] having n distinct values : (1) Choose an i uniformly at random from [1....n] (2) If A [i] = x then stop else Goto 1; Assuming that x is present A , What is the expected number of comparisons made by the algorithm before it terminates ? (A) n (B) n 1 (B) 2n
SOLUTION

(D) n 2

Given array A [1.....n], an element A [i] is chosen randomly from 1 to n. This would require n selections & comparisons to find x in array. Hence (A) is correct option.
Question. 13

The running time of the following algorithm Procedure A (n)


Page 7

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) (C) 0 (loglog n)
SOLUTION

(B) 0 (log n) (D) 0 (1)

This is a recursive procedure. Which always calls itself by value .So the recursion gas till n > 2 . Let n = 256 Rec 1 n = 256 2 n = 16 3 n = 4 recursion = 4 4n =2 log 2 256 = 8 Hence (B) is correct option.
Question. 14

A weight-balanced tree is a binary tree in which for each node, the number of nodes in the let sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the furthest leaf) of such a tree on n nodes is best described by which of the following ? (A) log 2 n (C) log 3 n
SOLUTION

(B) log 4 n 3
3n (D) log 2

log 3 12 , 4
Page 8

www.gatehelp.com
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

CS Topicwise 2001-2010 Algorithms

To evaluate an expression without any embedded function calls (A) One stack is enough (B) Two stack are needed (C) As many stacks as the height of the expression tree are needed (D) A Turning machine is needed in the general case
SOLUTION

To evaluate an expression we need only 1 stack in which the operands & operators are pushed into, & then evaluated using pop operations. Hence (A) is correct option.
YEAR 2003 Question. 16

Consider the following three claims 1. (n + k) m = (nm), where k and m are constants 2. 2n + 1 = O (2n) 3. 22 + 1 = O (2n)
n

Which of these claims are correct? (A) 1 and 2 (B) 1 and 3 (C) 2 and 3
SOLUTION

(D) 1, 2 and 3

(1) (n + k) m if we expand it. It is (nm + .....) During tight bound (nm) (2) 2n + 1 = 2.2n & (2.2n) & (2n) correct correct
Page 9

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
(3) 22n + 1 & 2.22 & (2.22 ) (22 ) = Y (2n) Hence option (A) is correct
Question. 17
n n n

incorrect

Consider the following graph

Among the following sequences 1. abeghf 2. abfehg 3. abfhge 4. agfhbe Which are depth first traversals of the above graph? (A) 1, 2 and 4 only (C) 2, 3 and 4 only
SOLUTION

(B) 1 and 4 only (D) 1, 3 and 4 only

DFS traversal takes the path to the end & then move to other branch.

Page 10

www.gatehelp.com

CS Topicwise 2001-2010 Algorithms

Hence option (D) is correct.


Question. 18

The usual (n2) implementation of Insertion Sort to sort ab array uses linear search to identify the position where an element is to be inserted into the already sorted part of the array. If, instead, we use binary search to identify the position, the worst case running time will (A) remain (n2) (C) become (n log n)
SOLUTION

(B) become (n (log n) 2) (D) become (n)

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) (C) (log n)
SOLUTION

(B) (n) (D) H (1)

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.

Data for Q. 20 & 21 are given below.


Solve the problems and choose the correct answers. In a permutation a1 ....an of n distinct integers, an inversion is a pair (a1, aj ) such that i < j and ai > aj .
Question. 20

If all permutation are equally likely, what is the expected number of inversions in a randomly chosen permutation of 1.....n ? (A) n (n 1)/ 2 (B) n (n 1)/ 4 (C) n (n + 1)/ 4
SOLUTION

(D) 2n [log2 n]

Let a1 ....an be 1.......3 here n = 3 consider all permutation 123, 132, 231, 213, 312, 321. Let us consider 312 here the inversions are {(3, 1), (3,2)} So in a randomly chosen permutation we need to select two no. following inversion property on an average. 1 n no. of inversions 2 C2 n (n 1) n! =1 &1 2 2! (n 2) ! 2 2 =
Page 12

n (n 1) 4

www.gatehelp.com
If n = 3 & 3 (3 1) = [ 1. 5] , 2 4

CS Topicwise 2001-2010 Algorithms

Solving this question taking a random example would be much easier. Hence (B) is correct option.
Question. 21

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)
SOLUTION

(D) (n)

Here at most n inversions are allowed, it means ai > a j only for n times. 52134 " {(5, 2), (2, 1), (5, 1), (5, 4), (5, 3)} Best case of insertion sort when all are sorted takes 0(n) time. Worst case when reverse sorted take 0 (n2). So here the solution in between 0 (n) & 0 (n2). Only n inversions means only n comparison required, each comparison take log n time. So time complexity is 0 (n log n).
Question. 22

The cube root of a natural number n is defined as the largest natural number m such that m3 # n . The complexity of computing the cube root of n (n is represented in binary notation) is (A) O (n) but not O (n0.5) (B) O (n0.5) but not O (log n ) k ) for any constant k > 0 (C) O (log n) k ) for some constant k > 0 , but not O (loglog n) m) for any constant m > 0 (D) O (loglog n) k ) for some constant k > 0.5 , but not O (loglog n) 0.5)
SOLUTION

n is represented in binary let W suppose using K bit. To calculate its cube root the time taken is 0 (log n) k but it cant be
Page 13

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

Let G = (V, E) be an undirected graph with a sub-graph G1 = (V1, E1), Weight are assigned to edges of G as follows 0 if e ! E, w (e) = ) 1 otherwise A single-source shortest path algorithm is executed on the weighted graph (V, E, w) with an arbitrary vertex v1 of V1 as the source. Which of the following can always be inferred from the path costs computed? (A) The number of edges in the shortest paths from v1 to all vertices of G (B) G1 is connected (C) V1 forms a clique in G (D) G1 is a tree
SOLUTION

Cligue :- In an undirected graph, a subset of vertices in which every vertex is connected to another vertex by an edge, this subset is called clique. Consider this graph

Let b be v1 , Now if we calculate path const. v1 " a = 1 v1 " C = 1 v1 " d = 0 v1 " e = 0 (A) So from v1 " C we have (b, d) & (c, d) edges i.e. two edges, but the path cost is 1 so (A) false. (B) Yes G1 is connected.
Page 14

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

CS Topicwise 2001-2010 Algorithms

What is the weight of a minimum spanning tree of the following graph?

(A) 29 (C) 38
SOLUTION

(B) 31 (D) 41

Starting from vertex a {(a, b), (a, c), (a, d), (a, c)} {(a, b), (a, d), (a, e), (c, d)} {(a, b), (a, e), (c, d), (b, d), (d, h)} (c, d) not selected since it make cycle {(a, b), (a, e), (d, h), (b, g)} {(a, b), (a, e), (d, h), (g, h), (g, j), (g, i)} {(a, e), (d, h), (g, j), (g, i), (h, i), (h, f), (e, h)} {(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 = (a, c) = 1 min = (a, d) = 2 min = (b, d) = 3 min = (b, g) = 2 (g, h) = 8 (h, i) = 4 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

The following are the starting and ending times of cetivities A, B, C, D, E, F, G and H respectively in chronological order; "as bs aa ae ds ae es fs be de gs ee fe hs ge hel Here, xs denotes the starting time and xe denotes the ending time of activity X . W need to schedule the activities in a set of rooms available to us. An activity can be scheduled in a room only if the room is reserved for the activity for its entire duration. What is the minimum number of rooms required? (A) 3 (C) 5
SOLUTION

(B) 4 (D) 6

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

Let G = (V, E) be a direction graph with n vertices. A path from vi to vj in G is sequence of vertices (vi, vi 1,....., vj ) such that (vk , vk + 1)! E for all k in i through j 1. A simple path is a path in which no vertex appears more than once. Let A be an n # n array initialized as follow 1 if (j, k) ! E A [j, k] = ) 0 otherwise Consider the following algorithm for o for i = 1 to n for k = 1 to n k =max
Page 16

i k

www.gatehelp.com
Which of the following statements is necessarily true for all j and k after terminal of the above algorithm? (A) A [j, k] # n (B) If A [j, j] # n 1, then G has a Haniltonian cycle (C) If there exists a path from j to k, A [j, k] contains the longest path lens from j to k (D) If there exists a path from j to k , every simple path from j to k contain most A [j, k] edges
SOLUTION

CS Topicwise 2001-2010 Algorithms

Here A during initialization gives the graph G (V, E). And for very (j, k) we maximum of the sum of edges making So if there exists a simple path from edges in that path.

adjacency matrix for directed calculate A [j, k.] which stores a simple path. j to K . A [j, k] contain no of

R0 1 1V W S S0 0 1W S W S0 0 0W 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 (C) depth first search (B) inorder traversal (D) breadth first search

Page 17

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

Level order traversal is done by traversing all the vertices in a particular level & them moving to next level. This is some as breadth first search where level by level search is done. Hence (D) is correct option.
Question. 28

Given the following input(4322,1334,1471,9679,1989,6171,6173,4199) and the hash function x mod 10, which of the following statements are true? 1. 9679,1989,4199 hash to the same value 2. 1471,6171 hash to the same value 3. All element hashes to a different value (A) 1 only (C) 1 and 2 only
SOLUTION

(B) 2 only (D) 3 and 4 only

Hash function X mod 10 4322 " 2 1334 " 4 1471 " 1 9679 " 9 1989 " 9 6171 " 1 6173 " 3 4199 " 9 Statement 1 & 2 are correct since. 9679, 1989, 4199, hash to same value.
Question. 29

The tightest lower bound on the number of comparisons, in the worst case, for comparision-based sorting is of the order of (A) n (B) n2 (C) n log n (D) n log2 n

Page 18

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Algorithms

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

Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely? 1. preorder and postorderr 2. inorderr and postorder 3. preorder and inorder 4. level order and postorder (A) 1 only (C) 3 only
SOLUTION

(B) 2 and 3 (D) 4 only

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

Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or columnmajor order in contiguous memory locations. The time complexity of an algorithm to compute M1 # M2 # will be (A) best if A is in row-major, and B is in column-major order (B) best if both are in row-major order (C) best if both are in column-major order (D) independent of the storage scheme

Page 19

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

Since the matrices are stored in array, there is no dependence of time complexity on row major or column major. Here only the starting address is known & on the basis of indexes the next memory locations are calculated. Hence (D) is correct option.
Question. 32

Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality will be the slowest? (A) union only (B) intersection, membership (C) membership, cardinality
SOLUTION

(D) union, intersection

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

Suppose we run Dijkstras single source shortest-path algorithm on the following edge-weighted directed graph with vertex P as as the source.

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

www.gatehelp.com
(C) P, Q, R, U, T, S
SOLUTION

CS Topicwise 2001-2010 Algorithms

(D) P, Q, T, R, U, S

Vertex I II III IV V VI P Q R S T U

I(P) 0 3 3 3 3 3

II(P) III(Q) IV(R) V(V) VI(S) 0 1 3 6 7 3 0 1 2 5 7 3 0 1 2 4 7 3 0 1 2 4 7 3 0 1 2 4 7 3

P is source so dist 0, underlined are the adjacent nodes of the current vertex +i gives the visited vertex at sequence i .I(P) means P is current vertex. So order is P Q R U S T Hence (B) is correct option.
Question. 34

Let A [1,.... n] be an array storing a bit (1 or 0) at each location, and f (m) is a function whose time complexity is (m). Consider the following program fragment written in a C like language: counter n; {if counter++ i else{f(counter); counter ;} } The complexity of this program fragment is (A) (n2) (C) (n) (B) (n log n) and O (n2) (D) o (n)
Page 21

; for

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

The time complexity of the following C function is (assume n > 0) int recursive(int n) { if (n ) return(1); else return(recursive(n 1)+recursive (n } (A) O (n) (B) O (n log n) (C) O (n2)
SOLUTION

1));

(D) O (2n)

Given recursion function can be changed into recursive equations i.e. T (1) = 1 = 2T (n 1) for n > 1 Let =3 = T (2) + T (2) = T (1) + T (1) = 1+1 = 2 T (3) = 2 + 2 = 4 T (1) = 20 T (2) = 21 T (3) = 22 T (n) = 2n 1 T (n) 0 (2n) Hence (D) is correct option. T (n) n T (3) T (2)
Question. 36

The recurrence equation T (1) = 1


Page 22

www.gatehelp.com
T (n) = 2T (n 1) + n, n # 2 evaluates to (A) 2n + 1 n 2 (C) 2n + 1 2n 2
SOLUTION

CS Topicwise 2001-2010 Algorithms

(B) 2n n (D) 2n + n

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

A program takes as input a balanced binary search tree with n leaf modes and computes the value of a function g (x) for each node x . If the cost of computing g (x) is min (number of leaf-nodes in learsubtree of x , number of leaf-nodes in right-subtree of x) then the worst case time complexity of the program is (A) (n) (C) O (n) 2
SOLUTION

(B) O (n log n) (D) O (2n)

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

A undirected graph G has n nodes. Its adjacency matrix is given by by an n # n square matrix whose 1. diagonal elements are O's, and 2. non-diagonal elements are 1s. Which one of the following is TRUE? (A) Graph G has no minimum spanning tree (MST) (B) Graph G has a unique MST of cost in-1 (C) Graph G has multiple distinct MSTs, each of cost n -1 (D) Graph G has multiple spanning trees of different costs
SOLUTION

Given adjacency matrix of order 4 is 4 # 4 0 1 2 3 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0

There can be many min spaning but all of n 1 cost

So on. Hence (C) is correct option.


Page 24

www.gatehelp.com
Question. 39

CS Topicwise 2001-2010 Algorithms

The time complexity of computing the transitive closure of a binary relation on a set of n elements is known to be (A) O (n) (C) O (n3/2)
SOLUTION

(B) O (n log n) (D) O (n3)

Wordshalls algorithm might be used for calculation transitive closure of a set with a elements. This algorithm has complexity 0 (n3) In transitive closure two binary relations are there 4 both ranges are the same set. The require three for loops so 0 (n3). Hence (D) is correct option.
Question. 40

A priority-Queue is implemented as a Max-Heap, Initially, it has 5 elements. The level-order traversal of the heap is given below: 10, 8, 5, 3, 2 Two new elements 1 and 7 are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is (A) 10, 8, 7, 5, 3, 2, 1 (C) 10, 8, 7, 1, 2, 3, 5
SOLUTION

(B) 10, 8, 7, 2, 3, 1, 5 (D) 10, 8, 7, 3, 2, 1, 5

Page 25

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com

7 is not in its place/

Level order traversal 10 8 7 3 2 5 Hence (D) is correct option.


Question. 41

How many distinct binary search trees can be created out of 4 distinct keys? (A) 5 (C) 24
SOLUTION

(B) 14 (D) 35

The formulae for getting no. of different BST for n distinct keys is given by. 1 2n C 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

In a complete k-ary, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is (A) n k (C) n (k 1) + 1
Page 26

(B) (n 1) k + 1 (D) n (k 1)

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Algorithms

No. of internal nodes = n Each node has K children So total nK Leaf nodes = nK n = n (K 1) So considering not node also. No. of leaf nodes = n (K 1) + 1 Hence (C) is correct option.
Question. 43

Suppose T (n) = 2T (n/2) + n, T (0) = T (1) = 1 Which one of the following is FALSE? (A) T (n) = O (n2) (C) T (n) = (n2)
SOLUTION

(B) T (n) = (n log n) (D) T (n) = O (n log n)

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. a T (n) = 6 (f (n) log n logb ) = 6 (n log n) Hence (B) is correct option.
Question. 44

Let G (V, E) an undirected graph with positive edge weights. Dijkstras single source-shortes path algorithm can be implemented using the binary heap data structure with time complexity? (A) O (| V | 2) (C) O (| V | log | V |) (B) O (| E |) +| V | log | V |) (D) O ((| E |+| V |) log | V |)
Page 27

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

Diykstra Algorithm for every vertex we consider the binary heap to find shortest path. This take V logV time. And we need to transverse each edge 1 time atleast. So overall complexity 0 (E + V log V) Which is option (B) Hence (B) is correct option.
Question. 45

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)
SOLUTION

(D) (n3/2)

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.

Data for Q. 46 & 47 are given below.


Solve the problems and choose the correct answers. Consider the following C-function: double foo(int n){ int i; double sum; if (n ) return 1.0; else { sum 0 0; for (i 0; n; i ) sum += goo (i); return sum; }}

Page 28

www.gatehelp.com
Question. 46

CS Topicwise 2001-2010 Algorithms

The space complexity of the above function is (A) O (1) (C) O (n!)
SOLUTION

(B) O (n) (D) O (nn)

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) (C) O (n )
SOLUTION
2

(B) O (n) (D) O (n!)

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.

Data for Q. 48 & 49 are given below,


Solve the problems and choose the correct answers. We are given 9 tasks T1, T2,........ T9 . The execution of each task requires one unit of time. We can execute one task at a time. Ti has a profit Pi and a deadline di profit Pi is earned if the task is completed before the end of the d1th unit of time.
Page 29

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
Task Profit Deadline T1 15 7 T2 20 2 5 T3 30 T4 18 3 T5 18 4 T6 10 5 T7 23 2 T8 16 7 T9 25 3

Question. 48

Are all tasks completed in the schedule that gives maximum profit? (A) All tasks are completed (C) T1 and T8 are left out
SOLUTION

(B) T1 and T6 are left out (D) T4 and T6 are left out

Arranging the data in increasing order of deadlines & then profit. Task Profi15t Deadtime Time 1 2 3 4 5 6 7 7 23 2 2 2 9 3 4 3 5 4 3 30 5 6 10 5 8 16 7 1 15 7 20 25 18 18

Task selected Profit 7 2 9 5 3 8 1 23 20 25 18 30 16 15

SUM 147 So here T4 & T6 not selected. Hence (D) is correct option.
Question. 49

What is the maximum profit earned? (A) 147 (C) 167


SOLUTION

(B) 165 (D) 175

Solving from the some algorithm solved in previous question the sum
Page 30

www.gatehelp.com
is 147 for the profit. Hence (A) is correct option.
YEAR 2006 Question. 50

CS Topicwise 2001-2010 Algorithms

Consider the polynomial p (x) = a0 + a1 x + a2 x2 + a2 x3, where ai ! 0, 6i. The minimum number of multiplications needed to evaluate p on an input x is (A) 3 (C) 6
SOLUTION

(B) 4 (D) 9

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

In a binary max heap containing n numbers, the smallest element can be found in time (A) (n) (C) (log log n)
SOLUTION

(B) (log n) (D) (1)

Heap is implemented using array & to find maximum or minimum element in array we take only n maximum comparison. So complexity is 6 (n) Hence (A) is correct option.
Question. 52

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

Given are n vertices {0 1 ......0 n} A simple min. spanning tree would be like joining edges between only vi & vi 1 . The weight of every such edge would be 2 vi v j = 2 (i j) = 2 ( i + 1 + i) =2 In complete graph the no. of edges in MST = n 1 So total weight of MST = 2 # (n 1) = 2n 2 Hence (B) is correct option.
Question. 53

To implement Dijkstras shortest path algorithm on unweighted graphs so that it runs in linear time, then data structure to be used is (A) Queue (B) Stack (C) Heap
SOLUTION

(D) B-Tree

The Best data structure would be heap or priority queue implemented as heap. Here we require the shortest path and in priority queue implementation the priorities may be assigned on the basis of shortest distance, so selection of max priority or min distance takes 0 (n) time. Hence (C) is correct option.
Question. 54

A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. The roots is stored at X [1]. For a node stored at X [1], the left child, if any, is stored in X [2i] and the right child, if any, in X [2i + 1]. To be able to store any binary tree on n vertices, the minimum size of X should be
Page 32

www.gatehelp.com
(A) log2 n (C) 2n + 1
SOLUTION

CS Topicwise 2001-2010 Algorithms

(B) n (D) 2n

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

Which one the following in place sorting algorithms needs the minimum number of swaps? (A) Quick-sort (B) Insertion sort (C) Selection sort
SOLUTION

(D) Heap sort

Quicksort, selection sort require, at most n swaps per iterations, the same case may occur making heap & keeping max-min property. But in insertion sort, one element is compared to all its pre index elements, but it is swapped only with 1 element but then all the elements need to move 1 index further so no. of swaps increases. So overall seeing Xeap sort would have min no. of swaps. Hence (D) is correct option.
Question. 56

Consider the following C-program fragment in which i, j, and n are integer variables. for (i = n, j = 0; i > 0; i/2, j += i); Let Val (j) =denote the value stored in the variable j after termination of the for loop. Which one of the following is true? (A) val(j) = (log n) (B) val (j) = ( n ) (C) val(j) = (n)
SOLUTION

(D) val(j) = (n log n)

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. j = n + n/2 + n/22 .......n/2 log 2 Sum of this series. Would give 6 (n) order. Hence (C) is correct option.
Question. 57
n

An element in an array X is called a leader if it is grater than all elements to the right of it in X . The best algorithm to find all leaders in an array. (A) Solves it in linear time using a left to right pass of the array (B) Solves in linear time using a right to left pass (C) Solves it is using divide and conquer in time (n log n) (D) Solves it in time (n2)
SOLUTION

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

Consider the following graph:

Page 34

www.gatehelp.com
Which one of the following cannot be the sequence of edges added, in that order, to a minimum spanning tree using Kruskals algorithm? (A) (a b),( d f),( b f).( d c),( d e) (B) (a b),( d f),( b c),( b f),( d e) (C) (d f),( a b),( d c),( d e),( d e) (D) (d f),( a b),( b f),( d e),( d e)
SOLUTION

CS Topicwise 2001-2010 Algorithms

Let us check each option (A) (a-b), (b-f), (b-f), (d-c), (d-e)

(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

Let T be a depth first search tree in a undirected graph G Vertices u and v are leaves of this tree T . The degrees of both u and v in G are at least 2. Which one of the following statements is true? (A) There must exist a vertex w adjacent to both u and v in G (B) There must exist a vertex w whose removal disconnects u and v in G (C) There must be exist a cycle in G containing u and v (D) There must exist a cycle in G containing u and all its neighbours in G
Page 35

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

Let the graph G be.

(A) is correct since W is the common vertex. (B) W is removed but u & v are not dis-connected. (C) No cycle containing u & v exist. (D) Not necessary the graph can be also.

Hence (A) is correct option.


Question. 60

A set X can be represented by an array x [n] as follows 1 if i ! X x [ i] = ) 0 otherwise Consider the following algorithm in which x, y and z are boolean arrays of size n ; algorithm zzz (x [], y [], z []){ int i ; for (i = 0; i < n; ++ i) z [i] = (x [i] / ~y [i]) 0 (~x [i] / y [i]) } The set Z computed by the algorithm is (B) (X + Y) (A) (X , Y) (C) (X Y) + (Y X)
SOLUTION

(D) (X Y) , (Y X)

Here z = (x / y') 0 (x' / y)


Page 36

www.gatehelp.com
(x + y') , (x' + y) This can be written as. (x y) , (y x) Hence (D) is correct option.
Question. 61

CS Topicwise 2001-2010 Algorithms

Consider the following is true? T (n) = 2T ([ n ])+ 1, T (1) = 1 Which one of the following is true? (A) T (n) = (loglog n) (C) T (n) = ( n )
SOLUTION

(B) T (n) = (log n) (D) T (n) = (n)

Given recurrence T (n) = 2T ([ n ]) + 1 Initially T (1) = 1 Solving it by method of change of variables Let m = log n 2 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.
Question. 62

(1)

(2)

The median of n elements can be found in O (n) time. Which one of the following is correct about the complexity of quick sort, in which remains is selected as pivot?
Page 37

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
(A) (n) (C) (n )
2

(B) (n log 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

Here we require to store two arrays each having n elements. i.e. space complexity. The calculation 0 (2n) (n) ai + ....... + a j = bi + ...... + b j is to be done n time each such calculation take constant time. So 0 (n) Hence (C) is correct.
Question. 64

Consider the following code written in a pass-by reference language like FORTAN and these statements about the code. Subroutine swap i i it i L1 : i i L2 : i it end
Page 38

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 (C) S3
SOLUTION

(B) S1 and S4 (D) S1 amd S5

S1 : Yes the compiler will generate a temporary nameless cell & initialize it to 13 and pass to swap. S2 : No error S3 : No error S4 : Program will print 13 and 8 S5 : False. Hence (B) is correct option.
YEAR 2007

Question. 65

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes is a binary tree of height h is (A) 2h (C)2h + 1 1 (B) 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.


Question. 66

22 1 23 1 2h + 1 1

The maximum number of binary trees that can be formed with three unlabeled nodes is (A) 1 (C) 4
SOLUTION

(B) 5 (D) 3

Mathematically No of binary trees = Here n = 3


6 = 1 # C3 4

1 2n C n+1 n

= 1 # 6 # 5 # 4 = 5 trees 3#2 4 Hence (B) is correct option.


Page 40

www.gatehelp.com
Question. 67

CS Topicwise 2001-2010 Algorithms

Which of the following sorting algorithms has the lowest worst-case complexity? (A) Merge sort (C) Quick sort
SOLUTION

(B) Bubble sort (D) Selection sort

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

The inorder and preorder traversal of a binary tree are dbeafcg andabdecfg respectively The postorder traversal of the binary tree is (A) debfgca (C) edbfgca
SOLUTION

(B) edbgfca (D) defgbca

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 (C)1,-,-,-,-,-,-,,3
SOLUTION

(B) 1,8,10,-,-,-,-,3 (D) 1,10,8,-,-,-,3

Hash table 0 1 2 3 4 5 6 1 8 10 3

Inputs. X 1 3 8 10 3X+4 mod 7 7 13 28 34 mod 7 mod 7 mod 7 mod 7

Hence (B) is correct option.


Question. 70

In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity, by (A) Dijkstras algorithm starting from S. (B) Warshalls algorithm
Page 42

www.gatehelp.com
(C) performing a DFS starting from S (D) preforming a BFS starting from S
SOLUTION

CS Topicwise 2001-2010 Algorithms

Since the graph is unweighted and undirected so no sense in using Diykstra or Warshall also their complexities are 0 (n2) & 0 (n3) respectively. BFS starting from S, traverses all the adjacent nodes, & then their adjacent nodes, this calculates shortest path with min complexity. Hence (D) is correct option.
Question. 71

A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I =10, what is the value of n (A) 3 (B) 4 (C) 5
SOLUTION

(D) 6

Each internal node has n children & so total nodes I # n No. of leaf in them I#n1 I (n 1) But root cant produce leaf I (n 1) + 1 = L n = L1+1 I n 41 1 + 1 10 n =5 Hence (C) is correct option.
Question. 72

In the following C function, let n # m. int gcd n {


Page 43

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
if n } How many recursive calls are made by this function? (A) (log2 n) (C) (log2 log2 n)
SOLUTION

return m; n m;

return gcd m n ;

(B) (n) (D) ( n )

In gcd n is replaced by n/m in every iteration so running time has to be less than 0 (n) or (n) even less then ( n ). It has to be (log 2 n) since recursion cause the problem size reduced by n/2 every iteration. Hence (A) is correct option.
Question. 73

What is the time complexity of the following recursive function : intDoSomething(int n) if else return(DoSomething(oor(sqrt(n)) )+ (A) (n )
2

n return 1;

n); } (B) (n log2 n) (D) (log2 log2 n)

(C) (log2 n)
SOLUTION

Here eg n = 16

T (n) = T ( n ) + n n = 4 n = 2 so

Recursion tree
Page 44

www.gatehelp.com

CS Topicwise 2001-2010 Algorithms

At any level K the problem size is n2 value reach 1. So 2 k log 2n = 1 2k = log 2 n K log 2 2 = log 2 log 2 n K = log 2 log 2 n T (n) = (log 2 log 2 n) Hence (D) is correct option.
Question. 74

eve keep recursion till this

Consider the process of inserting an element into a Max Heap, where the Max Heap is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is (B) (log2 log2 n) (A) (log2 n) (C) n
SOLUTION

(D) (n log2 n)

In a Max heap we insert 1 element this takes 0 (1) time since it is an array. Now to find correct position we perform Binary search, & we know BS an array takes 0 (log 2 n) time So (A) is correct option.
Question. 75

Let w be the minimum weight among all edge weights in an undirected connected graph, Let e be a specific edge of weight w. Which of the following is FALSE ? (A) There is a minimum spanning tree containing e . (B) If e is not in a minimum spanning tree T ,then in the cycle formed by adding e to T , all edges have the same weight.
Page 45

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

Consider every optim separately (A) since e has min weight w so there would be at test in spanning tree with e (B) e might not present in MST, but only possible if the other edge taken has also same weight

(C) Every MST must have an edge with w (D) e might not present in all MST as shown in above example. Hence (D) is correct option.
Question. 76

An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed? (A) At least 2n -c comparisons, for some constant c , are needed, (B) At most 1.5n -2 comparisons are needed. (C) At least n ,log2 n comparisons are needed. (D) None of the above
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

www.gatehelp.com
T (n) = 3n 2 2 = 1.5n 2 Hence (B) is correct option.
Question. 77

CS Topicwise 2001-2010 Algorithms

Consider the following C code segment: int IsPrime(n) { int i,n; for (i sqrt ;i (n); i if (n i ) print(Not Prime\n ; return0;) return 1; }

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

The loop runs from 2 to n . So maximum iterations can be n . When n = 2 loop has only 1 iteration so. 1 & n are lower & upper bounds respectively. (1) # T (n) # 0 (n) Hence (B) is correct option.

Data for Q. 78 & 79 are given below.


Solve the problems and choose the correct answers. Suppose the letters a, b, c, d, e, f have probabilities 1 , 1 , 1 , 1 , 1 2 4 8 16 32 respectively.
Page 47

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
Question. 78

Which of the following is the Hoffman code for the letters a, b, c, d, e, f ? (A) 0, 10, 110, 1110, 11110, 11111 (B) 11, 10, 011, 010, 001, 000 (C) 11, 10, 01, 001, 0001, 0000 (D) 110, 100, 010, 000, 111
SOLUTION

a .25

b .25

d .125

c .0625

e .01325

Arranging in ascending order.

Page 48

www.gatehelp.com

CS Topicwise 2001-2010 Algorithms

a b c d e

=0 = 10 = 110 = 1110 = 1111

Hence (A) is correct option.


Question. 79

What is the average length of the correct answer to Q. ? (A) 3 (C) 2.25
SOLUTION

(B) 2.1875 (D) 1.781

Length of Huffman code Length Prob. Product a"1 b"2 c"3 d"4 e"4 1/2 1/4 1/8 1/16 1/32 1/2 1/2 3/8 1/4 1/8
Page 49

Average length = 1/2 + 1/2 + 3/8 + 1/4 + 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

The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity. (A) (n) (C) (m + n)
SOLUTION

(B) (m) (D) (mn)

The algorithm we use for finding the number of connected components in an undirected graph on n vertices is to calculate articulation point detection algorithm. This articulation point divides the graph into 2 connected components. Complexity of this algorithm is same as 1 DFS run 0 (m + n) since DFS is the basis of articulation point. Hence (C) is correct option.
Question. 81

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 (C) QMNPRO
SOLUTION

CS Topicwise 2001-2010 Algorithms

(B) NQMPOR (D) QMNPOR

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

Hence (C) is correct option.


Question. 82

Consider the following function; f (n) = 2n g (n) = n! h (n) = n log n Which of the following statements about the asymptotic behavior of f (n). g (n) and h (n) is true?
Page 51

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 log n from order h (n) < f (n) < g (n)

g (n) is the upper bound of f (n) g (n) = 0 (f (n)) h (n) is the lower bound of f (n). h (n) = (f (n)) Hence (D) is correct option.
Question. 83

The minimum number of comparison required to determine if an integer appears more than n/2 times in a sorted array of n integers is (A) (n) (C) (log * n)
SOLUTION

(B) (log n) (D) (1)

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
eg n = 10 =122222468 = 2 correct = 2 correct = 2 correct 6log 2 10@ = 3 (log n) Hence (B) is correct option.
Question. 84

CS Topicwise 2001-2010 Algorithms

AB -tree of order 4 is built from scratch by 10 successive insertions. What is the maximum number of node splitting operations that may take place? (A) 3 (B) 4 (C) 5
SOLUTION

(D) 6

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 4 K # 1 + log 2 b10 l & 1 + log 2 3 K #B Hence (A) is correct option.
Question. 85

G is a graph on n vertices and 2n 2 edges. The edges of G can be partitioned into two edge-disjiont spanning trees. Which of the following is NOT true for G ? (A) For every subset of k vertices, the induced sub graph has a most
Page 53

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

Consider this graph with n = 4

Two spanning trees

Statement (B), (C) & (D) are correct.

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

Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into sub-lists each of which contains at least one-fifth of the elements. Let T (n) be the
Page 54

www.gatehelp.com
number of comparisons required to sort n elements. Then (A) T (n) # 2T (n/5) + n (B) T (n) # T (n/5) + T (4n/5) + n (C) T (n) # 2T (4n/5) + n (D) T (n) # 2T (n/2) + n
SOLUTION

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

The subset-sum problem is defined as follows: Given a set S of n positive integers and a positive integer W ; determine whether there is aa subset of S whose elements sum to W . An algorithm Q Solves this problem in O (nW) time. Which of the following statements is false? (A) Q sloves the subset-sum problem unpolynomial time when the input is encoded in unary (B) Q solves the subset-sum problem is polynominal time when the input is encoded in binary (C) The subset sum problem belongs to the class NP (D) The subset sum problem in NP-hard
SOLUTION

W is an integer so the time taken by the algorithm is (n) only. Since subset problem is NP complete, it should be in class NP & NP hard, so option (C) & (D) are true. Using unary integer the algorithm will be solved in (n) time but using binary it would take more time depending upon no. of bits. So option (B) is false
Page 55

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

(A) only vertex a (C) only vertices,a, b, c, d

(B) only vertices a, e, f, g, h (D) all the vertices

SOLUTION

We apply Dijkstra Algorithm. Vertex I(a) II(a) III(b) IV(e) V(f) VI(c) VII(h) VIII(g) I I V III III IV VII VI a"b=1 a " h = 2
Page 56

a b c d e f g h

0 1 3 3 3 3 3 3

0 1 3 3 2 3 3 3

0 1 3 3 2 0 3 3

0 1 3 3 2 0 3 2

0 1 3 6 2 0 3 2

0 1 3 6 2 0 3 2

0 1 3 6 2 0 3 2

Order a b e f c h g d a"c=3 a"b=6 a"g=3 a " e = 2 a " f = 0

www.gatehelp.com

CS Topicwise 2001-2010 Algorithms

Since there is no ve cycle so Dijkstra gives correct result for all vertices. Hence (D) is correct option.
Question. 89

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

To construct a BST from post order we also require in-order traversal since given the elements are 1 2.......n So their sorted order would be in order. Using both BST can be constructed in a linear scan. So it will take only n time. Hence (B) is correct option.
Question. 90

We have a binary heap on n elements and wish to insert n more elements (not necessarily one after another) into this heap. The total time required for this is (A) (log n) (C) (n log n) (B) (n) (D) (n2)
Page 57

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

Heaps are implemented as simple arrays, to insert n more elements each element take (1) time. So total time would be (n). Hence (D) is correct option.

Common data for Questions 91 & 92:


Consider the following C functions: int f1 (int n) { If(n==0||n==1) return n; else return(2)f1(n-1)+3)f1(n-2)); } int f2(int n) { int i; int X[N], Y[N], Z[N]; X[1]=1;Y[1]=2;Z[1]=3; for (i=2;i<=n;i++){ X[i]=Y[i-1]+Z[i-2]; Y[i]=2)X[i]; z[i]=3)X[i]; } return X[n]; }
Question. 91

The running time of f1 (n) and f2 (n) are (A) (n) and (n) (B) (2") and O (n) (C) (n) and (2")
SOLUTION

(D) (2") and (2")

Procedure f1 has the nature T (0) = 0 , T (1) = 1 = 2c T (n) = 2T (n 1) + 3T (n 2)


Page 58

www.gatehelp.com
Solution to this recursion is 2n So (2n) Procedure f2 has a single for loop from 2 to n so the complexity will be (n). Hence (B) is correct option.
Question. 92

CS Topicwise 2001-2010 Algorithms

f1 (8) f2 (8) return the values (A) 1661 and 1640 (C) 1640 and 1640
SOLUTION

(B) 59 and 59 (D) 1640 and 1661

f1 (8) n Value Return 1094 + 546 = 1640 364 + 183 = 547 122 + 60 = 182 40 + 21 = 61 14 + 6 = 20 4+3 = 7 2 1 0 f (1) (8) = 1640 Now X [ 1] = 1 Y [ 1] = 2 Z [ 1] = 3 Iteration X[i] 2 3 4 5 6 2+0 = 2 4+3 = 7 14 + 6 = 20 40 + 21 = 61 122 + 60 = 182 Y[i] 4 14 40 122 364 Z[i] 6 21 60 183 546
Page 59

8 2f1 (7) + 3f1 (6) 7 2f1 (6) + 3f1 (5) 6 2f1 (5) + 3f1 (4) 5 2f1 (4) + 3f1 (3) 4 2f1 (3) + 3f1 (2) 3 2f1 (2) + 3f1 (1) 2 2f1 (1) + 3f1 (0) 1 1 0 0

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
7 8 364 + 183 = 547 1094 + 546 = 1640 1094 1641

Return X [8] = 1640 finally Hence (C) is correct option.

Statement for Linked Answers Questions 93 & 94:


The subset-sum problem is defined as follows. Given set of n positive integers, S = {a1, a2, a3,....... an} and a positive integer W is there a subset S whose elements sum of W ? A dynamic program for solving this problem uses a 2-dimensiond Boolean array, X with n rows and W-1 columns X [i, j], 1 # i # W, is TRUE if and only if there is a subset of {a1, a2,...... ai} whose elements sum to j .
Question. 93

Which of the following is valid for 2 # i # n and a1 # j # W? (A) X [i, j] = X [i 1, j] 0 X [i, j ai] (B) X [i, j] = X [i 1, j] 0 X [i 1, j ai] (C) X [i, j] = X [i 1, j] / X [i, j ai] (D) X [i, j] = X [i 1, j] / X [i 1, j ai]
SOLUTION

Dynamic programming can be successfully used, i.e n rows for n elements & w + 1 columns. Each row is filled on the basis of its previous rows & the (j ai) th column. If any of them is 0 then X [i, j] should be zero. This require X [i, j] = X [i 1, j] V # [i 1, j ai] Hence (B) is correct option.
Question. 94

Which entry of the array X , if TRUE, implies that there is a subset whose elements sum to W? (A) X [1, W] (C) X [n, W]
Page 60

(B) X [n, 0] (D) X [n 1, n]

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Algorithms

The algorithm of dynamic programming has n rows & w columns. These would be filled dynamically depending upon previous rows & columns. So X [n, w] will be filled in the last & this would give the result. If X [n, w] = 1 i.e. TRUE, then we know that there is subset present whose sum = integer w . Otherwise subset not present. Hence (C) is correct option.

Statement for Linked Answers Questions 95 & 96:


Consider the following C program that attempts to locate an element x in an array Y [ ] using binary search. The program is erroneous. 1. 1 2. 3. 4. do { 5. 2 6. if i 7. } while i print f is in the array); 8. if 9. else printf is not in the array); 10. }
Question. 95

On which of the following contents of Y and x does the program fail? (A) Y is [1 2 3 4 5 6 7 8 9 10] and x < 10 (B) Y is [1 3 5 7 9 11 13 15 17 19] and x < 1 (C) Y is [2 2 2 2 2 2 2 2 2 2] and x > 2 (D) Y is [2 4 6 8 10 12 14 16 18 20] and 2 < x < 20 and x is even
SOLUTION

Running on option (C) i = 0 to 9 X let 3 2222222222 i 0 j K y [K] y [K] ! = X i < j 2 True True
Page 61

9"5 5

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
0 0 0 0 5"3 3 3"2 2 2"1 1 1 1 2 2 2 2 True True True True 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

The correction needed in the program to make it work properly is (A) change line 6 to : if (Y [k]) < x) i = k + 1; else j = k - 1; (B) change line 6 to: if (Y [k] < x) i = k 1; else j = k + 1; (C) change line 6 to: if (Y [k] < x) i = k; else j = k; (D) change line 7 to : } while ((Y [k] == x)&&( i < j));
SOLUTION

A slight change can be made which will prevent this loop to go infinite in line 6 : if Y (K) < x i = K + 1; else j = K 1; Should be there. Hence (A) is correct option.
YEAR 2009 Question. 97

What is the number of swaps required to sort n elements using selection sort, in the worst case ? (A) (n) (C) (n )
2

(B) (n log n) (D) (n2 log n)

Page 62

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Algorithms

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. Always finds a negative weighted cycle, if one exists. Finds whether any negative weighted cycle is reachable from the source (A) P only (B) Q only (C) Both P and Q
SOLUTION

(D) Neither P nor Q

Bellman ford Algorithm is used when there are negative weights assigned to the edges, this can cause generation of ve cycles, reached from the source vertex. So both statements are correct. Hence (C) is correct option.
Question. 99

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

Problems which are both NP & NP hard are called NP complete problems. So option (C) is correct option. (A) Cant be correct since P ! NP , so there can be any Algorithm with P time. (B) Is not true, if some solved deterministically but if not NP complete then cant be P = NP . (D) Is not correct because some problems which are NP decidable under certain conditions.
Question. 100

The running time of an algorithm is represented by the following recurrence relation: 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

n#3

(D) (n2 log n)

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

www.gatehelp.com
= (n) Hence (A) is correct option.
Question. 101

CS Topicwise 2001-2010 Algorithms

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) 0 1 2 3 4 5 6 7 8 9 (C) 0 1 2 3 4 5 6 7 8 9 12 13 2 3 23 5 18 15 (D) 0 1 2 3 4 5 6 7 8 9
Page 65

(B) 0 1 2 23 15 2 3 4 5 6 7 18 8 9 18 5 12 13

12, 2 13, 3, 23

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
SOLUTION

0 1 2 3 4 5 6 7 8 9

K = 12, 18, 13, 2, 3, 23, 5, 15 h K mod 10 Step 1 3 12 13 2 3 23 5 18 15 Step 2 8 4 5 6 7

Hence (C) is correct option.


Question. 102

Consider the following graph:

Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskals algorithm ? (A) (b, e) (e, f) (a, c) (b, c) (f, g) (c, d) (B) (b, e) (e, f) (a, c) (f, g) (b, c) (c, d) (C) (b, e) (a, c) (e, f) (b, c) (f, g) (c, d) (D) (b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
SOLUTION

Krushals algorithm, arranging edges in ascending order.


Page 66

www.gatehelp.com
{2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6}

CS Topicwise 2001-2010 Algorithms

(A)

(B)

(C)

(D) (A, C) cant be taken after (B, C). Hence (D) is correct option.
Question. 103

In quick sort, for sorting n elements, the (n/4th) smallest element is selected as pivot using an O (n) time algorithm. What is the worst
Page 67

CS Topicwise 2001-2010 Algorithms

www.gatehelp.com
case time complexity of the quick sort ? (A) (n) (C) (n )
2

(B) (n log n) (D) (n2 log 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.

Common Data for Question 104 & 105 :


A sub-sequence of a given sequence is just the given sequence with some elements (possibly none of all) left out. We are given two sequence X [m] and Y [n] of length m and n , respectively, with indexes of X and Y starting from 0.
Question. 104

We wish to find the length of the longest common sub-sequence (LCS) of x [m] and Y [n] of lengths m and n , where an incomplete recursive definition for the function l (i, j) to compute the length of the LCS of X [m] and Y [n] is given below : l (i, j) =0, if either i = 0 or j = 0 =expr1, if i , j > 0 and x [i 1] = Y [j 1] =expr2, if i , j > 0 and x [i 1] = Y Y [ j 1] Which one of the following options is correct ? (A) expr 1/ l (i 1, j) + 1 (B) expr 1/ l (i, j 1) (C) expr 2/ max (l (i 1, j), l (i, j 1)) (D) expr 2/ max (l (i 1, j 1), l (i, j))
Page 68

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Algorithms

LCS problem is solved using dynamic programming in which every row is dependent upon previous rows & columns. If two literals at ith row & jth column doesnt match then. Eve fill l [i, j] with max [L [i 1, j], [i, j 1]] i.e max of previous cell in row & column. So expr 1 = L [i 1, j 1] + 1 expr 2 = max ([l [i 1, j], L [i, j 1]]) Hence (C) is correct option.
Question. 105

The values of l (i, j) could be obtained by dynamic programming based on the correct recursive definition of l (i, j) of the form given above, using an array L [M, N], where M = m + 1and N = n + 1, such that L [i, j] = l (i, j). Which one of the following statements would be true regarding the dynamic programming solution for the recursive definition of l (i, j) ? (A) All elements of L should be initialized to 0 for the values of l (i, j) to be properly computed. (B) The values of l (i, j) may be computed in a row major order or column major order of L [M, N] (C) The values of l (i, j) cannot be computed in either row major order or column major order of L [M, N] (D) L [p, q] needs to be computed before L [r, s] if either p < r or q < s
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

Two alternative package A and B are available for processing a database having 10k records. Package A requires 0.0001 n2 time units and package B requires 10n log 10 n time units to process n records. What is the smallest value of k for which package B will be preferred over A ? (A) 12 (C) 6
SOLUTION

(B) 10 (D) 5

No. of record = 10K K = ? A = .0001n2 2 A = n5 10 Required time A >time B. n2 > 10 n log n 10 105 So here the co.eff. is 106 So smallest value of K = 6 Hence (C) is correct option.
Question. 107

n B = 10n log 10

The weight of a sequence a 0, a1 ......, an 1 of real numbers is defined as a 0 + a1 /2 + ......an 1 /2n 1 . A subsequence of a sequence is obtained by deleting some elements form the sequence, keeping the order of the remaining elements the same. Let X denote the maximum possible weight of a subsequence of a 0, a1, .......an 1 and Y the maximum possible weight of a subsequence of a1, a2, ......., an 1 . Then X is equal to (A) max (Y, a 0 + Y) (C) max (Y, a 0 + 2Y)
SOLUTION
1 Given X a 0 + a1 + a2 + ....... an n1 2 22 2

(B) max (Y, a 0 + Y/2) (D) a 0 + Y/2

(1)

Page 70

www.gatehelp.com
1 Y = a1 + a 2 + a 3 + ............ an 2 22 2n 2

CS Topicwise 2001-2010 Algorithms

(2)

Dividing eq. (2) by 2 Y a1 + a2 + a 3 ............. an 1 2 2 22 2 3 2n 1 Putting eq. (3) in eq. (1) X = a0 + Y 2 Hence (D) is correct option.

(3)

Common Data for Questions 108 & 109


Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the matrix W below is the weight of the edge {i, j} . J0 K K1 W = K8 K K1 K4 L
Question. 108

1 0 12 4 9

8 12 0 7 3

1 4 7 0 2

4N O 9O 3O O 2O 0O P

What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the tree T ? (A) 7 (C) 9
SOLUTION

(B) 8 (D) 10

let {0, 1, 2, 3, 4} be {a, b, c, d, e}

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

What is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges ? (A) 7 (B) 8 (C) 9
SOLUTION

(D) 10

Min possible path from B to C so we draw all paths from B to C

B " C = 12 B " A " C = 1+8 = 9 B " E " C = 9 + 3 = 12


Page 72

www.gatehelp.com
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.

CS Topicwise 2001-2010 Algorithms

**********

Page 73

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Compiler Design

YEAR 2001 Question. 1

Which of the following statements is false ? (A) An unambiguous grammar has same left most and right most derivation (B) An LL (1) parser is a top-down parser (C) LALR is more powerful than SLR (D) An ambiguous grammar can never be LR (K) for any k
SOLUTION

Yes, the LL (1) parser is top down parser. Order of strength LR < SLR < LALR . So (A) & (C) are, true. An ambiguous grammar cant be LR (K) So option (A) is false since an unambiguous grammar has unique right most derivation & left most derivations but both are not same. Hence (A) is correct option
YEAR 2002 Question. 2

Dynamic linking can cause security concerns because (A) Security is dynamic (B) The path for searching dynamic libraries is not known till run

CS Topicwise 2001-2010 Compiler Design

www.gatehelp.com
time. (C) Linking is insecure (D) Cryptographic procedures are not available for dynamic linking
SOLUTION

Dynamic linking is type of linking in which libraries required by the program are linked during run time. But at this time cryptographic procedures are not available, so make this process insecure. Hence (D) is correct option.
YEAR 2003

Question. 3

Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar? (A) Removing left recursion alone (B) Factoring the grammar alone (C) Removing left recursion and factoring the grammar (D) None of this
SOLUTION

If a grammar has left recursion & left factoring then it is ambiguous. So to convert a CFG to LL (1) grammar both removal of left recursion & left factoring need to be done. Hence (C) is correct option.
Question. 4

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
SOLUTION

CS Topicwise 2001-2010 Compiler Design

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

In a bottom-up evaluation of a syntax directed definition, inherited attributes can (A) always be evaluated (B) be evaluated if the definition is L-attributed (C) be evaluated only if the definition has synthesized attributes (D) never be evaluated
SOLUTION

Every S (synthesized) -attributed definitions is L - attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes. Hence (C) is correct option.
Question. 6

Which of the following statements is FALSE? (A) In statically typed language, each variable in a program has a fixed type (B) In up-typed languages, values do not have any types (C) In dynamically typed languages, variables have no types (D) In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program
SOLUTION

(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

Consider the grammar shown below S " | EtSS' | S' " eS | ! E "b In the predictive parse table. M , of this grammar, the entries M [Sl, ] and M [S',$] respectively are (A) {s' " eS} and {S' " } (B) {s' " eS}and{} (C) {s' " } and {S' " }
SOLUTION

(D) {s' " eS, S' " }and{ S' " }

Given grammar S " EtSSl Sl " eS E "b Terminals N.T S Sl S " iEtSSl S" Sl " eS 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

Sl "

Consider the grammar shown below. S "C C C " eC | d The grammar is (A) LL (1) (B) SLR (1) but not LL (1) (C) LALR (1) but not SLR (1)
Page 4

www.gatehelp.com
(D) LR (1) but not LALR (1)
SOLUTION

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

Consider the translation scheme shown below S " TR R " + T {print (+);} R | T " num {print (num.val);} Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string 9 + 5+ 2, this translation scheme will print (A) 9 + 5 + 2 (C) 9 5 2 ++
SOLUTION

(B) 9 5 + 2 + (D) ++ 9 5 2

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

Consider the syntax directed definition shown below S " id: = E " newtemp (); gen . place . place;); (t .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

In 3-address code we use temporary variables to reduce complex instructions so here t1 = Y t2 = Z t 3 = t1 + t 2 x = t3 Hence (D) is correct option.
Page 6

www.gatehelp.com Data for Q. 11 & 12 are given below.


Solve the problems and choose the correct answers. The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions. global inti void int i print i print } main () { (i
Question. 11

CS Topicwise 2001-2010 Compiler Design

) }

If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are (A) 115, 220 (B) 25, 220 (C) 25, 15
SOLUTION

(D) 115, 105

In static scoping the variables are initialized at compile time only So i = 100 & j = 5 P (i + j) = P (100 + 5) = P (105) So x = 105 x + 10 = 105 + 10 = 115 So 115 & 105 will be printed. Hence (D) is correct option.
Question. 12

If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are (A) 115, 220 (B) 25, 220
Page 7

CS Topicwise 2001-2010 Compiler Design

www.gatehelp.com
(C) 25, 15
SOLUTION

(D) 115, 105

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

Consider the following class definitions in a hypothetical object oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, thought the syntax is similar Class P { Class Q subclass of P { void f(int i) { void f (int i) { print (i); print ( i); } } } } Now consider the following program fragment: P x =new Q (); Q y =new Q (); P z =new Q (); x.f (1);(( P) y). f (1); z.f (1); Here ((P) y) denotes a typecast of y to P . The output produced by executing the above program fragment will be (A) 1 2 1 (B) 2 1 1 (C) 2 1 2 (D) 2 2 2

Page 8

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Compiler Design

1. 2. 3. 4. 5. 6.

Px = newQ (); Qy = newQ (); Pz = newQ (); x : f (1); print 2 # i = 2 ((P) y) : f (1); 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

Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries? (A) Smaller sizes of executable (B) Lesser overall page fault rate in the system (C) Faster program startup (D) Existing programs need not be re-linked to take advantage of newer versions of libraries
SOLUTION

The advantages of shared dynamically linked libraries include. (A) smaller size of executable since less data (B) lesser overall page fault rate. (C) No need for re-linking if newer versions of libraries are there. But since compilation time doesnt include linking so a long linking time required during runtime in DLL's so slow startup. Hence (C) is correct option.
YEAR 2004 Question. 15

Which of the following grammar rules violate the requirements of an


Page 9

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 (iii) P " (A) (i) only (C) (ii) and (iii) only
SOLUTION

(ii) P " Q s R (iv) P " Q t R r (B) (i) and (iii) only (D) (iii) and (iv) only

(I)

P " QR is not possible since two NT should include one operator as Terminal. (II) Correct (III) Again incorrect. (IV) Correct. Hence (B) is correct option.

Question. 16

Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2 , the reference will be resolved at (A) Edit-time (C) Link-time
SOLUTION

(B) Compile-time (D) Load-time

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

Consider the grammar rule E " E1 E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub expression, in order to get the shortest possible code (A) E1 should be evaluated first (B) E2 should be evaluated first
Page 10

www.gatehelp.com
(C) Evaluation of E1 and E2 should necessarily be interleaved (D) Order of evaluation of E1 and E2 is of no consequence
SOLUTION

CS Topicwise 2001-2010 Compiler Design

E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2 also. So E2 should be evaluated first & then E1, so finally E1 will be in accumulator, otherwise need to use move & load instructions. Hence (B) is correct option.
Question. 18

Consider the grammar with the following translation rules and E as the start symbol. value = .value * .value} E " E 1 #T .value = .value} .value = .value + .value} " .value = .value} .value =num.value} " num Compute E . value for the root of the parse tree for the expression: 2 # 3 # & 5 # 6 & 4. (A) 200 (B) 180 (C) 160
SOLUTION

(D) 40

The parse tree would be.

Now we evaluate bottom up.


Page 11

CS Topicwise 2001-2010 Compiler Design

www.gatehelp.com

LL " left to right left most derivation no ambignity should be there SLR or LR (0) L to R reverse right sentential form create LR (0) items. CLR or LR (1) create LR (1) items no bound LALR reduced CLR if while reducing any conflict found then not LALR

Hence (C) is correct option.


Page 12

www.gatehelp.com
YEAR 2005 Question. 19

CS Topicwise 2001-2010 Compiler Design

The grammar A " AA |( A)| is not suitable for predictive-parsing because the grammar is (A) ambiguous (C) right-recurisve
SOLUTION

(B) Left-recursive (D) an operator-grammar

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

Consider the grammar E " E + n | E # n | n For a sentence n + n , the handles in the right-sentential form of the reduction are (A) n, E + n and E + n # n (C) n, n + n and n + n # n
SOLUTION

(B) n, E + n and E + E # n (D) n, E + n and E # n

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

Consider the grammar


Page 13

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
SOLUTION

(D) n1 $ n3 $ n2

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

Consider line number 3 of the following C-program. int main (){ | * Line 1 * | int 1, N; | * line 2 * | fro (i | * Line 3 * | , 1 N, 1 ); } Identify the compilers response about this line while creating the object-module (A) No compilation error (B) Only a lexical error (C) Only syntactic errors (D) Both lexical and syntactic errors
SOLUTION

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.

Data for Q. 23 & 24 are given below.


Solve the problems and choose the correct answers. Consider the following expression grammar. The semantic rules for
Page 14

www.gatehelp.com
expression calculation are stared next to each grammar production. E"

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

The grammar has equal precedence and it is also ambiguous. Since LALR (1) parser prefer shift over reduce so + operation will be executed here before ). 2 + 1 = 3 & 3 # 3 = 9 also the operators are right associative. Hence (B) is correct option.
YEAR 2006 Question. 25

Consider the following grammar. S S E E F " S*E "E " F+E "F " id

Consider the following LR (0) items corresponding to the grammar above. (i) (ii) (iii) S " S * .E E " F. + E 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) (C) (i) and (iii)
SOLUTION

(B) (ii) and (iii) (D) None of these

If S " S ): E is in LR (0) then E " F + : E will also be there because both of them has ' : ' before E . Hence (C) is correct option.

Page 16

www.gatehelp.com
Question. 26

CS Topicwise 2001-2010 Compiler Design

Consider the following grammar S " FR R "*S| F " id In the predictive parser table, M , of the grammar the entries M [S, id] and M [R,$] respectively (A) {S " FR} and {R " } (C) {S " FR} and {R " * S}
SOLUTION

(B) {S " FR} and {} (D) {F " id} and {R " }

The predictive parser table is given as. Non Terminal S F R So at R " ) S R "! M [S, id] = {S " FR} M [R, $] = {R "!} Hence (A) is correct option.
Question. 27

id S " FR F " id

R "!

Consider the following translation scheme. S " ER R " * E {print { * ); R | f E " F + E {print ( + ); | F F " (S) | id {print (id.value);} Here id is a taken that represents an integer and id . value represents the corresponding integer value. For an input 2 * 3 + 4, this translation scheme prints (A) 2 * 3 + 4 (B) 2 * + 3 4 (C) 2 3 * 4 +
SOLUTION

(D) 2 3 4 + *

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

Consider the following C code segment.

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

Which one of the following grammars generates the language


Page 18

www.gatehelp.com
L = (ai bi | i ! j}? (A) S " AC | CB C " aCb | a | b A " aA | B " Bb | (C) S " ACCB C " aCb | ! A " aA | ! B " Bb | !
SOLUTION

CS Topicwise 2001-2010 Compiler Design

(B) S " aS | Sb | a | b

(D) S " AC | CB C " aCb | ! A " aA | a B " bB | b

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

In the correct grammar above, what is the length of the derivation (number of steps starting from S to generate the string al bm with l ! m? (A) max (l, m) + 2 (B) l+m+2 (C) l + m + 3
SOLUTION

(D) max (l, m) + 3

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

Which one of the following is a top-down parser? (A) Recursive descent parser (B) Operator precedence parser (C) An LR(k) parser
SOLUTION

(D) An LALR(k) parser

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

Consider the grammar with non-terminals N = {S, C, S}, terminals T = {a, b, i, t, e}, with S as the start symbol, and the following of rules S " iCtSS1 | a S1 " eS | C"b The grammar is NOTLL(1) because: (A) It is left recursive (B) It is right recursive (C) It is ambiguous
SOLUTION

(D) It is not context-free

The grammar has production S " iCtSS1 here the right hand side of grammar has the same symbol as left side. So the grammar is left recursive. The grammar is not ambiguous. Hence (A) is correct option.
Page 20

www.gatehelp.com
Question. 33

CS Topicwise 2001-2010 Compiler Design

Consider the following two statements: P: Every regular grammar is LL(1) Q: Every regular set has LR(1) grammar Which of the following is TRUE? (A) Both P and Q are true (C) P is false and Q is true
SOLUTION

(B) P is true and Q is false (D) Both P and Q are false

LL (1) parsers can recognize the regular grammars also LL (1) is subset of LR (1) or CLR grammar so it also recognizes regular sets. So both accept regular grammar.
Question. 34

In a simplified computer the instructions are: OP Rj , Ri Performs R j OP Ri and stores the result in register Ri OP m, Ri Performs val OP Ri abd stores the result in Ri. value denotes the content of memory location m . MCVm, Ri Moves the content off memory loction m to register Ri . MCVm, Ri, m Moves the content of register Ri to memory location m. The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block: t1 t2 t3 t4 = 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 (C) 5 (B) 3 (D) 6

Page 21

CS Topicwise 2001-2010 Compiler Design

www.gatehelp.com
SOLUTION

The operation sequence would be MOV a, R1 ADD b, R1 {R1 = t1 MOV c, R2 ADD d, R2 {R2 = t2 SUB e, R2 {t 3 = e R2 = R2 SUB R1, R2 {R2 = t 4 MOV R2, t 4 {finally in memory Totally no. of move operation are 3 Hence (B) is correct option

Data for Q. 35 & 36 are given below.


Solve the problems and choose the correct answers. Consider the CFG with {S, A, B} as the non-terminal alphabet, {a, b} as the terminal alphabet, S as the start symbol and the following set of production rules s " bA S " aB A"a B"b A " aS B " bS A " bAA B " aBB

Question. 35

Which of the following strings is generated by the grammar? (A) aaaabb (C) aabbab
SOLUTION

(B) aabbbb (D) abbbba

aabbab S " aB " aaBB " aabSB " aabbAB " aabbab Hence (C) is correct option.
Page 22

www.gatehelp.com
Question. 36

CS Topicwise 2001-2010 Compiler Design

For the correct answer string to Q. 9 how many derivation trees are there? (A) 1 (C) 3
SOLUTION

(B) 2 (D) 4

For the derivation two trees are possible

So due to ambiguity 2 trees are possible Hence (B) is correct option.


YEAR 2008

Question. 37

Which of the following describes a handle (as applicable to LRparsing) appropriately? (A) It is the position in a sentential form where the next shift or reduce operation will occur (B) It is a non-terminal whose production will be used for reduction in the next step (C) It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur. (D) It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found
Page 23

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

Some code optimizations are carried out on the intermediate code because (A) They enhance the portability of the complier to other target processors (B) Program analysis is name accurate on intermediate code than on machine code (C) The information from data flow analysis cannot otherwise be used for optimization (D) The information from the front end cannot otherwise be used for optimization
SOLUTION

Code optimizations are carried out on the intermediate code because program analysis is more accurate on intermediate code than on machine code. Hence (B) is correct option.
Question. 39

Which of the following are true? (i) A programming language option does not permit global variables of any king and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation (ii) Multi-level access link (or display) arrangement is needed to arrange activation records-only if the programming language being implemented has nesting of procedures/function (iii) Recursion in programming languages cannot be implemented with dynamic storage allocation (iv) Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stackbased allocation scheme for activation records
Page 24

www.gatehelp.com
(v) Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records (A) (ii) and (v) only (C) (i), (ii) and (v)
SOLUTION

CS Topicwise 2001-2010 Compiler Design

(B) (i), (iii) and (iv) only (D) (ii), (iii) and (v) only

I.

Statement is false since global variables are required for recursions with static storage. This is due to unavailability of stack in static storage. II. This is true III. In dynamic allocation heap structure is used, so it is false. IV. False since recursion can be implemented. V. Statement is completely true. So only II & V are true. Hence (A) is correct option.
Question. 40

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if (A) The SLR(1) parser for G has S-R conflicts (B) The LR(1) parser for G has S-R conflicts (C) The LR(0) parser for G has S-R conflicts (D) The LALR(1) parser for G has reduce-reduce conflicts
SOLUTION

LALR parser is reduced form of CLR or LR (1) parser, LALR parser uses the LR (1) items of CLR parser & of any shift reduce conflicts are there then it is due to LR (1) parser. Hence (B) is correct option.
YEAR 2009 Question. 41

Which of the following statements are TRUE ? I. There exist parsing algorithms for some programming languages
Page 25

CS Topicwise 2001-2010 Compiler Design

www.gatehelp.com
whose complex are less than (n3) II A programming language which allows recursion can be implemented with static storage allocation

III No L-attributed definition can be evaluated in the framework of bottom-up parsing IV Code improving transformations can be performed at both source language and intermediate code level (A) I and II (C) III and IV
SOLUTION

(B) I and IV (D) I, III and IV

I.

Statement is true since there are some parsers which take 0 (n log 2 n) time for parsing. II. Completely false, since there is no use of stack which is required for recursion. III. False IV. True since both types of optimizations are applied Hence (B) is correct option.
YEAR 2010 Question. 42

What data structure in a complier is used for managing information about variables and their attributes? (A) Abstract syntax tree (B) Symbol table (C) Semantic stack
SOLUTION

(D) Parse table

Symbol table is used for storing the information about variables and their attributes by compiler. Hence (B) is correct option.
Question. 43

Which languages necessarily need heap allocation in the runtime environment ? (A) Those that support recursion
Page 26

www.gatehelp.com
(B) Those that use dynamic scoping (C) Those that allow dynamic data structure (D) Those that use global variables
SOLUTION

CS Topicwise 2001-2010 Compiler Design

Dynamic memory allocation is maintained by heap data structure. So to allow dynamic data structure heap is required. Hence (C) is correct option.
Question. 44

The grammar S "aSA|bS|c is (A) LL (1) but not LR (1) (C) Both LL (1) and LR (1)
SOLUTION

(B) LR (1) but not LL(1) (D) Neither LL (1) nor LR (1)

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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Computer Network

YEAR 2003 Question. 1

Which of the following assertions is false about the internet Protocol (IP) ? (A) It is possible for a computer to have multiple IP addresses (B) IP packets from the same source to the same destination can take different routes in the network (C) IP ensures that a packet is farwarded if it is unable to reach its destination within a given number of hopes (D) The packet source cannot set the route of an outgoing packets; the route is determined only by the routing tables in the routers on the way.
SOLUTION

Internet protocol ensures that a packet is forwarded if it is unable to reach its destination within a given no. of hops. One computer can have multiple IP addresses also packets having same source & destination can take different routes. Source doesnt decide where to route the packet, but it is decided by the routing tables at intermediate routers. Hence (D) is correct option.
Question. 2

Which of the following functionalities must be implemented by a

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

Transport protocols are mainly for providing end to end connections by making sockets. Recovery from packet loss & delivery in correct order, duplication is checked by Data link layer. Hence (D) is correct option.
Question. 3

The subnet mask for a particular network is 255.255.31.0 Which of the following pairs of IP addresses could belong to this network ? (A) 172.57.88.62 and 172.56.87.23.2 (B) 10.35.28.2 and 10.35.29.4 (C) 191.203.31.87 and 191.234.31.88 (D) 128.8.129.43 and 128.8.161.55
SOLUTION

(A) Given subnet mask 255.255.31.0 11111111 .11111111 .00011111 .00000000 Option (A) & (C) has 16 MSBs different so IP address cant belong to same network. In option (B) & (C) let us see LSBs. 28.2 00011100.00000010 (B) 29.4 00011101.00000101 Anding with 00011111. 0000000 Both give different results. So not possible. 10000001.00101011 129.43 (D) 00011111.00000000 Anding 00000001.00000000
Page 2

www.gatehelp.com
10100001.00110111 161.55 00011111.00000000 00000001.00000000 Both belong to same network. Hence (D) is correct option.
Question. 4

CS Topicwise 2001-2010 Computer Network

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 (C) 200 bytes
SOLUTION

(B) 100 bytes (D) None of the above

Total distance for RTT = 4 Km Transfer rate = 2 # 108 ms 1 3 Time to transfer = 4 # 108 2 # 10 = 2 # 10 5 sec Data rate = 107 bps Packet size = 2 # 10 5 # 107 bytes = 200 bytes Hence (C) is correct option.
Question. 5

Host A is sending data to host B over a full duplex link. A and B are using the sliding window protocol for flow control. The send and receive window sizes are 5 packets each. Data packets (sent only from A to B) are all 1000 bytes long and the transmission time for such a packet is 50 s . Acknowledgment packets (sent only from B to A), are very small and require negligible transmission time. The propagation delay over the link is 200 s . What is the maximum achievable throughput in this communication ? (A) 7.69 # 106 bps (C) 12.33 # 106 bps (B) 11.11 # 106 bps (D) 15.00 # 106 bps
Page 3

CS Topicwise 2001-2010 Computer Network

www.gatehelp.com
SOLUTION

Data packet size No. of packets Total data Propagation delay Transmission time So far 5 packets Total time for 5 packets

= 1000 bytes =5 = 5000 bytes. = 200 s = 50 s /Packet. = 50 # 5 = 250s = 250 + 200 = 450s 5000 Rate = Data = Time 450 # 10 6 = 11.11 # 106 bps

Hence (B) is correct option.


YEAR 2004 Question. 6

Choose the best matching Group 1 and Group 2. Group-1 P. Data link layer Q. Network layer Group-2 1. Ensures reliable transport of data over a physical point-to-point link 2. Encodes/ decodes data for physical transmission 3. Allowed-to-end communication between two processes (B) P-2, Q-4, R-1 (D) P-1, Q-3, R-2

R. Transport layer (A) P-1, Q-4, R-3 (C) P-2, Q-3, R-1
SOLUTION

Transport layer is responsible for end to end communication, creation of sockets. Network layer routes the data from one node to other, till it reach to destination. Datalink layer ensures reliable data transfer by error correction, duplication check ordered delivery etc. P 1, Q 4, R 3 Hence (A) is correct option.
Page 4

www.gatehelp.com
Question. 7

CS Topicwise 2001-2010 Computer Network

Which of the following is NOT true with respective to a transparent bridge and a router ? (A) Both bridge and router selectively farward data packets (B) A bridge uses IP addresses while a router uses MAC addresses (C) A bridge builds up its routing table by inspecting incoming packets (D) A router can connect between a LAN and a WAN.
SOLUTION

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

How many 8-bit characters can be transmitted per second over a 9600 baud serial communication link using asynchronous mode of transmission with one start bit, eight data bits, and one parity bit ? (A) 600 (C) 876
SOLUTION

(B) 800 (D) 1200

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
SOLUTION

(D) 1.0

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

The routing table of a router is shown below : Destination 128.75.43.0 128.75.43.0 192.12.17.5 deraulf Subnet Mask 255.255.255.0 255.255.255.128 255.255.255.255 Interface Eth 0 Eth 1 Eth 3 Eth 2

On which interface will the router farward packets addressed to destinations 128.75.43.16 and 192.12.17.10 respectively ? (A) Eth 1 and Eth 2 (B) Eth 0 and Eth 2 (C) Eth 0 and Eth 3
SOLUTION

(D) Eth 1 and Eth 3

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
Equation (1) & (2) both are of same network. (1) 192.12.17.10. Eth 3 192.12.17.5. (2) Mask 255.255.255.255. Equation (1) & (2) both are of same network Hence (C) is correct option.

CS Topicwise 2001-2010 Computer Network

Data for Q. 11 & 12 are given below.


Solve the problems and choose the correct answers. Consider three IP networks A, B and C. Host HA in network A send messages each containing 180 bytes of application data to a host HC in network C. The TCP layer prefixes a 20 byte header to the message. This passes through an intermediate network B. The maximum packet size, including 20 byte IP header, in each network is A : 1000 bytes B : 100 bytes C : 1000 bytes The network A and B are connected through a 1 Mbps link, while B and C are connected by a 512 Kbps link (bps=bits per second).

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
SOLUTION

(D) 260

At A Data + Header = 200 bytes This would require only 1 packet of N/W A At B 200 bytes of payload from network A is packed in 80 payload + 20 header packet.
Page 7

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.
Question. 12

20+40

What is the rate at which application data is transferred to host Hc ? Ignore errors, acknowledgements, and other overheads. (A) 325.5 Kbps (C) 409.6 Kbps
SOLUTION

(B) 354.5 Kbps (D) 512.0 Kpps

200 byte at 1 Mbps 8 sec Time = 200 # 106 260 byte at 512 kbps or .5 Mbps #2 Time = 260 # 8 106 So rate of data transfer = Total data total time = 354.5 Kbps Hence (B) is correct option.
YEAR 2005 Question. 13

Packets of the same session may be routed through different paths in (A) TCP, but not UDP (C) UDP but not TCP
SOLUTION

(B) TCP and UDP (D) Neither TCP, nor UDP

Selection of any path during routing of a packet is done at Network layer not at transport layer, So TCP & UDP both have nothing to do with this.
Page 8

www.gatehelp.com
Hence (D) is correct option.
Question. 14

CS Topicwise 2001-2010 Computer Network

The address resolution protoc0l (ARP) is used for (A) Finding the IP address from the DNS (B) Finding the IP address of the default gateway (C) Finding the IP address that corresponds to a MAC address (D) Finding the MAC address that corresponds to an IP address
SOLUTION

Address resolution protocol is applied to determine MAC address corresponding to an IP address. Hence (D) is correct option.
Question. 15

The maximum window size for data transmission using the selective reject protocol with n -bit frame sequence numbers is (A) 2n (C) 2n 1
SOLUTION

(B) 2n 1 (D) 2n 2

n bit frame sequence nos are used so possible are 2n nos. n But sending & receiving window together so 2 = 2n 1 2 Hence (B) is correct option.
Question. 16

In a network of LANs connected by bridges, packets are set from one LAN to another through intermediate bridges. Since more than one path may exist between two LANs, packets may have to be routed through multiple bridges. Why is the spanning tree algorithm used for bridge-routing ? (A) For shortest path routing between LANs (B) For avoiding loops in the routing paths (C) For fault tolerance (D) For minimizing collisions
Page 9

CS Topicwise 2001-2010 Computer Network

www.gatehelp.com
SOLUTION

Spanning tree algorithm for a graph is applied to find a tree free of cycles, so in this network we apply spanning tree algorithm to remove loops in routing paths. Hence (B) is correct option.
Question. 17

An organization has a class B network and wishes to form subnets for 64 departments. The subnet mask would be (A) 255.255.0.0 (C) 255.255.128.0
SOLUTION

(B) 255.255.64.0 (D) 255.255.255.0

Class B has subnet mask = 255.255.0.0 We require 64 more subnets so 26 . 6 bits are required. 255.255.11111100.00000000 255.255. 252.0 Hence (D) is correct option.
Question. 18

In a packet switching network, packets are routed from source to destination along a single path having two intermediate node. If the message size is 24 bytes and each packet contains a header of 3 bytes, then the optimum packet size is (A) 4 (C) 7
SOLUTION

(B) 6 (D) 9

Packet switched network message Header size Case 1 If packet size Then data So require 24 packets Case 2
Page 10

= 24 byte =3 =4 = 4 3 = 1 byte only

Packet size 6

www.gatehelp.com
Data = 6 3 = 3 Require 8 pakets. Case 3 Packet size = 7 Data = 7 3 = 4 Require 24 = 4 packets. 4 Packet size = 9 Data = 9 3 = 6 Require = 24 = 4 packets. 6

CS Topicwise 2001-2010 Computer Network

Case 4

So min requirement is in case 4. Hence (D) is correct option.


Question. 19

Suppose the round trip propagation delay for a 10 Mbps Ethernet having 48-bit jamming signal is 46.4 s . The minimum frame size is : (A) 94 (B) 416 (C) 464
SOLUTION

(D) 512

Link speed = 10 Mbps Delay = 46.4 s Total bits transferred = 10 # 46.4 # 106 # 10 6 = 464 bits. But 48 bit jamming signal also required. So frame size = 464 + 48 = 512 bits Hence (D) is correct option.
YEAR 2006 Question. 20

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

IP use TTL (Time to Live) field in IP datagram header to check whether the datagram is later than its correct reach time. So if current time is greater than TTL then discard the packet. Hence (B) is correct option.
Question. 21

Station A uses 32 byte packets to transmit messages to Station B using a sliding window protocol. The round trip delay between A and B is 80 milliseconds and the bottleneck bankwidth on the path between aA and B is 128 kbps. What is the optimal window size that A should use ? (A) 20 (B) 40 (C) 160
SOLUTION

(D) 320

Path bandwidth = 128 kbps Time delay = 80 ms Total data = 80 # 128 # 103 # 10 3 bits = 80 # 128 bytes 8 = 1280 bytes. 1 packet size = 32 byte No. of packets = 1280 32 = 40 Hence (B) is correct option.
Question. 22

Two computers C1 and C2 are configured as follows. C1 has IP address 203. 197.2.53 and netmask 255.255. 128.0. C2 has IP address 203.197.75.201 and netmask 255.255.192.0. Which one of the following statements is true? (A) C1 and C2 both assume they are on the same network
Page 12

www.gatehelp.com
(B) C2 assumes C1 is on same network, but C1 assumes C2 is on a different network (C) C1 assumes C2 is on same network, but C2 assumes C1 is on a different network (D) C1 and C2 both assume they are on different networks
SOLUTION

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 Both are at different networks but. C1 203.197. 2.53 255.255.192.0 N/W 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

Interchanging of mask by C1 gives the same N/W ID as C 1 originally has for C 2 so C 1 assumes that C 2 is one same network, but C 2' s subnet doesnt given same N/W ID so. C2 assumes C 1 is not in same network. Hence (C) is correct option.
Question. 23

Station A needs to send a message consisting of 9 packets to Station B using a siding window (window size 3) and go-back-n error control strategy. All packets are ready and immediately available for transmission. If every 5th packet that A transmits gets lost (but no acks from B ever get lost), then what is the number of packets that A will transmit for sending the message to B ? (A) 12 (B) 14 (C) 16
SOLUTION

(D) 18

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.
Question. 24

2 3 4 5 6 7 8 9 10 11 12

ACK ACK ACK Lost Discard ACK ACK ACK ACK Lost

For the given connection of LANs by bridges, which one of the following choices represents the depth first traversal of the a panning tree of bridges? (A) B1,B5,B3,B4,B2 (C) B1,B5,B2,B3,B4
SOLUTION

(B) B1,B3,B5,B2,B4 (D) B1.B3.B4.B5.B2

Graph of bridge

Spinning tree

Hence (C) is correct option.


Page 14

www.gatehelp.com
Question. 25

CS Topicwise 2001-2010 Computer Network

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) Hosts H1,H2,H3,H4 H5,H6,H9,H10 H7,H8,H11,H12 Ports 3 1 2 (B) Hosts H1, H2 H3, H4 H5, H6 H11, H12 (C) Hosts H1, H2, H3, H4 H5, H6, H9, H10 H7,H8, H11, H12 Port 3 1 2 (D) Hosts H1, H2, H3, H4 H5, H7, H9, H10 H7, H8, H11, H12 Port 3 1 4 Port 4 3 1

H7, H8, H9, H10 2

SOLUTION

From the given graphs spanning tree port 1, 2, 3 of bridge 3 are used to access. Port 1 2 3 H5 H7 H1 H6 H8 H2 H9 H11 H3 H10 H12 H4

Hence (A) is correct option.

YEAR 2007

Question. 26

In Ehernet when manchester encoding is used, the bit rate is (A) Half the baud rate (C) Same as the baud rate (B) Twice the baud rate (D) None of these
Page 15

CS Topicwise 2001-2010 Computer Network

www.gatehelp.com
SOLUTION

In Manchester encoding each bit is described by 2 voltage levels. So bit rate becomes twice the band rate. Hence (B) is correct option.
Question. 27

Which one of the following uses UDP as the transport protocol? (A) HTTP (B) Telnet (C) DNS
SOLUTION

(D) SMTP

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

There are n stations in a slotted LAN. Each station attempts to transmit with a probability p in each time slot. What is the probability that ONLY one station transmits in a given time slot? (A) np (1 p) n 1 (B) (1 p) n 1 (C) p (1 p) n 1
SOLUTION

(D) 1 (1 p) n 1

Using binomial theorem. Prob. that only 1 station = nc (p) 1 (1 p) n 1 transmits. n! p (1 p) n 1 = (n 1) !


1

= np (1 p) n 1 Hence (A) is correct option.


Question. 29

In a token ring network the transmission speed is 10 bps and the propagation speed is 200 metres/ s . The 1-bit delay in this network is equivalent to; (A) 500 metres of cable (B) 200 metres of cable (C) 20 metres of cable
Page 16

(D) 50 metres of cable

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Network

Transmission speed = 107 bps Propagation speed = 200 m/s or 2 # 108 m/s 107 bps = 2 # 108 mps 8 m 1 bit = 2 # 10 7 10 = 20 m of cable Hence (C) is correct option.
Question. 30

The address of a class B host is to be split into subnets with a 6-bit subnet number. What is the maximum number of subnets and the maximum number of hosts in each subnet? (A) 62 subnets and 262142 hosts (B) 64 subnets and 262142 hosts (C) 62 subnets and 1022 hosts (D) 64 subnets and 1024 hosts
SOLUTION

Class B subnet mask. 255.255.0.0 6 bits are used for subnetting 255.255.11111100.00000000 255.255.252.0 Using 6 bits 26 = 64 combination Can be made but000 000 & 111 111 are used for default & broadcasting. So 62 subnets possible. Similarly for addressing host we have 10 bits 210 = 1024 addresses. But all Os & all 1s are not used so 1022 addresses for hosts. Hence (C) is correct option.
Question. 31

The message 11001001 is to be transmitted using the CRC polynomial x3 + 1 to protect it from errors. The message that should be transmitted is: (A) 11001001000 (B) 11001001011
Page 17

CS Topicwise 2001-2010 Computer Network

www.gatehelp.com
(C) 11001010
SOLUTION

(D) 110010010011

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 x6 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

! x4 x6 x 4 + x3 + 1 ! x3

The distance between two stations M and N is L kilo metres. All frames are K bits long. The propagation delay per kilo metre is t seconds Let R bits/second be the channel capacity. Assuming that processing delay is negligible, the minimum number of bits for the sequence number field in a frame for maximum utilization, when the sliding window protocol is used, is; (A) :log2 2LtR + 2K D (B) :log2 2LtR D K K (C) :log2 2LtR + K D K
SOLUTION

(D) :log2 2LtR + K D 2K

Dist between Propagation delay Total delay Frame size Capacity of channel RTT
Page 18

source & lest L Km = sec/km = Lt = K bits = R bit/sec = 2L sec

www.gatehelp.com
To get no. of bits we require no. of frames, required Total data = 2Lt # R & rate # time = 2LtR bits No. of frames = 2LtR K Let n bits required for sequence no. 2n = 2LtR K n = log 2 :2LtR D K Hence (B) is correct option.
Question. 33

CS Topicwise 2001-2010 Computer Network

Match the following: P. SMTP Q. BGP R. TCP S. PPP

1. Application layer 2. Transport layer 3. Data link layer 4. Network layer 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

SMTP (Simple mail transfer Protocol) is application layer based. BGP is network layer based. TCP (Transport Control Protocol) is transport layer based. PPP (Point to Point protocol) is data link layer based protocol. Hence (B) is correct option.
YEAR 2008 Question. 34

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 (C) 216 bytes
SOLUTION

(B) 216 bytes-size of TCP header (D) 1500 bytes

Application layer pass data to TCP layer. The length is of 16 bits. So total length 216 bytes. But this is not complete payload, it has header also. So actual data. 216 bytes Size of TCP header Hence (B) is correct option.
Question. 35

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

If a class B network on the Internet has a subnet mask of 255.255.248.0, what is the maximum number of hosts per subnet? (A) 1022 (B) 1023 (C) 2046
SOLUTION

(D) 2047

Class B subnet mask 255.255.0.0 Given subnet mask including subnetting 255.255.248.0
Page 20

www.gatehelp.com
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

CS Topicwise 2001-2010 Computer Network

A computer on a 10Mbps network is regulated by atoken bucket. The token bucket is filled at a rate of 2Mbps. It is initially filled to capacity with 16Megabits. What is the maximum duration for which the computer can transmit at the full 10Mbps? (A) 1.6 seconds (C) 5 seconds
SOLUTION

(B) 2 seconds (D) 8 seconds

Initially filled = 16 Mb Bucket fill rate = 2 Mbps Time (sec) 0 1 1.8 2 At t = 0 16 Mb are there.

Bucket (Mbps) 16 16 10 + 2 = 8 8 8 + 1.6 1.6 2 + .4 = 0

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

A client process P needs to make a TCP connection to a server Process S . Consider the following situation; the server process S executes a socket (), a bind() and a listen () system call in that order, following which it is preempted. Subsequently, the client Process P
Page 21

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

Since accept ( ) call is not executed then connect ( ) gets no response for a time stamp to wait & then return no response server error. Hence (C) is correct option.
YEAR 2009 Question. 39

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.
Page 22

M' = Me mod n M = (M') d mod n

www.gatehelp.com
II ed / 1 mod n

CS Topicwise 2001-2010 Computer Network

III ed / 1 mod (n) IV M' = Me mod (n) M = (M') d mod (n) Which of the above equations correctly represent RSA cryptosystem ? (A) I and II (C) II and IV
SOLUTION

(B) I and III (D) III and IV

RSA is an algorithm for public key cryptography Involves a public & one private key. We choose 2 different prime nos P & Q. Compute n = pq Calculate (pq) = (p 1) (q 1) (Eulers tolient function) Select e and exponent where 1 < e < (pq) Select d where ed 1 is divisible by (pq) So condition are M' = Me mod n eneryption M = (M') mod n decryption & ed = 1 mod (n) I & III Hence (B) is correct option.
Question. 40

While opening a TCP connection, the initial sequence number is to be derived using a time-of-day (ToD) clock that keeps running even when the host is down. he low order 32 bits of the counter of TOD clock is to be used for the initial sequence numbers. The clock counter increments once per millisecond. The maximum packet lifetime is given to be 64s. Which one of the choices given below is closet to the minimum permissible rate at which sequence numbers used for packets of a connection can increase ? (A) 0.015/s (C) 0.135/s (B) 0.064/s (D) 0.327/s
Page 23

CS Topicwise 2001-2010 Computer Network

www.gatehelp.com
SOLUTION

Packet life time = 64 sec Increment time = 1 ms So rate of generation of packets = 64 ms 1 = .064 /sec Hence (B) is correct option.
Question. 41

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

In this case polynomial generator should satisfy (A) Polynomial generated shouldnt be divisible by x (B) It should be divisible by 1 + x i.e (1 + x) is a factor of polynomial Hence (C) is correct option.

Statement for Linked Answer Question 42 & 43


Frames of 1000 bits are sent over a 106 bps duplex link between two hosts. The propagation time is 25 ms. Frames are to be transmitted into to maximally pack them in transit (within the link).
Question. 42

What is the minimum number of bits (l) that will be required to represent the sequence numbers distinctly ? Assume that no time gap needs to be given between transmission of two frames. (A) l = 2 (C) l = 4
Page 24

(B) l = 3 (D) l = 5

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Network

Link capacity = 106 bps Propagation time = 25 cms Total data = 106 # 25 # 10 3 = 25 kb Frame size = 1000 bits No. of frames = 25 # 1000 1000 = 25 25 = 32 2 4 = 16 So sequence nos required for 25 frames should have l = 5 bits. Hence (D) is correct option.
Question. 43

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 (C) 20 ms
SOLUTION

(B) 18 ms (D) 22 ms

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

One of the header fields in an IP datagram is the Time-to-Live (TTL) field. Which of the following statements best explains the need for this field ? (A) It can be used to prioritize packets (B) It can be used to reduce delays (C) It can be used to optimize throughput (D) It can be used to prevent packet looping
SOLUTION

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

Which one of the following is not a client-server application ? (A) Internet chat (B) Web browsing (C) E-mail
SOLUTION

(D) Ping

Internet- Chat is maintained by chat servers, web browsing is sustained by web servers, E-mails are stored at mail servers, but ping is an utility which is used to identify connection between any two computer. One can be client, other can be client or server anything but aim is to identify whether connection exists or not between the two. Hence (D) is correct option.
Question. 46

Suppose computers A and B have IP addresses 10.105.1.113 and 10.105.1.91 respectively and they both use the same netmask N. Which of the values of N given below should not be used if A and B should belong to the same network ? (A) 225.255.255.0 (B) 255.255.255.128
Page 26

www.gatehelp.com
(C) 255.255.255.192 (D) 255.255.255.224

CS Topicwise 2001-2010 Computer Network

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

So addresses belong to same N/W. 255.255.128 01110001 10000000 10.105.1.0 255.255.255.128 01011011 10000000 10.105. 1. 0

(B) N/W Addr

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

N/W ids differ so different network Hence (D) is correct option.

Statement for Linked Answer Questions 47 & 48


Consider a network with 6 routers R1 and R6 connected with links having weights as shown in the following diagram.
Page 27

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 (C) 2
SOLUTION

(B) 3 (D) 1

Tables for routing information R1 R2 3 + 2 = 5 R3 3 R 4 3 + 2 + 7 = 12 R5 3 + 9 = 12 R6 3 + 9 + 4 = 16 R4 R2 7 R3 7 + 2 = 9 R5 1 R3 2 R4 7 R5 7 + 1 = 8 R5 R2 1 + 7 = 8 R3 9 R4 1 R2 R1 2 + 3 = 5 R3 R1 4 + 9 + 3 = 16 R2 4 + 1 + 7 = 12 R 3 4 + 9 = 13 R4 4 + 1 = 5 R6 R2 4 + 1 + 7 = 12 R 3 4 + 9 = 13 R4 4 + 1 = 5 R5 4

R6 7 + 1 + 4 = 12 R5 4

R1 7 + 2 + 3 = 12 R1 9 + 3 = 12 R1 4 + 9 + 3 = 16

R6 4 R6 1 + 4 = 5 Edge R1 " R2 = 6 & R 4 " R6 = 8 Are never used


Page 28

www.gatehelp.com
Hence (C) is correct option.
Question. 48

CS Topicwise 2001-2010 Computer Network

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
SOLUTION

(D) 3

Now the network becomes

Using same method. R1 R2 2 R3 3 R4 2 + 7 = 9 R5 3 + 9 = 12 R6 2 + 7 + 2 = 11

R2 R1 2 R3 2 R4 7 R5 7 + 1 = 8 R6 7 + 2 = 9 R1 R2 R4 R5 R6

R3 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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Computer Organization and Architecture

YEAR 2001 Question. 1

More than one word are put in one cache block to (A) Exploit the temporal locality of reference in a program (B) Exploit the spatial locality of reference in a program (C) Reduce the miss penalty (D) None of the above
SOLUTION

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

A low memory can be connected to 8085 by using (A) INTER (C) HOLD
SOLUTION

(B) RESET IN (D) READY

A low memory can be connected to 8085 by using READY signal. If READY is set then communication is possible.

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

A processor needs software interrupt to (A) Test the interrupt system of the processor. (B) Implement co-routines. (C) Obtain system services which need execution of privileged instructions. (D) Return from subroutine.
SOLUTION

A CPU needs software interrupt to obtain system services which need execution of privileged instructions. Hence (C) is correct opton.
Question. 5

A CPU has two modes-privileged and non-privileged. In order to change the mode from privileged to non-privileged. (A) A hardware interrupt is needed.
Page 2

www.gatehelp.com
(B) A software interrupt is needed. (C) A privileged instruction (which does not generate an interrupt) is needed. (D) A non-privileged instruction (Which does not generate an interrupt) is needed.
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

A software interrupt is initiated by some program module which need some CPU services, at that time the two modes can be interchanged. Hence (B) is correct option.
Question. 6

The process of assigning load addresses to the various parts of the program and adjusting the code and date in the program to reflect the assigned addresses is called (A) Assembly (C) Relocation
SOLUTION

(B) Parsing (D) Symbol resolution

Load addresses are assigned to various parts of the program, the program can be loaded at any location in memory. This location is added to all addresses in the code, to get correct references. This makes a code re-locatable. Hence (C) is correct option.
Question. 7

Which of the following requires a device driver ? (A) Register (C) Main memory
SOLUTION

(B) Cache (D) Disk

Device driver is the program which co-ordinates with CPU to regulate the devices. Register, cache & main memory are directly connected to CPU. So only Disk from given options require device drivers. Hence (D) is correct option.
Page 3

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 (Y.) Indexed Addressing (Z.) Base Register Addressing (A) (X, III) (Y, I) (Z, II) (C) (X, III) (Y, II) (Z, I)
SOLUTION

(I.) Array implementation (II.) Writing re-locatable code (III.) Passing array as parameter (B) (X, II) (Y, III) (Z, I) (D) (X, I) (Y, III) (Z, II)

Indexed addressing is used for array implementation where each element has indexes. Base register is used to re-locatable code, where starts from base address & then all local addresses as added to base address. Indirect addressing is done when array is passed as parameter only name is passed. Hence (A) is correct option.
Question. 9

Consider the following data path of a simple non-pilelined CPU. The registers A, B, A1 , A2 , MDR the bus and the ALU are 8-bit wide. SP and MAR are 16-bit registers. The MUX is of size 8 # (2: 1) and the DEMUX is of size 8 # (1: 2). Each memory operation takes 2 CPU clock cycles and uses MAR (Memory Address Register) and MDR (Memory Date Register). SP can be decremented locally.

The CPU instruction push r, where = A or B, has the specification M [SP] !r


Page 4

www.gatehelp.com
SP ! SP 1 How many CPU clock cycles are needed to execute the push r instruction ? (A) 2 (C) 4
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(B) 3 (D) 5

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

Which of the following does not interrupt a running process ? (A) A device (C) Scheduler process
SOLUTION

(B) Timer (D) Power failure

A device can request interrupt service. A timer when finishes or power failure causes a running process to stop. But a scheduler process doesnt do this. Hence (C) is correct option.
YEAR 2002 Question. 11

A device employing INTR line for device interrupt puts the CALL instruction on the data bus while (A) INTA is active (C) READY is active (B) HOLD is active (D) None of the above
Page 5

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
SOLUTION

INTR is a signal which if enabled then microprocessor has interrupt enabled it receives high INR signal & activates INTA signal, so another request cant be accepted till CPU is busy in servicing interrupt. Hence (A) is correct option.
Question. 12

In 8085 which of the following modifies the program counter ? (A) Only PCHL instruction (B) Only ADD instructions (C) Only JMP and CALL instructions (D) All instructions
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

In serial data transmission, every byte of data is padded with a 0 in the beginning and one or two 1s at the end of byte because (A) Receiver is to be synchronized for byte reception (B) Receiver recovers lost 0s and 1 from these padded bits (C) Padded bits are useful in parity computation. (D) None of the above
SOLUTION

In serial data transmission the sender & receiver needs to be synchronized with each other. Receiver should know when 1 byte of data has been sent. 0 & 1s which are padded tell the receiver to synchronize. Hence (A) is correct option.
Page 6

www.gatehelp.com
Question. 14

CS Topicwise 2001-2010 Computer Organization & Architecture

Which of the following is not a form of memory ? (A) Instruction cache (C) Instruction opcode
SOLUTION

(B) Instruction register (D) Translation-a-side buffer

Instruction register stores instruction, look-a-side buffer & instruction cache are also memory. But instruction opcodes are the opcodes related to an instruction which are not part of memory hierarchy. Hence (C) is correct option.
Question. 15

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

Activation record is the contiguous memory locations where the data needed by the program is kept so at most one activation record exist between current activation record & the record for the main. Hence (A) is correct option.
Question. 16

In the absolute the addressing mode (A) The operand is inside the instruction (B) The address of the operand is inside the instruction (C) The register containing the address of the operand is specified
Page 7

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
inside the instruction (D) The location of the operand is implicit
SOLUTION

In absolute addressing mode, no need of giving operand, the operand are implicit, instruction itself has knowledge of operands. Hence (D) is correct option.
Question. 17

The performance of a pipelined processor suffers if (A) The pipelined stages have different delays (B) Consecutive instructions are dependent on each other (C) The pipeline stages share hardware resources (D) All the above
SOLUTION

Pipelining is a method to execute a program breaking it in several independent sequence of stages. In that case pipeline stages cant have different delays, no dependency among consecutive instructions & sharing of hardware resources shouldnt be there. So option (D) is true Hence (D) is correct option.
Question. 18

Horizontal microprogramming (A) Does not require use of signal decoders (B) Results in larger microprogramming (D) All of the above
SOLUTION

sized

microinstructions

than

vertical

(C) Uses one bit for each control signal

In horizontal microprogramming the instruction size is not large, & no decoding is required. But 1 bit is used for all control signals. Hence (C) is correct option.
Page 8

www.gatehelp.com
YEAR 2003 Question. 19

CS Topicwise 2001-2010 Computer Organization & Architecture

For a pipelined CPU with a single ALU, consider the following situations 1. The j + 1 st instruction uses the result of j th instruction as an operand 2. The execution of a conditional jump instruction 3. The j th and j + 1 st instructions require the ALU at the same time Which of the above can cause a hazard? (A) 1 and 2 only (B) 2 and 3 only (C) 3 only
SOLUTION

(D) All the three

Case 1

is here of data dependency, this cant be safe with single ALU so read after write. Case 2 Conditional jumps are always hazardous they create conditional dependency in pipeline Case 3 This is write after read problem or concurrency dependency so hazardous All the three are hazardous. Hence (D) is correct option.
Question. 20

Consider an array multiplier for multiplying two n bit numbers. If each gate in the circuit has a unit delay, the total delay of the multiplier is (A) (1) (B) (log n) (C) (n)
SOLUTION

(D) (n2)

The no. of gates used in n bit array multiplier (n # n) is 2n 1. So. if every single gate takes unit delay, then total delay 0 (2n 1) = 0 (n) It is of linear order Hence (C) is correct option.
Page 9

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
Question. 21

Consider the ALU shown below

If the operands are in 2s complement representation, which of the following operations can be performed by suitably setting the control lines K and C0 only (+ and - denote addition and subtraction respectively)? (A) A + B, and A B, but not A + 1 (B) A + B, and A + 1, but not A B (C) A + B, but not A B, or A + 1 (D) A + B, and A B, and A + 1
SOLUTION

This is the ckt to add two numbers in 2s complement form. K & C 0 are set to 1. So A + B & A B using bit adders can be done. Also since C 0 = 1 & in case B 0, B1 ........ all are 0 then it gives A + 1. Hence (D) is correct option.

Data for Q. 22 & 23 are given below.


Consider the following assembly language program for a hypothetical processor. A,B and C are 8 bit registers. The meanings of various instructions are shown as comments. 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 ag is set C ! C1

Z:

Page 10

www.gatehelp.com
RRC A, # 1 ; right rotate A through carry ; by one bit. Thus: if the ; initial values of A and the ; carry ag are a7 .......a0 and c0 ; respectively, their values ; after the execution of this ; instruction will be c0 a7 .....a1 ; and a0 respectively. ;jump to Y if carry ag is set ; jump to Z ; B ! B+1 ; jump to Z

CS Topicwise 2001-2010 Computer Organization & Architecture

Y: X:

JCY JMP Z ADD B, # 1 JMP Z

Question. 22

If the initial value of register A is A0 , the value of register B after the program execution will be (A) the number of 0 bits in A0 (B) the number of 1 bits in A0 (C) A0 (D) 8
SOLUTION

Here value of B incremented by 1 only if carry flag is 1, carry is filled using right rotation, so B will store the no. of is in A 0 . Hence (B) is correct option.
Question. 23

Which of the following instructions when inserted at location X will ensure that the value of register A after program execution is the same as its initial value? (A) RRC A,# 1 (B) NOP (C) LRC A, # 1 (D) ADD A, # 1
Page 11

; ;

no operation left rotate A through carry flag by one bit

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
SOLUTION

In the end of program execution to check whether both initial and final value of register A is A 0 , we need to right rotate register A through carry by one bit. Hence (A) is correct option.
YEAR 2004

Question. 24

Which of the following addressing modes are suitable for program relocation at run time? 1. Absolute addressing 2. Based addressing 3. Relative addressing 4. Indirect addressing (A) 1 and 4 (C) 2 and 3
SOLUTION

(B) 1 and 2 (D) 1,2 and 4

Program relocation at run time transfers complete block to some memory locations. This require as base address and block should be relatively addressed through this base address. This require both based addressing and relative addressing mode. Hence (C) is correct option.
Question. 25

Consider a multiplexer with X and Y as data inputs and Z as control input.Z = 0 selects input X , and Z =1 selects input Y . What are the connection required to realize the 2-variable Boolean function f = T + R , without using any additional hardware? (A) R to X, 1 to Y, T to Z (C) T to X, R to Y, 0 to Z (B) T to X, R to Y, T to Z (D) R to X, 0 to Y, T to Z

Page 12

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

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 0 1 1 1 0 1 0 1

So X = R Y = 1 Z = T f f = T'R + T = (T + T') (T + R) = T+R

Hence (A) is correct option.

Data for Q. 26 & 27 are given below.


Consider the following program segment for a hypothetical CPU having three user registers R1,R2 and R3.
Page 13

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
Instruction MOV R1,5000 MOV R2,R3 ADD R2,R3 MOV 6000,R2 HALT Operation ;R1 ! Memory[5000] ;R2 ! R2+R3 ;R2 ! R2+R3 ;Memory[6000] ! R2 ;Machine halts Instruction Size (in words) 2 1 1 2 1

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 (C) 1024
SOLUTION

(B) 1020 (D) 1028

Byte addressable so 1 word require 4 bytes. Instruction no. Size 1 2 3 4 5 Next location 1028. CPU has executed the HALT instruction so next time the CPU will resume at next location i.e. 1028 which would be at the top of stack. Hence (D) is correct option.
Question. 27

Address range 1000-1007 1008-1011 1012-1015 1016-1023 1024-1027

2 1 1 2 1

Let the clock cycles required for various operations be as follows: Register to/from memory transfer:
Page 14

3 clock cycles

www.gatehelp.com
ADD with both operands in register: Instruction fetch and decode: 1 clock cycle 2 clock cycles per word

CS Topicwise 2001-2010 Computer Organization & Architecture

The total number of clock cycles required to execute the program is (A) 29 (C) 23
SOLUTION

(B) 24 (D) 20

The clock cycles are per block so if an instruction size is 2 then it requires twice no. of clock cycles. Instruction No. Size 1 2 3 4 5 2 1 1 2 1 Total Hence (B) is correct option.
Question. 28

No. of clock cycles 3#2+2 1#3+2 1 (add only) 3#2+2 8 5 1 8 24

2 (fetch & decode) 2

Consider a small two-way set-associative cache memory, consisting of four blocks. For choosing the block to be replaced, use the least recently used (LRU) scheme. The number of cache misses for the following sequence of block addresses is 8, 12,0, 12,8 (A) 2 (C) 4
SOLUTION

(B) 3 (D) 5

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

The microinstructions stored in the control memory of a processor have a width of 26 bits. Each microinstruction is divided into three fields: a micro-operation field of 13 bits, a next address field (X), and a MUX select field (Y). There are 8 status bits in the inputs of the MUX.

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 (C) 5, 8, 2048
SOLUTION

(B) 8, 5, 256 (D) 10, 3, 512

MUX has 8 states bits as input lines so we require 3 select inputs to select & input lines. No. of bits in control memory next address field = 26 13 3 = 10 10 bit addressing, we have 210 memory size. So X, Y size = 10, 3, 1024 Hence (A) is correct option.
Question. 30

A hard disk with a transfer rate of 10 M bytes/second is constantly


Page 16

www.gatehelp.com
transferring data to memory using DMA. The processor runs at 600 MHz. and takes 300 and 900 clock cycles to initiate and complete DMA transfer respectively. If the size of the transfer is 20 Kbytes, what is the percentage of processor time consumed for the transfer operation? (A) 5.0% (B) 1.0% (C) 0.5%
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(D) 0.1%

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

(D) 590.0 microseconds

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

CPU has single interrupt request and grant line

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
Question. 33

CS Topicwise 2001-2010 Computer Organization & Architecture

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

In memory mapped I/0 the complete system (memory + I/0 ports) hold the same set of addresses. They are considered to be the part of that memory only. This management is done by OS only. Hence (A) is correct option.
Question. 34

What is the swap apace in the disk used for? (A) Saving temporary html pages (B) Saving process data (C) Storing the super-block (D) Storing device drivers
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

Increasing the RAM of a computer typically improves performance because (A) Virtual memory increases (B) Larger RAMs are faster
Page 19

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

Consider a three word machine instruction ADD A [R0],@ B The first operand (destination) A [R0] uses indexed addressing mode with R0 as the index register. The second operand (source) "@B" uses indirect addressing mode. A and B are memory addresses residing at the second and the third words, respectively. The first word of the instruction specifies the opcode, the index register designation and the source and destination addressing modes. During execution of ADD instruction, the two operands are added and stored in the destination (first operand). The number of memory cycles needed during the execution cycle of the instruction is (A) 3 (C) 5
SOLUTION

(B) 4 (D) 6

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
Question. 37

CS Topicwise 2001-2010 Computer Organization & Architecture

Match List-I with List-II and select the correct answer using the codes given below the lists: List-I A. A [1] = B [j]; B. while [* A ++]; C. int temp=*x ; Codes: A (A) (B) (C) (D) 3 1 2 1 B 2 3 3 2 C 1 2 1 3 List-II 1. Indirect addressing 2. Indexed addressing 3. Auto increment

SOLUTION

LIST-I A. A [1] = B [J]; B. While [) A ++] C. int temp = ) X

2 3.

LIST-II Indexed addressing here the indexing is used Auto increment the memory locations is A are automatically incriminated. Indirect addressing here temp is assigned the value of int type stored at the address contained in X

1.

A2 B3 C1 Hence (C) is correct option.


Question. 38

Consider a direct mapped cache of size 32 KB with block size 32 bytes. The CPU generates 32 bit addresses. The number of bits needed for cache indexing and the number of tag bits are respectively (A) 10,17 (B) 10,22
Page 21

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
(C) 15,17
SOLUTION

(D) 5,17

Cache is direct mapped. Size of Cache = 32 KB = 25 # 210 B = 215 Bytes. Require 15 bits for cache addressing so CPU address has tag and index No. of tag bits = 32 15 = 17 From 15 Cache addressing bits consist of blocks & words. Each block has 32 words (bytes) So require 5 bit. Index = block + word Block = 15 5 = 10 So, 10, 17 Hence (A) is correct option.
Question. 39

A 5 stage pipelined CPU has the following sequence of stages IF-Instruction fetch from instruction memory. RD-Instruction decode and register read, EX- Execute:ALU operation for data and address computation, MA-Data memory access-for write access the register read at RD stage it used, WB-register write back. Consider the following sequence of instruction: I1 : LR0, Locl; R0 <= M [Locl] I2 AR0, R0; R0 <= R0 + R0 I 3 AR2, R0; R2 <= R2 R0 Let each stage take one clock cycle. What is the number of clock cycles taken to complete the above sequence of instruction starting from the fetch of I1 ?
Page 22

www.gatehelp.com
(A) 8 (C) 12
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(B) 10 (D) 15

Order of phase in instruction cycle. IF " A 3 " E # MA " WB 1 R0 ! R0 + R0 R2 ! R2 R0 2 3 IF 4 5 6 7 8 9 10 R 0 ! M [LOC] IF RD EX MA WB RD EX MA WB IF RD EX MA WB

R 0 ! R 0 + R 0 cant start before 3 since R 0 has not been read by I1 . R2 ! R2 R 0 cant start before 6th since I2 has not executed R 0 ! R 0 + R 0 till 5th cycle Total cycles = 10 Hence (B) is correct option.
Question. 40

A device with data transfer rate 10 KB/sec is connected to a CPU. Data is transferred byte-wise. Let the interrupt overhead be 4 sec . The byte transfer time between the device interface register and CPU or memory is negligible. What is the minimum performance gain of operating the device under interrupt mode over operating it under program controlled mode? (A) 15 (B) 25 (C) 35
SOLUTION

(D) 45

Data transfer rate = 10000 B/sec Total data = 25 # 103 Rate = 10 4 Performance gain = 254 # 100 10 = 25%
Page 23

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
Hence (B) is correct option.
Question. 41

Consider a disk drive with the following specification 16 surfaces, 512 tracks/surface, 512 sectors/track, 1 KB/sector, rotation speed 3000 rpm. The disk is operated in cycle stealing mode whereby whenever one byte word is ready it is sent to memory; similarly, for writing, the disk interface reads a 4 byte word from the memory in each DMA cycle. Memory cycle time is 40 n sec . The maximum percentage of time that the CPU gets blocked during DMA operation is (A) 10 (C) 40 (B) 25 (D) 50

SOLUTION

Disk revolutions = 3000 PM or 50 RPS At a time can read in One revolution = 512 KB
19 Tracks read/sec = 2 2 ) 50 2

= 50 # 217 per sec. Interrupt = .2621 sec Percentage gain = .2621 # 100 1 , 26% Hence (B) is correct option.

Data for Q. 42 & 43 are given below


Consider the following data path of a CPU
Page 24

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

The instruction add R0, R1 has the register transfer in terpretation R0 <= R0 + R1. The minimum number of clock cycles needed for execution cycle of this instruction is (A) 2 (B) 3 (C) 4
SOLUTION

(D) 5

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

The instruction call Rn , sub is a two word instruction. Assuming that PC is incremented during the fetch cycle of the first word of the instruction, its register transfer interpretation is Rn <= PC = 1; PC <= M [PC];
Page 25

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
SOLUTION

(D) 5

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

A CPU has 24-bit instructions. A program starts at address 300(in decimal). Which one of the following is a legal program counter (all values in decimal)? (A) 400 (B) 500 (C) 600
SOLUTION

(D) 700

Size of instruction = 24 bits. Since each instruction require 24 = 3 bytes & start address is 300 so 3 the address for this range can be multiple of 3 only so 600. Hence (C) is correct option.
YEAR 2006 Question. 45

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
the bank numbers to be accessed in parallel and this takes k/2 ns . The latency of one bank access is 80 ns . If c = 2 and k =24, then latency of retrieving a cache block starting at address zero from main memory is (B) 104 ns (A) 92 ns (C) 172 ns
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(D) 184 ns

Size of Cache block = 64 B No. of main memory banks K = 24 Size of each bank C = 2 bytes. So time taken for < access. T = decoding time + latency time T = K/2 + latency = 12 + 80 = 92 ns. But since C = 2 for accesses. 2 # 92 = 189 ns. Hence (D) is correct option
Question. 46

A CPU has five-stages pipeline and runs at 1GHz frequency. Instruction fetch happens in the first stage of the pipeline. A conditional branch instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new instructions following a conditional branch until the branch outcome is known. A program executes 109 instructions out of which 20% are conditional branches. If each instruction takes one cycle to complete on average, then total execution time of the program is (A) 1.0 second (B) 1.2 seconds (C) 1.4 seconds
SOLUTION

(D) 11.6 seconds

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

Hence (B) is correct option.


Question. 47

Consider a new instruction named branch-on-bit-set (mnemonic bbs). The instruction bbs reg, pos, labbel jumps to label if bit in position pos of register operand reg is one. a register is 32 bits wide and the bits are numbered 0 to 31, bit in position 0 being the least significant. Consider the following emulation of this instruction on a processor that does not have bbs implemented. temp ! reg and mask Branch to label if temp is non-zero The variable temp is a temporary register. For correct emulation the variable mask must be generated by (B) musk ! 0x ffffffff >> pos (A) mask ! 0x1 << pos (C) mask ! pos
SOLUTION

(D) msdk ! 0xf

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
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

CS Topicwise 2001-2010 Computer Organization & Architecture

The value of h1 is (A) 2.4ns (C) 1.8ns


SOLUTION

(B) 2.3ns (D) 1.7ns

2 way set-associative Cache. Size 32 KB 2 way so 16 KB sets. Require 14 bits for 214 B Block size = 32 Byte. = 5 bits. No. of blocks14 5 = 9 Tag index

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
SOLUTION

(D) 1.7ns

Similarly to previous question. The CPU address is same but Direct coaching require for 32 KB 15 bits. Which would be 10 + 5 = 17 17 10 5 h2 = 17 + 0.6 10 = 2.3 ns Hence (B) is correct option.

Data for Q. 50 & Q. 51 are given below.


A CPU has a 32 KB direct mapped cache with 128-byte block size. Suppose A is a two dimensional array of size 512 # 512 with elements that occupy 8-bytes each. Consider the following two C code segments, P1 and P2 , P1 : for (i=0;i<512;i++) { for (j=0;j<512;j++) { x+=A[i][j]; } } P2 : for (i=0;i<512;i++) { for (j=0;j<512;j++) { {x+=A[j][i];} } } P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache and i, j, x are in registers. Let the number of cache misses experienced by P1 be M1 and that for P2 be M2 .
Question. 50

The value of M1 is
Page 30

www.gatehelp.com
(A) 0 (C) 16384
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(B) 2048 (D) 262144

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

The value of the ratio M1 /M2 is (A) 0 (C) 1/8


SOLUTION

(B) 1/16 (D) 16

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

Hence (B) is correct option.


YEAR 2007

Question. 52

Consider a 4-way set associative cache consisting of 120 lines with a line size of 64 words. The CPU generates a 20-bit address of a word in main memory. The number of bits in the TAG, LINE and WORD fields are respectively (A) 9,6,5 (C) 7,5,8
SOLUTION

(B) 7,7,6 (D) 9,5,6

4 way set associative cache Size = 128 # 64 words 128 # 64 = 32 # 64 But for 4 sets 4 For 32 lines we require 5 bits. For 64 words we require 6 bits. Indexing = 6 + 5 = 11 bits. Tag = 20 11 = 9 bits 9 Hence (D ) is correct option.
Question. 53

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 (A) 256 Mbytes, 19 bits (C) 512 Mbytes, 20 bits
Page 32

(B) 256 Mbyte, 28 bits (D) 64 Gbyte, 28 bits

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

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

Consider a pipelined processor with the following four stages IF: ID: EX: WB: 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 MUL SUB R2, R4, R6, R1, R3, R5, R0 R2 R4 R2 ! R1+R0 R4 ! R3*R2 R6 ! R5R4

(A) 7 (C) 10
SOLUTION

(B) 8 (D) 14

Order of instruction cycle-phases. IF " ID " EX " WB We have 3 instructions. 1 2 3 4 5 6 7 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 R6 ! R5 ! R 4 IF ID IF EX EX EX WB ID EX WB

Represent wait in pipeline due to result dependently. Clock cycles require = 8 Hence (B) is correct option.

Data for Q. 55, 56 & 57 are given below.


Consider the following program segment. Here R1, R2 and R3 are the general purpose registers. Instruction MOV R1,(3000) LOOP: MOV R2,R1 ADD R2,R1 MOV (R3),R2 INC R3 DEC R1 BNZ LOOP HALT Operation R1 ! M[3000] R2 ! M[R3] R2 ! R1+R2 M(R3] ! R2 R3 ! R3+1 R1 ! R1-1 Branch on not zero Stop Instruction size (no. of words) 2 1 1 1 1 1 2

Assume that the content of memory location 3000 is 10 and the content of the register R3 is 2000. The content of each of the memory locations from 2000 to 2010 is 100. The program is loaded from the memory location 100. All the numbers are in decided.
Question. 55

Assume that the memory is word addressable. The number of memory references for accessing the data in executing the program completely is (A) 10 (C) 20
Page 34

(B) 11 (D) 21

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

1st memory reference R1 ! M ^3000h and then in the loop which runs for 10 times there are 2 memory reference every iteration. 10 # 2 = 20 Total 20 + 1 = 21 R2 ! M [R 3] M [R 3] ! R2 Hence (D) is correct option
Question. 56

Assume that the memory is word addressable. After the execution of this program, the content of memory location 2010 is (A) 100 (C) 102
SOLUTION

(B) 101 (D) 110

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 (C) 1024
SOLUTION

(B) 1020 (D) 1040

Now byte addressable memory so 1 word i.e. 4 bytes require 4 addresses. Instruction MOV R1, (3000) MOV R2, R1 ADD R2, R1 Words Location 2 1 1 1000-1007 1008-1011 1012-1015
Page 35

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
MOV (R3), R2 INC R3 1 1 1016-1019 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.

Data for Q. 58 & Q. 59 are given below.


Consider a machine with a byte addressable main memory of 216 bytes. Assume that a direct mapped data cache consisting of 32 lines of 64 bytes each is used in the system. A 50 # 50 two-dimensional array of bytes is stored in the main memory stating from memory location 1100H.Assume that the data cache is initially empty. The complete array is accessed twice. Assume that the contents of the data cache do not change in between the two accesses.
Question. 58

How many data cache misses will occur in total? (A) 48 (B) 50 (C) 56
SOLUTION

(D) 59

Size of main memory 216 bytes. Size of Cache = 32 # 64 B = 211 B Size of array = 2500 B Array is stored in main memory but cache is empty. Size of Cache = 2048 B So no. of page faults = 2500 2048 = 452 For second access = 452 # 2 = 904 Total = 1356 Hence (C) is correct option.

Page 36

www.gatehelp.com
Question. 59

CS Topicwise 2001-2010 Computer Organization & Architecture

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

(D) line 0 to line 8

No of page faults = 452 One line has 64 B So the line at which these page faults will finish. = 452 , 7 64 So 0 to 7 line Hence (C) is correct option.
YEAR 2008 Question. 60

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

Tracks on magnetic disks are concentric a seek is from me sector to other may or maynt be in different tracks. This seek distance is not proportional to latency since the tracks at periphery has higher diameter so high in capacity to store data. Hence (C) is correct option.
Question. 61

Which of the following is/are true of the auto increment addressing mode? 1. It is useful in creating self relocating code 2. If it is included in an Instruction Set Architecture, then an
Page 37

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

(D) 2 and 3 only

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

(D) 1, 2 and 3 only

RFE (Return From Exception) is a privileged trap trap instruction which is executed when exception occurs, so an exception is not allowed to execute. Hence (D) is correct option.
Question. 63

For inclusion to hold between two cache level L1 and L2 in a multilevel cache hierarchy, which of the following are necessary? 1. L1 must be a write-through cache 2. L2 must be write-through cache
Page 38

www.gatehelp.com
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
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

(D) 1, 2, 3 and 4

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

Which of the following are NOT true in a pipe lined processor? 1. 2. Bypassing can handle alll Raw hazards. Register renaming can eliminate all register carried WAR hazards. 3. Control hazard penalties can be eliminated by dynamic branch prediction. (A) 1 and 2 only (B) 1 and 3 only (C) 2 and 3 only
SOLUTION

(D) 1,2 and 3

In a pipelined processor by passing cant handle all the row hazards. Registers carried WAR doesnt have register naming as proper solution. And control hazard penalties are eliminated by delayed branching not by dynamic branch prediction. So all are false. Hence (D) is correct option.
Question. 65

The use of multiple register windows with overlap causes a reduction in the number of memory accesses for 1. Function locals and parameters 2. Register saves and restores
Page 39

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
3. Instruction fetches (A) 1 only (C) 3 only
SOLUTION

(B) 2 only (D) 1,2 and 3

Multiple register windows with overlap causes a reduction in the number of memory accesses for instruction fetching. Hence (C) is correct option.
Question. 66

In an instruction execution pipeline, the earliest that the data TLB (Translation Look aside Buffer) can be accessed is (A) before effective address calculation has started (B) during effective address calculation (C) after effective address calculation has completed (D) after data cache lookup has completed
SOLUTION

TLB is used during effective address calculation in an instruction execution pipeline. Hence (B) is correct option.

Data for Q. 67, 68 & 69 are given below.


Consider a machine a 2-way set associative data cache of size 64 kbytes and block size 16 bytes. The cache is managed using 32 bit virtual addressed and the page size is 4 kbytes. A program to be run on this machine begins as follows: Double APR[1024]]1024] int i , j ; /*Initalize array APR to 0.0*/ for (i = 0; i < 1024; i ++) for (j = 0; k < 1024; j ++) APR[i] [j] = 0.0; The size of double 8 bytes. Array APR is in memory stating at the beginning of virtual page 0 # FF000 and stored in row major order. The cache is initially empty and no pre-fetching is done. The only
Page 40

www.gatehelp.com
data memory references made by the program are those to array APR.
Question. 67

CS Topicwise 2001-2010 Computer Organization & Architecture

The total size of the tags in the cache directory is (A) 32 kbits (B) 34 kbits (C) 64 kbits
SOLUTION

(D) 68 kbits

Virtual (CPU) address has 2 way set associative cache size Size of 1 set Require 15 bits for indexing. So Tag Size of block

= 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]
SOLUTION

(D) APR[5][0]

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

APR[%] [%] APR[%] [1]............... APR[2] [%]................................ APR[4] [%]................................ So on. This is virtual memory storage. So 15 LSB of APR [%] [%] & APR [%] [%] are same so same index APR [%] & APR [4] 17 MSB are different so tags differ. Hence (B) is correct option.
Question. 69

The cache hit ratio for this initialization loop is (A) 0% (C) 50%
SOLUTION

(B) 25% (D) 75%

Cache hit ratio = =

No. of hits Total accesses 1024 = 1 = 0.5 1024 + 1024 2

or = 50% Hence (C) is correct option.

Data for Q. 70 & 71 are given below.


Delayed branching can help in the handling of control hazardous
Question. 70

For all delayed conditional branch instruction, irrespective of weather the condition evato true or false, A (A) the instruction following the conditional branch instruction in memory is executed (B) the first instruction in the fall through path is executed (C) the first instruction in the taken path is executed (D) the branch takes longer to execute that any other instruction
Page 42

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

Delayed branching for conditional instructions, irrespective of whether the condition evaluates to true or false, the first instruction in the fall through path would be executed this prevent from hazardous control transfer. Hence (B) is correct option.
Question. 71

The following code is to run on a pipe lined processor with one branch delay slot 11: ADD R2 ! R7+R8 12: SUB R4 ! R5 R6 13: ADD R1 ! R2 + R3 14: STORE Memory [R4] ! R1 BRANCH to Label if R1==0 Which of the instruction 11,12,13 or 14 can legitimately occupy the delay slot without any other program modification? (A) 11 (C) 13
SOLUTION

(B) 12 (D) 14

In pipelining result of 1 instruction is used for the next in pipeline. Delay slot will be occupied by the next instruction in the fall through path. The branching instruction R1 == 0 goto Label X. So in delay slot I2 will be there. Hence (B) is correct option.
YEAR 2009 Question. 72

How many 32K#1 RAM chips are needed to provide a memory capacity of 356-bytes ? (A) 8 (C) 64 (B) 32 (D) 128
Page 43

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
SOLUTION

Memory capacity of 1 RAM = 32 K bits Total Memory required = 256 K bytes 3 No. of RAM = 256 # K # 2 # bits 32 # K # bits
8 23 Chips required = 2 # 5 2

= 26 = 64 Hence (C) is correct option.


Question. 73

A CPU generally handles are interrupt by executing an interrupt service routine (A) As soon as an interrupt is raised (B) By checking the interrupt register at the end of fetch cycle (C) By checking the interrupt register after finishing the execution of the current instruction (D) By checking the interrupt register at fixed time intervals
SOLUTION

An interrupt is a signal delivered to CPU, which tells to stop its normal service routine & execute interrupt service routine. This interrupt service routine is checked as soon as CPU receives the interrupt but since CPU working unit is an instruction so CPU can switch to ISR only after execution of current instruction. Hence (C) is correct option.
Question. 74

Consider a 4 stage pipeline processor. The number of cycles needed by the four instructions 11, 12, 13, 14 in stages S1, S2, S3, S4 is shown below:
S1 I1 I2 I3
Page 44

S2 1 3 1

S3 1 2 1

S4 1 2 3

2 2 2

www.gatehelp.com
I4 1 2 2 2

CS Topicwise 2001-2010 Computer Organization & Architecture

What is the number of cycles needed to execute the following loop? for (i = 1 to 2){I1; I2; I3; I4;} (A) 16 (C) 28
SOLUTION

(B) 23 (D) 30

We can see a single iteration of given for loop according to the cycles required. Cycle S1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 I1 I1 I2 I3 I3 I4 I1 I2 I2 I2 I3 I4 I4 I2 I2 I3 I4 I4 I2 I2 I3 I3 I3 I4 I4 I4 I3 I2 I1 I1 I1 S2 S3 S4 Completion

No. of cycle of 2 iteration = 2 # 15 = 30 Hence (D) is correct option.


Question. 75

Consider a 4 way set associative cache (initially empty) with total 16 cache blocks. The main memory consists of 256 blocks and the request for memory blocks is in the following order :
Page 45

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 (C) 129
SOLUTION

(B) 8 (D) 216

4 way set associative so 16 block will be divided in 4 sets of 4 blocks each. We apply (Address mod 4) function to decide set. 0 Set 0 4 8 216 1 Set 1 133 129 73 48 32 8 92 1 133 129 73 0 255 1 4 3 8 133 159 216 Set 2 129 63 8 255 Set 3 3 159 63 155 3 159 63 98 32 73 92 155 mod 4 = 0 ) mod 4 = 3 ) mod 4 = 1 ) mod 4 = 0 ) mod 4 = 3 ) mod 4 = 0 ) mod 4 = 1 ) mod 4 = 3 ) mod 4 = 0 ) mod 4 = 1 ) mod 4 = 3 ) mod 4 = 0 ) mod 4 = 0 ) mod 4 = 0 ) mod 4 = 1 ) mod 4 = 0 ) mod 4 = 3 )

All ) are misses S1 is the first stage & S2 is second. In the second stage 216 is not present in Cache Hence (D) is correct option.

Common Data for Question 76 & 77


A hard disk has 63 sectors per track, 10 platters each with 2 recording
Page 46

www.gatehelp.com
surfaces and 1000 cylinders. The address of a sector is given as a triple c, h, s , where c is the cylinder number, h is the surface number and s is the sector number. Thus, the 0th sector is addressed as 0, 0, 0 , the 1st sector as 0, 0, 1 , and so on.
Question. 76

CS Topicwise 2001-2010 Computer Organization & Architecture

The address 400, 16, 29 , corresponds to sector number: (A) 505035 (C) 505037
SOLUTION

(B) 505036 (D) 505038

Each cylinder has 10 platters or 20 recording surfaces or 63 # 20 sector = 1260 sectors. Each recording surface has 63 sectors. So < 400, 16, 297 =< c, h, s > 400 # 1260 + 16 # 63 + 29 505037 Hence (C) is correct option.
Question. 77

The address of 1039th sector is (A) 0, 15, 31 (C) 0, 16, 31


SOLUTION

(B) 0, 16, 30 (D) 0, 17, 31

1 cylinder has 1260 sectors So address for 1039th sector. C =0 Each surface has 63 sectors. Total surface here = 1039 = 16 surfaces 63 Remainder here 31 sectors So < 0, 16, 31 >. Hence (C) is correct option.
Page 47

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
YEAR 2010 Question. 78

A main memory unit with a capacity of 4 megabytes is build using 1M # 1 bit DRAM chips. Each DRAM chip has 1K rows of cells with 1 K cells in each row. The time taken for a single refresh operation is 100 nanoseconds. The time required to perform one refresh operation on all the cells in the memory unit is (A) 100 nanoseconds (B) 100)210 nanoseconds (C) 100)220 nanoseconds
SOLUTION

(D) 3200)220 nanoseconds

Size of main memory = 4 MB 1 DRAM size = 1 Mb No. of chips required = 4 # M # 8 # b 1#M#b = 32 1 DRAM has 1 K rows 1 ROW has 1 K cells Total cells in 1 DRAM = K2 = 220 In 32 DRAM = 32 # 220 Cells 1 cell refresh take 100 ns. So total refresh time = 32 # 100 # 220 ns = 3200 # 220 ns. Hence (D) is correct option.
Question. 79

A-5 stage pipelined processor has Instruction Fetch. (IF), Instruction Decode (ID), Operand Fetch (OF), Perform Operation (PO) and Write Operand (WO) stages. The IF, ID, OF and WO stages take 1 clock cycle each for any instruction. The PO stage takes 1 clock cycle for ADD and SUB instruction. The PO stage takes 1 stake clock cycle for ADD and SUB instructions 3 clock cycles for MUL instruction, and 6 clock cycles for DIV instruction respectively. Operand forwarding is used in the pipeline. What is the number of clock cycles needed to execute the following sequence of instructions ?
Page 48

www.gatehelp.com
Instruction Meaning of instruction I 0 : MUL R2, R 0, R1 I1 : DIV R5, R 3, R 4 I2 : ADD R2, R5, R2 I 3 : SUB R5, R2, R6 (A) 13 (C) 17
SOLUTION

CS Topicwise 2001-2010 Computer Organization & Architecture

R2 ! R 0)R1 R5 ! R 3 /R 4 R2 ! R5 + R2 R5 ! R2 R6 (B) 15 (D) 19

The order of operations IF " ID " OF " PO " WO Figure Here A = (R 3 /R 4) + R2, R6

So we can see that all the instruction can be executed in 17 clock cycles using piplining. Hence (C) is correct option.
Question. 80

The program below uses six temporary variables a, b, c, d, e, f a=1 b = 10 c = 20 d = a+b e = c+d f = c+e b = c+e e = b+f d = 5+e Assuming that all operations take their operands from register, what is the minimum number of registers needed to execute this program without spilling ? (A) 2 (B) 3 (C) 4 (D) 6
Page 49

CS Topicwise 2001-2010 Computer Organization & Architecture

www.gatehelp.com
SOLUTION

Replacement R1 a d d f f f R2 R3 b b e e b e c c c c c c

f e d So all the operations done using 3 registers only. Hence (B) is correct option.

Common Data for Questions 81 & 82


A computer system has an L1 and L2 cache, an L2 cache, and a main memory unit connected as shown below. The block size in L1 cache is 4 words. The block size is L2 cache is 16 words. The memory access times are 2 nanoseconds, 20 nanoseconds and 200 nanoseconds for L1 cache, L2 cache and main memory unity respectively.

Question. 81

When there is a miss in L1 cache and a hit in L2 cache, a block is transferred form L2 cache to L1 cache. What is the time taken for this transfer ? (A) 2 nanoseconds (C) 22 nanoseconds
SOLUTION

(B) 20 nanoseconds (D) 88 nanoseconds

Each block is L2 Cache is 4 times L1 Cache. So far 1 block miss in L1 Cache the block from L2 to L1 will be transferred, but L2 block has size 16 words & L1 data bus of 4 words, so 4L2 & 4L1 access are
Page 50

www.gatehelp.com
required. 4 # 2 + 4 # 20 8 + 80 88 ns Hence (D) is correct option.
Question. 82

CS Topicwise 2001-2010 Computer Organization & Architecture

When there is a miss in both L1 cache and L2 cache, first a block is transferred from memory to L2 cache, and then a block is transferred from L2 cache to L1 cache. What is the total time taken for these transfers ? (A) 222 nanoseconds (C) 902 nanoseconds
SOLUTION

(B) 888 nanoseconds (D) 968 nanoseconds

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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Database

YEAR 2000 Question. 1

Given the relations employee (name, salary, deptno), and department (deptno, deptname, address) Which of the following queries cannot be expressed using the basic relational algebra operations (, , A , , + ) ? (A) Department address of every employee (B) Employee whose name is the same as their department name (C) The sum of all employee salaries (D) All employees of a given department
SOLUTION

Question. 2

Given the following relation instance. X 1 1 1 3 Y Z 4 5 6 2 2 3 3 2

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

(D) XZ " Y and Y " X

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

Consider a schema R(A,B,C,D) and functional dependencies A " B and C " D. Then the decomposition of R intoR1 (AB) and R2 ]CD g is : (A) Dependency preserving and lossless join (B) Lossless join but not dependency preserving (C) Dependency preserving but not lossless join (D) Not dependency preserving and not lossless join
SOLUTION

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
R1 (AB) + R2 (CD) " R2 (CD) Since A " B &C " D So lossless join not possible. Hence (C) is correct option.
Question. 5

CS Topicwise 2001-2010 Database

Suppose the adjacency relation of vertices in a graph is represented in a table Adj (X, Y). Which of the following queries cannot be expressed by a relational algebra expression of constant length ? (A) List all vertices adjacent to a given vertex. (B) List all vertices which have self loops (C) List all vertices which belong to cycles of less than three vertices (D) List all vertices reachable from a given vertex
SOLUTION

The database contains the adjacency list of the graph. So relation algebra with face problems when while calculating the length of cycle self loops come, then the query would execute in one tuple only. Hence (C) is correct option.
Question. 6

Let r and s be two relations over the relation schemes R and S respectively, and let A be an attribute in R . Then the relational algebra expression A = a ]r A s g is always equal to : (B) r (A) A = a ]r g (C) A = a ]r A s g (D) None of the above
SOLUTION

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

R,(A,B,C,D) is a relation. Which of the following does not have a


Page 3

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

(D) A " BCD

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

Which of the following relational calculus expressions is not safe ? (A) {r | 7u ! R1 (t [A]) = u [A]^ J7s ! R2 (t [A] = s [A])} (B) {r | 6u ! R1 (u [A]) = "x" & 7s ! R2 (t [A] = s [A]^ s [A] = u [A]))} (C) {t | J (t ! R1)} (D) {t | 7u ! R1 (t [A] = u [A])^ 7s ! R2 9t [A] = s [A])}
SOLUTION

In option (C) {t (t ! R1)} is not safe since no criteria for selection of tuple has been given. Hence (C) is correct option.
Question. 9

Consider a relation geq which represents greater than or equal to, that is, (x, y) ! geq only if y # x: Create table gaq ( Ib integer not null ub integer not null primary key Ib foreign key (ub) references geq on delete cascade):
Page 4

www.gatehelp.com
Which of the following is possible if a tuple (x, y) is deleted ? (A) A tuple (z, w) with z > y is deleted (B) A tuple (z, w) with z > x is deleted (C) A tuple (z, w) with w < x is deleted (D) The deletion of (x, y) is prohibited
SOLUTION

CS Topicwise 2001-2010 Database

Tuple (x, y) is deleted. Here y $ x lb is primary key ub is foreign key

Since y refer to same key z . & in table A x a primary key is deleted so all enteries from table B will also be deleted. And also all enteries referencing it in y will also be deleted. So a tuple (z, w) with w < x will also be deleted. Hence (C) is correct option.
YEAR 2002 Question. 10

Relation R with an associated set of functional dependencies, F , is decomposed into BCNF . The redundancy (arising out of functional dependencies) in the resulting set of relations is. (A) Zero (B) More than zero but less than that of an equivalent 3NF decomposition (C) Proportional to the size of F+ (D) Indetermine.

Page 5

CS Topicwise 2001-2010 Database

www.gatehelp.com
SOLUTION

BCNF (Boyce Cold Normal Form) Since R is decomposed in BCNF then no redundancy in the resulting set may occur and all transitive dependencies are removed. Hence (A) is correct option.
Question. 11

With regard to the expressive power of the formal relational query languages, which of the following statements is true ? (A) Relational algebra is more powerful than relational calculus. (B) Relational algebra has the same power as relational calculus. (C) Relational algebra has the same power as safe relational calculus. (D) None of the above.
SOLUTION

Expressive power is the capacity of formal query languages to express various query statements, so relational algebra is as powerful as relational calculus only if calculus is safe relational calculus. Hence (C) is correct option.
Question. 12

AB+ -tree index is to be built on the Name attribute of the relation STUDENT . Assume that all student names are of length 8 bytes, disk blocks are of size 512 bytes, and index pointers are of size 4 bytes. Given this scenario, what would be the best choice of the degree (i.e. the number of pointers per node) of the B+ -tree ? (A) 16 (C) 43
SOLUTION

(B) 42 (D) 44

So

Size of 1 record of index = 8 + 4 = 12 bytes. Let no. of pointers required = P No. of index values per block = P 1 (P 1) 8 + 4P = 512 12P = 520 P , 44

Page 6

www.gatehelp.com

CS Topicwise 2001-2010 Database

Hence (D) is correct option.


Question. 13

Relation R is decomposed using a set of functional dependencies, F ,and relation S is decomposed using another set of functional dependencies, G . One decomposition is definitely BCNF , the other is definitely. 3NF , but it is not known which is which. To make a guaranteed identification, which one of the following tests should be used on the decompositions ? (Assume that the closures of F and G are available). (A) Dependency-preservation (C) BCNF definition
SOLUTION

(B) Lossless-join (D) 3NF definition

BCNF is more stricter than 3NF . So if we check database for BCNF then it will definitely be in 3NF . Hence (C) is correct option.
Question. 14

From the following instance of relation schema R (A, B, C), we can conclude that : A 1 1 2 2 B 1 1 3 3 C 1 0 2 2

(A) A functionally determines B and B functionally determines C (B) A functionally determines B and B does not functionally determines C . (C) B does not functionally determines C (D) A does not functionally B and B does not functionally determines.
SOLUTION

A is said to Be functionally determined by B only is A has same


Page 7

CS Topicwise 2001-2010 Database

www.gatehelp.com
value for same values of B for every corresponding tuple. In given database. A 1 1 2 2 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

B 1 1 3 3 here if A is 1 then B is necessarily 1 & if A is 2 then

Question. 15

Which of the following scenarios may lead to an irrecoverable error in a database system? (A) A transaction writes a data item after it is read by an uncommitted transaction (B) A transaction read a data item after it is read by an uncommitted transaction (C) A transaction read a data item after it is written by an committed transaction (D) A transaction read a data item after it is written by an uncommitted transaction
SOLUTION

(A) read & then write. (B) read after read (C) read after committed write (D) read after uncommitted write Option (D) is a condition for inconsisting Option (D) is correct option
Page 8

www.gatehelp.com
Question. 16

CS Topicwise 2001-2010 Database

Consider the following SQL query select distinct a1, a2,....... an from r1, r2,..... rm where P For an arbitrary predicate P ,this query is equivalent to which of the following relational algebra expressions? (A) (B) (C) (D)
a1, a2,... an

(r1 # r2 # ......rm)

a1, a2,... an

(r1 21 r2 21 ...... 21 rm) (r1 , r2 , ...... , rm) (r1 + r2 , ...... + rm)

a1, a2,... an

a1, a2,... an

SOLUTION

Here the SQL query selects distinct attributes, in relation algebra it doesnt require any symbol but only projection. P is the predicate in relation algebra, from has multiple relations, this is join in relation algebra (RA). (r1 # r2 # ..... # rm)
a1, a2 .......an

Hence (A) is correct option.


Question. 17

Consider the following functional dependencise in a database: Data_of_Birth " Age Name " Roll_number Age " Eligibility 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

Date of Birth " Age Age " Eligibility so transitively Date of Birth " Eligibility Name ? Roll no. Given relation C (Roll no. Name, Date of Birth, Age) Roll no. & Name are keys. 1. Age is functionally dependent upon date of birth which is non key, so 2NF is not applicable. 2. In 3NF , every non key should be non transitively or fully dependent upon all the keys, but here this is not the case, so not in 3NF . 3. In BCNF every non trivial functional dependency in the relation is a dependency on a super key. So also not in BCNF . So it is in INF only, since no repeating tuples. Hence (D) is correct option
Question. 4

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
SOLUTION

CS Topicwise 2001-2010 Database

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 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

T3

Let us draw a flow diagram between the three schedules, an edge between two schedules is there if there exist read-write or write-write
Page 11

CS Topicwise 2001-2010 Database

www.gatehelp.com
dependency in between them. So we draw the graph.

Since there exist a cycle between T1 & T3 so there is no serializability. Hence (D) is correct option
YEAR 2004 Question. 6

Let R1 (A, B, C) and R2 (D, E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in R1 referring to R2 . Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances r1 and rl2 . Which one of the following relational algebra expressions would necessarily produce an empty relation? (A) D (r1) C (r1) (C) D (r1 D C ! D R2) C (r1)
SOLUTION

(B) C (r1) D (r1) (D) C (r1 D C = D R2)

C is an attribute in R1 but D is a key in K2 . So consider C (r1) D (r2) So the result of this query would be all those tuples which are in C (r1) but not in D (r2). Since D is a key so it has all the possible values of C . So difference would always be empty. Hence (B) is correct.
Question. 7

Consider the following relation schema pertaining to a students database:


Page 12

www.gatehelp.com
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 (C) 960,8
SOLUTION

CS Topicwise 2001-2010 Database

(B) 120,8 (D) 960,120

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 (8,8) = (max, min) Hence (A) is correct option
Question. 8

It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id and salary. Employees belong to different categories and their salary is determined by their category. The functions get Name., getld and compute Salary are required. Given the class hierarchy below, possible locations for these functions are: (i) (ii) (iii) (iv) (v) (vi) (vii) getld is implemented in the superclass getld is implemented in the suclass getName is an abstract function in the superclass getName is implemented in the superclass getName is implemented in the subclass getSalary is an abstract function in the superclass getSalary is implemented in the superclass
Page 13

(viii) getSalary is implemented in the subclass

CS Topicwise 2001-2010 Database

www.gatehelp.com

Choose the best design (A) (i),(iv),(vi).(viii) (C) (i),(iii),(v),(vi),(viii)


SOLUTION

(B) (i),(iv),(vii) (D) (ii),(v),(viii)

Employee ID & employee name are independent of subclasses; manager engineer or secretary, so these should be implemented in super class, but salary is part of employee dependent, so abstract get salary should be in super class & its actual implementation in subclass. Hence (A) is correct option.
Question. 9

The relation scheme student Performance (name, courselNo, rollNo, grade) has the following functional dependencies: name, courseNo " grade RollNo, courseNo " grade name " rollNo rollNo " name The highest normal form of this relation scheme is (A) 2 NF (B) 3NF (C) BCNF
SOLUTION

(D) 4 NF

Name, course no. " grade Roll no. course no. " grade Name, Roll no are candidate keys grade depend upon both super keys. So it is 2NF , non key attribute grade depend upon super keys fully. But not in 3NF , since grade is not fully dependent upon all candidate keys.
Page 14

www.gatehelp.com
Hence (A) is correct option.
Question. 10

CS Topicwise 2001-2010 Database

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))

(A) names of girl students with the highest marks (B) names of girl students with more marks than some boy student (C) names of girl students with marks not less than some boy student (D) names of girl students with more marks than all the boy students
SOLUTION

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

The order of an internal node in a B* tree index is the maximum number of children it can have. Suppose that a child pointer takes 6 bytes, the search field value takes 14 bytes., and the block size is 512 bytes. What is the order of the internal node? (A) 24 (C) 26
SOLUTION

(B) 25 (D) 27

The structure of a block (node) of B+ tree

Page 15

CS Topicwise 2001-2010 Database

www.gatehelp.com
Total if let P pointers than (P 1) 14 + P # 6 20P 14 20P P 1 search fields. = 512 = 512 = 526 P 526 20 , 26 Hence (C) is correct option.
Question. 12

The employee information in a company is stored in the relation Employee (name, sex, salary, deptName) Consider the following SQL query select deptname from Employee where sex=M group by deptName having avg (salary)> (select avg(salary)from Employee) It returns the names of the department in which (A) the average salary is more than the average salary in the company (B) the average salary of male employees is more than the average salary of all male employees in the company (C) the average salary of male employees is more than the average salary of employees in the same department (D) the average salary of made employees is more than the average salary in the company
SOLUTION

Select average (salary) from employee selects average salary of the company. So the query returns the names of all the male employees of all the departments whose average salary is more than the average salary in the company. Hence (D) is correct option.
Page 16

www.gatehelp.com
YEAR 2005 Question. 13

CS Topicwise 2001-2010 Database

Which one of the following is a key factor for preferring B+ -trees to binary search trees for indexing database relation? (A) Database relations have a large number of record (B) Database relations are sorted on the primary key (C) B+ -trees require less memory than binary search trees (D) Data transfer from disks is in blocks
SOLUTION

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

Which-one of the following statements about normal forms is FALSE? (A) BCNF is stricter than 3 NF (B) Loss less, dependency-preserving decomposition into 3 NF is always possible (C) Loss less, dependency-preserving decomposition into BCNF is always possible (D) Any relation with two attributes is BCNF
SOLUTION

(A) BCNF is stricter than 3NF , is true. (B) True, dependency preserving lossless decomposition into 3NF is always possible, by removing transitive functional dependences. (C) False, lossless dependency preserving decomposition is not possible in all the cases, when all non trivial functional dependencies are not dependent upon super keys. (D) Certainly relation with two attributes is in BCNF , both will consist of super key. Hence (C) is correct option.
Page 17

CS Topicwise 2001-2010 Database

www.gatehelp.com
Question. 15

Let r be a relation instance with schema R = (A, B, C, D). WE DEFINE R1 = A, B, C (r) and r2 = AD (r). let S = r1 * r2 where * denotes natural join. Given that the decomposition of r into r1 and r2 is lossy, which one of the following is TRUE? (A) s 1 r (C) r 1 s
SOLUTION

(B) r 1 s = r (D) r * s = s

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 (C) 4
SOLUTION

(B) 3 (D) 5

Page 18

www.gatehelp.com
Since R2 is many to many so E1 has some primary key so one tables for E1 & to represent many to many relationship 1 table for R2 which will have the common attribute of E2 . R1 & E2 can be merged. So total 3 tables are required. Hence (B) is correct option.
Question. 17

CS Topicwise 2001-2010 Database

The following table has two attributes A and C where A is the primary key and C is the foreign key referencing A with on-delete cascade. A 2 3 4 5 7 9 6 C 4 4 3 2 2 5 4

The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple (2,4) is deleted is: (A) (3,4) and (6,4) (B) (5,2) and (7,2) (C) (5,2)(7,2) and (9,5)
SOLUTION

(D) 1

On delete cascade says that deletion of a primary key value should delete its all foreign key references. So in (2, 4) 2 is primary key so tuples (5, 2) & (7, 2) should be deleted, but in (5, 2) 5 is also a key so (9, 5) also deleted cascade. Hence (C) is correct option.
Question. 18

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

Consider a relation scheme R = (A, B, C, D, E, H) on which the following functional dependencies hold: {A " B, . BC " D, E " C, D " A} What are the candidate keys of R ? (B) AE, BE, DE (A) AE, BE (C) AEH, BEH, BCH
SOLUTION

(D) AEH, BEH, DEH

A " B , BC " D , E " C , D " A We start form set of all the attributes and reduce them using given functional dependences ABCDEH ABCDEH ABCEH {BC " D} ABEH {E " C} BCDEH {D " A} AEH {A " B} BEH {E " C} ABCDEH ACDEH {A " B} ADEH {E " C} DEH {D " A} So candidate keys are AEH , BEH & DEH
Page 20

www.gatehelp.com
Hence (D) is correct option.
YEAR 2006 Question. 20

CS Topicwise 2001-2010 Database

Consider the following log sequence of two transactions on a bank account, with initial balance 12000,that transfer 2000 to a mortgage payment and, then apply a 5% interest. 1. T1 start 2. T1 B old = 12000 new = 10000 3. T1 M old = 0 ne = 2000 4. T1 commit 5. T2 start 6. T2 B old = 10000 new = 10500 7. T2 commit Suppose the database system crashed just before log record 7 is written. When the system is restarted, which one statement is true of the recovery procedure? (A) We must redo log record 6 to set B to 10500 (B) We must undo log record 6 to set B to 10000 and then redo log records 2 and 3 (C) We need not redo log records 2 and 3 because transaction T1 has committed (D) We can apply redo and undo operations in arbitrary order because they are idempotent
SOLUTION

Here transaction T1 has been committed at record 4 so no need to redo them, since balanced commit & start. This is the step done for recovery. Hence (C) is correct option.
Question. 21

Consider the relation account (customer, balance) where customer is a primary key and there are no mall values. We would like to
Page 21

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. 2. 3. 4. 5. Query 1will produce the same row set as Query 2 for some but not all databases Both Query 1 Query 2 are correct implementations of the specification Query 1 is a correct implementation of the specification but Query 2 is not Neither query 1 nor Query 2 is a correct implementation of the specification 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 (D) 3 and 5

Which two of the above statements are correct? (A) 2 and 5 (C) 1 and 4
SOLUTION

Consider an example Customer Balance Correct Rank Query 1 (Rank) Query 2 (Rank) A B C D E 40 36 36 44 44 3 4 4 1 1 3 5 5 2 2 incorrect 3 4 4 1 1 correct

Query 1 is incorrect implementation Query 2 & 1 will give similar result when all balances are distinct, so
Page 22

www.gatehelp.com
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

CS Topicwise 2001-2010 Database

Consider the relation enrolled (student, course) in which student, course) is the primary key, and the relation paid (student, amount) where student is the primary key . Assume no null values and no foreign keys or integrity constraints. Given the following four queries: Query 1: Select from enrolled where student in (select student form paid) Query 2: Select student from paid where student in (select student from enrolled) Query 3: Select E. student from enrolled E, paid P where E. student= P student Query 4: Se3lect student from paid where exists (select*from enrolled where enrolled student=paid.student Which one of the following statements is correct? (A) All queries return identical row sets for any database (B) Query 2 and Query 4 return identical row sets for all databases but there exist database for which Query 1 and Query 2 retrun different row sets (C) There exist databases for which Query 3 returns strictly fewer rows than Query 2 (D) There exist databases for which Query 4 will encounter an intergrity violation at runtime
SOLUTION

Query 1

Return student names for different courses, so one student name may occur more than one time. Query 2 Student listed in paid, one student for one time only. Query 3 Repeating students. Query 4 One student selected only once from paid. So (A) is false. (B) is correct since (2) & (4) return same rows, but since three is
Page 23

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

Consider the relation enrolled (student, course) in which (student, course) is the primary key, and the relation paid (student, amount) where student is the primary key. Assume no null values and no foreign keys or integrity constraints. Assume that amounts 6000, 7000,8000,9000 and 10000 were each paid by 20% of the students. Consider these query plans (Plan 1 on left, Plan 2 on right) to list all courses taken by students who have paid more than x.

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
SOLUTION

CS Topicwise 2001-2010 Database

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

The following functional dependencies are given: AB " CF, AF " D, DE " F, C " G, F " E, G " A. Which one of the following options is false? (B) {BG} + = {ABCDG} (A) {CF} + = {ACFEFG} (C) {AF} + = {ACDEFG}
SOLUTION

(D) {AB} + = {ACDFG}

AB " CD AF " D DE " F C " G F " E G " A Let us take {AF} + AF AFE {F " E} AFDE {AF " D} = Y ACDEFG Hence (C) is correct option.
YEAR 2007 Question. 25

Information about a collection of students is given by the relation studInfo (studId, name, sex). The relation enroll (studID, CourseId) gives which student has enrolled for (or taken) what course(s). Assume that every course is taken by at least one male and at least one female student. What does the following relational algebra expression represent? courseld ((studId (sex = "female" (studInfo)) # courseId (enroII)) enroII) (A) Courses in which all the female students are enrolled (B) Courses in which a proper subset of female students are enrolled
Page 25

CS Topicwise 2001-2010 Database

www.gatehelp.com
(C) Courses in which only male students are enrolled (D) None of the above.
SOLUTION

studId (sex = female (studInfo) selects student id of all females. This is joined with all courses (unique) from enroll table. This results into all the combinations female students can take all the courses. Difference from enrol cause all the female student ids i.e the sub result eliminated, so virtually whole result is empty. Hence (A) is correct option.
Question. 26

Consider the relation employee (name, sex, supervisorName (with name as the key. supervisor Name-gives the name of the supervisor of the employee under consideration. What does the following Tuple Relational Calculus query produce? {e.name|employee(e) 0 (6 #) [Jemployee (x) 0 x.supervisorName ! e.name 0 x.sex = "male"]} (A) Names of employees with a male supervisor (B) Names of employees with no immediate male subordinates (C) Names of employees with no immediate female subordinates (D) Names of employees with a female supervisor
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

Consider the table employee (empId, name, department, salary) and the two queries Q1, Q2 below. Assuming that department 5 has more than one employee, and we want to find the employees who get higher
Page 26

www.gatehelp.com
salary than anyone in the department 5, which one of the statements is TRUE for any arbitrary employee table? Q1 : Select e. empId From employee e Where not exists (Select*From employee s Where s. department=5 and s.salay>=e.salary) Q.2 : Select e. empId From employee e Where e.salary>Any (Select distinct salary From employee s Where s. department=5) (A) Q1 is the correct query. (B) Q2 is the correct query (C) Both Q1 and Q2 produce the same answer (D) Neither Q1 nor Q2 is the correct query
SOLUTION

CS Topicwise 2001-2010 Database

Query Q2 is correct to calculate all the employee ID's where salary is greater than any employee of dept no. 5. So correct. But Q's sub-query is opposite also not correct no comparison after where clause. Hence (B) is correct option.
Question. 28

Which one of the following statements is FALSE? (A) Any relation with two attributes is in BCNF (B) A relation in which every key has only one attribute is in 2NF (C) A prime attribute can be transitively dependent on a key in 3NF relation (D) A prime attribute can be transitively dependent on a key in a BNCF relation.

Page 27

CS Topicwise 2001-2010 Database

www.gatehelp.com
SOLUTION

(A) True, since any relation with 2 attributes is in BCNF . (B) True since in 2NF non prime attributes should fully functional dependent upon keys. (C) A prime attribute can functionally dependent on a key in 3NF relation, this statement is tree. (D) But in BCNF transitivity is eliminated. So false. Hence (D) is correct option.
Question. 29

The order of a leaf node in a B+ tree is the maximum number of (value, data record pointer) pairs it can hold. Given that the block size is 1K bytes, data record pointer is 7 bytes long, the value field is 9 bytes long and a block pointer is 6 bytes long, what is the order of the leaf node? (A) 63 (C) 67
SOLUTION

(B) 64 (D) 68

Construction of B+ tree node here. 6 bytes block 7 byte data 9 byte value 7......... 7 pointer pointer So let P be no. of child pointer then data values = P 1 6 + (P 1) # 9 + P # 7 = 1024 16P 3 = 1024 16P = 1027 P = 1027 16 , 64 Hence (B) is correct option.
Question. 30

Consider the following schedules involving two transactions. Which one of the following statements is TRUE? S1:r1 (X); r1 (Y); r2 (X); r2 (Y); w2 (Y); w1 (X)
Page 28

www.gatehelp.com
S2:r1 (X); r2 (X); r2 (Y); w2 (Y); r1 (Y); w1 (X) (A) Both S1 and S2 are conflict serializable (B) S1 is conflict serializable and S2 is not conflict serializable (C) S1 is not conflict serializable and S2 is conflict serializable (D) Both S1 and S2 are not conflict serializable
SOLUTION

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

A clustering index is defined on the fields which are of type (A) Non-key and ordering (B) Non-key and non-ordering (C) key and ordering
SOLUTION

(D) Key and non-ordering

Clustering index is used when we have clusters of similar database enteries for a particular attribute.
Page 29

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

Let R and S be two relations with the following schema R (P, Q, R1, R2, R3) S (P, Q, S1, S2) Where {P, Q} is the key for both schemes. Which of the following queries are equivalent? I II III IV P (D S) P (R) D P (S) P (P, Q (R) + P, Q (S)) P (P, Q (R) (P, Q (R) P, Q (S))) (B) Only I and II (D) Only I, II and IV

(A) Only I and II (C) Only I, II and III


SOLUTION

I II

Projects P after joining R & S for common attributes P & Q . Selects P from R & P from S & then join so may have same tuples as I.

III Selects P from common PQ attributes & common tuples in R & S So same as equi join between R & S . IV Selects P from R which are only in S . So I, II & III are equivalent. Hence (C) is correct option.
Question. 33

Consider the following relational schemes for a library database: Book (Title, Author, Catalog_no, Publisher, Year, price)
Page 30

www.gatehelp.com
Collection (Title, Author, Catalog_no) Which the following functional dependencies: I. II. III. Title Author " Catalog_no Catalog_no " Title Author Publisher Year Publisher Title Year " price

CS Topicwise 2001-2010 Database

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 (D) 512 and 5

Page 31

CS Topicwise 2001-2010 Database

www.gatehelp.com
SOLUTION

The size of a block So total of bits required for So option (C) 256 &4 Hence (C) is correct option.

= 1024 bytes = 210 bytes first level & second level should be 10. = 28 = 22

Data for Q. 49 & 50 are given below.


Solve the problems and choose the correct answers. Consider the following ER diagram

Question. 35

The minimum number of tables needed to represent M, N, P, R1, R2 is (A) 2 (C) 4


SOLUTION

(B) 3 (D) 5

There are 3 entity set, but 2 relations R1 & R2 only. R1 is one to many from P to M . & R2 is one to many from P to N N is weak entity set here. Hence (B) is correct option.
Question. 36

Which of the following is a correct attribute set for one of the tables for the correct answer to the above question? (A) {M1,M2,M3,P1} (C) {M1,P1,N1} (B) {M1,P1,N1,N2} (D) {M1,P1}

Page 32

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Database

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 (C) S3 only (B) S2 and S3 (D) S4 only

SOLUTION

Conflict serializable schedules Schedule S1 T1 R (x) T2 Schedule S2 T1 R (x)


Page 33

T2

CS Topicwise 2001-2010 Database

www.gatehelp.com

Cycle exists between T1 & T2 Schedule S 3 T1 T2

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
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 (C) 4
SOLUTION

CS Topicwise 2001-2010 Database

(B) 3 (D) 5

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

Let R and S be relation schemes such that R = {a, b, c} and S = {c} . Now consider the following queries on the database : I. II. III. IV. R S (r) R S (R S (r) # S R S, S (r)) {t | t ! R S (r) / 6u ! s (7v ! r (u = v [s] / t = v [R S]))} {t | t ! R S (r) / 6v ! r (7u ! s (u = v [s] / t = v [R S]))} Select R.a, R.b

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

(C) III and IV

Query IV is a natural join between R & S . The similar result we obtain from Query II. Hence (C) is correct option.

Common Data for Q. 54 & 55:


Consider the following relational schema: Suppliers(sid: integer, sname:string, city:string, street:string) Parts(pid:integer, pname:string, color:string)
Page 36

www.gatehelp.com
Catalog(sid:integer, pid:integer, cost:real)
Question. 40

CS Topicwise 2001-2010 Database

Consider the following relational query on the above database : SELECT S.sname FROM Suppliers S WHERE S.sid NOT IN ( SELECT C.sid FROM Catalog C WHERE C.pid NOT IN ( SELECT P.pid FROM Parts P WHERE P.color?blue)) Assume that relations corresponding to the above schema are not empty. Which one of the following is the correct interpretation of the above query? (A) Find the names of all suppliers who have supplied a non-blue part. (B) Find the names of all suppliers who have not supplied a non-blue part. (C) Find the names of all suppliers who have supplied only blue parts. (D) Find the names of all suppliers who have not supplied only blue parts.
SOLUTION

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

Sname city forms the candidate key. Suppliers (sid, sname, city, street) Sname is primary key. Sid, sname is also key. City"street exists. Street is functionally dependent upon city. Sname" city. So transitivity occurs. So data base is in 3NF but not in BSNF .
YEAR 2010 Question. 42

Consider a B+ -tree in which the maximum number of keys in a node is 5. What is the minimum number of keys in any non-root node? (A) 1 (B) 2 (C) 3
SOLUTION

(D) 4

Given the no. of keys = 5 So order of any non root node = 6 This is maximum order Minimum no. of key = bP l 1 2 = b5l 1 = 3 1 = 2 2 Hence (B) is correct option
Question. 43

A relational schema for a train reservation database is given below. Passenger (pid, pname, age) Reservation (pid, class, tid)
Page 38

www.gatehelp.com
Table : passenger pid 0 1 2 3 pname Age

CS Topicwise 2001-2010 Database

Sachin 65 Rahul 66 Sourav 67 Anil 69

Table : Reservation pid class 0 1 2 3 4 5 AC AC SC AC SC AC tid 8200 8201 8201 8203 8204 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 (C) 1, 3
SOLUTION

(B) 1, 2 (D) 1, 5

The sub-query places a equity-join between 2 tables and select age >65. So pid 1, 2 & 3 are selected. In the main query from 1, 2 & 3 only 1 & 3 have class AC . Hence (C) is correct option.
Page 39

CS Topicwise 2001-2010 Database

www.gatehelp.com
Question. 44

Which of the following concurrency control protocols ensure both conflict serializability and freedom from deadlock? I. II 2-phase locking Time-stamp ordering (B) II only (D) Neither I nor II

(A) I only (C) Both I and II


SOLUTION

Two phase locking protocol works by running a transaction in two phases, in first phase locks on various data items is achieved only, once second phase i.e unlocking phase start, no locks can be granted then. So due to waiting to have lock, deadlock may occur. But time stamp protocol due to consideration of time stamp provide both conflict serializability as well as deadlock avoidance. Hence (B) is correct option.
Question. 45

Consider the following schedule for transactions T1, T2, and T3 : T1 Read (X) T2 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 (C) T2 " T3 " T1
SOLUTION

T3

(B) T2 " T1 " T3 (D) T3 " T1 " T2

Drawing the dependency graph where an edge between two transactions exits if there is read write or write-write conflict between them.
Page 40

www.gatehelp.com

CS Topicwise 2001-2010 Database

Applying topological sort gives order T1 " T3 " T2 Hence (A) is correct option.
Question. 46

The following functional dependencies hold for relations R(A,B,C) and S(B,D,E): B"A A"C The relation R contains 200 tuples and the relation S contains 100 tuples. What is the maximum number of tuples possible in the natural join R D S ? (A) 100 (C) 300 (B) 200 (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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Digital Logic

YEAR 2001

Question. 1

Given the following Karnaugh map, which one of the following represents the minimal sum-of-Products of the map ?

(A) xy + y'z (C) w'x + y'z + xy

(B) wx'y' + xy + xz (D) xz + y

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
SOLUTION

There are 2 quads. y'z + yx So xy + y'z Hence (A) is correct option.

Question. 2

Consider the following circuit with initial state Q 0 = Q1 = 0 . The D flip-flops are positive edged triggered and have set up times 20 nanosecond and hold times 0.

Consider the following timing diagrams of X and C ; the clock of C $ 40 nanosecond. Which one is the correct plot of Y

Page 2

www.gatehelp.com

CS Topicwise 2001-2010 Digital Logic

SOLUTION

Consider the following circuit with initial state Q 0 = Q1 = 0 . The D flip-flops are positive edged triggered and have set up times 20 nanosecond and hold times 0. Figure Consider the following timing diagrams of X and C ; the clock period of C $ 40 nanosecond. Which one is the correct plot of Y ? Figure

Question. 3

The 2s complement representation of ( 539) 10 is hexadecimal is (A) ABE (C) DE5


SOLUTION

(B) DBC (D) 9E7

Binary of 539 = 1000011011


Page 3

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).

Which of the following is true ? (A) f = x1' + x2 (C) f = x1x2 + x1'x2'


SOLUTION

(B) f = x1'x2 + x1x2' (D) f = x1 + x2

Output of any 2:1 MUX = ac' + bc Here output of MUX 1. ' g = ax 1 + bx1 Output of MVX 2 ' f = gx 2 + x1 x 2 ' ' f = (ax 1 + bx1) x 2 + x1 x 2 ' ' ' f = ax 1 x 2 + bx1 x 2 + x1 x2 Given a = 1, b = 0 ' ' f = x1 x 2 + x1 x 2 Hence (C) is correct option.
Question. 5

Consider the circuit given below the initial state Q 0 = 1, Q1 = Q2 = 0 . The state of the circuit is given by the value 4Q2 + 2Q1 + Q 0
Page 4

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 (C) 1, 2, 7, 3, 5, 6, 4 (B) 1, 2, 5, 3, 7, 6, 4 (D) 1, 6, 5, 7, 2, 3, 5

SOLUTION

Initially Clk 1 2 3 4 5 6

Q0 1 0 1 1 1 0 0

Q1 0 1 0 1 1 1 0

Q2 0 0 1 0 1 1 1

Value 4Q2 + 2Q1 + Q 0 1 2 5 3 7 6 4

Hence (B) is correct option.

YEAR 2002

Question. 6

Minimum sum of product expression for f (w, x, y, z) shown in Karnaugh-map below is


Page 5

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com

(A) xz + y'z (C) x'y + zx'


SOLUTION

(B) xz' + zx' (D) None of the above

There are 2 quads possible xz' + x'z Hence (B) is correct option.
Question. 7

The decimal value of 0.25 (A) is equivalent to the binary value 0.1 (B) is equivalent to the binary value 0.01 (C) is equivalent to the binary value 0.00111..... (D) cannot be represented precisely in binary.
Page 6

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Digital Logic

Given decimal no. 0.25 Binary = ? .25 # 2 = .5 .5 # 2 = 1 (.01) 2 Hence (B) is correct option.
Question. 8

The 2s complement represent representation of the decimal value 15 is (A) 1111 (C) 111111
SOLUTION

(B) 11111 (D) 10001

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

Sign extension is a step in (A) floating point multiplication (B) signed 16 bit integer addition (C) arithmetic left shift (D) converting a signed integer from one size to another.
SOLUTION

Sign extension is the operation in computer arithmetic of increasing no. of bits of a binary no., while preserving sign and value done by appending MSBs. In the floating point multiplication to bring the no. in desired no. of significant digits sign extension is done. Hence (A) is correct option.
Page 7

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
Question. 10

In 2s complement addition, overflow (A) Relational algebra is more powerful than relational calculus (B) Relational algebra has the same power as relational calculus. (C) Relational algebra has the same power as safe relational calculus. (D) None of the above.

SOLUTION

In 2s complement addition, overflow occurs when the carries from sign bit & previous bit doesnt match. So overflow cant occur when a positive value is added to some negative value. Hence (B) is correct option.
Question. 11

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) (C) (0, 1, 3, 5)
SOLUTION

(B) (6, 7) (D) None of the above

f1 (x, y, z) = (0, 1, 3, 5)
Page 8

www.gatehelp.com

CS Topicwise 2001-2010 Digital Logic

= x'y' + y'z + x'z f2 (x, y, z) = (6, 7)

= 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

Consider the following multiplexor where 10, 11, 12, 13 are four data input lines selected by two address line combinations A1A0 = 00, 01, 10, 11 respectively and f is the output of the multiplexor. EN is the Enable input.
Page 9

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com

The function f (x, y, z) implemented by the above circuit is (A) xyz' (C) x + y
SOLUTION

(B) xy + z (D) None of the above

A1 A 0 EN (MUX) work 0 0 1 1 0 1 0 1 1 0 1 0 do not (MUX) Work do not

So MUX is ENABLED only if A 0 = 0 So output should have Z' . Consider xyz' option (A) A, A 0 = 1 0 gives correct answer. Hence (A) is correct option.
Question. 13

Let f (A, B) = A' + B . Simplified expression for function f (f (x + y, y), z) is (A) x' + z (C) xy' + z
SOLUTION

(B) xyz (D) None of the above

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
[xy + yy ] + z xy + z Hence (C) is correct option.
Question. 14

CS Topicwise 2001-2010 Digital Logic

What are the states of the Auxiliary Carry (AC) and Carry Flag (CY) after executing the following 8085 program ? MIV H, MIV L, MOV A, ADD L (A) AC = 0 and CY = 0 (C) AC = 1 and CY = 0
SOLUTION

5DH 6BH H

(B) AC = 1 and CY = 1 (D) AC = 0 and CY = 1

Program is to add 2 nos kept in H & L, result of addition is stored in A. (5D) 16 + (6B) 16 &

0 is the carry so CY = 0 (1) is auxillary carry AC = 1 Hence (C) is correct option.


Question. 15

The finite state machine described by the following state diagram with A as starting state, where an arc label is x and x stands for y 1-bit input and y stands for 2-bit output.
Page 11

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

Previous input Present i/p Output 0(A) 0(A) 1(B) 1(B) 1(C) 1(C) 0(A) 1(B) 0(A) 1(C) 1(C) 0(A) 00 01 01 10 10 01

So output is always sum of the present and previous bits of input. Hence (A) is correct option.
YEAR 2003 Question. 16

Assuming all numbers are in 2s complement representation, which of the following number is divisible by 11111011? (A) 11100111 (C) 11010111
SOLUTION

(B) 11100100 (D) 11011011

We cant judge the nos in 2s complement first we need to convert them in decimal Given no. 11111011"00000101 = 5
Page 12

www.gatehelp.com
(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

CS Topicwise 2001-2010 Digital Logic

The following is a scheme for floating point number representation using 16 bits.

Let s, c and m be the number represented in binary in the sign, exponent, and mantissa fields respectively. Then the flouting point number represented id ( 1) 2 (1 + m # 2 9)2 e 31, if the exponent 111111 ) 0 otherwise What is the maximum difference between two successive real numbers representable in this system? (A) 2 40 (B) 2 9 (C) 222
SOLUTION

(D) 231

e has 6 bits so max value can be 26 1 = 63 when e = 111111 But given e = Y 111111 So max e = 62 = 111110 Two consecutive number will have same exponent but difference in mantissa by 1. Difference would be ( 1) 2 (1 + (m + 1) 2 9) 262 31 ( 1) 2 (1 + m # 2 9) 262 31 231 # 2 9 = 222 Hence (C) is correct option.
Page 13

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
Question. 18

A 1-input, 2-output synchronous sequential circuit behaves as follows. Let zk , nk denote the number of 0s and 1s respectively in initial k bits of the input (zk + nk = k). The circuit outputs 00 until one of the following conditions holds. 1. nk nk = 2 . In this case, the output at the k -th and all subsequency clock ticks is 10. 2. nk zk = 2 . In this case, the output at the k -th and all subsequent clock ticks is 01. What in the minimum number of states required in the state transition graph of the above circuit? (A) 5 (B) 6 (C) 7
SOLUTION

(D) 8

The sequential circuit has 3 variables to decide the state in which input & 2 inputs are present. Output for particular inputs decide states. i/p 0 0 0 0 1 1 1 1 op 1 op 2 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 State Intial nK zK = 2 zK nK = 2 Not applicable Initial nK zK = 2 zK nK = 2 is correct

Using 3 bits we require 23 1 = 7 states here. Hence (C) is correct option.


Question. 19

The literal count of a boolean expression is the sum of the number of times each literal appears in the expression. For example, the literal count of (xy + xz) is 4. What are the minimum possible literal counts
Page 14

www.gatehelp.com
of the product-of-sum and sum-of-product representations respectively of the function given by the following karnaugh map? Here, denotes dont care

CS Topicwise 2001-2010 Digital Logic

(A) (11,9) (C) (9,10)


SOLUTION

(B) (9,13) (D) (11,11)

Considering product of sum & sum of product separately.

Sum of product = wy + w'y' + z'wx' + xyz' 12 34 567 8910 Literal count =10 Hence (C) is correct option.

Product of sum = (y' + z') (z' + y) (w' + z') (x + z + w) Lateral count =9

In SOP the K-map is solved for 1 & POS K-map solved for 0
Page 15

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
Question. 20

Consider the following circuit composed of XOR gates and noninverting buffers.

The non-inverting buffers have delays 1 = 2ns and 2 = 4ns as shown in the figure. both XOR gates and al wires have zero delay. Assume that all gate inputs, outputs and wires are stable at logic level 0. If the following waveform is applied at input. A, how many transition (s) (change of logic levels) occur (s) at B during the interval from 0 to 10 ns ?

(A) 1 (C) 3
SOLUTION

(B) 2 (D) 4

Due to delays S1 = 2 & S2 = 4 the transitions would occur at time 1, 2 & 4. Time Input (A) Output (B) 0 I II III 1 2 4 1 1 1 0 0 0 0 1 Transition Transition Transition

So total 3 transitions Hence (C) is correct option.


YEAR 2004 Question. 21

The Boolean function x'y' + xy + x'y is equivalent to


Page 16

www.gatehelp.com
(A) x' + y' (C) x + y'
SOLUTION

CS Topicwise 2001-2010 Digital Logic

(B) x + y (D) x' + y

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

In an SR latch made by cross-coupling two NAND gates, if both S and R inputs are set to 0, then it will result in (A) Q = 0, Q' = 1 (B) Q = 1, Q' = 0 (C) Q = 1, Q' = 1
SOLUTION

(D) Indeterminate states

SR latch both S and R when 0 leads to invalid state.

Transition table for SR flip flop. S R Q(Next state) 0 0 Invalid so Q=Q=1 change 0 1 1 1 0 0 1 1 previous state For S=R=0 Q=Q=1 Hence (C) is correct option.
Page 17

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
SOLUTION

(D) 8, 11

(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.


Question. 24

5y + 4 84 64 69 59

What is the result of evaluating the following two expressions using three-digit floating point arithmetic with rounding? (113.+111.)+7.51 113.+(111.+7.51) (A) 9.51 and 10.0 respectively (C) 9.51 and 9.51 respectively
SOLUTION

(B) 10.0 and 9.51 respectively (D) 10.0 and 10.0 respectively

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
Question. 25

CS Topicwise 2001-2010 Digital Logic

A circuit outputs a digit in the form of 4 bits. 0 is represented by 0000, 1 by 0001,...9 by 1001. A combinational circuit is to be diesigned which takes these 4 bits as input and outputs 1 if the digit $ 5, and 0 otherwise. If only AND, OR and NOT gates may be used, what is the minimum number of gates required? (A) 2 (B) 3 (C) 4
SOLUTION

(D) 5

CKT takes 4 bits as the input so K-Map will have 4 variable so 16 options are available.

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

Which are the essential prime implicates of the following Boolean function? f (a, b, c) = a'c + ac' + b'c (A) a'c and ac' (B) a'c and b'c
Page 19

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
(C) a'c only
SOLUTION

(D) ac' and bc'

f (a, b, c) = a'c + ac' + b'c Making min terms a'bc + a'b'c + abc' + ab'c' + a'b'c + ab'c Since b'c gives no new term. So a'c & ac' are only essential prime implicants. Solution detailed method Tabulation method Since b'c gives no new term. So a'c & ac' are only essential prime implicants. Solution detailed method Tabulation method f (a, b, c) = / m (1, 3, 5, 6, 4) Figure Figure 3 & 6 have only 1 cross they are in a'c & ac'
Question. 27

Consider the partial implementation fo a 2-bit counter using T flip flops following the sequence 0-2-3-1-0, as shown below

To complete the circuit, the input X should be (A) Q2 ' (C) (Q1 5 Q2)'
SOLUTION

(B) Q2 + Q1 (D) Q1 5 Q2

Counter counts the no. of signal inversion change of states. Sequence input is 0 2 3 1 0
Page 20

www.gatehelp.com
Binary 00 10 11 01 00 to generate signals if we XOR gate then it outputs 1 if both are different. So output sequence would be. 0 1 0 1 0 & the sequence would be counted. So. X = Q1 5 Q2 Hence (D) is correct option.
Question. 28

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 (C) 10 time units
SOLUTION

(B) 6 time units (D) 12 time units

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

Let A = 11111010 and B 0000 1010 be two 8-bit 2s complement numbers. Their product in 2s complement is (A) 1100 0100 (C) 1010 0101 (B) 1001 1100 (D) 1101 0101
Page 21

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
SOLUTION

A and B are in 2s complement form. A = 11111010 Binary = 00000110 = 6 2s complement represent ve number So A = 6 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

Consider the following circuit.

Which one of the following is TRUE? (A) f is independent of X (C) f is independent of Z (B) f is independent of Y (D) None of X, Y, Z is redundant

Page 22

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Digital Logic

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

The range of integers that can be represented by an a bit 2s complement number system is (A) 2n 1 to (2n 1 1) (B) (2n 1 1) to (2n 1 1) (C) 2n 1 to 2n 1
SOLUTION

(D) (2n 1 + 1) to (2n 1 1)

n bit 2s complement system must have corresponding bit binary system. But to implement + ve & ve nos. Both we require MSB to be sign bit. So maximum magnitude can be 2n 1 1 suppose we take n = 4.
Page 23

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

The hexadecimal representation of 6578 is (A) 1AF (C) D71


SOLUTION

(B) D78 (D) 32F

(657) 8 = (?) 16 Making binary 0 0 01 01 1 1 1 = (IAF) 16 B01 CS S A BB Hence (A) is correct option.
Question. 33

The switching expression corresponding to f (A, B, C, D) = / (1, 4, 5, 9, 11, 12) is (A) BC'D' + A'C'D + AB'D (C) ACD' + A'BC' + AC'D'
SOLUTION

(B) ABC' + ACF + B'C'D (D) A'BD + ACD' + BCD'

f (A, B, C, D) = / (1, 4, 5, 9, 11, 12) Drawing K map for min terms.

Page 24

www.gatehelp.com
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

CS Topicwise 2001-2010 Digital Logic

Consider the following circuit involving a positive edge triggered D -FF.

Consider the following timing diagram. Let Ai represent the logic level on the line A in the i th clock period.

Let A represent the complement of A . The correct output sequence on Y over the clock perids 1 through 5 is (A) A0 A1 A1 'A3 A4 (C) A1 A2 A2 'A3 A4
SOLUTION

(B) A0 A1 A2 'A3 A4 (D) A1 A2 'A3 A4 A5

We need to calculate equation for D input. D = (Ai X') ' (X'Q') ' = Ai + X + X + Q D = Ai ' + X + Q Drawing truth table for ckt Clock X Q 0 = 0 Q1 = 1 A i Y
Page 25

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
0 1 2 3 4 5 1 1 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 A0 ' A1 ' A2 ' A3 ' A4 ' A5 ' A0 ' A0 ' A1 ' A1 ' A3 ' A4 '

Hence (A) is correct option.


Question. 35

The following diagram represents a finite state machine which takes as input a binary number from the least significant bit

Which one of the following is TRUE? (A) It computes 1s complement of the input number (B) It computes 2s complement of the input number (C) It increments the input number (D) It decrements the input number
SOLUTION

The transition table for the diagram Present state Input Next state Output Q0 Q0 Q1 Q1 0 1 0 1 Q0 Q1 Q1 Q1 0 1 1 0

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
Question. 36

CS Topicwise 2001-2010 Digital Logic

Consider the following circuit

The flip-flops are positive edge triggered D FFs . Each state is designated as a two bit string Q0, Q1 . Let the initial state be 00. The state transition sequence is (A) 00 " 11 " 01 (B) 00 " 11 A BBBBBB BC A BBB BC (C) 00 " 10 " 01 " 11 (D) 00 " 11 " 01 " 10 A BBBBBBBBB BC A BBBBBBBBBB C
SOLUTION

Truth table for DFF CP 0 1 1 D X 0 1 Qn + 1 Qn 0 1 Action No change Reset Set

D here AX + X'Q' Truth table for ckt

and so on. Hence (D) is correct option.

Data for Q. 37 & 38 are given below.


Page 27

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
Solve the problems and choose the correct answers. Consider the following floating point format

Mantissa is a pure fraction is sign-magnitude form.


Question. 37

The decimal number 0.239 # 213 has the following hexadecimal representation without normalization and rounding off (A) 0D 24 (C) 4D 0D
SOLUTION

(B) 0D 4D (D) 4D 3D

Sign bit 0 Exponent = 13 Excess 64 = 13 + 64 = 77 = 1001101 Binary of 239

We have 8 bits for Mantissa 0 0 1 1 1 1 0 1 So the floating point format.


Page 28

www.gatehelp.com
0 0100 4 1001101 1101 D 00111101 0011 3 1101 D

CS Topicwise 2001-2010 Digital Logic

Hence (D) is correct option.


Question. 38

The normalized representation for the above format is specified as follows. The mantissa has an implicit 1 preceding the binary (radix) point. Assume that only 0s are padded in while shifting a field. The normalized representation of the above number (0.239 # 213) is (A) 0A 20 (B) 11 34 (C) 4D D0
SOLUTION

(D) 4A E8

Given no. .239 # 213 Normalized form of binary. Binary " .239 = (00111101) 2 Normalized = 1.11101 # 210 Proceeding implicit 1 So 8 bit mantissa 11101000 S padding Excess 64 exponent 1 0 0 1 0 1 0 = 74 Sign bit = 0 Floating 0 0100 4 Point 1001010 1010 A Format 11101000 1110 E 1000 8

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

We require phase shift of 180 in f In ckt (B) the negation of signal f & clock delays signal f by 180.
Page 30

www.gatehelp.com

CS Topicwise 2001-2010 Digital Logic

So phase shift occurs. Hence (B) is correct option.


Question. 40

Consider the circuit below. Which one of the following options correctly represents f (x, y, z)?

(A) xz + xy + yz (C) xz + xy + yz
SOLUTION

(B) xz + xy + yz

(D) xz + xy + yz

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 0 0 0 1 1 1 1 Case I 0 0 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1

These are the possible value of a2 a1 a 0 & b2 b1 b 0 when a2 = 1 c=1 Case II b2 = 1 c = 1 so a2 + b2 Case III If any 1 of a2 or b2 is 1 a2 5 b2 then if a1 = 1 c = 1 b1 = 1 c = 1 so a2 5 b2 [a1 + b1] Case IV If any of a2 or b2 is 1 & any of a2 or b1 is 1 then if a 0 = 1 c = 1 or if b 0 = 1 then c = 1 so overall. a2 + b2 + [(a2 5 b2) {a1 + b1 + (a1 5 b1) (a 0 + b 0)}] Hence (C) is correct option.

Question. 42

Consider a boolean function f (w, x, y, z). Suppose that exactly one of its inputs is allowed to change at a time. If the function happens to be true for two input vectors i1 + < w1, x1, y1, x1 > and i2 + < w2, x2, y2, z2 >
Page 32

www.gatehelp.com
, 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 (C) wxyz, xz, wxyz
SOLUTION

CS Topicwise 2001-2010 Digital Logic

(B) wxy, wxz, wyz (D) wzy, wyz, wxz, wwxz, xyz, xyz

Given function f (w, x, y, z) = (5, 7, 11, 12, 13, 15) draw K-map of the above function.

1 quad = xz = xz (y + y') = xzy + xy'z 2 pairs = wxy' + wyz xyz + xy'z + wxy' + wyz Hence (A) is correct option.
Question. 43

We consider addition of two 2s complement numbers bn 1 bn 2 .....b0 and an 1 an 2 ....a0 . A binary adder for adding unsigned binary numbers is used to add the two numbers. The sum is denoted by cn 1 cn 2 ....c0 and the carryout by cout . Which one of the following options correctly identifies the overflow condition? (A) cout (an 1 5 bn 1) (C) cout 5 cn 1
SOLUTION

(B) an 1 bn 1 cn 1 + an 1 bn 1 cn 1 (D) an 1 5 bn 1 5 cn 1

Binary adder generates C out only if


Page 33

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
1 C in 0 a 1 b 1 1 0 0 1 1 1 1 1 1 1

1 C out 1 C in is Cn 2 So

C out in this case is Cn 1 generated carry.

b' n 1 a' n 1 cn 2 + bn 1 an 1 c' n 2 f = Cout 5 Cn 1 Hence (C) is correct option.


Question. 44

Consider number represented in 4-bit gray code. Let h3 h2 h1 h0 be the gray code representation of a number n and let g3 g2 g1 g0 be the gray code of (n + 1) (modulo 16) value of the number. Which one of the following functions is correct? (A) g0 (h1 h2 h1 h0) = / (1, 2, 3, 6, 10, 13, 14, 15) (B) g1 (h1 h2 h1 h0) = / (4,9,10,11,12,,13,14,15) (C) g2 (h1 h2 h1 h0) = / (2,4, 5, 6, 7,12,,13,15) (D) g3 (h1 h2 h1 h0) = / (0, 1,6,7, 10, 11,12,,13,)
SOLUTION

Binary h 0000 0001 0010 0011 0100 0101 0110 0111 1000
Page 34

h 3 h2 h1 h 0 (n + 1) mod 16 0000 0001 0011 0010 0110 0111 0101 0100 1100 1 2 3 4 5 6 7 8 9

g 3 g 2 g1 g 0 0001 0011 0010 0110 0111 0101 0100 1100 1101

0 1 2 3 4 5 6 7 8

www.gatehelp.com
1001 1010 1011 1100 1101 1110 1111 9 1101 10 11 12 13 14 15 0 1111 1110 1010 1011 1001 1000 0000

CS Topicwise 2001-2010 Digital Logic

10 1111 11 1110 12 1010 13 1011 14 1001 15 1000

This gives the solution option (B) g1 (h 3, h2, h1, h 0) = / (4, 9, 10, 11, 12, 13, 14, 15)
YEAR 2007 Question. 45

What is the maximum number of different Boolean functions involving n Boolean variables? (B) 2n (A) n2 (C) 22
n

(D) 2n

SOLUTION

Each boolean variable can have values involving n boolean variables will have need to be arranged in different manner So this arrangement would take 2M ways Hence (C) is correct option.
Question. 46

0 or 1, so for expression terms 2n . These 2n terms and nos., suppose 2n = M . n or 22 ways.

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
SOLUTION

(D) 10

Total output lines required = 64 We need to use 3 to 8 decoders. So decoders required 64 = 8 decoders for output. 8

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

Consider the following Boolean function of four variables f (w, x,, y, z) = / (1, 3, 4, 6, 9, 11, 12, 14) The function is (A) independent of one variable (B) independent of two variables (C) independent of three variables (D) dependent on all the variables
SOLUTION

f (w, x, y, z) = / m (1, 3, 4, 6, 9, 11, 12, 14)

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

Let f (w, x, y, z) = / (0, 4, 5, 7, 8, 9, 13, 15). Which of the following expressions are NOT equivalent to f ? (B) w'y'x' + wx'y' + xz (A) x'y'z + w'xy' + wy'z + xz (C) w'y'z' + wx'y' + xyz + xy'z
Page 36

(D) x'y'z + wx'y' + w'y

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Digital Logic

f (w, x, y, z) = / m (0, 4, 5, 7, 8, 9, 13, 15) Drawing K-map.

xz + w'y'z' + wx'y' Hence (B) is correct option.


Question. 49

Define the connective* for the boolean variable X and Y as: X * Y = XY + X'Y' Let Z = X * Z Consider the following expression P, Q and R . P: X = Y * ZQ: Y = X * Z R: X * Y * Z = 1 Which of the following is TRUE? (A) only P and Q are valid (B) Only Q and R are valid (C) Only P and R are valid
SOLUTION

(D) All P, Q , R are valid

Given Z = X ) Z & XZ + X'Z' P: X = Y ) Z = YZ + Y'Z' = Y (XZ + X'Z') + Y'Z' = XYZ + X'YZ' + Y'Z' = XYZ + X'YZ' + XY'Z' + X'Y'Z' valid. Q: Y = X ) Z = XZ + X'Z' = X (XZ + X'Z') + X'Z'
Page 37

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

(D) 2n 2 line to 1 line

To select 2n lines we need a select function with n bits. Here with n variables we have (n 1) select bits thus 2n 1 data lines. So MUX has 2n 1 lines to 1. Hence (C) is correct option.
Question. 51

In a look-ahead carry generator, the carry generate function Gi and the carry propagate function Pi for inputs, Ai and Bi are given by Pi = Ai 5 Bi and Gi = Ai Bi The expressions for the sum bit S and carry bit Ci + 1 of the look ahead carry adder are given by Si + Pi 5 Ci and Ci + 1 Gi + Pi Ci , Where C0 is the input carry. Consider a two-level logic implementation of the look-ahead carry generator.. Assume that all Pi and Gi are available for the carry generator circuit and that the AND and OR gates can have any number of inputs. The number of AND gates and OR gates needed to implement the look-ahead carry generator for a 4-bit adder with S3, S2, S1, S0 and C4 as its outputs are respectively
Page 38

www.gatehelp.com
(A) 6,3 (C) 6,4
SOLUTION

CS Topicwise 2001-2010 Digital Logic

(B) 10,4 (D) 10,5

The equation for 4 bit carry look ahead adder is Cout g 3 + p 3 g2 + p 3 p2 g1 + p 3 p2 p1 g 0 + p 3 p2 p1 p 0 Cin Here no. of AND gates = 10 OR gates = 4 Hence (B) is correct option.
Question. 52

The control signal functions of 4-bit binary counter are given below (where X is dont care) Clear Clock Load Count Function 1 0 0 0 X X X 0 1 0 X 0 X 1 Clear to 0 No change Load input Count next

The counter is connected as follows

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 (C) 0,1,2,3,4 (B) 0,3,4,5 (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

In the IEEE floating point representation the hexadecimal value 0x00000000 corresponds to (A) the normalized value 2 127 (C) the normalized value + 0
SOLUTION

(B) the normalized value 2 126 (D) the special value + 0

This 0X00000000 hexadecimal value can be converted into 32 bit binary. 0000 0000 0000 0000 0000 0000 0000 0000 0 # 2c This is representation in IEEE floating point format. Case for special + 0 . Hence (D) is correct option.
Question. 54

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

www.gatehelp.com
(A) b.d + a.d

CS Topicwise 2001-2010 Digital Logic


(B) a.b + b.d + a.b.d (D) a.b + b.d + a.d


(C) b.d + a.b.d


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

(D) any value> 2

(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) (C) /m (6, 8)
SOLUTION

(B) /m (4, 8) (D) /m (4,6,8)

Given f = m (1, 6, 8, 15) f3 = m (1, 6, 15) So output 1,6,8,15 here 1,6,15 can come form f3 . Since the final gate is OR gate so from f1 AND f2 no minterm except 1,6,8,15 should come. f1 = m (4, 5, 6, 7, 8) So f2 can be m (6, 8) Since 4,5, & 7 should no 7 come here. Hence (C) is correct option.
Question. 57

If P , Q , R are Boolean variables, (P + Q) (P.Q + P.R) (P.R + Q) simplifies to (A) P.Q


Page 42

(B) P.R

www.gatehelp.com
(C) P.Q + R
SOLUTION

CS Topicwise 2001-2010 Digital Logic

(D) P.R + Q

= (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 (C) (2297) 10


SOLUTION

(B) (028F) 16 (D) (0B17) 16

= (1217) 8 = 001010001111 SSS = (028F) 16 Hence (B) is correct option.


Question. 59

What is the minimum number of gates required to implement the Boolean function (AB + C) if we have to use only 2-input NOR gates ? (A) 2 (C) 4 (B) 3 (D) 5
Page 43

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
SOLUTION

AB+C implementation through NOR gate (X + Y ) We require one AND gate & 1 OR gate

AND gate & OR gate can be implemented by NOR gate. = A+C+B+C = A+C:B+C = (A + C) : (B + C) = C + AB So we require & NOR gates. Hence (B) is correct option.
YEAR 2010 Question. 60

The minterm expansion of f (P, Q, R) = PQ + QR + PR is (A) m2 + m 4 + m6 + m1 (B) m 0 + m1 + m 3 + m5 (C) m 0 + m1 + m6 + m1


SOLUTION

(D) m2 + m 3 + m 4 + m5

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
Hence (A) is correct option.
Question. 61

CS Topicwise 2001-2010 Digital Logic

P is a 16-bit signed integer. The 2s complement representation of P is (F87B) 16 . The 2s complement representation of 8)P is (A) (C3D8) 16 (B) (187B) 16 (C) (F878) 16
SOLUTION

(D) (987B) 16

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

The Boolean expression for the output f of the multiplexer shown below is

(A) P 5 Q 5 R

(B) P 5 Q 5 R
Page 45

CS Topicwise 2001-2010 Digital Logic

www.gatehelp.com
(C) P + Q + R
SOLUTION

(D) P + Q + R

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 0 1 1 0 1 0 1 0R 1R 2R 3R

The expression has 3 variables So K-map

This is K-map for P 5 Q 5 R i.e PQ R + P Q R + PQR + P QR Hence (B) is correct option.


Question. 63

What is the boolean expression for the output f of the combinational logic circuit of NOR gates given below ?

Page 46

www.gatehelp.com
(A) Q + R (C) P + R
SOLUTION

CS Topicwise 2001-2010 Digital Logic

(B) P + Q (D) P + Q + R

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 "A = A

= (P + Q + Q + R ) : (P + R + Q + R )

= (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 ?

(A) 11, 10, 01, 00 (C) 10, 00, 01, 11


SOLUTION

(B) 10, 11, 01, 00 (D) 11, 10, 00, 01

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 0 1 1 T X 0 1 Qn + 1 Qn Qn Qn Qn previous state CP clock pulse 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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Operating System

YEAR 2001 Question. 1

Which of the following statements is false ? (A) Virtual memory implements the translation of a programs address space into physical memory address space. (B) Virtual memory allows each program to exceed the size of the primary memory. (C) Virtual memory increases the degree of multi-programming (D) Virtual memory reduces the context switching overhead.
SOLUTION

Virtual memory enables a program to exceed the size of primary memory so it increases degree of multi-programming. Since data required by executing program is available here so context switching is reduced. But virtual memory doesnt translate programs address space into physical memory. Hence (A) is correct option.
Question. 2

Consider a set of n tasks with known runtimes r1, r2, ........rn to be run on a uniprocessor machine. Which of the following processor scheduling algorithms will result in the maximum throughput ? (A) Round-Robin (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

Where does the swap space reside ? (A) RAM (C) ROM
SOLUTION

(B) Disk (D) On-chip cache

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

Consider a virtual memory system with FIFO page replacement policy. For an arbitrary page access pattern, increasing the number of page frames in main memory will. (A) Always decrease the number of page faults (B) Always increase the number of page faults (C) Sometimes increase the number of page faults (D) Never affect the number of page faults
SOLUTION

During F1F0 page replacement policy, due to increase in the no. of page frames in memory should decrease the no. of page faults since more frames can be kept there. But due to Beladys Anomaly after certain limit or in some page access instances no. of page faults are high. Hence (C) is correct option.
Page 2

www.gatehelp.com
Question. 5

CS Topicwise 2001-2010 Operating System

Consider a machine with 64 MB physical memory and a 32-bit virtual address space. If the page size is 4 KB, what is the approximate size of the page table ? (A) 16 MB (B) 8 MB (C) 2 MB
SOLUTION

(D) 24 MB

Size of main memory = 64 MB Size of virtual memory = 232 B 32 No. of pages = 212 2 = 220 pages Required 1 M enteries. But each entry has both a virtual address & corresponding physical address. Total bits in each entry = 32 + 26 (Physical) = 58 = 58 = 8 Bytes. 8 So total memory = 8 # 1 MB = 8 MB Hence (B) is correct option.
Question. 6

Consider Petersons algorithm for mutual exclusion between two concurrent processes i and j . The program executed by process is shown below. repeat ag[i]=true; turn=j; while(p)do no-op; Enter critical section, perform actions, then exit critical section Flag[i]=false; Perform other non-critical section actions. Until false; For the program to guarantee mutual exclusion, the predicate P in
Page 3

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
the while loop should be (A) flag [j]= true and turn =j (C) flag [i]=true and turn=j
SOLUTION

(B) flag [j]=true and turn =j (D) flag [i]=true and turn=i

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

Which of the following scheduling algorithms is non-preemptive ? (A) Round Robin (B) First-In First-Out (C) Multilevel Queue Scheduling (D) Multilevel Queue Scheduling with Feedback
SOLUTION

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
SOLUTION

CS Topicwise 2001-2010 Operating System

Optimal page replacement algorithm assumes that the pages that will come in future are already known, so replacement of the page which will not be used in future occurs. Hence (B) is correct option.
Question. 9

Which combination of the following features will suffice to characterize an OS as a multi-programmed OS ? More than one program may be loaded into main memory at the same time for execution. (B) If a program waits for certain events such as I/O, another program is immediately scheduled for execution. (C) If the execution of a program terminates, another program is immediately scheduled for execution. (A) A (C) A and C
SOLUTION

(B) A and B (D) A, B and C

Multi-programmed:- More than one program can run on single CPU, when one is blocked. (A) Is true and a characteristic of multi-programmed (B) Is true & also characterise a multi-programmed OS (C) Is true but no necessary for this type this happens in all OS, even in batch processor. Hence (B) is correct option.
Question. 10

In the index allocation scheme of blocks to a file, the maximum possible size of the file depends on (A) The size of the blocks, and the size of the address of the blocks (B) The number of blocks used for the index, and the size of the blocks. (C) The size of the blocks, the number of blocks used for the index, and the size of the address of the blocks. (D) None of the above.
Page 5

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

In a system with 32 bit virtual addresses and 1 KB page size, use of one-level page tables for virtual to physical address translation is not practical because of (A) the large amount of internal fragmentation (B) the large amount of external fragmentation (C) the large memory overhead in maintaining page tables (D) the large computation overhead in the translation process
SOLUTION

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
overhead. Hence (C) is correct option.
Question. 13

CS Topicwise 2001-2010 Operating System

A uni-processor computer system only has two processes, both of which alternate 10 ms CPU bursts with 90 ms I/O bursts. Both the processes were created at nearly the same time. The I/O of both processes can proceed in parallel. Which of the following scheduling strategies will result in the least CPU utilizations (over a long period of time) for this system ? (A) First come first served scheduling (B) Shortest remaining time first scheduling (C) Static priority scheduling with different priorities for the two processes (D) Round robin scheduling with a time quantum of 5 ms .
SOLUTION

There should be no doubt that round robin scheduling would lead to maximum CPU utilization, but since in FCFS one task would starve for a long time so min CPU utilization would be in this case. Hence (A) is correct option.

Data for Q. 14 & 15 are given below.


A processor uses 2-level page table fro virtual to physical address translation. Page table for both levels are stored in the main memory. Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in both levels of page tables are 4 a bytes wide. Further, the processor has a translation look aside buffer(TLB), with a hit rate of 96%. The TLB caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed cache with a bit ratio of 90%. Main memory access time is 10 ns , cache access time is 1 ns , and {LB access time
Page 7

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
SOLUTION

(D) 4 ns

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
SOLUTION

(D) 20 KB

Total no. of pages required = 5 But due to 2 level page table = 2 # 4 kB # 2 = 16 kB Hence (D) is correct option.

Data for Q. 16 & 17 are given below.


Page 8

www.gatehelp.com
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below. Process P Process Q: while(1) { while(1) { W: Y: print 0; print 1 print 0; print 1 X: Z: } } Synchronization statements can be inserted only at points W,X,Y and Z.
Question. 16

CS Topicwise 2001-2010 Operating System

Which of the following will always lead to an output staring with 001100110011 ? (A) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T inutuakkt 1 (B) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0 (C) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1 (D) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0
SOLUTION

For output string 001100110011 alternatingly we require process P & Q to execute. For this to happen P (s) with S = 1 should be placed at W. At the same time P (T) with T = 0 will be at Y. At X we have V (T) which will have T = 1 so process Q starts. At the same time at Z we have V(s) which make S = 0 to stop process P. Hence (B) is correct option.
Question. 17

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

To ensure this condition that substring of form 01n 0 or 10n 1, where n is odd S should be initially 1, we will case only 1 semaphore S. So at W P (s), at X V (s) Whereas at Y P (s), at Z V (s) Hence (C) is correct option.
YEAR 2004 Question. 18

Consider the following statements with respect to user-level threads and kernel-supported threads (i) Context which is faster with kernel-supported threads (ii) For user-level threads. a system call can block the entire process (iii) Kernel-supported threads can be scheduled independently (iv) User-level threads are transparent to the kernel Which of the above statements are true? (A) (ii),(iii) and (iv) only (B) (ii) and (iii) only (C) (i) and (iii) only
SOLUTION

(D) (i) and (ii) only

(I)

It is false, context switch is not faster in support of kernel threads. (II) A system call can truly block the user level threads, since they dont have permission to do that. (III) True since kernel supported threads have their independent memory & resources. (IV) False since user level threads might need support of kernel threads.
Page 10

www.gatehelp.com
Hence (B) is correct option.
Question. 19

CS Topicwise 2001-2010 Operating System

Consider an operating system capable of loading and executing a single sequential user process at a time. The disk head scheduling algorithm used is First Come First Served (FCFS). If FCFS is replaced by shortest seek Time Fist (SSTF), claimed by the vendor to given 50% better beachmark results, what is the expected improvement in the I/O performance of user programs? (A) 50% (C) 25%
SOLUTION

(B) 40% (D) 0%

I/O performance is not entirely dependent upon disk access, it has effect of various other devices, so using SSTF in place of FCFS may reduce disk access time but no improvement in the I/O is done. Hence (D) is correct option.
Question. 20

The minimum number of page frames that must be allocated to a running process in a virtual memory environment is determined by (A) the instruction set architecture (B) page size (C) physical memory size (D) number of processes in memory
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 Arrival time Burst time
Page 11

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
P1 P2 P3 P4 0 1 2 4 5 3 3 1

What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm? (A) 5.50 (C) 6.00
SOLUTION

(B) 5.75 (D) 6.25

Then around time = (Submit time finish time) Gantt chart for the scheduler.

= 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

Consider a system with a two-level paging scheme in which a regular memory access takes 150 nanoseconds, and servicing a page fault takes 8 milliseconds. An average instruction takes 100 nanoseconds of CPU time, and two memory accesses. The TLB hit ratio is 99%, and the page fault rate is one in every 10,000 instructions. What is the effective average instruction execution time? (A) 645 nanoseconds (C) 1215 nanoseconds
Page 12

(B) 1050 nanoseconds (D) 1230 nanoseconds

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

Memory access time = .90 # 150 + .10 # (150 + 150) = 135 + 30 = 165 ns The error rate = 1 = 10 4 10000 CPU burst time = 100 ns Total execution time = [100 + 2 [165] + 10 4 # 8 # 106] = 100 + 330 + 800 = 100 + 1130 = 1230 ns Hence (D) is correct option.
Question. 23

Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores Sx and Sy respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows: P1: while true do{ :...... :..... : while true do{ :...... :.......

In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively (A) P (SY ), P (SX ); P (SX ), P (SY ) (B) P (SX ), P (SY ); P (SY ), P (SX ) (C) P (SX ), P (SX ); P (SY ), P (SY )
SOLUTION

(D) P (SX ), P (SY ); P (SX ), P (SY )

Here semaphores are required to obtain mutual exclusion since both


Page 13

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
SOLUTION

(D) 2 48 bytes

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

Hence (C) is correct option.


YEAR 2005 Question. 25

Suppose n processes, P1,..... Pn share m identical resource units, which can be reserved and released one at a time. The maximum resource requirement of process Pi is sp where si < 0. Which one of the following is a sufficient condition for ensuring that deadlock does not occur? (A) 6i, s < m (B) 6i, s, < n (C)
Page 14
i=1

/ si < (m + n)

(D)

i=1

/ si < (m * n)

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

For every Pi Si is maximum resource requirement where Si > 0 . To allot resources to all processes without any deadlock situation is
i=1

/ Si

< (m + n)

i.e. sum of all maximum resource requirement should be less than m + n. Hence (C) is correct option.
Question. 26

Consider the following code fragment: if (fork()==0 {a = a + 5; print f ("%d,%/ n"a, and a);} else {a 5; print f ("%d,% d/n", a,& a);} let u , vbe the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE? (B) u = x + 10 and v ! y (A) u = x + 10 and v = y (C) u + 10= x and v = y
SOLUTION

(D) u + 10 = x and v ! y

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

Consider three CPU-intensive processes, which require 10,20 and 30 time units and arrive at times 0,2, and 6, respectively. How many context switches are needed if the operating system implements a shortes remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end (A) 1 (B) 2
Page 15

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
(C) 3
SOLUTION

(D) 4

When CPU burst are given to another process, called context switching. The Gantt chart for shortest remaining time first is.

So there are two context & witches at T = 10 & T = 30 Hence (B) is correct option.
Question. 28

The atomic feth-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x . Consider the following implementation of P and V functions on a binary semaphore S. void p (binary_semaphore*S){ unsigned y; unsigned*x =& (S->value);} do { fetch-and-set x,y; } while(y); } void V (binary_semphore*S){ {S_>value = 0; } Which one of the following is true? (A) The implementation may not work if context switching is disabled in P (B) Instead of using fetch-and-set, a pair of normal load/store can be used (C) The implementation of V is wrong (D) The code does not implement a binary semaphore
Page 16

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

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 (C) 15 bits
SOLUTION

(B) 13 bits (D) 20 bits

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

A computer system supports 32-bit virtual addresses as well as 32-bit physical addresses, Since the virtual address space is of the same size as the physical address space, the operating system designers decide to get rid of the virtual entirely. Which one of the following is true? (A) Efficient implementation of multi-user support is no longer possible (B) The processor cache organization can be made more efficient now (C) Hardware support for memory management is no longer needed (D) CPU scheduling can be made more efficient now
Page 17

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

Consider three processes (process id 0,1,2, respectively) with compute time bursts 2,4, and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id . The average turn around time is (A) 13 units (B) 14 units (C) 15 units
SOLUTION

(D) 16 units

Process id 0 1 2 CPU burst 2 4 8 So we draw Gantt chart for scheduler

At t = 0 longest remaining time for P2 At t = 4 remaining times for both P1 & P2 is 4 so P1 is given priority. At t = 8 remaining time for P0 P1 & P2 is 2 P0 is given priority & cyclically done till t = 14 . Process TAT P0 12 0 = 12 P1 13 0 = 13 P2 14 0 = 14 = 13 units. 39 3 Hence (A) is correct option.
Question. 32

Consider three processes, all arriving at time zero, with total execution time of 10, 20 and 30 units, respectively. Each process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again.
Page 18

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% (C) 30.0%
SOLUTION

CS Topicwise 2001-2010 Operating System

(B) 10.6% (D) 89.4%

Process First I/0 2 2 3 4 6

Computation Second I/0 7 14 21 1 2 3

Total 10 20 30

Since I/0 can be done parallely. Gantt chart

Total time taken = 51 units CPU has to wait = 6 units = 6 # 100 51 = 10.6% Hence (B) is correct option.
Question. 33

Consider the following snapshot of a system running n processes. Process i is holding xi instances of a resource R , for 1 # i # n . Currently, all instances of R are occupied. Further, for all i , process
Page 19

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

(D) min (xp, xq) > 1

Here option (B) is that min (X p, Xq) < max k = Y p, q y k Means the min no. of resources allocated should be less than the maximum no. of resources required by any process other than p & q .It prevent from deadlock. Hence (B) is correct option.

Data for Q. 34 & 35 are given below.


Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on the left. Void 1 2 3 4 5 6 7 8 9 10 11 }
Page 20

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
The variable process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally.
Question. 34

CS Topicwise 2001-2010 Operating System

The above implementation of barrier is incorrect. Which one of the following is true? (A) The barrier implementation is wrong due to the use of binary semaphore S (B) The barrier implementation may lead to a deadlock if two barrier invocations are used in immediate succession (C) Lines 6 to 10 need not be inside a critical section (D) The barrier implementation is correct if there are only two processes instead of three
SOLUTION

This barrier implementation is to keep track of arrival & completion of processes in system, by incrementing no. of process arrived & left. This implementation may lead to deadlock if two barrier functions invocations are used is immediate sessions. Since V (s) in first invocation at line 3 removes 1-3 from critical section bring 5-11 in critical section at line 7. Hence (B) is correct option.
Question. 35

Which one of the following rectifies the problem in the implementation? (A) lines 6 to 10 are simply replaced by process_arrived (B) At the beginning of the barrier the first process to enter the barrier waits until process_arrived becomes zero before proceeding to execute P(S) (C) Context switch is disabled at the beginning of the barrier and re-enabled at the end. (D) The variable process_left is made private instead of shared
Page 21

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
SOLUTION

To rectify the barrier function at the beginning of the functions the first process which inters the function waits until process arrived becomes zero before executing P (s). This removes any deadlock situation. Hence (B) is correct option.
YEAR 2007 Question. 36

Group-1 contains some CPU scheduling algorithms and group-2 contains some applications. Match entries in Group-1 entries in Group-2 Group-1 P. Gang Scheduling Q. Rate Monotonic Scheduling R. Fair Share scheduling (A) P-3;Q-2;R-1 (C) P-2;Q-3;R-1
SOLUTION

Group-2 1. Guaranteed Scheduling 2. Real-time Scheduling 3. Thread Scheduling (B) P-1;Q-2;R-3 (D) P-1;Q-3;R-2

Rate monotonic scheduling is for real time processes, Gang scheduling is used to schedule group of program threads and fair share scheduling is a scheduling which guarantees a fair share of CPU burst to every competing process. Hence (A) is correct option.
Question. 37

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
(D) Blocking one kernel level thread blocks all related threads
SOLUTION

CS Topicwise 2001-2010 Operating System

Threading a method of executing small sub processes instead of single big process. This prevents thread from blocking. So blocking of one kernel level thread doesnt block other related threads, they are unaffected. So (D) is false. Hence (D) is correct option.
Question. 38

An operating system uses Shortest Remaining Time first (SRT) process scheduling algorithm. Consider the arrival times and execution times for the following processes Process P1 P2 P3 P4 (A) 5 (C) 40
SOLUTION

Execution time 20 25 10 15 (B) 15 (D) 55

Arrival time 0 15 30 45

What is the total waiting time for process P2?

Gantt chart for the processes.

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

A virtual memory system uses first In First Out (FIFO) page replacement policy and allocates a fixed number of frames to a process. Consider the following statements: P: Increasing the number of page frames allocated to a process sometimes increases the page fault rate. Q: Some program do not exhibit locality of reference. Which one of the following is TRUE? (A) Both P and Q are ture, and Q is the reason for P (B) Both P and Q are true, but Q is not the reason for P (C) P is false, but Q is true (D) Both P and Q are false
SOLUTION

Dueto Beladys Anomaly, increasing the number of page frames allocated to a process sometimes increase the page fault rate so P is true. Also some program do not exhibit locality of reference, so both are true but Q is not reason for P . Hence (B) is correct option.
Question. 40

A single processor system has three resource types X, Y, and Z, which are shared by three processes. There are 5 units of each resource type. Consider the following scenario, where the column alloc denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Which of these processes will finish LAST? alloc XYZ 121 201 221 request XYZ 103 012 120

P0 P1 P2
Page 24

www.gatehelp.com
(A) P0 (B) P1 (C) P2 (D) None of the above, since the system is in a deadlock
SOLUTION

CS Topicwise 2001-2010 Operating System

Initially. Process P0 P1 P2

Allow XYZ 121 121 221

Request/need XYZ 103 012 120

Available XYZ 012

Here looking at available resources, only need of P1 can be completed. So P1 will execute & free 2 0 1 so now available XYZ = 203 . This is need for P0 so at second no. P0 will execute & free XYZ = 121 so available 3 2 4 & in the end need of P2 is fulfilled. Hence (C) is correct option.
Question. 41

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: /* P1 */ while (true) { wants1=true; while(wants2==true); /* Critical /*P2*/ while (true) { wants2 = true; while (wants1 == true); /* Critical

Section*/ wants 1 = false; } /* Remainder section*/ }

Section*/ wants 2 = false;

/*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

If P1 make wants 1 = true then P2 goes in critical section & vice versa so both together are implementing mutual exclusion but. Since both are accessing wants 1 & wants 2 concurrently 4 wants 1 is first captured by P1 so P2 will wait & P2 captures want 2 so P1 will have to wait. So a definite deadlock. Hence (D) is correct option.

Data for Q. 42 & 43 are given below.


A process has been allocated 3 page frames. Assume that none of the pages of the process are available in the memory initially. The process makes the following sequence of page references (reference string): 1,2,1,3,7,4,5,6,3,1.
Question. 42

If optimal page replacement policy is used, how many page faults occur for the above reference string? (A) 7 (C) 9
SOLUTION

(B) 8 (D) 10

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

) denotes page fault So no. of page faults are 7. Hence (A) is correct option.
Question. 43

Least Recently Used (LRU) page replacement policy is a practical approximation to optimal page replacement. For the above reference string, how many more page faults occur with LRU than with the optimal page replacement policy? (A) 0 (C) 2
SOLUTION

(B) 1 (D) 3

Instead of optimal policy if we use LRU then we dont have future knowledge but we replace that page in memory which has been recently used in past. Order " 1, 2, 1, 3, 7, 4, 5, 6, 3, 1

) denotes page faults. In this case no. of page fault = 9 In optimal strategy = 7 Difference = 9 7 = 2 Hence (C) is correct option.
Page 27

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
YEAR 2008 Question. 44

Which of the following system calls results in the sending of SYN packets? (A) socket (B) bind (C) listen
SOLUTION

(D) connect

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

Generally a large file system for UNIX OS use indexed allocation, but for very large systems an extension of indexed allocation i.e. ext 2, ext 3 are used. Hence (D) is correct option.
Question. 46

The P and V operations on counting semaphores, where s is a counting ewmaphore, are defined as follows: P (s); s = s 1; ifs < 0 then wait; V (s): s = s + 1; ifs <= 0 then wakeup a process waiting on s ;
Page 28

www.gatehelp.com
Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary semaphores Xb and Yb are used to implement the semaphore operations P (s) and V (s) as follows: P (s): Pb (X b); if

CS Topicwise 2001-2010 Operating System

} else s s s if s

The initial values of xb and yb are respectively (A) 0 and 0 (B) 0 and 1 (C) 1 and 0
SOLUTION

(D) 1 and 1

Xb & Yb are binary semaphores used to implement mutual exclusion here. So when Xb is 1 Yb should be zero so only 1 code between the two could run. Since Pb (Xb) module implementing wait process so Xb should be 1. Pb (Yb) implementing signal S = S + 1 So Yb should be 0 initially. Hence (C) is correct option.
Question. 47

Which of the following statements about synchronous and asynchronous I/O is NOT true? (A) An ISR is invoked on completion of I/O in synchronous I/O but not in asynchronous I/O (B) In both synchronous and asynchronous I/O an ISR (Interrupt Serive Routine) is invoked after completion of the I/O (C) A process making a synchronous I/O cal waits until I/O is complete, but a process making an asynchronous I/O call does not wait for completion of the I/O
Page 29

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

For the completion of I/0 an interrupt should be generated for CPU in case of both synchronous & asynchronous I/0 and this ISR call is before them. So CPU can switch to I/0. Hence (B) is correct option.
Question. 48

Which of the following is NOT true of deadlock prevention and deadlock avoidance schemes? (A) In deadlock prevention, the request for resources is always granted if the resulting state is safe (B) In deadlock avoidance, the request for resources is always granted if the resulting state is safe (C) Deadlock avoidance is less restrictive than deadlock prevention (D) Deadlock avoidance requires knowledge of resource requirements a priori
SOLUTION

Both deadlock prevention, & avoidance allocate resources if the resulting state is safe state so option (A) & (B) are tree. The difference in both schemes is that in avoidance we know the requirement a prior. But Deadlock avoidance is less restrictive than prevention is false. Hence (C) is correct option.
Question. 49

A process executes the following code for(i = 0' i < n; i ++)fork(); The total number of child processes created is (A) n (B) 2n 1 (C) 2n (D) 2n + 1 1

Page 30

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

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

A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table entry is of size 4 bytes. A three level page table is used for virtual-to-physical address translation, where the virtual address is used as follows : bits 30-31 are used to index into the first level page table, : bits 21-29 are used to index into second level page table : bits 12-20 are used to index into third level page table : bits 0-11 are used as offset within the page The number of bits required for addressing the next level page table (or page frame) in the page table entry of the first, second and third level page table are respectively. (A) 20,20 and 20 (B) 24,24 and 24 (C) 24,24 and 20
SOLUTION

(D) 25,25 and 24

Total address single = 36 bit First level no. of bits = 2 # 12 = 24 bits Second level = 4 # 6 = 24 bits Third level = 8 # 3 = 24 bits Hence (B) is correct option.
YEAR 2009 Question. 51

Consider a system with 4 type of resources R1 (3 units), R2 (2 units), R3 (3 units), R4 (4units). A non-preemptive resource allocation policy is used. At any give instance, a request is not entertained if it
Page 31

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 P1: t=0; t=0; t=0; t=5; 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 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

t=7; release 1 units of R3 t=8; request 2 units of R4 t=10; Finishes

Which one of the following statements is TRUE if all three processes run concurrently starting at time t = 0 ? (A) All processes will finish without any deadlock (B) Only P1 and P2 will be in deadlock (C) Only P1 and P3 will be in deadlock (D) All three processes will be in deadlock
SOLUTION

Total resources = 3 2 3 2 Process 1 Process 2 Process 3 Available Time 1 2 3 4 0 1 2 3 4 5 6 7 8 9 0200 0210 0210 0210 0210 1110 1110 1100 1100 1102 1234 0020 0020 0021 0021 1021 1021 1011 1011 0000 0000 1234 0001 0001 2001 2001 2001 0001 0001 0101 0111 0000 1234 3011 3001 1000 1000 0000 1100 1110 1020 2021 2130

10 0 0 0 0 0000 0000 3232 All process computed without deadlock Hence (A) is correct option.
Page 32

www.gatehelp.com
Question. 52

CS Topicwise 2001-2010 Operating System

In which of the following page replacement policies, Beladys anomaly may occur ? (A) FIFO (C) LRU
SOLUTION

(B) Optimal (D) MRU

Beladys anomaly is a properly of FIFO page replacement policy in which the no. of page faults increases even if the no. of page frames are increased in some cases. Hence (A) is correct option.
Question. 53

The essential content(S) in each entry of a page table is/are (A) virtual page number (B) page frame number (C) Both virtual page number and page frame number (D) access right information
SOLUTION

A page table is in main memory which mop a page frame to a virtual memory page. So essential content is page frame number Hence (B) is correct option.
Question. 54

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 (C) 233 ms (B) 119 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

In the following process state transition diagram for a uniprocessor system, assume that there are always some processes in the steady state :

Now consider the following statements : I. If a process makes a transition D, it would result in another process making transition A immediately II A process P2 in blocked state can make transition E while another process P1 is in running state

III The OS uses non-premptive scheduling IV The OS uses non-premptive scheduling Which of the above statement are TRUE ? (A) I and II (B) I and III (C) II and III
Page 34

(D) II and IV

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

I II

Is not necessary that a new process enters immediately. Is true different process can be in different states one is ready and another in running state.

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

The enter_CS ( ) and leave_CS ( ) functions to implement critical section of a process are realized using test and set instruction as follows : Void enter_cs (X) { while (test-and-set)(X)) : } Void leave_CS(X) { X=0; } In the above solution, X is a memory location associated with the CS and is initialized to 0. Now consider the following statements I The above solution to CS problem is deadlock-free II The solution is starvation free III The processes enter CS in FIFO order IV More than one process can enter CS at the same time Which of the above statements are TRUE (A) I only (B) I and II (C) II and III
SOLUTION I Is true since

(D) IV only

X is initialized to zero, this cause only 1 process to enter


into critical so no deadlock.

II & III

Are false, other process which doesnt capture X will wait so ultimately starve.
Page 35

CS Topicwise 2001-2010 Operating System

www.gatehelp.com
IV Since I true so it is false. Hence (A) is correct option.
Question. 57

A multilevel page table is preferred in comparison to a single level page table for translating virtual address to physical address because (A) It reduces the memory access time to read or write and memory location (B) It helps to reduce the size of page table needed to implement the virtual address space of a process (C) If is required by the translation lookaside buffer (D) If helps to reduce the number of page faults in page replacement algorithms.
SOLUTION

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

Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables S1 and S2 are randomly assigned. Method used by P1 While (S1==S2); Critical Section S1=S2; Method used by P2 While (S1!=S2); Critical Section S2=not (S1)

While one of the following statements describes properties achieved ? (A) Mutual exclusion nut nor progress (B) Progress but not mutual exclusion (C) Neither mutual exclusion nor progress (D) Both mutual exclusion and progress
Page 36

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Operating System

Method used by P1 & P2 enters into critical section when S1 = S2 & S1 ! = S2 respectively, since both are opposite conditions so mutual exclusion is there, but if P1 's while loop true then it will always be true & in P2 if while loop true it would run infinitely so no. progress. Hence (A) is correct option.
Question. 59

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
SOLUTION

(D) 195

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

Which of the following statements are true ? I Shortest remaining time first scheduling may cause starvation II II Preemptive scheduling may cause starvation Round robin in better than FCFS in terms of response time (B) I and III only (D) I, II and III

(A) I only (C) II and III only


SOLUTION

I II

SRIF scheduling may cause starvation since the processes which require large CPU burst periods would have to wait. Generally preemptive scheduling doesnt cause starvation but
Page 37

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

The following program consists of 3 concurrent precesses and 3 binary semaphores. The semaphores are initialized as S 0 = 1, S1 = 0, S2 = 0 Process P0 Process P1 Process P2 wait (S2 ) release (S 0 );

While (true){ wait (S1 ); wait (S 0 ); release (S 0 ); print 0 release (S1 ); release (S2 ); }

How many times will precess P0 print 0 ? (A) At least twice (B) Exactly twice (C) Exactly thrice
SOLUTION

(D) Exactly once

Let us see what will happen initially S 0 = 1, S1 = 0 S2 = 0 so P1 & P2 will wait & P0 runs & make S 0 = 0 wait decrements semaphore by 1 & release increments if by 1. So after P0 's 1st run S1 = 1 & S2 = 1 0 is printed Now P1 & P2 can run & make S1 = 0 , S2 = 0 but both increments S 0 = 1 again. So P0 again starts and print '0' so this would continue again & again. So '0' will be printed at least twice. Hence (A) is correct option.
Question. 62

A system has n resources R 0 ..R n - 1, and k processes P0 ..Pk - 1.The implementation of the resource request logic of each process Pi , is as follows:
Page 38

www.gatehelp.com
if (i%2==0){ if(i<n)request
i

CS Topicwise 2001-2010 Operating System

;
i + 2;

if(i+2<n)request } else { if (i<n)request if (i+2<n)request }


n

;
n i 2

In which one of the following situations is a deadlock possible ? (A) n = 40, k = 26 (C) n = 20, k = 10 (B) n = 21, k = 12 (D) n = 41, k = 19

SOLUTION

Allotment of resources would be successful to all cases but in option (B) where n = 21 & k = 12 . Let use take i = 10 So for P10 only R10 can be allotted whereas for P11 odd case (else). R21 11 i.e R10 can only be allotted. This is an conflict. Hence (B) is correct option.

Page 39

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Programming and Data Structure

YEAR 2001 Question. 1

What is printed by the print statements in the program P1 assuming call by reference parameter passing ? Program P1( ) { 1 1( r r x; y; )

} func1(x,y,z) { y=y+4 z=x+y+z; } (A) 10, 3 (C) 27, 7


SOLUTION

(B) 31, 3 (D) None of the above

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

Consider the following three functions : [P1] int *g(void) { intx=10; return (& x); } [P2] int *g(void) { int *px; *px=10; return px; } [P3] int *g(void) { int *px px=(int*)malloc (size of (int)); *px=10; return px; } Which of the above three functions are likely to cause problems with pointers ? (A) Only P3 (B) Only P1 and P3 (C) Only P1 and P2
SOLUTION

(D) P1, P2 and P3

P1 : Here the function is returning address of the variable x (& x ) but the return type is pointer to integer not address. So incorrect. P2 : * px = 0 directly assigned a value but still px doesnt point to any memory location, so memory initialization or allocation should be done before. So incorrect. P3: Correction made in P2, memory pre allocated, So correct. Hence (C) is correct option.
Question. 3

Consider the following program Program P2


Page 2

www.gatehelp.com
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 (C) 3
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

(B) 11 (D) None of the above

n = 10 given but not passed to D. In D, n = 3 & W (n) increments by 1. So n = n + 1 = 4 . Hence (D) is correct option.
YEAR 2002

Question. 4

The results returned by function under value-result and reference parameter passing conventions (A) Do not differ (B) Differ in the presence of loops (C) Differ in all cases (D) May differ in the presence of exception
Page 3

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
SOLUTION

The results returned by function under value & reference parameter passing may differ in presence of loops. Hence (B) is correct option.
Question. 5

Consider the following declaration of a two-dimensional array in C : Char a[100][100] Assuming that the main memory is byte-addressable and that array is stored starting form memory address 0, the address of a [40] [50] is (A) 4040 (B) 4050 (C) 5040
SOLUTION

(D) 5050

Char a [100] [100] 1 char require 1 byte Total required 10000 bytes. Memory format is byte addressable a [ 0] [ 0 ] a [0] [50] g h g g a [50] [0] a [40] [50] g h g g a [99] [0] g g g a [0] [99] g h g h g h g a [99] [99]

100 bytes per row. I.e 40 # 100 = 4000 1 byte per column I. e. 50 # 1 = 50 Total 4050 Hence (B) is correct option.
YEAR 2003 Question. 6

Consider the following C function. oat f(oat x, int y){ oat p, s; int i; for (s=1, p=1, i=1, i<y; i++)
Page 4

www.gatehelp.com
{ 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)
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

(D) xx

The function is rewritten as s = ;p = ; for i = ; i y; i ++ { p = p ) x/i; s = s + p; } Here initial value of s increments every time with a factor of p ) x/i Initially s = p= Loop P counter (i) 1 2 3 4 x x ) x/2 : 1 = x2 /2 : 1 x3 /3! # x/4 = x 4 /4! S 1+x 1 + x + x2 /2 1 + x + x2 /2! + x3 /3! + x 4 /4!

x2 /2 ) x/3 = x3 /3 : 2 : 1 1 + x + x2 /2! + x3 /3!

Thus it can be checked for every value. Here the assumption is that the value of y is very large so y " 3 So the series 1 + x + x2 /2! + x3 /3!................3 will have infinite terms & from our previous knowledge we know that this 3 series is expansion of ex (exponential series) so. 1 + x + x2 /2! + x3 /3!...........3 = ex Hence (B) is correct option.
Question. 7

Assume the following C variable declaration int)A[10], B[10][10];


Page 5

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 (C) 2 and 4 only
SOLUTION

(B) 2, 3, and 4, only (D) 4 only

which is an array of 10 integer value We have int ) pointer whereas B [10] [10] is an array which stores 10 # 10 = 100 integers So let us try to solve it eliminating way. " Option 3 B[1] cant be at the left side since it is 2D array so cant use single index. We need not necessarily specify the size of first dimension for B[][3] " Option 4 B[2][3] is assignment to the array B value so possible. " Option 1 A [2] is also possible to assign some address os integer value " Option 2 this is some what tricky. Here A[2][3] becomes a 2D array if integer where A [2] means the 2nd integer in this array and A[2][3]o means 3rd integer in this row. eg. A [2] [3] = 5 means that at second row the third integer value is 5. Hence (*) Is correct option.
Question. 8

Let T (n) be the number of different binary search trees on n distinct elements. Then T [n] =
k=1

/ T (k 1) T (x), where x

is

(A) n k + 1 (C) n k 1
Page 6

(B) n k (D) n k 2

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

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.

Here the given expression. T (n) =


K=1

/T (k 1) T (X)

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) =
K=1

/T (X) T (k 1) / T (X) : [T (0) + T (1) + T (2) .....T (n 1)]


1 44444444 4 2 44444444 43
n

Expanding forT (k 1) we get T (n) =


K=1

no. of nodes in left subtree denoted by K Total nodes = n So remaining node n (k 1) i.e nodes in the right subtree. So = n k + 1 So overall we can say that the no. of different BSTs on n different elements. T (n) =
n=1

/T (n k + 1) T (k 1)

Hence ( ) is correct option.


Question. 9

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the inorder
Page 7

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 (C) 0 1 2 3 4 5 6 7 8 9 (B) 0 2 4 3 1 6 5 9 8 7 (D) 9 8 6 4 2 3 0 1 5 7

SOLUTION

We can solve it in shortcut that the first given element in 7, so we need to choose that particular option in which 7 is at the right place i.e. all the elements on its left should be smaller than it & all the elements on the right should be equal & greater than it. So this rule is followed in option C only. The method to make BST for given inputs is 7, 5, 1, 8, 3, 6, 0, 9, 4, 2.

Page 8

www.gatehelp.com

CS Topicwise 2001-2010 Programming & Data Structure

To make in order of a binary search tree. (i) Start with the root node. (ii) Scan its left subtree, (iii) If the node in subtree has any left child then store the node in stack & repeat this step for its left child unit no. left child of any node. (iv) If leaf reached then print the node & pop the stack, print the poped value. (v) Check its right subtree & repeat step (III) for it. (vi) When stack empty then stop So here inorder is 0 1 2 3 4 5 6 7 8 9. Actually a fact can be remembered that inorder traversal of a BST leads to a sorted sequence of elements. Hence (C) is correct option
Question. 10

A data structure is required for storing a set of integers such that each of the following operations can be done is (logn ) time, where n is the number of elements in the set. 1. Delection of the smallest element. 2. Insertion of an element if it is not already present in the set. Which of the following data structures can be used for this purpose ? (A) A heap can be used but not a balanced binary search tree (B) A balanced binary search tree can be used but not a heap (C) Both balanced binary search tree and heap can be used (D) Neither balanced binary search tree nor heap can be used
SOLUTION

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

Let S be a stack of size n $ 1. Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform n pop operations. Assume that Push and Pop operation take X seconds each , and Y seconds elapse between the end of the one such stack operation and the start of the next operation. For m $ 1, define the stack-life of mcs the time elapsed from the end or Push (m) to the start of the pop operation that removes m from S . The average stack-life of an element of this stack is (A) n (X + Y) (B) 3Y + 2X (C) n (X + Y) X
SOLUTION

(D) Y + 2X

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
of two) in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree

CS Topicwise 2001-2010 Programming & Data Structure

What is the result of inserting G in the above tree ?

(D) None of the above


SOLUTION

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.

Here in this node the no. of element >3. So we need a split or rotation.
Page 11

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.

Hence (C) is correct option.


Question. 13

In the following C program fragment, j, k, n and TwoLog_n are integer variables, and A is an array of integers. The variable n is initialized to an integer $ 3 , and TwoLog_n is initialized to the value of 2)6log 2 (n)@ for (k=3;k<=n;k++) A[k]=0; for (k=2;k<=TwoLog_n;k++) for (j=k+1;j<=n;j++) A[j]=A[j]<(j%k); for(j=3;j<=n;j++) if (!A[j])printf(%d,j); The set of number printed by this program fragment is (A) {m | m # n, (7i) [m = i!]} (B) {m | m # n, (7i) [m = i2]} (C) {m | m # n, m is prime}
SOLUTION

(D) {m | m # n, m is odd}

Question. 14

Consider the C program shown below. #include <stdio.h> #dene print(x)printf(%d,x) int x; void Q (int z){ z+=x; print(z); } void p (int)y){ int x=)y+2;
Page 12

www.gatehelp.com
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 (C) 14 6 6
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

(B) 22 12 11 (D) 7 6 6

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

Consider the function - defined below. struct item { int data; struct item)next; }; int f (struct item )p){ return ((p==NULL)||(p >next==NULL)|| ((p >data<=p >next >data)&& f(p >next))); } For a given linked list p, the function f return 1 if and only if (A) the list is empty or has exactly one element (B) the elements in the list are sorted in non-decreasing order of data value (C) the elements in the list are sorted in non-increasing order of data value (D) not all elements in the list have the same data value
SOLUTION

Here the return 1 any 1 of the following should be correct. (A) P == NULL i.e the list is empty (ends) (B) P " next = NULL i.e have one element. (C) P " data <= p " next " data i.e the element is smaller than its next element also. This is true for whole list. Since &&f(p "next) is also there. So overall it gives that the elements should be in sorted order. Hence (B) is correct option.
YEAR 2004 Question. 16

The goal of structured programming is to (A) have well indented programs (B) be able to infer the flow of control from the compiled code (C) be able to infer the flow of control form the program text (D) avoid the use of GOTO statements
Page 14

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

Structured programming :- It is way of programming using the sub structure method, i.e splitting the programs into sub sections. Structured programming prevents confusing transfer of control of avoiding the use of GOTO statements. Hence (D) is correct option.
Question. 17

Consider the following C function void swap {int temp a b } (int a, int b) temp; =a; =b; =temp;

In the order to exchange the values of two variables x and y . (A) call swap (x, y) (B) call swap (&x, &y) (C) swap (x, y) cannot be used as it does not return any value (D) swap (x, y) cannot be used as the parameters are passed by value
SOLUTION

Here the function takes the arguments by value. " Option (A) sends parameter by value but only the local variable a & b will be exchanged but not the actual variables x & y so incorrect. " Option (B) is incorrect sending address of x & y . " Option (C) swap (x, y) is usable there is no need to return. " Option (D) is the opposite statement of option (A), it says that the values are passed by value so wont swap so the option is correct. Hence (D) is correct option.
Question. 18

A single array A [1........MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top
Page 15

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

Let take maxsize =10

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 (C) 4 (B) 3 (D) 6

SOLUTION

Given are 10, 1, 3, 5, 15, 12, 16


Page 16

www.gatehelp.com

CS Topicwise 2001-2010 Programming & Data Structure

The height of the leaf node (5) is high 3. Hence (B) is correct option.
Question. 20

The best data structure to check whether an arithmetic expression has balanced parenthesis is a (A) queue (C) tree
SOLUTION

(B) stack (D) list

Balanced parenthesis in an equation are such that the no. of opening and closing parenthesis and in correct order should be there. We can check balancing using stack. When we get any opening parenthesis then we push that in the stack & if we get a closing one then we pop the stack. After the complete scanning of input string if stack is found empty then the arithmetic expression is balanced.
Page 17

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
Hence (B) is correct option.
Question. 21

Consider the following C function int f(int n) {static int i=1; if (n>=5) return n; n=n+i; i++; return f(n); } The value returned by f(1) is (A) 5 (C) 7
SOLUTION

(B) 6 (D) 8

Here i is an static variable, so if it is once initialized it cant be initialized again during its scope n is incremented by 1 & f(n) is called then. The final return is when n>=5 i.e. n returned then Step Call n i (1) 1 1 1 condition false n < 5 (2) 2 1+1 = 2 (3) 2 2 2 false n < 5 (4) 3 2+2 = 4 (5) 3 4 3 false n < 5 (6) 4 4+3 = 7 (7) 4 7 4 true return n = 7 So return value is 7. Hence (C) is correct option.
Question. 22

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = d1 d2 .......dm. int n, rev; rev=0; while(n>0){ rev=rev)10+n%10;
Page 18

www.gatehelp.com
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

CS Topicwise 2001-2010 Programming & Data Structure

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

Consider the following C program segment: char p[20]; char)s= string; int length=strlen(s); for (i=0;i<length; i++) p[i]=s[length i]; printf(% s, p); The output of the program is (A) gnirts (C) gnirt
SOLUTION

(B) string (D) no output is printed

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

A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time ?

(A) rear node (B) front node (C) not possible with a single pointer (D) node next to front
SOLUTION

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
Question. 25

CS Topicwise 2001-2010 Programming & Data Structure

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

Given elements are 32, 15, 20, 30, 12, 25, 16

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.

So option (A) is correct since it satisfy max heap property. Hence (A) is correct option.
Page 21

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
Question. 26

Assume that the operators + , - , # are left associative and ^ is right associative .The order of precedence (from highest to lowest) is ^, # , + , -. The postfix expression corresponding to the infix expression a + b # c - d ^ e ^ f is (A) abc #+ def ^^ (B) abc #+ de^f^ (C) ab+c#de^f^
SOLUTION

(D) + a#bc^^def

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

Consider the following C program main () { int x, y, m, n; scanf(%d%d, &x,&y); /)Assume x>0 and y>0)/ m=x; n=y; while (m!=n) { if (m>n) m=mn; else n=nm; } printf(%d,n); } The program computers (A) x ' y, using repeated subtraction (B) x mod y using repeated subtraction (C) the greatest common divisor of x and y
Page 22

www.gatehelp.com
(D) the least common multiple of x only
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

Here if m > n then m = m n m < n then n = n m Let take X = 24 Y = 9 Then m = 24 n = 9 iteration m n 1 9 24 9 = 15 2 9 15 9 = 6 3 6 96 = 3 4 3 63 = 3 Here m = n so n returned Which is GCD (Greatest common divisor) of X & Y Hence (C) is correct option.
Question. 28

What does the following algorithm approximate ? (Assume m>1, !> 0 ). x=m; y=1; while (xy>!) { x=(x+y)/2; y=m/x; } print (x); (A) log m (C) m1/2
SOLUTION

(B) m2 (D) m1/3

Here we take let x = 16 Loop will stop when x y = 0 or >0 Iteration 1 X (16 + 1) =8 2 Y 16 = 2 8
Page 23

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
2 3 8+2 = 5 2 5+3 = 4 2 16 = 3 5 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

Consider the following C program segment struct Cellnode { )leftChild; struct CellNode int element; )rightChild; struct CellNode } int DoSomething (struct CellNode )ptr) { int value=0; if(ptr!=NULL) { if (ptr >leftChild !=NULL) value=1+DoSomething (ptr >leftChild); if (ptr >rightChild!=NULL) value=max(value,1+DoSomething(ptr > right child)); return (value); } The value returned by the function DoSomething when a pointer to the proof of a non-empty tree is passed as argument is (A) The number of leaf nodes in the tree (B) The number of nodes in the tree (C) The number of internal nodes in the tree (D) The height of the tree.
SOLUTION

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
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

CS Topicwise 2001-2010 Programming & Data Structure

Choose the best matching between the programming styles in Group 1 and their characteristics in Group 2. Group-I P. Functional Q. Logic R. Object-oriented S. Imperative Group-2 1. Command-based, procedural 2. Imperative, abstract data types 3. Side-effect free, declarative, expression evaluation 4. Declarative, clausal representation, theorem proving (B) P-4, Q-3, R-2, S-1 (D) P-3, Q-4, R-2, S-1

(A) P-2, Q-3, R-4, S-1 (C) P-3, Q-4, R-1, S-2
SOLUTION

p. q r. s

Functional Programming is declarative in nature, involves expression evaluation, & side effect free. Logic is also declarative but involves theorem proving. Object oriented is imperative statement based & have abstract (general) data types. Imperative :- The programs are made giving commands & follows definite procedure & sequence.

Hence (D) is correct option.

YEAR 2005 Question. 31

What does the following C-statement declare? int 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

Given statement int () f) (int )) This is not the declaration of any function since the f has ) (pointer symbol) before it. So f is a pointer to a function also the argument type is ) & the return type is So overall we can say that f is a pointer to a function that takes an integer pointer as argument and returns an integer. Hence (C) is correct option.
Question. 32

An Abstract Data type (ADT) is (A) same as an abstract class (B) a data type that cannot be instantiated (C) a data type for which only the operations defined on it can be used, but none else (D) all of the above
SOLUTION

Abstract Data type :- It is defined as a user defined data type, specified by keyword abstract & defines the variables & functions, these operations can only use the variables of this data type. So option (C) which says that Abstract data type for which only operations defined on it can be used is correct. Eg. stack data type Here operations defined are push & pop. So we can apply only these 2 operations on it. Hence (C) is correct option.
Page 26

www.gatehelp.com
Question. 33

CS Topicwise 2001-2010 Programming & Data Structure

A common property of logic programming languages and functional languages is (A) both are procedural language (B) both are based on calculus (C) both are declarative (D) all of the above
SOLUTION

-calculus" It provides the semantics for computation with functions so that properties of functional computation can be studied. Both the languages require declaration before use of any object. Both are procedural So option (D) is correct. Both the languages are based on calculus, procedural & declarative Hence (D) is correct option.
Question. 34

Which of the following are essential features of an object-oriented programming languages? 1. 2. 3. 4. (A) Abstraction and encapsulation Strictly-typedness Type-safe property coupled with sub-type rule Polymorphism in the presence of inheritance 1 and 2 only (B) 1 and 4 only (D) 1, 3 and 4 only

(C) 1, 2 and 4 only


SOLUTION

Object oriented programming languages necessarily have features like. Abstraction Encapsulation, inheritance with polymorphism but OOPL are also strongly-typed since there are restrictions on how operations involving values having different data types can be intermixed. Eg. two integers can be divided but one integer & one string cant. Hence (B) is correct option.
Page 27

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
Question. 35

A program P reads in 500 integers in the range (0, 100) representing the scores of 500 students. It then prints the frequency of each score above 50. What be the best way for P to store the frequencies? (A) An array of 50 numbers (B) An array of 100 numbers (C) An array of 500 numbers (D) A dynamically allocated array of 550 numbers
SOLUTION

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

Consider the following C-program void foo(int n, int sum ){ int , if (n ) return; n ; n ; sum = sum ; foo ( , sum); printf(%d, ); } int main(){ int a = , sum = 0; foo (a, sum); printf (%d n ,sum); } What does the above program print? (A) 8, 4,0, 2, 14 (C) 2, 0, 4, 8, 14
Page 28

(B) 8, 4, 0, 2, 0 (D) 2, 0, 4, 8, 0

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

Here K = n%10 takes unit digit of n j = n/10 reduces 1 digit from n . Recurssion n 1 2 3 4 5 2048 204 20 2 0 Local Sum Print 0 8 12 12 14 -8 -4 - print 0 - print 2 " return 204 20 2 0 8 4 0 2

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

Consider the following C-program double foo (double); /* Line 1*/ int main(){ double da db; // input da db foo (da); } double foo(double a){ return a; } The above code complied without any error or warning. If Line 1 is deleted, the above code will show (A) no compile warning or error (B) some complier-warning not leading to unitended results (C) Some complier-warning due to type-mismatch eventually leading to unitended results (D) Complier errors
Page 29

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
SOLUTION

Here if line 1 which is prototype declaration of the function foo, in C compilation process this would give an compile warning , due to type-mismatch. Since then compiler wont know what is the return type of foo. So unintended results may occur. Hence (C) is correct option.
Question. 38

Postorder traversal of a given binary search tree, T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an inorder traversal of the tree T? (A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 (B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29 (C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95 (D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 0, 15, 29
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

An implementation of a queue Q, using two stacks S1 and S2 , is given below void insert(Q,x){ push (S1,x); } void delete(Q, x){ if (stack-empty (S2))then
Page 30

www.gatehelp.com
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

CS Topicwise 2001-2010 Programming & Data Structure

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

While loop will terminate i $ n & j $ m program is to merge a & b arrays into C . While loop terminates after merging then either (I) or (II) should hold but not both at the same time. (I) says j < m & (II) say j = m vice versa Hence (C) is correct option.
Question. 41

Consider these two functions and two statements S1 and S2 about them. int work1(int *a,int i,int j) int work2(int *a,int i,int j) { { int t1=i+2; int a i int t2=a[t1]; a j 1 return a i a[j]=t2+1 return t2-3; } }

S1:

The transformation from work 1 to work 2 is valid, i.e., for any program state and input arguments, work 2 will compute the same output and have the same effect on program state as work 1 S2: All the transformations applied to work 1 to get work 2 will always improve the performance (i.e. reduce CPU time) of work 2 compared to work 1 (A) S1 is false and S2 is false (B) S1 is false and S2 is true (C) S1 is true and S2 is false (D) S1 is true and S2 is true
SOLUTION

During the optimizations of code phase variables are reduced to temporary variables which are used to store results of unitary
Page 32

www.gatehelp.com
operations so later if this expression again evaluated then in optimized code it is replaced by temporary variable. Both work 1 & work 2 produces same state & since operation i + 2 in work 1 is performed only 1 time in work 2 due to use of t so it is also optimized. So both are true. Hence (D) is correct option.
Question. 42

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= px py; py=)px+)py; )px=)py )px;
) ) ) ) )

px,int

py){

} S1 : S2 : S3 : will generate a compilation error may generate a segmentation fault at runtime depending on the arguments passed correctly implements the swap procedure for all input pointers referreing to integers stored in memory locations accessible tot he process implements the swap procedure correctly for some but not all valid input pointers may add or subtract integers and pointers (B) S2 and S 3 S1 (D) S2 and S5

S4 : S5 : (A)

(C) S2 and S 4
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

Which one of the following is a valid sequence of elements in an array representing 2-ary max heap ? (A) 1, 3, 5, 6, 8, 9 (B) 9, 6, 3, 1, 8, 5 (C) 9, 3, 6, 8, 5, 1
SOLUTION

(D) 9, 5, 6, 8, 3, 1

Create max heap for options.

Here in option (A), (B) and (C), value present at node is not greater
Page 34

www.gatehelp.com
then all its children. Hence (D) is correct option.
Question. 44

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

Given heap is as follows

To add 7, 2, 10, 4 we add the node at the end of array

We keep if at right place in the heap tree. Compare elements with its parent node. Since 10 > 6 and 7 >5, we interchange
Page 35

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com

Since 10 >9, we interchange and we get

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

Consider the following segment of C-code int, , n while


Page 36

www.gatehelp.com

CS Topicwise 2001-2010 Programming & Data Structure

The number of comparisons made in the execution of the loop for any n > 0 is (A) [log2 n] + 1 (C) [log2 n]
SOLUTION

(B) n (D) 6log2 n @ + 1

Iteration Initially 0 1 2 3 Here condition is 2i <


th

j 1=2
0

Comparison

2 = 21 4 = 22 8 = 23 =n

In i iteration & it requires i + 1 comparisons. i + 1 = ^log 2 nh + 1 Hence (A) is correct option.


Question. 46

i = log 2 n

The following postfix expression with single digit operands in evaluated using a stack / Note that^is the exponentiation operator. The top two elements of the stack after the first* is evaluated are (A) 6, 1 (C) 3, 2
SOLUTION

(B) 5, 7 (D) 1, 5

Given postfix expression is 823 / /23 ) + 51 ) Scanning the string from left to right we push all the digits, & we get any operator we evaluate the operation between top 2 elements poped from stack. Then the result is pushed again into stack.
Page 37

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com

Stack contain 5, 7 Hence (B) is correct option.


Question. 47

Consider the following C function: int f(int n) static int r=0; if (n = 0) return 1; if (n ) {r = n; return f (n ) ; } return f (n 1) r; } What is the value of f(5) ? (A) 5 (C) 9
SOLUTION

(B) 7 (D) 18

Given f (5) = ? Recursion 1


Page 38

n 5

r 0"5

Return f (3) + 2

Final Return 16 + 2 = 18

www.gatehelp.com

CS Topicwise 2001-2010 Programming & Data Structure

Here r is a static int, so it will not be initialized again during recursive calls so the final return would be option (D) i.e. 18 Hence (D) is correct option.
Question. 48

Consider the following C program segment where Cell Node represents a node in a binary tree struct CellNode { struct CellNode*leftchild; int element; struct CellNode*rightchild; }; int GetValue(struct CellNode * ptr) { int vlaue = 0; if (ptr =NULL) { if ((ptr leftChild = = NULL)&& rightChild = = NULL)) (ptr Value = 1; else value = value + GetValue leftChild) (ptr + Get Value (ptr rightChild); } return(value); } The value returned by Get Value when a pointer to the root of a binary tree is passed as its argument is (A) the number of nodes (B) the number of internal nodes in the tree (C) the number of leaf nodes in the tree
Page 39

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

Which combination of the integer variables x, y, and z makes the variable a get the value 4 in the following expression? a = (x > y) ? ((x > z) ?x : z): ((y > z) ?y: z) (A) x = 3, y = 4, z = 2 (C) x = 6, y = 3, z = 5
SOLUTION

(B) x = 6, y = 5, z = 3 (D) x = 5, y = 4, z = 5

a = (x > y) ? ((x > z) ?x : z): ((y > z) ?y: z) Expr 1? expr 2 : expr 3 ; Here Expr 1 is a comparison expression whose result may be true or false. If true returned the expr 2 is selected as choice otherwise expr3. Here we want 4 to be printed which is only in option (A) & (D) for y = 4 to be printed. x > y should be false since y is in true part so this expr should be true. So both the conditions are true in option (A) only so correct. We can check. x=3y=4 z=2 a = (x > y) ? ((x > z) ?x: z) ((y > z) ?y: z) First we can check 3 > 2 ? 3 : 2 thus 3 is selected Then 4 > 2 ? 4 : 2 here 4 is selected Hence a = 3 > 4?3: 4 = 4 Hence (A) is correct option.
Page 40

www.gatehelp.com
Question. 50

CS Topicwise 2001-2010 Programming & Data Structure

What is printed by the following C program? int f(int x, int *py, int **ppz) void main() { { int , * , ** a int y, z a ** ppz z * ppz printf (" d", f ( , , a)) *py y * py x return x y z (A) 18 (B) 19 (C) 21
SOLUTION

(D) 22

Here C is an integer variable, b has the address of C and a is double pointer i.e it contains address of pointer b.

Let

c=4c b a Call f (4, 1000, 2000) ppz (1)

=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.
Question. 51

Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input
Page 41

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

The following C function takes a singly-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1,2,3,4,5,6,7 in the given order. What will be the contents of the list after the function completes execution? struct node { int value; struct node *next; } ;
Page 42

www.gatehelp.com
void rearrange (struct node *list) { struct node * * int temp; if (! list || ! list >next) return; list; list > next; p while ( ) { temp=p > value;p >value = > value; > next; > value = temp ; p = = p p > next : 0 ; } } (A) 1,2,3,4,5,6,7 (C) 1,3,2,5,4,7,6
SOLUTION

CS Topicwise 2001-2010 Programming & Data Structure

(B) 2,1,4,3,6,5,7 (D) 2,3,4,5,6,7,1

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

Consider the program below: #include<stdio.h> int fun(int n, int *f_p){ int t,f; if (n<=1){ *f_p=1 return 1; } t=fun(n-1,f_p); f=t+*f_p; *f_p=t; return f; } int main () { int x=15;
Page 43

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
printf(%d\n,fun(5,&x)); return 0; } The value printed is: (A) 6 (C) 14
SOLUTION

(B) 8 (D) 15

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

What is the maximum height of any AVL-tree with 7 nodes ? Assume that the height of a tree with a single node is 0. (A) 2 (C) 4
SOLUTION

(B) 3 (D) 5

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

Here the weight is 2, so AVL tree require rotation.

This is balanced.

In this tree the height is 3 and it is Also AVL balanced so maximum height will be 3

Hence (B) is correct option.

Statement for Linked Answer Question 55 & 56


Consider a binary max-heap implemented using an array
Question. 55

Which one of the follow9ng array represents a binary max-heap? (A) {25, 12, 16, 13, 10, 8, 14} (B) {25, 14, 13, 16, 10, 8, 12} (C) {25, 14, 16, 13, 10, 8, 12} (D) {25, 14, 12, 13, 10, 8, 16}
SOLUTION

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

Hence (C) is correct option.

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} (C) {14, 13, 8, 12, 10} (B) {14, 12, 13, 8, 10} (D) {14, 13, 12, 8, 10}

SOLUTION

Given Max heap

Page 46

www.gatehelp.com

CS Topicwise 2001-2010 Programming & Data Structure

So array contents are 14 13 12 8 10 Hence (D) is correct option.


YEAR 2010 Question. 57

The cyclomatic complexity of each of the modules A and B shown below is 10. What is the cyclomatic complexity of the sequential integration shown on the right hand side ?

(A) 19 (C) 20
SOLUTION

(B) 21 (D) 10

Cyclomatic complexity is defined as the no. of independent paths form begin to exit in a module. If some dependent sub modules are there in the module then the individual cyclomatic complexities are added & overall sum is reduced by 1.
Page 47

CS Topicwise 2001-2010 Programming & Data Structure

www.gatehelp.com
Here So CC (complete) = CC (A) + CC (B) 1 10 + 10 1 = 19

Hence (A) is correct option.


Question. 58

What does the following program print ? #include<stdio.h> void f(int *p, int *q){ p=q
)

} int i=0,j=1; int main(){ f(&i,&j); printf(%d%d\n,i,j); return 0; } (A) 22 (C) 01 (B) 21 (D) 02

SOLUTION

Here in the function p & q are integer pointer and p = q statement means now p contains the same address as contained by p*p=2 means now both locations contain 2. Since p & q both contain same location so value of *p & *q is 2. But the address i hasnt be modified so value of i is not changed. It is a & j has been changed to 2. Hence (D) is correct option.
Question. 59

What is the appropriate paring of items in the two columns listing various activities encountered in a software life cycle ?
Page 48

www.gatehelp.com
P. Requirement Capture Q. Design R. Implementation S. Maintenance 1. 2. 3. 4. Module Development Integration Domain Analysis Structural and Behavioral Modeling Performance Tuning and

CS Topicwise 2001-2010 Programming & Data Structure

(A) P-3 Q-2, R-4 S-1 (C) P-3 Q-2 R-1 S-4
SOLUTION

(B) P-2 Q-3 R-1 S-4 (D) P-2 Q-3 R-4 S-1

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 Design : Knowing the problem a systematic structure of the problem solution is designed and the behavior modelling refers to the functions of the module, which give certain output providing definite inputs. Implementation : After knowing behavior the modules are developed, converting the logics in the programming logics. The independent modules are then integrated. Maintenance : Successful implementation done but even then the performance might not optimal so some features or methods need to be change to tune the performance.

Hence (B) is correct option.


Question. 60

What is the value printed by the following C program ? #include<stdio.h> int f(int *a, int n) { if (n<=0) return 0; else if (*a%2==0) return *a+f(a+1,n-1); else return *a-f(a+1,n-1); }
Page 49

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
SOLUTION

(D) 19

Hence finally 15 will be returned. Hence () is correct option.


Question. 61

The following C function takes a singly-linked list as input argument. It modified the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank. typedef struct node { int value; struct node *next } Node; Node )mode_to_front(Node *head){ Node)p,) ; if((head==NULL)<(head->next==NULL))return head; q=NULL;p=head;
Page 50

www.gatehelp.com
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

CS Topicwise 2001-2010 Programming & Data Structure

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

The following program is to be tested for statement coverage : begin if(a==b){S1;exit} else if(c==d){S2;} else {S3;exit;} S4; end The test cases T1, T2, T3, and T4 given below are expressed in terms of the properties satisfied by the values of variables a b c and d . The exact values are not given. T1 : a b c and d are all equal
Page 51

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 (C) T3, T4
SOLUTION

(B) T2, T4 (D) T1, T2, T4

The following test cases covers statements. all are equal T1 : S1 executed and then so no other execution. all are distinct T2 : Only S 3 executed T3 : a =b & c!=d Only S1 executed !=b & c=d T4 : Only S2, S 4 only So to have all statements the option should be either T1, T2, T4 or T2, T3, T4 Option (D) is T1, T2, T4 Hence (D) is correct option.

Statement for Linked Answer Questions 63 & 64


A has table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty has table, the table is as shown below.
0 1 2 3 4 5 6 7
Page 52

42 23 34 52 46 33

www.gatehelp.com
8 9

CS Topicwise 2001-2010 Programming & Data Structure

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 (C) 46, 34, 42, 23, 52, 33
SOLUTION

(B) 34, 42, 23, 52, 33, 46 (D) 42, 46, 33, 23, 34, 52

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 (C) 30
SOLUTION

(B) 20 (D) 40

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

By NODIA and Company


Available in Two Volumes

www.gatehelp.com

GATE CS Topic wise Questions Theory of Computation

YEAR 2001 Question. 1

Consider the following two statements : S1 : {02n n $ 1 } is a regular language S2 : {0m 1n 0m + n m $ 1 and n $ 1 } is a regular language Which of the following statements is incorrect ? (A) Only S1 is correct (B) Only S2 is correct (C) BothS1 and S2 are correct (D) None of S1 and S2 is correct.
SOLUTION

S1 can be represented using a DFA so it is regular S1 is correct. S2 cant be represented by DFA but it requires PDA to accept. So is S2 is CFG not regular. S2 is false. Hence (A) is correct option.
Question. 2

Which of the following statements true ? (A) If a language is context free it can be always be accepted by a deterministic push-down automaton. (B) The union of two context free language is context free. (C) The intersection of two context free language is context free

CS Topicwise 2001-2010 Theory of Computation

www.gatehelp.com
(D) The complement of a context free language is context free
SOLUTION

(A) It is not necessary at all. (B) {an bn} , {an bn cn} = {an bn cn} always true so correct. (C) {an bn} + {an} = {an} not CFG so false. (D) Not necessary. Hence (B) is correct option
Question. 3

Given an arbitary non-deterministic finite automaton (NFA) with N states, the maximum number of states in an equivalent minimized DFA is at least. (B) 2N (A) N2 (C) 2N
SOLUTION

(D) N!

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

Consider a DFA over = {a, b} accepting all strings which have number of a's divisible by 6 and number of b's divisible by 8. What is the minimum number of states that the DFA will have ? (A) 8 (B) 14 (C) 15
SOLUTION

(D) 48

The valid strings will be where no. of a's 6, 12, 18, 24 No. of b's = 8, 16, 24

Page 2

www.gatehelp.com
No. of states = 7 for a

CS Topicwise 2001-2010 Theory of Computation

No. of states = 9 Total 9 + 7 1 = 15

1 subtracted due to 2 final states. Hence (C) is correct option.


Question. 5

Consider the following languages : L1 = {ww w ! {a, b} )} L2 = {wwR w ! {a, b})wR is the reverse of w} L3 = {02i i is an integer} 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
SOLUTION
2

(D) Only L3

L1 would be accepted by PDA so cant be regular. L2 similarly cant be accepted by DFA so not regular. L 3 & L 4 both require only finite no of zeros. So both regular. Hence (C) is correct option.
Question. 6

Consider the following problem x . Given a Turing machine M over the input alphabet , any state q of M . And a word w ! ) does the computation of M on w visit the state
Page 3

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

Since it is possible to create a turing machine for the problem, 20 this problem is decidable. Hence (A) is correct option.
YEAR 2002 Question. 7

The smallest finite automaton which accepts the language { x length of x is divisible by 3} has (A) 2 states (C) 4 states
SOLUTION

(B) 3 states (D) 5 states

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

Which of the following is true ? (A) The complement of a recursive language is recursive. (B) The complement of a recursively enumerable language is
Page 4

www.gatehelp.com
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

CS Topicwise 2001-2010 Theory of Computation

A recursive language has complement & its complement is also recursive. Whereas complement of others is not recursive. Hence (A) is correct option.
Question. 9

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

C language is context free language entirely based upon the productions. Hence (A) is correct option.
Question. 10

The language accepted by a Pushdown Automaton in which the stack is limited to 10 items is best described as (A) Context free (C) Deterministic Context free
SOLUTION

(B) Regular (D) Recursive

Pushdown Automaton uses stock as data structure & languages accepted by PDA is regular. Hence (B) is correct option.
Page 5

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

A problem is said to be NP - complete, if it is both NP & NP hard. 3-SAT problem is NP complete so a reduction of 3-SAT problem to & to 30-SAT. So this infers that is NP complete, since it is reducible to a NP complete problem. Hence (C) is correct option
Question. 12

Nobody knows yet if P = NP . Consider the language L defined as follows (0 + 1)* if P = NP L=* othervise Which of the following statements is true? (A) L is recursive (B) L is recursively enumerable but not recu (C) L is not recursively enumerable (D) Whether L is recursive or not will be known after we find out if P = NP
SOLUTION

A language L is said to be recursive if there exists any rule to determine whether an element belong to language or not, if language
Page 6

www.gatehelp.com
can be accepted by turning machine. So there exist the rules so L is recursive. Hence (A) is correct option.
Question. 13

CS Topicwise 2001-2010 Theory of Computation

The regular expression 0 *( 10)* denotes the same set as (A) (1 * 0) * 1 * (B) 0 + (0 + 10) * (C) (0 + 1) * 10 (0 + 1) *
SOLUTION

(D) None of the above

Question. 14

If the strings of a language L can be effectively enumerated in lexicographic (i.e. alphabetic) order, which of the following statements is true? (A) L is necessarily finite (B) L is regular but not necessarily finite (C) L is context free but not necessarily regular (D) L is recursive but not necessarily context free
SOLUTION

Since L can be effectively enumerated so L has to be regular, but is doesnt mean that the decisions are finite. Hence (B) is correct option.
Question. 15

Consider the following deterministic finite state automaton M .

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 (C) 7
SOLUTION

(B) 5 (D) 8

The strings accepted by the given automata are of type. 1234567 Option 1 1 1 These four blank spaces can have 0 or 1, so total 2 4 = 6 strings are possible, but the given automata does not accept all of those. 1. 1 1 1 1 0 0 1 2. 1 1 0 1 0 0 1 3. 1 0 1 1 0 0 1 4. 1 0 0 1 0 0 1 5. 1 0 0 1 0 0 1 6. 1 0 0 1 1 0 1 7. 1 0 0 1 1 1 1 Hence (C) is correct option.
Question. 8

Let G = ({S},{ a, b} R, S be a context free grammar where the rule set R is S " a S b|S S| Which of the following statements is true? (A) G is not ambiguous (B) There exist x, y, ! L (G) such that xy z L (G) (C) There is a deterministic pushdown automaton that accepts L (G) (D) We can find a deterministic finite state automaton that accepts L (G)
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
(D) The language is not regular so DFA is not possible. Hence (C) is correct option.
Question. 9

CS Topicwise 2001-2010 Theory of Computation

Consider two languages L1 and L2 each on the alphabet /. Let f: / " / be a polynomial time computable bijection such that (6x [x ! L1 iff f (x) ! L2]. Further, let f1 be also polynomial time commutable. Which of the following CANNOT be true? (A) L1 ! P and L2 finite (B) L1 ! NP and L2 ! P (C) L1 is undecidable and L2 is decidable (D) L1 is recursively enumerable and L2 is recursive
SOLUTION

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

A single tape Turing Machine M has two states q0 and q1 , of which q0 is the starting state. The tape alphabet of M is {0,1,B} and its input alphabet is {0,1}. The symbol B is the blank symbol used to indicate end of an input string. The transition function of M is described in the following table 0 q0 q1 q1, 1, R q1, 1, R 1 Q1, 1, R q0, 1, L B Halt qH0, B, L

The table is interpreted as illustrated below. The entry (q1, 1, R ) in row q0 and column 1 signifies that if M is in state q0 and reads 1 on the current tape square, then it writes 1 on the same tape square, moves its tape head one position to the right and
Page 9

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

This turning machine starts at 90 if it doesnt get any input symbol but B then it halts. So if (00 + 1)) is chosen then the M/C can halt. Option (B) is wrong. Option (C) & (D) are possible but not necessary. Option (A) (0 + 1)), 1 or more occurrence of 0 or 1. So 0, 1, 00, 01, 10, 11........are valid strings & the machine doesnt halt for them. Hence (A) is correct option.
Question. 11

Define languages L0 and L1 as follows L0 = {< M, w, 0 > | M halts on w} L0 = {< M, w, 1 > | M does not halts on w} Here< M, w, i > is a triplet, whose first component. M is an encoding of a Turing Machine, second component,w , is a string, and third component, t , is a bit. Let L = L0 , L1 . Which of the following is true? (A) L is recursively enumerable, but L is not (B) L is recursively enumerable, but L is not (C) Both L and L are recursive (D) Neither L nor L is recursively enumerable
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
So a L = L 0 , L , it is not. RE Hence (B) is correct option.
Question. 12

CS Topicwise 2001-2010 Theory of Computation

Consider the NFAM shown below.

Let the language accepted by M be L. Let L1 be the language accepted by the NFAM1 , obtained by changing the accepting state of M to a non-accepting state and by changing the non-accepting state of M to accepting states. Which of the following statements is true? (A) L1 = {0, 1}* L (C) L1 3 L
SOLUTION

(B) L1 = {0, 1}* (D) L1 = L

L is accepted by M (NFA) but NFA M 1 has

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 problems 3-SAT and 2-SAT are (A) both in P (B) both NP-complete (C) NP-complete and in P respectively (D) undecidable and NP-complete respectively
SOLUTION

3 SAT problem is both NP & NP hard so it is NP complete, but 2 SAT problem is solvable in Polynomial time so it is in class P . Hence (C) is correct option.
Question. 14

The following finite state machine accepts all those binary strings in which the number of 1s and 0s are respectively

(A) divisible by 3 and 2 (C) even and odd


SOLUTION

(B) odd and even (D) divisible by 2 and 3

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

The language {am bm + n | m, n # 1} is


Page 12

www.gatehelp.com
(A) regular (B) context-free but not regular (C) context sensitive but not context free (D) type-0 but not context sensitive
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

Language {an bn cm + n /m, n $ 1} is a context free language since it can be represented by pushdown automata, but it is not regular since FA cant count the no. of as & bs and then check the sum for occurrence of c . Hence (B) is correct option.
Question. 16

Consider the flowing grammar C S " bS | aA | b A " bA | aB B " bB | aS | a Let Na (W) and Nb (W) denote the number of as and bs in a string W respectively. The language L (G) 3 {a, b} + generated by G is (A) {W | Na (W) > 3Nb (W)} (B) {W | Nb (W) > 3Na (W)} (C) {W | Na (W) = 3k, k ! {0,1,2,...}} (D) {W | Nb (W) = 3k, k ! {0,1,2,...}}
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. S " bA " abA " abbA " abbaB " abbaa abbaB " abbaaS " abbaab

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

L1 is a recursively enumerable language over /. An algorithm A effectively enumerates its words as w1, w2, w3,.... Define another language L2 over / j {#} as {wi #wj : wi, wj ! L1, i < j}. Here # is a new symbol. Consider the following assertion. S1: L1 is recursive implies L2 is recursive S2: L2 is recursive implies L1 is recursive Which of the following statements is true? (A) Both S1 and S2 are true (B) S1 is true but S2 is not necessarily true (C) S2 is true but S1 ins necessarily true (D) Neither is necessarily true
SOLUTION

Problem can be solved using membership algorithm. If L1 is recursive & wi ! L1 & w j ! L1 then we can check. Whether i < j , so here wi Dw j ! L2 but if wi b L1 also w j b L2 or i $ j then wi Dw j b L2 So L2 is also recursive & S1 is true. L2 is recursive said by S2 but membership algorithm cant be applied here since L1 doesnt has 'D' symbol. So S2 is not necessarily true. Hence (B) is correct option.
YEAR 2005

Question. 18

Consider three decision problem P1, P2 and P3 . It is known that P1 is decidable and P2 is undecidable. Which one of the following is TRUE? (A) P3 is decidable if P1 is reducible to P3 (B) P3 is undecidable if P3 is reducible to P2 (C) PL3 is undecidable if P2 is reducible to P3 (D) P3 is decidable if P3 is reducible to P2 s complement
Page 14

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

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

Consider the machine M

The language recognized by M is (A) {W ! {a, b}*/ every a in w is followed by exactly two b's} (B) {W ! {a, b}*/ every a in w is followed by at least two b's} (C) {W ! {a, b}*/ w contains the substring abb (D) {W ! {a, b}*/ w does not contain aa as a substring}
SOLUTION

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 (C) Df = Nf and DP = NP
SOLUTION

(B) Df 1 Nf and DP = NP (D) Df = Nf and DP 1 NP

N f " languages accepted by NDFA N p " accepted by NDPDA D f " deterministic FA D p " deterministic PDA DFA & NDFA both can accept all the regular languages, the difference is in no. of states. So Df = Nf But NPDA accepts only a subset of context free languages which are deterministic, whereas NDPDA accept all the context free languages. So Dp 1 Np Hence (D) is correct option.
Question. 21

Consider the languages L1 + {an bn cm | n, m > 0} and L2 = {an bm cm | n, m > 0} (A) L1 + L2 is a context-free language (B) L1 , L2 is a context-free language (C) L1 and L2 are context-free language (D) L1 + L2 is a context sensitive language
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

Let L1 be a recursive language, and let L2 be a recursively enumerable but not a recursive language. Which one of the following is TRUE?
Page 16

www.gatehelp.com
(A) L1 is recursive and L2 is recursively enumerable (B) L1 is recursive and L2 is not recursively enumerable (C) L1 and L2 are recursively enumerable (D) L1 is recursively enumerable and L2 is recursive
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

The rules here used will be. All those languages which are recursive their complements are also recursive. So option (A) & (B) can be correct. Now languages which are recursively enumerable but not recursive, their complements cant be recursively enumerable. So only option (B) is correct Hence (B) is correct option
Question. 23

Consider the languages L1 = {WWR | W ! {0, 1}*} L2 = {W#WR | W ! {0, 1}*} , where # is a special symbol L3 = {WW | W ! {0, 1}*} Which one of the following is TRUE? (A) L1 is a deterministic CFL (B) L2 is a deterministic CFL (C) L3 is a CFL , but not a deterministic CFL (D) L3 is a deterministic CFL
SOLUTION

In all the options there is linear relationship among strings so all CFL's , but L1 & L 3 can be accepted by PDA , L2 can be accepted by deterministic CFL due to presence of special symbol D which tells the middle of the string, so deterministic. Hence (B) is correct option.
Question. 24

Consider the following two problems on undirected graphs


Page 17

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

Let S be an NP -complete problem Q and R be two other problems not known to be in NP . Q is polynomial-time reducible to S and S is polynomial-time reducible to R . Which one of the following statements is true? (A) R is NP -complete (C) Q is NP -complete
SOLUTION

(B) R is NP -hard (D) Q is NP -hard

S is NP complete and a NP complete problem is reducible to some unknown problem then that problem is also NP complete. So S " p R the R is NP complete. Hence (A) is correct option.
Question. 26

Let L1 = {0n + m 1n 0m | n, m # 0}, L2 = {0n + m 1n + m 0m | n, m # 0}, and L3 = {0n + m 1n + m 0n + m | n, m # 0}. Which of these languages are NOT context free? (A) L1 only (C) L1 and L2 (B) L3 only (D) L2 and L3

Page 18

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

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

If s is a string over (0+1)*, then let n0 (s) denote the number of 0s in s and n1 (s) the number of 1s in s . Which one of the following languages is not regular? (A) L = {s ! (0 + 1)*| n0 (s) is a 3-digit prime} (B) L = {s ! (0 + 1)*| for every prefixes of s,| n0 (s') n1 (s')| # 2} (C) L = {s ! (0 + 1)*|| n0 (s) n1 (s) # 4 (D) L = {s ! (0 + 1)*| n0 (s) mod 7=n1 (s) mod5 = 0 }
SOLUTION

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) L is 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

Let SHAM, be the problem of finding a Hamiltonian cycle in a graph G + (V, E) with [V] divisible by 3 and DHAM be the problem of determining if a Hamltonian cycle exists in such graphs. Which one of the following is true? (A) Both DHAM, and SHAM, are NP-hard (B) SHAM, is NP-hard, but DHAM, is not (C) DHAM, is NP-hard, but SHAM, is not (D) Neither DHAM,nor SHAM, is NP-hard
SOLUTION

Question. 30

Consider the following statements about the context-free grammar, G = {S " SS, S " ab, S " ba, S "!} 1. G is ambiguous. 2. 3. G produces all strings with equal number of as and bs . G can be accepted by a deterministic PDA .

Which combination below expresses all the true statements about G ? (A) 1 only (B) 1 and 3 only (C) 2 and 3 only
SOLUTION

(D) 1, 2 and 3

Due to S " SS this Grammar is ambiguous right hand side has two Non terminals.
Page 20

www.gatehelp.com
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

CS Topicwise 2001-2010 Theory of Computation

Let L1 be regular language, L2 be a deterministic context-free language and L3 a recursively enumerable, but not recursive, language. Which one of the following statements is false? (A) L1 + L2 is a deterministic CFL (B) L3 + L1 is recursive (C) L1 , L2 is context free (D) L1 + L2 + L3 is recursively enumerable
SOLUTION

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

Consider the regular language L = (111 + 111111)* . The minimum number of states in any DFA accepting this languages is (A) 3 (C) 8
SOLUTION

(B) 5 (D) 9

The valid strings are !, 111, 11111, 11111111, 11111111111......... No. of is can be 0, 3, 6, 9, 5, 8, 10, 15, 13, 11, 12 So the DFA accepts no. of 1s 8 to every digit i.e. 8, 9, 10, 11, 12.....
Page 21

CS Topicwise 2001-2010 Theory of Computation

www.gatehelp.com

So no. of states required = 9 Hence (D) is correct option.


YEAR 2007

Question. 33

Which of the following problems is undecidable? (A) Membership problem for CFGs (B) Ambiguity problem for CFGs (C) Finiteness problem for FSAs (D) Equivalence problem for FSAs
SOLUTION

Finite state automata (FSA) has no undecidability CFL membership problem is also decidable. So option (B) i.e Ambiguity of CFL cannot be decidable. Hence (B) is correct option.
Question. 34

Which of the following is TRUE? (A) Every subset of a regular set is regular (B) Every finite subset of a non-regular set is regular (C) The union of two non-regular sets is not regular (D) Infinite union of finite sets is regular
Page 22

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

(A) Not necessary eg. L1 = ) & L2 = {an bn, n $ 0} L1 is regular but L2 not so false. (B) It is true all finite sets are regular. (C) Can happen it L1 , L1c = ) (D) also false. Hence (B) is correct option.
Question. 35

A minimum state deterministic finite automation accepting the language L = {w | w ! (0, 1}* , number of 0s &1s in w are divisible by 3 and 5, respectively} has (A) 15 states (B) 11 states (C) 10 states
SOLUTION

(D) 9 states

To accept continuous string of 5 1's & 3 0's we require at least 7 states. But (0, 1)) is there so any combination of 0 & 1 can be there in the string. So a grid of states would be there.

Total states = 15
Page 23

CS Topicwise 2001-2010 Theory of Computation

www.gatehelp.com
Hence (A) is correct option.
Question. 36

The language L = {0T 21i | i # 0} over the alphabet {0,1,2) is (A) not recursive (B) is recursive and is a deterministic CFL (C) us a regular language (D) is not a deterministic CFI but a CFL
SOLUTION

L = {0i 21i i $ 0}, this language cant be accepted by DFA to regular, but it is recursive & can be accepted by PDA to CFL . Hence (B) is correct option.
Question. 37

Which of the following languages is regular? (A) {WWR | W ! {0,1} +} (B) {WWR X | X, W ! {0,1} +} (C) {WXWR X | X, W ! {0,1} +} (D) {XWWR X | X, W ! {0,1} +}
SOLUTION

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.

Data for Q. 46 & 47 are given below


Solve the problems and choose the correct answers. Consider the following Finite State Automation
Page 24

www.gatehelp.com

CS Topicwise 2001-2010 Theory of Computation

Question. 38

The language accepted by this automaton is given by the regular expression (A) b * ab * ab * ab * (C) b * a (a + b)*
SOLUTION

(B) (a + b)* (D) b * ab * ab *

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 (C) 3
SOLUTION

(B) 2 (D) 4

State q 3 has no incoming edge, so automata will never reach in that state. So q 3 can be removed. Also q1 & q2 works same so can be merged.

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

Which of the following in true for the language{aP | P is a prime}? (A) It is not accepted by a Turning Machine (B) It is regular but not context-free (C) It is context-free but not regular (D) It is neither regular nor context-free, but accepted by a Turing machine
SOLUTION

{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

Which of the following are decidable? 1. 2. 3. 4. Whether the intersection of two regular languages is infinite Whether a given context-free language is regular Whether two push-down automata accept the same language Whether a given grammar is context-free (B) 1 and 4 (D) 2 and 4

(A) 1 and 2 (C) 2 and 3


SOLUTION

We cant determine whether a given CFL is regular or not, also similarity of PDA's on basis of language acceptance is not possible but intersection of two REL & whether grammar is CFG is decidable. Hence (B) is correct option.

Page 26

www.gatehelp.com
Question. 42

CS Topicwise 2001-2010 Theory of Computation

If L and L are recursively enumerable then L is (A) regular (C) context-sensitive


SOLUTION

(B) context-free (D) recursive

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

Which of the following statements is false? (A) Every NFA can be converted to an equivalent DFA (B) Every non-deterministic Turing machine can be converted to an equivalent deterministic Turing machine (C) Every regular language is also a context-free language (D) Every subset of a recursively enumerable set is recursive
SOLUTION

(A) true since NFA " DFA conversion possible. (B) N.D turing M/C so true. (C) every rex is a CFL but reverse is not true. (D) false, since these may be proper subset of each other so not necessary. Hence (D) is correct option.
Question. 44

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:
a b 2 1

Z:
a b 2 1

"
2F

1 2

"
2F

2 1

(A)
a -P Q R(F) S S R Q Q b R S P P

(B)
a -P Q R(F) S S R Q Q b Q S P P

(C)
a -P Q R(F) S Q R Q Q b S S P P

(D)
a -P Q R(F) S S S Q Q b Q R P P

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

Let the states be P, Q, R & S . So this transition table would be. Fig. Hence (A) is correct option
Question. 45

Which of the following statements are true ? 1. 2. 3. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa All -productions can be removed from any context-free grammar by suitable transformations The language generated by a context-free grammar all of whose production are of the form X " w or X " wY (where, w is a staring of terminals and Y is a non-terminal), is always regular The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees.

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. 2. 3. 4. L = {a"b"c"d"| n # 1, m # 1} X " XbX | XcX | dXf | g L = {wcw | w ! (a | b)*} X " bXb | cXc |

Codes: A (A) (B) (C) (D) 1 3 3 1 B 3 1 1 3 C 2 4 2 4 D 4 2 4 2

SOLUTION

A. To check whether identifiers are declared before their use, are shown by L = {wcw w ! (a/b))} B. No. of formal parameters matching will be done by {an bm cn dm n $ 1, m $ 1} C. Arithmetic matching of parentheses. done by {X " XbX XcX dXf g} D. X " bXb cXc !, shows set of all even length palindromes. So A " 3, B " 1, C " 2, D " 4 Hence (C) is correct option.
Page 30

www.gatehelp.com
Question. 47

CS Topicwise 2001-2010 Theory of Computation

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) 2 1 1 3 b 1 3 2 2 c 3 3 3 1 d 4 4 4 4

SOLUTION

A. "this DFA is regulated by regular expression ! + 0 (01)100))01) , since this REX require two 00 in sub-expression & accepted by DFA . B. The string 010001100010 is accepted by DFA , & string follows e + 0 (10)1 + 00))0 So A " 1, B " 2 , C " S , D " 4 . Hence (C) is correct option.
Question. 48

Which of the following are regular sets? 1. 2. 3. 4. {an b2m | n # 0, m # 0} {an bm | n = 2m} {an bm | n ! m} {xcy | x, y ! {a, b}*} (B) 1 and 3 only (D) 4 only

(A) 1 and 4 only (C) 1 only


Page 32

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

I.

{an b2m, n $ 0, m $ 0} is a regular language, since we can represent it by regular expression (a))(bb)) both n & m do not have any linear relationship.

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

S " aSa bSb a b The language generated by the above grammar over the alphabet {a, b} is the set of (A) all palindromes (B) all odd length palindromes (C) strings that begin and end with the same symbol (D) all even length palindromes
SOLUTION

Given grammar S " aSa bSb a b . The strings generated through this grammar is definitely palindromes, but not all it can only generate palindromes of odd length only so (A) & (D) are false, (B) is correct. Also it can generate palindromes which start and end with same symbol, but not all strings eg. aabababba . Hence (B) is correct option.
Question. 50

Which one of the following languages over the alphabet {0, 1} is described by the regular expression : (0 + 1))0 (0 + 1))0 (0 + 1)) ? (A) The set of all strings containing the substring 00
Page 33

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

Given regular expression (0 + 1))0 (0 + 1))0 (0 + 1)) due to two 0 in between, every string would contain at least two 0's . Hence (C) is correct option.
Question. 51

Which one of the following is FALSE ? (A) There is a unique minimal DFA for every regular language (B) Every NFA can be converted to an equivalent PDA (C) Complement of every context-free language is recursive (D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA

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

www.gatehelp.com
Group 1 P. Regular expression Q. Pushdown automata R. Data flow analysis S. Register allocation 1. 2. 3. 4. Group 2 Syntax analysis Code generation Lexical analysis Code Optimization (B) P-3, Q-1, R-4, S-2 (D) P-2, Q-1, R-4, S-3

CS Topicwise 2001-2010 Theory of Computation

(A) P-4, Q-1, R-2, S-3 (C) P-3, Q-4, R-1, S-2
SOLUTION

Regular expressions are meant for lexical analysis to define tokens. Pushdown Automata is used to accept context free language which are used for syntax analysis. Data flow analysis is a technique for code optimization. Register allocation is used for code generation. So P 3, Q 1, R 4, S 2 . Hence (B) is correct option
Question. 53

Given the following state table of an FSM with two states A and B , one input and one output :
Present State A 0 0 1 1 0 0 1 1 Present State B 0 1 0 1 0 1 0 1 Input 0 0 0 0 1 1 1 1 Next State A 0 1 0 1 0 0 0 0 Next State B 0 0 1 0 1 0 1 0 Output 1 0 0 0 0 1 1 1

If the initial state is A = 0, B = 0 , what is the minimum length of an input string which will take the machine to the state A = 0, B = 1 with Output = 1 ? (A) 3 (B) 4
Page 35

CS Topicwise 2001-2010 Theory of Computation

www.gatehelp.com
(C) 5
SOLUTION

(D) 6

The path to follow for given state.

So the length of input string is three. Hence (A) is correct option.


Question. 54

Let L = L1 + L2 where L1 and L2 are language as defined below : L1 = {am bm can bn m, n $ 0} L2 = {ai b j ck i, j, k $ 0} Then L is (A) Not recursive (B) Regular (C) Context-free but not regular
Page 36

www.gatehelp.com
(D) Recursively enumerable nut not context-free
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

L = L1 + L2 , so L would contain am bm c where m = i = j & k = 1 in L 2 ai b j c k . So the language L = {am bm c is context free, but since it is recursive it is not regular, cant be represented using DFA . Hence (C) is correct option.
Question. 55

The following DFA accept the set of all string over {0, 1} that

(A) Begin either with 0 or 1 (C) End with 00


SOLUTION

(B) End with 0 (D) Contain the substring 00

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

Let L1 be a recursive language. Let L2 and L3 be language that are recursively enumerable but not recursive. What of the following statements is not necessarily true ? (A) L1 L1 is recursively enumerable (B) L1 L3 is recursively enumerable (C) L2 + L3 is recursively enumerable (D) L2 + L3 is recursively enumerable
Page 37

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

Let L = { ! (0 + 1)) has even number of 1s}, i.e., L is the set of all bit strings with even number of 1s. Which one of the regular expressions below represents L ? (B) 0)(10)10))) (A) (0)10)1)) (C) 0)(10)1))0)
SOLUTION

(D) 0)1 (10)1))10)

We require strings to have even no. of 1's , so to prove options false we need to find those strings which doesnt satisfy languages but have even no. of 1's Choice (A) (0)10)1)) is incorrect 1010101 string cant be derived Choice (B) accepts 1010101 Choice (C) 0)(10)1))0) Same 1010101 string is not accepted Choice (D) 0)1 (10)1))10) 010101010 cant be accepted. Hence (B) is correct option.
Question. 58

Consider the language L1 = {0i 1 j i = Y j}, L2 = {0i 1 j i = j}, L3 = {0i 1 j i = 2j + 1} L4 = {0i 1 j i = Y 2j}.Which one of the following statements is true ? (A) Only L2 is context free (B) Only L2 and L3 are context free (C) Only L1 and L2 are context free (D) All are context free
Page 38

www.gatehelp.com
SOLUTION

CS Topicwise 2001-2010 Theory of Computation

These sort of languages are accepted by PDA , so all should be context free languages. L2 & L 3 are definitely CFL since accepted by stock of PDA . And also L1 & L 4 are linear comparisons of i & j so can also be represented using PDA . So all are context free languages. Hence (D) is correct option.
Question. 59

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
SOLUTION

(D) 2n + 1

L is the set of all substrings of w where w ! {0, 1}) Any string in L would have length 0 to n , with any no. of 1's and 0's The NDFA

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

By NODIA and Company


Available in Two Volumes