You are on page 1of 485

GATE Overflow Book

This book is composed of all questions at GATE


Overflow, ordered by date, sorted by categories,
including their answers that were selected as best and
received at least 2 upvotes.
Questions without qualifying answers are not included
herein.
The book was created programatically by GATE
Overflow on Jun 20, 2015. If you feel any doubt
regarding the answer, click on the question link and give
a comment on the site. Studying all these questions
might get you 50 marks in GATE but that won't be
enough for an IIT. So, read standard books, solve
exercise questions and use these questions for
cementing the concepts.

Table of Contents
Algorithms
Compiler Design
CO & Architecture
Operating System
Databases
Theory of Computation
Computer Networks
Digital Logic
IS & Software Engg.
Web Technologies
Verbal Ability
Numerical Ability
Mathematical Logic
Probability
Set Theory & Algebra
Combinatory
Graph Theory
Linear Algebra
Numerical Methods
Calculus
Programming
DS

Algorithms top
GATE2012_4

top

Assuming P NP, which of the following is TRUE?


(A) NP-complete = NP
(B) NP-complete P =
(C) NP-hard = NP
(D) P = NP-complete

Answer is
(B) NP-complete P =
Since, P NP, there is at least one problem in NP, which is harder than all P problems. Lets take the hardest such problem, say
Now, by definition, NP-complete problems are the hardest problems in NP and so

X . Since, P NP, X P.

X problem is in NP-complete. And being in NP, X can be reduced to all


X P, none of the other NP-complete problems can also be not in P.

problems in NP-complete, making any other NP-complete problem as hard as X . So, since

-- Arjun Suresh

GATE2012_16 top
The recurrence relation capturing the optimal execution time of the T owersofHanoi problem with n discs is
(A) T (n) =
(B) T (n) =
(C) T (n) =
(D) T (n) =

2T (n 2) + 2
2T (n 1) + n
2T (n/2) + 1
2T (n 1) + 1

Recurrence relation for Towers of Hanoi is


T(1) = 1
T(n) = 2 T( n-1 ) +1
So Answer should be (D)
-- Narayan Kunal

Do i need to study P, NP computational problems like vertex cover problem also for gate
2015 or only the basic definitions? top

You would need to know some examples (not all) of NP Complete problems and why they are NP Complete. For example 3SAT problem is
NPC and in GATE they have asked about 2SAT. So, just learning some examples won't be enough.
-- Arjun Suresh

Suppose there is a balanced binary tree with n nodes

top

Answer should be (A).


We first find a in the BST in O(log n) time. Now there are two possibilities, b can be in the right subtree ofa or b can be in the right subtree of
any of the parents of a. For the first case, we simply search forb , in the right subtree ofa and at each step we add the number of elements in
the left subtree +1, if we are moving right and simply 1 if we are moving left. When we find b , this sum will give as the required number of
elements.
For the second case also we do the same method. But first we find the common ancestor of a and b (possible inO(log n)- say p and from p to
a add the number of nodes in the right subtree for each level and add this to the required sum. So, in the worst case we have to doO(log n)
additions.
-- Arjun Suresh

Is the following statement valid?

log(n!) = (n log n)
top

I think it is sterling's approximation

ln N! = N ln N N + ln
2n
-- Arpit Dhuriya

GATE2003_66 top
The cube root of a natural number
represented by binary notation) is

n is defined as the largest natural number m such that (m3 n) . The complexity of computing the cube root of n (n is

O(n) but not O(n 0.5 )


O(n 0.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((log log n) m ) for any constant m > 0
(D) O((log log n) k ) for some constant k > 0.5, but not O((log log n) 0.5 )
(A)
(B)

We can simply do a binary search in the array of natural numbers from 1..n and check if the cube of the number matches n. In this way we
can find the cube root in O(log n). So, options (A) and (B) are wrong.
Now, a number is represented in binary using log n bit. Since each bit is important in finding the cube root, any cube root finding algorithm
must examine each bit at least once. This ensures that complexity of cube root finding algorithm cannot be lower than log n. (It must be
log n). So, (D) is also false and (C) is the correct answer.
-- gatecse

Given an integer

top

Given an integer n 3 , consider the problem of determining if there exist integersa, b 2 such that n = ab . Call this the forward problem. The
reverse problem is: given a and b , compute ab ( mod b). Note that the input length for the forward problem is log n + 1, while the input length
for the reverse problem is log a + log b + 2. Which of the following statements is TRUE?
(a) Both the forward and reverse problems can be solved in time polynomial in the lengths of their respective inputs.
(b) The forward problem can be solved in polynomial time, however thereverse problem in NP-hard.
(c) The reverse problem can be solved in polynomial time, however theforward problem in NP-hard.
(d) Both the forward and reverse problems are NP-hard.
(e) None of the above.

The reverse problem can be solved in polynomial time asab requires at most log b recursive calls using the approach given below:
pow(int a, int b)
{
if(b%2)
return a* pow(a*a, b/2);
else
return pow(a*a, b/2);
}

Now, the forward problem is also solvable in polynomial time. We need to check for all the roots ofn (from
n till n log n ) whether it is an
integer . But each of these check can be done in log n time using a binary search on the set of integers from 2..n and so, the overall
complexity will be (log n)2 which is polynomial in log n (log n is the size of input). So, (a) must be the answer.
1

-- gatecse

GATE2008_40 top
The minimum number of comparisons required to determine if an integer appears more than n times in a sorted array ofn integers is
2

A. (n)
B. (log n)
C. (log n)
D. (1)

To check whether a given number is repeated n/2 times in the array can be done in O(log n) time.
Algo
1. find the first occurrence (index i) of x(given number) in the array which can be done in O(log n) time (a variant of binary search).
2. check if A[i] == A[n/2+i]
return true
3. else return false

-- Vikrant Singh

GATE2008_74,75 top
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[0] = Y[0] = Z[0] = 0;
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];

74. The running time of f1(n) and f2(n) are


A. (n) and (n)
B. (2n) and (n)
C. (n) and (2n)
D. (2n) and (2n)
75. f1(8) and f2(8) return the values
A.
B.
C.
D.

1661 and 1640


59 and 59
1640 and 1640
1640 and 1661

Time complexity of f1 is given by


T(n) = T(n-1) + T(n-2), (multiplication by 2 and 3 won't affect complexity as it is a constant time operation)
T(0) = T(1) = 1
The solution to this (fibonacci series) is given by Golden ratio. https://en.wikipedia.org/wiki/Golden_ratio which is O(2n). (Using theta in
question must be a mistake)
Time complexity of f2 is (n) as here all recursive calls are avoided by saving the results in an array (dynamic programming).
So, answer to 74 is (B).
75. Both f1 and f2 are calculating the same function. So,
f1(2) = 2f1(1) + 3f1(0) = 2
f1(3) = 2f1(2) + 3f1(1) = 7
f1(4) = 20
f1(5) = 61
f1(6) = 182
f1(7) = 547
f1(8) = 1640 = f2(8)
-- Arjun Suresh

GATE2008_78,79 top
Let xn denote the number of binary strings of lengthn that contain no consecutive 0s.
78. Which of the following recurrences doesxn satisfy?
A.
B.
C.
D.

xn
xn
xn
xn

= 2xn1
= xn/2 + 1
= xn/2 + n
= xn1 + xn2

79. The value of x5 is


A.
B.
C.
D.

5
7
8
16

0 1 -2
01 10 11 -3
010 011 101 110 111 -5
0101 0110 0111 1010 1011 1101 1110 1111 -8
So, xn = xn-1 + xn-2 (For all the strings ending in 1, we get two new strings and for all strings ending in 0, we get a new string. So, the new set
of strings for n+1, will have exactly n strings ending in 1)
x5 = 8+5 = 13
-- Arjun Suresh

GATE2000_2.15 top
Suppose you are given an array s[1....n] and a procedure reverse (s, i, j) which reverses the order of elements in s between positions i and j (both inclusive). What
does the following sequence do, where 1 k n:
reverse (s, 1, k);
reverse (s, k+1, n);
reverse (s, 1, n);

a.
b.
c.
d.

Rotates s left by k positions


Leaves s unchanged
Reverses all elements of s
None of the above

Answer is (a)
Effect of the above 3 reversal for any K is equivalent to left rotation of the array of size n by k.
Let , S[1......7]
1

so, n=7 ,k = 2
reverse(S,1,2) we get [2,1,3,4,5,6,7]
reverse(S,3,7) we get [2,1,7,6,5,4,3]
reverse(S,1,7) we get [3,4,5,6,7,1,2]
hence option (a) Rotates s left by k position is correct

-- Kalpna Bhargav

GATE2000_2.16 top
Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited `in a postorder, inorder and preorder traversal respectively, of a complete binary tree. Which
of the following is always true?

a.
b.
c.
d.

LASTIN = LASTPOST
LASTIN = LASTPRE
LASTPRE = LASTPOST
None of the above

The answer is D.
Take any random sequence and check for the inorder, postorder and preorder Last Node.
-- Gate Keeda

GATE2000_2.18 top
Let G be an undirected connected graph with distinct edge weights. Let emax be the edge with maximum weight and emin the edge with minimum weight. Which of
the following statements is false?

a.
b.
c.
d.

Every minimum spanning tree of G must contain emin


If emax is in a minimum spanning tree, then its removal must disconnect G
No minimum spanning tree contains emax
G has a unique minimum spanning tree

C. the case should be written as "may or may not", to be true.

D will always be true as per the question saying that the graph has distinct weights.
-- Gate Keeda

GATE2001_1.14 top
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) O(n)
(B) O(n log n)
(C) O(n 2 )
(D) O(n!)

In worst case, we may pick pivot elements in the increasing order (input also given in sorted order) which will result in running time of O(n 2 )
Ans. C
-- Vikrant Singh

GATE2005_39 top
Suppose there are
structure)

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

Since we have log n lists we can make a min-heap of log n elements by taking the first element from each of thelog n sorted lists. Now, we
start deleting the min-element from the heap and put the next element from the sorted list from which that element was added to the heap.
(This identity can be done by making a structure of two values, one for the number and one for identifying the origin sorted list of that number
and storing this structure in the heap). In this way each delete and the corresponding insert will take O(log log n) time as delete in heap is
O(1) and inserting an element on a heap of sizen is O(log n). (here, heap size is log n). Now, we have a total of log n n = n elements.
So, total time will be O(n log log n).

log n

-- gatecse

GATE2002_1.4

top

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 the
same colour is
A.
B.
C.
D.

2
3
4

n 2[ n2 ] + 2

Chromatic number will be 3 for when n is odd and will be 2 when n is even. Option (d) is a representation for this, hence the correct answer
-- Madhur Rawat

GATE2003_12 top
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 reductions?

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

C
Ram's reduction shows is NP hard.
Shyam's reduction shows is in NP.
So NPC.
-- Anurag_s

GATE2003_20 top
Consider the following three claims
I. (n + k)m = (n m ) where k and m are constants
II. 2 n+1 = O(2 n )
III. 2 2n+1 = O(2 n )
Which of the following claims are correct
A.
B.
C.
D.

I and II
I and III
II and III
I, II, and III

1) Clearly rate of growth of (n+k)^m = n^m as m is a constant


so TRUE
2) 2^(n+1) = 2*(2^n) = theta(2^n) as 2 is a constant here
so as 2^(n+1) is both upper and lower bounded by 2^n
so we can say 2^(n+1) = O(2^n)
so TRUE
3) 2^(2n+1) has same rate of growth as 2^(2n)
2^(2n) = (2^n)^2
so 2^n is upper bounded by (2^n)^2 , not the other way round
so FALSE

CORRECT ME IF I AM WRONG
-- Danish

GATE2006_15 top
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 variablej after termination of the for loop. Which one of the following is true?
(A)

(B)
(C)
(D)

Answer will be theta(n)


j = n/2+n/4+n/2+...+1
number of iteration will be 2^k = n or k = logn
this is in gp find sum till logn = thetha(n)
-- raunak bairoliya

GATE2006_16 top
Let S be an NP-complete problem and 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
(B) R is NP-hard
(C) Q is NP-complete
(D) Q is NP-hard

Q cannot be NP hard as no np hard problems(unless they are np) can be polynomial time reducible to np complete.Answer is B, as npc
problem can be reducible to np hard problem. But there is confusion if Q is not NP hard then what complexity class it is in!!
-- Shaun Patel

GATE2006_17 top
An element in an array X is called a leader if it is greater 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 it in linear time using a right to left pass of the array
(C) Solves it using divide and conquer in time (n log n)
(D) Solves it in time (n 2 )

Ans B should be correct.


We can move from right keeping a note of the maximum element(suppose current_max). At the start the right most element will
always be a leader. If an element is greater than our current_max, it will a leader. Add this element to leaders. Set current_max to
this element and carry on leftward. Time Complexity would be O(n)
-- Madhur Rawat

GATE2004_29 top
The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of
(a) n
(b) n 2
(c) n log n
(d) n log2 n

For comparison-based sorting the asymptotically tight bound for worst case is given by (log n), which means it is the tightest upper bound
(big O) as well as the tightest lower bound (big omega). So, answer is n log n.

Tightest lower bound of sorting (say S(n)) is n log n means there is no function f which has an order of growth larger than n log n and
f(n) = (S(n)) holds.
A usual mistake is to think worst case changes with lower and upper bounds, but that is not the case. Worst case is defined for the problem
and it is always the input which causes the algorithm the maximum complexity.
-- Arjun Suresh

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

In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?

A.
B.
C.
D.

P,Q,R,S,T,U
P,Q,R,U,S,T
P,Q,R,U,T,S
P,Q,T,R,U,S

Ans is (B). In Dijkstra's algorithm at each point we choose the smallest weight edge which starts from any one of the vertices in the shortest
path found so far and add it to the shortest path.
-- gate_asp

GATE2004_82 top
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 =0;
for (i=1; i<=n; i++)
{ if a[i] == 1) counter++;
else {f (counter); counter = 0;}
}

The complexity of this program fragment is

A. (n 2 )
B. (n log n) and O(n 2 )
C. (n)
D. o(n)

The key part in the code is "counter = 0" in the else part as we can see below.
Lets take the best case. This happens when a[i] = i for all i, and then the loop executes with time complexity (1) for each iteration and hence
overall time complexity of (n) and we can say time complexity of the code fragment is (n) and hence options a and b are false.
Now, consider the worst case. This happens when a[i] = 0 or when else part is executed. Here, the time complexity of each iteration will
be (counter) and after each else counter is reset to 0. So, the maximum complexity will be (1) + (1) + ... + (1) (n times) which will
be (n) for the whole loop. Even if we mix some if part and some else part, the maximum sum of the complexities for else part will always
be (n) (because of counter = 0) and hence for the code fragment the time complexity will be (n).

Since the time complexity is (n) and (n) we can say it is (n) also. Option (C). (Option D is false because the small o needs the growth
rate to be STRICTLY lower and not equal to or lower as the case for big 0)
If counter = 0 was not there in else part, time complexity would be (n) and O(n2) as (1) + (2) + ... + (n) would give O(n2).
-- Arjun Suresh

GATE2004_84 top
The recurrence equation

T (1) = 1

T (n) = 2T (n 1) + n, n 2

evaluates to
(a) 2 n+1 n 2

(b) 2 n n

(c) 2 n+1 2n 2

(d) 2 n + n

T(n) = 2T(n-1) +n, n >=2 & T(1) = 1


T(n)

= n + 2(n-1) + 22 (n-2) + ........... + 2(n-1) (n -(n-1))


=n( 1 + 2 + ......+ 2n-1) - (1.2 + 2.22 +3.23+.....+ (n-1).2 n-1)
=n(2n-1) -(n.2n-2n+1+2)
= 2n+1-n -2

-- suraj

GATE2004_85 top
A program takes as input a balanced binary search tree with n leaf nodes and computes the value of a functiong(x) for each node x. If the cost
of computing g(x) is

min(number of leaf-nodes in left-subtree of x,


number of leaf-nodes in right-subtree of x),
then the worst-case time complexity of the program is

A. (n)
B. (n log n)
C. (n 2 )
D. (n 2 log n)

should be B....at the root node the cost would be n/2 and similarly at each level the cost would be n/2 and so for log n levels it would be n/2
log n.
-- Shaun Patel

GATE2003_23 top
In a min-heap of size n the 7th smallest element can be found in

Time to find the smallest element on a min-heap- one retrieve operation -(1)
Time to find the second smallest element on a min-heap- requires 2 2 1 = 3 check operations to find the second smallest element out of 3
elements - (1)
Time to find the 7th smallest element - requires O(2 7 1) = O(127) check operations to find the seventh smallest element out of 127
possible ones - (1)
In short if the number of required operations is independent of the input size n, then it is always (1).
(Here, we are doing a level order traversal of the heap and checking the elements)
-- gatecse

GATE2007_13 top
The maximum number of binary trees that can be formed with three unlabeled nodes is:

A.
B.
C.
D.

1
5
4
3

can be found with formula... (2nCn/n+1)... n being the number of nodes. for the given question... where n=3... answer is 5. Let me also specify
here.. that number of Binary Search Trees with n nodes is equal to number of unlabeled Binary trees.
http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_nodes

-- Gate Keeda

GATE2007_14 top
Which of the following sorting algorithms has the lowest worse-case complexity?

A. Merge sort
B. Bubble sort
C. Quick sort
D. Selection sort

A.
Irrespective of the input, Merge sort always have a time complexity of (n log n).
-- Gate Keeda

GATE2007_39 top
The inorder and preorder traversal of a binary tree are

d b e a f c g and a b d e c f g , respectively
The postorder traversal of the binary tree is:

A. d e b f g c a
B. e d b g f c a
C. e d b f g c a
D. d e f g b c a

The answer is A.
Take the first node in preorder traversal - a will be the root of the tree
All nodes to the left of 'a' in inorder traversal will be in the left subtree of 'a' and all elements on the right will be in the right subtree of 'a'.
Take the second element from preorder traversal - 'b' - goes to left subtree of 'a' as it is in the left of 'a' in inorder list.
Proceeding likewise we can construct the binary tree as:

-- Gate Keeda

GATE2007_46 top
Consider the following C program segment where CellNode represents a node in a binary tree:
struct CellNode {
struct CellNode *leftChild;
int element;
struct CellNode *rightChild;
};
int Getvalue (struct CellNode *ptr) {
int value = 0;
if (ptr != NULL) {
if ((ptr->leftChild == NULL) &&
(ptr->rightChild == NULL))
value = 1;
else
value = value + GetValue(ptr->leftChild)
+ GetValue(ptr->rightChild);
}
return(value);
}

The value returned by GetValue when a pointer to the root of a binary tree is passed as its argument is:

A. the number of nodes in the tree


B. the number of internal nodes in the tree
C. the number of leaf nodes in the tree
D. the height of the tree

Answer: C

As the function returns 1 if and only if any node has both left & right children as NULL (that node is a leaf node). Hence,value gets
incremented at each leaf node.
-- Jon Snow

GATE2009_11 top
What is the number of swaps required to sortn elements using selection sort, in the worst case?

A. (n)
B. (n log n)
C. (n 2 )
D. (n 2 log n)

The answer is A.
we have 1 swap in each loop and hence n swaps at max for 1 to n. Therefore the worst case number of swaps is
-- Gate Keeda

GATE2009_39 top
In quick-sort, for sorting n elements, the (n/4) th smallest element is selected as pivot using an O(n) time algorithm. What is the worst case time
complexity of the quick sort?

A. (n)
B. (n log n)
C. (n 2 )
D. (n 2 log n)

B.
T(n)= O(n) pivot selection time + O(n) partition time + T(n/4 - 1) + T(3n/4)
which'll give theta(nlog4/3n).
-- Gate Keeda

GATE2009_53,54 top
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two
sequences X[m] and Y [n] of lengths m and n, respectively with indexes ofX and Y starting from 0 .
We wish to find the length of the longest common sub-sequence (LCS) ofX[m] and Y [n] as l(m, n), where an incomplete recursive definition
for the function I(i, j) to compute the length of the LCS ofX[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[j-1]

Which one of the following options is correct?

A. expr1 = l(i 1, j) + 1

B. expr1 = l(i, j 1)
C. expr2 = max(l(i 1, j), l(i, j 1))
D. expr2 = max(l(i 1, j 1), l(i, j))

54. The value of l(i, j) could be obtained by dynamic programming based on the correct recursive definition ofl(i, j) of the form given above,
using an array L[M, N], where M = m + 1 and 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 ofl(i, j)?
A.
B.
C.
D.

All elements of L should be initialized to 0 for the values ofl(i, j) to be properly computed.
The values of l(i, j) may be computed in a row major order or column major order ofL[M, N].
The values of l(i, j) cannot be computed in either row major order or column major order ofL[M, N].
L[p, q] needs to be computed before L[r, s] if either p < r or q < s.

53. Answer is C . When the currently compared elements doesn't match, we have two possibilities for the LCS, one including X[i] but not
Y[j] and other including Y[j] but not X[i].
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int lcs( char *X, char *Y, int m, int n )
{
if (m == 0 || n == 0)
return 0;
if (X[m-1] == Y[n-1])
return 1 + lcs(X, Y, m-1, n-1);
else
return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
}

54. Answer is D. Dynamic programming is used to save the previously found LCS. So, for any index [p,q] all smaller ones should have been
computed earlier.
int lcs( char *X, char *Y, int m, int n )
{
int L[m+1][n+1];
int i, j;
/* Following steps build L[m+1][n+1] in bottom up fashion. Note
that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (i=0; i<=m; i++)
{
for (j=0; j<=n; j++)
{
if (i == 0 || j == 0)
L[i][j] = 0;
else if (X[i-1] == Y[j-1])
L[i][j] = L[i-1][j-1] + 1;
else
L[i][j] = max(L[i-1][j], L[i][j-1]);
}
}
/* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
return L[m][n];
}

-- Praneeth A S

GATE2005_37 top
Suppose T (n) = 2T ( n ) + n, T (0) = T (1) = 1
2

Which one of the following is FALSE?

A. T (n) = O(n 2 )
B. T (n) = (n log n)
C. T (n) = (n 2 )

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

Applying Masters theorem T(n) = (n log n) So, it can't be (n2)


Hence answer is C.
-- shreya ghosh

GATE2005_45 top
Consider three decision problems 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. P3 is undecidable if P2 is reducible to P3
D. P3 is decidable if P3 is reducible to P2's complement

(A) If P1 is reducible to P3, then P3 is at least as hard as P1. So, no guarantee if P3 is decidable.
(B) If P3 is reducible to P2, then P3 cannot be harder than P2. But P2 being undecidable, this can't say P3 is undecidable.
(C) If P2 is reducible to P3, then P3 is at least as hard as P2. Since, P2 is undecidable, this means P3 is also undecidable -hence the answer.
(D) Complement of an undecidable problem is undecidable. Now, reducing to an undecidable problem can't prove P3 is decidable.
http://gatecse.in/wiki/Some_Reduction_Inferences
-- Arjun Suresh

GATE1999_1.12 top

(b) If it maintains the relative order of occurrence of non-distinct elements.


(from definition of stable sorting)
-- Arjun Suresh

GATE1999_1.14 top

20 47 15 8 9

4 40 30 12 17

\ /
\ / \ /
\ /
20 47 8 15 4 9
30 40
\
/
\
/
\
/
\
/
8,15,20,47
4,9, 30,40

\ /
12 17
\ /
\/
12,17

after 1st pass

after 2nd pass

Ans. B
-- Vikrant Singh

GATE1999_2.21 top
If T1 = O(1), give the correct matching for the following pairs:
(M) Tn = Tn1 + n
(N) Tn = T n + n
2

(O) Tn = T n + n log n
2

(P) Tn = Tn1 + log n

(U) Tn = O(n)

(V) Tn = O(n log n)


(W) T = O(n 2 )

(X) Tn = O(log2 n)

(A) M-W N-V O-U P-X


(B) M-W N-U O-X P-V
(C) M-V N-W O-X P-U
(D) M-W N-U O-V P-X

n(n+1)
2

(M) T (n) = Sum of first n natural numbers =

= O(n 2 )

(N) T (n) = (n) = O(n), third case of Master theorem


(f(n) = n = (n log b a+ ) = (n log 2 1+ ) = (n 0.5+ ),
satisfied
for
any
af( n ) < cf(n) f( n ) < cf(n) n < cn, satisfied for any c between 0 and 0.5)
b

positive

less

than 0.5.

Also,

(O) T (n) = (n log n) = O(n log n), third case of Master theorem
(f(n) = n log n = (n log b a+ ) = (n log 2 1+ ) = (n 0.5+ ),

af( nb ) < cf(n) f( n2 ) < cf(n)

n
2

log

n
2

satisfied

< cn log n, satisfied for c = 0.5)

(P) Like in (M), here we are adding the log of the first n natural numbers. So,

Tn = log 1 + log 2 + log 3+. . . . log n


= log(1 2 n)
= log(n!)
= n log n n + 1 (Stirling's Approximation)
= O(n log n)
-- Arjun Suresh

GATE1999_2.24 top

for

positive = 0.5.

Also,

a b c Return
111

The final return statement is c < b, so this never returns.


Answer D.

-- Arjun Suresh

GATE2013_30 top
The number of elements that can be sorted in (log n) time using heap sort is

(A) (1) (B) (


logn) (C) (

log n
)
log log n

(D) (log n)

To sort k elements in a heap, complexity is (k log k). Lets assume there are
Complexity = (

log n
log log n

log n
log log n

elements in the heap.

log( log log n ))


log n

log n

= ( log log n (log log n log log log n))


= ( log n

log n log log log n


log log n

= (log n) (as shown below)


So, (c) is the answer.

log log n > log log log n

log log log n


log log n

log n log log log n


log log n

<1

( log n

< log n

log n log log log n


log log n

) = (log n)

-- Arjun Suresh

GATE2013_31 top
Consider the following function:
int unknown(int n){
int i, j, k=0;
for (i=n/2; i<=n; i++)
for (j=2; j<=n; j=j*2)
k = k + n/2;
return (k);
}

The return value of the function is


(A) (n 2 )

(B) (n 2 log n)

(C) (n 3 )

(D) (n 3 log n)

The outer loop is running for n/2 times and inner loop is running for log2 n times (each iteration doubles j and j stops at n means log2 n times j
loop will iterate).
Now in each iteration k is incremented by n/2. So, overall k will be added n/2 * log n * n/2 with an initial value of 0. So, final value of k will
be (n2 log n)
-- Arjun Suresh

GATE2013_43 top
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder
traversal sequence of the same tree?
(A) 10, 20, 15, 23, 25, 35, 42, 39, 30
(B) 15, 10, 25, 23, 20, 42, 35, 39, 30
(C) 15, 20, 10, 23, 25, 42, 35, 39, 30
(D) 15, 10, 23, 25, 20, 35, 42, 39, 30

Since it is a binary search tree, its inorder traversal produces a sorted sequence i.e. 10, 15, 20, 23, 25, 30, 35, 39, 42.
Now given inorder and preorder traversals, we get following tree :

From this, we can give postorder traversal sequence as 15,10,23,25,20,35,42,39,30 i.e. option (D).
-- Happy Mittal

GATE2013_50,51 top
The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters
to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length
of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed.
void find_and_replace (char *A, char *oldc, char *newc) {
for (int i=0; i<5; i++)
for (int j=0; j<3; j++)
if (A[i] == oldc[j]) A[i] = newc[j];
}

The procedure is tested with the following four test cases.


(1) oldc = abc, newc = dab (2) oldc = cde, newc = bcd
(3) oldc = bca, newc = cda (4) oldc = abc, newc = bac
Q.50 The tester now tests the program on all input strings of length five consisting of characters a, b, c, d and e with duplicates allowed. If
the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?
(A) Only one

(B) Only two

(C) Only three

(D) All four

Q.51 If array A is made to hold the string abcde, which of the above four test cases will be successful in exposing the flaw in this procedure?
(A) None

(B) 2 only

(C) 3 and 4 only

(D) 4 only

The test cases 3 and 4 are the only cases that capture the flaw. The code doesn't work properly when an old character is replaced by a new
character and the new character is again replaced by another new character. This doesn't happen in test cases (1) and (2), it happens only in
cases (3) and (4).

50. B
51. C
-- Vikrant Singh

GATE1998_1.21 top

The algorithm is an example of dynamic programming.

http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm
-- csegate2

GATE1998_1.22 top

selection sort O(n^2)


merge sort O(nlogn)
binary search (log n)
insertion sort O(n) note if you use O(n^2) here you will not be left with any choice to fill selection sort
-- Bhagirathi Nayak

GATE2006_47 top
Consider the following graph:

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), (d c), (b f), (d e)
(C) (d f), (a b), (d c), (b f), (d e)
(D) (d f), (a b), (b f), (d e), (d c)

in kruskal's algo the edges are added in non decreasing order of their weight. But in Option D edge d-e with weight 3 is added before edge dc with weight 2. Hence Option D is wrong option
-- Sankaranarayanan P.N

GATE2006_51 top
Consider the following recurrence:

T (n) = 2T (
n ) + 1, T (1) = 1
Which one of the following is true?
(A) T (n) = (log log n)
(B) T (n) = (log n)
(C) T (n) = (
n)
(D) T (n) = (n)

T (n) = 2T (n 2 ) + 1
1

= 2(T ( n 2 2 ) + 1) + 1
1

= 2 T (n 2 2 ) + 3
1

= 4 T (n 2 3 ) + 5
1

= 2 (lg lg n) + 2 lg lg n + 1 (Proved below)


= O(lg n)

n 2k = 2
(Putting 2 so that we can take log.
One more step of recurrence can't change the complexity.)
1
lg n = 1(Taking log both sides)
2k
lg n = 2 k
k = lg lg n
-- Arjun Suresh

GATE2006_54 top
Given two arrays of numbers a1 , . . . , an and b 1 , . . . , b n where each number is 0 or 1 , the fastest algorithm to find the largest span(i, j) such
that ai + ai+1 +. . . . aj = b i + b i+1 +. . . . . b j or report that there is not such span,
(A) Takes 0(3 n ) and (2 n ) time if hashing is permitted
(B) Takes 0(n 3 ) and (n 2.5 ) time in the key comparison mode
(C) Takes (n) time and space
(D) Takes O(
n ) time only if the sum of the2n elements is an even number

Answer is (C). Following algorithm would do.


#include <stdio.h>
#define size 100 //assume n is less than 100
int main()
{
int n, a[size], b[size];
int start[2*size], end[2*size];
int sum1 = 0, sum2 = 0, i;
int diff[size];
printf("Enter n: ");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
printf("Enter a[%d]: ", i);
scanf("%d", &a[i]);
}
for(i = 0; i < n; i++)

{
printf("Enter b[%d]: ", i);
scanf("%d", &b[i]);
}
for(i = 0; i < n; i++)
{
if(a[i]) sum1++;
if(b[i]) sum2++;
diff[i] = sum1 - sum2;
}
for(i = 0; i < 2*n; i++)
start[i] = -1;
start[n] = end[n] = 0; //initially sum is 0 at the beginning of array and the first n-1 elements of start and end are used if sum of A till ith element is less than sum of B till ith element
for(i=0; i < n; i++)
{
if(start[diff[i] + n] == -1)
start[diff[i] + n] = i;
end[diff[i] + n] = i;
}
int max = -1;
int savei = -1; //savei is for storing the sum having the largest span
for(i = 0; i < 2*n; i++)
{
if(start[i] > -1 && (end[i] - start[i] > max))
{
max = end[i] - start[i];
savei = i;
}
}
if(savei >= 0)
{
printf("The largest span is from %d to %d\n", start[savei]+(savei != n), end[savei]);
//when sum zero is having the largest span, span starts from first element itself. Else, the span starts from the next element from which the span does not change
}
else
{
printf("No span\n");
}
}

-- Arjun Suresh

GATE2014-1_39 top
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ________

Ans: minimum number of comparison require to find minimum and maximum is: Approach is divide and conquer ....
T(n) = T(floor(n/2)) + T(ceil(n/2)) + 2
T(2) = 1 // if two element then compare both and return max and min
T(1) = 0 // if one element then return both max and min same

If n is a power of 2, then we can write T(n) as:


T(n) = 2T(n/2) + 2

After solving above recursion, we get


T(n) = 3/2n -2

Thus, the approach does 3/2n -2 comparisons if n is a power of 2. And itdoes more than 3/2n -2 comparisons if n is not a power of 2.
So, here in this case put n=100 and we will get (3/2)(100) - 2 = 148 comparison .....
-- Jayesh Malaviya

GATE2014-1_41 top
Consider the following C function in which size is the number of elements in the array E:
int MyX(int *E, unsigned int size)

{
int Y = 0;
int Z;
int i, j, k;
for(i = 0; i< size; i++)
Y = Y + E[i];
for(i=0; i < size; i++)
for(j = i; j < size; j++)
{
Z = 0;
for(k = i; k <= j; k++)
Z = Z + E[k];
if(Z > Y)
Y = Z;
}
return Y;
}

The value returned by the function MyX is the


(A) maximum possible sum of elements in any sub-array of array E.
(B) maximum element in any sub-array of array E.
(C) sum of the maximum elements in all possible sub-arrays of array E.
(D) the sum of all the elements in the array E.

answer is (A) maximum possible sum of elements in any sub-array of array E.


int MyX ( int * E, unsinged int size )
{
int Y= 0;
int z;
int i, j,k;
for i 0;i<size;i++) // calculate sum of the elements
Y= Y+E[i];

// of the array E and stores it in Y

for (i=0;i<size;i++)
for(j=i;j<size ;j++)
{

// calculate the
// sum of
// elements of

z = 0;

// all possible

for(k=i; k<=j;k++) // subarrays


z=z+E[k];

// of E

if(z>Y)
// checks whether sum of elements of each subarray is greater than the sum of array if
is assigned toY will be the sum of elements of complete array

// so, that sum

Y = z;

}
return Y; // ultimately returns the maximum possible sum of elements in any sub array of given array E
}

-- Kalpna Bhargav

GATE2014-2_38 top
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by
merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing
this is ____.

The optimal algorithm always chooses the smallest sequences for merging.

20 24 -44, 43 comparisons
30 35 -65, 64 comparisons
44 50 -94, 93 comparisons
65 94 -159, 158 comparisons

so, totally 43 + 64 + 93 + 158 = 358 comparisons.

-- Arjun Suresh

GATE2014-3_10 top
Let A be the square matrix of size n n . Consider the following pseudocode. What is the expected output?
C=100;
for i=1 to n do
for j=1 to n do
{
Temp = A[i][j]+C;
A[i][j] = A[j][i];
A[j][i] = Temp -C;
}
for i=1 to n do
for j=1 to n do
output (A[i][j]);

(A) The matrix A itself


(B) Transpose of the matrix A
(C) Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
(D) None of the above

A.
In the computation of given pseudo code for each row and column of Matrix A, each upper
triangular element will be interchanged by its mirror image in the lower triangular and after
that the same lower triangular element will be again re-interchanged by its mirror image in
the upper triangular, resulting the final computed Matrix A same as input Matrix A.
-- Gate Keeda

GATE2014-3_12 top
Consider the following rooted tree with the vertex labeled P as the root:

The order in which the nodes are visited during an in-order traversal of the tree is
(A) SQPTRWUV
(B) SQPTUWRV
(C) SQPTWUVR

(D) SQPTRUWV

A.
the inorder traversal order of a ternary tree is left-->root-->middle-->right.
-- Gate Keeda

GATE2014-3_13 top
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first
checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is _________.

19. apply DFS.


-- Gate Keeda

GATE2014-3_37 top
Suppose you want to move from

0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a

pre-specified pair of integers i, j with i < j . Given a shortcut i, j if you are at position i on the number line, you may directly move to j . Suppose T (k) denotes
the smallest number of steps needed to move from k to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is
a shortcut to 15. Let

y and z be such that T (9) = 1 + min(T (y), T (z)). Then the value of the product yz is _____.

T(9) = Distance from 9 to 100


T(9)=1+ min(T(y),T(z))=1+min(Distance from y to 100 , Distance from z to 100)
There are only two such values where we can reach from 9 , one is simple step to right on number line , i.e 10 and another is 15 (given
shortcut)
Hence , y=10 , z=15
yz=10x15 = 150
-- Srinath Sri

GATE2011_25 top
An algorithm to find the length of the longest monotonically increasing sequence of numbers in an arrayA[0 : n 1] is given below.
Let L i , denote the length of the longest monotonically increasing sequence starting at indexi in the array.
Initialize L n1 = 1.
For all i such that 0 i n 2

Li = { 1 + Li+1
1

if A[i] < A[i+1]


Otherwise

Finally the the length of the longest monotonically increasing sequence isMax (L 0 , L 1 , , L n1 ).
Which of the following statements is TRUE?
(A) The algorithm uses dynamic programming paradigm
(B) The algorithm has a linear complexity and uses branch and bound paradigm

(C) The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm
(D) The algorithm uses divide and conquer paradigm

(A) is the answer.


The algorithm is storing the optimal solutions to subproblems at each point (for each i), and then using it to derive the optimal solution of a
bigger problem. And that is dynamic programming approach. And the program has linear time complexity.
http://stackoverflow.com/questions/1065433/what-is-dynamic-programming
Now, branch and bound comes when we explore all possible solutions (branch) and backtracks as soon as we find we won't get a solution (in
classical backtracking we will retreat only when we won't find the solution). So, backtracking gives all possible solutions while branch and
bound will give only the optimal one. http://www.cs.cornell.edu/~wdtseng/icpc/notes/bt2.pdf
The given algorithm here is neither backtracking nor branch and bound. Because we are not branching anywhere in the solution space.
And the algorithm is also not divide and conquer as we are not dividing the problem and then merging the solution as in the case of merge
sort (where merge is the conquer step).
https://en.wikipedia.org/wiki/Divide_and_conquer_algorithms
-- Arjun Suresh

GATE2010_34 top
The weight of a sequence a 0 , a 1 , , a n1 of real numbers is defined as a 0 + a 1 /2 + + a n1 /2 n1 . A subsequence of a sequence is obtained by
deleting some elements from the sequence, keeping the order of the remaining elements the same. Let X denote the maximum possible weight of a subsequence
of

a o , a 1 , , a n1 and Y the maximum possible weight of a subsequence of a 1 , a 2 , , a n1 . Then X is equal to

(A)

max(Y , a 0 + Y )

(B)

max(Y , a 0 + Y /2)

(C) max(Y , a 0
(D) a 0

+ 2Y )

+ Y /2

Two possible cases arise:


1.

is included in the max weight subsequence of :


In
this case,

2.

is not included in the max weight subsequence of :


In this case,

Since the value of

can be negative

, it is possible that

The maximum possible weight of a subsequence of

-- Pragy Agarwal

GATE1997_1.5

top

is given by:

answer B
-- ankitrokdeonsns

GATE1997_4.2

top

c is the answer, in AI12 matrix will result into the same matrix as A but first column will be exchanged with second column.
A matrix:
a b c
d e f
g h i
I12 matrix
010
100
001
resulted matrix
bac
edf
hgi
-- Manu Thakur

GATE1997_4.6

top

answer B
using master method (case 1)
where a = 2, b = 2
O(n1/2) < O(nlogba)
O(n1/2) < O(nlog22)

-- ankitrokdeonsns

GATE1997_6.2

top

Let G be the graph with 100 vertices numbered 1 to 100. Two vertices i and j are adjacent if |
The number of connected components in G is

i j| = 8 or | i j| = 12.

a. 8
b. 4
c. 12
d. 25

From the description it is clear that vertices are connected as follows:


1-9-17-...-97
2-10-18-...-98
3-11-19-...-99
4-12-20-...-100
5-13-21-...-93
6-14-22-...-94
7-15-23-...-95
8-16-24-...96
We have covered all vertices using 8 vertex sets considering only i j = 8 . Using i j = 12 we can see the vertex 1 is connected to 13,
2-14, 3-15 and 4-16, so the top 4 vertex sets are in fact connected to the bottom 4 sets, thus reducing the connected components to 4.
-- Arjun Suresh

GATE1993_7.4

top

Answer is simply A i.e. it swaps the values of the two.. Take any two values for A and B. and perform the given operations over them.
-- Gate Keeda

GATE2010_35 top
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);
}
int main()
{
int a[] = (12, 7, 13, 4, 11, 6);
printf("%d", f(a, 6));
return 0;
}

(A) -9

(B) 5
(C) 15
(D) 19

It will print
12 + ( 7 - (13 - (4 + (11 - ( 6 + 0)))))
= 12 + (7 - (13 - ( 4 + ( 11 -6)))))
= 12 + 7 - 13 + 9
= 15
-- gatecse

GATE2010_36 top
The following C function takes a singly-linked list as input argument. It modifies 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 *move_to-front(Node *head) {
Node *p, *q;
if ((head == NULL) || (head -> next == NULL)) return head;
q = NULL; p = head;
while (p->next != NULL){
q=p;
p=p->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;

as per given code p points to last node which should be head in modified.
q is the previous node of tail which should be tail for modified
answer D
-- Sankaranarayanan P.N

GATE2010_50,51 top
Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry

W ij in the matrix W below is the weight of the edge {i, j}

Q.50 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
(B) 8
(C) 9
(D) 10

Q.51 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
(D) 10

Answer for 50 is (D) 10. The edges of the spanning tree are: 0 - 1, 1 - 3, 3 - 4, 4 - 2. Total Weight = 10
Answer for 51 is (B) 8. The possible path is: 1 - 0, 0 - 4, 4 - 2.
-- Ashis Kumar Sahoo

GATE1994_1.7

top

It is A. searching for only one half of the list. leading to T(n/2) + constant time in comparing and finding mid element.
-- Gate Keeda

GATE1994_1.11 top

J+(sum of natural number till i-1) because if you form a lower triangular matrix it contains elements in rows 1,2,3,... so c is the correct answer
-- Bhagirathi Nayak

GATE1994_1.17 top

B. Because in binary search we need to have access to the mid of the list in constant time. and finding the mid itself in a linked list takes O(n)
time which makes no sense to Binary search which takes O(logn).
-- Gate Keeda

GATE1994_1.19 top

C. it is one of the efficient algorithms in Divide and Conquer strategy.


-- Gate Keeda

GATE1994_1.23 top

For complexity, we assume sufficiently large n. So, g1(n) = n2 and g2(n) = n3. Growth rate of g1 is less than that of g2. i.e., g1(n) = O(g2(n))
-- Arjun Suresh

GATE1994_6

top

answer - xn
-- ankitrokdeonsns

GATE1994_25 top

i=1
j=n
while(i != j) {
if(A[i] + A[j] == M) break;
else if(A[i] + A[j] < M) i++;
else j--; [EDIT]
}
-- ankitrokdeonsns

GATE1995_1.5

top

It is A.
One of the best examples of Divide and conquer strategy.
-- Gate Keeda

GATE1995_1.16 top

It is C.
The number of moves are however always m+n so that we can term it as theta(m+n). But the number of comparisons vary as per the input. In
the best case the comparisons are Min(m,n) and in worst case they are m+n-1.
-- Gate Keeda

GATE1995_2.9

top

C.
concat(a,head(tail(tail(acbc))))
concat(a,head(tail(cbc)))
concat(a,head(bc))
concat(a,b)
ab.
-- Gate Keeda

GATE1995_2.22 top

Its D according to me.


Binary search using linked list is not efficient as it will not give O(logn), because we will not be able to find the mid in constant time. Finding
mid in linked list takes O(n) time.
Recursive programs are not efficient because they take a lot of space, Recursive methods will often throw StackOverflowException while
processing big sets. moreover it has its own advantages too.
-- Gate Keeda

GATE1995_12 top

1st Pass: 37 52 12 11 25 92

2nd Pass: 37 12 11 25 52 92
3rd Pass: 12 11 25 37 52 92
4th Pass: 11 12 25 37 52 92
5th Pass: 11 12 25 37 52 92
-- Gate Keeda

GATE1995_22 top

2 only.
{AB,BC,AE,BD} and {AB,BC,AE,CD}.
-- Gate Keeda

GATE1996_2.13 top
The average number of key comparisons done on a successful sequential search in a list of length n is
(a) log n
(b)

n1
2

(c)

n
2

(d)

n+1
2

Expected number of comparisons


= 1 Probability of first element be x + 2 Probability of second element be x + .... +n Probability of last element be x.
1
n

= 1
=
=
=

1
n
(

+2

2
n

n(n+1)
2

3
n

n1
n

+. . . . +

1
n1

+. . . . . +n

n
n

n+1
2

-- Arjun Suresh

GATE1996_2.15 top

C.
both are the worst cases of quick sort.

n1
n

n2
n1

...

1
2

i) is sorted in ascending order.


ii) is sorted in descending order.
-- Gate Keeda

GATE1996_16 top

minimum spanning tree


-- Anu

GATE1996_18 top

the code is wrong here ....k=(i+j) / 2;


if(a[k] < x) then i = k ;
else j = k ;
the (correct) code should be ..
k=(i+j) / 2;
if(a[k] < x) then i = k +1 ;
else j = k -1 ;
try an example ....with given code in question
let an array
a[1,2,3,4,5,6,7,8,9,10]
index number
1,2,3,4,5,6,7,8,9,10
and x=10 ; now run the code ;
initially i = 1 ,j=10;
first time k =(i+j) /2 = 11/2 =5.5 = 5 (because of integer type) =i
second time = k =(i+j) /2 =15/2 =7.5 =7 =i

third time = k =(i+j) /2 = 17/2 = 8.5 = 8 =i


fourth time = k =(i+j) /2 = 18/2 = 9 = i
fifth time = k =(i+j) /2 = 19/2 = 9.5 =9 = i
sixth time = k =(i+j) /2 = 19/2 = 9.5 =9 = i
seventh time = k =(i+j) /2 = 19/2 = 9.5 =9 = i
.................................................................
going to infinite loop (run time error) .... ;
for terminating loop , it should be , i = k + 1 instead of i =k ;and j = k - 1 instead of j = k ;
correct me ....???
-- csegate2

GATE2008-IT_11 top
For problems X and Y, Y is NP-complete and X reduces to Y in polynomial time. Which of the following is TRUE?

A)

If X can be solved in polynomial time, then so can Y

B)

X is NP-complete

C)

X is NP-hard

D)

X is in NP, but not necessarily NP-complete

We can't say X is NP hard unless until X is also a NP-complete. X can be NP-complete or below it.. that means it belongs to NP class, in that
class(in NP class) it may be NP-complete.. so X is NP for sure but may be NP-complete(but not neccessary).. so option (D)...
-- Vicky Bajoria

GATE2008-IT_12 top
Which of the following is TRUE?

1) The cost of searching an AVL tree is (log n) but that of a binary search tree is O(n)
2) The cost of searching an AVL tree is (log n) but that of a complete binary tree is (n log n)
3) The cost of searching a binary search tree is O (log n ) but that of an AVL tree is (n)
4) The cost of searching an AVL tree is (n log n) but that of a binary search tree is O(n)

1) is true as AVL tree is a balanced search tree that has time complexity of searching
completely left/right skewed tree, in which search is O(n).

, but in binary search tree, we can have a

-- Happy Mittal

GATE2007-IT_3 top
Consider a weighted undirected graph with positive edge weights and let uv be an edge in the graph. It is known that the shortest path from the
source vertex s to u has weight 53 and the shortest path from s to v has weight 65. Which one of the following statements is always true?

A)

weight (u, v) < 12

B)

weight (u, v) 12

C)

weight (u, v) > 12

D)

weight (u, v) 12

D. weight(u,v) 12
If weight (u, v) < 12, then the min. weight of (s, v) = weight of (s, u) + weight of (u, v) = 53 + (<12) will be less than 65.

-- Arjun Suresh

GATE2007-IT_27 top
The function f is defined as follows:
int f (int n) {
if (n <= 1) return 1;
else if (n % 2 == 0) return f(n/2);
else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
i.
ii.
iii.
iv.

The function f terminates for finitely many different values of n 1.


The function f terminates for infinitely many different values of n 1.
The function f does not terminate for finitely many different values of n 1.
The function f does not terminate for infinitely many different values of n 1.

Which one of the following options is true of the above?

A)

(i) and (iii)

B)

(i) and (iv)

C)

(ii) and (iii)

D)

(ii) and (iv)

The function terminates for all powers of 2 (which is infinite), hence (i) is false and (ii) is TRUE.
Let n = 5.
Now, recursive calls will go like 5 - 14 - 7 - 20 - 10 - 5 And this goes into infinite recursion. And if we multiply 5 with any power of 2, also result will be infinite recursion. Since, there are infinite
powers of 2 possible, there are infinite recursions possible (even considering this case only). So, (iv) is TRUE and (iii) is false.
So, correct answer is (D)

-- Arjun Suresh

GATE2006-IT_10 top
A problem in NP is NP-complete if

A)

it can be reduced to the 3-SAT problem in polynomial time

B)

the 3-SAT problem can be reduced to it in polynomial time

C)

it can be reduced to any other problem in NP in polynomial time

D)

some problem in NP can be reduced to it in polynomial time

(B) A problem in NP becomes NPC if all NP problems can be reduced to it in polynomial time. This is same as reducing any of the NPC
problem to it. 3-SAT being an NPC problem, reducing it to a NP problem would mean that NP problem is NPC.
http://gatecse.in/wiki/NP,_NP_Complete,_NP_Hard
-- Arjun Suresh

GATE2004-IT_58 top
Consider the following C program which is supposed to compute the transpose of a given 4 x 4 matrix M. Note that, there is an X in the
program which indicates some missing statements. Choose the correct option to replace X in the program.
#include<stdio.h>
#define ROW 4

#define COL 4
int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
main()
{
int i, j, t;
for (i = 0; i < 4; ++i)
{
X
}
for (1 = 0; i < 4; ++i)
for (j = 0; j < 4; ++j)
printf ("%d", M[i][j]);
}

for(j = 0; j < 4; ++j){


t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}

A)

for(j = 0; j < 4; ++j){


M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}

B)

for(j = i; j < 4; ++j){


t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}

C)

for(j = i; j < 4; ++j){


M[i][j] = t;
t = M[j][i];
M[j][i] = M[i][j];
}

D)

option C:
look at the initial value ofj, if j starts with 0, then double for loop will swap M[i][j] with M[j][i] and also M[j][i] and M[i][j] so the matrix M will
remain unchanged, so to avoid this double swapping we need to initialize j = i and swap only upper triangular matrix with lower triangular
matrix.

for(j = i; j < 4; ++j){


// code for swapping M[i][j] with M[j][i]
t = M[i][j];
M[i][j] = M[j][i];
M[j][i] = t;
}
-- Vikrant Singh

GATE2005-IT_52 top
Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G
containing the edge e. Which of the following statements is always TRUE?

A)

There exists a cutset in G having all edges of maximum weight.

B)

There exists a cycle in G having all edges of maximum weight.

C)

Edge e cannot be contained in a cycle.

D)

All edges in G have the same weight.

Option a is always true


Option b is not true when e is not part of a cycle.
Option c is not true when e is part of a cycle and all edge weights are same in that cycle
Option d is need not be true when e is not part of a cycle
Option a is always true as only the min weight edge in a cut set will be part of a minimum spanning tree.
-- Bhagirathi Nayak

GATE2005-IT_53 top
The following C function takes two ASCII strings and determines whether one is an anagram of the other. An anagram of a string s is a string
obtained by permuting the letters in s.
int anagram (char *a, char *b) {
int count [128], j;
for (j = 0; j < 128; j++) count[j] = 0;
j = 0;
while (a[j] && b[j]) {
A;
B;
}
for (j = 0; j < 128; j++) if (count [j]) return 0;
return 1;
}

Choose the correct alternative for statements A and B.

A)

A : count [a[j]]++ and B : count[b[j]]--

B)

A : count [a[j]]++ and B : count[b[j]]++

C)

A : count [a[j++]]++ and B : count[b[j]]--

D)

A : count [a[j]]++and B : count[b[j++]]--

The answer is D
#include <stdio.h>
int main(void) {
return 0;
}
int anagram (char *a, char *b) {
/*
ASCII characters are of 7-bits
so we use count array to represent all the ASCII characters
(ranging 0-127)
*/
int count [128], j;
/*
so this loop will initialize count of all the ASCII characters to be
0 (zero)
*/
for (j = 0; j < 128; j++) count[j] = 0;
j = 0;
/*
"a[j] && b[j]" ensures that anagram returns 0 (false) in case both
strings have different length. Because different length strings cannot
be anagram of each other
*/
/*
Logic:
Below while loop increments ASCII equivalent position for its occurence
in array 'a'in count array; and decrements ASCII equivalent position
for its occurence in array 'b'in count array.
Example: a = "ISS" and b = "SIS"
ASCII equivalent of:

I - 73
S - 83
j = 0: Statement A will increment count[ASCII of 'I']==>count[73]
count[73] = 0 --> 1
Statement B will decrement count[ASCII of 'S'] ==> count[83]
count[83] = 0 --> -1 and will increment j j = 0 --> 1
j = 1: Statement A will increment count[ASCII of 'S'] ==> count[83]
count[83] = -1 --> 0
Statement B will decrement count[ASCII of 'I'] ==> count[73]
count[73] = 1 --> 0 and will increment j j = 1 --> 2
j = 2: Statement A will increment count[ASCII of 'S'] ==> count[83]
count[83] = 0 --> 1
Statement B will decrement count[ASCII of 'S'] ==> count[83]
count[83] = 1 --> 0 and will increment j j = 2 --> 3
*** END OF LOOP ***
*/
while (a[j] && b[j]) {

A; //count [a[j]]++
/*
Note: j will be increment after count[]-- will execute
Resource: http://www.c4learn.com/c-programming/increment-operator-inside-printf
*/
B; //count[b[j++]]-}
/*
This loop checks that the number of occurences of the individual ASCII
characters is same or not.
If count[i] = 0 ---> same number of occurences for ASCII chracter i
---> return 1 (true)
if count[i]!= 0 ---> different number of occurences for ASCII chracter i
---> return 0 (false)
*/
for (j = 0; j < 128; j++) if (count [j]) return 0;
return 1;
}

-- Sohil Ladhani

GATE2005-IT_57 top
What is the output printed by the following program?
#include <stdio.h>
int f(int n, int k) {
if (n == 0) return 0;
else if (n % 2) return f(n/2, 2*k) + k;
else return f(n/2, 2*k) - k;
}
int main () {
printf("%d", f(20, 1));
return 0;
}

A)

B)

C)

D)

20

The sequence has to be followed.


6.) f(20,1) = 9.
5.) f(10,2) - 1 = 9
4.) f(5,4) - 2 = 10
3.) f(2,8) + 4 = 12

2.) f(1,16) - 8 = 8
1.) f(0,32) + 16 = 16
-- Gate Keeda

GATE2005-IT_58 top
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the
array whose difference is a specified number S > 0.
i = 0; j = 1;
while (j < n ){
if (E) j++;
else if (a[j] - a[i] == S) break;
else i++;
}
if (j < n) printf("yes") else printf ("no");

Choose the correct expression for E.

A)

a[j] - a[i] > S

B)

a[j] - a[i] < S

C)

a[i] - a[j] < S

D)

a[i] - a[j] > S

Answer is (B)
For some 'i' if we find that difference of ( A[j] - A[i] <S )we increment 'j' to make this difference wider so that it becomes equal to S .
If at times difference becomes greater than S we know that it wont reduce further for same 'i' and so we increment the .'i'
We do it for each 'i' if not found in previous iteration.until i=n
-- Sandeep_Uniyal

GATE2005-IT_59 top
Let a and b be two sorted arrays containing n integers each, in non-decreasing order. Let c be a sorted array containing 2n integers obtained by
merging the two arrays a and b. Assuming the arrays are indexed starting from 0, consider the following four statements
I.
II.
III.
IV.

a[i] b [i] => c[2i] a [i]


a[i] b [i] => c[2i] b [i]
a[i] b [i] => c[2i] a [i]
a[i] b [i] => c[2i] b [i]

Which of the following is TRUE?

A)

only I and II

B)

only I and IV

C)

only II and III

D)

only III and IV

a[i] b[i]
Since both a and b are sorted in the beginning, there are i elements smaller than a[i] (i starts from 0), and similarly i elements smaller than b[i].
So, a[i] b[i] means there are 2i elements smaller than a[i], and hence in the merged array a[i] can come only after these 2i elements (its
index will be > 2i). So, c[2i] a[i] (equality only comes when array contains repeated elements)
Similarly, a[i] b[i] says for b that, there are not more than 2i elements smaller than b[i] in the sorted array (i elements from b, and maximum
another i elements from a). So, b[i] c[2i]
So, II and III are correct -> option (C)
-- Arjun Suresh

GATE2005-IT_84a

top

A sink in a directed graph is a vertex i such that there is an edge from every vertex j i to i and there is no edge from i to any other vertex. A
directed graph G with n vertices is represented by its adjacency matrix A, where A[i] [j] = 1 if there is an edge directed from vertex i to j and 0
otherwise. The following algorithm determines whether there is a sink in the graph G.
i = 0;
do {
j = i + 1;
while ((j < n) && E1) j++;
if (j < n) E2;
} while (j < n);
flag = 1;
for (j = 0; j < n; j++)
if ((j! = i) && E3) flag = 0;
if (flag) printf("Sink exists");
else printf ("Sink does not exist");

Choose the correct expressions for E1 and E2

A)

E1 : A[i][j] and E2 : i = j;

B)

E1 : !A[i][j] and E2 : i = j + 1;

C)

E1: !A[i][j] and E2 : i = j;

D)

E1 : A[i][j] and E2 : i = j + 1;

If there is a sink in the graph, the adjacency matrix will contain all 1's(except diagonal) in one column and all 0's (except diagonal) in the
corresponding row of that vertex. The given algorithm is a smart way of doing this as it finds the sink in O(n) time complexity.
The first part of the code, is finding if there is any vertex which doesn't have any outgoing edge to any vertex coming after it in adjacency
matrix. The smart part of the code is E2, which makes rows skip when there is no edge from i to it, making it impossible them to form a sink.
This is done through
E1: !A[i][j]
and
E2: i = j;
E1 makes sure that there is no edge from i to j and i is a potential sink till A[i][j] becomes 1. If A[i][j] becomes 1, i can no longer be a sink,
similarly all previous j can also not be a sink (as there was no edge from i to them and a sink requires an edge from all other vertices). Now,
the next potential candidate for sink is j. So, in E2, we must make i = j.
So, answer is (C)
For E3,
http://gateoverflow.in/3857/gate2005-it_84b
-- Arjun Suresh

Hashing

top

Consider the following, five binary strings of length 8.


01010010, 11011011, 10011010, 11111011, 01110010
A hash table of size M = 8 (0 to 7) is using open addressing for hashing the binary strings. Assume finding an empty slot directly without
collision or after collision is also a probe. Calculate the total number of probes that occur while hashing five strings using linear probing.

Assuming mod 8 function for hashing


01010010 mod 8 = 010 = 2 (1 probe, goes to slot 2)
11011011 mod 8 = 011 = 3 (1 probe, goes to slot 3)
10011010 mod 8 = 010 = 2 (3 probes, goes to slot 4)

11111011 mod 8 = 011 = 3 (3 probes, goes to slot 5)


01110010 mod 8 = 010 = 2 (5 probes, goes to slot 6)
So, total number of probes = 13
http://webdocs.cs.ualberta.ca/~holte/T26/open-addr.html
-- Arjun Suresh

Time Complexity top


i=0
for(i=1;i<=n;++i)
for(j=1;j<=i*i;++j)
if((j%i)==0)
for(k=1;k<=j;++k)
c=c+1;

find time complexity of these program?

(The third loop executes only when j%i == 0, which will be true for j = i, 2i, 3i, ... i*i. i.e., it also executes i times. )
We have to count the number of times the statement c = c + 1; is executed.
the outer i loop executes from 1 to n.
for i = 1, 2, 3, 4, ... n
the k loop will execute for
1, 2 + 4, 3 + 6 + 9, 4 + 8 + 12 + 16, ... ,n + 2n + 3n + ...2n
So, we have to count the iterations for k, which will give

ni=1 ij=1 j i
= 1 + 6 + 18 + 40+. . . +n n
= ni=1 i i
= O(n 4 )

i+1
2

n+1
2

(We can assume the sum to the cubes of first n natural numbers)
-- Arjun Suresh

What is the complexity of finding 50th smallest element in an already constructed binary
min-heap? top

It is constant.as long as number is independent of n it can be found with kk-1/2 Comparisons.


-- Anurag_s

GATE2015-2_2 top

Consider two decision problems Q 1 , Q 2 such that Q 1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time toQ 2 . Then
which one of the following is consistent with the above statement?

A.
B.
C.
D.

Q 1 is in NP, Q 2 is NP hard.
Q 2 is in NP, Q 1 is NP hard.
Both Q 1 and Q 2 are in NP.
Both Q 1 and Q 2 are in NP hard.

3-SAT is NP-Complete and hence in NP as well as NP-hard.


Now, any less or equally hard problem can be reduced (in polynomial time) to 3-SAT. So, Q1 reducing to 3-SAT means Q1 is less harder than
3-SAT- can be P or NP. Since P NP. Q1 is in NP, need not be NP-Hard.
3-SAT reducing (in polynomial time) to Q2 means Q2 is harder or as hard as 3-SAT meaning Q2 is also NP-Hard. Q2, need not be in NP.
So, A option only is always correct.
-- Arjun Suresh

GATE2015-2_11 top
Consider the following C function.
int fun(int n) {
int x=1, k;
if (n==1) return x;
for (k=1; k<n; ++k)
x = x + fun(k) * fun (n-k);
return x;
}

The return value of fun(5) is ______.

fun(1) = 1;
fun(2) = 1 + fun(1) * fun(1) = 1 + 1 = 2;
fun(3) = 1 + fun(1) * fun(2) + fun(2) * fun(1) = 5;
fun(4) = 1 + fun(1) * fun(3) + fun(2) * fun(2) + fun(3) * fun(1) = 1 + 5 + 4 + 5 = 15;
fun(5) = 1 + fun(1) * fun(4) + fun(2) * fun(3) + fun(3) * fun(2) + fun(4) * fun(1) = 1 + 15 + 10 + 10 + 15 = 51;
-- Arjun Suresh

GATE2015-1_6 top
Match the following:

A.
B.
C.
D.

P-iii, Q-ii, R-iv, S-i


P-i, Q-ii, R-iv, S-iii
P-ii, Q-iii, R-iv, S-i
P-ii, Q-i, R-iii, S-iv

option c is correct ..
-- Anoop Sonkar

(P) Prim's algorithm for minimum spanning tree

(i) Backtracking

(Q) Floyd-Warshall algorithm for all pairs shortest paths

(ii) Greedy method

(R) Mergesort

(iii) Dynamic programming

(S) Hamiltonian circuit

(iv) Divide and conquer

GATE2015-2_22 top
An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum
is

A.
B.
C.
D.

(n log n)
(n)
(log n)
(1)

Ans O(1), because all elements are distinct, select any three numbers and output 2nd largest from them.
-- Vikrant Singh

GATE2015-2_36 top
Given below are some algorithms, and some algorithm design paradigms.
1. Dijkstra's Shortest Path

i. Divide and Conquer

2. Floyd-Warshall algorithm to compute all pairs


ii. Dynamic Programming
shortest path
3. Binary search on a sorted array

iii. Greedy design

4. Backtracking search on a graph

iv. Depth-first search


v. Breadth-first search

Match the above algorithms on the left to the corresponding design paradigm they follow.

A.
B.
C.
D.

1-i, 2-iii, 3-i, 4-v


1-iii, 2-iii, 3-i, 4-v
1-iii, 2-ii, 3-i, 4-iv
1-iii, 2-ii, 3-i, 4-v

Answer: C
-- Jon Snow

GATE2015-1_31 top
Consider the following C function.
int fun1 (int n) {
int i, j, k, p, q = 0;
for (i = 1; i < n; ++i) {
p = 0;
for (j = n; j > 1; j = j/2)
++p;
for (k = 1; k < p; k = k * 2)
++q;
}
return q;
}

Which one of the following most closely approximates the return value of the function fun1?
A. n3
B. n(log n)2
C. n log n
D. n log(log n)

i loop is executing n times. j loop is executing log n times for each i, and so value of p is log n. k loop is executing log p times, which is log log
n times for each iteration of i. In each of these q is incremented. So, over all iterations of i, q will be incremented n log log n times. So, D
choice.
-- Arjun Suresh

GATE2015-1_45 top
Let G = (V, E) be a simple undirected graph, and s be a particular vertex in it called the source. For xV, let d(x) denote the shortest distance in
G from s to x. A breadth first search (BFS) is performed starting at s. Let T be the resultant BFS tree. If (u, v) is an edge of G that is not in T,
then which one of the following CANNOT be the value of d(u) - d(v)?
A.
B.
C.
D.

-1
0
1
2

2 is the answer.
d(u) - d(v) = 0 is possible when both u and v have an edge from t and t is in the shortest path from s to u or v.
d(u) - d(v) = 1 is possible when u is in the shortest path from s to v, and t is also in the shortest path from s to v and both t and s are siblingssame distance from s to both t and u causing t-v edge to be in BFS tree and not u-v.
d(u) - d(v) = -1 is possible as explained above by interchanging u and v.
d(u) - d(v) = 2 is not possible. This is because on BFS traversal we either visit u first or v. Let's take u first. Now, we put all neighbors of u on
queue. Since v is a neighbour and v is not visited before as assumed, d(v) will become d(u) + 1. Similarly, for v being visited first.
-- Arjun Suresh

GATE2015-1_49 top
Let an represent the number of bit strings of length n containing two consecutive 1s. What is the recurrence relation foran ?
A.
B.
C.
D.

an2 + an1 + 2 n2
an2 + 2an1 + 2 n2
2an2 + an1 + 2 n2
2an2 + 2an1 + 2 n2

Counting the number of bit strings NOT containing two consecutive 1's. (It is easy to derive a recurrence relation for the NOT case as shown
below.)
01
00 01 10 - 3 (append both 0 and 1 to any string ending in 0, and append 0 to any string ending in 1)
000 001 010 100 101 - 5 (all strings ending in 0 give two strings and those ending in 1 give 1 string)
0000 0001 0010 0100 0101 1000 1001 1010 - 8
....

an' = an-1' + an-2' (where an denote the number of bit strings of length n containing two consecutive 1s)
2n - an = (2n-1 - an-1) + (2n-2 - an-2)
an = 2n-2(4 - 2 - 1) + an-1 + an-2
an = an-1 + an-2 + 2n-2
A choice.

-- Arjun Suresh

GATE2015-3_4 top
Consider the equality n(i=0) i3 = X and the following choices for X
I.
II.
III.
IV.

(n 4 )
(n 5 )
O(n 5 )
(n 3 )

The equality above remains correct if X is replaced by

A.
B.
C.
D.

Only I
Only II
I or III or IV but not II
II or III or IV but not I

Sum of the cubes of the first n natural numbers is given by (n(n+1)/2 2) which is (n4). So, I, III and IV are correct. II is wrong. C choice.
-- Arjun Suresh

GATE2015-3_27 top
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely
approximates the maximum input size of a problem that can be solved in 6 minutes?

A.
B.
C.
D.

256
512
1024
2018

The worst case time complexity of Mergesort is k n log n for an input of size n .
For an input of size 64, the algorithm takes 30s. Therefore,

k 64 log2 64 = 30s

k 384 = 30s

k = 0.078125s
Let the size of the problem that can be solved in 6 minutes be x. Then,

k x log2 x = 360s
From this, we get:

x log2 x =

360s
0.078125s

x = 512
-- Pragy Agarwal

GATE2015-3_30 top
Consider the following two C code segments. Y and X are one and two dimensional arrays of sizen and n n respectively, where
2 n 10 . Assume that in both code segments, elements ofY are initialized to 0 and each element X[i][j] of array X is initialized to i + j.

Further assume that when stored in main memory all elements of X are in same main memory page frame.
Code segment 1:
// initialize elements of Y to 0
// initialize elements of X[i][j] of X to i+j
for (i=0; i<n; i++)
Y[i] += X[0][i];

Code segment 2:
// initialize elements of Y to 0
// initialize elements of X[i][j] of X to i+j
for (i=0; i<n; i++)
Y[i] += X[i][0];

Which of the following statements is/are correct?


S1: Final contents of array Y will be same in both code segments
S2: Elements of array X accessed inside the for loop shown in code segment 1 are contiguous in main memory
S3: Elements of array X accessed inside the for loop shown in code segment 2 are contiguous in main memory

A.
B.
C.
D.

Only S2 is correct
Only S3 is correct
Only S1 and S2 are correct
Only S1 and S3 are correct

option C. Only S1 and S2 are correct because Y have same element in both code and in code1

Y[i] += X[0][i];
this row major order (In C, arrays are stored in row-major order) which gives address of each element in sequential order(1,2,3,....,n) means
we cross single element each time to move next shows contiguous in main memory but in code2 for

Y[i] += X[i][0];
we are crossing n element (row crossing with n element )to move next

-- Anoop Sonkar

GATE2015-3_39 top
Consider the following recursive C function.
void get(int n)
{
if (n<1) return;
get (n-1);
get (n-3);
printf("%d", n);
}

If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?

A.
B.
C.
D.

15
25
35
45

T(n) = T(n-1) + T(n-3) + 2


T(n<=0) = 0
T(1) = 2
T(2) = 4
T(3) = 6
T(4) = 10
T(5) = 16
T(6) = 24

So, answer is 24 + 1 call from main = 25.


-- Arjun Suresh

GATE2015-3_40 top
Let G be a connected undirected graph of 100 vertices and 300 edges. The weight of a minimum spanning tree ofG is 500. When the weight of
each edge of G is increased by five, the weight of a minimum spanning tree becomes ______.

first find no of edges in mst...


mst has n-1 edges where n is no of vertices. 100-1 =99 edges
each 99 edges in mst increases by 5 so weight in mst increased 99*5=495
now total weight of mst =500+495=995
-- Anoop Sonkar

GATE2015-3_42 top
Let f(n) = n and g(n) = n (1+sin n) where n is a positive integer. Which of the following statements is/are correct?
I. f(n) = O(g(n))
II. f(n) = (g(n))

A.
B.
C.
D.

Only I
Only II
Both I and II
Neither I nor II

The answer is option D.


Since the value of sin(n) will always range from -1 to +1, hence g(n) can take values 1, n, n^2.
Hence, if g(n) = 1, Statement I is incorrect.
And, if g(n) = n^2, then Statement II is incorrect.
-- saurabhrk

GATE2015-3_49 top
Suppose c = c[0], , c[k 1] is an array of length k, where all the entries are from the set {0, 1}. For any positive integersa and n, consider
the following pseudocode.
DOSOMETHING (c, a, n)
z1

for i 0 to k 1

do z z 2 mod n
if c[i]=1
then z (z a) mod n

return z

If k = 4, c = 1, 0, 1, 1, a = 2, and n = 8 , then the output of DOSOMETHING(c, a, n) is _______.

Initially k = 4, c = [1, 0, 1, 1], a = 2, n = 8


now let's iterate through the function step by step :
z = 1 (at the start of do-something)

i = 0 (start of external for loop)


in the do loop
z = 1*1 % 8 = 1 (non zero value so considered as true and continue)
c[0] = 1 so in the if clause z = 1*2 % 8 = 2
in the do loop
z = 2*2 % 8 = 4 (since now z = 2) (non zero value so considered as true and continue)
c[0] = 1 so in the if clause z = 4*2 % 8 = 0
now no need to check further :
reason all the operations that update Z are multiplicative operations and hence the value of Z will never change from 0.
-- Tamojit Chatterjee

minimum number of comparison required to compute the largest and second largest
element in an array is top
a) n- ( lg(n)) - 2
b) n + (lg(n)-2)

we can start comparing the elements pair wise and build a decision tree in which case it takes n-1 comparisons to obtain the highest element.
In order to get the second highest element we need to check only those elements which were compared with the highest element while building the decision tree, now as the height of the
tree is logn as logn comparisons are required for the highest element to reach the top, so to obtain second highest element one need logn-1 comparisons so all together n-1+logn-1=n+logn-2
comparisons are required.

-- computer science research

common data Linked quetion :- 1) which of the following is correct recurrence formula of
I(j) 2)how to evaluate this R.R top
At the end of it's 5th Successful season,The siruseri Permier league is planning to give an award to most improved bowler over 5 years . For
this an important Index will be computed for each bowler,This is defined as the longest Subsequence of strictly decreasing economy rate's by
the bowler among all his matches over 5 season's.For example seasons are (10.0,5.0,8.9,6.7,4.2,5.5,2.2,3.4,6.0,2.3,2.0) so his improvement
index is 7 based on sequence (10.0 ,8.9, 6.7, 5.5, 3.4, 2.3, 2.0)
Now let E[1...........N] Donates a sequence of n economy rates for which improvement index is to be calculated
for 1 j n,Let I[j] denotes the improved index for the prefix of score E[1.......j ] ending atE[j]

1. Which of the following is correct recursive formulation of I(j) ?


a) I(1)=1
for j 2,3,......,n I(j) = 1+ max {I(k)/ 1 K<j, E[k] > E[j]}
b) I(1)=1
for j 2,3,......,n I(j) = 1+E(j-1) if E(j-1)<E(j)
1 otherwise
C) I(1)=1
for j 2,3,......,n I(j) = 1+ max {I(k)/ 1 K<j, E[k] < E[j]}
d)I(1)=1
for j 2,3,......,n I(j) = 1+E(j-1) if E(j-1) > E(j)
1 otherwise

2. How to evaluate this Recursive definition Using Dynamic programming?


a) A 2-D table T of Size N X N to be filled row wise from T[1][1] to T[n][n]
b) A 1-D table T of Size N to be filled from T[n] to T[1]
C) A 2-D table T of Size N X N to be filled row wise from T[n][n] to T[1][1]
d) A 1-D table T of Size N to be filled from T[n] to T[1]

3. What is the Time complexity in Dynamic programming ?

a) O(n)
b) O(nLog n)
c) O(n2 )
d) O(n3 )

1. Answer is a. Reading the problem statement 4-5 times gives this :)


The current considered element must be smaller than ALL previous entries. So, b, c, and d are false.
2. 1-D table filled from T[1] to T[n]
3. O(n)
-- Arjun Suresh

Size of stack required is ?

top

A(n)
{
if(n>=1)
{
A(n-1); // statement 1
print n; //statement 2
A(n-1);// statement 3
}
}

Size of stack is of the order of the number of recursive calls which are currently live. (It is not equal because we save many info on the stack
during a call like local variables, return address etc. )
Here, we have two recursive calls with value (n-1) for input n. But before the second one starts, the first one finishes. So, total number of
recursive calls for n can be given by
Solve recurrence T(n) = 2T(n-1) + 1 (1 for the stack space required for the current process) with T(0) = 1.
and the number of live recursive calls (recursion depth) is given by
T(n) = T(n-1) + 1 which is O(n).
-- Digvijay Pandey

arrange the following in terms of asymptotic complexity

top

arrange the following in the increasing order of their asymptotic complexity in big theta notation

Log n! has same asymptotic growth as n log n as shown by Stirling approximation.


Log nlog n= log n log n which is asymptotically lower than n log n.
So the order would be
Log nlog n, log n!, (3/2)n, 2n, 22n
-- Arjun Suresh

Time complexity of a while loop

top

Assuming n>2

A()
{
while(n>1)
{
n = n/2;
}
}

T(n) = T(n/2) + c ,

// c is constant

Solve recurrence by Master method or recursive tree method..


Complexity will be logn ..
-- Digvijay Pandey

How to find the complexity of T(n)=T(sqrt(n)) + 1 ?

top

Please tell me the complete steps how to solve this problem.

For objective exams do:


Since we have a sqrt term, considering only perfect squares and those which are multiple of 2 as that can take care of log.

T (2) = 1//assume
T (2 2 ) = T (2) + 1 = 2
2
T (2 2 ) = T (4) + 1 = 3

T (2 2 ) = T (16) + 1 = 4
3

T (2 2 ) = T (256) + 1 = 5
4

So, we are getting T (n) = lg lg n + 1 T (n) = O(log log n)


-- Arjun Suresh

Compiler Design

top

Pankaj and Mythili were both asked to write the code to evaluate the following expression
top

Pankaj and Mythili were both asked to write the code to evaluate the following expression:

a b + c/(a b) + (a b)2
Pankaj writes the following code statements (Code A):
print (a-b) + c/(a-b) + (a-b)*(a-b)
Mythili writes the following code statements (Code B):
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or division between two operands is same, which of the following is
true?
Option 1 : Code A uses lesser memory and is slower than Code B
Option 2 : Code A uses lesser memory and is faster than Code B
Option 3 : Code A uses more memory and is faster than Code B
Option 4 : Code A uses more memory and is slower than Code B

Option 1 : Code A uses lesser memory and is slower than Code B


In code A, three variables are used a, b and c to store values. The computation of a-b is repetitive and is performed 4 times in print statement
requires more time compared to the computation of print statement of code B, because of the use of additional variable d, to store the
computed value of a-b. The print statement of code B replaces d with the already computed value of a-b.

-- Keith Kr

GATE2008_50 top
Which of the following statements are true?
I. Every left-recursive grammar can be converted to a right-recursive grammar and vice-versa
II. All -productions can be removed from any context-free grammar by suitable transformations
III. The language generated by a context-free grammar all of whose productions are of the formX w or X wY (where, w is a string of
terminals and Y is a non-terminal), is always regular
IV. The derivation trees of strings generated by a context-free grammar in Chomsky Normal Form are always binary trees

A.
B.
C.
D.

I, II, III and IV


II, III and IV only
I, III and IV only
I, II and IV only

Answer is C:
Statement 1 is true: Using GNF we can convert Left recursive grammar to right recursive and by using reversal of CFG and GNF we can
convert right recursive to left recursive.
Statement 2 is false: because if is in the language then we can't remove production from Start symbol. (For example L = a*)
Statement 3 is true because right linear grammar generates regular set
Statement 4 is true, only two non-terminals are there in each production in CNF. So it always form a binary tree.
-- Vikrant Singh

GATE2008_12 top
Some code optimizations are carried out on the intermediate code because

A. They enhance the portability of the compiler to the target processor


B. Program analysis is more accurate on intermediate code than on machine code
C. The information from dataflow analysis cannot otherwise be used for optimization
D. The information from the front end cannot otherwise be used for optimization

Ans is (A)
Intermediate codes are machine independent codes. So, intermediate code can be used for code optimization since a given source code can
be converted to target machine code.
-- Keith Kr

GATE2000_1.18 top
The number of tokens in the following C statement
printf("i=%d, &i=%x", i, &i);
is

a.
b.
c.
d.

3
26
10
21

answer - C
Tokens are:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.

printf
(
"i=%d, &i=%x"
,
i
,
&
i
)
;

-- ankitrokdeonsns

GATE2001_1.17 top
The process of assigning load addresses to the various parts of the program and adjusting the code and the date in the program to reflect the
assigned addresses is called
(A) Assembly
(B) parsing
(C) Relocation
(D) Symbol resolution

answer - C
-- ankitrokdeonsns

GATE2004_9

top

Consider a program P that consists of two source modules M 1 and M 2 contained in two different files. If M 1 contains a reference to a function
defined in M 2 the reference will be resolved at

A.
B.
C.
D.

Edit time
Compile time
Link time
Load time

answer - C. Each module is compiled separately and then linked together to make the executable. The below commands shows how to do
this for two modules c1.c and c2.c using gcc.
gcc -c c1.c -o c1.o
gcc -c c2.c -o c2.o
gcc c1.o c2.o -o C.exe

-- ankitrokdeonsns

GATE2013_9

top

What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production
(i.e., of type A and A a) to parse a string with n tokens?
(A) n/2
(B) n 1
(C) 2n 1
(D) 2 n

Ans will be B
A->BC
B->aa
C->bb
now suppose string is aabb
then
A->BC(reduction 3)
->aaC(reduction 2)
->aabb (reduction 1)
n=4
and number of reductions are 3 so n-1
-- raunak bairoliya

GATE1998_1.27 top

Type checking is normally done during


(a) lexical analysis
(b) syntax analysis
(c) syntax directed translation
(d) code optimization

The answer is C .
The use of syntax analyser is used to create parse Tree. But along with Grammar as input to Syntax Analyser we add even semantic rules
which form the basis of Syntax Directed Translation That help us in Evaluation of Expression .Remember that
Syntax Directed Translation are used in following cases
1. Conversion of infix to Postfix
2.Calculation of infix expression
3.For creating a Acyclic graph
4.Type Checking
5.Conversion of Binary number to Decimal
6.Counting the numbers of bits (0 or 1 ) in a binary number
7.Creation of syntax tree
8. To generate Intermediate code
9. Storing the data into Symbol table
-- spriti1991

GATE1998_1.28 top

answer - B
first module loaded starting at address 0. Size is 200. hence it will occup first 200 address last address being 199. Second module will be
present from 200 and so on.
-- ankitrokdeonsns

GATE2014-1_34 top
A canonical set of items is given below

S L. > R
Q R.
On input symbol < the set has
(A) a shift-reduce conflict and a reduce-reduce conflict.
(B) a shift-reduce conflict but not a reduce-reduce conflict.
(C) a reduce-reduce conflict but not a shift-reduce conflict.
(D) neither a shift-reduce nor a reduce-reduce conflict.

Ans : The given input symbol no where in the given grammar so with given symbol we have neither a shift-reduce nor a reduce-reduce
conflict. So, correct answer is (D.) ...
-- Jayesh Malaviya

GATE2006_59 top
Consider the following translation scheme.

S ER
R E{print( ); }R
E F + E{print( + ); } F
F S id{print(id. value); }
Here id is a token 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 +
(D) 2 3 4+*

It will be D. make a tree and perform post order evaluation.


-- Gate Keeda

GATE2006_60 top
Consider the following C code segment.
for (i = 0, i < n; i++)
{
for (j = 0; j < n; j++)
{
if (i%2)
{
x += (4*j + 5*i);
y += (7 + 4*j);
}
}
}

Which one of the following is false?


(A) The code contains loop invariant computation
(B) There is scope of common sub-expression elimination in this code
(C) There is scope of strength reduction in this code
(D) There is scope of dead code elimination in this code

4*j
is used at two places- so common subexpression elimination is possible
i%2
is loop invariant for the inner loop
5*i is also loop invariant for inner loop
x += 5*i
can be replaced by
x += p;
p +=5; (p must be initialized to 0 before the loop).

Thus replacing * with + and giving strength reduction.


Thus only (D) is false here.
-- Arjun Suresh

GATE2014-2_18 top
Which one of the following is NOT performed during compilation?

(A) Dynamic memory allocation


(B) Type checking

(C) Symbol table management


(D) Inline expansion

Dynamic means- at runtime. Dynamic memory allocation happens during the execution time and hence (A) is the answer.
-- Arjun Suresh

GATE2014-2_34 top
For a C program accessing X[i] [j] [k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of
a character is 8 bits.
t0 = i 1024
t1 = j 32
t2 = k 4
t3 = t1 + t0
t4 = t3 + t2
t5 = X[t4]

Which one of the following statements about the source code for the C program is CORRECT?

(A) X is declared as "int X[32] [32] [8].


(B) X is declared as "int X[4] [1024] [32].
(C) X is declared as "char X[4] [32] [8].
(D) X is declared as "char X[32] [16] [2].

k is multiplied by 4, means sizeof(dataype) is int.


j is multiplied by 32, means the inner most dimension of array is 32/4 = 8 (we have to divide by the size of the inner dimension- which here is
a simple integer)
i is multiplied by 1024, means the second dimension of array is 1024/32 = 32 (32 = 8*4 is the size of the inner dimension here)
So, (A) is correct. The first dimension is not needed for code generation and that is why in C language while passing an array to a function,
we can omit the value of the first dimension but not any others.
-- Arjun Suresh

GATE2014-3_11 top
The minimum number of arithmetic operations required to evaluate the polynomial
temporary variable is ______.

P (X) = X 5 + 4X 3 + 6X + 5 for a given value of X , using only one

In the above 8 steps of evaluation, the total number of arithmetic operations required are 7 [4
Multiplications, 3 Additions]
So answer is 7 arithmetic operations.
-- Gate Keeda

GATE2014-3_17 top
One of the purposes of using intermediate code in compilers is to
(A) make parsing and semantic analysis simpler.
(B) improve error recovery and error reporting.
(C) increase the chances of reusing the machine-independent code optimizer in other compilers.
(D) improve the register allocation.

C.
that is the actual use of intermediate code generator in a compiler.
-- Gate Keeda

GATE2014-3_18 top
Which of the following statements are CORRECT?
1.
2.
3.
4.

Static allocation of all data areas by a compiler makes it impossible to implement recursion.
Automatic garbage collection is essential to implement recursion.
Dynamic allocation of activation records is essential to implement recursion.
Both heap and stack are essential to implement recursion.

(A) 1 and 2 only


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

It will be D.
option 2 is wrong because it is not necessary to have automatic garbage collection to implement recursion.
option 4 is wrong because it says that both are required to implement recursion, which is wrong. Either of them will suffice.
-- Gate Keeda

GATE2011_27 top
Consider two binary operators and with the precedence of operator being lower than that of the operator . Operator is right
associative while operator is left associative. Which one of the following represents the parse tree for expression(7 3 4 3 2)
(A)

(B)

(C)

(D)

Answer is B.

-- Praneeth A S

GATE2010_13 top
Which data structure in a compiler is used for managing information about variables and their attributes?
(A) Abstract syntax tree
(B) Symbol table
(C) Semantic stack
(D) Parse table

B. It uses array to implement.


-- Gate Keeda

GATE1997_1.6

top

In the following grammar

X ::= X Y Y

Y ::= Z Y Z

Z ::= id
Which of the following is true?
a.
b.
c.
d.

' ' is left associative while ' ' is right associative


Both ' ' and ' ' are left associative
' ' is right associative while ' ' is left associative
None of the above

It will be A. For multiple ' ', the derivation is possible only via X
' ' which is on left side of
' ' in the production. Hence it is left associative.
For multiple ' ', the derivation is possible only via Y
' ' which is on the right side of ' ' in the production. Hence it is right associative.
If both left and right derivations were possible, the grammar would have been ambiguous and we couldn't have given associativity.
-- Gate Keeda

GATE1997_1.7

top

Which of the following is essential for converting an infix expression to the postfix form efficiently?
a.
b.
c.
d.

An operator stack
An operand stack
An operand stack and an operator stack
A parse tree

A.
we use operator stack (only operators are pushed as +, *, (, ), / ) for converting infix to postfix. And we use operand stack( operands such as
5,4,17 etc) for postfix evaluation.
-- Gate Keeda

GATE1997_1.8

top

A language L allows declaration of arrays whose sizes are not known during compilation. It is required to make efficient use of memory. Which
one of the following is true?
a.
b.
c.
d.

A compiler using static memory allocation can be written for L


A compiler cannot be written for L ; an interpreter must be used
A compiler using dynamic memory allocation can be written for L
None of the above

C.
Using dynamic memory allocation, memory will be allocated to array at runtime.
-- Gate Keeda

GATE1993_7.7

top

A part of the system software which under all circumstances must reside in the main memory is:
a.
b.
c.
d.
e.

text editor
assembler
linker
loader
none of the above

Answer: D
The loader is a program that loads the object program from the secondary memory into the main memory for execution of the program. The
loader resides in main memory.
-- Jon Snow

GATE1994_20 top
A grammar G is in Chomsky-Normal Form (CNF) if all its productions are of the formA BC or A a, where A, B and C , are non-terminals
and a is a terminal. Suppose G is a CFG in CNF and w is a string in L(G) of length n , then how long is a derivation ofw in G ?

its answer is 2n-1 for n length string, because in CNF at every step only 1 terminal can replace a variable, for example
S-AB
A-a
B-c
for generating string 'ac' 3 production will be used.
-- Manu Thakur

GATE1995_1.10 top

S ->
This violates the conditions of context-free and hence the grammar becomes context-sensitive.

-- Arjun Suresh

GATE1995_1.14 top

(c) is the answer. For linker to link external symbols (for example in C, to link an extern variable in one module to a global variable in another
module), it must know the location of all external symbols. In C external symbols includes all global variables and function names.
(a) is trivially there is an object module. (b) must be there if we need to have relocation capability.
(d) is no way needed.
-- Arjun Suresh

GATE1995_2.10 top

A.
Making a tree and performing post order traversal will yield answer as A.
S-->x x W (Pf'1')
W-->S z (Pf'3')
S-->x x W (Pf'1')
W-->S z (Pf'3')
S-->y (Pf'2').
-- Gate Keeda

GATE1996_2.10 top
The grammar whose productions are
-> if id then <stmt>
-> if id then <stmt> else <stmt>
-> id := id
is ambiguous because
(a) the sentence
if a then if b then c:= d

has more than two parse trees


(b) the left most and right most derivations of the sentence
if a then if b then c:= d

give rise to different parse trees


(c) the sentence
if a then if b then c:= d else c:= f

has more than two parse trees


(d) the sentence
if a then if b then c:= d else c:= f

has two parse trees

(d) the sentence


if a then if b then c: = d else c:= f
has two parse trees as follows:

if a then (if b then c:= d) else c:= f


and
if a then (if b then c:=d else c:= f)
-- Arjun Suresh

GATE1996_11 top

final grammar is
S-----> ABAC / ABC / BAC / BC / AC / AAC / d
A------> aA / a
B-------> bB / b
C-------> d
correct me ....
-- csegate2

GATE2008-IT_78 top
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.

S aS A
A aAb bAa
Which of the following strings is generated by the grammar above?

1)

aabbaba

2)

aabaaba

3)

abababb

4)

aabbaab

S aS
S aA
S aaAb
S aabAab
S aabbAaab
S aabbaab
hence d is d answer
-- Shreyans Dhankhar

GATE2008-IT_79 top
A CFG G is given with the following productions where S is the start symbol, A is a non-terminal and a and b are terminals.

S aS A
A aAb bAa
For the correct answer in above Question http://gateoverflow.in/3392/gate2008-it_78, how many steps are required to derive the string and how
many parse trees are there?

A)

6 and 1

B)

6 and 2

C)

7 and 2

D)

4 and 2

S aS

S aA

S aaAb

S aabAab

S aabbAaab

S aabbaab

Thus 6 steps are needed and only one way to derive the string so only one parse tree.
-- Shreyans Dhankhar

GATE2007-IT_9 top
Consider an ambiguous grammar G and its disambiguated version D. Let the language recognized by the two grammars be denoted by L(G)
and L(D) respectively. Which one of the following is true ?

A)

L (D) L (G)

B)

L (D) L (G)

C)

L (D) = L (G)

D)

L (D) is empty

c) grammar may change but language remain the same.


-- Arpit Dhuriya

GATE2005-IT_83a

top

Consider the context-free grammar


EE+E
E (E * E)
E id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.
Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?

A)

id + id + id + id

B)

id + (id* (id * id))

C)

(id* (id * id)) + id

D)

((id * id + id) * id)

Answer is A.
-- Gate Keeda

GATE2005-IT_83b top
Consider the context-free grammar
EE+E
E (E * E)
E id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of non-terminals is {E}.
For the terminal string id + id + id + id, how many parse trees are possible?
A)

B)

C)

D)

5 parse trees are possible.


-- ujjwal saini

GATE2005_61 top
Consider line number 3 of the following C-program.
int min() {
/*Line 1 */
int I, N;
/*Line 2 */
fro (I=0, I<N, I++); /*Line 3 */
}

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

C language allows only certain words in it- these are called tokens. If we input any invalid tokens it causes lexical error.
eg:
44a44
causes lexical error as in C as an alphabet cannot come in between digits.

Syntactic error is caused by bad combination of tokens. For example, we cannot have a constant on the left hand side of an assignment
statement, a for loop must have two expressions inside () separated by semi colon etc.
In the given question, line 3 won't cause lexical error or syntactic error. The statement will be treated as a function call with three arguments.
Function definition being absent will cause link time error, but the question asks only for compile time errors. So, (a) must be the answer.

http://stackoverflow.com/questions/15570553/lexical-and-semantic-errors-in-c
-- Arjun Suresh

GATE2004_10 top
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
(C) Evaluation of E1 and E2 should necessarily be interleaved
(D) Order of evaluation of E1 and E2 is of no consequence

E2 should be evaluated first


After evaluating E2 first and then E1, we will have E1 in the register and thus we can simply do SUB operation with E2 which will be in
memory (as we have only a single register). If we do E1 first and then E2, we must move E2 to memory and E1 back to register before doing
SUB, which will increase the code size.
-- Arjun Suresh

LR(K) grammer can be ambigious or not?

top

Yes as both LL grammer and LR grammer are sibset of unambiguous grammers


-- Kuldeeppunjabi1729

GATE2015-1_8 top
For computer based on three-address instruction formats, each address field can be used to specify which of the following:
(S1) A memory operand
(S2) A processor register
(S3) An implied accumulator register
A.
B.
C.
D.

Either S1 or S2
Either S2 or S3
Only S2 and S3
All of S1, S2 and S3

option A either A memory operand or A processor register.


-- Anoop Sonkar

GATE2015-2_19 top
Match the following:

P. Lexical analysis

1. Graph coloring

Q. Parsing

2. DFA minimization

R. Register allocation

3. Post-order traversal

S. Express evaluation

4. Production tree

A.
B.
C.
D.

P-2, Q-3, R-1, S-4


P-2, Q-1, R-4, S-3
P-2, Q-4, R-1, S-3
P-2, Q-3, R-4, S-1

Answer: C
-- Jon Snow

GATE2015-1_13 top
Which one of the following is TRUE at any valid state in shift-reduce parsing?
A.
B.
C.
D.

Viable prefixes appear only at the bottom of the stack and not inside
Viable prefixes appear only at the top of the stack and not inside
The stack contains only a set of viable prefixes
The stack never contains viable prefixes

C) should be the answer


-- GateMaster Prime

GATE2015-1_55 top
The least number of temporary variables required to create a three-address code in static single assignment form for the expression q + r / 3 +
s - t * 5 + u * v/w is__________________.

Answer should be 8. We will need a temporary variable for storing the result of each binary operation and SSA (static single assignment)
implies the variable cannot be repeated.
q + r / 3 + s - t * 5 + u * v/w
t1 = r/3;
t2 = t*5;
t3 = u*v;
t4 = t3/w;
t5 = q + t1;
t6 = t5 + s;
t7 = t5 - t2;
t8 = t7 + t4

http://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/240%20TAC%20Examples.pdf
-- Arjun Suresh

GATE2015-3_16 top
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to
implement and the method that is the most powerful, in that order?

A.
B.
C.
D.

SLR, LALR
Canonical LR, LALR
SLR, canonical LR
LALR, canonical LR

Answer is C.
SLR is the simplest to implement and Canonical LR is the most powerful.
http://en.wikipedia.org/wiki/LALR_parser_generator
-- Arjun Suresh

GATE2015-3_31 top
Consider the following grammar G
SF|H
Fp|c
Hd|c
Where S, F, and H are non-terminal symbols, p, d, and c are terminal symbols. Which of the following statement(s) is/are correct?
S1: LL(1) can parse all strings that are generated using grammarG
S2: LR(1) can parse all strings that are generated using grammarG

A.
B.
C.
D.

Only S1
Only S2
Both S1 and S2
Neither S1 and S2

A parser works on the basis of given grammar. It takes the grammar as it is. Parser does not work on the basis of the yield of the
grammar. Also, while constructing the LL(1) parser table, that entry for terminal 'c' will contain multiple entries. SO LL(1) parser
cannot be constructed for the given grammar.
SF|H
Fp|c
Hd|c

That {p, d, c} are the strings generated by the grammar is absolutely correct. But LL(1) and LR(1) can parse these strings
successfully only if the grammar is unambiguous and like given below...
SP|D|C
Pp
Dd
Cc

Please note the difference between these two grammars. Both derive the same strings, but in different manner. With the
grammar given in the question, both top-down and bottom-up parsers will get confused while deriving "c". Top-down parser
will get confused between F c and H

c. Similarly, bottom-up parser will get confused while reducing "c". This confusion

in case of bottom-up parsing is technically termed as "reduce-reduce" conflict.


While top-down parsing, follow(F) and follow(H) are not disjoint, so the grammar cannot be LL(1). Therefore, LL(1) parser
cannot parse it.

Hence, the answer should be option (D). Neither S1 nor S2.


-- ashishacm

CO & Architecture top


GATE2004_47 top
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 90%, and the page
fault rate is one in every 10,000 instructions. What is the effective average instruction execution time?
(A) 645 nanoseconds
(B) 1050 nanoseconds
(C) 1215 nanoseconds
(D) 1230 nanoseconds

Average Instruction execution time


= Average CPU execution time + Average time for getting data/instruction from memory for each instruction
= Average CPU execution time + Average address translation time for each instruction + Average memory fetch time for each instruction +
Average page fault time for each instruction
= 100 +2* ((0.9 * 0) + 0.1 * (2 * 150)) + 2*150 + (1/10,000) * 8 * 1,000,000 (page fault rate per 10,000 instruction is directly given in question.
Two memory accesses per instruction and hence we need 2 * address translation time for average instruction execution time)
[ TLB access time assumed as 0 and 2 page tables need to be accessed in case of TLB miss as the system uses two-level paging]
= 100 + 60 + 300 + 800
= 1260 ns
-- Arjun Suresh

GATE2013_45 top
Consider an instruction pipeline with five stages without any branch prediction: Fetch Instruction (FI), Decode Instruction (DI), Fetch Operand
(FO), Execute Instruction (EI) and Write Operand (WO). The stage delays for FI, DI, FO, EI and WO are 5 ns, 7 ns, 10 ns, 8 ns and 6 ns,
respectively. There are intermediate storage buffers after each stage and the delay of each buffer is 1 ns. A program consisting of 12
instructions I1, I2, I3, , I12 is executed in this pipelined processor. Instruction I4 is the only branch instruction and its branch target is I9. If the
branch is taken during the execution of this program, the time (in ns) needed to complete the program is
(A) 132

(B) 165

(C) 176

(D) 328

clock cycle time is 11ns


2 nop instructions req
clk1 clk2 cl3 clk4 clk5 clk6 clk7 clk8 clk9 clk10 clk11 clk12
1

3 3

nop nop nop nop nop


nop nop nop nop nop
9

10 10 10 10 10
11 11 11 11 11
12
total no of clk cycles is 14
hence 14*11=154 ns plz explain

12 12

12 12

You just need 1 more stall cycle as the FI of I9 can start only after the EI of I4. So, the total execution time will be

15 11 = 165ns.

Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk Clk
1 2 3 4 5
6
7
8
9 10 11 12 13 14 15
I1 FI DI FO EI WO
I2

FI DI FO EI

WO

I3

FI DI FO EI

I4

FI DI

WO

FO EI

WO

stall
stall
stall
I9

FI

I10

DI FO EI WO
FI DI FO EI

WO

I11

FI DI FO EI

I12

FI DI

WO

FO EI

WO

-- gatecse

GATE2008_33 top
Which of the following is/are true of the auto-increment addressing mode?
I. It is useful in creating self-relocating code
II. If it is included in an Instruction Set Architecture, then an additional ALU is required for effective address calculation
III. The amount of increment depends on the size of the data item accessed

A.
B.
C.
D.

I only
II only
III only
II and III only

In auto increment addressing mode, the base address is incremented after operand fetch. This is useful in fetching elements from an array.
But his has no effect in self-relocating code (where code can be loaded to any address) as this works on the basis of an initial base address.
An additional ALU is desirable for better execution especially with pipelining, but never a necessity.
Amount of increment depends on the size of the data item accessed as there is no need to fetch a part of a data.
So, answer must be C only.
-- Arjun Suresh

GATE2008_36 top
Which of the following are NOT true in a pipelined processor?
I. Bypassing can handle all RAW hazards
II. Register renaming can eliminate all register carried WAR hazards
III. Control hazard penalties can be eliminated by dynamic branch prediction

A.
B.
C.
D.

I and II only
I and III only
II and III only
I, II and III

(B) I and III


I - False
Bypassing can't handle all RAW hazard, consider when any instruction depends on the result of LOAD instruction, now LOAD
updates register value at Memory Access Stage (MA), so data will not be available directly on Execute stage.
II - True, register renaming can eliminate all WAR Hazard.
III- False, It cannot completely eliminate, though it can reduce Control Hazard Penalties
-- Prateeksha Keshari

GATE2008_38 top
In an instruction execution pipeline, the earliest that the data TLB (Translation Lookaside 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

C as only after the calculation of Virtual address you can look up in the TLB
-- Shaun Patel

GATE2008_71,72,73

top

Consider a machine with a 2-way set associative data cache of size 64 Kbytes and block size 16 bytes. The cache is managed using 32 bit
virtual addresses and the page size is 4 Kbytes. A program to be run on this machine begins as follows:
double ARR[1024][1024];
int i, j;
/*Initialize array ARR to 0.0 */
for(i = 0; i < 1024; i++)
for(j = 0; j < 1024; j++)
ARR[i][j] = 0.0;

The size of double is 8 bytes. Array ARR is located in memory starting at the beginning of virtual page 0xFF000 and stored in row major order.
The cache is initially empty and no pre-fetching is done. The only data memory references made by the program are those to array ARR.
71) The total size of the tags in the cache directory is
(A) 32 Kbits

(B) 34 Kbits

(C) 64 Kbits

(D) 68 Kbits

72) Which of the following array elements have the same cache index as ARR[0][0]?
(A) ARR[0][4]

(B) ARR[4][0]

(C) ARR[0][5]

(D) ARR[5][0]

73) The cache hit ratio for this initialization loop is


(A) 0%

(B) 25%

(C) 50%

(D) 75%

Number of sets = cache size/ size of a set


= 64 KB / (16 B * 2) (two blocks per set)
= 2 K = 211
So, we need 11 bits for set indexing.
Number of WORD bits required = 4 as a cache block consists of 16 bytes and we need 4 bits to address each of them.

So, number of tag bits = 32 - 11 - 4 = 17


Total size of the tag = 17 * Number of cache blocks
= 17 * 2 11 * 2 (since each set has 2 blocks)
= 68 KB
We use the top 17 bits for tag and the next 11 bits for indexing and next 4 for offset. So, for two addresses to have the same cache index,
their 11 address bits after the 4 offset bits from right must be same.
ARR[0][0] is located at virtual address 0x FF000 000. (FF000 is page address and 000 is page offset). So, index bits are 00000000000
Address of ARR[0][4] = 0xFF000 + 4 * sizeof (double) = 0xFF000 000 + 4*8 = 0xFF000 020 (32 = 20 in hex) (index bits differ)
Address of ARR[4][0] = 0xFF000 + 4 * 1024 * sizeof (double) [since we use row major storage] = 0xFF000 000 + 4096*8 = 0xFF000 000 +
0x8000 = 0xFF008 000 ( index bits matches that of ARR [0][0] as both read 000 0000 0000)
Address of ARR[0][5] = 0xFF000 + 5 * sizeof (double) = 0xFF000 000+ 5*8 = 0xFF000 028 (40 = 28 in hex) (index bits differ)
Address of ARR[5][0] = 0xFF000 + 5 * 1024 * sizeof (double) [since we use row major storage] = 0xFF000 000 + 5120*8 = 0xFF000 000 +
0xA000 = 0xFF00A 000 (index bits differ)
So, only ARR[4][0] and ARR[0][0] have the same cache index.
The inner loop is iterating from 0 to 1023, so consecutive memory locations are accessed in sequence. Since cache block size is only 16
bytes and our element being double is of size 8 bytes, during a memory access only the next element gets filled in the cache. i.e.; every
alternative memory access is a cache miss giving a hit ratio of 50%. (If loops i and j are reversed, all accesses will be misses and hit ratio will
become 0).
-- Arjun Suresh

GATE2008_76,77 top
Delayed branching can help in the handling of control hazards
76. For all delayed conditional branch instructions, irrespective of whether the condition evaluates to true or false,

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 than any other instruction

77. The following code is to run on a pipelined processor with one branch delay slot:
I1: ADD R2 R7 + R8
I2: Sub R4 R5 R6
I3: ADD R1 R2 + R3
I4: STORE Memory [R4] R1
BRANCH to Label if R1 == 0
Which of the instructions I1, I2, I3 or I4 can legitimately occupy the delay slot without any program modification?

A.
B.
C.
D.

I1
I2
I3
I4

76. Answer is A. In order to avoid the pipeline delay due to conditional branch instruction, a suitable instruction is placed below the conditional

branch instruction such that the instruction will be executed irrespective of whether branch is taken or not and won't affect the program
behaviour.
77. Answer is D) I4. The STORE instruction can be moved below the conditional branch instruction. Whether the branch is taken or not,
STORE will be executed as the next instruction after conditional branch instruction, due to delayed branching.
Here, I3 is not the answer because the branch conditional variable R1 is dependent on it. Same for I1. Similarly, I4 has a dependency on I2
and hence I2 must be executed before I4.
-- Arjun Suresh

GATE1991_03,iii

top

03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(iii) The total size of address space in a virtual memory system is limited by
a.
b.
c.
d.
e.

the length of MAR


the available secondary storage
the available main memory
all of the above
none of the above

Answer is (a) and (b)


Virtual memory concept is independent of size of main memory and depends only on the availability of the secondary storage.
MAR holds the address generated by CPU and this obviously limits the total virtual memory address space.
-- Kalpna Bhargav

GATE1992_05,a,b top

Average memory access time = Time spend for read + Time spend for write
= Read time when cache hit + Read time when cache miss
+Write time when cache hit + Write time when cache miss
= 0.8 0.9 50 + 0.8 0.1 (50 + 500)
+ 0.2 0.9 (50 + 500) + 0.2 0.1 (50 + 500)
= 36 + 44 + 99 + 11 = 190 ns
http://www.howardhuang.us/teaching/cs232/24-Cache-writes-and-examples.pdf
-- Arjun Suresh

GATE2000_1.8

top

Comparing the time T1 taken for a single instruction on a pipelined CPU with time T2 taken on a non-pipelined but identical CPU, we can say that

a. T1 T2
b. T1 T2
c. T1 < T2

d. T1 and T2 plus the time taken for one instruction fetch cycle

Here we are comparing the execution time of only a single instruction. Pipelining in no way increases the execution time of a single instruction
(the time from its start to end). It increases the overall performance by splitting the execution to multiple pipeline stages so that the following
instructions can use the finished stages of the previous instructions. But in doing so pipelining causes some problems also as given in the
below link, which might slow some instructions. So, (B) is the answer.
http://www.cs.wvu.edu/~jdm/classes/cs455/notes/tech/instrpipe.html
-- Arjun Suresh

GATE2000_12 top
An instruction pipeline has five stages where each stage take 2 nanoseconds and all instruction use all five stages. Branch instructions are not
overlapped. i.e., the instruction after the branch is not fetched till the branch instruction is completed. Under ideal conditions,
a. Calculate the average instruction execution time assuming that 20% of all instructions executed are branch instruction. Ignore the fact
that some branch instructions may be conditional.
b. If a branch instruction is a conditional branch instruction, the branch need not be taken. If the branch is not taken,
the following instructions can be overlapped. When 80% of all branch instructions are conditional branch instructions, and 50% of the
conditional branch instructions are such that the branch is taken, calculate the average instruction execution time.

Each stage is 2ns. So, after 5 time units each of 2ns, the first instruction finishes (i.e., after 10ns), in every 2ns after that a new instruction gets
finished. This is assuming no branch instructions. Now, once the pipeline is full, we can assume that the initial fill time doesn't matter our
calculations and average execution time for each instruction is 2ns assuming no branch instructions.
(a) Now, we are given that 20% of instructions are branch (like JMP) and when a branch instruction is executed, no further instruction enters
the pipeline. So, we can assume every 5th instruction is a branch instruction. So, with this assumption, total time to finish 5 instruction will be 5
* 2 + 8 = 18 ns (as when a branch instruction enters the pipeline and before it finishes, 4 pipeline stages will be empty totaling 4 * 2 = 8 ns).
And this is the same for every set of 5 instructions, and hence the average instruction execution time = 18/5 = 3.6 ns
(b) This is just a complex statement. But what we need is to identify the % of branch instructions which cause a branch to be taken as others
will have no effect on the pipeline flow.
20% of branch instructions are branch instructions. 80% of branch instructions are conditional.
That means .2*.8 = 16% of instructions are conditional branch instructions and it is given that 50% of those result in a branch being taken.
So, 8% of instructions are conditional branches being taken and we also have 20% of 20% = 4% of unconditional branch instructions which
are always taken.
So, percentage of instructions where a branch is taken is 8+4 = 12% instead of 20% in (a) part.
So, in 100 instructions there will be 12 branch instructions. We can do a different calculation here as compared to (a) as 12 is not a divisor of
100. Each branch instruction causes a pipeline delay of 4*2 = 8 ns. So, 12 instructions will cause a delay of 12 * 8 = 96 ns. For 100
instructions, we need 100 * 2 = 200 ns without any delay and with delay we require 200 + 96 = 296 ns for 100 instructions.
So, average instruction execution time = 296/100 = 2.96 ns
(We can also use this method for part (a) which will give 100 * 2 + 20*8 = 360 ns for 100 instructions)

-- Arjun Suresh

GATE2001_2.9

top

Which is the most appropriate match for the items in the first column with the items in the second column

(A) (X, III) (Y, I) (Z, II)


(B) (X, II) (Y, III) (Z, I)
(C) (X, III) (Y, II) (Z, I)

X. Indirect Addressing

I. Array implementation

Y. Indexed addressing

II. Writing relocatable code

Z. Base Register Addressing

III. Passing array as parameter

(D) (X, I) (Y, III) (Z, II)

(A) is the answer.


Array implementation can use Indexed addressing
While passing array as parameter we can make use of a pointer (as in C) and hence can use Indirect addressing
Base Register addressing can be used to write relocatable code by changing the content of Base Register.
-- Arjun Suresh

GATE2001_9

top

A CPU has 32-bit memory address and a 256 KB cache memory. The cache is organized as a 4-way set associative cache with cache block
size of 16 bytes.
A.
B.
C.
D.
E.

What is the number of sets in the cache?


What is the size (in bits) of the tag field per cache block?
What is the number and size of comparators required for tag matching?
How many address bits are required to find the byte offset within a cache block?
What is the total amount of extra memory (in bytes) required for the tag bits?

What is the number of sets in the cache?


Number of sets = Cache memory/(set associativity * cache block size)
= 256KB/(4*16 B)
= 4096

What is the size (in bits) of the tag field per cache block?
Memory address size = 32-bit
Number of bits required to identify a particular set = 12 (Number of sets = 4096)
Number of bits required to identify a paticular location in cache line = 4 (cache block size = 16)
size of tag field = 32 -12 -4 = 16-bit

What is the number and size of comparators required for tag matching?
We use 4-way set associate cache. So, we need 4 comparators each of size 16 bits
http://ecee.colorado.edu/~ecen2120/Manual/caches/cache.html

How many address bits are required to find the byte offset within a cache block?
Cache block size is 16 byte. so 4 bits are required to find the byte offset within a cache block.

What is the total amount of extra memory (in bytes) required for the tag bits?
size of tag = 16 bits
Number of sets = 4096
Set associativity = 4
Extramemory required to store the tag bits = 16 * 4096 * 4 bits = 215 bytes
-- suraj

GATE2004-IT_50 top
In an enhancement of a design of a CPU, the speed of a floating point until has been increased by 20% and the speed of a fixed point unit has been increased by
10%. What is the overall speedup achieved if the ratio of the number of floating point operations to the number of fixed point operations is 2:3 and the floating point
operation used to take twice the time taken by the fixed point operation in the original design?

(A) 1.155 (B) 1.185 (C) 1.255 (D) 1.285

Speed up = Original time taken/ new time taken


Let x be the time for a fixed point operation
Original time taken = (3x + 2*2x)/5 = 7x/5
New time taken = ((3x/1.1) + (4x/1.2))/5 = 8x/1.32*5
So, speed up = 7*1.32/8 = 1.155

-- gatecse

GATE2002_1.24 top
In the absolute addressing mode

A.
B.
C.
D.

the operand is inside the instruction


the address of the operand in inside the instruction
the register containing the address of the operand is specified inside the instruction
the location of the operand is implicit

(b) is the answer. Absolute addressing mode means address of operand is given in the instruction.
(a) operand is inside the instruction -> immediate addressing
(c) -> register addressing
(d) -> implicit addressing
-- gatecse

GATE2002_2.7

top

Horizontal microprogramming

A.
B.
C.
D.

does not require use of signal decoders


results in larger sized microinstructions than vertical microprogramming
uses one bit for each control signal
all of the above

option (d). All statements are true.


Ref: http://www.cs.virginia.edu/~cs333/notes/microprogramming.pdf
-- Suvojit Mondal

GATE2002_10 top
In a C program, an array is declared as float A[2048]. Each array element is 4 Bytes in size, and the starting address of the array is
0x00000000. This program is run on a computer that has a direct mapped data cache of size 8 Kbytes, with block (line) size of 16 Bytes.
a. Which elements of the array conflict with element A[0] in the data cache? Justify your answer briefly.
b. If the program accesses the elements of this array one by one in reverse order i.e., starting with the last element and ending with the first
element, how many data cache misses would occur? Justify your answer briefly. Assume that the data cache is initially empty and that
no other data or instruction accesses are to be considered.

(a)
Data cache size = 8KB.
Block line size = 16B.
Since each array element occupies 4B, four consecutive array elements occupy a block line (elements are aligned as starting address is 0)
Number of cache blocks = 8KB/16B = 512. Number of cache blocks needed for the array = 2048/4 = 512. So, all the array elements has its
own cache block and there is no collision.
We can also explain this with respect to array address. Starting address is 0x00000000 = 0b0000..0 (32 0's). Ending address is 0x00001000
= 0b0000..01000000000000.
Here, the last 4 bits are used as OFFSET bits and the next 9 bits are used as SET bits. So, since the ending address is not extending beyond
these 9 bits, all cache accesses are to diff sets.
(b) If the last element is accessed first, its cache block is fetched. (which should contain the previous 3 elements of the array also since each
cache block hold 4 elements of array and 2048 is and exact multiple of 4). Thus, for every 4 accesses, we will have a cache miss => for 2048
accesses we will have 512 cache misses. (This would be same even if we access array in forward order).
-- Arjun Suresh

GATE2004_39 top
Two matrices M 1 and M 2 are to be stored in arraysA and B respectively. Each array can be stored either in row-major or column-major order
in contiguous memory locations. The time complexity of an algorithm to compute M 1 M 2 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

D is correct
Here time complexity is asked, for each access of array element it will be constant,
So the time complexity will not depend upon storage. If at all program execution time is asked
a is true
-- Anurag_s

GATE2004_63,64 top
Consider the following program segment for a hypothetical CPU having three user registers R1, R2 and R3.
Instruction

Operation

MOV R1, 5000

R1 Memory[5000]

Instruction Size (in


words)
2

Memory[6000] R2
Machine halts

2
1

MOV R2(R1)
ADD R2, R3
MOV 6000, R2
HALT

R2 Memory[(R1)]
R2 R2 + R3

1
1

63. 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.
B.
C.
D.

1007
1020
1024
1028

64. Let the clock cycles required for various operations be as follows:
Register to/from memory transfer
ADD with both operands in register

: 3 clock cycles
: 1 clock cycle

Instruction fetch and decode

: 2 clock cycles per word

The total number of clock cycles required to execute the program is

A.
B.
C.
D.

29
24
23
20

63. Word size is 32 bits (4 bytes). Interrupt occurs after execution of HALT instruction NOTduring, So address of next instruction will be
saved on to the stack which is 1028. (We have 5 instructions starting from address 1000, each of size 2, 1, 1, 2, 1 totaling 7 words = 28
bytes).
After HALT instruction CPU enters a HALT state and if an interrupt happens the return address will be that of the instruction after the HALT.
Ref http://x86.renejeschke.de/html/file_module_x86_id_134.html
option D
64. B. 24 cycles
Instruction

Size

Fetch and Decode + Execute

mov

2*2 + 3 = 7

mov

2*1 + 3 = 5

add

2*1 + 1 = 3

mov

2*2 + 3 = 7

halt

2*1 + 0 = 2

Total 24 cycles

-- Vikrant Singh

GATE2004_69 top
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
D. 590.0 microseconds

Pipelining requires all stages to be synchronized meaning, we have to make the delay of all stages equal to the maximum pipeline stage
delay which here is 160.
Time for execution of the first instruction = (160+5) * 3 + 160 = 655 ns (5 ns for intermediate registers which is not needed for the final stage).
Now, in every 165 ns, an instruction can be completed. So,

Total time for 1000 instructions = 655 + 999*165 = 165.49 microseconds


-- Arjun Suresh

GATE2007_10 top
Consider a 4-way set associative cache consisting of 128 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.
B.
C.
D.

9, 6, 5
7, 7, 6
7, 5, 8
9, 5, 6

Number of sets = cache size/(size of a block * No. of blocks in a set)


= 128 * 64 / (64 * 4) (4 way set associative means 4 blocks in a set)
= 32.
So, number of index (LINE) bits = 5 and number of WORD bits = 6 size cache block (line) size is 64. So, number of TAG bits = 20 - 6 - 5 = 9.
Answer is (D) choice
-- Arjun Suresh

GATE2007_80,81 top
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 x 50 two-dimensional array of bytes is stored in the main memory starting 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.
80. How many data misses will occur in total?
A.
B.
C.
D.

48
50
56
59

81. Which of the following lines of the data cache will be replaced by new blocks in accessing the array for the second time?
A.
B.
C.
D.

line 4 to line 11
line 4 to line 12
line 0 to line 7
line 0 to line 8

2 16 = 64 KB main memory is mapped to 32 lines of 64 bytes. So, number of offset bits = 6 (to identify a byte in a line) and number of indexing
bits = 5 (to identify the line).

Size of array = 50* 50 = 2500 B. If array is stored in row-major order (first row, second-row..), and if elements are also accessed in row-major
order (or stored and accessed in column-major order), for the first 64 accesses, there will be only 1 cache miss, and for 2500 accesses, there
will be 2500/64 = 40 cache misses during the first iteration.
We have 5 index bits and 6 offset bits. So, for 211 (5 + 6 = 11) continuous memory addresses there wont be any cache conflicts as the least
significant bits are offset bits followed by index bits.
So, number of array elements that can be accessed without cache conflict = 2048 (as element size is a byte). The next 452 elements conflict
with the first 452 elements. This means 452/64 = 8 cache blocks are replaced. (We used ceil, as even if one element from a new block is
accessed, the whole block must be fetched).
So, during second iteration we incur misses for the first 8 cache blocks as well as for the last 8 cache blocks. So, total data cache misses
across 2 iterations = 40 + 8 + 8 = 56.

For 81. answer is lines 4 to 11 as we start from


1100 H = (0001 0001 0000 0000)b excluding lower 6 bits for offset, we get 0001 0001 00 bits for cache block which is the 4th block.
-- Arjun Suresh

GATE2005_65 top
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 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.
B.
C.
D.

3
4
5
6

1 memory read - get first operand from memory address A+R0 (A is given as part of instruction)
1 memory read - get address of second operand (since second uses indirect addressing)
1 memory read - to get second operand from the address given by the previous memory read
1 memory write - to store to first operand (which is the destination)
So, totally 4 memory cycles once the instruction is fetched.
-- Arjun Suresh

GATE2005_66 top
Match each of the high level language statements given on the left hand side with the most natural addressing mode from those listed on the
right hand side.
(1) A[I] = B[J]

(a) Indirect addressing

(2) while (*A++);


(3) int temp = *x

(b) Indexed addressing


(C) Auto increment

A.
B.
C.
D.

(1, c), (2, b) (3, a)


(1, c), (2, c) (3, b)
(1, b), (2, c) (3, a)
(1, a), (2, b) (3, c)

(c) is the answer.


A[i] = B[j]; Indexed addressing
while(*A++);
temp = *x;

Auto increment
Indirect addressing

-- Arjun Suresh

GATE2013_20 top

In a k-way set associative cache, the cache is divided intov sets, each of which consists of k lines. The lines of a set are placed in sequence
one after another. The lines in set s are sequenced before the lines in set(s + 1). The main memory blocks are numbered 0 onwards. The
main memory block numbered j must be mapped to any one of the cache lines from
(A) (j mod v) k to (j mod v) k + (k 1)
(B) (j mod v) to (j mod v) + (k 1)
(C) (j mod k) to (j mod k) + (v 1)
(D) (j mod k) v to (j mod k) v + (v 1)

Number of sets in cache = v.


The question gives a sequencing for the cache lines. For set 0, the cache lines are numbered 0, 1, .., k-1. Now for set 1, the cache lines are
numbered k, k+1,... k+k-1 and so on.
So, main memory block j will be mapped to set (j mod v), which will be any one of the cache lines from (j mod v) * k to (j mod v) * k + (k-1).
(Associativity plays no role in mapping- k-way associativity means there are k spaces for a block and hence reduces the chances of
replacement.)
-- Arjun Suresh

GATE1999_13 top

1
F

2
D
F

10 11

12 13 14 15

D D

E W W

E W

therefore 15 clock cycles needed.


CORRECT ME IF I AM WRONG
-- Danish

GATE2013_48,49 top
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have
atmost two source operands and one destination operand. Assume that all variables are dead after this code segment.
c = a + b;
d = c * a;
e = c + a;
x = c * c;
if (x > a) {
y = a * a;
}

else {
d = d * d;
e = e * e;
}

Q.48 Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion,
which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the
compiled code?
(A) 0

(B) 1

(C) 2

(D) 3

Q.49 What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without
any spill to memory? Do not apply any optimization other than optimizing register allocation.
(A) 3

(B) 4

(C) 5

(D) 6

We can do code motion as follows:


c = a + b; //a and b in register and b replaced by the result c after the instruction
x = c * c; //x replaces c in register and c is spilled (moved to memory)
if (x > a) { //x and a in memory
y = a * a;
d = c * a; //spilled c taken from memory and replaces x in register.
e = c + a;
}
else {
d = c * a; //spilled c taken from memory and replaces x in register. d replaces a in register
d = d * d; //c and d in register
e = c + a; //a taken from memory and e replaces c in register (a taken from memory is not a spill, it is a fill)
e = e * e;
}

So, we need minimum 1 spill in the compiled code.


https://en.wikipedia.org/wiki/Register_allocation

49) Here, we are told not to do code motion. So, we start with 3 registers
c = a + b; //a, c in register
d = c * a; //a, c, d in register
e = c + a; //a, c, e in register, d spilled.

So, now we try with 4 registers


c = a + b; //a, c in register
d = c * a; //a, c, d in register
e = c + a; //a, c, d, e in register
x = c * c; //a, x, d, e in register
if (x > a) {
y = a * a;
}
else {
d = d * d;
e = e * e;
}

No spilling. So, 4 is the minimum number of registers needed for avoiding spilling. (If code motion was allowed, we need only 3 registers for
avoiding spilling).
-- Arjun Suresh

GATE1998_2.18 top

ans a)
-- Aditi Dan

GATE2014-1_9 top

A machine has a 32-bit architecture, with 1-word long instructions. It has 64 registers, each of which is 32 bits long. It needs to support 45 instructions, which have
an immediate operand in addition to two register operands. Assuming that the immediate operand is an unsigned integer, the maximum value of the immediate
operand is ____________

64 registers means 6 bits for a register operand. So, 2 register operand requires 12 bits. Now, 45 instructions require another 6 bits for
opcode. So, totally 18 bits. So, we have 32 - 18 = 14 bits left for the immediate operand. So, the max value will be 214 - 1 = 16383 (as the
operand is unsigned we don't need a sign bit and with 14 bits we can represent from 0 to 214 -1)
-- Arjun Suresh

GATE2006_42 top
A CPU has a five-stage pipeline and runs at 1 GHz 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, the total execution time of the program is:
(A) 1.0 second
(B) 1.2 seconds
(C) 1.4 seconds
(D) 1.6 seconds

no of non branch instn = 8*108


no of branch instn = 2*108
no of bubble by control hazard(branch instrn)=3*2*108 = 6*108
then , total no of cycle for execution=8*10 8+6*108 ns = 14 *108 = 1.4sec
-- tariq husain khan

GATE2006_74,75 top
Common Data for Questions 74, 75:
Consider two cache organizations. First one is 32 kb 2-way set associative with 32 byte block size, the second is of same size but direct
mapped. The size of an address is 32 bits in both cases . A 2-to-1 multiplexer has latency of 0.6ns while a k bit comparator has latency of
k
ns . The hit latency of the set associative organization ish1 while that of direct mapped is h2 .
10

74. The value of h1 is:


(A) 2.4 ns
(B) 2.3 ns
(C) 1.8 ns
(D) 1.7 ns
75. The value of h2 is:
(A) 2.4 ns
(B) 2.3 ns
(C) 1.8 ns
(D) 1.7 ns

Case 1:
Cache size is 32 KB and cache block size is 32 B. So,

number of sets =
=

32KB
232B

cache size
no. of blocks in a set block size

= 512

So, number of index bits needed = 9 ( since 29 = 512). Number of offset bits = 5 (since 25 = 32 B is the block size and assuming byte

addressing). So, number of tag bits = 32 - 9 - 5 = 18 (as memory address is of 32 bits).


So, time for comparing the data = Time to compare the data + Time to select the block in set = 0.6 + 18/10 ns = 2.4 ns. (Two comparisons of
tag bits need to be done for each block in a set, but they can be carried out in parallel and the succeeding one multiplexed as the output)
Case 2:

number of sets =
=

32KB
132B

cache size
no. of blocks in a set block size

= 1024

So, number of index bits = 10, and number of tag bits = 32 - 10 - 5 = 17. So, h2
= 17/10 = 1.7 ns
-- Arjun Suresh

GATE2006_80,81 top
A CPU has a 32 KB direct mapped cache with 128 byte-block size. Suppose A is two dimensional array of size512 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 andi, j, x are in registers. Let the
number of cache misses experienced by P1 be M1 and that for P2 be M2.
80. The value of M1 is:
(A) 0
(B) 2048
(C) 16384
(D) 262144
81. The value of the ratio

M1
M2

(A) 0
(B)

1
16

(C)

1
8

(D) 16

Code being C implies array layout is row-major.


http://en.wikipedia.org/wiki/Row-major_order
When A[0][0] is fetched, 128 consecutive bytes are moved to cache. So, for the next 128/8 -1= 15 memory references there won't be a cache
miss. For the next iteration of i loop also the same thing happens as there is no temporal locality in the code. So, number of cache misses for
P1

512
16

512

= 32 512

= 2 14 = 16384

In the case of P2, the memory references are not consecutive. After A[0][0], the next access is A[1][0] which is after 512 * 8 memory locations.
Since our cache block can hold only 128 contiguous memory locations, A[1][0] won't be in cache after a[0][0] is accessed. Now, the next
location after A[0][0] is A[0][1] which will be accessed only after 512 iterations of the inner loop- after 512 distinct memory block accesses. In
our cache we have only space for 32 KB/128 B = 256 memory blocks. So, by the time A[0][1] is accessed, its cache block would be replaced.
So, each of the memory access in P2 results in a cache miss. Total number of cache miss

= 512 512
So,

M1
M2

32512
512512

1
16

-- Arjun Suresh

GATE2014-1_43 top
Consider a 6-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining.
When an application is executing on this 6-stage pipeline, the speedup achieved with respect to non-pipelined execution if 25% of the
instructions incur 2 pipeline stall cycles is ____________

Time without pipeline = 6 stages=6 cycles


Time with pipeline =1+stall freqency*stall cycle
=1+.25*2
=1.5
Speed up = 6/1.5
=4
-- aravind90

GATE2014-1_44 top
An access sequence of cache block addresses is of length N and contains n unique block addresses. The number of unique block addresses
between two consecutive accesses to the same block address is bounded above by k. What is the miss ratio if the access sequence is passed
through a cache of associativity A k exercising least-recently-used replacement policy?
(A)

n/N

(B)

1/N

(C) 1/A
(D) k/n

There are N accesses to cache.


Out of these n are unique block addresses.
Now, we need to find the number of misses. (min. n misses are guaranteed)
We are given that between two consecutive accesses to the same block, there can be only k-1 unique block addresses. So, for a block to get
replaced we can assume that all the next k-1 block addresses goes to the same set (given cache is set-associative) which will be the worst
case scenario. Now, if associativity size is >= k, and if we use LRU (Least Recently Used) replacement policy, we can guarantee that these k
accesses wont throw out our previously accessed cache entry (for that we need at least k accesses). So, this means we are at the best-cache
scenario for cache replacement -- out of N accesses we miss only n (which are unique and can not be helped from getting missed). So, miss
ratio is n/N.
-- Arjun Suresh

GATE2014-1_55 top
Consider two processors P 1 and P 2 executing the same instruction set. Assume that under identical conditions, for the same input, a program running on

P2

takes 25% less time but incurs 20% more CPI (clock cycles per instruction) as compared to the program running on
the clock frequency of P 2 (in GHz) is ______.

P 1 . If the clock frequency of P 1 is 1GHZ, then

CPU TIME ( T ) = No. of Instructions( I ) x No. of Cycles Per Instruction (c) x Cycle Time (t)
OR
CPU TIME ( T ) = No. of Instructions( I ) x No. of Cycles Per Instruction (c) x [Clock frequency ( f )-1]
===> T = I x c x f -1 ===> f = ( I x c) / T

P1 & P2 executing same instruction set -----> No. of Instructions same for both = 1I = I2 = I
If P1 takes T1 time ------> T2 = 0.75 x T1 -----> T2 / T1 = 0.75
If P1 incurs c1 clock cycles per instruction------> c2 = 1.2 x c1 -----> c2 / c1 = 1.2
Since I is same for both ----> ( f1 x T1 ) / c1 = ( f2 x T2 ) / c2 and f1 = 1 GHz
------> f2 = (c2/c1) x (T1/T2) x f1 = 1.2 / 0.75 x 1 GHz = 1.6 GHz
Hence,the clock frequency of

P2

is = 1.6 GHz.

-- Suraj Kaushal

GATE2014-2_9 top
A 4-way set-associative cache memory unit with a capacity of 16 KB is built using a block size of 8 words. The word length is 32 bits. The size
of the physical address space is 4 GB. The number of bits for the TAG field is ____

Number of sets = cache size / sizeof a set


Size of a set = blocksize * no. of blocks in a set
= 8 words * 4 (4-way set-associative)
= 8*4*4 (since a word is 32 bits = 4 bytes)
= 128 bytes.
So, number of sets = 16 KB / (128 B) = 128
Now, we can divide the physical address space equally between these 128 sets. So, the number of bytes each set can access
= 4 GB / 128
= 32 MB
= 32/4 = 8 M words = 1 M blocks. (2 20 blocks)
So, we need 20 tag bits to identify these 220 blocks.
-- Arjun Suresh

GATE2014-2_43 top
In designing a computer's cache system, the cache block (or cache line) size is an important parameter. Which one of the following statements
is correct in this context?
(A) A smaller block size implies better spatial locality
(B) A smaller block size implies a smaller cache tag and hence lower cache tag overhead
(C) A smaller block size implies a larger cache tag and hence lower cache hit time
(D) A smaller block size incurs a lower cache miss penalty

(A) A smaller block size means during a memory access only a smaller part of near by addresses are brought to cache- meaning spatial
locality is reduced.
(B) A smaller block size means more number of blocks (assuming cache size constant)and hence we need more cache tag bits to identify the
correct block. So, cache tag becomes bigger.
(C) A smaller block size implying larger cache tag is true, but this can't lower cache hit time in any way.

(D) A smaller block size incurs a lower cache miss penalty. This is because during a cache miss, an entire cache block is fetched from next
lower level of memory. So, a smaller block size means only a smaller amount of data needs to be fetched and hence reduces the miss penalty
(Cache block size can go til the size of data bus to the next level of memory, and beyond this only increasing the cache block size increases
the cache miss penalty).
-- Arjun Suresh

GATE2014-2_44 top
If the associativity of a processor cache is doubled while keeping the capacity and block size unchanged, which one of the following is
guaranteed to be NOT affected?
(A) Width of tag comparator
(B) Width of set index decoder
(C) Width of way selection multiplexor
(D) Width of processor to main memory data bus

If associativity is doubled, keeping the capacity and block size constant, then the number of sets gets halved. So, width of set index decoder
can surely decrease - (B) is false.
Width of way-selection muntiplexer must be increased as we have to double the ways to choose from- (C) is false
As the number of sets gets decreased, the number of possible cache block entries that a set maps to gets increased. So, we need more tag
bits to identify the correct entry. So, (A) is also false.
(D) is the correct answer- main memory data bus has nothing to do with cache associativity- this can be answered without even looking at
other options.
-- Arjun Suresh

GATE2014-3_9 top
Consider the following processors (ns stands for nanoseconds). Assume that the pipeline registers have zero latency.
P1: Four-stage pipeline with stage latencies 1 ns, 2 ns, 2 ns, 1 ns.
P2: Four-stage pipeline with stage latencies 1 ns, 1.5 ns, 1.5 ns, 1.5 ns.
P3: Five-stage pipeline with stage latencies 0.5 ns, 1 ns, 1 ns, 0.6 ns, 1 ns.
P4: Five-stage pipeline with stage latencies 0.5 ns, 0.5 ns, 1 ns, 1 ns, 1.1 ns.
Which processor has the highest peak clock frequency?
(A) P1
(B) P2
(C) P3
(D) P4

frequency = 1 / max( time in stages)


for P3 it is 1/1 GHz
for P1 it is 1/2 = 0.5 GHz
for P2, it is 1/1.5 = 0.67 GHz
for P4, it is 1/1.1 GHz
-- Arpit Dhuriya

GATE2014-3_43 top
An instruction pipeline has five stages, namely, instruction fetch (IF), instruction decode and register fetch (ID/RF), instruction execution (EX),
memory access (MEM), and register writeback (WB) with stage latencies 1 ns, 2.2 ns, 2 ns, 1 ns, and 0.75 ns, respectively (ns stands for
nanoseconds). To gain in terms of frequency, the designers have decided to split the ID/RF stage into three stages (ID, RF1, RF2) each of

latency 2.2/3 ns. Also, the EX stage is split into two stages (EX1, EX2) each of latency 1 ns. The new design has a total of eight pipeline
stages. A program has 20% branch instructions which execute in the EX stage and produce the next instruction pointer at the end of the EX
stage in the old design and at the end of the EX2 stage in the new design. The IF stage stalls after fetching a branch instruction until the next
instruction pointer is computed. All instructions other than the branch instruction have an average CPI of one in both the designs. The execution
times of this program on the old and the new design are P and Q nanoseconds, respectively. The value of P /Q is __________.

cpi for first case = 2.2(1+2*.2) as the stall required is 2 and 2.2 is the maximum stage delay.
cpi for second state = 1*(1+5*.2) as now stall increase to 5 as there are five stages before the address is calculated and the maximum stage
delay now is 1.
cpu_time1/cpu_time2 = 3.08/2 = 1.54
-- Arpit Dhuriya

GATE2014-3_44 top
The memory access time is 1 nanosecond for a read operation with a hit in cache, 5 nanoseconds for a read operation with a miss in cache, 2 nanoseconds for a
write operation with a hit in cache and 10 nanoseconds for a write operation with a miss in cache. Execution of a sequence of instructions involves 100 instruction
fetch operations, 60 memory operand read operations and 40 memory operand write operations. The cache hit-ratio is 0.9. The average memory access time (in
nanoseconds) in executing the sequence of instructions is ______.

Fetch is also a memory read operation.....

avg access time = [160(.9*1+.1*5)+.40(.9*2+.1*10)]/200


=[160*1.4+40*2.8]/200
=336/200
=1.68
-- aravind90

GATE2011_28 top
On a non-pipelined sequential processor, a program segment, which is the part of the interrupt service routine, is given to transfer 500 bytes
from an I/O device to memory.
Initialize the address register
Initialize the count to 500
LOOP: Load a byte from device
Store in memory at address given by address register
Increment the address register
Decrement the count
If count !=0 go to LOOP

Assume that each statement in this program is equivalent to a machine instruction which takes one clock cycle to execute if it is a nonload/store instruction. The load-store instructions take two clock cycles to execute.
The designer of the system also has an alternate approach of using the DMA controller to implement the same transfer. The DMA controller
requires 20 clock cycles for initialization and other overheads. Each DMA transfer cycle takes two clock cycles to transfer one byte of data from
the device to the memory.
What is the approximate speed up when the DMA controller based design is used in a place of the interrupt driven program based inputoutput?
(A) 3.4
(B) 4.4
(C) 5.1
(D) 6.7

STATEMENT

CLOCK CYCLE(S) NEEDED

Initialize the address register


1
Initialize the count to 500
1
LOOP: Load a byte from device
2
Store in memory at address given by address register
Increment the address register
1
Decrement the count
1
If count != 0 go to LOOP
1

Interrrupt driven transfer time = 1+1+500(2+2+1+1+1) = 3502


DMA based transfer time = 20+500*2 = 1020
Speedup = 3502/1020 = 3.4

-- Manu Thakur

GATE2011_41 top
Consider an instruction pipeline with four stages (S1, S2, S3 and S4) each with combinational circuit only. The pipeline registers are required between each stage
and at the end of the last stage. Delays for the stages and for the pipeline registers are as given in the figure.

What is the approximate speed up of the pipeline in steady state under ideal conditions when compared to the corresponding non-pipeline implementation?
(A) 4.0
(B) 2.5
(C) 1.1
(D) 3.0

I think the answer is B. 2.5


In pipeline system Time taken is determined by the max delay at any stage ie, 11ns plus the delay incurred by pipeline stages ie 1ns =12ns.
In non-pipeline system Delay=5ns+6ns+11ns+8ns=30ns.

-- Praneeth A S

GATE2010_33 top
A 5-stage pipelined processor has Instruction Fetch (IF), Instruction Decode (ID), Opearnd 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 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?
Instruction

t0
t1
t2
t3

(A) 13

:
:
:
:

MUL R 2 , R 0 , R 1
DIV R 5 , R 3 , R 4
ADD R 2 , R 5 , R 2
SUB R 5 , R 2 , R 6

Meaning of instruction

R2
R5
R2
R5

R0 R1
R 3 /R 4
R5 + R2
R2 R6

(B) 15
(C) 17
(D) 19

t1 t2 t3

t4

t5

t6

t7

t8

t9

t10 t11 t12 t13 t14

t15

IF ID OF PO PO PO WO
IF ID
IF

OF

PO PO PO PO PO PO

ID

OF

IF

ID

PO WO
OF

PO

WO

Operand forwarding allows an output to be passed for the next instruction. Here from the output of PO stage of DIV instruction operand is
forwarded to the PO stage of ADD instruction and similarly between ADD and SUB instructions.
http://www.cs.iastate.edu/~prabhu/Tutorial/PIPELINE/forward.html
-- Arjun Suresh

GATE2010_48,49 top
A computer system has an L1 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 in L2
cache is 16 words. The memory access times are 2 nanoseconds, 20 nanoseconds and 200 nanoseconds for L1 cache, L2 cache and the main memory unit
respectively.

Q.48 When there is a miss in L1 cache and a hit in L2 cache, a block is transferred from L2 cache to L1 cache. What is the time taken for this transfer?

(A) 2 nanoseconds
(B) 20 nanoseconds
(C) 22 nanoseconds
(D) 88 nanoseconds

Q.49 When there is a miss in both L1 cache and L2 cache, first a block is transferred from main 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
(B) 888 nanoseconds
(C) 902 nanoseconds
(D) 968 nanoseconds

A block is transferred from L2 to L1. And L1 block size being 4 words (since L1 is requesting we need to consider L1 block size and not L2
block size) and data width being 4 bytes, it requires one L2 access (for read) and one L1 access (for store). So, time = 20+2 = 22 ns.
For the second question, L2 block size being 16 words and data width between memory and L2 being 4 words, we require 4 memory
accesses(for read) and 4 L2 accesses (for store). Now, we need to send the requested block to L1 which would require one more L2 access
(for read) and one L1 access (for store). So, total time
= 4 * (200 + 20) + (20 + 2)
= 880 + 22
= 902 ns
-- Arjun Suresh

GATE1995_1.2

top

It is C.
Only the top of the stack can be accessed at any time. You can imagine a stack to be opened from only one side data structure. So that if we
put one thing over the other, we are able to access the last thing we inserted first. That is Last in First Out.(LIFO).
-- Gate Keeda

GATE1995_1.6

top

The principle of locality justifies the use of


(a) Interrupts
(b) DMA
(c) Polling
(d) Cache Memory

It is D.
Locality of reference is actually the frequent accessing of any storage location or some value. We can say in simple language that whatever
things are used more frequently, they are stored in the locality of reference. So we have cache memory for the purpose.
-- Gate Keeda

GATE1995_2.25 top
A computer system has a 4 K word cache organized in block-set-associative manner with 4 blocks per set, 64 words per block. The number of
bits in the SET and WORD fields of the main memory address format is:
(A) 15, 40
(B) 6, 4
(C) 7, 2
(D) 4, 6

Number of sets = 4K /(64*4) = 16. So, we need 4 bits to identify a set => SET = 4 bits.
64 words per block means WORD is 6 bits.
So, (D)
-- Arjun Suresh

GATE2008-IT_38 top
Assume that EA = (X)+ is the effective address equal to the contents of location X, with X incremented by one word length after the effective
address is calculated; EA = (X) is the effective address equal to the contents of location X, with X decremented by one word length before the
effective address is calculated; EA = (X) is the effective address equal to the contents of location X, with X decremented by one word length
after the effective address is calculated. The format of the instruction is (opcode, source, destination), which means (destination source op
destination). Using X as a stack pointer, which of the following instructions can pop the top two elements from the stack, perform the addition
operation and push the result back to the stack.

A)

ADD (X), (X)

B)

ADD (X), (X)

C)

ADD (X), (X)+

D)

ADD (X), (X)

I think it should be A as 998<-1000+998.(i am writing only memory locations for sake of brevity).lets say sp is 1000 initially then after it calculates the EA of source(which is 1000 as it
decrements after the EA) the destination becomes 998 and that is where we want to store the result as stack is decrementing...in case of C and D it becomes 998<-998+998

-- Shaun Patel

GATE2008-IT_80 top
Consider a computer with a 4-ways set-associative mapped cache of the following characteristics: a total of 1 MB of main memory, a word size
of 1 byte, a block size of 128 words and a cache size of 8 KB.
The number of bits in the TAG, SET and WORD fields, respectively are:

A.

7, 6, 7

B.

8, 5, 7

C.

8, 6, 6

D.

9, 4, 7

Number of cache blocks = 8KB/(128*1) = 64


Number of sets in cache = Number of cache blocks/ 4 (4-way set)
= 64 / 4 = 16
So, number of SET bits required = 4 (as 24 = 16, and with 4 bits we can get 16 possible outputs)
We can now straight away choose (D) as answer but for confirmation can proceed further.
Since, only physical memory information is given we can assume cache is physically tagged (which is anyway the common case even in case
of virtual memory). So, we can divide the physical memory into 16 regions so that, each set maps into only its assigned region. So, size of a
region a set can address = 1MB/16 = 216 Bytes = 216 /128 = 29 cache blocks (as cache block size is 128 words = 128 bytes). So, when an
access comes to an cache entry, it must be able to determine which out of the 29 possible physical block it is. In short it needs 9 bits for TAG.
Now, cache block size is 128 words and so to identify a word we need 7 bits for WORD.

-- Arjun Suresh

GATE2008-IT_81 top
Consider a computer with a 4-ways set-associative mapped cache of the following characteristics: a total of 1 MB of main memory, a word size
of 1 byte, a block size of 128 words and a cache size of 8 KB.
While accessing the memory location 0C795H by the CPU, the contents of the TAG field of the corresponding cache line is

A.

000011000

B.

110001111

C.

00011000

D.

110010101

As shown in https://gateoverflow.in/3403/gate2008-it_80 we have 16 sets in cache and correspondingly 16 regions in physical memory to
which each set is mapped. Now, WORD bit size is 7 as we need 7 bits to address 128 possible words in a cache block. So, the lowest 7 bits of
0C795H will be used for this giving us the remaining bits as
0000 1100 0111 1
Of these bits, the lower 4 are used for addressing the 16 possible sets, giving us the tag bits: 0000 1100 0 in (A) choice.
-- Arjun Suresh

GATE2007-IT_37 top
Consider a Direct Mapped Cache with 8 cache blocks (numbered 0-7). If the memory block requests are in the following order
3, 5, 2, 8, 0, 63, 9,16, 20, 17, 25, 18, 30, 24, 2, 63, 5, 82,17, 24.
Which of the following memory blocks will not be in the cache at the end of the sequence ?

A)

B)

18

C)

20

D)

30

ans is B
cache location (memory block) = block req mod number of cache blocks. Since each block has only one location (associativity is 1) the last
mod 8 request will be in cache (no need of any replacement policy as mapping is direct)
0 block - 8,0,16, at end contains 24
1- at ends contains 17
2 - at end contains 82
3-3
4- 20
5-5
6-30
7-63
-- rajsh3kar

GATE2006-IT_39 top
Which of the following statements about relative addressing mode is FALSE?

A)

It enables reduced instruction size

B)

It allows indexing of array elements with same instruction

C)

It enables easy relocation of data

D)

It enables faster address calculations than absolute addressing

(D) is false. Relative addressing cannot be faster than absolute addressing as absolute address must be calculated from relative address.
(A) is true as instead of absolute address we can use a much smaller relative address in instructions which results in smaller instruction size.
(B) By using the base address of array we can index array elements using relative addressing.
(C) is true as we only need to change the base address in case of relocation- instructions remain the same.
-- Arjun Suresh

GATE2006-IT_40 top
The memory locations 1000, 1001 and 1020 have data values 18, 1 and 16 respectively before the following program is executed.
MOVI
Rs, 1
; Move immediate
LOAD
Rd, 1000(Rs)
; Load from memory
ADDI
Rd, 1000
; Add immediate
STOREI 0(Rd), 20
; Store immediate
Which of the statements below is TRUE after the program is executed ?

A)

Memory location 1000 has value 20

B)

Memory location 1020 has value 20

C)

Memory location 1021 has value 20

D)

Memory location 1001 has value 20

D) Memory location 1001 has value 20.

Rs<-1
Rd<-1
Rd<-1001
store in address 1001 <- 20
-- Abhinav Rana

GATE2006-IT_42 top
A cache line is 64 bytes. The main memory has latency 32ns and bandwidth 1G.Bytes/s. The time required to fetch the entire cache line from
the main memory is

A)

32 ns

B)

64 ns

C)

96 ns

D)

128 ns

ans : c
for 1 sec it is 10^9 bytes
so for 64 bytes?
it is 64 * 1 /10^9 so it is 64 ns but mm latency is 32 so total time required to place cache line is
64+32 = 96 ns
-- rajsh3kar

GATE2006-IT_79 top
A pipelined processor uses a 4-stage instruction pipeline with the following stages: Instruction fetch (IF), Instruction decode (ID), Execute (EX)
and Writeback (WB). The arithmetic operations as well as the load and store operations are carried out in the EX stage. The sequence of
instructions corresponding to the statement X = (S - R * (P + Q))/T is given below. The values of variables P, Q, R, S and T are available in the
registers R0, R1, R2, R3 and R4 respectively, before the execution of the instruction sequence.
ADD
R5, R0, R1
; R5 R0 + R1
MUL
SUB
DIV
STORE

R6, R2, R5
R5, R3, R6
R6, R5, R4
R6, X

; R6 R2 * R5
; R5 R3 - R6
; R6 R5/R4
; X R6

The IF, ID and WB stages take 1 clock cycle each. The EX stage takes 1 clock cycle each for the ADD, SUB and STORE operations, and 3
clock cycles each for MUL and DIV operations. Operand forwarding from the EX stage to the ID stage is used. The number of clock cycles
required to complete the sequence of instructions is

A)

10

B)

12

C)

14

D)

16

This is what i have solved. so answer is 12


-- Manu Thakur

GATE2004-IT_12 top
Consider a system with 2 level cache. Access times of Level 1 cache, Level 2 cache and main memory are 1 ns, 10 ns, and 500 ns,
respectively. The hit rates of Level 1 and Level 2 caches are 0.8 and 0.9, respectively. What is the average access time of the system ignoring
the search time within the cache?
A)

13.0 ns

B)

12.8 ns

C)

12.6 ns

D)

12.4 ns

option C
t1 * h1 + (1- h1) h2 t2 + (1-h1) (1-h2) tm
tm- main memory access time
-- rajsh3kar

GATE2004-IT_47 top
Consider a pipeline processor with 4 stages S1 to S4. We want to execute the following loop:
for (i = 1; i < = 1000; i++)
{I1, I2, I3, I4}

where the time taken (in ns) by instructions I1 to I4 for stages S1 to S4 are given below:

The output of I1 for i = 2 will be available after


A)

11 ns

B)

12 ns

C)

13 ns

D)

28 ns

time

I1

s1

s2

s2

s3

s4

s4

s1

s1

s2

s3

s3

s4

s1

s2

s1

s1

I2
I3
I4
I1

so total time would be=13 ns

10

11

s3

s3

s4

s2

s1

s2

s3

s3

s4

s2

s3

12

13

s4

s4

so option (c).
correct me if i am wrong...
-- Suvojit Mondal

GATE2004-IT_48 top
Consider a fully associative cache with 8 cache blocks (numbered 0-7) and the following sequence of memory block requests:
4, 3, 25, 8, 19, 6, 25, 8, 16, 35, 45, 22, 8, 3, 16, 25, 7
If LRU replacement policy is used, which cache block will have memory block 7?

A)

B)

C)

D)

When 45 comes, the cache contents are


4 3 25 8 19 6 16 35
LRU array (first element being least recently used)
[4 3 19 6 25 8 16 35]
So, 45 replaces 4
45 3 25 8 19 6 16 35 [3 19 6 25 8 16 35 45]
Similarly 22 replaces 3 to give
45 22 25 8 19 6 16 35 [19 6 25 8 16 35 45 22]
8 hits in cache
45 22 25 8 19 6 16 35 [19 6 25 16 35 45 22 8]
3 replaces 19
45 22 25 8 3 6 16 35 [6 25 16 35 45 22 8 3]
16 and 25 hits in cache
45 22 25 8 3 6 16 35 [6 35 45 22 8 16 25 3]
Finally 7 replaces 6, which is in block 5.
So, answer is (B)
-- Arjun Suresh

GATE2004-IT_49 top
A CPU has only three instructions I1, I2 and I3, which use the following signals in time steps T1-T5:
I1 : T1 : Ain, Bout, Cin
T2 : PCout, Bin
T3 : Zout, Ain
T4 : Bin, Cout
T5 : End
I2 : T1 : Cin, Bout, Din
T2 : Aout, Bin
T3 : Zout, Ain
T4 : Bin, Cout
T5 : End
I3 : T1 : Din, Aout
T2 : Ain, Bout
T3 : Zout, Ain

T4 : Dout, Ain
T5 : End
Which of the following logic functions will generate the hardwired control for the signal Ain ?

A)

T1.I1 + T2.I3 + T4.I3 + T3

B)

(T1 + T2 + T3).I3 + T1.I1

C)

(T1 + T2 ).I1 + (T2 + T4).I3 + T3

D)

(T1 + T2 ).I2 + (T1 + T3).I1 + T3

We just have to see which all options give 1 whenever Ain is 1 and 0 otherwise.
So, Ain is 1 in T3 of I1, I2 and I3. Also during T1 of I1, and T2 and T4 of I3. So, answer will be
T1.I1 + T2.I3 + T4.I3 + T3.I1 + T3.I2 + T3.I3
Since CPU is having only 3 instructions, T3.I1 + T3.I2 + T3.I3 can be replaced with T3 (we don't need to see which instruction and A
in will be
activated in time step 3 of all the instructions).
So, T1.I1 + T2.I3 + T4.I3 + T3
is the answer. Option A.
-- Arjun Suresh

GATE2005-IT_49 top
An instruction set of a processor has 125 signals which can be divided into 5 groups of mutually exclusive signals as follows:
Group 1 : 20 signals, Group 2 : 70 signals, Group 3 : 2 signals, Group 4 : 10 signals, Group 5 : 23 signals.
How many bits of the control words can be saved by using vertical microprogramming over horizontal microprogramming?
A)

B)

103

C)

22

D)

55

In horizontal microprogramming we need 1 bit for every control word, therefore total bits in
Horizontal Microprogramming=20+70+2+10+23=125
Now lets consider vertical microprogramming, In vertical microprogramming we use Decoder (n to 2n ) and output lines are equal to number
of control words . A input is given according to what control word we have to select.
Now in this question these 5 groups contains mutually exclusive signals, i.e, they can be activated one at a time for a given group, we can
safely use decoder.
group 1= log220=5 (Number of input bits for decoder, given output is number of control word in given group)
group 2= log270 =7
group 3= log22 =1
group 4= log210 =4
group 5= og223 =5
Total bits required in vertical microprogramming= 5+7+1+4+5=22
So number of control words saved= 125-22=103 hence (B) is answer
-- Prateeksha Keshari

GATE2005-IT_61 top
Consider a 2-way set associative cache memory with 4 sets and total 8 cache blocks (0-7) and a main memory with 128 blocks (0-127). What
memory blocks will be present in the cache after the following sequence of memory block references if LRU policy is used for cache block

replacement. Assuming that initially the cache did not have any memory block from the current job?
0 5 3 9 7 0 16 55

A)

0 3 5 7 16 55

B)

0 3 5 7 9 16 55

C)

0 5 7 9 16 55

D)

3 5 7 9 16 55

128 main memory blocks are mapped to 4 sets in cache. So, each set maps 32 blocks each. And in each set there is place for two blocks (2way set).
Now, we have 4 sets meaning 2 index bits. Also, 32 blocks going to one set means 5 tag bits.
Now, these 7 bits identify a memory block and tag bits are placed before index bits. (otherwise adjacent memory references- spatial localitywill hamper cache performance)
So, based on the two index bits (lower 2 bits) blocks will be going to sets as follows:
Set Number

Block Numbers

0,16

5, 9

2
3

3, 7, 55

Since, each set has only 2 places, 3 will be throw out as its the least recently used block. So, final content of cache will be
0 5 7 9 16 55
(C) choice.

-- Arjun Suresh

coa top
A hard disk with a transfer rate of 10 M bytes/second is constantly 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%
(D) 0.1%

Solution : D
Transfer rate =10MBps
Data to be transferred = 20KB

Duration of transfer =
= 2 2 10

20210
10220

Frequency of the CPU = 600MHz


Clock overhead for transfer = 300 + 900 = 1200 clock cycles.
Time for 1200 clocks =

1200
600106

= 2 106 and processor is used only for this much of time. So,

Percentage of CPU time consumed =

2104
2103

= 0.1% ( 2 10 103 )

2106
2210

100%

-- Gowthaman Arumugam

GATE2015-2_24 top
Assume that for a certain processor, a read request takes 50 nanoseconds on a cache miss and 5 nanoseconds on a cache hit. Suppose while
running a program, it was observed that 80% of the processor's read requests result in a cache hit. The average read access time in
nanoseconds is _____.

Ans 14 ns = 0.8(5) + 0.2(50)


-- Vikrant Singh

GATE2015-2_42 top
Consider a processor with byte-addressable memory. Assume that all registers, including program counter (PC) and Program Status Word
(PSW), are size of two bytes. A stack in the main memory is implemented from memory location (0100)16 and it grows upward. The stack
pointer (SP) points to the top element of the stack. The current value of SP is (016E)16 . The CALL instruction is of two words, the first word is
the op-code and the second word is the starting address of the subroutine (one word = 2 bytes). The CALL instruction is implemented as
follows:
Store the current value of PC in the stack
Store the value of PSW register in the stack
Load the statring address of the subroutine in PC
The content of PC just before the fetch of a CALL instruction is(5F A0)16 . After execution of the CALL instruction, the value of the stack pointer
is

A.
B.
C.
D.

(016A)16
(016C)16
(0170)16
(0172)16

first we have to consider here memory is byte-addressable


The CALL instruction is implemented as follows:
Store the current value of PC in the stack
pc is 2 byte it means when we store pc in stack it will increase by 2
so current value of SP is (016E)16 +2
Store the value of PSW register in the stack
psw is 2 byte it means when we store psw in stack it will increase by 2
so current value of SP is (016E)16 +2+2 =(0172)16
-- Anoop Sonkar

GATE2015-1_38 top
Consider a non-pipelined processor with a clock rate of 2.5 gigahertz and average cycles per instruction of four. The same processor is
upgraded to a pipelined processor with five stages; but due to the internal pipeline delay, the clock speed is reduced to 2 gigahertz. Assume
that there are no stalls in the pipeline. The speedup achieved in this pipelined processor is_______________.

answer is 3.2

Speed up = Old execution time/New execution time


= CPIold / CFold / (CPInew / CFnew) (CF is clock frequency and CPI is Cycles Per Instruction, so CPI/CF gives time per instruction)
= 4 / 2.5 / (1 / 2)
= 3.2
Without pipelining an instruction was taking 4 cycles. After pipelining to 5 stages we need to see the max. clock cycle a stage can take and
this will be the CPI assuming no stalls.
-- naresh1845

GATE2015-3_47 top
Consider the following code sequence having five instructions fromI 1 to I 5 . Each of these instructions has the following format.
OP Ri, Rj, Rk
Where operation OP is performed on contents of registers Rj and Rk and the result is stored in register Ri.

I 1 : ADD R1, R2, R3


I 2 : MUL R7, R1, R3
I 3 : SUB R4, R1, R5
I 4 : ADD R3, R2, R4
I 5 : MUL R7, R8, R9
Consider the following three statements.
S1: There is an anti-dependence between instructions I 2 and I 5
S2: There is an anti-dependence between instructions I 2 and I 4
S3: Within an instruction pipeline an anti-dependence always creates one or more stalls
Which one of the above statements is/are correct?

A.
B.
C.
D.

Only S1 is true
Only S2 is true
Only S1 and S3 are true
Only S2 and S3 are true

Answer should be B.
Anti-dependence can be overcome in pipeline using register renaming. So, "always" in S3 makes it false. Also, if I2 is completed before I4
(execution stage of MUL), then also there won't be any stall.
-- ppm

Mapping Strategies

top

A 2-way set associative cache consists of four sets. Main memory contains 2K blocks of eight words each.
a) Show the main memory address format that allows us to map addresses from main memory to cache. Be sure to include the fields as well
as their sizes.
b) Compute the hit ratio for a program that loops 3 times from locations 8 to 51 in main memory. You may leave the hit ratio in terms of a
fraction.
Hello Sir, I am write now solving sums from "The essentials of Computer architecture " I got this sum . and there is no solution provided i just
wanna ask you to check this
Solution :
No of lines in a set=2
No of set in Cache = 4
Block size=8 words

So, Size of each cache= No of set* No of line in set * Block Size= 8*4*2=64 Words
Size of MM= no of block in main memory * size of each block=(2^11)*(2^3)= 2^14 words
Bits used to represent Physical address = 14 bits
Field of Cache address will be
1. word offset = 3 bits
2. index bits = 2 bits
3.Therefore no of bits used to represent Tag field =(14-(3+2)) = 9 bits.

Now the solution for part b


Since the size of both memory is expressed in words
We have a cache size/ capacity = 64 words and Size of Main Memory as( 2 ^ 14 words )
And since the loop says it starts from location 8 to 51 then . No of elements that will be encountered = (51-8+1)= 44 which is equivalent for
running i from 0 to 43 times (for 44 words )
Since they have asked for 3 iteration,
we know that size of cache= 64 words
And the required data that we have is 44 words
Out of these 44 words there would be 22 words which would be mapped to set 0 and 22 words which would be mapped to Set 1
Now in each Set , we have 2 lines and Each block has a size of 8 words ,
So in 16 words we have would have 2 miss
And so in reamining in (22-16) words we would have 6 words . to accomodate these 6 words again 1 block need to replaced
So total miss in 1 set in first iteration is 3 miss
Similarly total miss in second set in first iteration = 3 miss
Total no of miss in first iteration = 6 miss
While in second iteration there would be again need of replacing 1 block to (first 8 words ) rest would be hit till and then again 1 miss for (last 6
words ) this is just for 1 set
so total no of miss in second iteration=4 (both sets )
And similarly Total no of miss in third set = 4
And miss ratio would be equal to = (6+4+4)/(44+44+44)= 14/132.
Is this correct ? Please help . i am sorry to write such a big content . But this question need and to show my way of approaching towards sums
:)

Your first part is correct. But b part is not.


Actually in first part we got 9 tag bits, 2 index bits and 3 offset bits. So, these bits are like these:
tag bits | index bits | offset bits
That is, the lower bits are offset bits followed by index bits and then tag bits.
Our memory access starts from address 8. With 3 offset bits, this cache line reference will be from address 8 to address 15 (1000 - 1111 in
binary). Say this cache line goes to cache set A during the memory access for address 8. Next 7 accesses are cache hits. When address 16
is accessed, its cache line goes to set B and not set A because after offset comes the index/set bits so the set changes (this is made so that
spacial locality won't reduce cache hits). Now, all accesses till 23 are hits and 24 will be a miss and cache line for 24 goes to set C. Similarly,
cache line for 32 goes to set D. Now, for cache line of 40, it should go to set A. But it won't replace the cache line at set A, as each set has
space for 2 cache lines (2-way associative). Similarly cache line of address 48 goes to set B. And that is the last cache miss in iteration 1. So,
we have 6 cache misses and 38 cache misses in iteration 1. For iterations 2 and 3, all are cache hits. So,
hit ratio = (38 + 44 + 44) / (3 * 44)
= 126/132
-- Arjun Suresh

In Operand Forwarding technique how does the next instruction is able to access the
dependent operand which is calculated in the previous instruction in the same Cpu Cycle?
top

In the same CPU cycle is not possible. Operand forwarding happens in the next cycle after the operation producing the operand is finished.
-- Arjun Suresh

co top
What will be the minimum size of ROM which maintains truth table of square of 3 bit numbers(in bits) ?

Truth Table will be as:


I0

I1

I2

B0

B1

B2

B3

B4

B5

example for 111 (7), square will 110001 (49)


so it will have 3 address line mean 8 address [000 to 111] and 6 bits [B0 to B5] at each address = 8 X 6 = 48 bits
but we do not need to store B4 and B5 [as B4 = 0 and B5 = I2 ]
so ROM will be of size 8 x 4 = 32bits.
-- Praveen Saini

16 KB, 4-way set-associative cache, 32-bit address, byte addressable memory, 32-byte
cache blocks/lines top
16 KB, 4-way set-associative cache, 32-bit address, byte addressable memory, 32-byte cache blocks/lines
1. How many tag bits?
2. Where would you find the word at address 0x200356A4?

Cache size = 16kB = 14 bit


Block size = 32B = 5 bit
No of sets = 4 = 2 bit
No of cache lines = 14 -(5+2) = 7 bit
No of tag bit = 32 - (#set bit) - (#block bit)
.

= 32 - 7 - 5 = 20 bit

0x200356A4 = (<0010 0000 0000 0011 0101> <0110 101> <0 0100>)
=(<tag no><set no><block no>)

Set no = 0110101 = 51th set


Block no = 00100 = 4th block
-- Digvijay Pandey

cache memory top


A computer system contains a main memory of 32K 16-bit words. It also has a 4Kword cache divided into four-line sets with 64 words per line.
Assume that the cache is initially empty. The processor fetches words from locations 0, 1, 2, . . ., 4351 in that order. It then repeats this fetch
sequence nine more times.The cache is 10 times faster than main memory. Estimate the improvement resulting from the use of the
cache. Assume an LRU policy for block replacement.

Memory access time without cache = 4352 10x = 43520x, where x is the time for one access.
In cache we have 64 words per line and 4 lines per set (4 way associativity) and total size is 4096 words. So,

number of sets =

4096
644

= 16

So after accessing 16 64 = 1024 words (0-1023) all the sets will be filled with one entry each. But with 4-way associativity each set has
space for 3 more. So filling can go like this for 4096 words (0-4095). After this next entry (cache line from 4096-4159) will go to first set and will
replace the cache line 0-63 due to LRU policy. Like wise total no. of cache replacements = (4351-4096)/64 = 256/64 = 4.
Now for the second iteration the first four cache line accesses will be cache misses as they got replaced. But these cache lines will be
replacing the oldest used one in the set. For example cache line 0-63 will be replacing 1024-1095. Now the cache line 1024-1095 will in turn
be replacing 2048-2111 and likewise all new cache line accesses will be cache misses (LRU works badly). This will trigger 16 cache line
misses - 4 each from the first four sets. For 5th set to 16th set, there won't be any cache miss. Now, for the cache lines 4096-4351, there
will be 4 more cache misses which are again coming from the first 4 sets. So, totally 16+4 = 20 cache misses. (Shown in figure at end)

Thus,

Access time with cache = No. of cache hits hit time


+no. of cache misses memory access time
(Assuming simultaneous access possible to memory)
= (4284 + 9 4332) 0.1x + (68 + 9 20)x
= 4574.9x
So,

Performance improvement =

43520x
4574.9x

= 9.45 times

-- Arjun Suresh

Operating System top


GATE2012_8

top

A process executes the code


fork();
fork();
fork();

The total number of child processes created is


(A) 3
(B) 4
(C) 7
(D) 8

At each fork() the no. of processes becomes doubled. So, after 3 fork calls, the total no. of processes will be 8. Out of this 1 is the parent
process and 7 are child processes. So, total number of child processes created is 7.
-- Arjun Suresh

Page replacement top


A memory page containing a heavily used variable that was initialized very early and is in constant use is removed when
(a) LRU page replacement algorithm is used
(b) FIFO page replacement algorithm is used
(c) LFU page replacement algorithm is used
(d) None of the above

LRU can't be used as the page is still is in use , so it will be in most high priority.
LFU can't be used as it has been accessed several time , it's frequency value will be larger.
FIFO can do it as it only considers the time the page came in RAM. So the page can be deleted byFIFO . also from that statement we can
assume FIFO wasn't in use till now.
-- Palash Nandi

GATE2013_52,53 top
A computer uses 46-bit virtual address, 32-bit physical address, and a threelevel paged page table organization. The page table base register
stores the base address of the first-level table (T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of
the second-level table (T2). Each entry of T2 stores the base address of a page of the third-level table (T3). Each entry of T3 stores a page
table entry (PTE). The PTE is 32 bits in size. The processor used in the computer has a 1 MB 16 way set associative virtually indexed
physically tagged cache. The cache block size is 64 bytes.
What is the size of a page in KB in this computer?
(A) 2 (B) 4 (C) 8 (D) 16
What is the minimum number of page colours needed to guarantee that no two synonyms map to different sets in the processor cache of this
computer?
(A) 2 (B) 4 (C) 8 (D) 16

Let the page size be x.


Since virtual address is 46 bits, we have total number of pages =

246
x

We should have an entry for each page in last level page table which here is T3. So,

number of entries in T3 =

246
x

Each entry takes 32 bits = 4 bytes. So, size of T3 =

246
x

4=

248
x

bytes

Now, T3 must occupy (sizeof T3/page size) pages and for each of these page we must have an T2 entry. So, no. of entries in T2

2 48
x

248
x2

Now, size of T2 =

4 bytes =

248
x2

2 50
x2

250
x3

pages

Now, for each of these page we must have an entry in T1. So, number of entries in T1

250
x3

And size of T1 =

250
x3

4 =

252
x3

Given in question, size of T1 is page size which we took as x. So,

x=

252
x3

x4 = 2 52
x = 2 13
= 8KB

Min. no. of page color bits = No. of set index bits + no. of offset bits - no. of page index bits (This ensures no synonym maps to different sets
in the cache)
We have 1MB cache and 64B cache block size. So,
number of sets = 1MB/(64B * Number of blocks in each set) = 16K/16 (16 way set associative) = 1K = 10
2.
So, we need 10 index bits. Now, each block being 64 (26) bytes means we need 6 offset bits.
And we already found page size = 8KB = 213, so 13 bits to index a page
Thus, no. of page color bits = 10 + 6 - 13 = 3.
With 3 page color bits we need to have 23 = 8 different page colors

Explanation for 53:


A synonym is a physical page having multiple virtual addresses referring to it. So, what we want is no two synonym virtual addresses to map
to two different sets, which would mean a physical page could be in two different cache sets. This problem never occurs in a physically
indexed cache as indexing happens via physical address bits and so one physical page can never go to two different sets in cache. In virtually
indexed cache, we can avoid this problem by ensuring that the bits used for locating a cache block (index+offset) of the virtual and physical
addresses are the same.
In our case we have 6 offset bits + 10 bits for indexing. So, we want to make these 16 bits same for both physical and virtual address. One
thing is that the page offset bits - 13 bits for 8 KB page, is always the same for physical and virtual addresses as they are never translated.
So, we don't need to make these 13 bits same. We have to only make the remaining 19 + 6 - 13 = 3 bits same. Page coloring is a way to do
this. Here, all the physical pages are colored and a physical page of one color is mapped to a virtual address by OS in such a way that a set in
cache always gets pages of the same color. So, in order to make the 3 bits same, we take all combinations of it (23 = 8) and colors the
physical pages with 8 colors and a cache set always gets a page of one color only. (In page coloring, it is the job of OS to ensure that the 3
bits are the same).
http://ece.umd.edu/courses/enee646.F2007/Cekleov1.pdf
-- Arjun Suresh

GATE2008_20 top
The data blocks of a very large file in the Unix file system are allocated using
A.
B.
C.
D.

continuous allocation
linked allocation
indexed allocation
an extension of indexed allocation

The data blocks of a very large file in the unix file system are allocated using an extension of indexed allocation or EXT2 file system. Hence
option (d) is the right answer.
-- Kalpna Bhargav

GATE2008_67 top
A processor uses 36 bit physical address 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 the 2nd level page table.
Bits 12-20 are used to index into the 3rd 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 tables are respectively
a) 20,20,20
b) 24,24,24
c) 24,24,20
d) 25,25,24

Physical address is 36 bits. So, number of page frame's possible = 36/12 = 24 (12 offset bits as given in question). So, the third level page
table must have 24 bits for addressing the page frames.
Number of third level page tables possible =

Physical memory size


Size of a third level page table

= 236/(Number of entries in third level page table * Size of an entry)


= 236/(29 * 4) (bits 12-20 gives 9 bits)
= 236/211
=225
http://www.cs.utexas.edu/~lorenzo/corsi/cs372/06F/hw/3sol.html See Problem 3, second part solution - It clearly says that we should not
assume that page tables are page aligned.
So, we need 25 bits in second level page table for addressing the third level page tables.
Now, number of second level page tables possible =

Physical memory size


Size of a second level page table

= 236/(Number of entries in second level page table * Size of an entry)


= 236/(29 * 4) (bits 21-29 gives 9 bits)
= 236/211
=225

So, we need 25 bits for addressing the second level page tables as well.
So, answer is (D).
-- Arjun Suresh

GATE1991_02,iii

top

02. Match the pairs in the following questions by writing the corresponding letters only.

A-R
B-P
C-S
D-Q
-- Gate Keeda

GATE1992_02,x top
02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:

Ans=option B
currently semaphore is 7 so after 20 P(wait) operation it will come to -12 then for 15 V(signal) operation the value comes to 2.
-- sanjeev_zerocode

GATE1992_02,xi

top

02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
(xi) A computer system has 6 tape devices, with n processes competing for them. Each process may need 3 tape drives. The maximum value
of n for which the system is guaranteed to be deadlock free is:
a.
b.
c.
d.

2
3
4
1

Answer: A
For n=3, 2-2-2 combination of resources leads to deadlock.
For n=2, 3 - 3 is the maximum need and that can always be satisfied.
-- Jon Snow

GATE2001_1.7

top

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

exploit the spatial locality of reference in a program as, if the next locality is addressed immediately, it will already be in the cache.
-- Arjun Suresh

GATE2001_1.22 top

Which of the following requires a device driver?


(A) Register
(B) Cache
(C) Main memory
(D) Disk

A disk driver is a device driver that allows a specific disk drive to communicate with the remainder of the computer. A good example of this
driver is a floppy disk driver.
-- Bhagirathi Nayak

GATE2005_72 top
Consider the following code fragment:
if (fork() == 0)
{
a = a + 5;
printf("%d, %d n", a, &a);
}
else
{
a = a - 5;
printf ("%d, %d n", a,& a);
}

Let u,v be 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?
a) x < u and y < v
b) x < u and y = v
c) x = u+10 and y < v
d) x = u+10 y = v

(d) is the answer. Child is incrementing a by 5 and parent is decrementing a by 5. So, x = u + 10.
During fork(), address space of parent is copied for the child. So, any modifications to child variable won't affect the parent variable or viceverse. But this copy is for physical pages of memory. The logical addresses remains the same between the parent and child processes.
-- gatecse

GATE2003_78,79 top
A processor uses 2-level page tables for virtual to physical address translation. Page tables 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 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 hit rate of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and TLB access time is also 1 ns.
78. Assuming that no page faults occur, the average time taken to access a virtual address is approximately (to the nearest 0.5 ns)
(A) 1.5 ns (B) 2 ns (C) 3 ns (D) 4 ns
79. Suppose a process has only the following pages in its virtual address space: two contiguous code pages starting at virtual address
0x00000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual address 0xFFFFF000. The
amount of memory required for storing the page tables of this process is
(A) 8 KB (B) 12 KB (C) 16 KB (D) 20 KB

78. It's given cache is physically addressed. So, address translation is needed for all memory accesses.
Average access time = Average address translation time + Average memory access time
= 1ns (TLB is accessed for all accesses) + 2*10*0.04 (2 page tables accessed from main memory in case of TLB miss) + Average memory access time

= 1.8ns + Cache access time + Average main memory access time


= 1.8ns + 1 * 0.9 (90% cache hit) + 0.1 * 10 (main memory is accessed for cache misses only)
= 1.8ns + 0.9 + 1
= 3.7ns

79. First level page table is addressed using 10 bits and hence contains 210 entries. Each entry is 4 bytes and hence this table requires 4 KB.
Now, the process uses only 3 unique entries from this 1024 possible entries (two code pages starting from 0x00000000 and two data pages
starting from 0x00400000 have same first 10 bits). Hence, there are only 3 second level page tables. Each of these second level page tables
are also addressed using 10 bits and hence of size 4 KB. So,
total page table size of the process
= 4 KB + 3 * 4 KB
= 16 KB

-- gatecse

GATE2002_1.23 top
The optimal page replacement algorithm will select the page that

A.
B.
C.
D.

Has not been used for the longest time in the past
Will not be used for the longest time in the future
Has been used least number of times
Has been used most number of times

Optimal page replacement algorithm will always select the page that will not be used for the longest time in the future for replacement, and
that is why the it is called optimal page replacement algorithm. Hence, (B) choice.
-- Arjun Suresh

GATE2003_76 top
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statistically linked libraries?
A. Smaller sizes of executable files
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

option c) DLL takes more time in program setup(in loading and linking phase)
Since DLLs are separated from executable, the size of executable becomes smaller.
Since DLLs are shared among multiple executables, the total memory usage of the system goes down and hence overall page fault rate
decreases.
Dynamic linking takes place during program runtime. So, if a DLL is replaced to a new version, it will automatically get linked during runtime.
There is no explicit relinking required as in the case of static linking. (This works by linking the DLL calls to Global Offset Table and the
contents of this table is filled during program run. So, a simple jump in static linking becomes an indirect jump in dynamic linking).
-- GateMaster Prime

GATE2004_12 top
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 First (SSTF), claimed by the vendor to give 50% better
benchmark results, what is the expected improvement in the I/O performance of user programs?

A.
B.
C.
D.

50%
40%
25%
0%

Question says "single sequential user process". So, all the requests to disk scheduler will be in sequence and hence there is no use of any
disk scheduling algorithm. Anyone will give the same sequence and hence the improvement will be 0%.
-- Arjun Suresh

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

A is the answer of this question, b,c,d options don't make a sense


-- Manu Thakur

GATE2007_11 top
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.
B.
C.
D.

256 Mbyte, 19 bits


256 Mbyte, 28 bits
512 Mbyte, 20 bits
64 Gbyte, 28 bits

ans is A.
16 surfaces= 4 bits, 128 tracks= 7 bits, 256 sectors= 8 bits, sector size 512 bytes = 9 bits
capacity of disk = 2^(4+7+8+9) = 2^28 = 256MB
to specify a particular sector we do not need sector size, so bits required = 4+7+8 = 19
-- jayendra

GATE2009_33 top
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.
B.
C.
D.

I only
I and II
II and III
IV only

The answer is A only.


The solution satisfies:
1) Mutual Exclusion as test-and-set is an indivisible (atomic) instruction (makes option IV wrong)
2) Progress as at initially X is 0 and at least one process can enter critical section at any time.
But no guarantee that a process eventually will enter CS and hence option IV is false. Also, no ordering of processes is maintained and hence
III is also false.
So eliminating all the 3 choices remains A.
-- Gate Keeda

GATE2009_34 top
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 a memory location.


B. It helps to reduce the size of page table needed to implement the virtual address space of a process
C. It is required by the translation lookaside buffer.
D. It helps to reduce the number of page faults in page replacement algorithms.

B.
Which is a clear reason why we perform paging.
When the page table size increases we perform paging on the page table. Resulting in multi-level page table.
-- Gate Keeda

GATE2009_51,52 top
A hard disk has 63 sectors per track, 10 platters each with 2 recording 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 addresses as 0, 0, 0 , the
1st sector as 0, 0, 1 , and so on
51. The address <400, 16, 29> corresponds to sector number:

A.
B.
C.
D.

505035
505036
505037
505038

52. The address of the 1039th sector is

A. 0, 15, 31
B. 0, 16, 30
C. 0, 16, 31
D. 0, 17, 31

The data on a disk is ordered in the following way. It is first stored on the first sector of the first surface of the first cylinder. Then in the next
sector, and next, until all the sectors on the first track are exhausted. Then it moves on to the first sector of the second surface (remains at the
same cylinder), then next sector and so on. It exhausts all available surfaces for the first cylinder in this way. After that, it moves on to repeat
the process for the next cylinder.
So, to reach to the cylinder numbered 400 (401th cylinder) we need to skip 400 * (10*2) * 63 = 504,000 sectors.
Then, to skip to the 16th surface of the cylinder numbered 400, we need to skip another 16*63 = 1,008 sectors.
Finally, to find the 29 sector, we need to move another 29 sectors.
In total, we moved 504,000 + 1,008 + 29 = 505,037 sectors.
Hence, the answer to 51 is option C.
52. 1039th sector will be stored in track number (1039 + 1)/63 = 16.5 (as counting starts from 0 as given in question) and each track has 63
sectors. So, we need to go to 17th track which will be numbered 16 and each cylinder has 20 tracks (10 platters * 2 recording surface each) .
Number of extra sectors needed = 1040-16*63 = 32 and hence the sector number will be 31. So, option C.
-- Pragy Agarwal

GATE2013_16 top
Three concurrent processes X , Y , and Z execute three different code segments that access and update certain shared variables. ProcessX
executes the P operation (i.e., wait ) on semaphores a, b and c ; process Y executes the P operation on semaphores b , c and d; process Z
executes the P operation on semaphores c , d, and a before entering the respective code segments. After completing the execution of its code
segment, each process invokes the V operation (i.e., signal ) on its three semaphores. All semaphores are binary semaphores initialized to
one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?
(A) X : P (a)P (b)P (c)Y
(B) X : P (b)P (a)P (c)Y
(C) X : P (b)P (a)P (c)Y
(D) X : P (a)P (b)P (c)Y

: P (b)P (c)P (d)Z


: P (b)P (c)P (d)Z
: P (c)P (b)P (d)Z
: P (c)P (b)P (d)Z

: P (c)P (d)P (a)


: P (a)P (c)P (d)
: P (a)P (c)P (d)
: P (c)P (d)P (a)

For deadlock-free invocation, X, Y and Z must access the semaphores in the same order so that there won't be a case where one process is
waiting for a semaphore while holding some other semaphore. This is satisfied only by option B.
In option A, X can hold a and wait for c while Z can hold c and wait for a
In option C, X can hold b and wait for c, while Y can hold c and wait for b
In option D, X can hold a and wait for c while Z can hold c and wait for a
So, a deadlock is possible for all choices except B.
http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf
-- Arjun Suresh

GATE1999_2.11 top
Which of the following is/are advantage(s) of virtual memory?
(a) Faster access to memory on an average.
(b) Processes can be given protected address spaces.
(c) Linker can assign addresses independent of where the program will be loaded in physical memory.
(d) Program larger than the physical memory size can be run.

Virtual memory provides an interface through which processes access the physical memory. So,
(a) Is false as direct access can never be slower.
(b) Is true as without virtual memory it is difficult to give protected address space to processes as they will be accessing physical memory
directly. No protection mechanism can be done inside the physical memory as processes are dynamic and number of processes changes
from time to time.
(c) Position independent can be produced even without virtual memory support.
(d) This is one primary use of virtual memory. Virtual memory allows a process to run using a virtual address space and as and when memory
space is required, pages are swapped in/out from the disk if physical memory gets full.
-- Arjun Suresh

GATE2013_39 top
A certain computation generates two arrays a and b such that a[i] = f(i) for 0 i < n and b[i] = g(a[i]) for 0 i < n. Suppose this computation is
decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two
binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown
below.
Process X:
private i;
for (i=0; i< n; i++) {
a[i] = f(i);
ExitX(R, S);
}

Process Y:
private i;
for (i=0; i< n; i++) {
EntryY(R, S);
b[i] = g(a[i]);
}

Which one of the following represents the CORRECT implementations of ExitX and EntryY?
(A)
ExitX(R, S) {
P(R);
V(S);
}
EntryY(R, S) {
P(S);
V(R);
}
(B) ExitX(R, S) {
V(R);
V(S);
}
EntryY(R, S) {
P(R);
P(S);
}
(C) ExitX(R, S) {
P(S);
V(R);

}
EntryY(R, S) {
V(S);
P(R);
}
(D) ExitX(R, S) {
V(R);
P(S);
}
EntryY(R, S) {
V(S);
P(R);
}

A choice:
X is waiting on R and Y is waiting on X. So, both cannot proceed.
B choice:
Process X is doing Signal operation on R and S without any wait and hence multiple signal operations can happen on the binary semaphore
so Process Y won't be able to get exactly n successful wait operations. i.e., Process Y may not be able to complete all the iterations.
C choice:
Process X does Wait(S) followed by Signal(R) while Process Y does Signal(S) followed by Wait(R). So, this ensures that no two iterations of
either X or Y can proceed without an iteration of the other being executed in between. i.e., this ensures that all n iterations of X and Y
succeeds and hence the answer.
D choice:
Process X does Signal(R) followed by Wait(S) while Process Y does Signal(S) followed by Wait(R). There is a problem here that X can do two
Signal(R) operation without a Wait(R) being done in between by Y. This happens in the following scenario:
Process Y: Does Signal (S); Wait(R) fails; goes to sleep.
Process X: Does Signal(R); Wait(S) succeeds; In next iteration Signal(R) again happens;
So, this can result in some Signal operations getting lost as the semaphore is a binary one and thus Process Y may not be able to complete
all the iterations. If we change the order of Signal(S) and Wait(R) in EntryY, then D option also can work.
-- Arjun Suresh

GATE1998_1.31 top

answer is option (b)


Initially semaphore is 10 , then 6 down operations are performed means (10-6=4) and 4 up operations means (4+4=8)
so , at last option(b) 8 is correct.
-- Kalpna Bhargav

GATE1998_1.32 top
A computer has six tape drives, with n processes competing for them. Each process may need two drives. What is the maximum value ofn for
the system to be deadlock free?

a.
b.
c.
d.

6
5
4
3

Each process needs 2 drives


Consider this scenario
P1 P2 P3 P4 P5 P6
1

1 1

1 1 1

This is scenario when a deadlock would happen, as each of the process is waiting for 1 more process to run to completion. And there are no
more Resources available as max 6 reached. If we could have provided one more R to any of the process, any of the process could have
executed to completion, then released its resources, which further when assigned to other and then other would have broken the deadlock
situation.
In case of processes, if there are less than 6 processes, then no deadlock occurs.
Consider the maximum case of 5 processes.
P1 P2 P3 P4 P5
1 1

1 1

In this case system has 6 resources max,and hence we still have 1 more R left which can be given to any of the processes, which in turn runs
to completion, releases its resources and in turn others can run to completion too.
Ans b) 5
-- Sourav Roy

GATE1998_2.9

top

Ans is C
http://en.wikipedia.org/wiki/Disk_formatting
-- Keith Kr

GATE1998_2.16 top

B) 14 KB is answer,
At execution time overlays D and E will both utilize the same memory locations
For example.....given below .
The following example shows the control statements that instruct the OS/360 Linkage Editor to link an overlay program, indented to show
structure:
INCLUDE SYSLIB(MOD1)
INCLUDE SYSLIB(MOD2)
OVERLAY A
INCLUDE SYSLIB(MOD3)
OVERLAY AA
INCLUDE SYSLIB(MOD4)
INCLUDE SYSLIB(MOD5)
OVERLAY AB
INCLUDE SYSLIB(MOD6)
OVERLAY B
INCLUDE SYSLIB(MOD7)

+--------------+
| Root Segment |
| MOD1, MOD2 |
+--------------+
|
+----------+----------+
|
|
+-------------+
+-------------+
| Overlay A |
| Overlay B |
| MOD3
|
| MOD7
|
+-------------+
+-------------+
|
+--------+--------+
|
|
+-------------+ +-------------+
| Overlay AA | | Overlay AB |
| MOD4, MOD5 | | MOD6
|
+-------------+ +-------------+
These statements define a tree consisting of the permanently resident segment, called theroot, and two overlays A and B which will be loaded
following the end of MOD2. Overlay A itself consists of two overlay segments, AA, and AB. At execution time overlays A and B will both utilize
the same memory locations; AA and AB will both utilize the same locations following the end of MOD3.
All the segments between the root and a given overlay segment are called apath.
refere @ http://en.wikipedia.org/wiki/Overlay_(programming)#Example
-- csegate2

GATE2014-1_31 top
An operating system uses the Banker's algorithm for deadlock avoidance when managing the allocation of three resource types X, Y, and Z to
three processes P0, P1, and P2. The table given below presents the current system state. Here, the Allocation matrix shows the current
number of resources of each type allocated to each process and the Max matrix shows the maximum number of resources of each type
required by each process during its execution.
Allocation

Max

P0

P1

P2

There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system is currently in asafe state. Consider the following
independent requests for additional resources in the current state:
REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z
REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z
Which one of the following is TRUE?

(A) Only REQ1 can be permitted.


(B) Only REQ2 can be permitted.
(C) Both REQ1 and REQ2 can be permitted.
(D) Neither REQ1 nor REQ2 can be permitted.

Option B
Request 1 if permitted does not lead to a safe state.
After allowing Req 1,
Allocated :

Max :

Requirement :

P0 0 0 3

8 43

8 4 0

P1 3 2 0

6 20

3 0 0

P2 2 1 1

3 3 3

1 2 2

Available : X=3 Y=2 Z=0

Now we can satisfy P1's requirement completely. So Availabe becomes : X=6,Y=4,Z=0.


Since Z is not available now, neither P0 nor P2's requirement can be satisfied. So its an unsafe state.
-- Poulami Das

GATE2014-1_32 top
Consider the following set of processes that need to be scheduled on a single CPU. All the times are given in milliseconds.

Process Name

Arrival Time

Execution Time

10

Using the shortest remaining time first scheduling algorithm, the average process turnaround time (in msec) is ____________________.

So, answer is 7.2 msec..


-- Jayesh Malaviya

GATE2014-1_33 top
Assume that there are 3 page frames which are initially empty. If the page reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, the number of page
faults using the optimal replacement policy is__________.

Ans : initially all empty frames fill by 1,2,3 so all time page fault which is 3 .
then next 4 was not available in frame set sowe look at ahead of request which was coming lastwe replace 4 with that so 3 will be
replace by 4 and like wise next 2 and 1 is present already so no page fault and then next 5 is not present so replace with 1 and then 3 was not
present and replace with 5 and then 2 and 4 are present already so no page fault and then last 6th was not already there so page fault.
So total page fault at : 1 , 2 , 3 , 4 , 5 , 3 , 6 . so, total 7 page fault occur ...
-- Jayesh Malaviya

GATE2014-2_55 top
Consider a main memory system that consists of 8 memory modules attached to the system bus, which is one word wide. When a write request
is made, the bus is occupied for 100 nanoseconds (ns) by the data, address, and control signals. During the same 100 ns, and for 500 ns
thereafter, the addressed memory module executes one cycle accepting and storing the data. The (internal) operation of different memory
modules may overlap in time, but only one request can be on the bus at any time. The maximum number of stores (of one word each) that can
be initiated in 1 millisecond is ________

When a write request is made, the bus is occupied for 100 ns. So, between 2 writes at least 100 ns interval must be there.
Now, after a write request, for 100 + 500 = 600 ns, the corresponding memory module is busy storing the data. But, assuming the next stores
are to a different memory module (we have totally 8 modules in question), we can have consecutive stores at intervals of 100 ns. So,
maximum number of stores in 1 ms
= 10-3 * 1/(100 * 10 -9) = 10,000
-- Arjun Suresh

GATE2014-3_31 top
A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that
deadlocks never arise is _________.

for this types of problems in which every process is making same number of request,use the formula

n.(m-1)+1<=r

where n=no. of processes


m=resource request made by processes
r=no. of resources
so above problem can be solved as 3.(3-1)+1<=r i.e. 7<=r
min number of resource required are 7
-- neha pawar

GATE2014-3_33 top
Consider a paging hardware with a TLB. Assume that the entire page table and all the pages are in the physical memory. It takes 10
milliseconds to search the TLB and 80 milliseconds to access the physical memory. If the TLB hit ratio is 0.6, the effective memory access time
(in milliseconds) is _________.

EMAT=TLB hit*(TLB access time+memory access time)+TLB miss(TLB access time+page table access time+memory access time)
=0.6(10+80)+0.4(10+80+80)
= 54+68
=122msec
-- neha pawar

GATE2011_44 top
An application loads 100 libraries at startup. Loading each library requires exactly one disk access. The seek time of the disk to a random location is given as 10
ms. Rotational speed of disk is 6000 rpm. If all 100 libraries are loaded from random locations on the disk, how long does it take to load all libraries? (The time to
transfer data from the disk block once the head has been positioned at the start of the block may be neglected.)

(A) 0.50 s
(B) 1.50 s
(C) 1.25 s
(D) 1.00 s

disk access time =seek time +rotational latency+transfer time (given that transfer time is neglected)
here seek time=10msec
rotational speed=6000rpm
60sec ----- 6000 rotation
1 rotation------60/6000 sec
rotational latency---1/2 *60/6000 sec=5msec
total time to transfer one library=10+5=15 msec
total time to transfer 100 libraries=100*15msec=1.5 sec
-- neha pawar

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

Method used by P2

while (S1==S2);
Critical Section
S1=S2;

while (S1!=S2);
Critical Section
S2 = not(S1)

Which one of the following statements describes the properties achieved?


(A) Mutual excusion but not progress
(B) Progress but not mutual exclusion
(C) Neither mutual exclusion nor progress
(D) Both mutual exclusion and progress

ans is A ..in this mutual exclusion is satisfied,only one process can access the critical section at particular time but here progress will not
satisfied because suppose when s1=1 and s2=0 and process p1 is not interested to enter into critical section but p2 want to enter critical
section. P2 is not able to enter critical section in this as only when p1 finishes execution, then only p2 can enter (then only s1 = s2 condition
be satisfied). Progress will not be satisfied when any process which is not interested to enter into the critical section will not allow other
interested process to enter into the critical section.
-- neha pawar

GATE2010_24 top
A system uses FIFO policy for system replacement. It has 4 page frames with no pages loaded to begin with. The system first accesses 100
distinct pages in some order and then accesses the same 100 pages but now in the reverse order. How many page faults will occur?
(A) 196

(B) 192
(C) 197
(D) 195

ans is A
when we access the 100 distinct page in some order (suppose order is 1 2 3....100) then total page fault occurs are 100. and in last, frame
contain the pages 100 99 98 97 .when we reverse the string (100,99,98....1) then first four page will not cause the page fault bcz they already
present in frame but the remaining 96 page will cause 96 page fault,so total page fault are 100+96=196
-- neha pawar

GATE2010_25 top
Which of the following statements are true?
I. Shortest remaining time first scheduling may cause starvation
II. Preemptive scheduling may cause starvation
III. Round robin is better than FCFS in terms of response time
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III

ans is D
i)In SRTF ,job with the shorest CPU burst will be scheduled first bcz of this process with large CPU burst may suffer from starvation
ii)In preemptive scheduling , suppose process P1 is executing in CPU and after some time process P2 with high priority then P1 will arrive in
ready queue then p1 is prrempted and p2 will brought into CPU for execution.in this way if process which is arriving in ready queue is of
higher prioirity then p1 ,then p1 is always preempted and it may possible that it suffer from starvation.
iii)round robin will give better response time then FCFS ,in FCFS when process is executing ,it executed upto its complete burst time,but in
round robin it will execute upto time quantum.
-- neha pawar

GATE1997_3.9

top

Thrashing
A.
B.
C.
D.

reduces page I/O


decreases the degree of multiprogramming
implies excessive page I/O
improve the system performance

C. implies excessive page i/o


http://en.wikipedia.org/wiki/Thrashing_%28computer_science%29
-- Sankaranarayanan P.N

GATE1997_3.10 top

The dirty bit allows for a performance optimization. A page on disk that is paged in to physical memory, then read from, and subsequently
paged out again does not need to be written back to disk, since the page hasn't changed. However, if the page was written to after it's paged
in, its dirty bit will be set, indicating that the page must be written back to the backing store answer: a
-- Sankaranarayanan P.N

GATE1997_6.8

top

Each Process Pi , i = 1....9 is coded as follows


repeat
P(mutex)
{Critical section}
V(mutex)
forever

The code for P10 is identical except it uses V(mutex) in place of P(mutex). What is the largest number of processes that can be inside the
critical section at any moment?
A.
B.
C.
D.

1
2
3
None

Answer is D
If initial value is 1//execute P1 or P10 first
If initial value is 0, P_10 can execute and make the value 1.
since the both code (ie p1 to p9 and p10)can be executed any number of times and code for p10 is

repeat
{
v(mutex)
C.S.
V(mutex)
}
forever

now let me say P1 is in c.s


then p10 comes executes the CS(up on mutex)
now P2 comes (down on mutex)
now P10 moves out of CS (again binary semaphore will be 1 )
now P3 comes (down on mutex)
now P10 come (up on mutex)
now P4 comes (down on mutex)
so if we take p10 in out of CS recursively all 10 process can be in CS
using Binary semaphore only

-- Kalpish Singhal

GATE1993_7.8

top

The root directory of a disk should be placed


(A) at a fixed address in main memory
(B) at a fixed location on the disk
(C) anywhere on the disk
(D) at a fixed location on the system disk
(E) anywhere on the system disk

file system uses directories which are the files containing the name and location of other file in the file system. unlike other file,directory does
not store the user data.Directories are the file that can point to other directories. Root directory point to various user directory.so they will be

stored in such a way that user cannot easily modify them .they were placed at fixed location in system disk.
-- neha pawar

GATE1993_7.9

top

Consider a system having m resources of the same type. These resources are shared by 3 processes A, B and C, which have peak demands
of 3, 4 and 6 respectively. For what value of m deadlock will not occur?
a.
b.
c.
d.
e.

7
9
10
13
15

13 and 15.
Consider the worst scenario: all processes require one more instance of the resource. So, P1 would have got 2, P2 - 3 and P3 - 5. Now, if one
more resource is available at least one of the processes could be finished and all resources allotted to it will be free which will lead to other
processes also getting freed. So, 2 + 3 + 5 = 10 would be the maximum value of m so that a deadlock can occur.
-- Arjun Suresh

GATE2010_46 top
A system has n resources R0 , , Rn1 , and k processes

P 0 , , P k1 . The implementation of the resource request logic of each process P i is as follows:

if (i%2==0) {
if (i<n) request Ri;
if (i+2 < n) request Ri+2
}
else {
if (i<n) request Rn-i ;
if (i+2 <n) request Rn-i-2;
}
In which of the following situations is a deadlock possible?
(A)

n = 40, k = 26

(B)

n = 21, k = 12

(C) n

= 20, k = 10

(D) n

= 41, k = 19

From the resource allocation logic, it's clear that even numbered processes are taking even numbered resources and all even numbered
processes share no more than 1 resource. Now, if we make sure that all odd numbered processes take odd numbered resources without a
cycle, then deadlock cannot occur. The "else" case of the resource allocation logic, is trying to do that. But, if n is odd, Rni and Rni2 will
be even and there is possibility of deadlock, when two processes requests the same Ri and Rj . So, only B and D are the possible answers.
Now, in D , we can see that P0 requests R0 and R2 , P2 requests R2 and R4 , so on until, P18 requests R18 and R20 . At the same time P1
requests R40 and R38 , P3 requests R38 and R36 , so on until, P17 requests R24 and R22 . i.e.; there are no two processes requesting the same
two resources and hence there can't be a cycle of dependencies which means, no deadlock is possible.
But for B, P8 requests R8 and R10 and P11 also requests R10 and R8 . Hence, a deadlock is possible. (Suppose P8 comes first and occupies
R8 . Then P11 comes and occupies R10 . Now, if P8 requests R10 and P11 requests R8 , there will be deadlock)
-- Arjun Suresh

GATE1994_1.13 top

FIFO replaces a page which was brought into memory first will be removed first so since variable was initialized very early. it is in the set of
first in pages. so it will be removed answer: b if you use LRU - since it is used constantly it is a recently used item always. so cannot be
removed. If you use LFU - the frequency of the page is more since it is in constant use. So cannot be replaced
-- Sankaranarayanan P.N

GATE1995_1.15 top
Which scheduling policy is most suitable for a time shared operating system?
A.
B.
C.
D.

Shortest Job First


Round Robin
First Come First Serve
Elevator

B. Round Robin.
-- Sankaranarayanan P.N

GATE1995_19 top
Consider the following program segment for concurrent processing using semaphore operatorsP and V for synchronization. Draw the
precedence graph for the statements S1 to S9.
var
a,b,c,d,e,f,g,h,i,j,k : semaphore;
begin
cobegin
begin S1; V(a); V(b) end;
begin P(a); S2; V(c); V(d) end;
begin P(c); S4; V(e) end;
begin P(d); S5; V(f) end;
begin P(e); P(f); S7; V(k) end
begin P(b); S3; V(g); V(h) end;
begin P(g); S6; V(i) end;
begin P(h); P(i); S8; V(j) end;
begin P(j); P(k); S9 end;
coend
end;

Precedence graph will be formed as

-- neha pawar

GATE1995_20 top
The head of a moving head disk with 100 tracks numbered 0 to 99 is currently serving a request at track 55. If the queue of requests kept in
FIFO order is
10, 70, 75, 23, 65
which of the two disk scheduling algorithms FCFS (First Come First Served) and SSTF (Shortest Seek Time First) will require less head
movement? Find the head movement for each of the algorithms.

FCS:55->10->70->75->23->65 => 45+60+5+52+42=204.


SSTF:55->65->70->75->23->10 => 10+5+5+52+13=85
Hence SSTF.
-- kireeti

GATE1996_1.18 top

Answer is B. The transition from running to ready indicates that the process in the running state can be preempted and bought back to ready
state.
-- kireeti

GATE1996_1.19 top
A critical section is a program segment
A.
B.
C.
D.

which should run in a certain amount of time


which avoids deadlocks
where shared resources are accessed
which must be enclosed by a pair of semaphore operations, P and V

C. is the answer
http://en.wikipedia.org/wiki/Critical_section
A - there is no time guarantee for critical section
B - critical section by default doesn't avoid deadlock. While using critical section, programmer must ensure deadlock is avoided.
D - This is not a requirement of critical section. Only when semaphore is used for critical section management, this becomes a necessity. But,
semaphore is just ONE of the ways for managing critical section.
-- Gate Keeda

GATE1996_1.20 top

ans is A
spooling(simultaneous peripheral operations online) is a technique in which an intermediate device such as disk is interposed between
process and low speed i/o device.for ex. in printer if a process attempt to print a document but printer is busy printing another document ,the
process,instead of waiting for printer to become available,write its output to disk.when the printer become available the data on disk is
printed.spooling allows process to request operation from peripheral device without requiring that the device be ready to service the request.
-- neha pawar

GATE1996_2.18 top
A 1000 Kbyte memory is managed using variable partitions but no compaction. It currently has two partitions of sizes 200 Kbytes and 260
Kbytes respectively. The smallest allocation request in Kbytes that could be denied is for
(a) 151
(b) 181
(c) 231
(d) 541

Answer is B. Since the total size of the memory is 1000KB, lets assume that the partitioning for the current allocation is done in such a way
that it will leave minimum free space.
Partitioning the 1000kB as below will allow gaps of 180KB each and hence a request of 181kB will not be met.
[180Kb-200kb-180kb-260kb-180kb]. The reasoning is more of an intution rather than any formula.
-- kireeti

GATE1996_2.19 top

acc. to me it should be c) because.. according to condition.. out of all , one philosopher will get both the forks.. so deadlock should not be
there.
-- Sneha Goel

GATE1996_2.20 top

here all process arrive at time 0.so there order of execution will be A B C D, in this manner completion time for A is 9
-- neha pawar

GATE2008-IT_16 top
A paging scheme uses a Translation Look-aside Buffer (TLB). A TLB-access takes 10 ns and a main memory access takes 50 ns. What is the
effective access time(in ns) if the TLB hit ratio is 90% and there is no page-fault?

A)

54

B)

60

C)

65

D)

75

Effective access time = hit ratio * time during hit + miss ratio * time during miss
In both cases TLB is accessed and assuming page table is accessed from memory only when TLB misses.
= 0.9 * (10+50) + 0.1 *(60 + 50)
= 54 + 11
= 65
-- Arjun Suresh

GATE2008-IT_41 top
Assume that a main memory with only 4 pages, each of 16 bytes, is initially empty. The CPU generates the following sequence of virtual
addresses and uses the Least Recently Used (LRU) page replacement policy.
0, 4, 8, 20, 24, 36, 44, 12, 68, 72, 80, 84, 28, 32, 88, 92
How many page faults does this sequence cause? What are the page numbers of the pages present in the main memory at the end of the
sequence?

A)

6 and 1, 2, 3, 4

B)

7 and 1, 2, 4, 5

C)

8 and 1, 2, 4, 5

D)

9 and 1, 2, 3, 5

The question says LRU policy, so the cache must be associative as there is no need of a replacement policy in direct-mapped cache. We can
assume fully associative cache as no other information is given. So, we have 4 spaces for a page and there will be a replacement only when a
5th distinct page comes.
0: Page fault - 1, Pages in memory - 0
4: Page faults - 1, Pages in memory - 0
8: Page faults - 1, Pages in memory - 0
20: Page faults - 2, Pages in memory - 0, 1
24: Page faults - 2, Pages in memory - 0, 1
36: Page faults - 3, Pages in memory - 0, 1, 2
44: Page faults - 3, Pages in memory - 0, 1, 2
12: Page faults - 3, Pages in memory - 1, 2, 0
68: Page faults - 4, Pages in memory - 1, 2, 0, 4
72: Page faults - 4, Pages in memory - 1, 2, 0, 4
80: Page faults - 5, Pages in memory - 2, 0, 4, 5
84: Page faults - 5, Pages in memory - 2, 0, 4, 5

28: Page faults - 6, Pages in memory - 0, 4, 5, 1


32: Page faults - 7, Pages in memory - 4, 5, 1, 2
88: Page faults - 7, Pages in memory - 4, 1, 2, 5
92: Page faults - 7, Pages in memory - 4, 1, 2, 5
So, (B) choice.
-- Arjun Suresh

GATE2008-IT_53 top
The following is a code with two threads, producer and consumer, that can run in parallel. Further, S and Q are binary semaphores equipped
with the standard P and V operations.
semaphore S = 1, Q = 0;
integer x;
producer:
while (true) do
P(S);
x = produce ();
V(Q);
done

consumer:
while (true) do
P(Q);
consume (x);
V(S);
done

Which of the following is TRUE about the program above?

A) The process can deadlock


B) One of the threads can starve
C) Some of the items produced by the producer may be lost
D) Values generated and stored in 'x' by the producer will always be consumed before the producer can generate a new value

D Consumer can consume only once the producer has produced the item, and producer can produce(except the first time) only once the
consumer has consumed the item.
-- Shaun Patel

GATE2008-IT_55 top
If the time-slice used in the round-robin scheduling policy is more than the maximum time required to execute any process, then the policy will

A)

degenerate to shortest job first

B)

degenerate to priority scheduling

C)

degenerate to first come first serve

D)

none of the above

ans is c
-- Sanjay Sharma

GATE2007-IT_12 top
The address sequence generated by tracing a particular program executing in a pure demand paging system with 100 bytes per page is
0100, 0200, 0430, 0499, 0510, 0530, 0560, 0120, 0220, 0240, 0260, 0320, 0410.
Suppose that the memory can store only one page and if x is the address which causes a page fault then the bytes from addresses x to x + 99
are loaded on to the memory.
How many page faults will occur ?

A)

B)

C)

D)

0100 - page fault, addresses till 199 in memory


0200 - page fault, addresses till 299 in memory
0430 - page fault, addresses till 529 in memory
0499 - no page fault
0510 - no page fault
0530 - page fault, addresses till 629 in memory
0560 - no page fault
0120 - page fault, addresses till 219 in memory
0220 - page fault, addresses till 319 in memory
0240 - no page fault
0260 - no page fault
0320 - page fault, addresses till 419 in memory
0410 - no page fault
So, 7 is the answer- (C)
-- Arjun Suresh

GATE2007-IT_44 top
A hard disk system has the following parameters :
Number of tracks = 500
Number of sectors/track = 100
Number of bytes /sector = 500
Time taken by the head to move from one track to adjacent track = 1 ms
Rotation speed = 600 rpm.
What is the average time taken for transferring 250 bytes from the disk ?

A)

300.5 ms

B)

255.5 ms

C)

255 ms

D)

300 ms

Avg. time to transfer = Avg. seek time + Avg. rotational delay + Data transfer time
RPM = 600
So, rotational delay = 60 / 600 = 0.1 s
In 1 rotations we can transfer the whole data in a track which is equal to number of sectors in a track * bytes per track
= 100 * 500 = 50,000
i.e., in 0.1 s, we can transfer 50,000 bytes.
Hence time to transfer 250 bytes = 0.1 * 250 / 50,000 = 0.5 ms
Avg. rotational delay = 0.5 * rotational delay = 0.5 * 0.1s = 50 ms
Avg. seek time = (0 + 1 + 2 + .... + 499)/500 (as time to move between successive tracks is 1 ms and we have 500 such tracks) = 499 * 250
/500 = 249.5

So, average time for transferring 250 bytes = 249.5 + 50 + 0.5 = 300 ms
-- Arjun Suresh

how many process created?

top

At the call of fork, a child process is created which executes the same code of the parent from that point. the return value or fork is 0 for the
child and is child pid (not 0) for the parent and this value is used to distinguish between child-parent while writing code using fork.

Thus 5 child processes are created. Since the question asks for "total number of processes created" we must include parent also making this
6 processes in total,
-- Arjun Suresh

GATE2004-IT_14 top
Which one of the following is NOT shared by the threads of the same process ?

A)

Stack

B)

Address Space

C)

File Descriptor Table

D)

Message Queue

Stack is not shared

-- Sankaranarayanan P.N

GATE2004-IT_62 top
A disk has 200 tracks (numbered 0 through 199). At a given time, it was servicing the request of reading data from track 120, and at the
previous request, service was for track 90. The pending requests (in order of their arrival) are for track numbers.
30 70 115 130 110 80 20 25.
How many times will the head change its direction for the disk scheduling policies SSTF(Shortest Seek Time First) and FCFS (First Come Fist
Serve)?

A.
B.
C.
D.

2 and 3
3 and 3
3 and 4
4 and 4

Answer is (C)
SSTF: (90) 120 115 110 130 80 70 30 25 20
Direction changes at 120,110,130
FCFS: (90) 120 30 70 115 130 110 80 20 25
direction changes at 120,30,130,20
-- Sandeep_Uniyal

GATE2004-IT_63 top
In a certain operating system, deadlock prevention is attemped using the following scheme. Each process is assigned a unique timestamp, and
is restarted with the same timestamp if killed. Let Ph be the process holding a resource R, Pr be a process requesting for the same resource R,
and T(Ph) and T(Pr) be their timestamps respectively. The decision to wait or preempt one of the processes is based on the following algorithm.
if T(Pr) < T(Ph) then
kill Pr
else wait

Which one of the following is TRUE?

A.
B.
C.
D.

The scheme is deadlock-free, but not starvation-free


The scheme is not deadlock-free, but starvation-free
The scheme is neither deadlock-free nor starvation-free
The scheme is both deadlock-free and starvation-free

Answer is (A)
When the process wakes up again after it has been killed once or twice IT WILL HAVE SAME TIME-STAMP as it had WHEN IT WAS KILLED
FIRST TIME. And that time stamp can never be greater than a process that was killed after that or a NEW process that may have arrived.
So every time when the killed process wakes up it MIGHT ALWAYS find a new process that will say "your time stamp is less than me and I
take this resource", which of course is as we know, and that process will again be killed.
This may happen indefinitely if processes keep coming and killing that "INNOCENT" process every time it try to access.
So STARVATION is possible. Deadlock is not possible.
-- Sandeep_Uniyal

GATE2004-IT_64 top
A process executes the following segment of code :
for(i = 1; i < = n; i++)
fork ();

The number of new processes created is

A)

B)

((n(n + 1))/2)

C)

2n - 1

D)

3n - 1

option C
-- prakash

GATE2004-IT_66 top
In a virtual memory system, size of virtual address is 32-bit, size of physical address is 30-bit, page size is 4 Kbyte and size of each page table
entry is 32-bit. The main memory is byte addressable. Which one of the following is the maximum number of bits that can be used for storing
protection and other information in each page table entry?

A)

B)

10

C)

12

D)

14

ans is D
page table entry must contain bits for representing frames and other bits for storing information like dirty bit,reference bit etc
no. of frames (no. of possible pages) = Physical memory size/ Page size = 230/212 = 218
18+x=32

(PT entry size=32 bit)

x =14 bits
-- neha pawar

GATE2005-IT_17 top
A student wishes to create symbolic links in a computer system running Unix. Three text files named "file 1", "file 2" and "file 3" exist in her
current working directory, and the student has read and write permissions for all three files. Assume that file 1 contains information about her
hobbies, file 2 contains information about her friends and file 3 contains information about her courses. The student executes the following
sequence of commands from her current working directory
ln -s file 1 file 2
ln -s file 2 file 3

Which of the following types of information would be lost from her file system?
(I) Hobbies (II) Friends (III) Courses
A)

(I) and (II) only

B)

(II) and (III) only

C)

(II) only

D)

(I) and (III) only

option B
As ln -s is symbolic link. In this case

File3 File2 File1 Hobbies(actual data).


So File2 and File3 content are lost.
-- Laxmi

GATE2005-IT_62 top
Two shared resources R1 and R2 are used by processes P1 and P2. Each process has a certain priority for accessing each resource. Let Tij
denote the priority of Pi for accessing Rj. A process Pi can snatch a resource Rh from process Pj if Tik is greater than Tjk.
Given the following :
I. T11 > T21
II. T12 > T22
III. T11 < T21
IV. T12 < T22
Which of the following conditions ensures that P1 and P2 can never deadlock?

A)

(I) and (IV)

B)

(II) and (III)

C)

(I) and (II)

D)

None of the above

The answer is (c)


If R1 and R2 are allocated to the Process P1 , then it will complete it's job and release it . After that process P
2 will get both the resources and
complete it's Job .
-- zabiullah shiekh

GATE2005-IT_63 top
In a computer system, four files of size 11050 bytes, 4990 bytes, 5170 bytes and 12640 bytes need to be stored. For storing these files on disk,
we can use either 100 byte disk blocks or 200 byte disk blocks (but can't mix block sizes). For each block used to store a file, 4 bytes of
bookkeeping information also needs to be stored on the disk. Thus, the total space used to store a file is the sum of the space taken to store
the file and the space taken to store the book keeping information for the blocks allocated for storing the file. A disk block can store either
bookkeeping information for a file or data from a file, but not both.
What is the total space required for storing the files using 100 byte disk blocks and 200 byte disk blocks respectively?

A)

35400 and 35800 bytes

B)

35800 and 35400 bytes

C)

35600 and 35400 bytes

D)

35400 and 35600 bytes

for 100 bytes block:


11050 = 111 blocks requiring 111 * 4 = 444 bytes of bookkeeping info which requires another 5 disk blocks. So, totally 111 + 5 = 116 disk
blocks. Similarly,
4990 = 50 + (50*4)/100 = 52
5170 = 52 + (52*4)/100 = 55
12640 = 127 + (127*4/100) = 133
----356 x 100 = 35600 bytes
For 200 bytes block:
56 + (56*4/200) = 58
25 + (25 * 4 / 200) = 26
26 + (26 * 4 / 200) = 27
64 + (64 * 4 / 200) = 66
-----

177 x 200 = 35400


So, C option.
-- Viral Kapoor

GATE2005-IT_81a

top

A disk has 8 equidistant tracks. The diameters of the innermost and outermost tracks are 1 cm and 8 cm respectively. The innermost track has
a storage capacity of 10 MB.
What is the total amount of data that can be stored on the disk if it is used with a drive that rotates it with (i) Constant Linear Velocity (ii)
Constant Angular Velocity?

A)

(i) 80 MB (ii) 2040 MB

B)

(i) 2040 MB (ii) 80 MB

C)

(i) 80 MB (ii) 360 MB

D)

(i) 360 MB (ii) 80 MB

With Constant Linear Velocity, CLV, the density of bits is uniform from cylinder to cylinder. Because there are more sectors in outer
cylinders, the disk spins slower when reading those cylinders, causing the rate of bits passing under the read-write head to remain
constant. This is the approach used by modern CDs and DVDs.
With Constant Angular Velocity, CAV, the disk rotates at a constant angular speed, with the bit density decreasing on outer cylinders.
( These disks would have a constant number of sectors per track on all cylinders. )
CLV=10+20+30+40+..80=360
CAV=10*8 = 80 so answer should be d
-- spriti1991

Address Translation top


A cpu generates 32- bit virtual address .The page size is 4kb .The processor has a tlb which can hold 128 entries and is 4-way set associative
.The minimum size of tlb tag is ???

Answer is 11- where is that found?


Your approach is correct.
128 entries and each set has 4 entries => 32 sets
5 set bits are required. 12 offset bits for indexing a page
Now, 32-5-12 = 15 bits are there and we need all of them to be used as tag bits as otherwise we cannot identify a page from the tag.
(215 possible page can come to a set and minimum 15 bits are needed to identify the page).

-- Arjun Suresh

Deadlock

top

Consider a system consisting of n resources of same type being shared by 4 processes, 2 of which need at most 2 resources each and other
need at most 3 resources each.The min value of n so that the system is deadlock free is ___________?

Total resources required = 2 * 2 + 2 * 3 = 10.


Now, with n = 10, there won't be a deadlock.
Now, assume the worst case. All processes are allotted all resources except 1. So, 2*1 + 2 * 2 = 6. Here, deadlock is possible with n = 6.
When n = 7, at least one process must finish and we get 7 resources for 3 processes which require maximum 8 resources between them. So,
again at least one of them will finish and there won't be a deadlock.
So, n = 6 + 1 = 7 is the answer.
-- Arjun Suresh

GATE2015-2_23 top
A system has 6 identical resources and N processes competing for them. Each process can request atmost 2 requests. Which one of the
following values of N could lead to a deadlock?

A.
B.
C.
D.

1
2
3
4

3*2=6
4 * 2 = 8.
I guess a question can't get easier than this- D choice. (Also, we can simply take the greatest value among choice for this question)
[There are 6 resources and all of them must be in use for deadlock. If the system has no other resource dependence, N=4 cannot lead to a
deadlock. But if N=4, the system can be in deadlock in presence of other dependencies.
Why N=3 cannot cause deadlock? It can cause deadlock, only if the system is already in deadlock and so the deadlock is independent of the
considered resource. Till N=3, all requests for considered resource will always be satisfied and hence there won't be a waiting and hence no
deadlock with respect to the considered resource. ]
-- Arjun Suresh

GATE2015-2_25 top
A computer system implements a 40-bit virtual address, page size of 8 kilobytes, and a 128-entry translation look-aside buffer (TLB) organized
into 32 sets each having 4 ways. Assume that the TLB tag does not store any process id. The minimum length of the TLB tag in bits is ____.

Ans 40 - (5+13) = 22 bits


TLB maps a virtual address to the physical address of the page. (The lower bits of page address - offset bits- are not used in TLB as they are
the same for virtual as well as physical addresses). Here, for 8 kB page size we require 13 offset bits.
In TLB we have 32 sets and so virtual address space is divided into 32 using 5 set bits. (Associativity doesn't affect the set bits as they just
adds extra slots in each set).
So, number of tag bits = 40 - 5 - 13 = 22
-- Vikrant Singh

GATE2015-2_30 top
Consider 6 memory partitions of sizes 200 KB, 400 KB, 600 KB, 500 KB, 300 KB and 250 KB, where KB refers to kilobyte. These partitions
need to be allotted to four processes of sizes 357 KB, 210 KB, 468 KB, 491 KB in that order. If the best fit algorithm is used, which partitions
are NOT allotted to any process?

A.
B.
C.
D.

200 KB and 300 KB


200 KB and 250 KB
250 KB and 300 KB
300 KB and 400 KB

option A is correct because we have 6 memory partitions of sizes 200 KB, 400 KB, 600 KB, 500 KB, 300 KB and 250 KB and the partition
allotted to the process using best fit is given below357 KB process allotted at partition 400 KB.
210 KB process allotted at partition 250 KB
468 KB process allotted at partition 500 KB
491 KB process allotted at partition 600 KB
so we have left only two partitions 200 KB and 300 KB

-- Anoop Sonkar

GATE2015-1_12 top
Consider a system with byte-addressable memory, 32-bit logical addresses, 4 kilobyte page size and page table entries of 4 bytes each. The
size of the page table in the system in megabytes is_________________.

total no of pages = 2^32 / 2^12 = 2^20


We need a PTE for each page and an entry is 4 bytes. So,
page table size = 4 * 2^20 = 2^22 = 4MB
-- Anoop Sonkar

GATE2015-2_47 top
A computer system implements 8 kilobyte pages and a 32-bit physical address space. Each page table entry contains a valid bit, a dirty bit,
three permission bits, and the translation. If the maximum size of the page table of a process is 24 megabytes, the length of the virtual address
supported by the system is _______ bits.

8 KB pages means 13 offset bits.


For 32, bit physical address, 32 - 13 = 19 page frame bits must be there in each PTE (Page Table Entry).
We also have 1 valid bit, 1 dirty bit and 3 permission bits.
So, total size of a PTE = 19 + 5 = 24 bits = 3 bytes.
Given in question, maximum page table size = 24 MB
Page table size = No. of PTEs * size of an entry
So, no. of PTE = 24 MB / 3 B = 8 M
Virtual address supported = No. of PTEs * Page size (As we need a PTE for each page)
= 8 M * 8 KB
= 64 GB = 236 Bytes
So, length of virtual address supported = 36 bits (assuming byte addressing)

-- Arjun Suresh

GATE2015-2_49 top
Consider a typical disk that rotates at 15000 rotations per minute (RPM) and has a transfer rate of 50 106 bytes/sec. If the average seek time
of the disk is twice the average rotational delay and the controller's transfer time is 10 times the disk transfer time, the average time (in
milliseconds) to read or write a 512-byte sector of the disk is _____.

Average time to read/write = Avg. seek time + Avg. rotational delay + Effective transfer time
Rotational delay = 60/15 = 4 ms
Avg. rotational delay = 1/2 * 4 = 2 ms
Avg. seek time = 2 * 2 = 4 ms
Disk transfer time = 512/(50 * 103) = 0.0102 ms
Effective transfer time = 10 * disk transfer time = 0.102 ms
So, avg. time to read/write = 4 + 2 + 0.1 = 6.1 ms
Ref: http://www.csc.villanova.edu/~japaridz/8400/sld012.htm

-- Arjun Suresh

GATE2015-1_48 top
Consider a disk pack with a seek time of 4 milliseconds and rotational speed of 10000 rotations per minute (RPM). It has 600 sectors per track
and each sector can store 512 bytes of data. Consider a file stored in the disk. The file contains 2000 sectors. Assume that every sector access
necessitates a seek, and the average rotational latency for accessing each sector is half of the time for one complete rotation. The total time (in
milliseconds) needed to read the entire file is__________________.

Since each sector requires a seek,


Total time = 2000 * (seek time + avg. rotational latency + data transfer time)
Since data transfer rate is not given, we can take that in 1 rotation, all data in a track is read. i.e., in 60/10000 = 6ms, 600 * 512 bytes are
read. So, time to read 512 bytes = 6/600 ms = 0.01 ms
= 2000 * (4 ms + 60 * 1000 /2* 10000 + 0.01)
= 2000 * (7.01 ms)
= 14020 ms.
http://www.csee.umbc.edu/~olano/611s06/storage-io.pdf
-- Arjun Suresh

GATE2015-3_1 top
The maximum number of processes that can be in readyReady state for a computer system with n CPUs is

A.
B.
C.
D.

n
n2
2n

Independent of n

D. independent of n.
The number of processes that can be in READY state depends on the Ready Queue size and is independent of the number of CPU's.
-- Arjun Suresh

GATE2015-3_10 top
Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes
Process X

Process Y

/* other code for process x*/


while (true)
{
varP = true;
while (varQ == true)
{
/* Critical Section */
varP = false;
}
}
/* other code for process X */

/* other code for process Y */


while (true)
{
varQ=true;
while (varP == true)
{
/* Critical Section */
varQ = false;
}
}
/* other code for process Y */

Here varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?

A.
B.
C.
D.

The proposed solution prevents deadlock but fails to guarantee mutual exclusion
The proposed solution guarantees mutual exclusion but fails to prevent deadlock
The proposed solution guarantees mutual exclusion and prevents deadlock
The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion

When both processes try to enter critical section simultaneously,both are allowed to do so since both shared variables varP and varQ are
true. So, clearly there is NO mutual exclusion. Also, deadlock is prevented because mutual exclusion is one of the conditions for deadlock
to happen.Hence, answer is A.
-- tanaya

GATE2015-3_52 top
Consider the following policies for preventing deadlock in a system with mutually exclusive resources.
I. Process should acquire all their resources at the beginning of execution. If any resource is not available, all resources acquired so far are
released.
II. The resources are numbered uniquely, and processes are allowed to request for resources only in increasing resource numbers
III. The resources are numbered uniquely, and processes are allowed to request for resources only in deccreasing resource numbers
IV. The resources are numbered uniquely. A processes is allowed to request for resources only for a resource with resource number larger
than its currently held resources
Which of the above policies can be used for preventing deadlock?

A.
B.
C.
D.

Any one of I and III but not II or IV


Any one of I, III and IV but not II
Any one of II and III but not I or IV
Any one of I, II, III and IV

a deadlock will not occur if any one of the below four conditions are prevented :
1> hold and wait
2> mutual exclusion
3> circular weight
4> no-premption
now
option-1 if implemented violates 1 so deadlock cannot occur.
option-2 if implemented violates circular wait(making the dependency graph acyclic)
option-3 if implemented violates circular wait(making the dependency graph acyclic)
option-4 it is equivalent to the other options 2 and 3
so the correct option is 4 as all of them are methods to avoid deadlock.
http://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/7_Deadlocks.html
-- Tamojit Chatterjee

Databases top
GATE2012_2

top

Which of the following is TRUE?


(A) Every relation in 3NF is also in BCNF
(B) A relation R is in 3NF if every non-prime attribute of R is fully functionally dependent on every key of R
(C) Every relation in BCNF is also in 3NF
(D) No relation can be in both BCNF and 3NF

(C) Every relation in BCNF is also in 3NF. Striaght from definition of BCNF.
-- Arjun Suresh

GATE2012_14 top
Given the basic ER and relational models, which of the following isINCORRECT?
(A) An attribute of an entity can have more than one value
(B) An attribute of an entity can be composite
(C) In a row of a relational table, an attribute can have more than one value
(D) In a row of a relational table, an attribute can have exactly one value or a NULL value

(C) is incorrect as a relational table requires that, in a row, an attribute can have exactly one value or NULL value.
-- Arjun Suresh

GATE2012_15 top
Which of the following statements areTRUE about an SQL query?
P : An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause
Q : An SQL query can contain a HAVING clause only if it has a GROUP BY clause
R : All attributes used in the GROUP BY clause must appear in the SELECT clause
S : Not all attributes used in the GROUP BY clause need to appear in the SELECT clause
(A) P and R
(B) P and S
(C) Q and R
(D) Q and S

(C) Q and R are true.


HAVING clause is meant for groups and hence a GROUP BY clause is necessary and GROUP BY is working on the selected attributes and
hence all attributes in the GROUP BY clause must appear in the SELECT clause.
-- Arjun Suresh

GATE2008_70 top
Consider a file of 16384 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 firstlevel 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

Content of an index will be <key, block pointer> and so will have size 6 + 10 = 16.

In the first level, there will be an entry for each record of the file. So,total size of first-level index
= 16384 * 16
No. of blocks in the first-level =Size of first-level index / block size
= 16384 * 16 / 1024
= 16 * 16 = 256
In the second-level there will be an entry for each block in the first level. So, total number of entries = 256 and total size of second-level index
= No. of entries * size of an entry
= 256 * 16
No. of blocks in second-level index = Size of second-level index / block size
= 256 * 16 / 1024
=4
-- gatecse

GATE2008_82,83 top
82. Consider the following ER diagram

The minimum number of tables needed to represent M, N, P, R1, R2 is


A.
B.
C.
D.

2
3
4
5

83. Which of the following is a correct attribute set for one of the tables for the correct answer to the above question?

A.
B.
C.
D.

{M1, M2, M3, P1}


{M1, P1, N1, N2}
{M1, P1, N1}
{M1, P1}

First strong entity types are made to tables. So, we get two tables M and P.
I assume R1 is 1:1 or 1:n as that would minimize the number of tables as asked in question.
Now participation of M in R1 is total (indicated by double arrow) meaning every entity of M participate in R1. Since R1 is not having an
attribute, we can simple add the primary key of P to the table M and add a foreign key reference to M. This handles R1 and we don't need an
extra table. So, M becomes {M1, M2, M3, P1}.
N here is a weak entity weakly related to P. So, we form a new table N, and includes the primary key of P (P1) as foreign key reference. Now
(P1, N1) becomes the primary key of N.
Thus we get 3 tables.
M: {M1, M2, M3, P1} - M1 primary key, P1 references P
P: {P1, P2} - P1 primary key
N: {P1, N1, N2} - (P1, N1) primary key, P1 references P.
So, answers are 82: B and 83: A.

Ref: http://web.cse.ohio-state.edu/~gurari/course/cse670/cse670Ch9.xht
-- Arjun Suresh

GATE2008_15 top
Which of the following tuple relational calculus expression(s) is/are equivalent tot r(P (t))?
1.
2.
3.
4.

t r(P (t))
t r(P (t))
t r(P (t))
t r(P (t))

(A) I only
(B) II only
(C) III only
(D) III and IV only

Only III is correct.


The given statement means for all tuples from r, P is true. III means there does not exist a tuple in r where P is not true. Both are equivalent.
IV is not correct as it as saying that there exist a tuple, not in r for which P is not true, which is not what the given expression means.
-- Arjun Suresh

GATE2008_68 top
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 schemas. Which of the following queries are equivalent?
I. P (R S)
II. P (R) P (S)
III. P (P,Q (R) P,Q (S))
IV. P (P,Q (R) (P,Q (R) P,Q (S)))

A.
B.
C.
D.

Only I and II
Only I and III
Only I, II and III
Only I, III and IV

(d) i, iii, iv
iv) is expansion for natural join represented with other operators.
Why ii is not equivalent? Consider the following instances of R and S

R : {" 1 ", " abc ", " p1 ", " p2 ", " p3 ",
" 2 ", " xyz ", " p1 ", " p2 ", " p3 "}
S : {" 1 ", " abc ", " q1 ", " q2 ", " q3 "
" 2 ", " def ", " q1 ", " q2 ", " q3 "}
Now, consider the given queries:
i. R S gives

{" 1 ", " abc ", " p1 ", " p2 ", " p3 ", " q1 ", " q2 ", " q3 "}
Projecting P gives {" 1 "}
ii. P (R) P (S) gives

{" 1 "" 2 "} {" 1 "" 2 "}


= {" 1 ", " 2 "}
iii. P (P,Q (R) P,Q (S)) gives

{" 1 ", " abc ", " 2 ", " xyz "} {" 1 ", " abc ", " 2 ", " def " }
= {" 1 ", " abc "}
Projecting P gives {" 1 "}
iv. P (P,Q (R) (P,Q (R) P,Q (S))) gives

{" 1 ", " abc ", " 2 ", " xyz "}
({" 1 ", " abc ", " 2 ", " xyz "} {" 1 ", " abc ", " 2 ", " def "})
= {" 1 ", " abc ", " 2 ", " xyz "}
{" 2 ", " xyz "}
= {" 1 ", " abc "}
Projecting P gives {" 1 "}
-- Aravind

GATE2008_69 top
Consider the following relational schemes for a library database:
Book (Title, Author, Catalog_no, Publisher, Year, Price)
Collection(Title, Author, Catalog_no)

with the following functional dependencies:


I. Title Author Catalog_no
II. Catalog_no Title Author Publisher Year
III. Publisher Title Year Price
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 in 3NF
D. Both Book and Collection are in 2NF only

Answer: C
It is given that {Author , Title} is the key for both schemas.
The given dependencies are :
{Title, Author} --> {Catalog_no}
Catalog_no --> {Title , Author , Publisher , Year }
{Publisher , Title , Year} --> {Price}
First , let's take schema Collection ( Title , Author , Catalog_no ) :
{Title , Author} --> Catalog_no
So , here no partial dependency exists . So , it is in 2NF , Now , let's check for Transitive dependency. We can not find any TD as well. So . it

is in 3NF. Now , let's check for BCNF. Catalog_no is also key attribute. So , Collection is in BCNF.
Now , let's see Book (Title , Author , Catalog_no , Publisher , Year , Price ) :
{Title , Author}+ --> {Title , Author , Catalog_no , Publisher , Year , Price}
{Catalog_no}+--> {Title , Author , Publisher , Year , Price , Catalog_no}
So candidate keys are : Catalog_no , {Title , Author}
But in the given dependencies , {Publisher , Title , Year} --> Price , which has Transitive Dependency.So , Book is in 2NF.

-- Shounak Kundu

GATE2000_1.23 top
Given the relations
employee (name, salary, dept-no), and
department (dept-no, dept-name,address),
which of the following queries cannot be expressed using the basic relational algebra operations(, , , , , , )?
A.
B.
C.
D.

Department address of every employee


Employees whose name is the same as their department name
The sum of all employees' salaries
All employees of a given department

possible solutions , relational algebra


(a) join relation using attribute dpart_no.
address (emp depart)
or
address ( emp.depart_no.=depart.depart_no. (emp X depat))

(b)

name ( emp.depart_no.=depart.depart_no. emp.name = depart.depart_name (emp X depat))

or
name (emp emp.name = depart.depart_name depart)
(d) Let given department number is = 'x'
name ( emp.depart_no.=depart.depart_no. depart_no. = 'x' (emp X depat))
or
name (emp depart_no.='x' depart)

(c) but we can't generate relational algebra of aggregate function using basic operation , so we need extended operation here , option (c) is
false .
correct me ...... ???
-- csegate2

GATE2000_2.25 top
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.
B.
C.
D.

r has no duplicates and s is non-empty


r and s have no duplicates
s has no duplicates and r is non-empty
r and s have the same number of tuples

(a)
if s is empty r x s will give empty set, so s cant be empty
-- Aravind

GATE2000_2.26 top
In SQL, relations can contain null values, and comparisons with null values are treated as unknown. Suppose all comparisons with a null value
are treated as false. Which of the following pairs is not equivalent?
A.
B.
C.
D.

x=5
not (not (x = 5))
x=5
x > 4 and x < 6, where x is an integer
x5
not (x = 5)
none of the above

Answer: C
As (null) != 5 gives false.
But, not((null) = 5) gives not(false) gives true.
-- Aravind

GATE2001_2.23 top
R(A,B,C,D) is a relation. Which of the following does not have a lossless join, dependency preserving BCNF decomposition?
A.
B.
C.
D.

A B, B CD
A B, B C, C D
AB C, C AD
A BCD

(C) is the answer. Because of AB -> C and C -> A, we cannot have A, B and C together in any BCNF relation- in relation ABC, C is not a
super key and C->A exists violating BCNF condition. So, we cannot preserve AB -> C dependency in any decomposition of ABCD.
For (A) we can have AB, BCD, A and B the respective keys
For (B) we can have AB, BC, CD, A, B and C the respective keys
For (D) we can have ABCD, A is key
-- Arjun Suresh

GATE2002_1.19 top
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. Indeterminate

Answer: A
If a relation schema is in BCNF then all redundancy based on functional dependency has been removed, although other types of redundancy
may still exist. A relational schema R is in BoyceCodd normal form if and onlyif for every one of its dependencies
X Y, at least one of
the following conditions hold:
X Y is a trivial functional dependency (Y X)
X is a super key for schema R
http://en.wikipedia.org/wiki/Boyce%E2%80%93Codd_normal_form
-- Priya_das

GATE2002_16 top
For relation R=(L, M, N, O, P), the following dependencies hold:

M O, NO P , P L and L MN
R is decomposed into R 1 = (L, M, N, P) and R 2 = (M, O).
a. Is the above decomposition a lossless-join decomposition? Explain.
b. Is the above decomposition dependency-preserving? If not, list all the dependencies that are not preserved.
c. What is the highest normal form satisfied by the above decomposition?

a) Yes as R1 R2 = M and M O
b) NO
From the Dependencies obtained from R1 and R2, we CANNOT infer NO P
Mistake That CAN be made: Here we CANNOT apply Pseudo Transitivity Rule using MO & MN P to obtain NO P because the
rule says :
if MO and NOP then NMP or MNP
But here we have MO and MNP ... SO we CANNOT apply the rule here to obtain NOP from it.
c) BCNF
R1 keys : P,L,MN hence BCNF
R2 key : M hence BCNF
-- Danish

GATE2003_30 top
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. a 1 ,a 2 ,a n p (r1 r2 rm )
B. a ,a ,a p (r1 r2 rm )
1
2
n
C. a 1 ,a 2 ,a n p (r1 r2 rm )
D. a 1 ,a 2 ,a n p (r1 r2 rm )

select distinct in SQL is equivalent to project and by default relation 1, relation 2 in SQL corresponds to cross-product. So, option A.
-- Arjun Suresh

GATE2003_85 top
Consider the following functional dependencies in a database.
Date_of_Birth -> Age

Age -> Eligibility

Name -> Roll_number

Roll_number -> Name

Course_number -> Course_name

Course_number
Instructor

(Roll_number,
Grade

Course_number)

->

->

The relation (Roll_number, Name, Date_of_birth, Age) is


A. in second 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

There are three FDs that are valid from the above set of FDs for the given relation :
Date_of_Birth -> Age
Name -> Roll_number
Roll_number -> Name
candidate keys for the above are : (Date_of_Birth,Name) and (Date_of_Birth,Roll_number)
clearly there is partial dependency here (Date_of_Birth -> Age) and Age is not a prime attribute. So it is only in 1NF.
Option (D).

-- Danish

GATE2004_13 top
Let R1 ( A , B, C, D) and R2 ( D , E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key inR1

referring to R2 . Suppose there is no violation of the above referential integrity constraint in the corresponding relation instancesr1 and r2 .
Which of the following relational algebra expressions would necessarily produce an empty relation?

A. D (r2 ) C (r1 )
B. C (r1 ) D (r2 )
C. D (r1 C D r2 )
D. C (r1 C= D r2 )

ans (B)
C in R1 is a foreign key referring to the primary key D in R2. So, every element of C must come from some D element.

-- Vicky Bajoria

GATE2004_14 top
Consider the following relation schema pertaining to a students database:
Students(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), whew * denotes natural join?

A.
B.
C.
D.

8, 8
120, 8
960, 8
960, 120

Rollno in students is key, ans students table has 120 tuples, In Enroll table rollno is FK referencing to Students table. in natural join it'll return
the records where the rollno value of enroll matches with the rollno of students so in both conditions min and max records will be resulted
(8,8).
hence A is the answer.
Hint: table which has non-key, no of records of that will be resulted.
-- Manu Thakur

GATE2004_50 top
The relation scheme Student Performance (name, courseNo, 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.
B.
C.
D.

2 NF
3 NF
BCNF
4 NF

If we proceed with given FDs then either Name,courseno or RollNo,courseNo becomes the candidate key. So no non-prime attributes are
partially dependent on any Key attributes. Hence 2NF test passed.
Again for 3rd and 4th FD, Name,roll are part of the key and for first 2 FDs, determinants are candidate key itself. So 3NF test passed but not
BCNF. Hence 3NF answer. b.
-- shreya ghosh

GATE2007_60 top
Consider the relation employee(name, sex, supervisorName) with name as the key, supervisorName gives the name of the supervisor of the
employee under consideration. What does the following Tuple Relational Calculus query produce?

A.
B.
C.
D.

Names of employees with a male supervisor.


Names of employees with no immediate male subordinates.
Names of employees with no immediate female subordinates.
Names of employees with a female supervisor.

Query is selecting e such that e is an employee and for all x, either x is not an employee or x's supervisor's name is not e.name or x is male.
So, this is equivalent to saying, select all employees who don't have an immediate female subordinate. (Assuming there is no transgender).
(C) option.
-- Arjun Suresh

GATE2007_62 top
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 a 3 NF relation
D. A prime attribute can be transitively dependent on a key in a BCNF relation

(d)
Defn from wiki:
The 3NF version of the definition is weaker than Date's BCNF variation, as the former is concerned only with ensuring thatnon-key attributes
are dependent on keys. Prime attributes (which are keys or parts of keys) must not be functionally dependent at all; they each represent a fact
about the key in the sense of providing part or all of the key itself. (It should be noted here that this rule applies only to functionally dependent
attributes, as applying it to all attributes would implicitly prohibit composite candidate keys, since each part of any such key would violate the
"whole key" clause.)
-- Aravind

Consider table R(A,B,C,D,E) with FDs as A->B, BC->E and ED-> A. The table is in which
normal form? Justify your answer. top

First step: Identify the candidate keys. Candidate keys must be able to determine all other attributes. Most of the time they can be found by
just looking at the FDs. Here,
EDC is a candidate key so are ACD and BCD.
Now, just check for the conditions of each normal form.
We can see A->B.
ACD is the candidate key and A is a partial key. But B is a prime-attribute (part of a candidate key). Hence, this is not a partial functional
dependency.
Similarly in BC->E and ED->A, E and A are prime-attributes and hence both are not partial functional dependencies. Hence R is in 2NF.
Now 3NF states that every non-prime attribute must be dependent on the candidate key. In the given functional dependencies, all dependent
attributes are prime-attributes and hence it is trivially in 3NF.
Now BCNF requires that for every FD > , must be a super key (candidate key or its superset). This condition is violated by all the 3
FDs given and hence R is not in BCNF.

So, 3NF is the highest normal form table can be in.


-- gatecse

GATE2009_45 top
Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following queries on the database:
1. RS (r) RS (RS (r) s RS,S (r))
2. {t t RS (r) u s(v r(u = v[s] t = v[R S]))}
3. {t t RS (r) v r(u s(u = v[s] t = v[R S]))}
4.
Select R.a,R.b
From R,S
Where R.c = S.c

Which of the above queries are equivalent?


(A) 1 and 2
(B) 1 and 3
(C) 2 and 4
(D) 3 and 4

1. RS (r) RS (RS (r) s RS,S (r))


= a,b (r) a,b (a,b (r) s R (r))
= (r/s)
2. Expanding logically the statement means to select t (a,b) from r such that for all tuples u in s, there is a tuple v in r, such that u = v[S] and t =
v[R-S]. This is just equivalent to

(r/s)

3. Expanding logically the statement means that select t (a,b) from r such that for all tuples v in r, there is a tuple u in s, such that u = v[S] and t
= v[R-S]. This is equivalent to saying to select (a,b) values from r, where the c value is in (s/r), which will be true only if c in r is a foreign key
referring to c in s.
4. This selects (a,b) from all tuples from r which has an equivalent c value in s.
So, 1 and 2 are equivalent
r
a

Arj

TY

12

Arj

TY

14

Cell

TR

13

Tom

TW

12

Ben

TE

14

s
c
12
14
1.
2.
3.
4.

will give <Arj, TY>


will give <Arj, TY>
will not return any tuple as the c value 13, is not in s.
will give <Arj, TY>, <Arj, TY>, Tom, TW>, <Ben, TE>

http://pages.cs.wisc.edu/~dbbook/openAccess/firstEdition/slides/pdfslides/mod3l1.pdf

-- Arjun Suresh

GATE2005_29 top
Which one of the following statements about normal forms is FALSE?

A. BCNF is stricter than 3NF


B. Lossless, dependency-preserving decomposition into 3NF is always possible
C. Lossless, dependency-preserving decomposition into BCNF is always possible
D. Any relation with two attributes is in BCNF

option c
-- Sankaranarayanan P.N

GATE2005_30 top
Let r be a relation instance with schema R = (A, B, C, D). We definer1 = A,B,C (R) and r2 = A,D (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 r
B. r s = r
C. r s
D. r s = s

Answer is C.
A

R
C

B
1
1

2
5

3
3

3
4

3
4
S = R1 * R2
B
C
2
3
2
3
5
3
5
3

D
3
4
3
4

R1
B
2

A
1
1

5
R2
D

A
1
1
A
1
1
1
1

C
3
3

Red color rows of S are present in R so


and one more result R * S = R.
-- Vikrant Singh

GATE2005_75 top

Let E 1 and E 2 be two entities in an E/R diagram with simple-valued attributes. R1 and R2 are two relationships between E 1 and E 2 , 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.
B.
C.
D.

2
3
4
5

We need a separate table for many-to-many relation.


one-to-many relation doesn't need a separate table and can be handled using a foreign key.
So, answer is B. 3 tables.
Ref: http://web.cse.ohio-state.edu/~gurari/course/cse670/cse670Ch9.xht
-- Arjun Suresh

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

The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple (2, 4) is deleted is:

A.
B.
C.
D.

(3, 4) and (6, 4)


(5, 2) and (7, 2)
(5, 2), (7, 2) and (9, 5)
(3, 4), (4, 3) and (6, 4)

(c)
since deleting (2,4) , since 2 is a primary key, u have to delete its foreign key occurence i.e (5,2) and (7,2)
since we are delting 5 , and 7 we have delete it foreign key occurence i.e (9,5)
there is no foreign key occurence for 9
-- Aravind

GATE2005_78 top
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 R?

A. AE, BE
B. AE, BE, DE

C. AEH, BEH, BCH


D. AEH, BEH, DEH

(d) AEH, BEH, DEH


using the given functional dependencies and looking at the dependent attributes, E and H are not dependent on any. So, they must be part of
any candidate key. So, only option is D. If we see the FD's, adding A, B or D to EH do form candidate keys.
-- Aravind

GATE1999_2.25 top
Which of the following is/are correct?
A.
B.
C.
D.

An SQL query automatically eliminates duplicates


An SQL query will not work if there are no indexes on the relations
SQL permits attribute names to be repeated in the same relation
None of the above

(d)
sql wont remove duplicates, we have to remove it explicilty by distict
sql, if we din chose any indexes it will choose by its own
sql doesn not permit 2 attributes to have same name
-- Aravind

GATE2013_54,55 top
Relation R has eight attributes ABCDEFGH. Fields of R contain only atomic values. F ={CHG, ABC, BCFH, EA, FEG} is a set of
functional dependencies (FDs) so that F + is exactly the set of FDs that hold for R.
Q.54 How many candidate keys does the relation R have?
(A) 3

(B) 4

(C) 5

(D) 6

Q.55 The relation R is


(A) in 1NF, but not in 2NF.
(B) in 2NF, but not in 3NF.
(C) in 3NF, but not in BCNF.
(D) in BCNF.

54) B.4 candidate keys namely DA,DB,DE,DF.


55) A.
as in F->G,G is non-prime attribute but F is a proper subset of a candidate key.so violates 2nf condition.hence R is in 1nf.
-- kalpashri

GATE1998_2.19 top
Which of the following query transformations (i.e., replacing the l.h.s. expression by the r.h.s expression) is incorrect? R1 and R2 are relations,
C 1 and C2 are selection conditions and A1 and A2 are attributes of R1.

A. C 1 (C 2 (R1 )) C 2 (C 1 (R1 ))
B. C 1 (A1 (R1 )) A1 (C 1 (R1 ))
C. C 1 (R1 R2 ) C 1 (R1 ) C 1 (R2 )
D. A1 (C 1 (R1 )) C 1 (A1 (R1 ))

D) if the selection condition is on attribute A2, then we cannot replace it by RHS as there will not be any attribute A2 due to projection of A1
only.
-- Shaun Patel

GATE2014-1_21 top
Consider the relation scheme R

= (E, F , G, H, I, J, K, L, M, N) and the set of functional dependencies


{{E, F } {G}, {F } {I, J}, {E, H} {K, L},
{K} {M}, {L} {N}}

on

R. What is the key for R?

(A) {E, F }
(B) {E, F , H}
(C) {E, F , H, K, L}
(D) {E}

since H cannot be derived from anything else H should be there in key


using Find {EFH}+ it contains all the attributes of the relation
hence it is key
-- Sankaranarayanan P.N

GATE2014-1_22 top
Given the following statements:
S1: A foreign key declaration can always be replaced by an equivalent check assertion in SQL.
S2: Given the table R(a, b, c) where a and b together form the primary key, the following is a valid table definition.
CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R)

Which one of the following statements is CORRECT?


(A) S1 is TRUE and S2 is FALSE
(B) Both S1 and S2 are TRUE
(C) S1 is FALSE and S2 is TRUE
(D) Both S1 and S2 are FALSE

(D)both are false


S1: foreign key constraint means a lot of constraints it has to be a primary key(which intrun has few constraints)
we cannot replace it with a single check

S2:
if a and b forms a primary key in R, a alone cannot form a foreign key.
foreign ken dfn: it should be a candidate key in some other table(in our case it is only a prime attribute)

please add points if i had missed any


-- Aravind

GATE2006_70 top
The following functional dependencies are given:

AB CD, AF D, DE F ,C G, F E, G A
Which one of the following options is false?
(A) {CF }
(B) {BG}
(C) {AF }
(D) {AB}

= {ACDEF G}
= {ABCDG}
= {ACDEF G}
= {ABCDG}

{AF}* ={AFDE}. Hence option C is wrong


-- Sankaranarayanan P.N

GATE2014-1_54 top
Given the following schema:
employees(emp-id, first-name, last-name, hire-date, dept-id, salary)
departments(dept-id, dept-name, manager-id, location-id)
You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the
following query:
SQL>SELECT last-name, hire-date
FROM employees
WHERE (dept-id, hire-date) IN
(SELECT dept-id, MAX(hire-date)
FROM employees JOIN departments USING(dept-id)
WHERE location-id =1700
GROUP BY dept-id);

What is the outcome?


(A) It executes but does not give the correct result
(B) It executes and gives the correct result.
(C) It generates an error because of pairwise comparison.
(D) It generates an error because of the GROUP BY clause cannot be used with table joins in a sub-query.

SELECT dept-id, MAX(hire-date)


FROM employees JOIN departments USING(dept-id)
WHERE location-id =1700
GROUP BY dept-id

this inner query will give the max hire date of each department whose location_id =1700
and outer query will give the last name and hire-date of all those employees who joined on max hire date.
answer should come to (B) no errors
And we can use group by and where together, who said we can not :(
Example: create table departments(dept_id number, dept_name varchar2(25), location_id number);
Query: select d1.dept_name,max(d1.location_id)

from departments d1, departments d2


where d1.dept_name = d2.dept_name
and d1.dept_name='AA'
group by d1.dept_name;
will give output

-- Manu Thakur

GATE2014-2_22 top
Given an instance of the STUDENTS relation as shown as below

StudentID

StudentName

StudentEmail

StudentAge

CPI

2345

Shankar

Shankar@math

9.4

1287

Swati

swati@ee

19

9.5

7853

Shankar

Shankar@cse

19

9.4

9876

Swati

swati@mech

18

9.3

8765

Ganesh

ganesh@civil

19

8.7

For (StudentName, StudentAge) to be a key for this instance, the value X should NOT be equal to______.

should not eqaul to 19.


Since if it is equal the same key will have two different values which cannot be true by the definition of candidate/primary/super key.
-- Aravind

GATE2014-2_54 top
SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives
the same answer as the nested query shown below:
select * from R where a in (select S.a from S)

(A)
select R.* from R, S where R.a=S.a

(B)
select distinct R.* from R,S where R.a=S.a

(C)
select R.* from R,(select distinct a from S) as S1 where R.a=S1.a

(D)
select R.* from R,S where R.a=S.a and is unique R

C)
Consider the following instances of R & S
Let R
A

Let S:A

1
3

2
5

3
7

Now output of given Query

select * from R where a in (select S.a from S)

A
1

B
2

C
3

For Option,
A) since multiplicity of tuples is disturbed
select R.* from R, S where R.a=S.a
Output will be
A

B)
select distinct R.* from R,S where R.a=S.a
only Distinct R will be chosen in the end so , Output will look like
A

C) ANSWER
select R.* from R,(select distinct a from S) as S1 where R.a=S1.a
Multiplicity of tuples is maintained. Multiplicity of duplicate tuples will be distributed when there is a match between R.a and S.a and for that
match S.as value is repeated.
So, Output will be
A

1
1

2
2

3
3

-- Kalpish Singhal

GATE2014-3_21 top
What is the optimized version of the relation algebra expression
are Boolean expressions based on the attributes in r?
(A)

A1 ((F1F2) (r))

(B)

A1 ((F1F2) (r))

A1 (A2 (F1 (F2 (r)))), where A1, A2 are sets of attributes in r with A1 A2 and F 1, F 2

(C) A2 ( (F1F2) (r))


(D) A2 ( (F1F2) (r))

(A)

A1 ((F1F2)(r))

since A1 is subset of A2 will get only A1 attributes as it is in th eoutside, so we can remove project A2
two selects with boolean expreassion can be combined into one select with and of two boolean expressions
-- Aravind

GATE2014-3_22 top
A prime attribute of a relation scheme
(A) in all candidate keys of

(B) in some candidate key of


(C) in a foreign key of

R is an attribute that appears

(D) only in the primary key of

prime attribute is a constituent of a candidate key. it need not present in all candidate keys. hence option B is correct
correct me if i went wrong
-- Sankaranarayanan P.N

GATE2014-3_30 top
Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee.
Assume that every employee has at least one associated dependent in the dependent relation.
employee (empId, empName, empAge)
dependent(depId, eId, depName, depAge)
Consider the following relational algebra query:

empId (employee) empId (employee (empId=eID)(empAgedepAge) dependent)


The above query evaluates to the set ofempIds of employees whose age is greater than that of
(A) some dependent.
(B) all dependents.
(C) some of his/her dependents.
(D) all of his/her dependents.

(D) all of his/her dependents.


The inner query selects the employees whose age is less than or equal to at least one of his dependents. So, subtracting from the set of
employees, gives employees whose age is greater than all of his dependents.
-- Arjun Suresh

GATE2014-3_54 top
Consider the following relational schema:
employee(empId,empName,empDept)

customer(custId,custName,salesRepId,rating)
salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer.
What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
FROM customer C
WHERE C.salesRepId = E.empId
AND C.rating <> 'GOOD');

(A) Names of all the employees with at least one of their customers having a GOOD rating.
(B) Names of all the employees with at most one of their customers having a 'GOOD' rating.
(C) Names of all the employees with none of their customers having a 'GOOD' rating.
(D) Names of all the employees with all their customers having a 'GOOD' rating.

(D)
inner query selects "employees with atleast one bad rating"
so negation on the above stmt give -> "employees with all ratings as good"
PS:put a ven diagram and practice for these kind of questions
-- Aravind

GATE2011_32 top
Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record(X=1, Y=1) is
inserted in the table.
Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. UsingMX and MY ,
new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after
the insertion, values of MX and MY change.
What will be the output of the following SQL query after the steps mentioned above are carried out?
SELECT Y FROM T WHERE X=7;

(A) 127
(B) 255
(C) 129
(D) 257

X = 1, Y = 1
X = 2, Y = 2*1 +1 = 3
X = 3, Y = 2*3 + 1 = 7
X = 4, Y = 2*7 + 1 = 15
X = 5, Y = 2*15 + 1 = 31
X = 6, Y = 2*31+1 = 63
X = 7, Y = 2*63 + 1 = 127
-- Arjun Suresh

GATE2011_46 top
Database table by name

Loan_Records is given below.


Borrower

Bank_Manager

Loan_Amount

Ramesh
Suresh

Sunderajan
Ramgopal

10000.00
5000.00

Mahesh

Sunderajan

7000.00

What is the output of the following SQL query?


SELECT count(*)
FROM (
SELECT Borrower, Bank_Manager FROM Loan_Records) AS S
NATURAL JOIN
(SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T
);

(A) 3
(B) 9
(C) 5
(D) 6

i think ans is (c)


when we perform natural join on S and T then result will be like this
BORROW

B MANAGER

LOAD_AMOUNT
ramesh

after that count (*) will count total tuples present in this table so here it is 5
-- neha pawar

GATE2010_19 top
A relational schema for a train reservation database is given below.
passenger(pid, pname, age)
reservation(pid, class, tid)

Table: Passenger
pid

pname

Age

'Sachin'

65

'Rahul'

66

'Sourav'

67

'Anil'

69

Table: Reservation
pid

class

tid

'AC'

8200

'AC'

8201

'SC'

8201

'AC'

8203

'SC'

8204

'AC'

8202

What pids are returned by the following SQL query for the above instance of the tables?
SELECT pid

sunderajan
ramesh
sunderajan
suresh
ramgopal
mahesh sunderajan
mahesh
sunderajan

10,000
7000
5000
10,000
7000

FROM Reservation
WHERE class='AC' AND
EXISTS (SELECT *
FROM Passenger
WHERE age>65 AND
Passenger.pid=Reservation.pid)

(A) 1, 0
(B) 1, 2
(C) 1, 3
(D) 1, 5

(c)1,3
the inner query gives passenger_id with age above 65 i.e. 1,2,3
the outer query chooses the class as AC, which are 1 and 3
-- Aravind

GATE1997_6.9

top

Ck is ab.
Since all a,b,c,d are atomic so the relation is in 1 NF.
Now check the FD s.
a->c(P->NP)
b->d(P->NP)
Since there are partial dependencies,so it is not 2 NF.
a}Ans 1NF but not 2NF
-- Sourav Roy

GATE1997_6.10 top

R
a Let(PK)

1
2
S

d(FK referring to PK of R)

2
1
@)Insert into R cannot cause any violation.
Insert into S can cause violation if any value is inserted into d of S, which value is not in a of R.
Delete from S would cause no violation.
Delete from R would cause violation if it any tuple is deleted,and as a result a value in a gets deleted which is refereed to by d in S.
Hence
d)Ans
-- Sourav Roy

GATE1993_14 top

Answer: 3
Size of each index entry = 14 + 2 = 16 B
Block size
Record size

Blocking factor of record file =


Blocking factor of index file =

= 512 B/64 B = 8

Block size
Index entry size

No. of Blocks needed for data file =

= 512 B/16 B = 32

No. of Records
Blocking factor of record file

= 16 K/8 = 2 K

No. of first level index entries = No. of Data Blocks needed for data file = 2 K
No. of first level index blocks = No. of first level index entries = 2K = 64
Blocking factor of index file

32

No. of second level index entries = No. of first level index blocks = 64
No. of second level index blocks = No. of second level index entries = 64 = 2
Blocking factor of index file

32

No. of third level index entries = No. of second level index blocks = 2
No. of third level index blocks = No. of third level index entries =
Blocking factor of index file

32

-- Jon Snow

GATE2010_42 top
Consider the following schedule for transactions T1, T2 and T3:

T1

T2

T3

Read(X)
Read(Y)
Read(Y)
Write(Y)
Write(X)
Write(X)
Read(X)
Write(X)

Which one of the schedules below is the correct serialization of the above?

=1

(A)

T1 T3 T2

(B)

T2 T1 T3

(C) T 2

T3 T1

(D) T 3

T1 T2

You can use method of conflict serializability graph or precedence graph Ref: Elmasri Navathe. Then serialisation is T1 T3 T2
-- Sankaranarayanan P.N

GATE2010_43 top
The following functional dependencies hold for relations R(A, B, C) and S(B, D, E).

BA
AC
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 S?
(A) 100
(B) 200
(C) 300
(D) 2000

(A) 100
natural join will combine tuples with same value of the common rows(if there are two common rows then both vaues must be equal to get into
the resultant set). So by this defn: we can get at the max only 100 common values :P
-- Aravind

GATE2007 _59

top

Information about a collection of students is given by the relationstudInfo(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?

courceId ((studId (sex="female"(studInfo)) courseId (enroll)) enroll)


(A) Courses in which all the female students are enrolled.
(B) Courses in which a proper subset of female students are enrolled.
(C) Courses in which only male students are enrolled.
(D) None of the above

What the cartesian product actually doing is, it taking the studentId of "female" student from studInfo relation, and performing the cartesian
product with all courses that are available... so it will return the all possible combination of "female" student can enroll in various courses.. Now
finally we are subtracting "enroll" from it.. "enroll" relation contain what actually enrollment has been done.. so the substraction will return the
"courseId" a "female student has not been enrolled..!!
because, ( all possible enrollment in various course of female) - ( actual enrollment) = courses in which female enrollment has not
happened!!...
Option (b) is saying "female student which are enrolled (proper Subset)".. No but it is returning courses in which female student are NOT
enrolled!!.. so option (D)
-- Vicky Bajoria

GATE1994_3.7

top

An instance of a relational scheme R(A, B, C) has distinct values for attribute A. Can you conclude that A is a candidate key for R?

No.
A

Suppose this is the relational instance at any point of time.


Now we may see that A->BC holds for this instance ,hence A+={ABC}.
But FD s are defined on the schema itself not the instance, so based on the state of the instance we cannot say what holds for schema (there
can be a many instances for R).
-- Sourav Roy

GATE1995_26 top
Consider the relation scheme R(A, B, C) with the following functional dependencies:
A, B C,
CA
a. Show that the scheme R is in 3NF but not in BCNF.
b. Determine the minimal keys of relation R.

The Candidate Keys are AB and BC.


None of the given functional dependencies are partial. So, the scheme qualifies for 2 NF.
There is no transitive dependency. So, the scheme qualifies for 3 NF.
All determinants are not Candidate Keys. So, the scheme do not qualify for BCNF.
-- Jon Snow

GATE1995_27 top

a. select pname from publisher;


2. select author.* from author, book
where author.aname = book.name
and book.pname = 'TECHNICAL PUBLISHERS';
3. select author.aname from author, book, publisher
where author.aname = book.aname

and book.pname = publisher.pname


and publisher.pcity='Madras';
-- Manu Thakur

GATE1996_27 top
A library relational database system uses the following schema
USERS (User#, User Name, Home Town)
BOOKS (Book#, Book Title, Author Name)
ISSUED (Book#, User#, Date)
Explain in one English sentence, what each of the following relational algebra queries is designed to determine
a. User#=6 (User#, Book Title ((USERS ISSUED) BOOKS))
b. Author Name (BOOKS Home Town=Delhi (USERS ISSUED))

(a) Select the (user# and) titles of the books issued to User# 6
(b) Select author names of the books issued to users whose home town is Delhi
-- Arjun Suresh

functional dependency

top

GIven a relation instance


X

10

12

which of the following FDs is satisfied by relation


A)XY Z, Z Y
B)YZ X, Y Z
C)YZ X, X Z
D)XZ Y, Y X

Z-> Y is not satisfied as when Z = 4, Y has values 8 as well as 4. So, (A) is False.
YZ and Y are unique and hence FDs in (B) are trivially satisfied.
X->Z is not satisfied as when X=2, Z can have 4 as well as 6. So, (C) is false.
XZ -> Y is not satisfied as when XZ = {2,6}, Y can have 10 as well as 12. So, D is false.
-- Arjun Suresh

Find the number of candidates keys that includes attribute A3

top

A relation R with 5 attributes A1, A2, A3, A4, A5. Given the following FDs
A1 A2
A2A3 A5
A4A5 A1
Find the number of candidates keys that includes attribute A3

A4 and A3 are not coming on the RHS of any FD. So, they must be in all candidate keys.
Consider A4A5, due to A4A5 -> A1 and A1-> A2, A4A5 determines {A1 A2 A4 A5}, and hence A3A4A5 is a candidate key.

Similarly, A2A3A4 and A1A3A4 are candidate keys.


So, 3 is the answer.
-- Arjun Suresh

GATE2008-IT_61 top
Let R (A, B, C, D) be a relational schema with the following functional dependencies :
A B, B C,
C D and D B. The decomposition of R into (A, B), (B, C), (B, D)

A)

gives a lossless join, and is dependency preserving

B)

gives a lossless join, but is not dependency preserving

C)

does not give a lossless join, but is dependency preserving

D)

does not give a lossless join and is not dependency preserving

Option A.
(A,B) (B,C) -> common attribute is B and due to B->C, B is a key for (B,C) and hence ABC can be losslessly decomposed into (A,B) and (B,C).
(A, B, C) (B, D), common attribute is B and B->D is a FD (via B->C, C->D), and hence B is a key for (B, D). So, decomposition of (A, B, C, D)
into (A, B, C) (B, D) is lossless.
Thus the given decomposition is lossless.
The given decomposition is also dependency preserving as the dependencies A->B is is present in (A, B), B->C is present in (B, C), D->B is
present in (B, D) and C->D is indirectly present via C->B in (B, C) and B->D in (B, D).
http://www.sztaki.hu/~fodroczi/dbs/dep-pres-own.pdf
-- Arjun Suresh

GATE2008-IT_62 top
Let R (A, B, C, D, E, P, G) be a relational schema in which the following functional dependencies are known to hold: AB CD, DE P, C
E, P C and B G. The relational schema R is

1)

in BCNF

2)

in 3NF, but not in BCNF

3)

in 2NF, but not in 3NF

4)

not in 2NF

Answer: D
Here AB is the candidate key and B->G is a partial dependency. So, R is not in 2 NF.
-- Jon Snow

GATE2008-IT_74 top
Student (school-id, sch-roll-no, sname, saddress)
School (school-id, sch-name, sch-address, sch-phone)
Enrolment(school-id sch-roll-no, erollno, examname)
ExamResult(erollno, examname, marks)
What does the following SQL query output?
SELECT sch-name, COUNT (*)
FROM School C, Enrolment E, ExamResult R
WHERE E.school-id = C.school-id
AND
E.examname = R.examname AND E.erollno = R.erollno

AND
R.marks = 100 AND S.school-id IN (SELECT school-id
FROM student
GROUP BY school-id
HAVING COUNT (*) > 200)
GROUP By school-id

1) for each school with more than 200 students appearing in exams, the name of the school and the number of 100s scored by its students
2) for each school with more than 200 students in it, the name of the school and the number of 100s scored by its students
3) for each school with more than 200 students in it, the name of the school and the number of its students scoring 100 in at least one exam
4) nothing; the query has a syntax error

D:
If Select clause consist aggregate and non - aggregate columns.All non aggregate columns in the Select clause must appear in Group By
clause. But in this query Group by clause consists school-id instead of school-name
http://weblogs.sqlteam.com/jeffs/archive/2007/07/20/but-why-must-that-column-be-contained-in-an-aggregate.aspx
-- erravi90

GATE2007-IT_68 top
Consider the following relation schemas :
b-Schema = (b-name, b-city, assets)
a-Schema = (a-num, b-name, bal)
d-Schema = (c-name, a-number)
Let branch, account and depositor be respectively instances of the above schemas. Assume that account and depositor relations are much
bigger than the branch relation.
Consider the following query:
c-name (b-city = "Agra" bal < 0 (branch (account depositor)
Which one of the following queries is the most efficient version of the above query ?

A)

c-name (bal < 0 (b-city = "Agra" branch account) depositor)

B)

c-name (b-city = "Agra" branch (bal < 0 account depositor))

C)

c-name ((b-city = "Agra" branch b-city = "Agra"

bal < 0

account) depositor)

D)

c-name (b-city = "Agra" branch (b-city = "Agra"

bal < 0

account depositor))

It should be A. As in B we are doing a join between two massive table whereas in A we are doing join between relatively smaller table and
larger one and the output that this inner table gives(which is smaller in comparison to joins that we are doing in B) is used for join with
depositer table with the selection condition.
-- Shaun Patel

GATE2006-IT_14 top
Consider the relations r1(P, Q, R) and r2(R, S, T) with primary keys P and R respectively. The relation r1 contains 2000 tuples and r2 contains
2500 tuples. The maximum size of the join r1 r2 is :

A)

2000

B)

2500

C)

4500

D)

5000

the common attribute is R and it is primary key in the second relation. hence the R value is distinct for 2500 rows. hence when we join max
possible number of tuples is 2000
option A

-- Sankaranarayanan P.N

GATE2006-IT_84 top

Consider a database with three relation instances shown below. The primary keys for the Drivers and Cars relation aredid and cid respectively
and the records are stored in ascending order of these primary keys as given in the tables. No indexing is available in the database.
D: Drivers relation
did

dname

rating

age

22

Karthikeyan

25

29

Salman

33

31

Boris

55

32

Amoldt

25

58

Schumacher

10

35

64

Sachin

35

71

Senna

10

16

74

Sachin

35

85

Rahul

25

95

Ralph

53

R: Reserves relation
did

cid

day

22

101

10/10/06

22

102

10/10/06

22

103

08/10/06

22

104

07/10/06

31

102

10/11/06

31

103

06/11/06

31

104

12/11/06

64

101

05/09/06

64

102

08/09/06

74

103

08/09/06

cid

cname

colour

101

Renault

blue

102

Renault

red

103

Ferrari

green

104

Jaguar

red

C: cars relation

What is the output of the following SQL query?


select D.dname
from Drivers D
where D.did in (
select R.did
from Cars C, Reserves R
where R.cid = C.cid and C.colour = 'red'
intersect
select R.did
from Cars C, Reserves R
where R.cid = C.cid and C.colour = 'green'
)

A)

Karthikeyan, Boris

B)

Sachin, Salman

C)

Karthikeyan, Boris, Sachin

D)

Schumacher, Senna

For color = "Red"


did = {22, 22, 31, 64}
For color = "Green"
did = {22, 31, 74}
intersection of Red and Green will give = {22, 31}
which is Karthikeyan and Boris
Ans: A
-- Vikrant Singh

GATE2004-IT_21 top
Which level of locking provides the highest degree of concurrency in a relational database ?

A)

Page

B)

Table

C)

Row

D)

Page, table and row level locking allow the same degree of concurrency

row level locking provides more concurrency. because different transactions can access different rows in a table / page at same time
-- Sankaranarayanan P.N

GATE2004-IT_74 top
A relational database contains two tables student and department in which student table has columns roll_no, name and dept_id and
department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty
tables:
Insert into department values (1, 'Mathematics')
Insert into department values (2, 'Physics')
Insert into student values (l, 'Navin', 1)
Insert into student values (2, 'Mukesh', 2)
Insert into student values (3, 'Gita', 1)

How many rows and columns will be retrieved by the following SQL statement?
Select * from student, department

A.
B.
C.
D.

0 row and 4 columns


3 rows and 4 columns
3 rows and 5 columns
6 rows and 5 columns

since there is no specific joining condition specified it will retrieve cartesian product of the table
number of rows = product of number of rows in each realtion = 3*2 = 6
number of columns = sum of number of columns = 3+2 = 5
answer: D
-- Sankaranarayanan P.N

GATE2004-IT_75 top
A relation Empdtl is defined with attributes empcode (unique), name, street, city, state and pincode. For any pincode, there is only one city and

state. Also, for any given street, city and state, there is just one pincode. In normalization terms, Empdtl is a relation in
A.
B.
C.
D.

1NF only
2NF and hence also in 1NF
3NF and hence also in 2NF and 1NF
BCNF and hence also in 3NF, 2NF an 1NF

its in 2nf - for 2nf all non prime attribute should be fully functionally dependent on key. here key is empcode. key contains only one attribute
hence. no partial dependency. but there is transitive dependency in this. so it is not in 3 NF
answer: B
-- Sankaranarayanan P.N

GATE2004-IT_76 top
A table T1 in a relational database has the following rows and columns:
roll no.

marks

10

20

30

Null

The following sequence of SQL statements was successfully executed on table T1.
Update T1 set marks = marks + 5
Select avg(marks) from T1

What is the output of the select statement?

A.
B.
C.
D.

18.75
20
25
Null

Update on null gives null. Now, avg function ignores null values. So, here avg will be (15 + 25 + 35) / 3 = 25.
http://msdn.microsoft.com/en-us/library/ms177677.aspx
-- Arjun Suresh

GATE2004-IT_78 top
Consider two tables in a relational database with columns and rows as follows:

Table: Student
Roll_no

Name

Dept_id

ABC

DEF

GHI

JKL

Table: Department
Dept_id

Dept_name

Dept_id

Dept_name

Roll_no is the primary key of the Student table, Dept_id is the primary key of the Department table and Student.Dept_id is a foreign key from
Department.Dept_id
What will happen if we try to execute the following two SQL statements?
i. update Student set Dept_id = Null where Roll_on = 1
ii. update Department set Dept_id = Null where Dept_id = 1

A)

Both (i) and (ii) will fail

B)

(i) will fail but (ii) will succeed

C)

(i) will succeed but (ii) will fail

D)

Both (i) and (ii) will succeed

ans is C
here in (i) when we update in STUDENT table dept id =NULL then it will not cause any problem to referenced table
but in (II) if we set in DEPARTMENT table dept id =NULL then it will produce inconsistency because in STUDENT table we still have the
tuples containing the dept id =1
-- neha pawar

GATE2005-IT_21 top
Consider the entities 'hotel room', and 'person' with a many to many relationship 'lodging' as shown below:

If we wish to store information about the rent payment to be made by person (s) occupying different hotel rooms, then this information should
appear as an attribute of

A)

Person

B)

Hotel Room

C)

Lodging

D)

None of these

since it is many to many. rent cannot be an attribute of room or person entities alone. if depending on number of persons sharing a room the
rent for each person for the room will be different. otherwise rent can be attribute of room. hence i go for attribute of Lodging
-- Sankaranarayanan P.N

GATE2005-IT_22 top
A table has fields Fl, F2, F3, F4, F5 with the following functional dependencies
F1 F3 F2 F4 (F1 . F2) F5
In terms of Normalization, this table is in

1)

1 NF

2)

2 NF

3)

3 NF

4)

None of these

ans : 1
key is f1f2
f1->f3, f2-> f4 are partial dependencies
-- rajsh3kar

GATE2005-IT_24 top
Amongst the ACID properties of a transaction, the 'Durability' property requires that the changes made to the database by a successful
transaction persist

1)

Except in case of an Operating System crash

2)

Except in case of a Disk crash

3)

Except in case of a power failure

4)

Always, even if there is a failure of any kind

answer d. irrespective of any failure the successful result of transaction should persist.
suppose we book ticket 2 months in advance in irctc and transaction success
then when we are going to board the train on that time they tells because of system/disk/power crash they dont have your seat information
and you are not allowed in the seat
it is a serious problem. hence result should persist irrespective of all crashes
-- Sankaranarayanan P.N

GATE2005-IT_67 top
A company maintains records of sales made by its salespersons and pays them commission based on each individual's total sales made in a
year. This data is maintained in a table with following schema:
salesinfo = (salespersonid, totalsales, commission)
In a certain year, due to better business results, the company decides to further reward its salespersons by enhancing the commission paid to
them as per the following formula:
If commission < = 50000, enhance it by 2%
If 50000 < commission < = 100000, enhance it by 4%
If commission > 100000, enhance it by 6%
The IT staff has written three different SQL scripts to calculate enhancement for each slab, each of these scripts is to run as a separate
transaction as follows:
Update salesinfo

T1 Set commission = commission * 1.02


Where commission < = 50000;

Update salesinfo

T2 Set commission = commission * 1.04


Where commission > 50000 and commission is < = 100000;

Update salesinfo

T3 Set commission = commission * 1.06


Where commission > 100000;

Which of the following options of running these transactions will update the commission of all salespersons correctly

1)

Execute T1 followed by T2 followed by T3

2)

Execute T2, followed by T3; T1 running concurrently throughout

3)

Execute T3 followed by T2; T1 running concurrently throughout

4)

Execute T3 followed by T2 followed by T1

T3 followed by T2 followed by T1 will be correct execution sequence


other cases some people will get two times increment

eg if we have T1 followed by T2
if initial commision is 49500
then he is belonging to < 50000
hence 49500*1.02 = 50490
now he is eligible in second category
then 50490*1.04 = 52509.6

so he wil get increment two times. but he is eligible for only one slab of commision
-- Sankaranarayanan P.N

GATE2005-IT_68 top
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown
below:
Table: Student
Roll

Name

Hostel

Marks

1798

Manoj Rathod

95

2154

Soumic Banerjee

68

2369

Gumma Reddy

86

2581

Pradeep Pendse

92

2643

Suhas Kulkarni

78

2711

Nitin Kadam

72

2872

Kiran Vora

92

2926

Manoj Kunkalikar

94

2959

Hemant Karkhanis

88

3125

Rajesh Doshi

82

Table: hobby
Roll

Hobbyname

1798

chess

1798

music

2154

music

2369

swimming

2581

cricket

2643

chess

2643

hockey

2711

volleyball

2872

football

2926

cricket

2959

photography

3125

music

3125

chess

The following SQL query is executed on the above tables:


select hostel
from student natural join hobby
where marks > = 75 and roll between 2000 and 3000;

Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S is
obtained by the following relational algebra operation:
S = hostel (( s.roll = H.roll (marks > 75 and roll > 2000 and roll < 3000 (S)) X (H))

The difference between the number of rows output by the SQL statement and the number of tuples in S is

A)

B)

C)

D)

Sql query will return


Roll Hostel
2369 7
2581 6
2643 5
2643

5 Duplicate Row is present in


Hobby table

2872 5
2926 5
2959 7
Total 7 rows are selected.

In RA only distinct values of hostels are selected i.e. 5,6,7

SQL row count - RA row count = 7 - 3 = 4


Answer is B
-- Vikrant Singh

GATE2005-IT_70 top
In a schema with attributes A, B, C, D and E following set of functional dependencies are given
AB
AC
CD E
BD
EA
Which of the following functional dependencies is NOT implied by the above set?
A)

CD AC

B)

BD CD

C)

BC CD

D)

AC BC

Answer is B.
Apply membership test for all the given Functional Dependencies.
1.) CD-->AC
CD+ = CDEAB
2.) BD-->CD
BD+ = BD
i.e. BD cannot derive CD and hence is not implied.
Similarly do for rest two.
-- Gate Keeda

GATE2005-IT_82a

top

A database table T1 has 2000 records and occupies 80 disk blocks. Another table T2 has 400 records and occupies 20 disk blocks. These two
tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The
memory buffer space available can hold exactly one block of records for T1 and one block of records for T2 simultaneously at any point in time.
No index is available on either table.
If Nested-loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of
block accesses required for reading the data are

A)

800000

B)

40080

C)

32020

D)

100

Refer : http://en.wikipedia.org/wiki/Nested_loop_join
as per this reference This algorithm will involve n r*bs + br block transfers
either T1 can be R or T2
if R is T1 then total number of block access is 2000*20 + 80 = 40080
if R is T2 then total number of block access is 400*80+20 = 32020
so better is the second case (32020) Hence i go for option C

-- Sankaranarayanan P.N

GATE2005-IT_82b top
A database table T1 has 2000 records and occupies 80 disk blocks. Another table T2 has 400 records and occupies 20 disk blocks. These two
tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The
memory buffer space available can hold exactly one block of records for T1 and one block of records for T2 simultaneously at any point in time.
No index is available on either table.
If, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in
number of block accesses required for reading the data will be

A) 0
B) 30400
C) 38400
D) 798400

In Nested loop join for each tuple in first table we scan through all the tuples in second table.

Here we will take table T2 as the outer table in nested loop join algorithm. The number of block accesses then will be 20 + (400 80) = 32020
In block nested loop join we keep 1 block of T1 in memory and 1 block of T2 in memory and do join on tuples.

For every block in T1 we need to load all blocks of T2. So number of block accesses is 80*20 + 20 = 1620
So the difference is 32020 - 1620 =30400

(B) 30400
-- Omesh Pandita

What exactly a weak entity ?

top

We know that a weak entity has no primary key .

SO , A weak entity is an entity that cannot be uniquely identified by its attributes alone . Does it mean it has duplicates and it always a multi-set ?

Weak entity normally can be identified in connection with strong entity also . They are connected by an identifying relation. But it does not
mean that it should always have duplicates . it need not be always multi set
-- Sankaranarayanan P.N

Explain top

Ans is B:
here, inner query will retrive all students who have enrolled for the course with less than 5 credits. after join operation we are retriving SID of
all those students.
now, difference operator will return all SID which are in student relation but not in the result that we can from inner query. therefore it will
return all the SID of students who have enrolled for courses with credit greater than 5.
A is not correct because;
while performing set difference operator if any student has enrolled for any subject with less than 5 credit will be removed.
-- jayendra

Gate CS 2012 top


Consider the following transactions with data items P and Q initialized to zero:
T1: read (P) ;
read (Q) ;
if P = 0 then Q : = Q + 1 ;
write (Q) ;
T2: read (Q) ;
read (P) ;
if Q = 0 then P : = P + 1 ;
write (P) ;

Any non-serial interleaving of T1 and T2 for concurrent execution leads to


(A) A serializable schedule

(B) A schedule that is not conflict serializable


(C) A conflict serializable schedule
(D) A schedule for which a precedence graph cannot be drawn
I am new to transactions and concurrency control. Please provide simple explanation?

Ans is (B): explanation: T1:r(P),r(Q),w(Q) T2:r(Q),r(P),w(P) now consider any non serial schedule for example,
S:r1(P),r2(Q),r1(Q),r2(P),w1(Q),w2(P) now draw a precedence graph for this schedule. here there is a conflict from T1->T2 and there is a
conflict from T2->T1 therefore, the graph will contain a cycle. so we can say that the schedule is not conflict serializable.
-- jayendra

A relational table EMP(ENO(PK), EName, Dept) has 88 number of tubples. What will be the
result of following SQL Statement? top

Where E_no not in NULL - the predicate evaluates to unknown. so no rows will be printed.
-- shreya ghosh

True or False: Relational algebra cannot perform aggregate function


True or False: Relational algebra cannot perform aggregate function

False. Average, count, max, min are all in relational algebra.


-- anshu

GATE2015-2_1 top
Consider the following transaction involving two bank accounts x and y .
read(x); x:=x-50; write (x); read(y); y:=y+50; write(y)

The constraint that the sum of the accounts x and y should remain constant is that of
A.
B.
C.
D.

Atomicity
Consistency
Isolation
Durability

Kindly check out PPT for Transaction chapter in below link.( Part 5: Transaction Management Ch. 15)
http://www.cse.iitb.ac.in/~sudarsha/db-book/slide-dir/
Question is directly taken from Korth. And wording almost completely matches to Consistency requirement.
-- kshirsagar1992

top

GATE2015-2_6 top
With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the Root node) that must be fetched in
order to satisfy the following query. "Get all records with a search key greater than or equal to 7 and less than 15" is ______.

The total number of nodes accessed including root will be 5.


The order is,
(9)-->(5)-->(5,7)-->(9,11)-->(13,15).
-- Gate Keeda

GATE2015-1_7 top
SELECT operation in SQL is equivalent to
A.
B.
C.
D.

The selection operation in relational algebra


The selection operation in relational algebra, except that SELECT in SQL retains duplicates
The projection operation in relational algebra
The projection operation in relational algebra, except that SELECT in SQL retains duplicates

option D is correct because SELECT operation in SQL is equivalent to The projection operation in relational algebra, except
that SELECT in SQL retains duplicates but projection gives only distinct
-- Anoop Sonkar

GATE2015-1_24 top
A file is organized so that the ordering of the data records is the same as or close to the ordering of data entries in some index. Than that index
is called
A.
B.
C.
D.

Dense
Sparse
Clustered
Unclustered

Clustered- this is the definition of clustered indexing and for the same reason a table can have only one clustered index.
http://www.ece.rutgers.edu/~yyzhang/spring03/notes/7-B+tree.ppt
-- Arjun Suresh

GATE2015-1_27 top
Consider the following relation:
Student
Roll-No

Student name

Raj

Rohit

Raj
Performance

Roll-No

Course

Marks

Math

80

English

70

Math

75

English

80

Physics

65

Math

80

Consider the following SQL query.


SELECT S. student_Name, Sum(p. Marks)
FROM student S, performance P
WHERE S.Roll_No= P.Roll_No
GROUP BY S.STUDENT_Name

The numbers of rows that will be returned by the SQL query is_________________.

answer is 2 as there are only 2 distinct student names.


-- naresh1845

GATE2015-2_46 top
Consider a simple checkpointing protocol and the following set of operations in the log.
(start, T4); (write, T4, y, 2, 3); (start, T1); (commit, T4); (write, T1, z, 5, 7);
(checkpoint);
(start, T2); (write, T2, x, 1, 9); (commit, T2); (start, T3); (write, T3, z, 7, 2);
If a crash happens now and the system tries to recover using both undo and redo operations, what are the contents of the undo list and the
redo list?

A.
B.
C.
D.

Undo: T3, T1; Redo: T2


Undo: T3, T1; Redo: T2, T4
Undo: none; Redo: T2, T4, T3, T1
Undo: T3, T1, T4; Redo: T2

T1

T2

T3

T4
start
W(y,2,3)

start
commit
W(z,5,7)
Checkpoint

Checkpoint

Checkpoint

Checkpoint

start
W(x,1,9)
commit
start
W(z,7,2)
crash

crash

crash

crash

Now from the table we can find , T1 and T3 has uncommitted write operation , so they must be undone. and even though T2 has committed
after writing , but it is after checkpoint. So , it needs to be redone. So answer is A.
-- Shounak Kundu

GATE2015-3_3 top
Consider the following relation
Cinema(theater, address, capacity)
Which of the following options will be needed at the end of the SQL query
SELECT P1.address
FROM Cinema P1

such that it always finds the addresses of theaters with maximum capacity?

A. A. WHERE P1.capacity >= All (select P2.capacity from Cinema P2)


B. B. WHERE P1.capacity >= Any (select P2.capacity from Cinema P2)
C. C. WHERE P1.capacity > All (select max(P2.capacity) from Cinema P2)
D. D. WHERE P1.capacity > Any (select max(P2.capacity) from Cinema P2)

A is the answer
B - Returns the addresses of all theaters except the one with the min capacity
C - Returns null set. max() returns a single value and there won't be any value > max.
D - Returns null set. Same reason as C. All and ANY works the same here as max returns a single value.
-- Arjun Suresh

GATE2015-3_20 top
Consider the relation X(P , Q, R, S, T , U) with the following set of functional dependencies

F ={
{P , R} {S, T }
{P , S, U} {Q, R}
}
Which of the following is the trivial functional dependency inF + , where F + is closure to F?

A.
B.
C.
D.

{P , R} {S, T }
{P , R} {R, T }
{P , S} {S}
{P , S, U} {Q}

option C is correct because{P,S}{S}


for trivial if XY then Y must b subset of X and for non trivial FD X Y= . and {S} is subset of {P,S}
-- Anoop Sonkar

GATE2015-3_29 top
Consider the partial Schedule S involving two transactions T 1 and T 2 . Only the read and the write operations have been shown. The read
operation on data item P is denoted by read(P) and write operation on data item P is denoted by write(P) .
Schedule S
Time Instance
1

Transaction id

T1
read(A)

T2

write(A)

read(C)

write(C)

read(B)

write(B)

read(A)
commit

8
9

read(B)

Suppose that the transaction T 1 fails immediately after time instance 9. Which of the following statements is correct?

A.
B.
C.
D.

T 2 must be aborted and then both T 1 and T 2 must be re-started to ensure transaction atomicity
Schedule S is non-recoverable and cannot ensure transaction atomicity
Only T 2 must be aborted and then re-started to ensure transaction atomicity
Schedule S is recoverable and can ensure transaction atomicity and nothing else needs to be done

I think the correct option is B.


Why A is not correct because it says abort transaction T2 and then redo all the operations .
But is there a gaurantee that it will succed this time ??(no maybe again T1 will fail). .
now as to why b is correct because as the other answer points out it is by definition an irrecoverable schedule now even if we start to undo the actions
on by one(after t1 fails) in order to ensure transaction atomicity. Still we cannot undo a commited transaction. hence this schedule is unrecoverable by
definition and also not atomic since it leaves the data base in an inconsistent state.

-- Tamojit Chatterjee

GATE2015-3_46 top
Consider a B+ tree in which the search key is 12 bytes long, block size is 1024 bytes, recorder pointer is 10 bytes long and the block pointer is
8 byte long. The maximum number of keys that can be accommodated in each non-leaf node of the tree is ______.

(n-1)12 + n*8<=1024
n<=51
in non leaf node number of keys = n-1
=51-1=50
-- ppm

SQL top
Consider the Following Collection of relational schema
Professor( profname , deptname)
Department (deptname, building)
Committee(commname, Profname)
Which of following query finds all the professors who have not offices in any of those buildings that professor Piper has offices in
A.

Select distinct P.profname from professor P Where not exists (( Select building from department d where P.deptname= D.deptname ) Union (Select building from department D1, professor P1 Wh

B.
Select distinct P.profname Prom professor P
Where not exists
(( Select building from department d where P.deptname= D.deptname )

Intersect
(Select building from department D 1., professor P1
Where P1.profname=Piper and P1.deptname= D1.deptname))

C)
Select distinct P.profname
From professor P
Where not exists(
Select Building from Department d1, professor p1
Where P1.Profname=Piper and p1.deptname=D1.deptname )

D) None of these

Option B is correct, even though it has NOT EXISTS, it checks whether set of the building(s) belonging to the "current" professor (in the outer query) has any intersection with
the set of building(s) belonging to Prof. Piper, and if they intersect, we shouldn't take the current professor, otherwise yes. This is ensured by the NOT EXISTS clause that is
dependent on the outer query this time.

-- spriti1991

is the following relation is in BCNF form

top

r={a,b,c,d,e}
a->b
bc-> e
ed -> a

The candidate keys are ACD, BCD and CDE.


So all attributes are prime attributes and it is in 3 NF.. but not in BCNF as any of the determinants is not super keys (even one is sufficient to
disprove BCNF Condition).
-- Digvijay Pandey

Theory of Computation

top

GATE2012_12 top
What is the complement of the language accepted by the NFA shown below?
Assume = {a} and is the empty string.

(A)
(B) {}
(C) a
(D) {a, }

The language being accepted is a+ . So, complement of the language is {} .


-- Arjun Suresh

Consider the following languages

top

Consider the following languages

A = {< M > TM M accepts at most 2 distinct inputs}


B = {< M > TM M accepts more than 2 distinct inputs}
Identify the correct statement from the following:
(A) A is Turing recognizable B is not Turing recognizable
(B) B is Turing recognizable A is not Turing recognizable
(C) Both A and B are Turing recognizable
(D) Neither A nor B is Turing recognizable

B is the answer- A is not Turing recognizable while B is Turing recognizable.


A is Turing recognizable if TM for A, say TA outputs "yes" for "yes" cases of A- i.e.; when M accepts at most 2 distinct inputs. But M can loop
forever without accepting more than 2 distinct inputs and we can never be sure if it will or will not accept any more input. Thus, TA may not
output "yes" for "yes" cases of the language and hence A is not Turing recognizable.
Similarly, B is Turing recognizable if TM for B, say TB outputs "yes" for "yes" cases of B- i.e.; when M accepts more than 2 distinct inputs. If M
is accepting more than 2 distinct inputs, it's possible to enumerate all strings from the language (strings of length 1 followed by strings of
length 2 and so on ) and feed to M. (We should use [ dovetailing][1] technique so that even if some string causes TM to loop forever, we can
continue progress). If M is accepting more than 2 distinct inputs we are sure that we'll encounter those strings after some finite moves of the
TM. Thus TB can always output "yes" for "yes" cases of the language and hence B is Turing recognizable.
(It's easier to see that A and B are complement to each other. TM can say "yes" for "yes" cases of B means it can say "no" for "no" cases of A.
But to make A Turing recognizable we need the output "yes" for "yes" cases of A, which is not the case here. )
(Once we prove that B is Turing recognizable but not Turing acceptable (recursive), there is no need to check for A. The complement of a
Turing recognizable but not Turing acceptable language is always not Turing recognizable.)
[1]: http://www.xamuel.com/dovetailing/
-- Arjun Suresh

L= {| L(M) = *}

top

L = {< M > L(M) = }


A. L is RE but L is not RE
B. Both L and L are RE
C. L is not RE but L is RE
D. Both L and L are not RE

Yes. Both L and L' are not RE. We can have the same reduction as done for L(M) is infinite.
Lets assume L is RE. So, we have a TM N which will say "yes" if given an encoding of a TM whose language is . Now using N we try to
solve non-halting problem as follows:
A non halting problem is given as follows: Given an encoding of TM <H> and a word w, whether H does not halt on w. That is, we have to
decide if H does not halt on w. This problem is proved to be not RE and so no TM can not even say "yes" for "yes" case of the problem.
Now, given a halting problem (<H>, w), we proceed as follows: We make a new TM say A, which on input x, just simulates H on w for |x|
steps. If H halts on w, A goes to reject state. Otherwise it accepts. So, L(A) = if H does not halt on w and L(A) = a finite set if H halts on
w. (If H halts in |x| steps for w, any string with length greater than |w|, would certainly be not in L, making L a finite set and hence can never
equal ).
Now, we just give the encoding of A to our assumed TM N. If N says "accept", we have that L(A) is => H does not halt on w => we solved
"yes" case of not halting problem, which is not possible. Hence, our initial assumption of L is RE is false. L is not RE.
Proving L' is not RE is easy.
L' = {<M> | L(M) is not equal to }
L(M) is not equal to is a non-monotonic property of TM. Because we can take TMTyes with L(Tyes ) = and Tno with L(Tno ) = . Here,
Tyes satisfies the property (of being not being equal to ) and Tno does not satisfy that property and L(Tyes ) L(Tno ), making this a nonmonotonic property of TM. And hence this becomes not RE as per Rice's theorem second part.
So, both L and L' are not RE making (D) the correct answer.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- gatecse

GATE2003_15 top
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 Regular
(b) L is context free but not necessarily Regular
(c) L is recursive but not necessarily Regular
(d) L is recursively enumerable but not necessarily Recursive

Answer is (c)- L is recursive but not necessarily Regular or not even context-free.
Since, the strings of L can be enumerated it means L is recursively enumerable. That is we have a TM which accepts all strings in L. Now, to
be recursive the TM should reject all strings not in L. Since, the strings of the language can be enumerated in lexicographic order, it's easy to
do this. For any word w , if we see a word in the enumeration which is lexicographically higher thanw but no w , it means w is not in the
language. This makes L '''recursive'''.
Now, why L need not be context free or regular? Consider

L = {an b n c n | n 0}
The strings of this language can be enumerated in lexicographic order. But we know L is not context free as no PDA can accept L.
-- Arjun Suresh

To say P=NP top


To say P=NP which one of the following is sufficient? (All reductions in polynomial time)
A. Reduction of a NP problem to a P problem
B. Reduction of a NP-complete problem to a P problem
C. Reduction of a P problem to an NP problem
D. Reduction of a P problem to an NP-complete problem

Option B is the most correct answer. (To know why it is not THE correct answer read the tail section of this answer)
The reasons are as follows.
A problem p in NP is NP-complete if every other problem in NP can be transformed intop in polynomial time. They have another property
that given a problem in NP and a solution, we can verify deterministically in polynomial time that the solution is indeed a valid solution or not.
P represents the class of all problems whose solution can be found in polynomial time.
Reduction of an NPC problem to a P problem would imply 2 things:
1) All problems in NP are reducible to this problem in P because all NP problems are reducible to NPC problems.
2) We can solve the NPC problem in polynomial time as well because we ca solve ther problem in P in polynomial time by definition of class
P.
This implies that all problems in NP are solvable in polynomial time. (1)
A problem which can be solved in polynoimial time is essential in P
Which implies P=NP (QED)
Tail
The statement of option B is incomplete. It is not enought to say that that reduction of NPC problem to a problem in P, but the reduction
should be polynomial reduction or karp reduction.
The statement which implies P=NP would be There exist a polynomial time reduction of a problem in NPC to a problem in P. The
answer is partially correct because when we say reduction, we usually mean polynomial time reduction, but neverthless it doesnt hurt to be
precise.
-- NitHish Divakar

Let L be a regular language

top

Let L be a regular language and w be a string in L . If w can be split into x, y and z such that |xy| number of states in the minimal DFA forL ,
and |y| > 0 then,
(A) i N, xy i z L
(B) i N, xy i z L
(C) i N, xy i z L
(D) i N, xy i z L

(C) i N, xy i z L
This is the result of Pumping Lemma for regular language
-- Keith Kr

Which of the following are useful in proving a language to be regular?


Which of the following are useful in proving a language to be regular?
1.
2.
3.
4.

Myhill-Nerode theorem
Pumping lemma
Drawing an NFA
Forming a regular expression

top

(A) All of these


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

(B)1, 3 and 4 only


As from the given options, Myhill-Nerode theorem is useful by providing necessary and sufficient condition for proving that a language regular.
Pumping lemma is often used to prove that a language is non-regular. Drawing an NFA can be useful to prove a language is regular. Forming
a regular expression can also help us prove if it is a regular language

-- Keith Kr

GATE2003_54 top
Define languages L0 and L1 as follows :

L0 = {< M, w, 0 > M halts on w}


L1 = {< 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 i is a bit.
Let L = L 0 L 1 . Which of the following is true ?
(A) L is recursively enumerable, but 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

Both L and L are undecidable and not even semi-decidable (not recursively-enumerable). Because halting problem can be solved with both
L and L.
Halting problem can be stated as follows: A machine M and a word w are given. You have to tell, if M halts on w .
So, to solve halting problem < M, w > using L , just give < M, w, 0 > and < M, w, 1 > to two instances of T which is the assumed Turing
machine for L . If T accepts the triplet < M, w, 0 > , it means M halts on w => we have solved halting problem. If T accepts the triplet
< M, w, 1 > , it means M doesn't halt on w => we have solved halting problem. We know that either< M, w, 0 > or < M, w, 1 > is in L. So,
i f L is recursively enumerable, T is bound to stop on at least one of these inputs T
( M for a recursively enumerable language stops and
accepts, when provided with a word in its language).
Hence, if L is recursively enumerable we can solve halting problem => L is not recursively enumerable.
Similarly, we can also show that halting problem can be solved with L .
Hence, neither L nor L is recursively enumerable.
-- gatecse

GATE1999_1.6

top

Let L1 be the set of all languages accepted by a PDA by final state and L2 the set of all languages accepted by empty stack. Which of the
following is true?
A) L1 = L2
B) L1 L2
C) L1 L2
D) None

There are two modes of acceptance of DPDA - final state and empty stack. For languages accepted by empty stack there is a prefix property.
Explain in simple terms about this property and its importance.

Answer to the question is (A) L1 = L2.


Reason is for any PDA which accepts by final state there is an equivalent PDA (equivalent means that accepts the same language) which
accepts by empty stack and vice-verse.
Now, this is not the case for DPDAs.
The set of languages accepted by a DPDA by empty stack is a strict subset of the set of languages accepted by a DPDA by final
state.
It can also be said that set of languages accepted by a DPDA by empty stack is the set of languages accepted by a DPDA by final state and
which has the prefix property.
A language has prefix property means if w L , then no prefix of w L .
From the above definition of prefix property it must be clear why DPDA by empty stack has this property. If any prefix of a word w (w in L) is in
L means the stack should have been empty even before completely processing w . But, being a deterministic PDA, once the stack becomes
empty, the DPDA accepts and halts. So, in no way can a DPDA accepts w and its prefix.
Good read: http://www.cs.ucr.edu/~jiang/cs150/slides4week7_PDA+EquivToCFG.pdf
-- gatecse

GATE2008_10 top
Which of the following are decidable?
I.
II.
III.
IV.

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

A.
B.
C.
D.

I and II
I and IV
II and III
II and IV

(1) Intersection of two regular languages is regular. And checking if a regular language is infinite is decidable.
(2) Undecidable
(3) Undecidable
(4) Decidable as we just have to check if the grammar obeys the rules of CFG. (Obviously undecidable had it been language instead of
grammar)
Reference: http://gatecse.in/wiki/Grammar:_Decidable_and_Undecidable_Problems
-- gatecse

GATE2008_13 top
are recursively enumerable then L is
If L and L
A.
B.
C.
D.

regular
context-free
context-sensitive
recursive

(D) recursive

is recursively enumerable means a T M accepts all strings in L


. So, we
L is recursively enumerable means a T M accepts all strings in L. L
can always decide if a string is in L or not, making L recursive.

http://books.google.co.in/books?
id=hsxDiWvVdBcC&pg=PA283&lpg=PA283&dq=if+l+and+l+are+recursively+enumerable+then+l+is+recursive&source=bl&ots=rdEqRfUndV&sig=1dglP3QL4
-- Keith Kr

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

(D) is correct answer


-- Keith Kr

GATE2008_52 top
Match the following NFAs with the regular expressions they correspond to

1. + 0(01 1 + 00) 01
2. + 0(10 1 + 00) 0
3. + 0(10 1 + 10) 1
4. + 0(10 1 + 10) 10

A.
B.
C.
D.

P-2, Q-1, R-3, S-4


P-1, Q-3, R-2, S-4
P-1, Q-2, R-3, S-4
P-3, Q-2, R-1, S-4

Correct Ans is (C)

Trace the given regular expressions with the diagrams


-- Keith Kr

GATE2008_53 top
Which of the following are regular sets?
I. {an b 2m n 0, m 0}
II. {an b m n = 2m }
III. {an b m n m}
IV. {xcy x, y, {a, b} }

A.
B.
C.
D.

I and IV only
I and III only
I only
IV only

Answer is A.
Since in option 2 and 3, n is dependent on m, therefore a comparison has to be done to evaluate those and hence are not regular.
I and IV are clearly regular sets.
-- Gate Keeda

GATE1991_03,xiii top

ans is A and C
to know the ans let us check all the option..
a) L(S) L(R) : string generated by S is any numbers of 1's followed by one 0 ,i.e 10,110,1110,1110,,,,. string generated by R is 1 followed by
any combination of 0 or 1,i.e 1,10,11,1110,101,110......
it shows that all the strings that can be generated by S ,can also be
generated by R it means L(S) L(R) is true.
L(S) L(T): here string generated by T is any numbers of 1(here 1* means we have strings as ,1,11,111,....) followed by only one 0,i.e
0,10,110,1110..... ..so we can see that all the strings that are present in S can also be generated by T,hence L(S) L ( T )
it shows that option A is true
b) L(R) L(S):it is false because string 1 which can be generated by L(R), cannot be generated by L(S)
C) same as option A
d)L(T) L(S): it is false because string 0 which can be generated by T,cannot be generated by L(S).

-- neha pawar

GATE1991_03,xiv top
03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:

(b), (c) and (d) are true. But the strongest answer would be (d) a regular language. It is trivial to say that a finite set of strings (finite language)
can be accepted using a finite set of states. And regular language context-free context-sensitive Turing recognizable, would imply that
regular language is the strongest answer.
-- gatecse

GATE1992_02,xvii

top

02. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
Which of the following regular expression identities is/are TRUE?
(a) r( ) = r
(b) (r s ) = (r + s)
(c) (r + s) = r + s
(d) r s = r + s

(a) is the answer


(b) RHS generates while LHS can't generate strings where r comes after s like sr, srr etc. LHS RHS.
(c) LHS generates while RHS can't generate strings where r comes after an s. RHS LHS.
(d) LHS contains all strings where after an s, no r comes. RHS contains all strings of either r or s but no combination of them. So, RHS
LHS.
-- Arjun Suresh

GATE2000_1.4

top

Let S and T be languages over = {a. b} represented by the regular expressions (a + b ) and (a + b) , respectively. Which of the following
is true?
(a) S T
(b) T S
(c) S = T
(d) S T =

(c) S = T . Both generates all strings over .


-- Arjun Suresh

GATE2000_1.5

top

Let L denote the languages generated by the grammar S 0S0 | 00.


Which of the following is TRUE?
A.
B.
C.
D.

L = 0+
L is regular but not 0+
L is context free but not regular
L is not context free

B. is the answer for this question


Language generated by this grammar is L = (00)^+ that is regular but not 0^+
-- Manu Thakur

GATE2001_1.4

top

Consider the following two statements:

S1 : {0 2n n 1} is a regular language
S2 : {0 m 1 n 0 m+n m 1 and n 1} is a regular language
Which of the following statement is correct?
(A) Only S1 is correct
(B) Only S2 is correct
(C) Both S1 and S2 are correct
(D) None of S1 and S2 is correct

Only s1 is correct a dfa with 2 states where one of the states is both the initial and final state..
-- Bhagirathi Nayak

GATE2001_1.5

top

Which of the following statements is true?


(A) If a language is context free it can always be accepted by a deterministic push-down automaton
(B) The union of two context free languages is context free
(C) The intersection of two contest free languages is a context free
(D) The complement of a context free language is a context free

Answer is (B)
(A) is wrong as a language can be context free even if it is being accepted by non deterministic PDA for ex- { WWr: W *(a,b) and Wr is
reverse}
(C) and (D) not always true as Context free languages are not closed under Complement and Intersection.
-- Prateeksha Keshari

GATE2001_2.5

top

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
(D) 48

Answer is D. It can be proved using Myhill Nerode theorem. We need a separate state for #a mod 6 = 0..5 and #b = 0..7. Each combination of
them must also be a new state giving 6*8 = 48 minimum states required in the DFA.
Reading Myhill-Nerode theorem might be confusing though it is actually very simple.
http://courses.cs.washington.edu/courses/cse322/05wi/handouts/MyhillNerode.pdf
-- Arjun Suresh

GATE2001_2.7

top

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 of q?
Which of the following statements about X is correct?
A.
B.
C.
D.

X is decidable
X is undecidable but partially decidable
X is undecidable and not even partially decidable
X is not a decision problem

X is undecidable but partially decidable.


We have the TM M. Just make the state q the final state and make all other final states non-final and get a new TM M'. Give input w to M'. If w
would have taken M to state q (yes case of the problem), our new TM M' would accept it. So, the given problem is partially decidable.
If M goes for an infinite loop and never reaches state q (no case for the problem), M' cannot output anything. This problem is the state entry
problem, which like word accepting problem and halting problem is undecidable.

-- Arjun Suresh

GATE2001_7

top

Let a decision problem X be defined as follows:

X : Given a Turing machine M over and any word w , does M loop forever on w ?
You may assume that the halting problem of Turing machine is undecidable but partially decidable.
(a) Show that X is undecidable
(b) Show that X is not even partially decidable

The question asks if M loop forever on w. If M loop forever on w, M wouldn't halt on w. And if M doesn't halt on w, M should loop forever. So,
this problem is exactly same as asking if "M doesn't halt on w", which is the complement of halting problem and is not even partially decidable.
So, X is not even partially decidable.
-- Arjun Suresh

GATE2002_2.14 top
Which of the following is true?

A. The complement of a recursive language is recursive


B. The complement of a recursively enumerable language is 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

Complement of recursive language is always recursive


-- Bhagirathi Nayak

GATE2002_21 top
We require a four state automaton to recognize the regular expression (a/b)*abb
a. Give an NFA for this purpose
b. Give a DFA for this purpose

NFA for regular expression (a+b)*abb and its equivalent DFA will be as follow:

-- Praveen Saini

GATE2003_13 top
Nobody knows yet if P=NP. Consider the language L defined as follows.

L = { (0 + 1)

if P = NP
otherwise

Which of the following statements is true?


(A) L is recursive
(B) L is recursively enumerable but not recursive
(C) L is not recursively enumerable
(D) Whether L is recursively enumerable or not will be known after we find out ifP = NP

(A) L is recursive. If P = NP , L is which is recursive (in fact regular). If not, L = which is again recursive. So, in both casesL is
recursive.
-- Arjun Suresh

GATE2003_14 top
The regular expression 0 (10 ) denotes the same set as
(A) (1 0) 1
(B) 0 + (0 + 10)
(C) (0 + 1) 10(0 + 1)
(D) None of the above

(A) is the answer. Both (A) and the given expression generates all strings over .
(B) doesn't generate 11
(C) doesn't generate 11
-- Arjun Suresh

GATE2003_50 top
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
A.
B.
C.
D.

1
5
7
8

Language of above DFA is all strings over {0,1} that contain substring 001.
Regular expression of above DFA is (0+1)*001(0+1)*
1 that is underlined can not be first bit of 7-bit binary no, but can be fourth bit or last bit.
Case 1: if it is 4th bit ,then possible set of strings can be
First 001 twobits Last = 1 001(00+01+10+11)1 = 4 strings
Case 2 : if it is last bit, then possible set of strings can be
First twobits fourth 001 = 1(00+01+10+11)1 001 = 4 strings
String common in both cases 1001001
Total strings = 4 + 4 - 1 = 7 strings
-- Praveen Saini

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

q1, 1, R
q0, 1, L

Halt
q0, 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 page square, then it writes 1 on the same
tape square, moves its tape head one position to the right and transitions to state q1.
Which of the following statements is true about M?
A.
B.
C.
D.

M does not halt on any string in (0 + 1)+


M does not halt on any string in (00 + 1)
M halts on all strings ending in a 0
M halts on all strings ending in a 1

option A. or epsilon is only accepted i.e tape contain B as the first character
-- Supromit Roy

GATE2003_55 top
Consider the NFA M shown below.

Let the language accepted by M be L. Let L 1 be the language accepted by the NFA M 1 obtained by changing the accepting state of M to a nonaccepting state and by changing the non-accepting states of M to accepting states. Which of the following statements is true?
A.
B.
C.
D.

L1
L1
L1
L1

= {0, 1} L
= {0, 1}
L
=L

L= (0+1)^+ while L1= (0+1)^* So Ans is B


-- Abhishek Kumar

GATE2006_19 top
Let

L1 = {0 n+m 1 n 0 m n, m 0 } ,
L2 = {0 n+m 1 n+m 0 m n, m 0} and
L3 = {0 n+m 1 n+m 0 n+m n, m 0} .
Which of these languages are NOT context free?
(A) L1 only
(B) L3 only
(C) L1 and L2
(D) L2 and L3

L1 is context-free. We count the number of 0's and check if the remaining number of 1's followed by 0's count to the initial number of 0's.
L2 is not context-free. Here the number of 0's and the following 1's must be same, which can be checked using a PDA. But after that we must
also ensure that the following number of 0's must be less than the previous count of 0's and 1's (otherwise n < 0, which violates the condition
for acceptance) and we cannot do these two checks using a single PDA.
L3 is again not context-free as it is nothing but equal number of 0's followed by equal number of 1's followed by equal number of 0's.
-- Arjun Suresh

GATE2006_29 top
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) n 0 (s) is a 3-digit prime }
(B) L = {s (0 + 1) for every prefix s' of s, n 0 (s ) n 1 (s ) 2}
(C) L = {s (0 + 1) n 0 (s) n 1 (s) 4}
(D) L = {s (0 + 1) n 0 (s) mod 7 = n 1 (s) mod 5 = 0}

A. There are only finite 3 digit primes. And any finite set is regular
B. Here we need just 6 states to recognise L.
1.
2.
3.
4.
5.

#0 - #1 = 0
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = -1
#0 - #1 = -2

If the difference goes above 2 or below -2, we go to a dead state. All other states are accepting. This transition to dead state is possible
because of the words "for every prefix s' of s" in L and that is what makes this language regular.
C. L is not regular
#0 - #1 = 1
#0 - #1 = 2
#0 - #1 = 3
#0 - #1 = 4
#0 - #1 = 5
.....
#0 - #1 = 1000
......
All these forms distinct equivalent classes under Myhill-Nerode theorem meaning from the strings in each of these sets, we can append a
string which will take the new string to L, while the same string appended to string in any other set won't reach L.
For example, for 000000, we append 11, for 0000000, we append 111 etc. So, in short we need to maintain the count of 1's and 0's and the
count here is not finite.
D. This is regular. We need a finite automata with 5 * 7 = 35 states for maintaining the counts of 0's mod 7 and 1's mod 5.
-- Arjun Suresh

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

Refer this
http://gateoverflow.in/1695/gate1998_4
L1 = { s(0+1)* d(s) mod 5=2 } is regular
having 2 as final state out of {0,1,2,3,4} states
as given in example in posted link [in same DFA , final state will be 2 instead of 0 ]
similarly L2 = ( s(0+1)* d(s) mod 74 } is also regular
having states {0,1,2,3,4,5,6} and all are final state except 4
L1 L2 is L (given problem ) is also regular
As regular languages are closed under intersection. D is correct option.
-- Praveen Saini

GATE2006_33 top
Let L1 be a 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)
(B)
(C)
(D)

is a deterministic CFL
is recursive
is context free
is recursively enumerable

A) True : DCFL are closed under Intersection with Regular Languages


C) True : L1 is regular hence also CFL and every DCFL is also CFL and All CFL are closed under Union.
D) True : L1 is regular hence also RE; L2 is DCFL hence also RE; RE languages are closed under Intersection
B) False : L1 is recursive hence also decidable, L3 is RE but not Recursive hence it is undecidable. Intersection of Recursive language and
Recursive Enumerable language is Recursive Enumerable language.
-- Danish

GATE2004_87 top
The language {am b n c m+n m, n 1} is

A. regular
B. context-free but not regular
C. context-sensitive but not context free
D. type-0 but not context sensitive

Language is not regular bcoz we need to match count of c's is equal to count of b's + count of a's
and that can implement by PDA
(q0,a,^)= (q0,a)

[ push a in stack, as per language a comes first]

(q0,a,a)= (q0,aa)

[push all a's into stack]

(q0,b,a) = (q1,ba) [push b in stack, state change to q1 that sure b comes after a]
(q1,b,b)=(q1,bb) [push all b's in stack]
(q1,c,b) = (q2,^) [ pop one b for one c]
(q2,c,b) = (q2,c) [ pop one b's for each c and continue same ]
(q2,c,a) = (q3,^) [ pop one a for one c , when there is no more b in stack]
(q3,c,a) = (q3,^) [pop one a for each c and continue same]
(q3,^,^) = (qf,^)

[ if sum of c's is sum of a's and b's then stack will be empty when there is no c in input]

so language is context- free but not regular.


Note :1. state changes make sure b's comes after a and c's comes after b's]
-- Praveen Saini

find minimal dfa for L

top

L = {an b : n 0} {b n a : n 1}

6 states are required.

-- gatecse

GATE2007_6

top

Which of the following problems is undecidable?


A.
B.
C.
D.

Membership problem for CFGs


Ambiguity problem for CFGs
Finiteness problem for FSAs
Equivalence problem for FSAs

Membership problem is decidable as it can be solved by parsers.


Finiteness problem is decidable for FSAs (also for CFGs), as we just need to check for a loop in the DFA.
Equivalence problem for FSAs is decidable as we can take the complement of one FSA (complement of FSA is another FSA), and do an
intersection with the other (FSAs are closed under intersection also), giving a new FSA. If this new FSA accept no string, then the given FSAs
are equivalent, else not equivalent.
Only ambiguity problem for CFGs are undecidable.
http://gatecse.in/wiki/Grammar:_Decidable_and_Undecidable_Problems
-- Arjun Suresh

GATE2007_7

top

Which of the following is TRUE?


A.
B.
C.
D.

Every subset of a regular set is regular


Every finite subset of a non-regular set is regular
The union of two non-regular sets is not regular
Infinite union of finite sets is regular

(B) Every finite subset of a non-regular set is regular.


Any finite set is always regular.

being regular any non regular language is a subset of this, and hence (A) is false.
If we take a CFL which is not regular, and takes union with its complement (complement of a CFL which is not regular won't be regular as
regular is closed under complement), we get which is regular. So, (C) is false.
Regular set is not closed under infinite union. Example:
Let L i = {0i1i }, i N
Now, if we take infinite union over all i, we get
L = {0i1i | i N}, which is not regular.
So, D is false.
-- Omesh Pandita

GATE2007_29 top
A

minimum

state

deterministic

finite

automaton

L = {w w {0, 1} , number of 0s and 1s in w are divisible by 3 and 5, respectively} has

A.
B.
C.
D.

accepting

15 states
11 states
10 states
9 states

Answer will be (A) 15 states.


We need a separate state for #0 = 0, 1, 2 and #1 = 0, 1, 2, 3, 4 giving total minimum number of states = 3 * 5 = 15.
This is a direct consequence of Myhill-Nerode theorem.
http://courses.cs.washington.edu/courses/cse322/05wi/handouts/MyhillNerode.pdf
-- Arjun Suresh

GATE2007_30 top
The language L = {0 i 21i i 0} over the alphabet {0, 1, 2} is:

A. not recursive
B. is recursive and is a deterministic CFL
C. is a regular language
D. is not a deterministic CFL but a CFL

the

language

The answer is B.
-- Gate Keeda

GATE2007_31 top
Which of the following languages is regular?

A. {ww R w {0, 1} + }
B. {ww R x x, w {0, 1} + }
C. {wxw R x, w {0, 1} + }
D. {xww R x, w {0, 1} + }

A. CFL
B. CFL
C. Regular, language is string stating and ending with same symbol and having length at least 3. e.g. 0x0 or 1x1
D. CFL
http://gatecse.in/wiki/Identify_the_class_of_the_language
-- Vikrant Singh

GATE2007_74,75 top
Common data for Questions 74, 75:
Consider the following Finite State Automaton:

74. The language accepted by this automaton is given by the regular expression

A. b ab ab ab
B. (a + b)
C. b a(a + b)
D. b ab ab

75. The minimum state automaton equivalent to the above FSA has the following number of states

A.
B.
C.
D.

1
2
3
4

The answer for 74 is C.


You can see that both the states, Q1 and Q2 are final and are accepting (a+b)*.
75 its B.
The state Q3 is redundant as it is not reachable. And the Regular expression b*a(a+b)* can be made with two states.
Q1-->b-->Q1
Q1-->a-->Q2
Q2-->a-->Q2
Q2-->b-->Q2.
Clearly there are 2 states.
-- Gate Keeda

GATE2006_34 top
Consider the regular language L = (111 + 11111) . The minimum number of states in any DFA accepting this languages is:
(A) 3
(B) 5
(C) 8
(D) 9

there will be 9 states. with 1st,4th,6th,7th and 9th state being the final states. with a loop on the ninth state.
{0,3,5,6,8,9,10,11,12,........}this is the set which will be accepted by the min dfa for this expression.

-- Gate Keeda

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

ans is B..string generated by this language is a,b,aba,bab,aabaa,.....all this strings are odd length palindromes
-- neha pawar

GATE2009_16 top
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.

Option d ndpa is more powerful than dpda so they are not equivalent..actually dpda is a proper subset of ndpa...
C is TRUE as CFL is a proper subset of recursive languages and recursive languages are closed under complement.
-- Bhagirathi Nayak

GATE2009_40 top
Let L = L 1 L 2 , where L 1 and L 2 are languages as defined below:

L1 = {am b m can b m m, n 0}
L2 = {ai b j c k i, j, k 0}
Then L is
A.
B.
C.
D.

Not recursive
Regular
Context free but not regular
Recursively enumerable but not context free.

L1 = {c, abcb, abcab, aabbcbb, ...}


L2 = {, a, b, c, ab, ac, bc, abc, ...}
So, L1 L2 = {c} which is Regular.
-- Arjun Suresh

GATE2009_41 top

The above DFA accepts the set of all strings over {0,1} that

A. begin either with 0 or 1.


B. end with 0.
C. end with 00.
D. contain the substring 00.

A) begin either with 0 or 1


Regular expression (0+1)(0+1)*

[begin with 0 or 1 Anything ]

b) end with 0
[Anything end with 0 ]

regular expression = (0+1)*0


NFA

Equivalent DFA

c) end with 00
regular expression (0+1)*00

[Anything end with 00 ]

NFA

Equivalent DFA

d) containing the substring


regular expression = (0+1)*00(0+1)*

[Anything substring 00 Anything ]

NFA

Equivalent DFA

So C is the correct answer


-- Praveen Saini

GATE2005_55 top
Consider the languages:

L1 = {an b n c m n, m > 0} and L2 = {an b m c m n, m > 0}


Which one of the following statements is FALSE?

A. L 1 L 2 is a context-free language
B. L 1 L 2 is a context-free language
C. L 1 and L 2 are context-free languages
D. L 1 L 2 is a context sensitive language

L1 is CFL [ put a's in stack , and pop a with each b]]


L2 is CFL [put b's in stack and pop b with each c ]
c) is True.
b) is True CFL is closed under Union

[ S-> S1 | S2

where S1 is grammar for L1 and S2 for L2]

CFL is not closed under Intersection, so intersection of two CFLs may or may not be CFL. Lets examine:
L1 L2 = { aibici , i>0 } which is Context sensitive but not context free [can't match a's,b's and c's with one stack]
So a) is False
d) is True
-- Praveen Saini

GATE2005_56 top
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?
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

L1 being recursive, we have a TM M for L1 which accepts all words in L1 and rejects all words in L1'. So, this TM also works for L1' by changing
the accept and reject states. Thus L1' is recursive.
L2 being recursively enumerable but not recursive means TM for L2 can accept all words in L2 but cannot reject all words not in L2 => TM for
L2' cannot exist (as otherwise TM for L2 could simulate the moves of that TM to reject words in L2')=> L2' is not recursively enumerable. So,
(B).
-- Arjun Suresh

GATE2005_57 top
Consider the languages:

L1 = {ww R w {0, 1} }
L2 = {w#w R w {0, 1} } , where # is a special symbol
L3 = {ww w {0, 1} }
Which one of the following is TRUE?

A. L 1 is a deterministic CFL
B. L 2 is a deterministic CFL
C. L 3 is a CFL, but not a deterministic CFL
D. L 3 is a deterministic CFL

B. http://gatecse.in/wiki/Identify_the_class_of_the_language
-- Gate Keeda

GATE2005_63 top

The following diagram represents a finite state machine which takes as input a binary number from the least significant bit.

Which 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

for any binary no, FSM read input from LSB and remain unchanged till first 1, and it complement after that
100 -> 100

[1's complement of 100 + 1 = 011+ 1 = 100 = 2's complement of 100]

010 -> 110

[1's complement of 010 + 1 = 101 + 1 = 110 = 2's complement of 010]

1010100 -> 0101100

[ 1's complement of 1010100 + 1 = 0101011+ 1 = 0101100 ]

Note : Underline part is unchanged (till first 1 from lsb) then 0's changed to 1's and 1's changed to 0's

-- Praveen Saini

GATE2013_8

top

Consider the languages L 1 = and L 2 = a. Which one of the following represents L 1 L 2 L 1 ?


(A) {}
(B)
(C) a
(D) {, a}

L1.anything is empty language and empty union empty* is epsilon hence a


-- kireeti

GATE1999_1.5

top

Cfl are not closed under intersection and complement now choose the correct option so b)union and klenne closure
-- Bhagirathi Nayak

GATE1999_7

top

Show that the language

L = {xcx x {0, 1} and c is a terminal symbol}


is not context free. c is not 0 or 1 .

language contains strings where sub string on left of c is same as that on right of c
say 01100c01100
sub string on left of c and right of c cannot be matched with one Stack
while that can be done using two stack
if we push all 0's and 1's on left of c in stack 1 , and all 0's and 1' on right of c in stack 2
then Top of stack of both stack will have same symbol .. that can be matched
-- Praveen Saini

GATE2013_32 top
Consider the following languages.

L1 = {0 p 1 q 0 r p, q, r 0}
L2 = {0 p 1 q 0 r p, q, r 0, p r}
Which one of the following statements is FALSE?
(A) L 2 is context-free.
(B) L 1 L 2 is context-free.
(C) Complement of L 2 is recursive.
(D) Complement of L 1 is context-free but not regular.

L1 is regular and hence context-free also. Regular expression for L1 is 0*1*0*. So, (D) is the false choice.
L2 is context-free but not regular. We need a stack to count if the number of 0's before and after the 1 (1 may be absent also) are not same.
(L2 is but not deterministic context-free)
So, L1 L2 is context-free as regular context-free is context-free. -> (B) is true.
Complement of L2 is recursive as context-free complement is always recursive (actually even context-sensitive).

-- Arjun Suresh

GATE2013_33 top
Consider the DFA A given below.

Which of the following are FALSE?


1.
2.
3.
4.

Complement of L(A) is context-free.

L(A) = L((11 0 + 0)(0 + 1) 0 1 )

For the language accepted by A, A is the minimal DFA.


A accepts all strings over {0, 1} of length at least 2.

(A) 1 and 3 only


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

1. Complement of L(A) (regular language) is regular , i.e also Context Free . True
2. Regular expression is (11*0 +0)(0+1)* True
3 . Minimized DFA is

[both non-final states are equivalents can be minimized]

So 3 is False

4. From 3, shortest length string reached from q0 to q1(final) is 0, so 4 is false

Note : a) (0+1)*0*1* = (0+1)* +something =(0+1)*


b) (11*0+0)(0+1)* = (11*+ ^)0(0+1)* =1*0(0+1)* look at Minimized DFA at 3.

-- Praveen Saini

GATE2013_41 top
Which of the following is/are undecidable?
1.
2.
3.
4.

G is a CFG. Is L(G) = ?
G is a CFG. Is L(G) = ?
M is a Turing machine. Is L(M) regular?
A is a DFA and N is an NFA. Is L(A) = L(N)?

(A) 3 only

(B) 3 and 4 only

(C) 1, 2 and 3 only

It will be D.
First is Emptiness for CFG.
Second is everything for CFG.
Third is Regularity for REC
Fourth is equivalence for regular.
-- Gate Keeda

GATE1998_1.9

top

(D) 2 and 3 only

If the regular set A is represented by A = (01 + 1) and the regular set B is represented by B = ((01) 1 ) , which of the following is true?
(a) A B
(b) B A
(c) A and B are incomparable
(d) A = B

(d) A = B. Both generates all strings over {0, 1} where a 0 is immediately followed by a 1.
-- Arjun Suresh

GATE1998_1.10 top

Option A is correct
A. is regular
L = {1, 10, 100, 1000, 10000, ....... }
regular expression 10*
DFA :

B . L = {1,11,1111,11111111, .... }= {1i | i =2 n , n>=0 } is non regular language


C. Equal- Equal , is CFL , and non regular
D, L = { 1 i01 i , i>0

1 } is also CFL, and non regular

-- Praveen Saini

GATE1998_1.11 top

Ans B
-- Keith Kr

GATE1998_1.12 top
The string 1101 does not belong to the set represented by
(a) 110*(0 + 1)
(b) 1(0 + 1)*101
(c) (10)*(01)*(00 + 11)*
(d) (00 + (11)*0)*

Only (a) and (b) can generate 1101.


In (c) after 11, we can not have 01 and so 1101 cannot be generated.
In (d) Every 11 followed by some 0. So it cannot generate 1101 or 11011.
-- Arjun Suresh

GATE1998_2.5

top

Let L be the set of all binary strings whose last two symbols are the same. The number of states in the minimal state deterministic finite state
automaton accepting L is
A.
B.
C.
D.

2
5
8
3

binary strings whose last two symbols are same


regular expression = (0+1)*(00+11)
Having NFA

Equivalent DFA

Total no of states = 5
-- Praveen Saini

GATE1998_4

top

suppose we have decimal no 3 after that we get a symbol 2 . it becomes 32 as 3 x 10 +2 = 32


in binary if we have 10 ( i.e 2 in decimal say old no) and after that we get symbol 1 it become 101( i.e 5 in decimal say new no )
2 (old no.) x 2( base) +1( input symbol) = 5 (new no.)
Now in the given problem , binary no is divisible by 5 , i.e 0,101,1010,1111.....
We need 5 states in DFA , 0,1,2,3 and 4 .Each state represent remainder that comes when we divide no by 5.
input symbol = {0,1}
We get the transition
[Old state x base + input symbol] mod 5 = New state

, where base is 2

[0 x 2 + 0]mod 5 = 0

[1 x 2 + 0]mod 5 = 2

[2 x 2 + 0]mod 5 = 4

[0 x 2 + 1]mod 5 = 1

[1 x 2 + 1]mod 5 = 3

[2 x 2 + 1]mod 5 = 0

[3 x 2 + 0]mod 5 = 1

[4 x 2 + 0]mod 5 = 3

[3 x 2 + 1]mod 5 = 2

[4 x 2 + 1]mod 5 = 4

-- Praveen Saini

GATE2014-1_15 top
Which one of the following is TRUE?

(A) The language L = {an b n n 0} is regular.


(B) The language L = {an n is prime } is regular.
(C) The language L = {w w has 3k + 1 b s for some k N with = {a, b}} is regular.
(D) The language L = {ww w with = {0, 1}} is regular.

(A) is CFL and (B) and (D) are CSL. (C) is regular and regular expression for (C) would be

a b(a ba ba b)+ a
-- Arjun Suresh

GATE2014-1_16 top
Consider the finite automaton in the following figure:

What is the set of reachable states for the input string 0011?
(A) {q 0 , q 1 , q 2 }
(B) {q 0 , q 1 }
(C) {q 0 , q 1 , q 2 , q 3 }
(D) {q 3 }

q0, q1 and q2 are reachable from q0 on input 0011

-- Praveen Saini

GATE2014-1_35 top
Let L be a language and

be its complement. Which one of the following is NOT a viable possibility?


L

is recursively enumerable (r. e. ).


(A) Neither L nor L
is r.e. but not recursive; the other is not r.e.
(B) One of L and L
are r.e. but not recursive.
(C) Both L and L
are recursive.
(D) Both L and L

(C) is not possible. If L is re we have a TM that accepts string in L. If L' is re, we have a TM that accepts strings in L'. So, using both these
TMs we can make a new TM M which accepts strings in L and rejects strings in L' - that is M decides L, making L recursive.
-- Arjun Suresh

GATE2014-1_36 top
Which of the regular expressions given below represent the following DFA?

I. 0 1(1 + 00 1)
II. 0 1 1 + 11 0 1
III. (0 + 1) 1

(A) I and II only


(B) I and III only
(C) II and III only
(D) I, II and III

(B) is the answer. (II) doesn't generate 11011 which is accepted by the given DFA
-- Arjun Suresh

GATE2014-2_15 top
If L 1 = {an n 0} and L 2 = {b n n 0} , consider
(I) L 1 . L 2 is a regular language
(II) L 1 . L 2 = {an b n n 0}
Which one of the following is CORRECT?
(A) Only (I)
(B) Only (II)
(C) Both (I) and (II)
(D) Neither (I) nor (II)

Option A
L1= {, a, aa, aaa, aaaa, ........................}
L2= {, b, bb, bbb, bbbb, ........................}
L1.L2 = {, a, b, ab, abb, abbb, abbbb,..........,aab, aabb, aabbb, ................} = a*b*

This is regular language and not equal to anbn

-- Viral Kapoor

GATE2014-2_16 top
Let A

m B denotes that language A is mapping reducible (also known as many-to-one reducible) to language B. Which one of the following is FALSE?
(A) If A

m B and B is recursive then A is recursive.

(B) If A

m B and A is undecidable then B is undecidable.

(C) If A

m B and B is recursively enumerable then A is recursively enumerable.

(D) If A

m B and B is not recursively enumerable then A is not recursively enumerable.

A m B means A cannot be harder than B. (Since A can be reduced to B, instead of deciding A, we can now decide B)
So, the first 3 options are correct. Option (D) is false, as B is not recursively enumerable doesn't guarantee A is not recursively enumerable.
-- Arjun Suresh

GATE2014-2_35 top
Let < M > be the encoding of a Turing machine as a string over = {0, 1} . Let

L = {< M > M is a Turing machine that accepts a string of length 2014 }


. Then L is
(A) decidable and recursively enumerable
(B) undecidable but recursively enumerable
(C) undecidable and not recursively enumerable
(D) decidable but not recursively enumerable

There are only a finite number of strings of length 2014. So, we can give all those strings to TM simulating each string for 1 step, then 2 step
and so on (dovetailing), and if the TM accepts any of them ("yes" case of TM), we can say "yes". So, L is recursively enumerable.
(If the TM doesn't accept any string of length 2014, it can go to an infinite loop ("no" case of TM), and hence we can't say the method is
decidable).
Now, to prove whether the problem is decidable or not we can make use of Rice's theorem. Rice's theorem (I) states that any non-trivial
property of L(TM) is undecidable. L(TM) has a string of length 2014 is a non-trivial property as there are TMs whose language contains such a
string and there are TMs whose language doesn't have such a string. So, the given problem is undecidable.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- Arjun Suresh

GATE2014-2_36 top
L

t L1

= {w {0, 1} w has at least as many occurrences of (110) s as (011) s} .

L2 = {w {0, 1} w has at least as many occurrences of (000) s as(111) s} . Which one of the following is TRUE?

Let

(A)

L1 is regular but not L2

(B)

L2 is regular but not L1

(C) Both L 1 and L 2 are regular


(D) Neither L 1 nor L 2 are regular

(A) is True. Though at first look both L1 and L2 looks non-regular, L1 is in fact regular. The reason is the relation between 110 and 011.
We cannot have two 110's in a string without a 011 or vice verse. And this would mean that we only need a finite number of states to check for
acceptance of any word in this language.
That was just an intuitive explanation. Now I say that L contains all binary strings starting with 11. Yes, if a binary string starts with 11, it can
never have more no. of 011 than 110.
Lets take an example:
11 011 011 -There are two 011's. But there are also two 110's. Similarly for any binary string starting with 11.
Using this property, DFA for L1 can be constructed as follows:

-- gatecse

GATE2014-3_15 top
The length of the shortest string NOT in the language (over = {a, b}) of the following regular expression is _______.

a b (ba) a

R = a*b*(ba)*a*
for finding shortest string that is not in language it is better to look strings of length 0, then of length 2 and soon
length0 { } is in L
length1 {a, b}

all belong to L

length2 {aa, ab, ba, bb}

all belong to L

length 3 {aaa, aab, aba, abb, baa, bab, bba, bbb} bab does not belong to L
-- Praveen Saini

GATE2014-3_36 top
Consider the following languages over the alphabet = {0, 1, c}

L1 = {0 n 1 n n 0}
L2 = {wcw r w {0, 1} }
L3 = {ww r w {0, 1} }
Here, w r is the reverse of the string w . Which of these languages are deterministic Context-free languages?
(A) None of the languages
(B) Only L 1

(C) Only L 1 and L 2


(D) All the three languages

C.
L3 is CFL and not DCFL as in no way we can deterministically determine the MIDDLE point of the input string.
-- Gate Keeda

GATE2011_42 top
Definition of a language L with alphabet {a} is given as following.

L = {ank k > 0, and n is a positive integer constant}


What is the minimum number of states needed in a DFA to recognizeL ?
(A) k + 1
(B)

n+1

(C) 2 n+1
(D) 2 k+1

(A) n+1
We need a state for strings of length 0, 1, 2, ... n (and their respective multiples with k). Each of these set of strings form an equivalence class
as per Myhill-Nerode theorem and hence needs a separate state in min-DFA.
-- Arjun Suresh

GATE2011_45 top
A deterministic finite automaton (DFA )

D with alphabet = {a, b} is given below.

Which of the following finite state machines is a valid minimal


(A)

(B)

(C)

DFA which accepts the same languages as D ?

(D)

(A) is the answer.


In (B) and (C) when the first letter of input is 'b' we reach final state, while in the given DFA first letter 'b' is not a final state. So, (B) and (C) are
not accepting same language as the given DFA.
In (D) we can reach final state when the last letter is 'a', whatever be the previous transitions. But in the given DFA, when the first 2 letters are
'b' we can never reach the final state. So, (D) is also accepting a different language than the given DFA.
-- Arjun Suresh

GATE2012_46 top
Consider the set of strings on {0, 1} in which, every substring of 3 symbols has at most two zeros. For example, 001110 and 011001 are in the
language, but 100010 is not. All strings of length less than 3 are also in the language. A partially completed DFA that accepts this language is
shown below.

The missing arcs in the DFA are

(A)

00

00

01

10

01
10

11

1
0

11

(B)
00

01

00

01

10
11

10

11

0
0

(C)
00

01

00

01

10

11

10

11

(D)
00

00

01

10

01
10

11

1
0

11

(D) is the answer. From 00 state, a '0' should take the DFA to the dead state-q. From 11, a '0' should go to 00 representing the 00 at the end
of string so far. Similarly, from 00 a 1 should go to 01, from 01 a '1' should go to 11 and from 10 a '0' should go to '00'.
-- Arjun Suresh

GATE2010_17 top
Let L 1 be the recursive language. Let L 2 and L 3 be languages that are recursively enumerable but not recursive. Which of the following statements is not
necessarily true?
(A)

L2 L1 is recursively enumerable.

(B)

L1 L3 is recursively enumerable.

(C) L 2

L3 is recursively enumerable.

(D) L 2

L3 is recursively enumerable.

Recursively enumerable languages are closed under union and intersection. So, lets consider each option
(A) L 2 L 1 = L 2 L1
Recursive languages are closed under complement, and so L1 is recursive and hence recursively enumerable also. So, L 2 L1 is recursively
enumerable is always TRUE.
(B) L 1 L 3 = L 1 L3
Recursively enumerable languages are not closed under complement. So, L3 may or may not be recursively enumerable and hence we can't
say anything if L 1 L3 is recursively enumerable or not.
(C) Intersection of two recursively enumerable languages is always recursively enumerable(RE closed under intersection).
(D) Union of two recursively enumerable languages is always recursively enumerable(RE closed under union).
For verifying closure properties:
http://gatecse.in/wiki/Closure_Property_of_Language_Families
-- Arjun Suresh

GATE1997_3.4

top

Given = {a, b} , which one of the following sets is not countable?

(a) Set of all strings over


(b) Set of all languages over
(c) Set of all regular languages over
(d) Set of all languages over accepted by Turing machines

(b) Set of all languages over is uncountable.


Ref:
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-045j-automata-computability-and-complexity-spring2011/lecture-notes/MIT6_045JS11_lec05.pdf
-- Arjun Suresh

GATE1997_6.4

top

Which one of the following regular expressions over {0, 1} denotes the set of all strings not containing100 as substring?
(a) 0 (1 + 0)
(b) 0 1010
(c) 0 1 01
(d) 0 (10 + 1)

"A regular expression denoting a language (set of strings) means it should generate all string in L and not generate any string not
in L"
(a) - generates 100
(b) doesn't generate 0 (start trying strings in lexicographic order- 0, 1, 00, 01, 10,...)
(c) doesn't generate 1
(d) is the answer
-- Arjun Suresh

GATE1997_6.5

top

Equivalence of two TMs is undecidable


-- Bhagirathi Nayak

GATE1997_6.6

top

Which of the following languages over {a, b, c} is accepted by a deterministic pushdown automata?
(A) {wcw R w {a, b} }
(B) {ww R w {a, b, c} }
(C) {an b n c n n 0}
(D) {w w is a palindrome over {a, b, c}}
Note: w R is the string obtained by reversing w .

A. rest cannot be accepted by a DPDA.


-- Gate Keeda

GATE1997_20 top
Construct a finite state machine with minimum number of states, accepting all strings over (a,b) such that the number of a's is divisible by two
and the number of b's is divisible by three.

A state qxy means namod2 =x , nbmod3=y


q00 means namod2 =0 , nbmod3=0 [no of a's is divisible of 2 and no of b's are divisible of 3]
q00 x a q10
q00 x b q01 and so on

-- Praveen Saini

GATE1997_21 top
Given that L is a language accepted by a finite state machine, show that L P and L R are also accepted by some finite state machines, where

LP = {s ss L some string s }
LR = {s s obtained by reversing some string in L}

Suppose we have a finite automation for L , then we can build a finite automation for L P by marking all the states from which final state is
reachable as the final states for new automaton, the reasoning is that suppose we can reach final state f form some state q, then that means
there exists some string s' that takes automation from q to f, so if there is some string s that takes automation to state q from start state this
string should belong to the new language L P .
Also, we can obtain an automation for L R by swapping the start and final states of original automationL and by reversing all the edges in the
DFA.
-- Omesh Pandita

GATE1993_27 top
Draw the state transition of a deterministic finite state automaton which accepts all strings from the alphabet {a, b} , such that no string has 3
consecutive occurrences of the letter b.

Design a DFA that accepts all strings contain bbb

regular expression (a+b)*bbb(a+b)*


then take complement of DFA such that no string has 3 consecutive occurrences of the letter b.

having regular expression (a+ba+bba)*(^ + b+ bb)

-- Praveen Saini

GATE2010_39 top
Let L

= {w (0 + 1) w has even number of 1s} . i.e., L is the set of all the bit strings with even numbers of 1 s. Which one of the regular expressions

below represents L ?
(A)

(0 10 1)

(B) 0 ( 10 10 )
(C) 0 ( 10 1) 0
(D) 0 1( 10 1) 10

(A) - If the string contains a 1, it must end in a 1 hence cannot generate all bit strings with even number of 1's (eg, 1010)
(B) - is the answer
(C) - between the second and third 1's a 0 is not allowed (eg, 011011)
(D) - 00 is not allowed, zero is an even number.
-- Arjun Suresh

GATE2010_40 top
Consider the languages

L1 = {0 i 1 j i j},
L2 = {0 i 1 j i = j},
L3 = {0 i 1 j i = 2j + 1},
L4 = {0 i 1 j i 2j}

(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

All are context free.


L1 -> Push 0 on stack and when 1 comes, start popping. If stack becomes empty and 1's are remaining start pushing 1. At end of string
accept if stack is non- empty.
L2 -> Do the same as for L1, but accept if stack is empty at end of string.

L3 -> Do, the same as for L2, but for each 0, push two 0's on stack and start the stack with a 0.
L4 -> Do the same as for L1, but for each 0, push two 0's on stack
All are in fact DCFL. Pushing two 0's on stack might sound non-trivial but we can do this by pushing one symbol and going to a new state.
Then on this new state on empty symbol, push one more symbol on stack and come back.
-- Arjun Suresh

GATE2010_41 top
Let w be the any string of length
that accepts L ?
(A)

n1

(B)

n in {0, 1} . Let L be the set of all substrings of w . What is the minimum number of states in non-deterministic finite automation

(C) n + 1
(D) 2 n1

We need a state for counting the length. So, for length n we need n+1 states (one for length zero). We don't need a reject state for larger
strings as we have NFA and not DFA. So, totally n+1 states are required. (For DFA it would be n+2).
-- Arjun Suresh

Toc theorem proof

top

How = ?

= {} , which is empty set. Now by definition of *, it repeats the content of a set ZERO or more times. And anything repeated zero time is
.
And nothing repeated 1 or more times is nothing.

So, generates the language {} whose regular expression is . Hence,

It can be also shown as:

a generates {, a, aa, aaa, . . . . }


generates {}
-- Arjun Suresh

GATE1994_1.16 top

This will be C. Because if that would have been possible then NPDA and DPDA must had same powers, which is not the case. You can take
example of NFA and DFA. Both are convertible to each other and hence share the same power.
-- Gate Keeda

GATE1994_2.10 top

L={0*1*}
-- Manu Thakur

GATE1994_3.3

top

State True or False with one line explanation


A FSM (Finite State Machine) can be designed to add two integers of any arbitrary length (arbitrary number of digits).

No. Perhaps that wont be possible to add any two arbitrary numbers because that will need a memory element which is not there in a FSM.
-- Gate Keeda

GATE1994_19 top
(a) Given a set

S = {x there is an x-block of 5's in the decimal expansion of }


(Note: x-block is a maximal block of x successive 5's)
Which of the following statements is true with respect to S? No reason to be given for the answer.
i.
ii.
iii.
iv.

S
S
S
S

is regular
is recursively enumerable
is not recursively enumerable
is recursive

(b) Given that a language L 1 is regular and and that the language L 1 L 2 is regular, is the language L 2 always regular? Prove your answer.

(a) S is regular. It might not be possible to find what is x, but once it is found, it will be an integer and hence can be represented using an
automaton. For finding the class of a language, we needn't consider the difficulty in getting the language contents (strings of language). We
only need to count the difficulty in recognizing the strings of language.
(b) No. need not be. Take L2 = {anbn | n > 0} and L1 = all strings over {a,b}. Now, L1 U L2 is L1 only and is regular but L2 is not regular.
-- Arjun Suresh

GATE1995_1.9

top

In some programming language, an identifier is permitted to be a letter followed by any number of letters or digits. If L and D denote the sets of
letters and digits respectively, which of the following expressions defines an identifier?
(a) (L D)+
(b) L(L D)
(c) (LD)
(d) L(LD)

It is B.

It has to be started by a letter followed by any number of letters and digits.


-- Gate Keeda

GATE1995_2.20 top

A.
In the other two you can have any number of x and y. There is no such restriction over the number of both being equal.
-- Gate Keeda

GATE1995_2.23 top

if A is start state , shortest sequence is 10 or 00 to reach C


if B is start state , shortest sequence is 0 to reach C
if C is start state , shortest sequence is 10 or 00 to reach C
if D is start state , shortest sequence is 0 to reach C
b) is correct.

-- Praveen Saini

GATE1995_2.24 top
Let = {0, 1}, L = and R = {0 n 1 n n > 0} then the languages L R and R are respectively
(A) regular, regular
(B) not regular, regular
(C) regular, not regular
(D) not regular, not regular

Answer is (C). L R is nothing but L as R is a subset of L and hence regular. R is deterministic context-free but not regular as we require a
stack to keep the count of 0's to match that of 1's.
-- Arjun Suresh

GATE1996_1.8

top

C.
you can have any no. of 0's as well as null.
A is false because you cannot have single 0 in ii). same for option B. In D you are forced to have single 0 in iv) whereas not in iii).
-- Gate Keeda

GATE1996_1.9

top

D..
equivalence of Regular languages is decidable.
1.Membership,
2.Emptiness,
3.Finiteness,
4.Equivalence,
5.Ambiguity,
6.Regularity,
7.Everything,
8.Disjointedness...

All are decidable for Regular languages.


First 3 for CFL.
Only 1st for CSL and REC.
None for RE.
-- Gate Keeda

GATE1996_1.10 top
Let L where = {a, b} . Which of the following is true?
(a) L = {x x has an equal number of a's and b's} is regular
(b) L = {an b n n 1} is regular
(c) L = {x x has more number of a's than b's} is regular
(d) L = {am b n m 1, n 1} is regular

Only D. because n and m are independent and thus no memory element required.
a and b are same and are DCFL's.
c is L = { an bm | n > m }. which is not regular.
Correction:I think c should be that x has more a's than b's.
-- Gate Keeda

GATE1996_2.8

top

B.
CFL's are not closed under intersection.
-- Gate Keeda

GATE1996_2.9

top

(b) is the answer. Because for any binary string of 0's and 1's we can append another string to make it contain equal number of 0's and 1's.
i.e., any string over {0,1} is a prefix of a string in L.
Example:
01111 - is prefix of 011110000 which is in L.
1111- is prefix of 11110000 which is in L.
01010- is prefix of 010101 which is in L.
-- Arjun Suresh

GATE1996_2.23 top

3 states are required in the minimized machine. States B and C can be combined as follows:

-- Arjun Suresh

GATE1996_12 top

We can combine the final state of M1 with the start state of M2 as follows recognizing L1L2

-- Arjun Suresh

GATE1996_13 top
Let Q = ({q 1 , q 2 }, {a, b}, {a, b, }, , , ) be a pushdown automaton accepting by empty stack for the language which is the set of all
nonempty even palindromes over the set {a, b} . Below is an incomplete specification of the transitions . Complete the specification. The top of
the stack is assumed to be at the right end of the string representing stack contents.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

(q1 , a, ) = {(q1 , a)}


(q1 , b, ) = {(q1 , b)}
(q1 , a, a) = {(q1 , aa)}
(q1 , b, a) = {(q1 , ab)}
(q1 , a, b) = {(q1 , ba)}
(q1 , b, b) = {(q1 , bb)}
(q1 , a, a) = {( , )}
(q1 , b, b) = {( , )}
(q2 , a, a) = {(q2 , )}
(q2 , b, b) = {(q2 , )}
(q2 , , ) = {(q2 , )}

(q1 , a, b) = {(q2 , ba)} means from state q1 on input a with stack top being b , the PDA moves to state q2 and pushes a on top of stack.
So, here the missing transitions are at the middle of the input string:

(q1 , a, a) = {(q2 , )}
(q1 , b, b) = {(q2 , )}
Once middle is reached, now we should start popping. And so, we must go to state q 2 as well as pop the previous character on the stack.
(The character before and after the middle must be same as the string is even length palindrome)
(This is a non-deterministic PDA)
-- Arjun Suresh

GATE1998_3b top
Give a regular expression for the set of binary strings where every 0 is immediately followed by exactly k 1's and preceded by at least k 1s (k
is a fixed integer)

The expression will be of the form 1 1 k (01k ) .


-- neha pawar

Regular or not ?

top

{ wxw | w belongs to {0,1}* , x belongs to {0,1} + }

Lets see the strings in L


= { 0, 1, 00, 01, 10, 11, 000, ..... } (When w is , wxw generates all these strings and hence we don't need to consider any other case for w)
= * - {}
Hence, regular.
More examples: http://gatecse.in/wiki/Identify_the_class_of_the_language
-- Arjun Suresh

GATE2008-IT_5 top
Which of the following regular expressions describes the language over{0, 1} consisting of strings that contain exactly two 1's?

A)

(0 + 1) * 11(0 + 1) *

B)

0 * 110 *

C)

0 * 10 * 10 *

D)

(0 + 1) * 1(0 + 1) * 1 (0 + 1) *

A) with at least 2 consecutive 1's, any no of 0's and any no of 1's


B) exactly two consecutive 1's
C)exactly two 1's but need not be consecutive
D) any no of 1's and 0's with at least two 1's
Hence C) is the correct option.
-- Manu Thakur

GATE2008-IT_6 top
Let N be an NFA with n states and let M be the minimized DFA with m states recognizing the same language. Which of the following in
NECESSARILY true?

A)

m 2n

B)

nm

C)

M has one accept state

D)

m = 2n

A state in a DFA will be a subset of the set of states of the equivalent NFA. So, the maximum number of states in the equivalent DFA of an
NFA, will be 2n, where n is the number of states in NFA, as a set with n items has maximum n2 subsets.
So, answer here is (A).
-- Arjun Suresh

GATE2008-IT_32 top
If the final states and non-final states in the DFA below are interchanged, then which of the following languages over the alphabet {a, b} will be
accepted by the new DFA?

A)

Set of all strings that do not end with ab

B)

Set of all strings that begin with either an a or a b

C)

Set of all strings that do not contain the substring ab,

D)

The set described by the regular expression b*aa*(ba)*b*

Above DFA is for regular expression (a+b)*ab . All strings end with ab.
Complement of DFA accepts all strings does not end with ab.
DFA(L') is

B. String begin with either a or b.


ab (string start with a) doesnt accept in it reach to nonfinal state q2.
bab (string start with b) doesnt accept in it reach to nonfinal state q2.
C. Set of strings that do not contain the substring ab
aba (have substring ab) does accept in it reach to final state q1.
D. The set described by the regular expression b*aa*(ba)*b*
b is string accepted by DFA(L') but above regular expression cannot derive it.
Option A is correct.
DFA (L') accepts all strings that doesnt end with ab.

-- Praveen Saini

GATE2008-IT_33 top
Consider the following languages.
L1 = {ai bj ck | i = j, k 1}
L2 = {ai bj | j = 2i, i 0}
Which of the following is true?

A)

L1 is not a CFL but L2 is

B)

L1 L2 = and L1 is non-regular

C)

L1 L2 is not a CFL but L2 is

D)

There is a 4-state PDA that accepts L1, but there is no DPDA that accepts L2

Both languages can be accepted by a DPDA :


L1 = start pushing element X into the stack on input 'a' ... start poping X on input 'b' ... move to final state when stack empty and input = 'c'
L2 = start pushing elements XX into the stack on input 'a' ... start poping X on input 'b' ... move to final state when stack empty and input =
'epsilon'
so (A) and (D) are False
L1 L2 is a CFL ... we can build it by having L1, L2 and an extra state ... and an 'epsilon' transition to both L1 and L2 from that extra state.
so (C) is false
L1 L2 = Phi because we have no string aibj where i=j and i=2j for i,j>=1
and clearly L1 is not a regular language
so (B) is true.

-- Danish

GATE2008-IT_35 top
Which of the following languages is (are) non-regular?
L1 = {0m1n | 0 m n 10000}
L2 = {w | w reads the same forward and backward}
L3 = {w {0, 1} * | w contains an even number of 0's and an even number of 1's}

A)

L2 and L3 only

B)

L1 and L2 only

C)

L3 only

D)

L2 only

L1 is regular.. since 10000 is finite.. so finite states are required..


L3 is also regular.. we can make DFA for L3.. states will represent mod 2 for 0 and mod 2 for 1, which is finite
L2 is non. regular.. it is CFG S->aSa | ... | zSz | epsilon | [a-z]

so option (d)
-- Vicky Bajoria

GATE2008-IT_36 top
Consider the following two finite automata. M1 accepts L1 and M2 accepts L2.
Which one of the following is TRUE?

A)

L1 = L2

B)

L1 L2

C)

L1 L2' =

D)

L1 L2 L1

L1: (0 + 10)*11(0 + 1)* L2: (0 + 1)*11(0 + 1)* it is quite clear that L1 = L2.. So, option (A)
-- Vicky Bajoria

Gate2011_24

top

Let P be a regular language and Q be a context-free language such that Q P . (For example, let
p q and Q be {p n q n n N}) . Then which of the following is ALWAYS regular?

P be the language represented by the regular expression

(A)

P Q

(B)

P Q

(C)

(D)

c)complement of regular Language is regular


-- VOOTLA SRINIVAS

GATE2007-IT_46 top
The two grammars given below generate a language over the alphabet {x, y, z}
G1 :
S

x|z|xS|zS|yB
B

y|z|yB|zB
G2 :

y|z|yS|zS|xB
B

y|yS
Which one of the following choices describes the properties satisfied by the strings in these languages ?

A)

G1 : No y appears before any x


G2 : Every x is followed by at least one y

B)

G1 : No y appears before any x


G2 : No x appears before any y

C)

G1 : No y appears after any x


G2 : Every x is followed by at least one y

D)

G1 : No y appears after any x


G2 : Every y is followed by at least one x

from Above grammar


Regular expression for G1: (x+z)+ + (x+z)*y(y+z)+
Regular expression for G2 :(y+z+xy)+
Option A is correct
-- Praveen Saini

GATE2007-IT_47 top
Consider the following DFA in which s0 is the start state and s1, s3 are the final states.

What language does this DFA recognize ?

A) All strings of x and y


B)

All strings of x and y which have either even number of x and even number of y or odd number or x and odd number of y
C) All strings of x and y which have equal number of x and y
D) All strings of x and y with either even number of x and odd number of y or odd number of x and even number of y

Above DFA can be redesigned as

[S0 as q00, S1 as q10 , S2 as q11, S3 as q01 ]

where , each state as qab [a = namod2 , b = nbmod2]


q00 as namod2 =0 nbmod2=0 [no of x is even no of y is even ]
and (q00, x) -> q10 [(0+1)mod2 =1 as x increase from 0 to 1 ] (q00, y) -> q01
and (q10, x) -> q00 [(1+1)mod2 =0]

(q00, y) -> q01 and soon

q01 is final state mean where no of x is even and no of y is odd


q10 is final state mean where no of x is odd and no of y is even.
so D is correct answer
-- Praveen Saini

GATE2007-IT_48 top
Consider the grammar given below
S
A
B

xB|yA
x|xS|yAA
y|yS|yBB

Consider the following strings.


(i)
(ii)
(iii)
(iv)
(v)
(vi)

xxyyx
xxyyxy
xyxy
yxxy
yxx
xyx

Which of the above strings are generated by the grammar ?

A)

(i), (ii), and (iii)

B)

(ii), (v), and (vi)

C)

(ii), (iii), and (iv)

D)

(i), (iii), and (iv)

ii), iii) and iv)


so option C is correct

Above grammar is for equal no of x and y


from Non-terminal S -> xB
=>xy

[as B->y one y for one x]

S->xB
=> xxBB [as B ->yBB one B result in one y for one x ]

S->xB
=>xyS [as B->yS one y for one x and start again]
Note :Same applies for string start with y i.e . S->yA

-- Praveen Saini

GATE2007-IT_49 top
Consider the following grammars. Names representing terminals have been specified in capital letters.
G1 : stmnt WHILE (expr) stmnt
stmnt OTHER
expr
ID
G2 : stmnt WHILE (expr) stmnt
stmnt OTHER
expr
expr + expr
expr
expr * expr
expr
ID
Which one of the following statements is true?

A)

G1 is context-free but not regular and G2 is regular

B)

G2 is context-free but not regular and G1 is regular

C)

Both G1 and G2 are regular

D)

Both G1 and G2 are context-free but neither of them is regular

Regular grammar is either right linear or left linear. A left linear grammar is one in which there is at most 1 non-terminal on the right side of
any production, and it appears at the left most position. Similarly, in right linear grammar non-terminal appears at the right most position.
Here, we can write a right linear grammar for G1 as
S -> w(E
E -> id)S
S -> o
(w - WHILE, o - OTHER)
So, L(G1) is regular.
Now for G2 also we can write a right linear grammar:
S -> w(E
E -> id)S
E -> id+E
E -> id*E
S -> o
making its language regular.
So, both G1 and G2 have an equivalent regular grammar. But as such both these grammars are neither right linear nor left linear and hence
not a regular grammar. So, D must be the answer.
http://www.cs.odu.edu/~toida/nerzic/390teched/regular/grammar/reg-grammar.html
-- Arjun Suresh

GATE2007-IT_71 top

Consider the regular expression R = (a + b)* (aa + bb) (a + b)*


Which of the following non-deterministic finite automata recognizes the language defined by the regular expression R? Edges labeled denote
transitions on the empty string.

A)

B)

C)

D)

Design NFA for R = (a+b)*(aa+bb)(a+b)*

convert NFA to equivalent DFA

A is correct.

-- Praveen Saini

GATE2007-IT_72 top
Consider the regular expression R = (a + b)* (aa + bb) (a + b)*
Which deterministic finite automaton accepts the language represented by the regular expression R ?

A)

B)

C)

D)

DFA given in option A


having S3 and S4 are equivalent states .. that can minimized.
and result in DFA given in
http://gateoverflow.in/3523/gate2007-it_71
-- Praveen Saini

GATE2007-IT_73 top
Consider the regular expression R = (a + b)* (aa + bb) (a + b)*

Which one of the regular expressions given below defines the same language as defined by the regular expression R?

A) (a(ba)* + b(ab)*)(a + b)+


B) (a(ba)* + b(ab)*)*(a + b)*
C)
D)

(a(ba)* (a + bb) + b(ab)*(b + aa))(a +


b)*
(a(ba)* (a + bb) + b(ab)*(b + aa))(a +
b)+

R = (a+b)*(aa+bb)(a+b)*
having NFA

Equivalent DFA :

which is equivalent Transition graph [ by removing transition from q1 to q2 and q2 to q1 but does not effect on language ..be careful ]

That is equivalent to

which is equivalent to

which is equivalent to

so equivalent regular expression is [a(ba)*(a+bb) + b(ab)*(b+aa)](a+b)*


so option C is answer.

-- Praveen Saini

GATE2006-IT_3 top
In the automaton below, s is the start state and t is the only final state.

Consider the strings u = abbaba, v = bab, and w = aabb. Which of the following statements is true?

A)

The automaton accepts u and v but not w

B)

The automaton accepts each of u, v, and w

C)

The automaton rejects each of u, v, and w

D)

The automaton accepts u but rejects v and w

for u

(s,abbaba)

for v

(s,bab)

for w

(s,aabb)


for
u
(x,bbaba)
(x,baba)
(x,aba)

for v
(t,ab)
(t,b)
s - rejected

(s,ba)
(t,a)
t - accepted

for w
(x,abb)
(s,bb)
(t,b)
s - rejected

-- Praveen Saini

GATE2006-IT_4 top
In the context-free grammar below, S is the start symbol, a and b are terminals, and denotes the empty string
S aSa | bSb | a | b |
Which of the following strings is NOT generated by the grammar?

A)

aaaa

B)

baba

C)

abba

D)

babaaabab

L(G) = PALINDROME
baba does not belong to palindrome , so B is the answer
-- Praveen Saini

GATE2006-IT_29 top
Consider the regular grammar below
S bS | aA |
A aS | bA
The Myhill-Nerode equivalence classes for the language generated by the grammar are

A)

{w (a + b)* | #a(w) is even) and {w (a + b)* | #a(w) is


odd}

B)

{w (a + b)* | #a(w) is even) and {w (a + b)* | #b(w) is


odd}

C)

{w (a + b)* | #a(w) = #b(w) and {w (a + b)* | #a(w)


#b(w)}

D) {}, {wa | w (a + b)* and {wb | w (a + b)*}

Option A is correct.
The given grammar generates all string over the alphabet

which have an even number of 's.

The given right-linear grammar can be converted to the following DFA.

-- Pragy Agarwal

GATE2006-IT_30 top
Which of the following statements about regular languages is NOT true ?

A)

Every language has a regular superset

B)

Every language has a regular subset

C)

Every subset of a regular language is regular

D)

Every subset of a finite language is regular

Option C is not True.


A) Every language has a regular superset: True.
B) Every language has a regular subset: True.

is such a superset.
is such a subset.

C) Every subset of a regular language is regular: False.

, but

is not Regular.

D) Every subset of a finite language is regular: True. Every subset of a finite set must be finite by definition. Every finite set is regular.
Hence, every subset of a finite language is regular.
-- Pragy Agarwal

GATE2006-IT_31 top
Which of the following languages is accepted by a non-deterministic pushdown automaton (PDA) but NOT by a deterministic PDA?

A)

{anbncn | n 0}

B)

{albmcn | l m or m n}

C)

{anbn| n 0}

D)

{ambn| m, n 0}

option B is correct
L = {albmcn | l m or m n}
(q0,a,Z0) (q0,aZ0)
(q0,a,a) (q0,aa)
(q0,b,a) (q1,), (q2,ba)
[here it is NPDA where we have to check l m or m n; for l m we need to pop a for b; for m n we need to keep b in
stack so that we can pop b for c ]
(q1,b,a)(q1,)
(q1,c,a) (qf,)
(q1,b,Z0) (qf,)
(q2,b,b)q2,bb)
(q2,c,b)(q3,)
(q3,c,b)(q3,)
(q3,c,a)(qf,)
(q3,,b)(qf,)

A is wrong as it is not context free

D a*b* is regular, so must have DFA , and so an equivalent DPDA


C can be accepted using DPDA

-- Praveen Saini

GATE2006-IT_33 top
Consider the pushdown automaton (PDA) below which runs over the input alphabet (a, b, c). It has the stack alphabet {Z
0, X} where Z0 is the
bottom-of-stack marker. The set of states of the PDA is (s, t, u, f} where s is the start state and f is the final state. The PDA accepts by final
state. The transitions of the PDA given below are depicted in a standard manner. For example, the transition (s, b, X) (t, XZ0) means that if
the PDA is in state s and the symbol on the top of the stack is X, then it can read b from the input and move to state t after popping the top of
stack and pushing the symbols Z0 and X (in that order) on the stack.
(s, a, Z0)
(s, , Z0)
(s, a, X)
(s, b, X)
(t, b, X)
(t, c, X)
(u, c, X)
(u, , Z 0)

(s, XXZ0)
(f, )
(s, XXX)

(t, )
(t,.)
(u, )
(u, )
(f, )

The language accepted by the PDA is

A)

{albmcn | l = m = n}

B)

{albmcn | l = m}

C)

{albmcn | 2l = m + n}

D)

{albmcn | m = n}

for every a we put two X in stack [at state s]


after that for every b we pop out one X

[reach to state t ( getting b after a) ]

after that for every c we pop out one X

[reach to state u (getting c after b)]

if all X are popped out then reached to final state f , mean for every b there is a, for every c there is a .
a was followed by b and b was followed by c [ state s to t , t to u , u to f, final]
means sum of no of b's and no of c's = twice of no of a's

[ one a for one b , one a for one c ]

i.e. {albmcn | 2l = m + n}

-- Praveen Saini

GATE2006-IT_34 top
In the context-free grammar below, S is the start symbol, a and b are terminals, and denotes the empty string.
S aSAb |
A bA |
The grammar generates the language

A)

((a + b)* b)*

B)

(ambn | m n}

C)

(ambn | m = n)

D)

a* b*

A bA|

A = b

S aSAb |
S aS b b |
S aS b + |
n

S = an ( b + ) ,
n n ,

S=a b b

S = am b n ,

n0
n0

mn

Hence, option B is correct.


-- Pragy Agarwal

What is the type of the language I,where L={a^nb^n|0

top

L contains aabb, aaabbb, aaaaabbbbb, ... ak bk where k is the largest prime below 327. Now there are only a finite set of strings in L making it
a finite language. L can be accepted by a finite automaton.
-- Arjun Suresh

GATE2004-IT_7 top
Which one of the following regular expressions is NOT equivalent to the regular expression (a + b + c)*?
A)

(a* + b* + c*)*

B)

(a*b*c*)*

C)

((ab)* + c*)*

D)

(a*b* + c*)*

A)

(a* + b* + c*)* = ( ^ + a+aa+.. ..+b+bb+...+c+cc...)* = (a+b+c+ aa+..+bb+..+cc+..)*=


(a+b+c)*
[any combination of rest of aa ,bb,cc, etc already come in (a+b+c)* ]

B)

(a*b*c*)* = (a*+b*+c* +a*b*+b*c*+a*c*+..)*=(a+b+c+....)* = (a+b+c)*

C)

((ab)* + c*)* =(ab+c+^+abab+...)* = (ab+c)*

D)

(a*b* + c*)* = (a*+b*+c*+...)* =(a+b+c+..)* =(a+b+c)*

-- Praveen Saini

GATE2004-IT_9 top
Which one of the following statements is FALSE?

A) There exist context-free languages such that all the context-free grammars generating them are ambiguous
B) An unambiguous context-free grammar always has a unique parse tree for each string of the language generated by it
C) Both deterministic and non-deterministic pushdown automata always accept the same set of languages
D) A finite set of string from some alphabet is always a regular language

A) this is true for inherently ambiguous language


B) always correct, that's why called un ambiguous
C) NPDA is a supper set of DPDA, hence it's FALSE
D) finite language is always regular
-- Manu Thakur

GATE2004-IT_41 top
Let M = (K, , , s, F) be a finite state automaton, where
K = {A, B}, = {a, b}, s = A, F = {B},
(A, a) = A, (A, b) = B, (B, a) = B and (B, b) = A
A grammar to generate the language accepted by M can be specified as G = (V, , R, S), where V = K U , and S = A.
Which one of the following set of rules will make L(G) = L(M) ?

A)

{A aB, A bA, B bA, B aA, B )

B)

{A aA, A bB, B aB, B bA, B )

C)

{A bB, A aB, B aA, B bA, B )

D)

{A aA, A bA, B aB, B bA, A )

(A, a) = A,

A aA

(A, b) = B,

A bB

(B, a) = B

B aB

(B, b) = A

B bA

B is final state so B
-- Praveen Saini

GATE2005-IT_4 top
Let L be a regular language and M be a context-free language, both over the alphabet . Let Lc and Mc denote the complements of L and M
respectively. Which of the following statements about the language Lc Mc is TRUE?
A)

It is necessarily regular but not necessarily context-free.

B)

It is necessarily context-free.

C)

It is necessarily non-regular.

D)

None of the above

Take L = * then Lc = and Mc = Mc .


We know that complement of CFL need not be a CFL as CFL is not closed under complement.
So, (A) and (B) are false.
If we take L = then Lc = * and Mc * = * which is regular - (C) is also false.
So, answer (D)
-- Arjun Suresh

GATE2005-IT_5 top
Which of the following statements is TRUE about the regular expression 01*0?

A)

It represents a finite set of finite strings.

B)

It represents an infinite set of finite strings.

C)

It represents a finite set of infinite strings.

D)

It represents an infinite set of infinite strings.

(B). Infinite set (because of *) of finite strings. A regular expression cannot generate any infinite string AFAIK.
-- Arjun Suresh

GATE2005-IT_6 top
The language {0n 1n 2n | 1 n 106} is

A)

regular

B)

context-free but not regular.

C)

context-free but its complement is not context-free.

D)

not context-free.

Regular (in fact finite). Since n is finite, we have a finite set of strings satisfying the given conditions. So, we can easily make a finite automata
for those strings.
-- Arjun Suresh

GATE2005-IT_37 top
Consider the non-deterministic finite automaton (NFA) shown in the figure.

State X is the starting state of the automaton. Let the language accepted by the NFA with Y as the only accepting state be L1. Similarly, let the
language accepted by the NFA with Z as the only accepting state be L2. Which of the following statements about L1 and L2 is TRUE?

A)

L1 = L2

B)

L1 L2

C)

L2 L1

D)

None of the above

In Qs. Z -> Y (0 edge)


L1 can have 00 string while L2 can't. L2 can have 01 while L1 can't
So we can conclude neither they are same set not proper subset of each other.
Hence Ans. D.
-- shreya ghosh

GATE2005-IT_39 top
Consider the regular grammar:
S Xa | Ya
X Za
Z Sa |
Y Wa
W Sa

where S is the starting symbol, the set of terminals is {a} and the set of non-terminals is {S, W, X, Y, Z}.
We wish to construct a deterministic finite automaton (DFA) to recognize the same language. What is the minimum number of states required
for the DFA?

A)

B)

C)

D)

(D) 3
The string generated by the language is the set of strings with a's such that number of a mod 3 is 2.
So the number of states required should be 3 to maintain the count of number of a's mod 3.
-- Omesh Pandita

Given that a language LA = L1 U L2,

top

Given that a language L A = L 1 L 2 , where L 1 and L 2 are two other languages. If L A is known to be a regular language, then which of the
following statements is necessarily TRUE?
A.
B.
C.
D.

If L 1 is regular then L 2 will also be regular


If L 1 is regular and finite then L 2 will be regular
If L 1 is regular and finite then L 2 will also be regular and finite
None of these

(b) is the answer because we cannot make an irregular set S regular, by adding a finite number of elements to it. This can be proved as
follows:
Let R F = T be regular, where F is a finite set. We remove all elements from F which are in R and let the new set be E. Still,
R E = T. and E is a finite set (but no strings common between E and R)
Now, T being regular means we have a DFA for T. We can find all the states in this DFA where each of the strings in F is being accepted. In
each of these accepting state, none of the string in R will be accepted as R and E doesnt have any string in common. So, if we make all these
states non-accepting, what we get is DFA for R. Meaning R is regular.
We can prove (a) false be taking L 1 = and L 2 = {an b n n > 0} . Now, union of these is which is regular but L 2 is not regular.
(c) can be proved false by taking L 1 = {a} and L 2 = {an n > 0} . Now L 1 L 2 is regular and L 1 finite but L 2 is not finite.
-- Arjun Suresh

How to draw NPDA for language L = { a^i b^j c^m | m >= min( i,j) }

top

L1 = { a^i b^j c^m | m min(i,j) }


L2 = { a^i b^j c^m | m max(i,j) }
Which language is CFL ?
ANS : L1 is CFL but L2 is NOT.
My understanding :
For Language L1 :
( Here I am interested in checking Whether language is DCFL or not , also. )
Checking DCFL or not :
By looking at language , it is not possible to construct PDA as it contains 2 conditions ( i > j or i < j And m min (i,j) )
But there is a way of checking language is DCFL or not. ( By Prefix Property )
No Proper Prefix Prefix property DCFL

But there is No Proper Prefix getting for this language , So, Prefix property , and so L1 is DCFL ( but there is no DPDA for L1 as per my 1st
conclusion ( i.e. 2 conditions -> No PDA )
It means somewhere I am wrong. Please correct me.
Checking CFL or not :
We will have to check whether it is accepted by NPDA or not.
I dont know correct way to construct NPDA but I tried in following way.
1) At some point PDA will assume that i < j or i > j
condition 1st : i < j
We are interested in min , so consider only i, means accept "a" and skip all "b" and for each "c" , pop each "a"
Condition 2nd: i > j
We are interested in min , so consider only j means skip all "a" and accept "b" and for each "c" , pop each "b" So it is CFL. Please correct me if
it is wrong.
If above NPDA is right , then we can construct NPDA for L2 also.
But Answer part saying L2 is not CFL.
So above NPDA is right or wrong ??

Prefix property is not obeyed by all DCFLs. It is obeyed only by those languages accepted by a deterministic PDA which accepts by empty
stack- if a prefix of the string is in L, stack should have been empty before and deterministic means, this cannot happen.
Now, a language obeys prefix property doesn't mean it is DCFL. {anbncn | n 1} obeys prefix property but not even CFL.

L1 = { a i bj cm | m min(i,j) }
Here number of c's is greater than minimum of number of a's and number of b's. So, we can say that if number of c's is greater than number
of a's or if number of c's is greater than number of b's, we accept. i.e.,

L1 = { a ibjcm | m i OR m j) }
The OR condition here means even though we need to do two checks, we can accept in either case and hence using non-determinism we just
need a PDA to accept L1 (we non-deterministically check if m j and if m i). So, L1 is a CFL but not DCFL.

L2 = { a i bj cm | m max(i,j) }
This can be rewritten as

L2 = { a ibjcm | m i AND m j) }
The AND condition here means we need to do two checks and even non-determinism cannot help us here. This is because if we nondeterministically guess i j, and accept if m i, suppose if the guess is wrong, then we would have accepted a word not in L2. (In short nondeterminism can help only when we have OR condition). So, L2 is not even CFL- it is a CSL.
-- Arjun Suresh

Which is true?

top

REG contains the set of all strings which are encodings of TM whose language is regular. So, REG is deciding a property of TM- we are lucky
and can make use of Rice's theorem.
Here we want to prove whether RE or not. (Rice's theorem part 1 won't help)
So, lets see if the property is non-monotonic so that we can apply Rice's theorem part 2.
For non-monotonicity, language of TM satisfying the property must be a subset of language of TM not satisfying the property. So, if we take
L(TMyes) = and T(TMno) = any non regular language, this proves the property is non-monotonic. So, as per Rice's theorem part 2, REG is
not RE.
Using the same technique we can prove Co-Reg is also not RE. Just take L(TMyes) = any non regular language and L(TMno) = *.
http://gatecse.in/wiki/Rice%27s_Theorem_with_Examples
-- Arjun Suresh

Let L1 is regular and L2 is CFG. Then what is L1-L2?


(A) Regular

top

(B)CFG

(C)Deterministic CFG

(D) Context Sensitive

L1 - L2 = L1 L2'
Now CFL complement need not be CFL (as CFL's are not closed under complement).But any CFL is also a CSL and CSLs are closed under
complement. So, any CFL complement is guaranteed to be a CSL. Now, CSL intersection CSL (regular is also a CSL) is CSL, and so L1-L2 is
always Context Sensitive.
(It can also be regular or CFL but we can say always only with respect to CSL)
http://gatecse.in/wiki/Closure_Property_of_Language_Families
-- Arjun Suresh

I think the answer should be 32 but its not in options? Help me in this question..

top

First of all I would like to clear that empty language is and not and there is only one way to have final state in finite automata then - By not
having any final state at all . Now 16 is total number of transitions possible in DFA of two states and two inputs. So possible number of DFA's
with no final state= 16 , now there are 4 more possibilities when q1 is final state and it is not reachable from initial state.. ( courtesy @Arjun sir
) Therefore ans is 16+4=20
-- Prateeksha Keshari

plz answer...

top

Lets see the strings generated by G and G'.


For G,
S -> bAcAb -> bcAb ->bcb
S -> bbSbb -> bbAcAbb -> bbcbb
S -> bbSbb -> bbAcAbb -> bbcAb -> bbcb
So, G is generating all strings where number of b's to the left of 'c' in the input string is greater than or equal to the number of b's to the right.
So, L(G) is context-free but not regular.
For G' we have an extra production bA -> A which can condense any number of b's. So, G' will generate all strings over b and c containing at
least one b before and after a c. This language is hence regular.
So, (B) is correct.

-- Arjun Suresh

which of the following is always regular

top

Let P be a regular language and Q be a context free language such that Q P.


Which of the following is always regular ?
(A) P Q
(B) P-Q
(C) *

-P

(D) * - Q

Option C. As Regular languages are closed under complement


A. P Q need won't be regular, if P = {} and Q is a CFL but not regular.

and CFL complement need not be even CFL.


B. P Q need not be regular when P = and Q is a CFL as this will be Q
D. This is CFL complement and this need not be even CFL.
-- shreya ghosh

Does PDA accepts L={a^n b^n | n>=0 , n!=13}???


If it does, how??

top

Consider the following Languages:

We can see that


is a Deterministic Context Free Language (
is a Regular Language (
)
Since

, we can conclude that

is

To draw the DPDA for :


Draw a DPDA for
Draw a DFA for
Take the product of the two machines. It is simple. The procedure for doing that is listed in thispdf(Click to view)
-- Pragy Agarwal

complement of every contet free language is recursive ? or recursive enumerable? or


both? top

Both. Also, context-sensitive.


CFL is a strict subset of CSL. CSL is closed under complement. So, CFL complement is CSL.
And CSL is a strict subset of recursive which in turn is a strict subset of recursively enumerable.
-- Arjun Suresh

True or False: DCFL is closed under set difference

top

True or False: DCFL is closed under set difference

Let L 1 and L 2 be two DCFLs.


Now u want to find whether L 1 L 2 is dcfl or not? (if DCFL is closed under set-difference, this must be TRUE for ANY suchL 1 and L 2 ).
To prove this we make use of the fact that DCFL is not closed under intersection. (For example take L 1 = {a b n c n n 0}
L2 = {an b c n n 0} which gives L1 L2 = {an b n c n n 0} , which is not even a CFL.)

and

Now we can L 1 L 2 = L 1 L2
DCFL is closed under complement (If we complement the accept states of DPDA for L we get DPDA for the complement of L, but this is not
true for a general PDA.) So, L2 is a DCFL, let it be R. So,

L1 L2 = L1 R , where L1 , L2 and R are DCFLs. Now, if DCFL is closed under set difference it must also be closed under complement.
But we already showed that it is not. So, DCFL is not closed under set difference.
-- Shreyans Dhankhar

The number of states in a DFA accepting all the strings over {0,1} in which 5th symbol from
right hand side is always '1' is? top
Will the answer be 4 or 2 5 ?

It will be 25 as 25 possible combinations of characters are possible with the 5th last character being 1. We need to remember each of them as
any of them can be the 5th last character as we continue processing further characters.

-- Arjun Suresh

What is the number of states in the minimal DFA with input symbols {0,1,2} where 2nd last
symbol is 1? top
What is the number of states in the minimal DFA with input symbols {0,1,2} where 2nd last symbol is 1?
A. 8
B. 9
C. 6
D. None

Second last symbol is 1 over {0,1, 2 }


regular expression = (0+1+2)*1(0+1+2).

Anything Second last Last

For this regular expression NFA is

Convert NFA to DFA

-- Praveen Saini

Language accepted by PDA is __________?

top

L = a(a + b)+ b
In q 0 when stack is empty and an a comes, a is pushed on stack. After this for either a or b , we reach q 1 without modifying the stack. In q 1 we
can ignore all a's and b's without modifying the stack. Finally, we can move to q 2 on a b and this pops the a on stack (there is non-determinism
here for the given PDA). And now stack is empty and PDA reached final state. So, L is regular but infinite.
-- Arjun Suresh

equivalent regular expression?

top

Assume R1 , R2 , and R3 are three regular expressions.


Given R1 + R2 R3 = (R1 + R2 ) (R1 + R3 ) for any R2 and R3 . Which of the following could be correct condition which always satisfies the
above equation.
1. R1 = R2
2. R1 = R3
3. R1 =
A) only 1 and 2 are correct
B) only 1 and 3 are correct
C) only 2 and 3 are correct
D) 1,2, and 3 are correct
Answer is given as D

(R1+R2) (R1+R3) = R1R1 + R1R3 + R2R1 + R2R3


Now, R1 = R2 => LHS = R1 + R2R3 = R1 + R1R3
RHS = R1R1 + R1R3 + R1R1 + R1R1
So, they are not equal. For example consider R1 = R2 = a, R3 = b. LHS = a + ab, RHS = aa + ab
When R1 = R3, LHS = R1 + R2R1
RHS = R1R1 + R1R1 + R2R1 + R2R1, again not equal. For example, R1 = R3 = a, R2 = b, LHS = a + ba, RHS = aa + ba
When R1 = ,
LHS = as concatenated with anything is
RHS = hence equal.
-- Arjun Suresh

toc top
Let L1 = {anbmcn | m,n 0 } and L2 = {ancn | n 0 }. Both L1 and L2 are context free languages. if L = ( L1 - L2 ) then L is ____.
a. Finite Language
b. Regular language
c. DCFL
d. Not DCFL

L1 = {, ac, abc, abbc, aacc, aabcc, aabbcc, } .


L2 = {, ac, aacc, aaaccc, , } .
So,

L1 L2 = {an b m c n m > 0, n 0}
DCFL.
-- Arjun Suresh

Which of the following languages are Recursively Enumerable language?

top

Which of the following languages are Recursively Enumerable language?


a. {< M > | M is a TM and there exist an input whose length is less than 100, on which M halts}
b. {< M > | M is a TM and L(M) = {00, 11} }
c. { <M1, M2, M3> | L(M1) = L(M2) L(M3) }
d. All of these

a) is recursively enumerable but not recursive. If there is such an input, then we can say "yes". But for the no case we cannot decide as we
can never be sure that such an input does not exist.
b) is not RE. We can use Rice's 2nd theorem which will be most straightforward. Here we are given the encoding of a TM and asked if the
language of that machine is {00, 11}. (This is different from asking if that machine accepts 00 and 11, which would be RE). So, now to apply
Rice's 2nd theorem, we need to make 2 TMs, TM yes and TMno, with L(TMyes) = {00,11} and L(TMno) != {00,11} and L(TMyes) subset of
L(TMno). (The last condition is for non-monotonicity).
Here, we can easily get a TMno as L(TMno) can be {00, 11, 011} or any subset of sigma star containing {00, 11} except {00, 11}. Since we get
TMyes, and TMno, the given language is not RE.
c) Checking the equivalence of language of 2 TMs itself is not even semi-decidable. So, this is a double non-recursively enumerable
language. We can use Rice's 2'nd theorem here also, by taking L(TM no) = sigma star.
-- Arjun Suresh

No. of states in the minimal finite automata which accepts the binary strings whose
equivalent is divisible by 32 is ________? top
No. of states in the minimal finite automata which accepts the binary strings whose equivalent is divisible by 32 is ________?
A. 5
B. 6
C 31
D 32

Answer is 6.
For binary strings divisible by 2 we check if the last char from right is a 0.
For binary strings divisible by 22 we check if the last char from right is a 00.
...
For binary strings divisible by 25 we check if the last char from right is a 00000
So, we need 6 states for

counting the number of 0's on right, from 0 to 5.

-- Arjun Suresh

GATE2015-1_3 top
For any two languages L 1 and L 2 such that L 1 is context-free and L 2 is recursively enumerable but not recursive, which of the following is/are
necessarily true?
I.
II.
III.

1 ( Compliment of L1 ) is recursive
L
2 ( Compliment of L2 ) is recursive
L
1 is context-free
L
1

1 L2 is recursively enumerable
IV. L

A.
B.
C.
D.

I only
III only
III and IV only
I and IV only

D.
L1 is context-free and hence recursive also. Recursive set being closed under complement, L1' will be recursive.
L1' being recursive it is also recursively enumerable and Recursively Enumerable set is closed under Union. So, L1' U L2 is recursively
enumerable.
Context free languages are not closed under complement- so III is false
Recursive set is closed under complement. So, if L2' is recursive, (L2')' = L2 is also recursive which is not the case here. So, II is also false.
-- Arjun Suresh

GATE2015-2_35 top
Consider the alphabet = {0, 1} , the null/empty string and the set of strings X 0 , X 1 , and X 2 generated by the corresponding non-terminals
of a regular grammar. X 0 , X 1 , and X 2 are related as follows.

X 0 = 1X 1
X 1 = 0X 1 + 1X 2
X 2 = 0X 1 + {}
Which one of the following choices precisely represents the strings inX 0 ?

A.
B.
C.
D.

10(0*+(10)*)1
10(0*+(10)*)*1
1(0+10)*1
10(0+10)*1 +110(0+10)*1

option c is correct because look at the smallest string generated by the grammar is 11 which is not accepted by any option.
-- Anoop Sonkar

GATE2015-2_51 top
Which of the following is/are regular languages?

L1 : {wxw R w, x {a, b} and |w|, |x| > 0}, w R is the reverse of string w
L2 : {an b m m n and m, n 0}
L3 : {ap b q c r p, q, r 0}

A.
B.
C.
D.

L1
L2
L2
L3

and L 3 only
only
and L 3 only
only

Ans A.
L1: all strings of length 3 or more with same start and end letter- because everything in middle can be consumed by x as per the definition of
L.

L2: We need to compare number of a's and b's and these are not bounded. So, we need at least a DPDA.
L3: Any number of a's followed by any number of b's followed by any number of c's. Hence regular.
-- Vikrant Singh

GATE2015-1_51 top
Consider the NPDA Q = {q 0 , q 1 , q 2 }, = {0, 1}, = {0, 1, }, , q 0 , , F = {q 2 } , where (as per usual convention) Q is the set of states,
is the input alphabet, is the stack alphabet, is the state transition function q0 is the initial state, is the initial stack symbol, and F is the set
of accepting states. The state transition is as follows:

Which one of the following sequences must follow the string 101100 so that the overall string is accepted by the automaton?
A.
B.
C.
D.

10110
10010
01010
01001

In q 0 state for '1', a '1' is pushed and for a '0' a '0' is pushed. In q1 state, for a '0' a '1' is popped and for a '1' a '0' is popped. So, the given PDA
is accepting all strings of of the form x0x'r or x1x'r, where x'r is the reverse of the 1's complement of x.
The given string 101100 has 6 letters and we are given 5 letter strings. So, x0 is done, with x = 10110. So, x'
r = (01001)r = 10010.
B choice.
-- Arjun Suresh

GATE2015-1_52 top

Consider the DFAs M and N given above. The number of states in a minimal DFA that accept the language L(M) L(N) is_____________.

L(M) = (a+b)* a = {a, aa, ba, aaa, aba, bba, ...}


L(N) = (a+b)* b = {b, ab, bb, aab, abb, bbb, ...}
So, L(M) L(N) = {}. So, in the minimal DFA, we just have 1 start state with all transitions going to it self and no final state.
-- Arjun Suresh

GATE2015-3_18 top
Let L be the language represented by the regular expression 0011 where = {0, 1} . What is the minimum number of states in a DFA that
(complement of L)?
recognizes L

A.
B.
C.
D.

4
5
6
8

first we can draw dfa for L which has 5 states after that for L compliment we will convert all final to non final and all non final to final so total
states is 5 .. option B
-- Anoop Sonkar

GATE2015-3_32 top
Which of the following languages are context-free?

L1 : {am b n an b m m, n 1}
L2 : {am b n am b n m, n 1}
L3 : {am b n m = 2n + 1}

A.
B.
C.
D.

L1
L1
L2
L3

and L 2 only
and L 3 only
and L 3 only
only

first check for L1. now look a^m&b^m and a^n&b^n must b comparable using one stack for CFL.
now take a stack push all a^m in to the stack then push all b^n in to stack now a^n is coming so pop b^n for each a^n by this
b^n and a^n will b comparable. now we have left only a^m in stack and b^m is coming so pop a^m for each b^m by which we
can compare a^m to b^m ..we conclude that we are comparing this L1 using a single stack so this is CFG.
now for L2.this can not be done in to a single stack because m and n are not comparable we can not find when to push or
pop so this is CSL.
now for L3. push all a's in to stack and pop a single a for every 2b and after popping all a's with 2 b's we will get a single b in
stack so this comparable hence L3 is CFG.
so the option is B.. L1 and L3 are CFG
-- Anoop Sonkar

plz answer

top

L1 is a finite language n L2 is a language, if L1 intersection L2 is empty and L1 union L2 is regular, than L2 isregular n finite
regular n infinite
need not to be regular
none of these

Let L2 = compl(L1). Now, L1 intersect L1 is empty and L1 union L2 is * and hence regular. And L2 here is regular and infinite - so A option is
eliminated.
Now, we have L1 union L2 as regular and hence we have a DFA (say D) for it. We also have DFA for L1 (say D1). Now, we can make a DFA
for L2 (say D2) by doing D intersect compl(D1), as complement of a regular language is regular and regular set is closed under intersect. So,
L2 must be regular.
Now, consider L2 = {}. Now, L1 intersect L2 is empty and L1 union L2 is L1 which is regular. But here, L2 is regular and finite.
Hence option D- none of these.
-- Arjun Suresh

plz answer

top

the minimum number of states in the PDA accepting the language

L = {an b m n > m; m, n > 0}


a) 2

b) 3
c) 4
d) 5

if we use stack symbols as {z0,A} where initial stack symbol is {z0} and final state is {q2} than if the transition functions are(q0, a, z0) --> (q0, Az0)
(q0, a, A) --> (q0, AA)
(q0, b, A) --> (q1, )
(q1, b, A) --> (q1, )
(q1, , A) --> (q2, )
q2 is final state..
i m getting minimum no. of states = 3 .
-- shreshtha5

NFA for the language, L= (ab, ba)* would have how many states?

top

NFA for (ab+ba)*

Having 3 states
and DFA for same

have 4 states
-- Praveen Saini

Build an FA that accepts the language of all strings of a's and b's such that next-to-last
letter is an a top
alphabet set is {a,b}

if you mean to say second last symbol is always a


regular expression = anything secondlast last = (a+b)* a (a+b) [ second last is a , last is either a or b ]
Corresponding NFA will be

convert the above NFA into DFA


resulting DFA will be

-- Praveen Saini

How many DFA's exist with three states over the input alphabet {0,1}

top

Is there any procedure to generalize these types of problems ?

Thanks in advance

Input set is given. So, we have 3 parts of DFA which we can change:
1. Start state
2. Transition Function
3. Final state
Start state can be chosen as any one among 3 in 3 ways.
Transition function is from Q Z to Q, where Q is the set of states and Z is the alphabet state. |Q| = 3, |Z| = 2. So, number of possible
transition functions = 3(3 * 2) = 36
Final state can be any subset of the set of states including empty set. With 3 states, we can have 23 = 8 possible sub states.
Thus total number of DFAs possible

= 3 3 6 2 3 = 17496

For n states and m input alphabets we can have the formula

n n nm 2 n = n mn+1 2 n
-- Arjun Suresh

Question of regular expression

top

Consider the following regular expressions :


(i) ((a/b)

(ii) (a /b ) (iii) ((/a)b )

Which of the following statements are correct ?


(a) (i) ,(ii) are equal and (ii) , (iii) are not .
(b) (i) ,(ii) are equal and (i) , (iii) are not .
(c) (ii) ,(ii) are equal and (i) , (ii) are not .
(d) All are equal

Answer is given as (d) . .

But , my question is :
from (ii) (a /b ) : I can derive (a/) , which can give me (a)* . Isn't it so ?
From (i) ((a/b) : I can not separate a and b .
So , how can they all be equal ?

1. (a + b)*
2. (a* + b*)* =(a+b) *
3. ((null + a)b*)* = (b* + ab*)*
= ((null + b + bb + bbb + .....) + a(null + b + bb + bbb + .....))*
= (b + a + a(all string of b) + null + (all string of b except ))* //rearranging b*
= (a +b + rest) *
= (a + b)* as anything of rest or their combination is already included in (a+b) *
So all are equal.
-- Digvijay Pandey

Question on Regular expression - 2

top

Answer given as : e
But , my question is (P*Q*) * = {null string , any number of P , any number of Q , P followed by Q , }
whereas (P*+Q*)* = { null string , any number of P , any number of Q , P followed by Q , Q followed by P }
So , in the (P*Q*)* , Q followed by P is not possible . So , how they can be equal ?

(P*Q*)* = null + (P*Q*) + (P*Q*)(P*Q*) + (P*Q*)(P*Q*)(P*Q*) + .....


Now lets take (P*Q*)(P*Q*);
((NULL + P + PP ...)Q*)(P*(NULL + Q + QQ + QQQ ...)
// combine Q* and null from 1st bracket and P* and null from 2nd
= (Q*P*)
rearrange P*, Q* for other combination..
-- Digvijay Pandey

Which of the the languages are CFL ( and not )

top

Q 1.

My answer is (c) all are CFL ,


as in case of L1 , we can break it as an am c2m c2n : so we can compare using a stack
in case of L2 , we can compare either of them , so it is CFL
In case of L3 , it can also be resolved using a single stack . So , this is also CFL.

Q2.

Here in the question , S->aS | bS | a | b , my answer is (a+b)+ (b).


Am I correct in solving these questions ?

Q1.
L1 = {apc2p | p 0} is DCFL
L2 is CFL but not DCFL as we cannot deterministically check two unbounded conditions using a single check but the conditions being OR we
can do this non-deterministically.
L3 again is CFL but not DCFL. At every point we have two options- to equal the number of 0's or to double the number of 0's.

Q2.
Options b, c and d aren't same?

Q3. X-> aX|bX|a means anything ending with a that is (a+b)*a


Y -> Ya|Yb|a means anything start with a that is a(a+b)*
S->XY that is (a+b)*aa(a+b)*
in the given options , (d is fit. even though it is not same )
-- Arjun Suresh

proper non empty substrings

top

The maximum no of proper non empty sub-strings for the given 'n' length string is:
A)

n*(n+1)/2

- 1

B)

n*(n+1)/2

C)

n*(n+1)/2 + 1

D)

none of the above

I basically want a good explanation here for whatever option you choose???thanks in advance

<answer given as per coaching book is B>

take "abc" string. Sub strings are


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

a
b
c
ab
bc
abc

For a string of length n, we can have 1 sub-string of length n, 2 sub-strings of length n-1, 3 sub-strings of length n-2, ... n substrings of length
1. So, total no. of sub-strings = 1 + 2 + ... + n = n (n+1)/2
But the question asks for "proper" sub-strings. Proper sub-string means the given string (of length n) must not be counted. So, the answer
must be n(n+1)/2 - 1.
Ref: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/StringMatch/stringMatchIntro.htm
-- Arjun Suresh

regular expresstion matching

top

The regular expression 0*(10)* denotes the same set as:


A) (1*0)*1*
B) 0+(0+10)+
C) (0+1)*10(0+1)*
D) none of the above
well according to me in option A we can get 111111...(many no of one's) without the need of 0, but same is not the case with the original R.E
posted above, where in i have to get 0's in order to get 1's in my strings. <answer given is option A> what do you say guys??

A can generate "11" but given RE can't


B can generate "100" but given RE can't
C can generate "100" but given RE can't
So, answer must be D- none of these.
-- Arjun Suresh

Choose correct option top

The answer given is (d) .

But , in my opinion answer should be (a) . Am I wrong ? Please correct me.


CFLs are not closed under complement. So , how can the answer be (d) ?

A. is clearly CSL.

// CFL can do string matching in order likr WWr but not as WW

B. Power is quadratic . So it cant simulated by PDA .. LBA neede..


C. Again CSL. two infinite comparison on same variable 'n' simultaneously.. PDA cant simulate.
D. Yes complement of WW IS CFL.. How complement of CSL will be CFL ??
LET A be CFL & its complement is B which is CSL.. now some one asking what is complement of CSL 'B' ?? Obviously answer will be A
which is CFL only..
CFG for complement of WW :
Every odd length string will be in complement of WW.
S(odd) ----> 0A | 1A | 0 | 1
A ----> OS(odd) | 1S(odd)
Now for even length string :
S(even) ----> BC | CB
B ----> DBD | 0
C ----> DCD | 1
D ----> 0 | 1
-- Digvijay Pandey

Computer Networks top


GATE2012_10 top
The protocol data unit (PDU) for the application layer in the Internet stack is
(A) Segment
(B) Datagram
(C) Message
(D) Frame

(C) Message is answer.


For Application, Presentation and Session layers, the PDU is message
For Transport layer, PDU is segment for TCP and datagram for UDP
For Network layer, PDU is packet
For Datalink layer, PDU is frames
For physical layer, PDU is stream of bits
-- gatecse

If a organisation requires 30 hosts.which is the best possible mask that can be used?

Since organistation has 30 hosts, Class C network with /24 Prefix should be used since it can support 254 hosts.
Now there are 30 hosts, so the minimum number of bits required for host number is 5, since 2 5 2 is 30.
The rest of bits i.e 3 can be used as subnet number.
So the mask is 11111111.11111111.11111111.11100000
For reference have a look at http://andthatsjazz.org/wbglinks/pages/reads/misc/ip.html
-- Omesh Pandita

GATE1992_03,v top

Answer is C
-- saurabhrk

GATE2003_82 top
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.233
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

top

A and C are not the answers as the second byte of IP differs and subnet mast has 255 for second byte.
Consider B,
10.35.28.2 & 255.255.31.0 = 10.35.28.0 (28 = 11100)
10.35.29.4 & 255.255.31.0 = 10.35.29.0 (29 = 11111)
So, we get different subnet numbers
Consider D.
128.8.129.43 & 255.255.31.0 = 128.8.1.0 (129 = 10000001)
128.8.161.55 & 255.255.31.0 = 128.8.1.0 (161 = 10100001)
The subnet number matches. So, D is the answer.
-- Arjun Suresh

GATE2003_84 top
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. Acknowledgement 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
B. 11.11 106 bps
C. 12.33 106 bps
D. 15.00 106 bps

I think options are given in bytes per sec instead of bits per sec.
Transmission time =50 micro sec
Propagation time =200 micro sec
RTT= 50+2*200=450 microsec (Receiver can send an ACK as soon as the first packet is received)
total number of bits transmitted before first ACK is received = 1000x5x8 bits =40000 bits
After first ACK is received, same cycle of action repeats. So,
Throughput = (40000/450) x10^6 bits = 88.88x10^6 bits ps=11.11x10^6 bytes per sec
-- Parul Agarwal

GATE2004_15 top
Choose the best matching between Group 1 and Group 2
Group - 1

Group -2

1. Ensures reliable transport of data over a physical point-to-point


link
Q. Network layer 2. Encodes/decodes data for physical transmission
R.
Transport
3. Allows end-to-end communication between two processes
layer
4. Routes data from one network node to the next
P. Data link layer

A.
B.
C.
D.

P-1, Q-4, R-3


P-2, Q-4, R-1
P-2, Q-3, R-1
P-1, Q-3, R-2

ans a)
-- Aditi Dan

GATE2007_19 top
In Ethernet when Manchester encoding is used, the bit rate is:

A. Half the baud rate


B. Twice the baud rate
C. Same as the baud rate
D. None of the above

Bit rate is half the baud rate in Manchester encoding as bits are transferred only during a positive transition of the clock.
http://stackoverflow.com/questions/25834577/why-in-manchester-encoding-the-bit-rate-is-half-of-the-baud-rate
-- Arjun Suresh

GATE2007_70 top
Match the following:
(P)
(Q)
(R)

SMTP
BGP
TCP

(1)
(2)
(3)

Application layer
Transport layer
Data link layer

(S)

PPP

(4)
(5)

Network layer
Physical layer

P - 2, Q - 1, R - 3, S - 5
P - 1, Q - 4, R - 2, S - 3
P - 1, Q - 4, R - 2, S - 5
P - 2, Q - 4, R - 1, S - 3

I guess answer is (b) here.PPP is a data link layer protocol


https://docs.oracle.com/cd/E18752_01/html/816-4554/ipov-6.html
-- Madhur Rawat

GATE2009_57,58 top
Frames of 1000 bits are sent over a 106 bps duplex link between two hosts. The propagation time is 25ms. Frames are to be transmitted into
this link to maximally pack them in transit (within the link).
57. What is the minimum number of bits (I) 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. I=2
B. I=3
C. I=4

D. I=5
58. Suppose that the sliding window protocol is used with the sender window size of2 l , where I is the numbers of bits identified in the earlier
part and acknowledgements are always piggy backed. After sending 2 I 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.
B.
C.
D.

16ms
18ms
20ms
22ms

Bandwidth won't be halved in full duplex. http://superuser.com/questions/335979/does-1-gbit-s-port-in-full-duplex-mean-1-gbit-s-send-and-1gbit-s-receive


Propagation time is given as 25 ms.
Bandwidth = 106 bps.
So, to fully utilize the channel, we must send 106 bits into the channel in a second, which will be 1000 frames per second as each frame is
1000 bits. Now, since the propagation time is 25 ms, to fully pack the link we need to send at least 1000 * 25 * 10-3 = 25 frames. So, we need
log 2 25 = 5 bits.

58. I = 5, so 2I = 32 frames are sent.


Now, we need to get RTT (which is the time between which a frame is sent and its ACK is received), to determine the waiting time.
Transmission time (for a frame of size 1000 bits) = 1000/106 = 1 ms.
So, transmission time for 32 frames = 32 ms.
RTT = Propagation time for frame + Transmission time for frame + Propagation time for ACK + Transmission time for ACK
= 25 ms + 1 ms + 25 ms + 1 ms (ACK is piggy backed and assuming frame size for piggy backing is also 1000 bits)
= 52 ms
So, waiting time = 52 - 32 = 20 ms.
-- Arjun Suresh

GATE2005_23 top
Packets of the same session may be routed through different paths in:
A.
B.
C.
D.

TCP, but not UDP


TCP and UDP
UDP, but not TCP
Neither TCP nor UDP

b) TCP and UDP.


Routing happens in Network layer and hence has no dependency with the the transport layer protocols TCP and UDP. The transport layer
protocol- whether TCP or UDP is hidden to the router and the routing path is determined based on the the network configuration at the time
and hence can change even during a session.
-- Arjun Suresh

GATE2005_24 top
The address resolution protocol (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

ans d)
-- Aditi Dan

GATE2005_25 top
The maximum window size for data transmission using the selective reject protocol with n bit frame sequence numbers is:
(a) 2 n

(b) 2 n1

(c) 2 n 1

(d) 2 n2

ans b)
In selective reject protocol, the maximum window size must be half the sequence number space = n2/2 = 2n-1.
For Go-back n, the maximum window size can be 2n-1.
http://webmuseum.mi.fh-offenburg.de/index.php?view=exh&src=73
-- Aditi Dan

GATE2005_74 top
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.
B.
C.
D.

94
416
464
512

The sender must be able to detect a collision before completely sending a frame. So, the minimum frame length must be such that, before the
frame completely leaves the sender any collision must be detected.
Now, the worst case for collision detection is when the start of the frame is about to reach the receiver and the receiver starts sending.
Collision happens and a jam signal is produced and this signal must travel to the sender. So, the time for this will be propagation delay for the
start of the frame to reach near the receiver + propagation delay for the jam signal to reach the sender + transmission time for the jam signal.
(We don't need to include propagation time for the frame as as soon as the first bit of the frame arrives, the receiver will have detected it). So,
this will be
2 * 46.4/2 + 48/10 (48 bits at 10 Mbps takes 4.8 micro sec.) = 51.2 s.
Now, the frame length must be such that its transmission time must be more than 51.2 s. So, minimum frame length
= 51.2 * 10 = 512 bits.
http://gatecse.in/w/images/3/32/3-MACSublayer.ppt
-- Arjun Suresh

GATE2014-1_24 top
Which of the following are used to generate a message digest by the network security protocols?
(P) RSA

(Q) SHA-1

(A) P and R only


(B) Q and R only
(C) Q and S only

(R) DES

(S) MD5

(D) R and S only

RSA and DES are used for Encryption where MD5 and SHA 1 are used to generate Message
Digest.
-- Shiva Chaitanya Gajula

GATE2014-1_26 top
Consider a token ring network with a length of 2 km having 10 stations including a monitoring station. The propagation speed of the signal is
2 108 m/s and the token transmission time is ignored. If each station is allowed to hold the token for2sec , the minimum time for which the
monitoring station should wait (in sec ) before assuming that the token is lost is _______.

Time required to complete one cycle=Tp (Ring Latency) +N*THT


= 2km/(2*108 m/s) +10*2
= 10 + 10 * 2 = 30 s
where THT is token holding time .
-- Rajat Sharma

GATE2014-1_27 top
Let the size of congestion window of a TCP connection be 32 KB when a timeout occurs. The round trip time of the connection is 100 msec and the maximum
segment size used is 2 KB. The time taken (in msec) by the TCP connection to get back to 32 KB congestion window is _________.

Ans: Given that at the time of Time Out, Congestion Window Size is 32KB and RTT = 100ms ,
When Time Out occurs, for the next round of Slow Start, Threshold = (size of Cwnd) / 2 ,
It means Threshold = 16KB
So , we have Slow start ==>> 2KB | 4KB | 8KB | 16KB (now threshold reaches so Additive increase starts) | 18KB | 20KB | 22KB |
24KB | 26KB | 28KB | 30KB | 32KB
So, in above number of | (vertical line) is represented by RTT so total number of vertical line is 11 * 100ms ==>> 1100 msec is
Answer...

-- Jayesh Malaviya

GATE2006_46 top
Station A needs to send a message consisting of 9 packets to Station B using a sliding 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
(D) 18

Since all packets are ready initially itself, we can assume a timeout is detected after all possible packets are sent. So, the sending happens as
shown in figure (I draw the figure assuming 10 packets. For 9 packets answer will be 16).

-- Arjun Suresh

GATE2011_2

top

A layer-4 firewall (a device that can look at all protocol headers up to the transport layer) CANNOT

(A) block entire HTTP traffic during 9:00PM and 5:00AM


(B) block all ICMP traffic
(C) stop incoming traffic from specific IP address but allow outgoing traffic to the same IP address
(D) block TCP traffic from a specific user on a multi-user system during 9:00PM to 5:00AM

Answer is (D).
(A) It is POSSIBLE to block "entire" HTTP traffic by blocking all the traffic on port number 80 Since here we DON'T need to check anything that is application layer specific. We only need to
block port no 80 for required time span.
(B) & (C) are fairly possible to achieve.
(D) However (D) is not possible to achieve although the service uses TCP at transport layer. But see the question. We dont need to block entire TCP traffic so we cant block any specific
PORT number. Also it is given that IT IS MULTI- USER System and so many user may be using same port for communication. Therefore blocking that port would block all the users WHILE
we want a specific user. So how to do that. To do so we need Application layer specific information of the user like user_id type of things which cant be checked as it is 4-layer firewall.
So it is not possible to allow other users and block some specific at the same time using a 4-layer firewall (unless they all be using different port numbers which we actually cant predict).

-- Sandeep_Uniyal

GATE2010_15 top

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.

It can be used to prevent packet looping.

-- Sankaranarayanan P.N

GATE1995_1.12 top
What is the distance of the following code 000000, 010101, 000111, 011001, 111111?
A.
B.
C.
D.

2
3
4
1

Distance (also called min-distance) of a block code is the minimum number of positions in which any two distinct codes differ. Here, mindistance occurs for the codes 2 and 3 and they differ only in 2 positions. So, d = 2.
https://en.wikipedia.org/wiki/Block_code
-- Arjun Suresh

GATE2008-IT_65 top
8m/s
The minimum frame size required for a CSMA/CD based computer network running at 1 Gbps on a 200m cable with a link speed of 2 10
is

A)

125 bytes

B)

250 bytes

C)

500 bytes

D)

None of the above

Minimum frame size is needed to ensure that collisions are detected properly. The minimum frame size ensures that before a frame is
completely send, it would be notified of any possible collision and hence collision detection works perfectly.
In CSMA/CD a sender won't send a packet if it senses that another sender is using it. So, assume a sender A and a receiver B. When sender
sends a packet, receiver might use the cable until it is notified that a packet is being send to it. The receiver will be notified as soon as the first
bit arrives that a packet is coming and it won't send any packet after this until that packet is finished. So, in the worst case for collision,
receiver will transmit a packet back to the sender just before the first bit of the packet reaches it. (If t d is the propagation delay of the channel,
this time would be just t d ). In this case, surely there will be collision. But for the sender to detect it, it should be notified of B's packet before
the sending of the first packet finishes. i.e., when B's packet arrives at A (takes another t d time), A shouldn't have finished transmission of the
first packet for it to detect a collision. i.e., A should be still continuing the sending of the packet in this time interval of 2 t d . Thus,
The amount of bits that can be transmitted by A in 2 t d time should be less than the frame size (S) (sending of the frame shouldn't finish in
this time)
Amount of bits transmitted in time t is bandwidth t and propagation delay- t d is
So, S 2 bandwidth t d

2 109
2000 bits

200
2108

distance
link speed

250 bytes
-- Arjun Suresh

GATE2008-IT_70 top
The total number of keys required for a set ofn individuals to be able to communicate with each other using secret key and public key
cryptosystems, respectively are:

A)

n(n-1) and 2n

B)

2n and ((n(n - 1))/2)

C)

((n(n - 1))/2) and 2n

D)

((n(n - 1))/2) and n

For private key crypto for communication between each pair of individuals on secret key will be required, so if a individual wants to
communicate with other n-1 individuals he should have n-1 secret keys, so the total number of secret keys for private encryption is n*(n-1).
For public key encryption each individual needs to have a public and private key, so the total keys required in 2*n
So the answer is A) n(n-1) and 2n
-- Omesh Pandita

GATE2008-IT_85 top
Host X has IP address 192.168.1.97 and is connected through two routers R1 and R2 to another host Y with IP address 192.168.1.80. Router
R1 has IP addresses 192.168.1.135 and 192.168.1.110. R2 has IP addresses 192.168.1.67 and 192.168.1.155. The netmask used in the
network is 255.255.255.224.
Which IP address should X configure its gateway as?

1)

192.168.1.67

2)

192.168.1.110

3)

192.168.1.135

4)

192.168.1.155

X must be able to reach the gateway using the net mask.


Subnet number of host X = 192.168.1.97 & 255.255.255.224 =192.168.1.96
Now, the gateway must also have the same subnet number.
255.255.255.224 =192.168.1.96 and hence this can be used by X.

Lets

take

IP

192.168.1.110

of

R1.

192.168.1.110

&

(To quickly identify the matching mask divide the last part of mask (224 here) into powers of 2. So, 224 = 128 + 64 + 32. Now, our host X has
97 as the last part of IP = 64 + 32 + 1. So, the last part of subnet number becomes 64 +32 =96. Now, we need to consider only those IPs
whose last part will contain 64 as well as 32)
http://courses.washington.edu/css432/joemcc/slides/03_cidr.ppt
-- Arjun Suresh

GATE2007-IT_64 top
A broadcast channel has 10 nodes and total capacity of 10 Mbps. It uses polling for medium access. Once a node finishes transmission, there
is a polling delay of 80 s to poll the next node. Whenever a node is polled, it is allowed to transmit a maximum of 1000 bytes. The maximum
throughput of the broadcast channel is

1)

1 Mbps

2)

100/11 Mbps

3)

10 Mbps

4)

100 Mbps

Propagation time is not given so that's negligible here.


efficiency = transmission time/(transmission time + polling time)
Tx=1000 bytes/10Mbps =800s.
Delay because of polling is = 80 s
Efficiency of channel , e =transmission delay/ (total delay) =800/(800+80)= 10/11
Maximum throughput is =(10/11) * 10 Mbps= 100/11 Mbps
-- Manu Thakur

GATE2006-IT_70 top
A subnetted Class B network has the following broadcase address : 144.16.95.255. Its subnet mask

A)

is necessarily 255.255.224.0

B)

is necessarily 255.255.240.0

C)

is necessarily 255.255.248.0.

D)

could be any one of 255.255.224.0, 255.255.240.0, 255.255.248.0

option (D) is correct. In the broadcast address for a subnet, all the host bits are set to 1. So as long as all the bits to the right are 1, bits left to
it can be taken as possible subnet.
broadcast address for subnet is .95.255 .0101 1111. 1111 1111 (as in Class B, 16 bits each are used for network and host)
So we can take minimum 3 bits (from left) as subnet and make rest as host bits(as they are 1).

.224.0

1110 0000. 0000 0000 (leftmost 3 bits for subnet)

.240.0

1111 0000. 0000 0000 (leftmost 4 bits for subnet)

.248.0

1111 1000. 0000 0000 (...

5 bits for subnet )

-- Sandeep_Uniyal

GATE2004-IT_25 top
A sender is employing public key cryptography to send a secret message to a receiver. Which one of the following statements is TRUE?
A)

Sender encrypts using receiver's public key

B)

Sender encrypts using his own public key

C)

Receiver decrypts using sender's public key

D)

Receiver decrypts using his own public key

A) Sender encrypts using receiver's public key


-- Omesh Pandita

GATE2004-IT_26 top
A subnet has been assigned a subnet mask of 255.255.255.192. What is the maximum number of hosts that can belong to this subnet?
A)

14

B)

30

C)

62

D)

126

C is answer since you have 6 zeroes so u can make 64-2 hosts

-- Shreyans Dhankhar

GATE2004-IT_27 top
A host is connected to a Department network which is part of a University network. The University network, in turn, is part of the Internet. The
largest network in which the Ethernet address of the host is unique is

A)

the subnet to which the host belongs

B)

the Department network

C)

the University network

D)

the Internet

Ans is D, Ethernet address is nothing but MAC Address which is present on NIC and it is unique for every system.
-- Pradyumna Paralikar

GATE2004-IT_28 top
In TCP, a unique sequence number is assigned to each

A)

byte

B)

word

C)

segment

D)

message

a) it should be byte
http://www.industrialethernetu.com/courses/202_2.htm
-- Parul Agarwal

GATE2004-IT_45 top
A serial transmission T1 uses 8 information bits, 2 start bits, 1 stop bit and 1 parity bit for each character. A synchronous transmission T2 uses
3 eight-bit sync characters followed by 30 eight-bit information characters. If the bit rate is 1200 bits/second in both cases, what are the transfer
rates of T1 and T2?

A)

100 characters/sec, 153 characters/sec

B)

80 characters/sec, 136 characters/sec

C)

100 characters/sec, 136 characters/sec

D)

80 characters/sec, 153 characters/sec

1. T1: 1 char. = ( 8 + 2 + 1 + 1) = 12 bit


Transfer Rate = 1200/12 = 100 char/sec.
T2: Transfer character in bits = 24 + 240 = 264 bits
In 264 = 30 character
Then 1200 = ?
264/30 = 1200/X
X = 136.3 character / sec.
so correct option is (C)
-- Shreyans Dhankhar

GATE2004-IT_80 top
In a data link protocol, the frame delimiter flag is given by 0111. Assuming that bit stuffing is employed, the transmitter sends the data
sequence 01110110 as

A)

01101011

B)

011010110

C)

011101100

D)

0110101100

Answer will be option D.)


The bit stuffing is done after every two '11' (as flag is 0111) to differentiate the data part from the flag- there must not be "111" in the data so
after every 11 a '0' is added. The receiver also knows this and so it decodes every "110" as "11". Therefore option D. is the answer.
http://web.nchu.edu.tw/~pcwang/computer_networks/data_link_layer.pdf
https://en.wikipedia.org/wiki/High-Level_Data_Link_Control
-- Gate Keeda

GATE2004-IT_81 top
In a sliding window ARQ scheme, the transmitter's window size is N and the receiver's window size is M. The minimum number of distinct
sequence numbers required to ensure correct operation of the ARQ scheme is

A)

min (M, N)

B)

max (M, N)

C)

M+N

D)

MN

C) M+N
Because Ws+Wr Sequence numbers (as the maximum number of unacknowledged packets at sender will be Ws and at the receiver it will
be Wr, similar to the sequence numbering in Selective Repeat)
where Ws is size of sender window and Wr is receiver window's size.
-- Parul Agarwal

GATE2004-IT_86 top
In the TCP/IP protocol suite, which one of the following is NOT part of the IP header?

A)

Fragment Offset

B)

Source IP address

C)

Destination IP address

D)

Destination port number

D.) Destination Port number.


Why? Because the IP header has nothing to do with the port number.
Port numbers are used by the transport layer to ensure process to process delivery.
-- Gate Keeda

GATE2005-IT_25 top
Consider the three commands : PROMPT, HEAD and RCPT.
Which of the following options indicate a correct association of these commands with protocols where these are used?

A)

HTTP, SMTP, FTP

B)

FTP, HTTP, SMTP

C)

HTTP, FTP, SMTP

D)

SMTP, HTTP, FTP

RCPT->Recipient to,As the name suggest it is used in SMTP(Simple Mail Transfer protocol)
HEAD->this is used in HTTP to get the meta-information,to decide the category of packet.
Prompt->turns off prompting for individual files when using the mget or mput commands
-- nagalla pruthvi

GATE2005-IT_26 top
Traceroute reports a possible route that is taken by packets moving from some host A to some other host B. Which of the following options
represents the technique used by traceroute to identify these hosts

1) By progressively querying routers about the next router on the path to B using ICMP packets, starting with the first router
2)

By requiring each router to append the address to the ICMP packet as it is forwarded to B. The list of all routers en-route to B is returned by
B in an ICMP reply packet

3) By ensuring that an ICMP reply packet is returned to A by each router en-route to B, in the ascending order of their hop distance from A
4) By locally computing the shortest path from A to B

A) Traceroute works by sending packets with gradually increasing TTL value, starting with TTL value of 1. The first router receives the packet, decrements the
TTL value and drops the packet because it then has TTL value zero. The router sends an ICMP Time Exceeded message back to the source. The next set of
packets are given a TTL value of 2, so the first router forwards the packets, but the second router drops them and replies with ICMP Time Exceeded. Proceeding
in this way, traceroute uses the returned ICMP Time Exceeded messages to build a list of routers that packets traverse, until the destination is reached and
returns an ICMP Echo Reply message

-- Shaun Patel

GATE2005-IT_71 top
A network with CSMA/CD protocol in the MAC layer is running at 1 Gbps over a 1 km cable with no repeaters. The signal speed in the cable is
2 x 10 8 m/sec. The minimum frame size for this network should be

A)

10000 bits

B)

10000 bytes

C)

5000 bits

D)

5000 bytes

Minimum frame size is needed to ensure that collisions are detected properly. The minimum frame size ensures that before a frame is
completely send, it would be notified of any possible collision and hence collision detection works perfectly.
In CSMA/CD a sender won't send a packet if it senses that another sender is using it. So, assume a sender A and a receiver B. When sender
sends a packet, receiver might use the cable until it is notified that a packet is being send to it. The receiver will be notified as soon as the first
bit arrives that a packet is coming and it won't send any packet after this until that packet is finished. So, in the worst case for collision,
receiver will transmit a packet back to the sender just before the first bit of the packet reaches it. (If t d is the propagation delay of the channel,
this time would be just t d ). In this case, surely there will be collision. But for the sender to detect it, it should be notified of B's packet before
the sending of the first packet finishes. i.e., when B's packet arrives at A (takes another t d time), A shouldn't have finished transmission of the
first packet for it to detect a collision. i.e., A should be still continuing the sending of the packet in this time interval of 2 t d . Thus,

The amount of bits that can be transmitted by A in 2 t d time should be less than the frame size (S) (sending of the frame shouldn't finish in
this time)
Amount of bits transmitted in time t is bandwidth t and propagation delay- t d is

distance
link speed

So, S 2 bandwidth t d

2 109

1000
2108

10000 bits
-- Arjun Suresh

GATE2005-IT_73 top
On a TCP connection, current congestion window size is Congestion Window = 4 KB. The window size advertised by the receiver is Advertise
Window = 6 KB. The last byte sent by the sender is LastByteSent = 10240 and the last byte acknowledged by the receiver is LastByteAcked =
8192. The current window size at the sender is

A)

2048 bytes

B)

4096 bytes

C)

6144 bytes

D)

8192 bytes

Answer is (A)
Current Sender window = min (Congestion Window, Advertised Window)= min(4KB, 6KB)= 4B
Unacknowledged Bytes= 10240 - 8192 = 2048 Bytes =2 KB
Since 2KB data is unacknowledged it can send only (Current window- Unacknowledged Bytes)= 4KB- 2KB =2KB = 2048 Bytes
-- Sandeep_Uniyal

GATE2015-2_20 top
Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIX socket API.

A.
B.
C.
D.

listen, accept, bind, recv


bind, listen, accept, recv
bind, accept, listen, recv
accept, listen, bind, recv

Answer: B
Bind: Binds the socket to an address
Listen: Waits for connections to the socket
Accept: Accepts a connection to the socket
Recv: Receives data from connection
From Man page of accept:
It extracts the first connection request on the queue of pending connections for the listening socket, creates a new connected socket, and
returns a new file descriptor referring to that socket. The newly created socket is not in the listening state. The original socket is unaffected
by this call

-- Jon Snow

GATE2015-2_34 top

Assume that the bandwidth for a TCP connection is 1048560 bits/sec. Let be the value of RTT in milliseconds (rounded off to the nearest
integer) after which the TCP window scale option is needed. Let be the maximum possible window size with window scale option. Then the
values of and are

A.
B.
C.
D.

63 milliseconds, 65535 2 14
63 milliseconds, 65535 2 16
500 milliseconds, 65535 2 14
500 milliseconds, 65535 2 16

In TCP when the bandwidth delay product increases beyond 64K receiver window scaling is needed.
The bandwidth delay product is the maximum amount of data on the network circuit at any time and is measured as RTT * Bandwidth. This is
not the time for sending data rather just the time for sending data without acknowledgement.
So, here, we have bandwidth delay product = (1048560 / 8) B * = 64 K
= (64 K * 8 ) / 1048560 = 0.5 s = 500 milliseconds.
When window scaling happens, a 14 bit shift count is used in TCP header. So, the maximum possible window size gets increased from 16
21 to (216-1) * 214 or from 65535 to 65535 * 214
http://en.wikipedia.org/wiki/TCP_window_scale_option
-- Arjun Suresh

GATE2015-1_17 top
In one of the pairs of protocols given below , both the protocols can use multiple TCP connections between the same client and the server.
Which one is that?
A.
B.
C.
D.

HTTP, FTP
HTTP, TELNET
FTP, SMTP
HTTP, SMTP

SMTP: only one TCP connection


Ref: https://tools.ietf.org/html/rfc821
Telnet: only one TCP connection
Ref: https://tools.ietf.org/html/rfc854
HTTP: Multiple connections can be used for each resource
Ref: http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1
FTP: FTP uses Telnet protocol for Control info on a TCP connection and another TCP connection for data exchange
Ref: https://tools.ietf.org/html/rfc959 (See page 8)
So, answer is A.
-- Arjun Suresh

GATE2015-1_19 top
Suppose two hosts use a TCP connection to transfer a large file . Which of the following statements is/are FALSE with respect to the TCP
connection?
I. If the sequence number of a segment is m, then the sequence number of the subsequent segment is always m+1.
II. If the estimated round trip time at any given point of time is t sec, the value of the retransmission timeout is always set to greater than or
equal to t sec.
III. The size of the advertised window never changes during the course of the TCP connection.
IV. The number of unacknowledged bytes at the sender is always less than or equal to the advertised window.

A.
B.
C.
D.

III only
I and III only
I and IV only
II and IV only

Option B
III. False. It is the size of the receiver's buffer that's never changed. RcvWindow is the part of the receiver's buffer that's changing all the time
depending on the processing capability at the receiver's side and the network traffic.
http://web.eecs.utk.edu/~qi/teaching/ece453f06/hw/hw7_sol.htm
-- GATERush

GATE2015-1_22 top
Which of the following fields of an IP header is NOT modified by a typical IP router?
A.
B.
C.
D.

Check sum
Source address
Time to Live (TTL)
Length

Source Address.
-- Arjun Suresh

GATE2015-2_52 top
Host A sends a UDP datagram containing 8880 bytes of user data to host B over an Ethernet LAN. Ethernet frames may carry data up to 1500
bytes (i.e. MTU = 1500 bytes). Size of UDP header is 8 bytes and size of IP header is 20 bytes. There is no option field in IP header. How
many total number of IP fragments will be transmitted and what will be the contents of offset field in the last fragment?

A.
B.
C.
D.

6 and 925
6 and 7400
7 and 1110
7 and 8880

Ans C
number of fragments = ceil(8888/1480) = 7
offset of last fragment = (1500 - 20) * 6 / 8 = 1110 (scaling factor of 8 is used in offset field).
TCP or UDP header will be added to the DataUnit received from Transport Layer to Network Layer. And fragmentation happens at Network
Layer. So no need to add TCP or UDP header into each fragment.
-- Vikrant Singh

GATE2015-1_53 top
Suppose that the stop-and-wait protocol is used on a link with a bit rate of 64 kilobits per second and 20 milliseconds propagation delay.
Assume that the transmission time for the acknowledgement and the processing time at nodes are negligible. Then the minimum frame size in
bytes to achieve a link utilization of at least 50% is_________________.

Link Utilization = Amount of data sent/Max. amount of data that could be sent.
Let x be the frame size in bits.
In stop-and-wait protocol, once a frame is sent, next frame won't be sent until ACK is received. Time for this,
RTT = Propagation delay for frame + Transmission time for frame + Propagation delay for ACK + Transmission time for ACK
= 20 ms + x /64 ms + 20 ms + 0(as given in question)
= (40 + x/64) ms.

Amount of data sent during RTT = x


Max. amount of data that could be sent = (40 + x/64) * 64 = 2560 + x bits.
So, link utilization, 0.5 = x/(2560 + x)
x = 2560 bits = 320 bytes.
-- Arjun Suresh

GATE2015-3_6 top
Consider a CSMA/CD network that transmits data at a rate of 100 Mbps (108 bits per second) over a 1 km (kilometer) cable with no repeaters.
If the minimum frame size required for this network is 1250 bytes, what is the signal speed (km/sec) in the cable?

A.
B.
C.
D.

8000
10000
16000
20000

For collision to be detected, the frame size should be such that the transmission time of the frame should be greater than twice the
propagation delay (So, before the frame is completely sent, any possible collision will be discovered).
So, 1250 * 8 /(108) >= 2 * 1 / x
x = 2 * 104 = 20000
-- Arjun Suresh

GATE2015-3_22 top
Consider the following statements.
I. TCP connections are full duplex
II. TCP has no option for selective acknowledgement
III. TCP connections are message streams

A.
B.
C.
D.

Only I is correct
Only I and III are correct
Only II and III are correct
All of I, II and III are correct

answer is (A) since TCP has options for selective ACK and TCP uses byte streams that is every byte that is send using TCP is numbered.
http://repo.hackerzvoice.net/depot_madchat/ebooks/TCP-IP_Illustrated/tcp_tran.htm
-- Tamojit Chatterjee

GATE2015-3_28 top
Consider a network connecting two systems located 8000 kilometers apart. The bandwidth of the network is 500 106 bits per second. The
propagation speed of the media is 4 106 meters per second. It is need to design a Go-Back-N sliding window protocol for this network. The
average packet size is 107 bits. The network is to be used to its full capacity. Assume that processing delays at nodes are negligible. Then, the
minimum size in bits of the sequence number field has to be ______.

Answer = 8 bits
In order to achieve full utilization, sender has to keep on sending frames till the acknowledgement arrives for the first frame.
Time taken for acknowledgement to arrive is 2 times propagation delay + transmission time for a frame.

One way propagation time = 8000x10^3 / (4x10^6)


= 2 secs
Time taken to transmit one frame = 10^7/(500x10^6)
=0.02 secs
So, RTT = 2 * 2 = 4
No of frames that can be transmitted in 4 secs = 4/0.02
=200
Hence minimum number of bits required for sequence numbers till 200 is 8 (as 2^8 = 256)
-- overtomanu

GATE2015-3_38 top
In the network 200.10.11.144/27, the fourth octet (in decimal) of the last IP address of the network which can be assigned to a host is _____.

Answer=158
144 in binary = 100 10000
out of this 3 bits in left are subnet bits. (27 bits are used for subnet, which means top 3 bytes and leftmost 3 bits from the last byte)
so the 4th octet in the last ip address of the network which can be assigned to a host is 100 11110. (its not 100 11111 because its network
broadcast address)
so 10011110 is 158 in decimal.
-- overtomanu

networks top
Monitor is an example of which of the following communication mode?
Response:
Simplex
Half duplex
Full duplex
None of these

I think It is simplex.
As Simplex is a one way communication
half duplex is a two way communication but one way at a time not simultaneous (eg. as walkie-talkie over and out)
full duplex is a two way communication simultaneously , as we talk over mobile
-- Praveen Saini

Digital Logic top


GATE2012_6

top

The truth table


X

(X,Y)

represents the Boolean function


(A) X
(B) X + Y
(C) X Y
(D) Y

Whenever X is true (X, Y ) is true and whenever X is false (X, Y ) is false, so the answer is (A) X .
-- Omesh Pandita

GATE2012_7

top

The decimal value 0.5 in IEEE single precision floating point representation has
(A) fraction bits of 000000 and exponent value of 0
(B) fraction bits of 000000 and exponent value of 1
(C) fraction bits of 100000 and exponent value of 0
(D) no exact representation

(B) is the answer. In IEEE uses normalized representation and hence an implicit '1' is used before the decimal point. So, if mantissa is
0000..0
it would be treated as
1.000..0
and hence the exponent need to be -1 for us to get 0.1 which is the binary representation of 0.5.
More into IEEE floating point representation:
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
-- gatecse

GATE2012_19 top
The amount of ROM needed to implement a 4 bit multiplier is
(A) 64 bits
(B) 128 bits
(C) 1 Kbits
(D) 2 Kbits

A ROM cannot be written. So, to implement a 4 bit multiplier we must store all the possible combinations of 2 4 2 4 input bits and 8 output bits

giving a total of 2 4 2 4 8 bits = 2048 bits. So, (D) is the answer.


-- Arjun Suresh

GATE1991,05,c top
Find the maximum clock frequency at which the counter(given in figure) can be operated. Assume that the propagation delay through each flipflop and AND gate is 10ns. Also assume that the setup time for the JK inputs of the flip-flops is negligible.

In a JK flip flop the output toggles when both J and K inputs are 1. So, we must ensure that with each clock the output from the previous stage
reaches the current stage. From the figure, there is an AND gate between each stage and 2 10 = 20ns (10ns for output to reach the gate
and 10ns for the output of AND gate to reach the next flipflop) is needed for the output to reach the next stage. So, minimum time period
needed for of clock is 20ns which would mean a maximum clock frequency of

1/20GHz = 50MHz
-- Arjun Suresh

GATE2005_62 top
Consider the following circuit involving a positive edge triggered D FF.

D = AX + X'Q'
Y=D
Ai represent the logic level on the line A at the i-th clock period. If we see the timing diagram carefully, we can see that during the rising edge,
the output Y is determined by the X value just before that rising edge. i.e., during the rising edge say for clk2, X value that determines the

output is 1 and not 0 (because it takes some propagation delay for the 0 to reach the flip flop). Similarly, the A output that determines the
output for clk i, is Ai-1
For clk1, X is 1, so, D = A = A0
For clk2, X is 1, so D = A = A1
For clk 3, X is 0, so D = Q2' = A1'
For clk4, X is 1, so D = A = A3
For clk5, X is 1, so D = A = A4
So, answer is A choice.
-- Arjun Suresh

GATE2008_6

top

= 11 , is/are
Let r denote number system radix. The only value(s) of r that satisfy the equation
121
r
(A) decimal 10
(B) decimal 11
(C) decimal 10 and 11
(D) any value > 2

Check by substituting all the options given satisfies above relation. (D) is the most appropriate answer
-- Keith Kr

GATE2008_8

top

Given f 1 , f 3 and f in canonical sum of products form (in decimal) for the circuit

f 1 = m(4, 5, 6, 7, 8)
f 3 = m(1, 6, 15)
f = m(1, 6, 8, 15)
then f 2 is

A. m(4, 6)
B. m(4, 8)
C. m(6, 8)
D. m(4, 6, 8)

answer - C
with AND gates we will choose intersection of min-terms
with OR gates we will take union of min-terms
-- ankitrokdeonsns

GATE2008_26 top
If P , Q, R are Boolean variables, then

)(P . Q
+ P . R)(P . R
+Q
) simplifies to
(P + Q

A. P . Q

B. P . R
+R
C. P . Q
+Q
D. P . R

Ans is (A) P Q
)(P Q
+ P R)(P R
+Q
)
(P + Q
+ PPR + PQ
+ PQ
R)(P R
+Q
)
= (P P Q
+ PR + PQ
+ PQ
R)(P R
+Q
)
= (P Q
+ PQ
R
+ PQ
R
= PQ
+ PQ
(R
+ R)
= PQ
+ PQ

= PQ

= PQ
-- Keith Kr

GATE1991_01,iii

top

Hex representation of given no. is (9753)16


Its binary representation is (1001 0111 0101 0011)2
The no. of 1's is 9
-- Keith Kr

GATE1992_02,i top

answer - D
-- ankitrokdeonsns

GATE2000_1.6

top

The number 43 in 2's complement representation is


A.
B.
C.
D.

01010101
11010101
00101011
10101011

2's complement representation is not same as 2's complement of a number. In 2's complement representation positive integers are
represented in its normal binary form while negative numbers are represented in its 2's complement form. So (c) is correct here.
http://www.ele.uri.edu/courses/ele447/proj_pages/divid/twos.html
-- Arjun Suresh

GATE2000_2.14 top
Consider the values of A = 2.0 x 1030 , B = -2.0 x 10 30 , C = 1.0, and the sequence
X:= A + B
X:= X + C

Y:= A + C
Y:= Y + B

executed on a computer where floating point numbers are represented with 32 bits. The values for X and Y will be

a.
b.
c.
d.

X = 1.0, Y = 1.0
X = 1.0, Y = 0.0
X = 0.0, Y = 1.0
X = 0.0, Y = 0.0

Given 32 bits representation. So, the maximum precision can be 32 bits (In 32-bit IEEE representation, maximum precision is 24 bits but we
take best case here). This means approximately 10 digits.
A = 2.0 * 1030, C = 1.0
So, A + C should make the 31st digit to 1, which is surely outside the precision level of A (it is 31st digit and not 31st bit). So, this addition will
just return the value of A which will be assigned to Y.
So, Y + B will return 0.0 while X + C will return 1.0.
B choice.
Sample program if any one wants to try:
#include<stdio.h>
int main()
{
float a = 2.0e30;
float b = -2.0e30;
float c = 1.0;
float y = a+c;
printf("a = %0.25f y = %0.25f\n",a, y);
y = y + b;
float x = a + b;
printf("x = %0.25f\n",x);
x = x + c;
printf("x = %0.25f\n",x);
}

-- Arjun Suresh

GATE2001_1.11 top
Given the following karnaugh map, which one of the following represents the minimal Sum-Of-Products of the map?

(A) XY + Y Z
(B) W X Y + XY + XZ
(C) W X + Y Z + XY
(D) XZ + Y

answer - A
-- ankitrokdeonsns

GATE2001-2.10

top

The 2's complement representation of (-539)10 in hexadecimal is


(a) ABE
(b) DBC
(c) DE5
(d) 9E7

539 = 512 + 16 + 8 + 2 + 1 = 29 + 24 + 23 + 21 + 20
= (1000011011)2
Now all answers have 12 bits, so we add two 0's at beginning = (001000011011)2
To convert to 2's complement invert all bits till the rightmost 1, which will be (110111100101)2
= (1101 1110 0101)2
= (DE5)16
-- Arjun Suresh

GATE2001.2.11 top
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
(B) f = X1 X2 + X1X2
(C) f = X1X2 + X1 X2
(D) f = X1 + X2

g = x1'
So, f = ac' + bc
= x1'x2' + x1x2
So, (C).
-- Arjun Suresh

GATE2001_2.12 top
Consider the circuit given below with initial state Q 0 = 1, Q 1 = Q 2 = 0 . The state of the circuit is given by the value4Q 2 + 2Q 1 + Q 0

Which one of the following is correct state sequence of the circuit?

A.
B.
C.
D.

1, 3, 4, 6, 7, 5, 2
1, 2, 5, 3, 7, 6, 4
1, 2, 7, 3, 5, 6, 4
1, 6, 5, 7, 2, 3, 4

Q0 = Q1prev Q2prev

Q1 = Q0prev

Q2 = Q1prev

State = 4Q2 + 2Q1+Q0


So, state sequence = 1, 2, 5, 3, 7, 6, 4
-- Arjun Suresh

GATE2003_44 top
A 1-input, 2-output synchronous sequential circuit behaves as follows:
Let zk , n k denote the number of 0s and 1s respectively in initialk bits of the input

(zk + n k = k). The circuit outputs 00 until one of the following conditions holds.
zk n k = 2 . In this case, the output at thek-th and all subsequent clock ticks is 10.
n k zk = 2 . In this case, the output at thek-th and all subsequent clock ticks is 01.

What is the minimum number of states required in the state transition graph of the above circuit?
A.
B.
C.
D.

5
6
7
8

Though the question is from digital logic, answer is purely from automata. As per question, we just need to count the difference of the number
of 0's and 1's in the first k bit of a number. And we just need to count till this count reaches 2 or -2 (negative when number of 0's is less than
number of 1's) . So, the possibilities are -2, -1, 0, 1 and 2 which represents the five states of the state transition diagram.
For state -2, the output of the circuit will be 01, for state 2, output will be 10 (both these states not having any outgoing transitions) and for
other 3 states, output will be 00 as per the given description of the circuit.
-- gatecse

GATE2009_5

top

(1217)8 is equivalent to

A.
B.
C.
D.

(1217)16
(028F )16
(2297)10
(0B17)16

Answer is B.

-- Praneeth A S

GATE2005_16 top
The range of integers that can be represented by an n bit 2s complement number system is:

A. 2 n1 to (2 n1 1)
B. (2 n1 1) to (2 n1 1)
C. 2 n1 to 2 n1
D. (2 n1 + 1) to (2 n1 1)

answer - A
-- ankitrokdeonsns

GATE2005_17 top
The hexadecimal representation of 6578 is:
(a) 1AF

(b) D78
(c) D71
(d) 32F

6578 = (110 101 111)2 = (1 [10 10] [1 111])2 =(1AF)16


-- Arjun Suresh

GATE2005_64 top
Consider the following circuit:

The flip-flops are positive edge triggered D FFs. Each state is designated as a two-bit stringQ 0 Q 1 . Let the initial state be 00. The state
transition sequence is

A.
B.
C.
D.

Clearly Q0 alternates in every clk cycle as Q0' is fed as input and it is D flipflop.
Q1 becomes 1 either if its prev value is 0, or if Q0 is 1.
So, the sequence of transitions will be 00 -> 11 -> 00 -> (B) choice.
-- Arjun Suresh

GATE2013_5

top

In the following truth table, V = 1 if and only if the input is valid.

Inputs

Outputs

D0

D1

D2

D3

X0

X1

What function does the truth table represent?


(A) Priority encoder

(B) Decoder

(C) Multiplexer

(D) Demultiplexer

Answer is A.
For
http://en.wikipedia.org/wiki/Priority_encoder
-- Praneeth A S

GATE1999_2.16 top

answer - B
for LSB addition we do not need a full adder
for addition of subsequent bits we need full adders since carry from previous addition has to be fed into the addition operation
-- ankitrokdeonsns

GATE1999_2.17 top
Zero has two representations in
A.
B.
C.
D.

Sign magnitude
2's complement
1's complement
None of the above

-0 and 0 in 1's complement that is why the range is -2^n-1 to 2^n-1


-- Bhagirathi Nayak

GATE1998_1.14 top

for n bit data select input


2^n:1
for 4 its 16:1
-- Bhagirathi Nayak

GATE1998_2.8

top

Which of the following operations is commutative but not associative?


A.
B.
C.
D.

AND
OR
NAND
EXOR

we all know AND ,OR are both associative and commutative.we dont know about EXOR and NAND
we can consume some time and prove it by truth table..and come up with the results that EXOR is also associative and commutative so the
only left out is NAND its commutative but not associative
-- Bhagirathi Nayak

GATE1998_2.20 top

I assume byte addressable memory- nothing smaller than a byte can be used.
We have four digits. So, to represent signed 4 digit numbers we need 5 bytes- 4 for four digits and 1 for the sign. So, required memory = 5
bytes
Now, if we use integer, the largest number needed to represent is 9999 and this requires 2 bytes of memory for signed representation.
So, memory savings while using integer is

(52)
5

3
5

= 60%

-- Arjun Suresh

GATE2014-1_8 top
The base (or radix) of the number system such that the following equation holds is____________.
312
20

= 13.1

Let x be the base or radix of the number system .


The equation is : (3.x2+1.x1 +2.x0 ) /(2.x1 +0.x0) =1.x1 +3.x0 +1.x-1
=>(3.x 2+x +2 ) /(2.x) =x+3 +1/x
=>(3.x2+x +2 ) /(2.x) =(x2+3x +1) /x
By solving above quadratic equation you will get x=0 and x=5
As base or radix of a number system cannot be zero, here x = 5
-- vinodmits

GATE2006_39 top
We consider the addition of two 2s complement numbers b n1 b n2 . . . . . b 0 and an1 an2 . . . . . a0. A binary adder for adding unsigned binary
numbers is used to add the two numbers. The sum is denoted by c n1 c n2 . . . . . c 0 and the carry-out by c out . Which one of the following options
correctly identifies the overflow condition?

)
(A) c out (
an1
bn1
n1 n1

bc
(B) an1 b n1
+ an1
cn1
n1 n1
(C) c out c n1
(D) an1 b n1 c n1

Overflow in 2's complement : Carry to MSB & no carry out of MSBOR no carry to MSB and carry out of MSB..
Here C(n-1) is carry into MSB & Cout is carry out of MSB..
Writing overflow condition in expression ,
C(n-1) . Cout' + C(n-1)' . Cout = C(n-1) Ex-OR Cout
Should be Option C.
-- Digvijay Pandey

GATE2014-1_45 top
Consider the 4-to-0 multiplexer with two select lines

S 1 and S 0 given below

The minimal sum-of-products form of the Boolean expression for the output F of the multiplexer is
(A)

+ PQ
R
P Q + QR

(B)

+ P QR
+ PQ
R
P Q + P QR

+ QR
+ PQ
R
(C) P QR + P QR

(D) P QR

S0 and S1 are used to select the input to the given to output.


S0

S1

Output

R'

So, output becomes 1 for

S 0 S1 + S0S 1 R + S0S1R
= P Q + P Q R + P QR
= P Q + P QR + P Q R
= Q(P + P R ) + P Q R

= Q(P + R ) + P Q R ( A + A B = A + B)
= P Q + QR + P Q R
Option (A)
-- Arjun Suresh

GATE2014-3_7 top
Consider the following minterm expression for F :

F (P , Q, R, S) = 0, 2, 5, 7, 8, 10, 13, 15
The minterms 2, 7, 8 and 13 are 'do not care' terms. The minimal sum-of-products form forF is

S
(A) QS + Q
(B)

S + QS
Q

R
S
(C) Q

RS + QR
S + QRS
+Q

S
(D) P Q

S
+ P QS + P QS + P Q

While putting the terms to K-map the 3rd and 4th columns are swapped so do 3rd and 4th rows. So, term 2 is going to (0,3) column instead of
(0,2), 8 is going to (3,0) instead of (2,0) etc..

Solving this k-map gives B) as the answer.


Reference: http://www.cs.uiuc.edu/class/sp08/cs231/lectures/04-Kmap.pdf
-- Srinath Sri

GATE2014-3_45 top

The above synchronous sequential circuit built using JK flip-flops is initialized with
is
(A) 001, 010, 011

Q 2 Q 1 Q 0 = 000 . The state sequence for this circuit for the next 3 clock cycles

(B) 111, 110, 101


(C) 100, 110, 111
(D) 100, 011, 001

Initial State

Input

Next State

Q2

Q1

Q0

J2

K2

J1

K1

J0

K0

Q2'

Q1'

Q0'

Option C
-- Gate_15_isHere

GATE2011_15 top
The minimum number of

D flip-flops needed to design a mod-258 counter is

(A) 9
(B) 8
(C) 512
(D) 258

Answer is A
-- Praneeth A S

GATE2010_7

top

A main memory unit with a capacity of 4 megabytes is built using 1M

1-bit DRAM chips. Each DRAM chip has 1K rows of cells with 1K 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 2 10 nanoseconds

(C) 100 2 20 nanoseconds


(D) 3200 2 20 nanosesonds

There are 4*8 = 32 DRAM chips to get 4MB from 1M 1-bit chips. Now, all chips can be refreshed in parallel so do all cells in a row. So, the
total time for refresh will be number of rows times the refresh time

= 1K 100
= 100 2 10 nanoseconds

Ref: http://www.downloads.reactivemicro.com/Public/Electronics/DRAM/DRAM%20Refresh.pdf
-- Arjun Suresh

GATE1997_2.1

top

z x = (x y) x
= (x
+ y) x
y + x
= x
+
x. y + x = x
-- Arjun Suresh

GATE1997_5.1

top

Answer: C
f(x,y,z) = x' + y'x + xz
An implicant of a function is a product term that is included in the function.
so x', y'x and xz ,all are implicants of given function.
A prime implicant of a function is an implicant that is not included in any other implicant of the function.
option a) y'x is not a prime implicant as it is included in xz [xy'z+ xyz]
option d) y is not a prime implicant as it include in both x' and xz.
a product term in which all the variables appear is called a

option b) xz is not a minterm


-- Praveen Saini

GATE1997_5.4

top

(224)r = (13)r
convert r base to decimal
2
2r + 2r + 4 = r + 3

take square both sides


2r2 + 2r + 4 = r2 + 6r+ 9

minterm of the function

r2 - 4r -5 = 0
r2 -5r +r - 5 = 0
(r-5)(r+1)=0
r can not be -1 so
r = 5 is correct answer

-- Praveen Saini

GATE1997_5.5

top

f = (f 1 f 2 ) f 3
Since f 1 and f 2 are in canonical sum of products form,f 1 f 2 will only contain their common terms- that is f 1 f 2 = 8
Now, 8 f 3 = 8, 9
So, f 3 = 9
-- Arjun Suresh

GATE1993_6.6

top

A ROM is used to store the Truth table for a binary multiple unit that will multiply two 4-bit numbers. The size of the ROM (number of words
number of bits) that is required to accommodate the Truth table is M words N bits. Write the values of M and N .

A is 4 bit binary no A4A3A2A1


B is 4 bit binary no B4B3B2B1
M is result of multiplication M8M7M6M5M4M3M2M1

[check biggest no 1111 x 1111 =11100001]

A4 A3 A2 A1 B4 B3 B2 B1 M8 M7 M6 M5 M4 M3 M2 M1
0

So 4 bit of A 4 bit of B
input will consist of 8 bit need address 00000000 to 11111111 = 28 address
output will be of 8 bits
so memory will be of 2 8 8
M = 256 , N = 8

-- Praveen Saini

GATE1993_9

top

Assume that only half adders are available in your laboratory. Show that any binary function can be implemented using half adders only.

Half Adder give two output


S = AB
C = A.B
We can Perform any operation using Half adder if we can implement basic gates using half adder
AND operation C = AB
Not operation = S (with A and 1) = A1 = A'.1+A.1' = A'
OR operation = ((A1).(B1))1= (A'.B')' = A+B
-- Praveen Saini

GATE1994_2.1

top

The number of flip-flops required to construct a binary modulo N counter is __________

Let say we have to Design mod-8 counter i.e 000 to 111. so we need 3 bit to represent i.e 3 FF
for Mod N
2x = N
x = ceiling (log2N)
-- Praveen Saini

GATE1994_2.7

top

Consider n-bit (including sign bit) 2's complement representation of integer numbers. The range of integer values, N , that can be represented is
_____ N _____

-2n-1 <= N <= 2n-1 -1

Example : let we have 3 bit binary no (unsigned )


000 (0) to 111(7) total of 8 (23) no.
but when we have one signed bit then we have half of negative -4 to -1 and 0 and 1 to 3
bit pattern:

100 101 110 111 000 001 010 011

1's comp:

-3

-2 -1

0 0

2's comp.:

-4

-3 -2 -1 0

-- Praveen Saini

GATE1994_4

top

a) i) A* A = AA+A'A' = A + A' = 1
ii) C*A= (A*B)*A = (AB + A'B')*A= (AB + A'B')A +(AB + A'B')'A'
=(AB + A'B')A+(A'B+AB')A' = AB +0 +A'B+0 = B.
b) AB + A'C= 1 , AC + B = 0
AC + B = 0 , means both B = 0 and AC = 0
AB+ A'C = 1
A'C = 1

[ bcoz B = 0 so AB = 0 ]

So C = 1 and A= 0
so A = 0 , B = 0 and C = 1
-- Praveen Saini

GATE1995_2.2

top

ans c)
-- Aditi Dan

GATE1995_2.5

top

Answer can be A and D. because D can be anything, either 0 or 1.


For verification, just put up the values and check for AND OR operations and their outputs.
-- Gate Keeda

GATE1995_2.12 top
The number of 1's in the binary representation of (3*4096 + 15*256 + 5*16 + 3) are:
(A) 8
(B) 9
(C) 10
(D) 12

3 = (11)2
3 4096 = 3 (2 12 ) = (11)2 << 12 = (11000000000000)2
Similarly, 15 256 = (1111)2 << 8 = (111100000000)2 and 5 16 = (101)2 << 4 = (1010000)2
So, 3 4096 + 15 256 + 5 16 + 3 = (11111101010011)2
Number of 1's = 10.

-- Arjun Suresh

GATE1996_1.21 top
A ROM is used to store the table for multiplication of two 8-bit unsigned integers. The size of ROM required is
1.
2.
3.
4.

256 16
64 K 8
4 K 16
64 K 16

When we multiply two 8 bit numbers result can go up to 16 bits. So, we need 16 bits for each of the multiplication result. Number of results
possible = 28 28 = 216 = 64 K as we need to store all possible results of multiplying two 8 bit numbers. So, 64 K 16 is the answer.
-- Arjun Suresh

GATE1996_2.22 top

Options for this question seem wrong, its expression f will come to A'B'C + A'BC + AB'C + ABC, that further can be minimized to C.
-- Manu Thakur

GATE2008-IT_1 top
A set of Boolean connectives is functionally complete if all Boolean functions can be synthesized using those. Which of the following sets of
connectives is NOT functionally complete?

1)

EX-NOR

2)

implication, negation

3)

OR, negation

4)

NAND

EX-NOR is not functionally complete. NOR and NAND are functionally complete logic gates, OR , AND, NOT any logic gate can be generated using them.
And (Implication, Negation) also
p->q = p'+q = apply negation (p+q')' = pq+p'q'= apply again negation =(pq)' + p'q' = (p'+q') + p'q' = p'+q' + p'q' = p'+q' = again apply negation = (p'+q')' = pq that's
how we got AND logic gate.

-- Manu Thakur

GATE2008-IT_7 top
The following bit pattern represents a floating point number in IEEE 754 single precision format
1 10000011 101000000000000000000000

The value of the number in decimal form is

A)

- 10

B)

- 13

C)

- 26

D)

None of the above

Sign bit is 1 -> number is negative


Exponent bits- 10000011
Exponent is added with 127 bias in IEEE single precision format. So, Actual exponent = 10000011 - 127 = 131 - 127 = 4
Mantissa bits- 101000000000000000000000
In IEEE format, an implied 1 is before mantissa, and hence the actual number is
-1.101 * 24
=- (11010)2 = - 26
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
-- Arjun Suresh

GATE2007-IT_42 top
(C012.25)H - (10111001110.101)B =

A)

(135103.412)o

B)

(564411.412)o

C)

(564411.205)o

D)

(135103.205)o

(C012.25)H - (10111001110.101)B
= 1100 0000 0001 0010. 0010 0101
- 0000 0101 1100 1110. 1010 0000
= 1011 1010 0100 0011. 1000 0101
= 1 011 101 001 000 011 . 100 001 010
= (135103.412)o
Binary subtraction is like decimal subtraction: 0-0 = 0, 1-1 = 0, 1-0 = 1, 0-1 = 1 with 1 borrow.
-- Arjun Suresh

GATE2006-IT_7 top
The addition of 4-bit, two's complement, binary numbers 1101 and 0100 results in

A)

0001 and an overflow

B)

1001 and no overflow

C)

0001 and no overflow

D)

1001 and an overflow

Answer: C

The addition results in 0001 and no overflow with 1 as carry bit.


In 2's complement addition Overflow happens only when :
Sign bit of two input numbers is 0, and the result has sign bit 1.
Sign bit of two input numbers is 1, and the result has sign bit 0.
-- Jon Snow

GATE2004-IT_8 top
What is the minimum number of NAND gates required to implement a 2-input EXCLUSIVE-OR function without using any other logic gate?
A)

B)

C)

D)

Any 2-input Exclusive OR function can be implemented with the 4 NAND gates.
1st NAND gate:
Input: A,B
output: (AB)'
2nd NAND gate:
Input: (AB)' , A
output: A' +AB
3rd NAND gate:
Input: (AB)', B
output: B' +AB
4th NAND gate:
Input: A' +AB, B'+AB
output: A'B + AB' (Exclusive OR function)
-- suraj

GATE2004-IT_10 top
What is the minimum size of ROM required to store the complete truth table of an 8-bit x 8-bit multiplier?

A)

32 K x 16 bits

B)

64 K x 16 bits

C)

16 K x 32 bits

D)

64 K x 32 bits

answer - B
multiplying 2 8 bit digits will give result in maximum 16 bits
total number of multiplications possible = 28 x 28
hence space required = 64K x 16 bits
-- ankitrokdeonsns

GATE2004-IT_42 top

Using a 4-bit 2's complement arithmetic, which of the following additions will result in an overflow?
i. 1100 + 1100
ii. 0011 + 0111
iii. 1111 + 0111

A)

(i) only

B)

(ii) only

C)

(iii) only

D)

(i) and (iii) only

Only (ii) is the answer.


Overflow happens only when
1. Sign bit of two input numbers is 0, and the result has sign bit 1
2. Sign bit of two input numbers is 1, and the result has sign bit 0.
Overflow is important only for signed arithmetic while carry is important only for unsigned arithmetic.
A carry happens when there is a carry to (or borrow from) the most significant bit. Here, (i) and (iii) cause a carry but only (ii) causes
overflow.
http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt

-- Arjun Suresh

GATE2004-IT_43 top
The number (123456)8 is equivalent to

A)

(A72E)16 and (22130232)4

B)

(A72E)16 and (22131122)4

C)

(A73E)16 and (22130232)4

D)

(A62E)16 and (22120232)4

(123456)8 = (001 010 011 100 101 110)2 = (00 1010 0111 0010 1110)2 = (A72E)16
= (00 10 10 01 11 00 10 11 10)2 = (22130232)4
So, option (A)
-- Arjun Suresh

GATE2004-IT_44 top
The function ABC + ABC + ABC + ABC + ABC is equivalent to

A)

AC + AB + AC

B)

AB + AC + AC

C)

AB + AC + AB

D)

AB + AC + AB

K-map
C'

A'B'

A'B

AB

AB'

C
1
A'B'
So, the equivalent expression will be A'C + AC' + AB'

1
A'B

0
AB

1
AB'

(B) option
-- Arjun Suresh

GATE2005-IT_7 top
Which of the following expressions is equivalent to(A B) C
A.
B.
C.
D.

+B
+ C )
(A + B + C)(A
+B
+ C)
(A + B + C)(A

(A C)
ABC + A(B C) + B
None of these

Correct answer is C
(AB)C
At C = 0 ,(AB)C = (AB) ----(I) [ as 0 x = 0.x' +0.'x = 0+ 1.x = x]
At C = 0, ABC + A'(BC)+ B'(AC)
= 0+A'(B0)+B'(A0) = A'B+AB' = AB -----(II)
At c= 1, (AB)C =(AB) --- (III) [as 1x= 1.x'+1'.x = x']
At C = 1, ABC + A'(BC)+ B'(AC)
=AB+A'(B1)+B'(A1) = AB +A'B' =(AB) --(IV)
from eq (I), (II), (III) and (IV) it is clear
(AB)C = ABC + A'(BC)+ B'(AC)
-- Praveen Saini

GATE2005-IT_9 top
A dynamic RAM has a memory cycle time of 64 nsec. It has to be refreshed 100 times per msec and each refresh takes 100 nsec. What
percentage of the memory cycle time is used for refreshing?
A.
B.
C.
D.

10
6.4
1
0.64

Ans : C) 1

-- Afaque Ahmad

GATE2005-IT_10 top
A two-way switch has three terminals a, b and c. In ON position (logic value 1),a is connected to b, and in OFF position, a is connected to c.
Two of these two-way switches S1 and S2 are connected to a bulb as shown below.

Which of the following expressions, if true, will always result in the lighting of the bulb ?

A. S1.S2
B. S1 + S2

S2

C.
S1
D. S1 S2

If it's looked carefully, bulb will be on when both switch s1 and s2 are in same state, either off or on. that is exnor operation
S1 S2 Bulb

0 0 On
0 1 Off
1 0 Off
1 1 On
it's Ex-NOR operation hence (C) is the correct option.
-- Manu Thakur

GATE2005-IT_11 top
How many pulses are needed to change the contents of a 8-bit up counter from 10101100 to 00100111 (rightmost bit is the LSB)?
A.
B.
C.
D.

134
133
124
123

D.123 Pulses.
As in a 2^8 Counter the range would be from 0-255. Hence to go from 10101100 (172) to 00100111 (39) , the counter has to go initially from
172 to 255 and then from 0 to 39.
Hence to go from 172 to 255, 255-172 = 83 Clock pulses would be required. then from 255 to 0 , again 1 clock pulse would be required.Then
from 0 to 39 , 39 clock pulses would be required. Hence in total 83+1+39 =123 Clock pulses would be required.
-- Afaque Ahmad

GATE2005-IT_47 top
(34.4)8 (23.4)8 evaluates to

A)

(1053.6) 8

B)

(1053.2) 8

C)

(1024.2) 8

D)

None of these

Simply Convert 34.4 and 23.4 to decimal. We can do this by this method :
34.4 = 28.5 in decimal and 23.4 = 19.5 in decimal.
Multiplying 28.5 x 19.5 = 555.75

Now convert 555.75 back to octal which is 1053.6.


-- Afaque Ahmad

GATE2005-IT_48 top
The circuit shown below implements a 2-input NOR gate using two 2-4 MUX (control signal 1 selects the upper input). What are the values of
signals x, y and z?

A)

1, 0, B

B)

1, 0, A

C)

0, 1, B

D)

0, 1, A

f = Az + Bz (As A will be selected when z is high) .


So next function will become g

= xf + yf

+
Bz
)
= x(Az + B z ) + y (Az
= ( A + B = A + B) and answer will become D
Putting x = 0, y = 1, z = A,we get g =
AA + BA
A+B
A
-- John Carter

Let f(x,y,z) = x' + y'x + xz be a switching function. Which one of the following is valid?

top

Let f(x,y,z) = x' + y'x + xz be a switching function. Which one of the following is valid?
1. y'x is a prime implicant of f.
2 xz is a minterm of f.
3. xz is an implicant of f
4 y is a prime implicant of f

xz is an implicant and y is both prime and essential prime implicant. The sop would be z + x + y .
Implicant: Something that implies a function is its implicant
Prime implicant: The most reduced (minimal) implicant
Essential prime implicant: The prime implicant which cannot be avoided in any SOP
Ref: https://en.wikipedia.org/wiki/Implicant
-- Shaun Patel

which one is not self complemetry code

top

Self complementing code is a code wherein sum of weights is 9. Except for D, all other options have sum of weights=9
-- Keith Kr

GATE2015-2_7 top
The minimum number of JK flip-flops required to construct a synchronous counter with the count sequence (0, 0, 1, 1, 2, 2, 3, 3, 0, 0, ...) is
_______.

Here it appears to have 8 discrete states. That requires 3 bits, therefore 3 flip-flops. From inspection, there are 4 groups of 2 identical bits per group. I'd
break that down to into a divide by two (1 flip-flop) followed by a divide by four (2 flip-flops).

-- Vikrant Singh

GATE2015-2_48 top
A half adder is implemented with XOR and AND gates. A full adder is implemented with two half adders and one OR gate. The propagation
delay of an XOR gate is twice that of an AND/OR gate. The propagation delay of an AND/OR gate is 1.2 milliseconds. A 4-bit-ripple-carry

binary adder is implemented by using four full adders. The total propagation time of this 4-bit binary adder in microseconds is ______.

S1 should wait for C1 to be ready. Delay for generating C is 1 EXOR + 1 AND + 1 OR = 2.4 + 1.2 + 1.2 = 4.8 ms
Delay for sum is XOR + XOR = 2.4 + 2.4 = 4.8 ms
But for the second adder, there the first EXOR can be done even before waiting for the previous output. So, we can get sum in another 2.4
ms and carry in another 2.4 ms. In this way, 4 bit sum can be obtained after
4.8 ms + 3 * 2.4 ms = 12 ms.

But the question says we use ripple-carry adder. So, each adder must wait for the full output from the previous adder. This would make the
total delay = 4 * 4.8 = 19.6 ms and this is the key given by GATE, so obviously they meant this.
Ref: http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Comb/adder.html
-- Arjun Suresh

GATE2015-3_35 top
Consider the equation (43)x = (y3)8 where x and y are unknown. The number of possible solutions is _____

(43)x =(y3)8
From this equation it is clear x should be greater than 4 and y should be less than 8
x>=5, and y<=7
now convert this expression in decimal no
4*x+3=y*8+3 , ie 4x = 8y
x=2y. and( x>=5 ,y<=7) and x,y should be integer.
x=6,y=3
x=8,y=4
x=10,y=5
x=12,y=6
x= 14, y=7 .. so I am getting 5 possible values
-- Praveen Saini

GATE2015-3_43 top
The total number of prime implicants of the function f(w, x, y, z) = (0, 2, 4, 5, 6, 10) is __________.

(Can be solved using K-Map also. )


Place all minterms that evaluate to one in a minterm table.

Input (first column for no. of 1's)


0

m0

0000

m2
m4

0010
0100

m5
m6
m10

0101
0110
1010

Combine minterms with other minterms. If two terms vary by only a single digit changing, that digit can be replaced with a dash indicating that
the digit doesn't matter. Terms that can't be combined any more are marked with a "*". When going from Size 2 to Size 4, treat '-' as a third bit
value. For instance, -110 and -100 or -11- can be combined, but -110 and 011- cannot. (Trick: Match up the '-' first.)
First Comparison
0

(2, 0)
(4, 0)

00-0
0-00

(6, 2)
(10, 2)
(5, 4)
(6, 4)

0-10
-010
01001-0

Second Comparison
0

(6, 4, 2, 0)

0--0

Prime Implicants
(6, 4, 2, 0)

0--0

(10, 2)
(5, 4)

-010
010-

Answer: Total number of prime implicants


Source: Finding prime implicants - Quine-McCluskey algorithm - Wikipedia
-- Shyam Singh

GATE2015-3_44 top
Given the function F = P + QR , where F is a function in three Boolean variables P , Q and R and P =!P , consider the following statements.

(S1)F = (4, 5, 6)
(S2)F = (0, 1, 2, 3, 7)
(S3)F = (4, 5, 6)
(S4)F = (0, 1, 2, 3, 7)
Which of the following is true?

A.
B.
C.
D.

(S1)-False, (S2)-True, (S3)-True, (S4)-False


(S1)-True, (S2)-False, (S3)-False, (S4)-True
(S1)-False, (S2)-False, (S3)-True, (S4)-True
(S1)-True, (S2)-True, (S3)-False, (S4)-False

F=P'+QR, draw the Kmap for this


we can find the minterm (0,1,2,3,7)
and maxterm (4,5,6)
so option A is correct ...(S1)-False, (S2)-True, (S3)-True, (S4)-False

-- Anoop Sonkar

The state transistion diagram for the logic circuit is ?

top

Answer should be (D) ,


Since ,
Y = D = Q+ = A'.Q' + A.Q = A (XNOR) Q ,
A

Q+

WHEN A=0 , Q=0 THEN Q+ = 1 ,


A=0 , Q=1 THEN Q+ = 0 ,
A=1 , Q=0 THEN Q+ = 0 ,
A=1 , Q=1 THEN Q+ = 1 .
means ,

When A is 0, Y = X0 = Q' and hence next Q = Q'.


When A is 1, Y = X1 = Q and hence next Q = Q
-- csegate2

A cascade of three identical modulo-5 counters has an overall modulus of ?


(A) 5

(B) 25

(C) 125

(D) 625

125..
cascading two modulo M and modulo N counter gives modulo M*N counter..
-- Digvijay Pandey

solve top

top

D = X' Z + Y Z' which an be compared with eq D = J Q' + K' Q hence option D is correct
-- gate2016

digital

top

Minimise the following problems using the Karnaugh maps method.


Z = f(A,B,C) =

B + AB + AC

A'B'C'

: 000

A'B = A'BC' + A'BC

: 010 | 011

ABC'

AC = AB'C + ABC :

110
101 | 111

= min { 0, 2, 3, 5, 6, 7}
Now solve k- Map..
0132
4576
So, 2-3-6-7, 0-2, and 5-7 can be combined. We get
B + AC + A'C'
-- Digvijay Pandey

IS & Software Engg. top


GATE2009_50 top
50.
Consider the following statements about the cyclomatic complexity of the control flow graph of a program module. Which of these are
TRUE?
I. The cyclomatic complexity of a module is equal to the maximum number of linearly independent circuits in the graph.
II. The cyclomatic complexity of a module is the number of decisions in the module plus one, where a decision is effectively any conditional
statement in the module.
III. The cyclomatic complexity can also be used as a number of linearly independent paths that should be tested during path coverage
testing.
(A) I and II

(B) II and III

(C) I and III

(D) I, II and III

ans: b) 2 and 3
In 1, it should be "path" and not "circuit".
-- Preeti Verma

GATE2013_38 top
The following figure represents access graphs of two modules M1 and M2. The filled circles represent methods and the unfilled circles
represent attributes. If method m is moved to module M2 keeping the attributes where they are, what can we say about the average cohesion
and coupling between modules in the system of two modules?

(A) There is no change.


(B) Average cohesion goes up but coupling is reduced.
(C) Average cohesion goes down and coupling also reduces.
(D) Average cohesion and coupling increase.

Answer: A

-- Jon Snow

GATE2014-1_18 top
Match the following:
1) Waterfall model

a) Specifications can be
developed incrementally

2) Evolutionary model

b) Requirements compromises are


inevitable

3) Component-based software
engineering

c) Explicit recognition of risk

4) Spiral development

d) Inflexible partitioning of the project into


stages

(A) 1-a, 2-b, 3-c, 4-d


(B) 1-d, 2-a, 3-b, 4-c
(C) 1-d, 2-b, 3-a, 4-c
(D) 1-c, 2-a, 3-b, 4-d

Ans is (B)
-- Keith Kr

GATE2014-3_19 top
In the context of modular software design, which one of the following combinations is desirable?

(A) High cohesion and high coupling


(B) High cohesion and low coupling
(C) Low cohesion and high coupling
(D) Low cohesion and low coupling

(B) High cohesion and low coupling


(Ideal software design requires less interaction between modules so that any module can be easily modified/replaced as the requirements

change)
-- Preeti Verma

GATE2011_7

top

A company needs to develop a digital signal processing software for one of its newest inventions. The software is expected to have 40000 lines of code. The
company needs to determine the effort in person-months needed to develop this software using the basic COCOMO model. The multiplicative factor for this model
is given as 2.8 for the software development on embedded systems, while the exponentiation factor is given as 1.20. What is the estimated effort in person-months?
(A) 234.25
(B) 932.50
(C) 287.80
(D) 122.40

kLOC = 40000/1000 = 40
Effort Applied (E) = 2.8(40)^1.2 [ person-months ]
= 234.22

-- Aditya Gaurav

GATE2011_10 top
Which one of the following is NOT desired in a good Software Requirement Specifications (SRS) document?
(A) Functional Requirements
(B) Non-Functional Requirements
(C) Goals of Implementation
(D) Algorithm for Software Implementation

Algorithms for software implementation may not be required at requirement phase. they are required at later stages like design and
development
-- Sankaranarayanan P.N

GATE2011_47 top
The following is the comment written for a C function.
/* This function computes the roots of a quadratic equation
a.x^2 + b.x + c = 0. The function stores two real roots
in *root1 and *root2 and returns the status of validity
of roots. It handles four different kinds of cases.
(i) When coefficient a is zero irrespective of discriminant
(ii) When discriminant is positive
(iii) When discriminant is zero

(iv) When discriminant is negative


Only in case (ii) and (iii), the stored roots are valid.
Otherwise 0 is stored in the roots. The function returns
0 when the roots are valid and -1 otherwise.
The function also ensures root1 >= root2.
int get_QuadRoots (float a, float b, float c,
float *root1, float *root2);
*/

A software engineer is assigned the job of doing black box testing. He comes up with the following test cases, many of which are redundant.
Test
Case

Input Set
a

Expected Output Set


root1

root2

Return Value

T1

0.0

0.0

7.0

0.0

0.0

-1

T2

0.0

1.0

3.0

0.0

0.0

-1

T3

1.0

2.0

1.0

-1.0

-1.0

T4

4.0

-12.0

9.0

1.5

1.5

T5

1.0

-2.0

-3.0

3.0

-1.0

T6

1.0

1.0

4.0

0.0

0.0

-1

Which one of the following options provide the set of non-redundant tests using equivalence class partitioning approach from input perspective for black box
testing?
(A) T1, T2, T3, T6
(B) T1, T3, T4, T5
(C) T2, T4, T5, T6
(D) T2, T3, T4, T5

In Black Box Testing we just focus on inputs and output of the software system without bothering about internal knowledge of the software .
Equivalence partitioning is a software testing technique that divides the input data of a software unit into partitions of equivalent data from
which test cases can be derived
. As T1 and T2 checking same condition a=0
So,we can select T1 or T2.
For T3 ,T4 (b^2-4ac)=0.
so , we can select T3 or T4.
for T5 (b^2-4ac) > 0
for T6 (b^2-4ac) < 0
So, C is the answer.
-- Priya_das

GATE2010_21 top
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
(B) 21
(C) 20

(D) 10

Cyclomatic Complexity of module = Number of decision points + 1


Number of decision points in A = 10 - 1 = 9
Number of decision points in B = 10 - 1 = 9
Cyclomatic Complexity of the integration = Number of decision points + 1
= (9 + 9) + 1
= 19
-- Vikrant Singh

GATE2010_22 top
What is the appropriate pairing of items in the two columns listing various activities encountered in a software life cycle?
P. Requirements Capture

1. Module Development and Integration

Q. Design

2. Domain Analysis

R. Implementation

3. Structural and Behavioral Modeling

S. Maintenance

4. Performance Tuning

(A) P-3 Q-2 R-4 S-1


(B) P-2 Q-3 R-1 S-4
(C) P-3 Q-2 R-1 S-4
(D) P-2 Q-3 R-4 S-1

B is the correct answer


-- Sankaranarayanan P.N

GATE2010_44 top
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 variablesa, b, c and d. The
exact values are not given.
T1: a, b, c and d are all equal
T2: a, b, c and d are all distinct
T3: a = b and c != d
T4: a != b and c = d
Which of the test suites given below ensures coverage of statements S1, S2, S3 and S4?
(A) T1, T2, T3
(B) T2, T4
(C) T3, T4
(D) T1, T2, T4

T1 covers S1
T2 covers S3

T3 covers S1
T4 covers S2, S4
so inorder to cover all 4 either T1,T2, T4 or T2, T3 , T4
option D
-- Sankaranarayanan P.N

GATE2008-IT_60 top
Which of the following requirement specifications can be validated?
(S1)
(S2)
(S3)
(S4)

If the system fails during any operation, there should not be any loss of data
The system must provide reasonable performance even under maximum load conditions
The software executable must be deployable under MS Windows 95, 2000 and XP
User interface windows must fit on a standard monitor's screen

1)

S4 and S3

2)

S4 and S2

3)

S3 and S1

4)

S2 and S1

3rd is correct, as not specified what standard size of monitor is, and for 2nd, reasonable performance cannot be measured specifically.
-- Shaun Patel

GATE2007-IT_4 top
In the Spiral model of software development, the primary determinant in selecting activities in each iteration is

A)

Iteration size

B)

Cost

C)

Adopted process such as Rational Unified Process or Extreme Programming

D)

Risk

d) risk
-- Aditi Dan

GATE2007-IT_53 top
In the simplified flowchart given below, the shaded boxes represent code that is executed during a test case.

The Branch coverage is

A)

3/4

B)

2/3

C)

1/2

D)

3/8

There are 8 possible branches. 3 are covered by the test case. So, branch coverage is 3/8.
-- Arjun Suresh

GATE2006-IT_16 top
The cyclomatic complexity of the flow graph of a program provides

A) an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
B) a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
C) an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
D) a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at least once

its C as each edge must be visited at least once that's why we use cyclomatic complexity to determine the number of independent paths.
-- nagendra

GATE2006-IT_17 top
With respect to software testing, consider a flow graph G with one connected component. Let E be the number of edges, N be the number of
nodes, and P be the number of predicate nodes of G. Consider the following four expressions:
I.
II.
III.
IV.

E-N+P
E-N+2
P+ 2
P+1

The cyclomatic complexity of G is given by

A)

I or III

B)

II or III

C)

II or IV

D)

I or IV

ans c)
-- Aditi Dan

GATE2004-IT_69 top
Consider the following program module:
int module1 (int x, int y) {
while (x! = y) {
if (x > y)
x = x - y,
else y = y - x;
}
return x;
}

What is Cyclomatic complexity of the above module?

A)

B)

C)

D)

answer - C
There are 2 decision points in this module
1. while condition and
2. if condition
hence cyclomatic complexity = number of decision points + 1 = 3
-- ankitrokdeonsns

GATE2004-IT_70 top
Assume that the delivered lines of code L of a software is related to the effort E in person months and duration t in calendar months by the
relation L P* (E/B)1/3 * t4/3, where P and B are two constants for the software process and skills factor. For a software project, the effort was
estimated to be 20 person months and the duration was estimated to be 8 months. However, the customer asked the project team to complete
the software project in 4 months. What would be the required effort in person months?

A)

10

B)

40

C)

160

D)

320

P* (E1/B)1/3 * t14/3 = P* (E2/B)1/3 * t24/3


E1 = 20 person-months
t1 = 8 months
t2 = 4 months
On calculation we get E2 = 320 person-months (So, D is the answer)

-- Aditya Gaurav

GATE2004-IT_71 top

A software was tested using the error seeding strategy in which 20 errors were seeded in the code. When the code was tested using the
complete test suite, 16 of the seeded errors were detected. The same test suite also detected 200 non-seeded errors. What is the estimated
number of undetected errors in the code after this testing?
1)

2)

50

3)

200

4)

250

estimated no of undetected errors in the code after testing=n(S-s)/s=200*(20-16)/16=50...


n=no of defects be found by testing
S=total no of seeded errors
s=defects found during testing
-- Aditya Gaurav

GATE2004-IT_72 top
What is the availability of a software with the following reliability figures?
Mean Time Between Failure (MTBF) = 25 days
Mean Time To Repair (MTTR) = 6 hours

A)

1%

B)

24%

C)

99%

D)

99.009%

Availability = MTBF/(MTBF+MTTR) * 100


= 25*24/(25*24 + 6) * 100
= 99.009 %
-- Aditya Gaurav

GATE2005-IT_20 top
The Function Point (FP) calculated for a software project are often used to obtain an estimate of Lines of Code (LOC) required for that project.
Which of the following statements is FALSE in this context.

1) The relationship between FP and LOC depends on the programming language used to implement the software.
2) LOC requirement for an assembly language implementation will be more for a given FP value, than LOC for implementation in COBOL.
3) On an average, one LOC of C++ provides approximately 1.6 times the functionality of a single LOC of FORTRAN
4) FP and LOC are not related to each other

option D... relation between FP and LOC depends on programming language chosen
http://www.cs.helsinki.fi/u/taina/ohtu/fp.html
-- Manali

GATE2005-IT_64 top
The availability of a complex software is 90%. Its Mean Time Between Failure (MTBF) is 200 days. Because of the critical nature of the usage,
the organization deploying the software further enhanced it to obtain an availability of 95%. In the process, the Mean Time To Repair (MTTR)
increased by 5 days.
What is the MTBF of the enhanced software

A)

205 days

B)

300 days

C)

500 days

D)

700 days

Availability = MTBF/(MTBF + MTTR)


Case 1 :
0.9 = 200/(200 + x)
x = 22.22
Case 2 :
0.95 = y/(y+22.22+5)
0.95 = y/(y+27.22)
y = 517.18 (It is near to option C)

-- Aditya Gaurav

GATE2005-IT_65 top
Tb carry out white box testing of a program, its flow chart representation is obtained as shown in the figure below:

For basis path based testing of this program, its cyclomatic complexity is

A)

B)

C)

D)

No. of Nodes(N) = 9
No. of Edges(E) = 10
Cyclomatic Complexity = E - N + 2P
= 10 -9 + 2*1
=3
-- Aditya Gaurav

GATE2015-1_1 top
Match the following:
(P) Condition Coverage

(i) Black-box testing

(Q) Equivalence class partitioning

(ii) System testing

(R) Volume testing

(iii) White-box testing

(S) Alpha testing

(iv) Performance testing

A.
B.
C.
D.

P - ii, Q - iii, R - i, S - iv
P - iii, Q - iv, R - ii, S - i
P - iii, Q - i, R - iv, S - ii
P - iii, Q - i, R - ii, S - iv

C) P - iii, Q - i, R - iv, S - ii
Ref: https://en.wikipedia.org/wiki/Software_testing
-- piyushhurpade

GATE2015-2_4 top
A software requirements specification (SRS) document should avoid discussing which one of the following?

A.
B.
C.
D.

User interface issues


Non-functional requirements
Design specification
Interfaces with third party software

Ans C

-- Vikrant Singh

GATE2015-2_12 top
Consider the basic COCOMO model where E is the effort applied in person-months, D is the development time in chronological months,
KLOC is the estimated number of delivered lines of code (in thousands) andab , b b , c b , db have their useful meanings. The basic COCOMO
equations are of the form

A. E = ab (KLOC)exp(b b ), D = c b (E)exp(db )
B. D = ab (KLOC)exp(b b ), E = c b (D)exp(db )

C. E = ab exp(b b ), D = c b (KLOC)exp(db )
D. E = ab exp(db ), D = c b (KLOC)exp(b b )

Answer: A
In basic COCOMO model,
Effort Applied, E = a*(KLOC)b
Development Time, D = c*Ed
People Required, P = E/D
where KLOC = Estimated number of delivered lines in thousands and a,b,c,d depends upon the software being Organic, Semi detached or
Embedded.
http://www.mhhe.com/engcs/compsci/pressman/information/olc/COCOMO.html
-- Jon Snow

GATE2015-2_43 top
Which one of the following assertions concerning code inspection and code walkthrough is true?

A.
B.
C.
D.

Code inspection is carried out once the code has been unit tested
Code inspection and code walkthrough are synonyms
Adherence to coding standards is checked during code inspection
Code walkthrough is usually carried out by an independent test team

c.
Unit testing is not necessary before code inspection. Code walk through is done by a member of development team in presence of reviewers.
So, a and d are false.
http://nptel.ac.in/courses/106105087/pdf/m10L23.pdf
http://www.tutorialspoint.com/software_testing_dictionary/code_inspection.htm
-- Arjun Suresh

GATE2015-1_42 top
Consider the following C program segment.
while (first <= last)
{
if (array[middle] < search)
first = middle + 1;
else if (array[middle] == search)
found = TRUE;
else last = middle - 1;
middle = (first + last)/2;
}
if (first > last) notpresent = TRUE;

The cyclomatic complexity of the program segment is_______________.

Number of predicates = 4, if, else if, while and if.


Cyclomatic complexity = No. of predicates + 1 = 5.
-- Arjun Suresh

GATE2015-3_11 top
Consider a software program that is artificially seeded with 100 faults. While testing this program, 159 faults are detected, out of which 75 faults

are from those artificially seeded faults. Assuming that both real and seeded faults are of same nature and have same distribution, the
estimated number of undetected real faults is _______.

Answer:28
Explanation:
75% of faults are detected because 75 artificially seeded faults are detected out of 100.
No of detected real faults = 159-75=84
Hence no of real faults = (84)*100/75
=112
Therefore undetected real faults = 112-84 = 28.
According to ace academy solution:175
-- overtomanu

GATE2015-3_21 top
Consider a software project with the following information domain characteristics for calculation of function point metric.
Number of external inputs (I) = 30
Number of external outputs (O) = 60
Number of external inquiries (E) = 23
Number of files (F) = 08
Number of external interfaces (N) = 02
It is given that the complexity weighting factors for I, O, E, F and N are 4, 5, 4, 10 and 7, respectively. It is also given that, out of fourteen value
adjustment factors that influence the development effort, four factors are not applicable, each of the other four factors have value 3, and each of
the remaining factors have value 4. The computed value of function point metric is _________.

Ans: 612.06
FP = UAF * VAF
UAF = 30 * 4 + 60 * 5 + 23 * 4 + 08 * 10 + 02 * 7 = 606
VAF = 0.65 + [4 * 3 + 6 * 4]/100 = 1.01
So, FP = 606 * 1.01 = 612.06
calculations can be done here : http://groups.engin.umd.umich.edu/CIS/course.des/cis525/js/f00/artan/functionpoints.htm
For theory part see this : http://www.softwaremetrics.com/fpafund.htm

-- ashwini anand

GATE2015-3_55 top
Consider the following software items: Program-X , Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown
below

The values of McCabe's Cyclomatic complexity of program-X , program-Y , and program-Z respectively are

A.
B.
C.
D.

4, 4, 7
3, 4, 7
4, 4, 8
4, 3, 8

cyclomatic complexity = no of predicate nodes +1


No of predicate nodes = decision making nodes
so for program X , no of predicate nodes = 3 (if, while , if )
cyclomatic complexity of program X = 3+1=4
For program Y, no of predicate nodes = 3 ( node3, node6, node8)
cyclomatic complexity for program Y = 3+ 1=4
For program Z , no of predicate nodes = 6 ( 3 of X followed by 3 of Y)
cyclomatic complexity of Z = 6+1 =7
-- Praveen Saini

Web Technologies top


GATE2009_20 top
Consider a HTML table definition given below:
<table border =1>
<tr> <td rowspan=2> ab </td>
<td colspan=2> cd </td>
</tr>
<tr> <td> ef </td>
<td rowspan=2> gh </td>
</tr>
<tr> <td colspan=2> ik </td>
</tr>
</table>

The number of rows in each column and the number of columns in each row are:

A. 2, 2, 3 and 2, 3, 2
B. 2, 2, 3 and 2, 2, 3
C. 2, 3, 2 and 2, 3, 2
D. 2, 3, 2 and 2, 2, 3

The table description is for the below table:

So, answer will be (2,3,2) and (2,3,2)


-- Arjun Suresh

GATE2014-2_28 top
A graphical HTML browser resident at a network client machine

Q accesses a static HTML webpage from a HTTP server S . The static HTML page has exactly

one static embedded image which is also at S . Assuming no caching, which one of the following is correct about the HTML webpage loading (including the
embedded image)?

(A) Q needs to send at least 2 HTTP requests to S , each necessarily in a separate TCP connection to server S
(B)

Q needs to send at least 2 HTTP requests to S , but a single TCP connection to server S is sufficient

(C) A single HTTP request from

Q to S is sufficient, and a single TCP connection between Q and S is necessary for this

(D) A single HTTP request from

Q to S is sufficient, and this is possible without any TCP connection between Q and S

A separate HTML request must be send for each image or component in HTML like css file of js. But all can be done in same connection. So,
(B) is the answer.
-- Arjun Suresh

GATE2010_16 top
Which one of the following is not a client-server application?
(A) Internet chat

(B) Web browsing


(C) E-mail
(D) Ping

ping is a utility to test whether a node is reachable in the network


it is not client server. all other application are client server
-- Sankaranarayanan P.N

GATE2004-IT_24 top
Which one of the following statements is FALSE?

A)

HTTP runs over TCP

B)

HTTP describes the structure of web pages

C)

HTTP allows information to be stored in a URL

D)

HTTP can be used to test the validity of a hypertext link

B is false, HTTP is protocol, which has no relations with the structure of a web page. Web page structure is given using HTML.
-- Manu Thakur

GATE2004-IT_29 top
Which of the following objects can be used in expressions and scriplets in JSP (Java Server Pages) without explicitly declaring them?

A)

session and request only

B)

request and response only

C)

response and session only

D)

session, request and response

A) Session and request only


-- Shankar

GATE2004-IT_90 top
Given below are several usages of the anchor tag in HTML.
I. <A HREF = "http://www.gate.ac.in/HTML/BASIC/testpage.html">Test Me</A>
II. <A HREF = "/BASIC/testpage.html">Test Me</A>
III. <A HREF = "testpage.html">Test Me</A>
IV. <A HREF = "testpage.html#test">Test Me</A>
Which of the above are valid?

A)

I and II only

B)

I and III only

C)

I, II and III only

D)

I, II, III and IV

D) all are valid rfc 3986.

I. For absolute URL


II. For relative URL starting from website root
III. For relative URL starting from the current page location
IV. For relative URL starting from the current page location and then going to "test" part of the loaded page
-- Arpit Dhuriya

GATE2005-IT_30 top
A HTML form is to be designed to enable purchase of office stationery. Required items are to be selected (checked). Credit card details are to
be entered and then the submit button is to be pressed. Which one of the following options would be appropriate for sending the data to the
server. Assume that security is handled in a way that is transparent to the form design.

A)

Only GET

B)

Only POST

C)

Either of GET or POST

D)

Neither GET nor POST

Refer: http://www.w3schools.com/tags/ref_httpmethods.asp
since credit card info is also submitted POST is recommended
-- Sankaranarayanan P.N

GATE2015-1_15 top
Which of the following statement is/are FALSE?
I.
II.
III.
IV.

XML overcomes the limitations in HTML to support a structured way of organizing content.
XML specification is not case sensitive while HTML specification is case sensitive.
XML supports user defined tags while HTML uses pre-defined tags.
XML tags need not be closed while HTML tags must be closed.

A.
B.
C.
D.

only
only
II and IV only
III and IV only

option c
-- GATERush

GATE2015-3_8 top
In a web server, ten WebPages are stored with the URLs of the form http://www.yourname.com/
var.html; where var is a different number from 1
to 10 for each Webpage. Suppose the client stores the Webpage with var = 1 (say W1) in the local machine, edits and then tests. Rest of the
Webpages remains on the web server. W1 contains several relative URLs of the form "var.html" referring to the other Webpages. Which one of
the following statements needs to be added in W1, so that all the relative URLs in W1 refer to the appropriate Webpages on the web server?

A.
B.
C.
D.

<a href: "http://www.yourname.com/", href:"...var.html">


<base href: "http://www.yourname.com/">
<a href: "http://www.yourname.com/">
<base href: "http://www.yourname.com/", range:"...var.html">

B choice.

http://www.w3schools.com/tags/tag_base.asp
-- Arjun Suresh

Verbal Ability top


GATE2014-1_GA_1 top
Which of the following options is the closest in meaning to the phrase in bold in the
sentence below?
It is fascinating to see life forms **cope with** varied environmental conditions.
(A) Adopt to (B) Adapt to (C) Adept in (D) Accept with

Answer is Adapt to. Often seen in newspaper "Indian players couldn't adapt to foreign conditions".
Adopt - means legally take care of. Also means to take up and use as in "He adopted my point of view."
Adept in - means smart in. Example- "Sachin is adept in batting."
-- Arjun Suresh

GATE2014-1_GA_2 top
Choose the most appropriate word from the options given below to complete the following sentence.
He could not understand the judges awarding her the first prize, because he thought that her performance was quite _________.
A. superb
B. medium
C. mediocre
D. exhilarating

C. Mediocre meaning not very good, not up to par, average. Her performance was average and not worthy of 1st prize.
-- Kathleen Bankson

GATE2014-1_GA_3 top
In a press meet on the recent scam, the minister said, "The buck stops here". What did the minister convey by the statement?
A. He wants all the money
B. He will return the money
C. He will assume final responsibility
D. He will resist all enquiries

C. The buck stops here is a term meaning to put an end to something, not continue, stop it.
(idiomatic) A statement that no excuses will be made, that the speaker is going to take direct responsibility for matters, rather than pass the responsibility to higher
authorities.

-- Kathleen Bankson

GATE2014-1_GA_6 top
The Palghat Gap (or Palakkad Gap) , a region about 30 km wide in the southern part of the Western Ghats in India, is lower than the hilly
terrain to its north and south. The exact reasons for the formation of this gap are not clear. It results in the neighbouring regions of Tamil Nadu
getting more rainfall from the South West monsoon and the neighbouring regions of Kerala having higher summer temperatures.
What can be inferred from this passage?
Select one:

A. The Palghat gap is caused by high rainfall and high temperatures in southern Tamil Nadu and Kerala
B. The regions in Tamil Nadu and Kerala that are near the Palghat Gap are low-lying
C. The low terrain of the Palghat Gap has a significant impact on weather patterns in neighbouring parts of Tamil Nadu and Kerala
D. Higher summer temperatures result in higher rainfall near the Palghat Gap area

The answer is C. The primary statement is about the Palghat Gap being low lying which is mentioned in thefirst sentence. The second part
mentions the results of that causing lots of rain and unusual temperatures in the other areas. (Tamil Nadu and Kerala)
-- Kathleen Bankson

GATE2014-1_GA_7 top
Geneticists say that they are very close to confirming the genetic roots of psychiatric illnesses such as depression and schizophrenia, and
consequently, that doctors will be able to eradicate these diseases through early identification and gene therapy.
On which of the following assumptions does the statement above rely?
Select one:
A. Strategies are now available for eliminating psychiatric illnesses
B. Certain psychiatric illnesses have a genetic basis
C. All human diseases can be traced back to genes and how they are expressed
D. In the future, genetics will become the only relevant field for identifying psychiatric illnesses

B is correct, The first sentence mentions two specific illnesses, (depression and schizophrenia). B is the only one that mentions certain illnesses.
A states strategies are now available. The statement says they are very close so its not yet available.
C states that ALL human diseases can be traced back. The statement only mentions two specific illnesses.

D the statement does not mention at all that it is the only relevant field.
-- Kathleen Bankson

GATE2013_56 top
Which one of the following options is the closest in meaning to the word given below?
Nadir
(A) Highest

(B) Lowest

(C) Medium

(D) Integration

B, the lowest point


-- Kathleen Bankson

GATE2013_57 top
Complete the sentence:
Universalism is to particularism as diffuseness is to _______________.
(A) specificity

(B) neutrality

(C) generality

(D) adaptation

A...Specificity. This is asking for opposites.


Specificity

Diffuseness

Direct, to the point, purposeful in Indirect, circuitous, seemingly


relating
"aimless" forms of relating
Precise, blunt, definitive and Evasive, tactful, ambiguous, even
transparent
opaque
Principles and consistent moral Highly
situational
morality
stands independent of the person depending upon the person and
being addressed
context encountered

-- Kathleen Bankson

GATE2013_59 top
Were you a bird, you ___________________ in the sky.
(A) would fly

(B) shall fly

(C) should fly

(D) shall have flown

A...would fly
-- Kathleen Bankson

GATE2013_60 top
Choose the grammatically INCORRECT sentence:
(A) He is of Asian origin.
(B) They belonged to Africa.
(C) She is an European.
(D) They migrated from India to Australia.

C. Should be... She is a European


"The sound of a word's first letter determines which to use. If the word starts with a vowel sound, you should use an. If it starts with a consonant sound, you
should use a."
The word "European" does not start with a vowel sound, it starts with the syllable "you". The "y"-sound is in this case a consonant (or at least a half-consonant), so the
indefinite article is "a".

-- Kathleen Bankson

GATE2013_63 top
After several defeats in wars, Robert Bruce went in exile and wanted to commit suicide. Just before committing suicide, he came across a
spider attempting tirelessly to have its net. Time and again, the spider failed but that did not deter it to refrain from making attempts. Such
attempts by the spider made Bruce curious. Thus, Bruce started observing the near-impossible goal of the spider to have the net. Ultimately,
the spider succeeded in having its net despite several failures. Such act of the spider encouraged Bruce not to commit suicide. And then, Bruce
went back again and won many a battle, and the rest is history.
Which one of the following assertions is best supported by the above information?
(A) Failure is the pillar of success.
(B) Honesty is the best policy.
(C) Life begins and ends with adventures.
(D) No adversity justifies giving up hope.

D is my answer. He gave up hope and wanted to commit suicide until he saw the spider in his struggles so no struggle or difficulty is worth
giving up hope. Continue on!
-- Kathleen Bankson

GATE2014-2_GA_3 top

Match the columns.


Column 1

Column 2

1) eradicate

P) misrepresent

2) distort

Q) soak completely

3) saturate

R) use

4) utilize

S) destroy utterly

(A) 1:S, 2:P, 3:Q, 4:R


(B) 1:P, 2:Q, 3:R, 4:S
(C) 1:Q, 2:R, 3:S, 4:P
(D) 1:S, 2:P, 3:R, 4:Q

Answer is A
-- Poshita Shrivastava

GATE2014-3_GA_1 top
While trying to collect an envelope from under the table, Mr. X fell down and
I

II

III

was losing consciousness.


IV
Which one of the above underlined parts of the sentence is NOT appropriate?
(A) I
(B) II
(C) III
(D) IV

Answer D)
While trying to collect an envelope from under the table, Mr. X fell down and was losing consciousness.
A :Mr. X is trying to collect an envelope from under the table (Present continuous tense)
B :Mr. X fell down (Simple past tense)
C :Mr. X was losing consciousness. (Past continuous tense)
While A, B and C
What is wrong is the usage of sentences B and C together.
"We use the past
eg-I

continuous tense with the simple past tense when we want to show that one thing happened in the middle of another thing."
was taking a bath and the telephone rang.

Here it says..
"Mr. X fell down and was losing consciousness."
i.e B is done.. and C starts. Where as the usage says.. C should have happened in the middle of B.
It should have been Mr. X fell down and lost consciousness.
Source - http://www.5minuteenglish.com/nov12.htm
-- Srinath Sri

GATE2014-3_GA_2 top
If she _______________ how to calibrate the instrument, she _______________ done the experiment.
(A) knows, will have
(B) knew, had
(C) had known, could have
(D) should have known, would have

To answer these i normally use the language(even english itself) i am fluent in.
Option C) makes perfect sense , rest do not relate to each other.
-- Srinath Sri

GATE2014-3_GA_3 top
Choose the word that is opposite in meaning to the word c oherent.
(A) sticky
(B) well-connected
(C) rambling
(D) friendly

C)Rambling
coherent = Logical and clear
Rambling = Confused

-- Srinath Sri

GATE2014-3_GA_6 top
A dance programme is scheduled for 10.00 a.m. Some students are participating in the programme and they need to come an hour earlier than the start of the
event. These students should be accompanied by a parent. Other students and parents should come in time for the programme. The instruction you think that is
appropriate for this is

(A) Students should come at 9.00 a.m. and parents should come at 10.00 a.m.
(B) Participating students should come at 9.00 a.m. accompanied by a parent, and other parents and students should come by 10.00 a.m.
(C) Students who are not participating should come by 10.00 a.m. and they should not bring their parents. Participating students should come at 9.00 a.m.
(D) Participating students should come before 9.00 a.m. Parents who accompany them should come at 9.00 a.m. All others should come at 10.00 a.m.

It will be B.
-- Gate Keeda

GATE2014-3_GA_7 top
By the beginning of the 20th century, several hypotheses were being proposed, suggesting a paradigm shift in our understanding of the
universe. However, the clinching evidence was provided by experimental measurements of the position of a star which was directly behind our
sun.
Which of the following inference(s) may be drawn from the above passage?
i. Our understanding of the universe changes based on the positions of stars
ii. Paradigm shifts usually occur at the beginning of centuries

iii. Stars are important objects in the universe


iv. Experimental evidence was important in confirming this paradigm shift
(A) (i), (ii) and (iv)
(B) (iii) only
(C) (i) and (iv)
(D) (iv) only

A paradigm shift means a fundamental change in approach or underlying assumptions.


And a change in paradigm happens only when we have an experimented evidence. It is crucial to have an evidence.
In this para the evidence was provided by the experimental measurements of the position of a star which was directly behind our sun.

Option D) suits well for the given para.

-- Srinath Sri

GATE2011_56 top
Which of the following options is the closest in the meaning to the word below:
Inexplicable
(A) Incomprehensible
(B) Indelible
(C) Inextricable
(D) Infallible

answer is (a)
Inexplicable => difficult or impossible to explain
Incomprehensible => difficult or impossible to understand or comprehend => Most appropriate
Indelible => impossible to remove, erase or wash away => Not appropriate
Inextricable => unavoidable , inescapable => Not appropriate
Infallible

=> completely dependable or trustworthy => irrelevant

-- Kalpna Bhargav

GATE2012_57 top
Choose the most appropriate alternative from the options given below to complete the following sentence:
Despite several the mission succeeded in its attempt to resolve the conflict.
(A) attempts
(B) setbacks
(C) meetings
(D) delegations

B...setbacks
-- Kathleen Bankson

GATE2012_58 top
Which one of the following options is the closest in meaning to the word given below?

Mitigate
(A) Diminish
(B) Divulge
(C) Dedicate
(D) Denote

A. Diminish
-- Kathleen Bankson

GATE2012_59 top
Choose the grammatically INCORRECT sentence:
(A) They gave us the money back less the service charges of Three Hundred rupees.
(B) This countrys expenditure is not less than that of Bangladesh.
(C) The committee initially asked for a funding of Fifty Lakh rupees, but later settled for a lesser sum.
(D) This countrys expenditure on educational reforms is very less.

D...."is very less" should be "is much less".


-- Kathleen Bankson

GATE2012_60 top
Choose the most appropriate alternative from the options given below to complete the following sentence:
Sureshs dog is the one was hurt in the stampede.
(A) that
(B) which
(C) who
(D) whom

A....that
Who and whom are people, not dogs.
Regarding that and which...
Restrictive ClauseThat
A restrictive clause is just part of a sentence that you can't get rid of because it specifically restricts some other part of the sentence. Here's an
example:
Gems that sparkle often elicit forgiveness.
The words that sparkle restrict the kind of gems you're talking about. Without them, the meaning of the sentence would change. Without
them, you'd be saying that all gems elicit forgiveness, not just the gems that sparkle. (And note that you don't need commas around the
words that sparkle.)
Nonrestrictive ClauseWhich
A nonrestrictive clause is something that can be left off without changing the meaning of the sentence. You can think of a nonrestrictive clause
as simply additional information. Here's an example:
Diamonds, which are expensive, often elicit forgiveness.

-- Kathleen Bankson

GATE2012_61 top
Wanted Temporary, Part-time persons for the post of Field Interviewer to conduct personal interviews to collect and collate

economic data. Requirements: High School-pass, must be available for Day, Evening and Saturday work. Transportation paid,
expenses reimbursed.
Which one of the following is the best inference from the above advertisement?
(A) Gender-discriminatory
(B) Xenophobic
(C) Not designed to make the post attractive
(D) Not gender-discriminatory

D. Not gender_discriminatory. The post mentions "persons" meaning any gender.

Xenophobic means having or showing an intense or irrational dislike or fear of people from other countries, so does not apply.
C and A do not apply.

-- Kathleen Bankson

GATE2010_56 top
Choose the most appropriate word from the options given below to complete the following sentence:
His rather casual remarks on politics ________ his lack of seriousness about the subject.
(A) masked
(B) belied
(C) betrayed
(D) suppressed

answer is option (c)

(a) Masked

: Hide under a false appearance =>opposite

(b) Belied

: Be in contradiction with =>not appropriate

(c) Betrayed

: Reveal unintentionally => most appropriate

(d) Suppressed: To put down by force or authority => irrelevent


-- Kalpna Bhargav

GATE2010_57 top
Which of the following options is the closest in meaning to the word given below:
Circuitous
(A) cyclic
(B) indirect

(C) confusing
(D) crooked

B Indirect
Synonyms for circuitous

adj going around, indirect

-- Kathleen Bankson

GATE2010_58 top
Choose the most appropriate word from the options given below to complete the following sentence:
If we manage to __________ our natural resources, we would leave a better planet for our children.
(A) uphold
(B) restrain
(C) cherish
(D) conserve

D Conserve
-- Kathleen Bankson

GATE2010_60 top
The question below consists of a pair of related words followed by four pairs of words. Select the pair that best expresses the relation in the
original pair.
Unemployed : Worker
(A) fallow : land
(B) unaware : sleeper
(C) wit : jester
(D) renovated : house

A. Fallow: Land
Fallow is land that is uncultivated
Unemployed is a worker without a job
-- Kathleen Bankson

GATE2010_63 top
Modern warfare has changed from large scale clashes of armies to suppression of civilian populations. Chemical agents that do their
work silently appear to be suited to such warfare; and regretfully, there exist people in military establishments who think that
chemical agents are useful tools for their cause.
Which of the following statements best sums up the meaning of the above passage:
(A) Modern warfare has resulted in civil strife.
(B) Chemical agents are useful in modern warfare.
(C) Use of chemical agents in warfare would be undesirable.
(D) People in military establishments like to use chemical agents in war.

D. People in military establishments like to use chemical agents in war.


-- Kathleen Bankson

Complete the sentence: Dare __ mistake.

top

Dare __________ mistake.


A. commit
B. to commit
C. committed
D. commiting

commit. No need of "to" after dare here.


http://www.thefreedictionary.com/DARE
-- Arjun Suresh

GATE2015-2_GA_4 top
A generic term that includes various items of clothing such as a skirt, a pair of trousers and a shirt is

A.
B.
C.
D.

fabric
textile
fibre
apparel

its 'D' apparel


-- Anoop Sonkar

GATE2015-3_GA_2 top
The Tamil version of __________ John Abraham-starrer Madras Cafe __________ cleared by the Censor Board with no cuts last week, but the
film's distributor _______ no takers among the exhibitors for a release in Tamilnadu _______ this Friday.

A.
B.
C.
D.

Mr., was, found, on


a, was, found, at
the, was, found, on
a, being, find at

answer is c
-- naresh1845

GATE2015-3_GA_3 top
Extreme focus on syllabus ans studying for tests has become such a dominant concern of Indian student that they close their minds to anything
___________ to the requirements of the exam.

A. related
B. extraneous
C. outside

D. useful

answer is b
-- naresh1845

GATE2015-3_GA_4 top
Select the pair of best expresses a relationship similar to that expressed in the pair:
Children : Pediatrician

A.
B.
C.
D.

Adult : Orthopaedist
Females : Gynaecologist
Kidney : Nephrologist
Skin : Dermatologist

its B ....Females : Gynaecologist


-- Anoop Sonkar

GATE2015-3_GA_6 top
Alexander turned his attention towards India, since he had conquered Persia.
Which one of the statements below is logically valid and can be inferred from the above sentence?

A.
B.
C.
D.

Alexander would not have turned his attention towards India had he not conquered Persia.
Alexander was not ready to rest on his laurels, and wanted to march to India.
Alexander was not completely in control of his army and could command it to move towards India.
Since Alexander's kingdom extended to Indian borders after the conquest of Persia, he was keen to move further.

Answer should be A......as other options required more information


-- Srijay Deshpande

GATE2015-3_GA_7 top
The head of newly formed government desires to appoint five of the six selected members P, Q, R, S, T and U to portfolios of Home, Power,
Defense, Telecom, and Finance. U does not want any portfolio if S gets one of the five. R wants either Home or Finance or no portfolio. Q says
that if S gets Power or Telecom, then she must get the other one. T insists on a portfolio if P gets one.
Which is the valid distribution of portfolios?

A.
B.
C.
D.

P-Home, Q-Power, R-Defense, S-Telecom, T-Finance


R-Home, S-Power, P-Defense, Q-Telecom, T-Finance
P-Home, Q-Power, T-Defense, S-Telecom, U-Finance
Q-Home, U-Power, T-Defense, R-Telecom, P-Finance

"U does not want any portfolio if S gets one of the five"
So, S and U cannot come together. Option C eliminated.
"R wants either Home or Finance or no portfolio"
So, options A and D eliminated.

So, answer is B.
Just to confirm:
Q says that if S gets Power or Telecom, then she must get the other one
In B, S gets Power and Q gets Telecom
"T insists on a portfolio if P gets one"
In B, T is getting a portfolio.
-- Arjun Suresh

Numerical Ability top


GATE2014-1_GA_5 top
The roots of ax2 +bx+c=0 are real and positive. a, b and c are real. Then ax2 +b|x|+c=0 has
A. no roots
B. 2 real roots
C. 3 real roots
D. 4 real roots

2+b|x|+c=0 and hence we have 4 roots.


Let the positive roots be m and n. Now, -m and -n will also satisfy the equation ax

-- Arjun Suresh

GATE2014-1_GA_4 top
If (z + 1/z)2 = 98, compute (z2 + 1/z2).

Ans: (Z+1/Z)2 = (z2 + 2(z)(1/z) + (1/z)2) = (z2 + 1/z2) +2 = 98 ==>> 98-2 = 96 is answer..
-- Jayesh Malaviya

GATE2014-1_GA_8 top
Round-trip tickets to a tourist destination are eligible for a discount of 10% on the total fare. In addition, groups of 4 or more get a discount of
5% on the total fare. If the one way single person fare is Rs 100, a group of 5 tourists purchasing round-trip tickets will be charged Rs
__________

For individual , Round-trip discount 10% on TOTAL fare . So for each person (200 X 10%)=20 .
So for 5 member 100 rupees .
For 5 member group they will get 5% discount on TOTAL fare i.e. (5x200 X 5%)= 50 rupess.
Total discount is (100+50)=150 . They have to pay 850 rupees

-- Palash Nandi

GATE2014-1_GA_9 top
In a survey, 300 respondents were asked whether they own a vehicle or not. If yes, they were further asked to mention whether they own a car
or scooter or both. Their responses are tabulated below. What percent of respondents do not own a scooter?

Own vehicle

Men

Women

Car

40

34

Scooter

30

20

Both

60

46

20

50

Do not own vehicle

Not having scooter from Men (40 (car owner) + 20 (nothing owns))=60
Not having scooter from Men (34 (car owner) + 50 (nothing owns))=84
percentage =(60+84)/300 =.48 i.e. 48%
-- Palash Nandi

GATE2014-1_GA_10

top

When a point inside of a tetrahedron (a solid with four triangular surfaces) is connected by straight lines to its corners, how many (new) internal
planes are created with these lines?

It is 6.
-- Palash Nandi

GATE2013_64 top
A tourist covers half of his journey by train at 60 km/h, half of the remainder by bus at 30 km/h and the rest by cycle at 10 km/h. The average
speed of the tourist in km/h during his entire journey is
(A) 36

(B) 30

(C) 24

(D) 18

let the total distance be D then


avg speed=D/total time taken
Total time taken=D/2*60+D/4*30+D/4*10
avg speed-120/5=24
-- Bhagirathi Nayak

GATE2014-2_GA_5 top

is

The value of 12 +
12 +
12
(A) 3.464
(B) 3.932
(C) 4.000
(D) 4.444

x =
12
+
x
x2 = 12 + x
x2 x 12 = 0
(x 4)(x + 3) = 0
x = 4 or x = 3
-- Arjun Suresh

GATE2014-3_GA_4 top
Which number does not belong in the series below?

2, 5, 10, 17, 26, 37, 50, 64


(A) 17
(B) 37
(C) 64
(D) 26

If a1 , a2 , a3 ... an is the series and i = 1 to n , then the series is defined as ai=i^2 + 1.


i.e the ith term is 1 plus the square of i.
Series will be as follows : 1^2 + 1 , 2^2 + 1 , 3^2 + 1 , 4^2 + 1 .... n^2 + 1
2,5,10,17,26,37,50,65
Hence 64 does not belong to the series.
-- Srinath Sri

GATE2014-3_GA_10
Consider the equation:

top

(7526)8 (Y )8 = (4364)8 , where (X)N stands for X to the base N . Find Y .

(A) 1634
(B) 1737
(C) 3142
(D) 3162

C)
The given numbers are in octal representation. Digits range from 0 to 7.
Y=7526-4364
7526
-4364
_______
3142
steps : 1. (6-4) =2
2. (2-6) , borrow a 8. Now (8+2-6)=4
3. (5-1-3) = 1

(Subtracted by 1 because ONE 8 was borrowed)

4. (7-4) = 3

-- Srinath Sri

GATE2011_57 top
If

log(P) = (1/2) log(Q) = (1/3) log(R), then which of the following options is TRUE ?

(A)

P2 = Q 3 R2

(B)

Q 2 = PR

(C) Q 2
(D) R

= R3 P

= P2 Q 2

B.
Following Log formula,we get :

P=Q1/2=R1/3
so, Q2= P4= P. P3=PR.

-- shreya ghosh

GATE2011_62 top
P, Q, R and S are four types of dangerous microbes recently found in a human habitat. The area of each circle with its diameter printed in brackets represents the
growth of a single microbe surviving human immunity system within 24 hours of entering the body. The danger to human beings varies proportionately with the
toxicity, potency and growth attributed to a microbe shown in the figure below:

A pharmaceutical company is contemplating the development of a vaccine against the most dangerous microbe. Which microbe should the company target in its
first attempt?
(A) P
(B) Q
(C) R
(D) S

Answer is D.
As per the question, it is quite clear that the danger of a microbe to human being will be directly proportional to potency and growth. At the
same time it is inversely proportional to toxicity, defined as( more dangerous will a microbe be if lesser of its milligram is required).
So,
Level Of Danger (D)

Growth (G)

Potency (P)
1/ Toxicity (T)
D = KGP/T
where K is contant of proportionality.
So level of danger will be maximum for S.
Given by,
D S = 0.8 * (10)2/200
= 1.256
Similar Calculations for DP , DQ , DR can be done. Which will consequently lead to DS being the most dangerous and hence will be targeted
first.
-- Gate Keeda

GATE2011_64 top

A transporter receives the same number of orders each day. Currently, he has some pending orders (backlog) to be shipped. If he uses 7 trucks, then at the end of
the 4th day he can clear all the orders. Alternatively, if he uses only 3 trucks, then all the orders are cleared at the end of the 10 th day. What is the minimum number
of trucks required so that there will be no pending order at the end of 5th day?
(A) 4
(B) 5
(C) 6
(D) 7

Let the amount of orders received per day be x and let the amount of pending orders be y and let the amount of orders carried by a truck each
day be z.
7z * 4 = 4x + y -> (1)
3z * 10 = 10x + y (2)
(2) - (1) => 2z = 6x, z = 3x, y = 80x
We want to find the number of trucks to finish the orders in 5 days. Let it be A.
Az * 5 = 5x + y
15Ax = 5x + 80x
A = 85/15 = 17/3 = 5.67
So, minimum 6 trucks must be used.
-- Arjun Suresh

GATE2011_65 top
A container originally contains 10 litres of pure spirit. From this container 1 litre of spirit replaced with 1 litre of water. Subsequently, 1 litre of the mixture is again
replaced with 1 litre of water and this process is repeated one more time. How much spirit is now left in the container?
(A) 7.58 litres
(B) 7.84 litres
(C) 7 litres
(D) 7.29 litres

Quantity left after n operations = x(1 - y/x)^n


where x = initial quantity
y = amount of mixture withdrawn each time (this should be same every time)
n = no of times operation performed
= 10(1 - 1/10)^n = 10(9/10)^3 = 10*.9*.9*.9 = 10*.729 = 7.29 liters
hence option D is correct.
Reference Video: https://www.youtube.com/watch?v=YYg23Fm3qW0
-- Manu Thakur

GATE2012_56 top
The cost function for a product in a firm is given by5q 2 , where q is the amount of production. The firm can sell the product at a market price of
50 per unit. The number of units to be produced by the firm such that the profit is maximized is
(A) 5
(B) 10
(C) 15
(D) 25

Answer is A. The equation for profit is Profit=SP-CP, here SP=Q*50 and CP=5Q^2 so when a function attains its maximum value its first
order differentiation is zero. Hence 50-5*2*Q=0. therefore Q=5.
-- kireeti

GATE2012_62 top
A political party orders an arch for the entrance to the ground in which the annual convention is being held. The profile of the arch follows the
equation y = 2x 0.1x2 where y is the height of the arch in meters. The maximum possible height of the arch is
(A) 8 meters
(B) 10 meters
(C) 12 meters
(D) 14 meters

B. 10
y = 2x - 0.1x2
dy/dx=2 - 2*0.1 x => dy/dx=0 => x=10
so y= 20-10=10
-- shreya ghosh

GATE2012_63 top
An automobile plant contracted to buy shock absorbers from two suppliers X and Y . X supplies 60% and Y supplies 40% of the shock
absorbers. All shock absorbers are subjected to a quality test. The ones that pass the quality test are considered reliable. Of X s shock
absorbers, 96% are reliable. Of Y s shock absorbers, 72% are reliable.
The probability that a randomly chosen shock absorber, which is found to be reliable, is made by Y is
(A) 0.288
(B) 0.334
(C) 0.667
(D) 0.720

B.

Probability of Y given R =
=

0.40.72
0.40.72+0.60.96

1
3

Probability of Y and R
Probability of R

= 0.33

-- shreya ghosh

GATE2012_64 top
Which of the following assertions are CORRECT?
P: Adding 7 to each entry in a list adds 7 to the mean of the list
Q: Adding 7 to each entry in a list adds 7 to the standard deviation of the list
R: Doubling each entry in a list doubles the mean of the list
S: Doubling each entry in a list leaves the standard deviation of the list unchanged
(A) P, Q
(B) Q, R
(C) P, R
(D) R, S

Suppose we double each entry of a list

Initial Mean (M I ) =

i=1 xi
n

New Mean (M N ) =

i=1 2xi
n

2
n

ni=1 xi

So, when each entry in the list is doubled, mean also gets doubled.

Standard Deviation I = ni=1 (M I xi )2

New Standard Deviation N = ni=1 (M N 2 xi ) 2

= ni=1 (2 (M I xi ))2
= 2 I

So, when each entry is doubled, standard deviation also gets doubled.

When we add a constant to each element of the list, it gets added to the mean as well. This can be seen from the formula of mean.

When we add a constant to each element of the list, the standard deviation (or variance) remains unchanged. This is because, the mean also
gets added by the same constant and hence the deviation from the mean remains the same for each element.

So, here P and R are correct.


-- Arjun Suresh

GATE2012_65 top
Given the sequence of terms, AD CG FK JP, the next term is
(A) OV
(B) OW
(C) PV
(D) PW

A. OV
AD - difference 2 (B,C)
CG - difference 3 (D,E,F)
FK - difference 4 and JP - difference 5
so next term will have 6 differnce
again each term starts with preceding term's 2nd last letter
so JKLMNOP , next term will start with O and having 6 difference it will be OV
-- shreya ghosh

GATE2010_59 top
25 persons are in a room. 15 of them play hockey, 17 of them play football and 10 of them play both hockey and football. Then the number of persons playing

neither hockey nor football is:


(A) 2
(B) 17
(C) 13
(D) 3

D. 3
either play football or hockey = 15+17 -10 = 22
number of persons playing neither hockey nor football is= 25-22=3

-- shreya ghosh

GATE2010_61 top
If

137 + 276 = 435 how much is 731 + 672?

(A) 534
(B) 1403
(C) 1623
(D) 1513

Answer. C.
(137)8 + (276)8 = (435)8
So basically the number are given in Octal base.
Similarly, addition of 731,672 gives 1623 in octal.
-- shreya ghosh

GATE2010_64 top
5 skilled workers can build a wall in 20 days; 8 semi-skilled workers can build a wall in 25 days; 10 unskilled workers can build a wall in 30 days. If a team has 2
skilled, 6 semi-skilled and 5 unskilled workers, how long it will take to build the wall?
(A) 20 days
(B) 18 days
(C) 16 days
(D) 15 days

D. 15 days
1 skilled person can do 1/100 of work in 1 day, so 2 skilled person do 2/100 of work in a day.
similarly, 6 semi-skilled and 5 unskilled person can do 6/200 and 5/300 respectively in 1 day.
so they do 1/15 of work together in 1 day, which gives required number of day to complete the work = 15 .
-- shreya ghosh

GATE2015-1_GA_9 top
The pie chart below has the breakup of the number of students from different departments in an engineering college for the year 2012. The

proportion of male to female students in each department is 5:4. There are 40 males in Electrical Engineering. What is the difference between
the numbers of female students in the civil department and the female students in the Mechanical department?

Number of female students in Electrical = 40 * 4/5 = 32


Number of female students in Civil = 32 * 30/20 = 48 (Since proportion of male students to female students is same, the breakup chart is the
same for number of female students)
Number of female students in Mechanical = 32 * 10/20 = 16
So, answer = 48 - 16 = 32
-- Arjun Suresh

GATE2015-2_GA_5 top
Based on the given statements, select the most appropriate option to solve the given question.
What will be the total weight of 10 poles each of same weight?
Statements:
I. One fourth of the weight of the pole is 5 Kg.
II. The total weight of these poles is 160 Kg more than the total weight of two poles.

A.
B.
C.
D.

Statement I alone is not sufficient.


Statement II alone is not sufficient.
Either I or II alone is sufficient.
Both statements I and II together are not sufficient.

Ans C
-- Vikrant Singh

GATE2015-2_GA_8 top
In a triangle PQR, PS is the angle bisector ofQP R and QP S = 60 . What is the length of PS?

A.
B.

(q+r)
qr
qr
q+r

C.
(q 2 + r2 )
D.

(q+r) 2
qr

As per Angle Bisector theorem,


QS/SR = r/q
QS/(p-QS) = r/q
QS = pr/(q+r) -> (1)
We have in a triangle a/SinA = b/Sin B = c/Sin C
So, from triangle QPS, QS/Sin 60 = PS/Sin Q
PS = QS * Sin Q/ Sin 60 -> (2)
From triangle PQR, p/Sin 120 = q/Sin Q
p = q Sin 120/Sin Q = Sin 60/Sin Q -> (3)
So from (1), (2) and (3),
PS = qr/(q+r)
B choice.
http://en.wikipedia.org/wiki/Angle_bisector_theorem
-- Arjun Suresh

GATE2015-3_GA_1 top
If ROAD is written as URDG, then SWAN should be written as:

A.
B.
C.
D.

VXDQ
VZDQ
VZDP
UXDQ

option B.. VZDQ


(every letter is replaced by third letter in alphabetical order)
-- Anoop Sonkar

GATE2015-3_GA_5 top
A function f(x) is linear and has a value of 29 atx = 2 and 39 at x = 3 . Find its value at x = 5 .

A. 59

B. 45
C. 43
D. 35

f(x) is linear means it is of the form ax+b


given f(-2) and f(3)
solve the equation and find out value for a and b. then find f(5). it will be 43
-- Sankaranarayanan P.N

GATE2015-3_GA_8 top
Choose the most appropriate equation for the function drawn as thick line, in the plot below.

A.
B.
C.
D.

x
x
x
x

= y |y|
= (y |y|)
= y + |y|
= (y + |y|)

When y is -1, x is 2.
When y is positive x is 0.
So, x = (y |y|)
-- Arjun Suresh

GATE2015-3_GA_10

top

The exports and imports (in crores of Rs.) of a country from the year 2000 to 2007 are given in the following bar chart. In which year is the
combined percentage increase in imports and exports the highest?

Exports
Imports

So, 2006.
-- Arjun Suresh

Increase

% Increase = (Increase/Value) *
100

2000 90

2001 110

20

18.18

2002 130

20

15.38

2003 130

2004 150

20

13.33

2005 160

10

6.25

2006 220

60

27.27

2007 230

10

4.35

Mathematical Logic top


GATE2012_1

top

Consider the following logical inferences.

I 1 : If it rains then the cricket match will not be played.


The cricket match was played.
Inference: There was no rain.
I 2 : If it rains then the cricket match will not be played.
It did not rain.
Inference: The cricket match was played.
Which of the following isTRUE?
(A) Both I 1 and I 2 are correct inferences
(B) I 1 is correct but I 2 is not a correct inference
(C) I 1 is not correct but I 2 is a correct inference
(D) Both I 1 and I 2 are not correct inferences

I 1 is a correct inference. I 2 is not a correct inference as it was not mentioned what would have happened if it hadn't rained- They might have
played or they might not have played.
-- Arjun Suresh

GATE2012_13 top
What is the correct translation of the following statement into mathematical logic?
Some real numbers are rational
(A) x(real(x) rational(x))
(B) x(real(x) rational(x))
(C) x(real(x) rational(x))
(D) x(rational(x) real(x))

Meaning of each choices:


(A): There exists a number which is either real or rational
(B): If a number is real it is rational
(C): There exists a number which is real and rational
(D): There exists a number such that if it is rational, it is real
So, (C) is the answer.
-- Arjun Suresh

GATE2013_47 top
Which one of the following is NOT logically equivalent to x(y() z())?

(A) x(z() y())


(B) x(z() y())
(C) x(y() z())
(D) x(y() z())

A useful rule:

x() = (x) ()

i.e.; If some property is true for all x, then it is equivalent ot say that no x exists such that property does not hold for it.
Starting with choices:
A: x(z() y())

x(z() y())
x(z() y())
x(z() y())
x (z() y())
So, A is not matching with the logical statement in question.
B: x(z() y())

x(z() y())
x(z() y())
x(z() y())
x(z() y())
Hence matches with the given statement.
C. x(y() z())

x(y() z())
x(y() z())
x(y() z())
x(y() z())
Hence matches with the given statement.
D: x(y() z())

x(y() z())
x(y() z())
x(y() z())
x (y() z())
x (y() z())
So, D is not matching with the logical statement in question.
Thus both A and D are not logically equivalent to the given statement.
In GATE 2013 marks were given to all for this question
-- Arjun Suresh

GATE1992_92,xv top
Which of the following predicate calculus statements is/are valid?
(1) ((x))P (x) ((x))Q(x) ((x))(P (x) Q(x))
(2) ((x))P (x) ((x))Q(x) ((x))(P (x) Q(x))

(3) ((x))(P (x) Q(x)) ((x))P (x) ((x))Q(x)


(4) ((x))(P (x) Q(x)) ((x))P (x) ((x))Q(x)

(1) The corresponding English meaning: If P (x) is true for all x, or if Q(x) is true for all x, then for all x, either P (x) is true or Q(x) is true. This
is always true and hence valid. To understand deeply, consider X = {3, 6, 9, 12} . For LHS of implication to be true, eitherP (x) must be true
for all elements in X or Q(x) must be true for all elements in X . In either case, if we take each elementx in X , either one of P (x) or Q(x) will
be true. Hence, this implication is always valid.
(If still in doubt, let P (x) mean x is a multiple of 3 and Q(x) means x is a multiple of 2 )
(2) The corresponding English meaning: If P (x) is true for at least one x, and if Q(x) is true for at least one x, then there is at least one x for
which both P (x) and Q(x) are true. This is not always true as P (x) can be true for one x and Q(x) can be true for some other x . To
understand deeply, consider X = {3, 6, 9, 12} . Let P (x) be x is a multiple of 9 and Q(x) be x is a multiple of 6 . Now, LHS of implication is
true, since P (x) is true for x = 9 , and Q(x) is true for x = 6 . But RHS of implication is not true as there is nox for which both P (x) and Q(x)
holds. Hence, this implication is not valid.
(3) If for each x, either P (x) is true or Q(x) is true then P (x) is true for all x or Q(x) is true for all x. Just one read is enough to see this is an
invalid implication. Consider set {2,4,5}. Here every element is either a multiple or 2 or 5. But all elements are neither multiple of 2 nor 5.
(4)If there is at least one x for which either P (x) or Q(x) is true then either it is not the case that P (x) is true for all x or Q(x) is true for at
least one x. This is clearly invalid as LHS of implication becomes true ifP (x) is true for some x and Q(x) is not true for any x, but RHS will
be false.
A little modification to the statement is enough to make it valid:

(x)(P (x) Q(x)) ((x) P (x)) (x)Q(x)


which means if there is at least one x for which either P (x) or Q(x) is true then
either it is not the case that P (x) is true for all x (which means P(x) is true for some x) or Q(x) is true for some x.
Note
De Morgan's law is applicable in first order logic and is quite useful:

(x)(P (x)) (x)(P (x))


This is a logical reasoning statement which means ifP (x) is true for all x, then there can never exist an x for which P (x) is not true. This
formula is quite useful in proving validity of many statements as is its converse given below:

(x)(P (x)) (x)(P (x))


-- gatecse

GATE2001_1.3

top

Consider two well-formed formulas in propositional logic

F 1 : P P

F 2 : (P P ) (P P )

Which one of the following statements is correct?


(A) F1 is satisfiable, F2 is valid
(B) F1 unsatisfiable, F2 is satisfiable
(C) F1 is unsatisfiable, F2 is valid
(D) F1 and F2 are both satisfiable

F1: P => P
= P V P
=P
F2:

can be true when P is false ( Atleast one T hence satisfiable)

(P => P)V( P=>P)


= P V (P V P)
=PVP
=T

VALID
Option A
-- Manali

GATE2009_23 top
Which one of the following is the most appropriate logical formula to represent the statement?
"Gold and silver ornaments are precious".

The following notations are used:

G(x) : x is a gold ornament


S(x) : x is a silver ornament
P (x) : x is precious
(A) x(P (x) (G(x) S(x)))
(B) x((G(x) S(x)) P (x))
(C) x((G(x) S(x)) P (x))
(D) x((G(x) S(x)) P (x))

is D.

Answer

-- Praneeth A S

GATE2009_24 top
The binary operation is defined as follows

PQ

Which one of the following is equivalent toP Q ?


(A) Q P
(B) P Q
(C) P Q
(D) P Q

Answer is B because the truth values for option B is same as that of P "or" Q.

+P.
The given truth table is for Q P which is Q
+ P = P + Q
Now, with A option we get Q
-- chetna

GATE2002_1.8

top

"If X then Y unless Z" is represented by which of the following formulas in prepositional logic? (" " is negation, " " is conjunction, and "" is
implication)
A.
B.
C.
D.

(X Z) Y
(X Y ) Z
X (Y Z)
(X Y ) Z

while ( not z ) {
if (X) then
Y
}
or
unless( z ) {
if (X) then
Y
}

this is what it means in programming. if you want to execute statement Y then X must be True and Z False,
which is equivalent to (X AND NOT Z)-->Y
option A
-- Vikrant Singh

GATE2003_33 top
Consider the following formula and its two interpretations I 1 and I 2 .

: (x)[Px (y)[Q xy Q yy ]] (x)[Px ]


I 1 : Domain: the set of natural numbers
Px = 'x is a prime number'
Q xy = 'y divides x'
I 2 : same as I 1 except that Px = 'x is a composite number'.
Which of the following statements is true?
(A) I 1 satisfies , I 2 does not (B) I 2 satisfies , I 1 does not
(C) Neither I 1 nor I 2 satisfies (D) Both I 1 and I 2 satisfies

in words:

LHS implies RHS, where for I 1


LHS = If for all x, x is prime if and only if for all y, y is a factor of x if and only if y does not divide itself. In other words, for all x, if x is prime, x
cannot have any factor and if x is not having any factor then x is prime.
RHS = All x are non-prime
Here LHS is always TRUE but RHS is not true as domain of x is set of natural numbers and hence x cannot be always not prime. So, is not
satisfiable for I 1 .
Now for I 2 ,
LHS = If for all x, x is composite if and only if for all y, y is a factor of x if and only if y does not divide itself. In other words, for all x, if x is
composite, x cannot have any factor and if x is not having any factor then x is composite.
RHS = All x are non-composite
Here, LHS can never be true. x can either be prime or composite. If x is composite, P (x) is true but the right side of double implication is false.
If x is prime, P (x) is false, but right side of double implication is true. So, the double implication never returns TRUE making LHS of always

FALSE. So, becomes TRUE irrespective of RHS and I 2 is satisfiable.


-- Arjun Suresh

GATE2004_23 top
Identify the correct translation into logical notation of the following assertion.
Some boys in the class are taller than all the girls
Note: taller (x, y) is true if x is taller than y.

A. (x)(boy(x) (y)(girl(y) taller(x, y)))


B. (x)(boy(x) (y)(girl(y) taller(x, y)))
C. (x)(boy(x) (y)(girl(y) taller(x, y)))
D. (x)(boy(x) (y)(girl(y) taller(x, y)))

(x)(boy(x) (y)(girl(y) taller(x, y)))


Should be the answer.
-- Arjun Suresh

GATE2010_30 top
Suppose the predicate F(x, y, t) is used to represent the statement that person x can fool person y at time t. which one of the statements below
expresses best the meaning of the formula

xyt(F (x, y, t))


?
(A) Everyone can fool some person at some time
(B) No one can fool everyone all the time
(C) Everyone cannot fool some person all the time
(D) No one can fool some person at some time

B is the correct answer.the trick is bring the negate sign to the extreme left ..form a sentence withou using negate and just negate that
-- Bhagirathi Nayak

GATE2005_41 top
What is the first order predicate calculus statement equivalent to the following?
"Every teacher is liked by some student"
(A) (x)[teacher(x) (y)[student(y) likes(y, x)]]
(B) (x)[teacher(x) (y)[student(y) likes(y, x)]]
(C) (y)(x)[teacher(x) [student(y) likes(y, x)]]
(D) (x)[teacher(x) (y)[student(y) likes(y, x)]]

Answer is B. In simpler way we can sayIf X is a teacher then there exists some Y who is a student and likes X.
A choice: If X is a teacher, then there exists a Y such that if Y is a student, then Y likes X.
C choice: There exist a student who likes all teachers.
D choice: Everyone is a teacher and there exists a Y such that if Y is student then y likes X. Assuming one cannot be both student and

teacher at same time, this just means, everyone is a teacher.

-- Manali

GATE2007_22 top
Let Graph(x) be a predicate which denotes that x is a graph. Let Connected(x) be a predicate which denotes that x is connected. Which of
the following first order logic sentences DOES NOT represent the statement:
"Not every graph is connected"?

(A) x(Graph(x) Connected(x))


(B) x(Graph(x) Connected(x))
(C) x(Graph(x) Connected(x))
(D) x(Graph(x) Connected(x))

D says "all graphs are not connected" but the qs says " not every graph is connected" .i.e " there exists atleast one graph which is not
connected". Hence the answer is D
-- Manali

GATE2013_27 top
What is the logical translation of the following statement?
"None of my friends are perfect."
(A) x(F (x) P (x))
(B) x(F (x) P (x))
(C)x(F (x) P (x))
(D)x(F (x) P (x))

A. some of my friends are not perfect


B. some of those who are not my friends are perfect
C. some of those who are not my friends are not perfect
D. NOT (some of my friends are perfect) / none of my friends are perfect

-- Bhagirathi Nayak

GATE1998_1.5

top

A only if B => A->B


A= "I stay"
B= "You go"
converse of A->B is B->A
" If you go then I stay "
Answer: A
-- Manali

GATE2014-1_53 top
Which one of the following propositional logic formulas is TRUE when exactly two of
(A)

((p q) r) (p q r)

(B)

( (p q) r) (p q r)

(C) ((p

q) r) (p q r)

(D) (

(p q) r) (p q r)

p, q and r are TRUE ?

A. will be true if P,Q,R are true,((p q) r) will return true. So "exactly two" is false
C. if r is only true and p and q are false, first part of implication itself will result in true
D. if r is true or false, this returns false due to r and ~r present in conjunction.
B is the answer. B is true if p is TRUE and q is FALSE or vice verse, and r is true or if p and q are TRUE and r is FALSE.
PS: Actually the question should have been "TRUE ONLY when exactly two of p,q and r are TRUE"
-- Manu Thakur

GATE2014-3_1 top
Consider the following statements:
P: Good mobile phones are not cheap
Q: Cheap mobile phones are not good

L: P implies Q
M: Q implies P
N: P is equivalent to Q
Which one of the following about L, M, and N isCORRECT?
(A) Only L is TRUE.
(B) Only M is TRUE.
(C) Only N is TRUE.
(D) L, M and N are TRUE.

D)
Lets break the given compound statements into atomic statements.
A : Good mobile phones.
B : Cheap mobile phones.

P : A --> ~B <=> ~A v ~B
Q : B --> ~A <=> ~B v ~A <=> ~A v ~B (Disjunction is commutative)
Hence P <=> Q
( P is equivalent to Q, which means P imples Q ,and Q implies P)
-- Srinath Sri

GATE2014-3_53 top
The CORRECT formula for the sentence, "not all Rainy days are Cold" is
(A)

d(Rainy(d) ~Cold(d))

(B)

d(~Rainy(d) Cold(d))

(C) d(~Rainy(d)
(D) (Rainy(d)

Cold(d))

~Cold(d))

Not all rainy days are cold.


In other words it says "Some rainy days are cold" or "Some rainy days are not cold"

Given statement is
~Vd[R(d)->C(d)]
<=>~Vd[~R(d)VC(d)]
<=> d[R(d) ^ ~C(d)]
D)

-- Srinath Sri

GATE1997_3.2

top

C) P OR (P -->Q) = P OR (NOT P OR Q)
=(P OR NOT P) OR Q
=T OR Q
=T
-- Manali

GATE1993_8.2

top

OPTION (B)
-- Manali

GATE1994_3.13 top

Associativity rule

Let p and q be propositions. Using only the Truth Table, decide whether

p q does not imply p q


is True or False.

p q pq

p q

(p q) (p q)

0 0

0 1

1 0

1 1

So, "imply" is FALSE making does not imply TRUE.


-- Arjun Suresh

GATE1996_2.3

top

OPTION D... when x= F & y=F


-- Manali

GATE2008-IT_22 top
Which of the following is the negation of [ x, (y, ( u, v, y))]

A. [ x, (y, (u, v, y))]


B. [ x, (y, (u, v, y))]
C.

[ x, (y, (u, v,
y))]

D. [ x, (y, (u, v, y))]

[ x, (y, ( u, v, y))] = [ x, v (y, v ( u, v, y))]


Now, doing complement gives (complement of is and vice versa while propagating negation inwards as x (P) = x (P) and x (P)
= x (P))
[ x, (y, ( u, v, y))]
D choice
-- Arjun Suresh

GATE2007-IT_21 top
Which one of these first-order logic formulae is valid?

A)

x(P(x) =>
xQ(x))

Q(x))

=>

(xP(x)

=>

B) x(P(x) Q(x)) => (xP(x) => xQ(x))


C) x(P(x) Q(x)) <=> (xP(x) xQ(x))
D) xy P(x, y) => yx P(x, y)

(A) is the answer


(A)
LHS: For every x, if P holds then Q holds
RHS: If P(x) holds for all x, then Q(x) holds for all x.
LHS implies RHS but RHS does not imply LHS.
(B)
LHS: An x exist for which either P(x) is true or Q(x) is true.
RHS: If an x exist for which P(x) is true then another x exist for which Q(x) is true.
LHS does not imply RHS, but on RHS if we change xP(x) to ~xP(x), implication becomes TRUE.
(C)
LHS: There exist an x for which both P(x) and Q(x) are true.
RHS: There exist an x for which P(x) is true and there exist an x for which Q(x) is true.
LHS implies RHS but RHS does not imply LHS as the 'x' for P and Q can be different on the RHS
(DP
LHS: For every x, there exist a y such that P(x, y) holds.
RHS: There exist a y such that for all x P(x, y) holds.
Here RHS implies LHS but LHS does not imply RHS as the y on LHS can be different for each x.
-- Arjun Suresh

GATE2006-IT_21 top
Consider the following first order logic formula in which R is a binary relation symbol.
xy (R(x, y) => R(y, x))
The formula is

A)

satisfiable and valid

B)

satisfiable and so is its negation

C)

unsatisfiable but its negation is valid

D)

satisfiable but its negation is unsatisfiable

The given relation is nothing but symmetry. We have both symmetric relations possible as well as anti-symmetric but neither always holds for
all sets. So they both are not valid but are satisfiable. B option.
-- Arjun Suresh

GATE2005-IT_36 top
Let P(x) and Q(x) be arbitrary predicates. Which of the following statements is always TRUE?
A.
B.
C.
D.

((x(P (x) Q(x)))) ((xP (x)) (xQ(x)))


(x(P (x) Q(x))) ((xP (x)) (xQ(x)))
(x(P (x)) x(Q(x))) (x(P (x) Q(x)))
(x(P (x)) (x(Q(x)))) (x (P (x) Q(x)))

Answer: B
Let P: Student is a girl.
and Q: Student is smart.
Option B says: IF for all student x if x is a girl then the student is smart THEN if the whole class comprises of girls then the whole class
comprises of smart students.
-- Jon Snow

Use quantifiers to express:->There is exactly one person whom everybody loves

top

Let L(x, y) be the statement "x loves y," where the domain for both x and y consists of all people in the world.
Use quantifiers to express:
Q->There is exactly one person whom everybody loves.
E-some || A-for all ||
Answer-> Ex ( AyL(y,x) ^ Az((Aw L(w,z))->z=x) )
Can anyone explain the answer and how to solve these questions
i mean how to analyze these questions??

First of all we have only two quantifiers- exists and forall. So, first try to convert the given sentence into a sentence containing those (its just
English)
There is exactly one person whom everybody loves
This can be rewritten as
There is someone who is loved by everyone, and there is no one else who is loved by everyone
Again translated as:
There is someone, x, who is loved by everyone, and if there is another one, y, who is loved by everyone else, means x and y are
the same person.
This can be translated into first order logic (first order logic is just propositional logic with and )
x(y(y,x) (z(w(w,x)) (z = x)))
(In the given answer in question z is used in place of z which is wrong)
Here actually in place of w, we can use y as the life of y expires immediately after y(y,x) this. Using w instead of y is strictly not needed.
You can also try to express "There is at most one person whom everybody loves"
Now, the translations I did is based on my knowledge about the expressive powers of first order logic. Thats is first order logic can't be used
for all statement forms- we first need to convert it into a suitable form. Luckily there are only a few cases, which you will get experienced by
solving previous year questions in this topic. You can see the below 3 questions and they should cover almost any type of question from this
topic.
http://gateoverflow.in/256/gate1992_92-xv
http://gateoverflow.in/923/gate2003_33
http://gateoverflow.in/922/gate2003_32

-- Arjun Suresh

GATE2002_5b top
Determine whether each of the following is a tautology, a contradiction, or neither (" " is disjunction, " " is conjunction, "" is implication, " "
is negation, and "" is biconditional (if and only if).

A. A (A A)
B. (A B) B
C. A ((A B))

This can be solved by Truth table. But there is something else which can be done quickly. See what each formula means:
1. A(AA) It says if A then (A or A) and if (A or A) then A. Always a tautology
2. (AB)B If A or B then B. No guarantee that if only A is true, B need to be true. Hence neither tautology nor contradiction
3. A((AB)) When A is true (AB) will be false. So, this formula is a contradiction
-- Arjun Suresh

Comment on (R,*) group / commutative / monoid

top

Which of the following true about (R,*)?


1) Group but not commutative
2) A commutative group
3) Not a semigroup
4) Not a monoid

Its a monoid.
Closure, associativity, Identity are defined for Real numbers.But inverse is not defined as R can be zero also. So (R,*) is neither Group nor
Abelian(commutative), but Monoid.
-- GateMaster Prime

Which of the following is a tautology?

top

P Q = P Q
Q P = Q P
Hence, D is correct.
C choice is also correct as is usually taken as right associative (See here: http://math.stackexchange.com/questions/12223/associativity-oflogical-connectives ). It'll be interpreted as

((P Q) (Q R)) (P R)
This is a tautology.
-- Arjun Suresh

maths_mocktest1_11

top

A + B, is satisfiable when either A or B is 1. But not tautology. as both A and B can 0.

A tautology means any assignment to variables produces a 1. So, it is trivially satisfiable.


A contradiction means any assignment ot variables produces a 0. So, it can never be satisfied.
Coming to B option, it says Every satisfiable formula is not tautology. This is wrong as valid formula is both satisfiable as well as tautology. If
we change "every" to "some", B option becomes correct. Actually this sentence is not grammatically correct and can also be interpreted as
"Every satisfiable formula is not a tautology" meaning some satsfiable formula is not tautology. In this case B option becomes TRUE.
-- Arjun Suresh

GATE2015-2_3 top
Consider the following two statements.
S1: If a candidate is known to be corrupt, then he will not be elected
S2: If a candidate is kind, he will be elected
Which one of the following statements follows from S1 and S2 as per sound inference rules of logic?

A.
B.
C.
D.

If a person is known to be corrupt, he is kind


If a person is not known to be corrupt, he is not kind
If a person is kind, he is not known to be corrupt
If a person is not kind, he is not known to be corrupt

option c ...If a person is kind, he is not known to be corrupt


-- Anoop Sonkar

GATE2015-1_14 top
Which one of the following is NOT equivalent to p q?
A.
B.
C.
D.

(p q) (p q)
(p q) (q p)
(p q) ( p q)
(p q) (p q)

pq
= (p q) (qp)
= (p q) (q p)

( As p q = p q )

=(p q) (q p)
=(p q) (p q)
So, answer C
-- Priya_das

GATE2015-2_55 top
Which one of the following well formed formulae is a tautology?

A.
B.
C.
D.

x y R(x, y) y x R(x, y)
(x [y R(x, y) S(x, y)]) x y S(x, y)
[x y (P (x, y) R(x, y))] [x y(P (x, y) R(x, y))]
x y P (x, y) x y P (y, x)

Ans C.

(P Q) (P Q)

D is wrong as shown below.


Let S = {2, 3, 4, 5} and P (x, y) be x < y .
Now, P(2,3) is true but P(3,2), P(4,2) etc are false and hence the implication also.
This is because the given formula is evaluated as:

x y (P (x, y) x y P (y, x))


The below one is a tautology.

(x yP (x, y) ) (xy P (y, x))

-- Vikrant Singh

GATE2015-3_24 top
In a room there are only two types of people, namely Type 1 and Type 2. Type 1 people always tell the truth and Type 2 people always lie. You
give a fair coin to a person in that room, without knowing which type he is from and tell him to toss it and hide the result from you till you ask for
it. Upon asking the person replies the following
"The result of the toss is head if and only if I am telling the truth"
Which of the following options is correct?

A.
B.
C.
D.

The result is head


The result is tail
If the person is of Type 2, then the result is tail
If the person is of Type 1, then the result is tail

Person 1, result is head. No doubt here as he is a truth teller.


Person 2. result is head if and only if he is telling truth. He is telling lies. So, the truth is the opposite of his statement. We can analyze his
statement as two
1. If I'm telling the truth result is head
2. If result is head I'm telling the truth
Both these are of the form A B = A B. Now, the truth will be the negation of these statements which will beA B which can be
expressed as
1. I'm telling the truth and result is not head
2. Result is not head and I'm telling false
Both of these means, result is head. (Actually even if iff is replaced with if, answer would be A)
So, option A.
-- Arjun Suresh

What is the correct representation of the stmt in first-order predicate calculus ?

top

a is correct.
b

is

wrong

due

to

implication

having

lower

precedence

(xy man(x) intelligent(x)) (knowledge(y) have knowledge(x, y)).

than

quantifiers.

Here, for the RHS, there is no quantification for x or y , meaning it must be true for every x and y .
We can make (b) correct by writing it as follows:

xy(man(x) intelligent(x) knowledge(y) have knowledge(x, y))


Ref: https://en.wikipedia.org/wiki/First-order_logic#Notational_conventions
-- Arjun Suresh

It

will

be

evaluated

as

Probability top
GATE2008_27 top
Aishwarya studies either computer science or mathematics everyday. If she studies computer science on a day, then the probability that she
studies mathematics the next day is 0.6. If she studies mathematics on a day, then the probability that she studies computer science the next
day is 0.4. Given that Aishwarya studies computer science on Monday, what is the probability that she studies computer science on
Wednesday?
(A) 0.24

(B) 0.36

(C) 0.4

(D) 0.6

answer - C
prob of studying CS on Tue = 0.4
prob of studying CS on Wed given that it was studied on Tue = 0.4 x 0.4 = 0.16
prob of studying Math on Tue = 0.6
prob of studying CS on Wed given that Math was studied on Tue = 0.6 x 0.4 = 0.24
prob = 0.16 + 0.24 = 0.4
-- ankitrokdeonsns

GATE2000_1.1

top

The minimum number of cards to be dealt from an arbitrarily shuffled deck of 52 cards to guarantee that three cards are from same suit is
(a) 3

(b) 8

(c) 9

(d) 12

There are 4 sets of cards. So, up till 8 cards there is a chance that no more than 2 cards are from a given set. But, once we pick theth9 one, it
should make 3 cards from any one of the sets. So, (C) is the answer.
-- gatecse

GATE2001_2.4

top

Seven (distinct) car accidents occurred in a week. What is the probability that they all occurred on the same day?
(a)

1
77

(b)

1
76

(c)

1
27

(d)

7
27

answer - B [EDIT]
for every car accident we can pick a day in 7 ways
total number of ways in which accidents can be assigned to days = 77
probability of accidents happening on a particular day = 1/77
we can choose a day in 7 ways
hence probability = 7/77= 1/76

-- ankitrokdeonsns

GATE1995_1.18 top

The probability that a number selected at random between 100 and 999 (both inclusive) will not contain the digit 7 is:
(a) 16/25
(b) (9/10)3
(c)27/75
(d) 18/25

First digit can be chosen in 8 ways from 19 excluding 7


Second digit can be chosen in 9 ways from 09 excluding 7 and similarly the third digit in 9 ways.
So, total no. of ways excluding 7 = 899
Total no. of ways including 7 = 91010
So, ans = (899)/(91010)=18/25
-- gatecse

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

n
2

Why is the third term

, and not

The way I see it, the probability of getting it in 2nd try is: Probability of failing at first trial times probability of succeeding in 2nd trial.
It's not like we are removing one element from the list after the first trial.

Here is my calculation and proof:

-- Pragy Agarwal

GATE2002_2.16 top
Four fair coins are tossed simultaneously. The probability that at least one head and one tail turn up is

A.

1
16

B.

1
8

C.

7
8

D.

15
16

answer - C
probability of getting all heads = 1/16
probability of getting all tails = 1/16
probability of getting at least one head and one tail = 1 - 1/16 - 1/16 = 7/8
-- ankitrokdeonsns

GATE2006_21 top
For each element in a set of size 2n, an unbiased coin is tossed. The 2n coin tosses are independent. An element is chosen if the
corresponding coin toss was a head. The probability that exactly n elements are chosen is
(A)
(B)
(C)
(D)

2n C

2n C

4n
2n
1

2n C

1
2

answer - A
ways of getting n heads out of 2n tries =2nC n
probability of getting exactly n heads and n tails = (1/2n)(1/2n)

number of ways = 2nC n/4n


-- ankitrokdeonsns

GATE2004_78 top
Two n bit binary strings, S 1 and S 2 are chosen randomly with uniform probability. The probability that the Hamming distance between these
strings (the number of bit positions where the two strings differ) is equal to d is

A.

C d /2 n

B.

C d /2 d

C. d/2 n
D. 1/2 d

answer - A
there n binary digits that can differ but only d should differe in this case
ways of choosing these d digits nC d
probability of d digits differ and n - d digits do not differ = (1/2)d(1/2)(n - d)
no of ways = nC d/2n
-- ankitrokdeonsns

GATE2010_27 top
What is the probability that divisor of 1099 is a multiple of 1096 ?
(A) 1/625 (B) 4/625 (C) 12/625 (D) 16/625

Prime factorization of 10 = 2 5 .
So, 1099 = 2 99 5 99 and
No. of possible factors for 1099 = No. of ways in which prime factors can be combined
= 100 100 (1 extra possibility for each prime number as prime factor raised to 0 is also possible for a factor)

1099 = 1096 1000

So, no. of multiples of 1096 which divides 1099 = No. of possible factors of 1000

= 4 4( 1000 = 2 3 5 3 ) (See below)


= 16
So, required probability =

16
10000

1
625

How number of possible factors of 1000 = 16?


Here we can prime factorize 1000 as 2 3 5 3 . Now, any factor of 1000 will be some combination of these prime factors. For 2, a factor has 4
1.
2. .
n
options - 2 0 , 2 1 , 2 2 or 2 4 . Similarly 4 options for 5 also. This is true for any numbern , if n can be prime factorized as am
am
am
n ,
1
2
number of factors of n = (m1 + 1) (m2 + 1) (mn + 1) ,
the extra one in each factor term coming for power being 0.
-- Arjun Suresh

GATE2005_52 top
A random bit string of length n is constructed by tossing a fair coin n times and setting a bit to 0 or 1 depending on outcomes head and tail,
respectively. The probability that two such randomly generated strings are not identical is:
(A)

1
2n

(B) 1

1
n

(C)

1
n!

(D) 1

1
2n

answer - D
suppose there are k places within n bit string where mismatch has occoured
probability of this occouring is nC k (prob. of mismatch)k (prob. of match)(n - k) = nC k (1/2)k (1/2)(n-k) = nC k (1/2)n
k can range from 1 to n hence required probability sum(nC k (1/2)n) where k ranges from 1 to n
hence (1/2 n)(2n - 1)
Alternatively
Probability of matching at given place 1/2
there are n places hence probability of matching 1/(2n)
hence probability of mismatch 1 - 1/(2n)
-- ankitrokdeonsns

GATE2007_24 top
Suppose we uniformly and randomly select a permutation from the 20! permutations of 1, 2, 3 ... ,20. What is the probability that 2 appears at
an earlier position than any other even number in the selected permutation?
(A)

1
2

(B)

1
10

9!
20!

(C)

(D) None of these

There are 10 even numbers (2,4,..20) possible as the one in the earliest position and all of these are equally likely. So, the probability of 2
becoming the earliest is simply 1 .
10

-- Arjun Suresh

GATE2013_24 top
Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the
expected number of unordered cycles of length three?
(A) 1/8 (B) 1 (C) 7 (D) 8

A cycle of length 3 requires 3 vertices.


Number of ways in which we can choose 3 vertices from 8 =8C 3 =56.
Probability that 3 vertices form a cycle = Probability of edge between vertices 1 and 2 * Probability of edge between vertices 2 and 3
* Probability of edge between vertices 1 and 3
=1/2 * 1/2 * 1/2 = 1/8
So, expected number of cycles of length 3 = 56 * 1/8 = 7
-- Arjun Suresh

GATE1998_1.1

top

A die is rolled three times. The probability that exactly one odd number turns up among the three outcomes is

(a)

1
6

(b)

3
8

(c)

1
8

(d)

1
2

answer - B
there are total 8 possible combinations for three rolls of the die
out of them only 3 will have exactly one odd number {OEE, EOE, EEO}
probability = 3/8
-- ankitrokdeonsns

GATE1998_3a top
Two friends agree to meet at a park with the following conditions. Each will reach the park between 4:00 pm and 5:00 pm and will see if the
other has already arrived. If not, they will wait for 10 minutes or the end of the hour whichever is earlier and leave. What is the probability that
the two will not meet?

We are given that both will be reaching the park between 4:00 and 5:00.
Probability that one friend arrives between 4:00 and 4:50 = 5/6
Probability that one friend arrives between 4:00 and 4:50 and meets the other arriving in the next 10 minutes = 5/6 * 1/6 * 2 = 10/36 = 5/18
(For any time of arrival between 4:00 and 4:50, we have a 10 minute interval possible for the second friend to arrive, and 2 cases as for
choosing which friend arrives first)
Probability that both friend arrives between 4:50 and 5:00 = 1/6*1/6 = 1/36
This covers all possibility of a meet. So, required probability of non-meet
= 1 - (5/18 + 1/36)
= 1 - 11/36
=25/36
-- Arjun Suresh

GATE2014-1_2 top
Suppose you break a stick of unit length at a point chosen uniformly at random. Then the expected length of the shorter stick is ________ .

Length of shorter stick can be from 0 to 0.5 (because if it is greater than 0.5, it is no longer a shorter stick). This random variable L (length of
shorter stick) follows a uniform distribution, and hence probability density function of L is

for all lengths in range 0 to 0.5.

Now expected value of L =


-- Happy Mittal

GATE2014-1_48 top
Four fair six-sided dice are rolled. The probability that the sum of the results being 22 is

X . The value of
1296

There are only two possible sets whose elements sum to 22 : {6,6,6,4}, {6,6,5,5}
Number of permutations for 1st set : 4!/3! = 4

X is _______

Number of permutations for 2nd set : 4!/(2!*2!) = 6


So total number of ways to sum 22 = 10
So X =10.
-- Happy Mittal

GATE-2014-2_1 top
The security system at an IT office is composed of 10 computers of which exactly four are working. To check whether the system is functional, the officials inspect
four of the computers picked at random (without replacement). The system is deemed functional if at least three of the four computers inspected are working. Let
the probability that the system is deemed functional be denoted by p. Then 100p = _____________.

Initially P(working computer) = 4/10, P(non-working computer) = 6/10.


Case 1 : three computers are functional : There are 4 sub-cases WWWN, WWNW, WNWW, NWWW, where W means working, N means
non-working, but P(WWWN) = P(WWNW) = P(WNWW) = P(NWWW), because for example

In all other 3 sub-cases, we get same numerators and denominators (in different order), so total prob in this case is 4*144/5040 = 576/5040.
Case 2 : all 4 are working

P(atleast 3 are working) = 600/5040


So 100 * p =11.90
-- Happy Mittal

GATE2014-2_2 top
Each of the nine words in the sentence T he quick

brown fox jumps over the lazy dog is written on a separate piece of paper. These nine pieces of

paper are kept in a box. One of the pieces is drawn at random from the box. The expected length of the word drawn is _____________. (The answer should be
rounded to one decimal place.)

Each of the nine words have equal probability. So, expected length

= 3
= 35
9
= 3.9

1
9

+ 5

1
9

+ 5

1
9

+ 3

1
9

+5

1
9

+4

1
9

+3

1
9

+4

1
9

+3

1
9

-- Arjun Suresh

GATE2011_3

top

If two fair coins are flipped and at least one of the outcomes is known to be a head, what is the probability that both outcomes are heads?
(A)

1/3

(B)

1/4

(C) 1/2
(D) 2/3

answer - A
prob(at least one head) = 3/4
prob(both heads) = 1/4

using bayes' theorem = (1/4)/(3/4) = 1/3


-- ankitrokdeonsns

GATE1994_1.4

top

(a) is true only if events are independent.


(b) is true only if events are mutually exclusive i.e.
(c) is false everywhere
(d) is always true as
Since

-- Happy Mittal

GATE1994_2.8

top

P(A) = 0.8 P(A') = 1-.8 = .2


P(B) = 0.5 P(A') = 1-.8 = .5
P(C) = 0.3 P(A') = 1-.8 = .7
P(No event will occur): = .2*.5*.7 =.07
P(at least 1 event will occur): 1 - .07 = .93
-- Manu Thakur

GATE1995_2.14 top

answer - C
probability of first ball white and second one black = (10/25)x(15/24)
probability of first ball black and second one white = (15/25)x(10/24)
probabilty = sum of above two probabilities = 1/2
-- ankitrokdeonsns

GATE1996_1.5

top

1-(no 6 in both the dice)=1-(5/6 *5/6)=11/36


-- Bhagirathi Nayak

GATE1996_2.7

top

There are 52 cards including 4 aces so the probabilit must be 4/52 * 3/51
-- Bhagirathi Nayak

GATE2006-IT_22 top
When a coin is tossed, the probability of getting a Head is p, 0 < p< 1. Let N be the random variable denoting the number of tosses till the first
Head appears, including the toss where the Head appears. Assuming that successive tosses are independent, the expected value of N is

A)

1/P

B)

1/(1 - P)

C)

1/P2

D)

1/(1 - P2)

E = p * 1 + (1 - p)p * 2 + (1 - p)(1 - p)p * 3 +....


multiply both side with (1 - p) and subtract:
E - (1 - p)E = p * 1 + (1 - p)p + (1 - p)(1 - p)p +.... = p /(1 - (1 -p)) = 1 (because it's now forming a GP)
=>(1 - 1 + p)E = 1
=> E = 1 / P

So, Option (A)...


-- Vicky Bajoria

GATE2004-IT_33 top
Let X and Y be two exponentially distributed and independent random variables with mean and , respectively. If Z = min (X, Y), then the
mean of Z is given by

A)

(1/( + ))

B)

min (, )

C)

(/( + ))

D)

X is an exponential random variable of parameter when its probability distribution function is


f(x) = { e
0

x0
x<0

For a > 0, we have the cumulative distribution function

Fx (a) =

a
0

f(x)dx =

a
0

ex dx = ex a0 = 1 ea

So,

P {X < a} = 1 ea
and

P {X > a} = ea
Now, we use P {X > a} for our problem because our concerned variable Z is min of X and Y .
For exponential distribution with parameter , mean is given by
We have,

1.

P {X > a} = e a
1

P {Y > a} = e a
P {Z > a} = P {X > a} P {Y > a}( X and Y are independent events and
Z > min(X, Y ) )
So,

= e a e a
1

=e
=e

+ 1 )a

)a

This shows that Z is also exponentially distributed with parameter

and mean

.
+

R
e
f
: http://ocw.mit.edu/courses/mathematics/18-440-probability-and-random-variables-spring-2011/lecturenotes/MIT18_440S11_Lecture20.pdf
-- Arjun Suresh

Bayes Theorem

top

Probability of Urn 3 given the balls are white and green


= P(Urn 3 and white + Urn 3 and green)/ P(white and green)
= P(Urn 3 and white + Urn 3 and green)/ [P(Urn 3 and white + Urn 3 and green) + P(Urn 2 and white + Urn 2 and green) + P(Urn 1 and white
+ Urn 1 and green)]
= 1/3 * (4/12 * 3/11 * 2C1) / [1/3 * (4/12 * 3/11 * 2C1) + 1/3 * (2/4 * 1/3 * 2C1) + 1/3 * (1/6 * 3/5 * 2C1)]
= (2/33) / (2/33 + 1/9 + 1/15)
= (2/33) / ( 30 + 55 + 33)/495
= 2 * 15/118
= 15/59
(2C1 is multiplied because the 2 balls could be drawn in 2C1 ways)
-- Arjun Suresh

GATE2015-3_37 top
for i = 1, 2, 3 are independent and identically distributed random variables whose probability mass functions are
P r[X i = 0] = P r[X i = 1] = 12 for i = 1, 2, 3 . Define another random variable Y = X 1 X 2 X 3 , where denotes XOR. Then
P r[Y = 0 X 3 = 0] = ______.
Suppose X i

Answer is 0.75

As X3 = 0 is given, to have Y = 0, X1X2 should be 0, meaning (X1, X2) should be one of {(0,0) (0,1) (1,0)}....
so, required probability = 3 * (1/2) * (1/2) = 0.75......
-- Srijay Deshpande

Set Theory & Algebra top


GATE2003_38 top
Consider the set {a, b, c} with binary operators + and defined as follows.
+ a b c
a b a

b a b

c a

* a b c
a a b

b b

c c

For example, a + c = c, c + a = a, c b = c and b c = a .


Given the following set of equations:

(a x) + (a y) = c
(b x) + (c y) = c
The number of solution(s) (i.e., pair(s) (x, y) that satisfy the equations) is
(A) 0 (B) 1 (C) 2 (D) 3

consider each pair


1. (a,a ) (a*a) +(a*a) = a+a = b

c so (a,a) is not possible

2. (a,b) (a*a) + (a*b) = a +b = a

3. (a,c)

so (a,b) is not possible

(a*a)+(a*c) = a+c = c
(b*a) +(c*c) = b + b =b

c , so (a,c) is not possible

4. (b,a) (a*b) +(a*a) = b +a = a

c , so (b,a) is not possible

5. (b,b) (a*b) + (a*b) = b+b =b

c , so (b,b) is not possible

6. (b,c)

(a*b) + (a*c) = b + c = c
(b*b) + (c*c) = c+b = c , so (b,c) is a solution

7. (c,a)

(a*c) + (a*a) = c+a = a

8.(c,b)

(a*c) + (a*b) = c+b = c

c, so (c,a) is not possible

(b*c) +(c*b) = a+c = c , so (c,b) is a solution


9. (c,c)

(a*c) +(a*c) =c+c= b

so no of possible solution is 2
-- Praveen Saini

c, so (c,c) is not possible

GATE2006_24 top
Given a set of elements N = {1, 2, ..., n} and two arbitrary subsets AN and BN, how many of the n! permutations from N to N satisfy min(
(A)) = min((B)), where min(S) is the smallest integer in the set of integers S, and(S) is the set of integers obtained by applying permutation
to each element of S?
(A) (n - |A B|) |A| |B| (B) (|A|2 + |B|2 )n 2 (C) n!

|AB|
|AB|

(D)

|AB| 2
nC

|AB|

min((N)) = 1, since in a permutation of n elements from 1..n, some element must get 1.
Similarly, in any subsets A and B, min((A)) = min((B)) only if A and B has a common element and its permutation is the smallest of all the
other elements in A and B.
(With this understanding itself we can eliminate options A and B)
Now we have n! total permutations and we have to see the number of permutations satisfying the given condition. If A = B, all of the n!
permutations satisfy the given condition. (This is enough to get the answer as C). Otherwise, the fraction of the n! permutations satisfying the
given condition
= |A B| / |A B|
This is because without the given restriction, the smallest element (among the |A B| elements) can be any one of the |A B| elements, and
with the restriction, the smallest element must be one of the |AB| elements.
So, answer is C.
-- Arjun Suresh

GATE2010_3

top

What is the possible number of reflexive relations on a set of 5 elements?


(A) 2 10 (B) 2 15 (C) 2 20 (D) 2 25

A relation consists of set of ordered pairs(a, b). Here a can be chosen in n ways and similarly b can be chosen in n ways. So, totally n 2
possible ordered pairs are possible for a relation. Now each of these ordered pair can either be present in the relation or not- 2 possibilities for
each of the n 2 pair. So, total number of possible relations =

2 (n

2)

.
Now, for a relation R to be reflexive, ordered pairs {(a, a) a S} , must be present in R. i.e.; the relation set R must have n ordered pairs
fixed. So, number of ordered pairs possible is n 2 n and hence total number of reflexive relations is equal to

2 (n
.
-- Arjun Suresh

GATE1999_3

top

Let set A be {1,2,3}, and let a relation R on A be

2 n)

R is both symmetric and transitive, but not reflexive. The key point here is that there may be some element in set A which is not related to any
of the element in R, but to be reflexive, all elements must be related to themselves.
-- Happy Mittal

GATE2014-1_50 top
Let S
denote the set of all functions

f : {0, 1} 4 {0, 1} . Denote by N the number of functions from S to the set {0, 1} . The value of log2 log2 N is _______.

For a function from set A to set B, we need to have a mapping for all elements of A and mapping must be unique.
Let number of elements in A be m and that in B be n
So, if we consider an element from A, it can be mapped to any of the element from B. i.e., it has n possibilities when a function is formed.
Similarly, for all other members also there are n possibilities as one element from A can be mapped to only a single element in B (though
reverse need not true). So, for n elements in A, we totally have n n = n m possible functions.

m times

In the question Number of elements (functions) in f is 2 2 as {0, 1} 4 contains 2 4 elements. So, number of functions from S to {0, 1} will be
4

2
2 2 . So, log2 log2 N = 2 4 = 16.

-- Arjun Suresh

GATE2014-2_5 top
A non-zero polynomial f(x) of degree 3 has roots at

x = 1 , x = 2 and x = 3 . Which one of the following must be TRUE?

(A) f(0)f(4) < 0


(B)

f(0)f(4) > 0

(C) f(0)

+ f(4) > 0

(D) f(0)

+ f(4) < 0

The roots are x=1, x=2, and x=3.


So polynomial is f(x) = (x-1)(x-2)(x-3)
f(0) = -6, f(4) = 6
So f(0)f(4) < 0.
-- Happy Mittal

GATE2014-3_2 top
Let X and Y be finite sets and

f : X Y be a function. Which one of the following statements is TRUE?

(A) For any subsets

A and B of X, |fA B| = |f(A)| + |f(B)|

(B) For any subsets

A and B of X, f(A B) = f(A) f(B)

(C) For any subsets

A and B of X, |f(A B| = min{|f(A)|, |f(B)|}

(D) For any subsets

S and T of Y , f 1 (S T ) = f 1 (S) f 1 (T )

D)
3 out of 4 options can be eliminated with the help of a counter example.
Let x = { a , b , c } and y = { 1 , 2 }
A Function f maps each element of x to 1 in y.

f(a)=1 , f(b)=1 , f(c) =1


A={a,b}B={b,c}
A)
|f ( A u B )| = |f ({a,b,c})| = 3
|f(A)|+|f(B)| = 2 + 2 = 4 , LHS != RHS.
B)
f ( A B ) = f ({b}) = { 1 }
f(A) f(B) = { 1 , 1 } { 1 , 1 } = { 1 , 1 }

LHS!=RHS
C)
|f ( A B )| = |f ({b})| = |{ 1 }| = 1
min{|f(A)|,|f(B)|} = min(2,2) = 2
LHS!=RHS
D) Its easy to see that this is true because in a function a value can be mapped only to one value.
-- Srinath Sri

GATE2014-3_49 top
Consider the set of all functions f : {0, 1, , 2014} {0, 1, , 2014} such that f(f(i)) = i, for all 0 i 2014 . Consider the following
statements:

P . For each such function it must be the case that for every i, f(i) = i.
Q . For each such function it must be the case that for some i, f(i) = i.
R. Each function must be onto.
Which one of the following is CORRECT?
(A) P , Q and R are true
(B) Only Q and R are true
(C) Only P and Q are true
(D) Only R is true

Let f(i) = j. Now, we have f(j) = i, as per the given condition f(f(i)) = i.
When j = i, the condition holds and since domain and co-domain of the functions do intersect (actually same),Q is definitely true.
Since f(i) = j and f(j) = i, and since 0 i 2014 i must take all 2015 possible values (since f is a function, it must have a value for any
element in the domain). We can easily see that f(i) cannot be the same for two different is- because suppose f(2) = 5 , and f(3) = 5 . Now
as per given condition, f(5) = 2 and f(5) = 3 , which is not allowed in a function. So, allf(i) values are unique co-domain = range as
there are only 2015 values in co-domain. So, R is true.
An identity function satisfies the given conditions. But that alone cant prove that P is true. We can also have a different function where all even
numbers maps to the next odd number and all odd numbers map to the previous even number which satisfies the given conditions. i.e.,
f(0) = 1, f(1) = 0, f(2) = 3, f(3) = 2 f(2015) = 2014 . This proves, P is false.
So, (B) is the answer.
-- Arjun Suresh

GATE2014-3_50 top
There are two elements x, y in a group (G, ) such that every element in the group can be written as a product of some number ofx's and y 's
in some order. It is known that

xx = yy = xyxy = yxyx = e
where e is the identity element. The maximum number of elements in such a group is ____.

And so the answer is 4.


-- Gate Keeda

GATE1997_4.4

top

A polynomial p(x) is such that p(0) = 5, p(1) = 4, p(2) = 9 and p(3) = 20. The minimum degree it should have is
A.
B.
C.
D.

1
2
3
4

Lets take p(x) = ax +b


Now, p(0) = 5 => b = 5.
p(1) = 4 => a + b = 4, a = -1
p(2) = 9 => 4a + b = 9 => -4 + 5 = 9, which is false. So, degree 1 is not possible.

Let p(x) = ax2 + bx + c


p(0) = 5 => c = 5
p(1) = 4 => a + b + c = 4 => a + b = -1 ->(1)
p(2) = 9 => 4a + 2b + c = 9 => 2a + b = 2 -> (2)
(2) - (1) => a = 3, b = -1 - 3 = -4
p(3) = 20 => 9a + 3b + c = 20, 27 -12 + 5 = 20, equation holds.
So, degree 2 also will suffice.
-- Arjun Suresh

GATE1997_6.1

top

A partial order is defined on the set S = {x, a1, a2, ... an, y} as x ai for all i and ai y for all i, where n 1. The number of total orders on the
set S which contain the partial order is
A.
B.
C.
D.

n!
n+2
n
1

To make this partial order a total order, we need the relation to hold for every two element of the partial order. Currently between any iaand
aj, there is no relation. So, for every ai, aj, we have to add either (ai, aj) or (aj, ai) in total order. So, this translates to giving an ordering for n
elements between x and y, which can be done in n! ways. So, answer is (a).

The bottom figure is for a total order. We can permute the ai from i = 1 to n, and each permutation will also be a total order containing the
given partial order.
-- Arjun Suresh

GATE1997_6.3

top

Ans A. no. of equivalence relations = no. of partition set possible = 1 (all four elements) + 3(2 + 2 elements partition) + 4(3 + 1 element
partition) + 6 (2 + 1 + 1 element partition) + 1 (1 + 1+ 1+ 1 element partition) = 15
-- Vikrant Singh

GATE1995_23 top
Prove using mathematical induction for n 5, 2 n > n 2

Base case: n = 1, 2 1 = 2 > 1 2

Induction hypothesis: 2 n > n 2


To prove: 2 n+1 > (n + 1)2

LHS = 2.2 n > 2.n 2 (Induction hypothesis)


RHS = (n + 1)2 = n 2 + 2n + 1 < LHS , hence proved.
-- Arjun Suresh

GATE1996_1.1

top

(a - b) U (b - a) U (a ^ b)
a - b is a but not b i.e. only a
b - a. is b but not a i.e. only b
a ^ b is a and b both
Union of all is (only a) U (only b) U (a^b)
=aUb
-- Digvijay Pandey

GATE1996_2.1

top

Let R denote the set of real numbers. Let f : R R R R be a bijective function defined by f(x, y) = (x + y, x y). The inverse function
of f is given by
(a) f 1 (x, y) = ( 1 ,
x+y

1 )
xy

(b) f 1 (x, y) = (x y, x + y)
(c) f 1 (x, y) = (

x+y
2

xy
)
2

(d) f 1 (x, y) = [2(x y), 2(x + y)]

to find inverse of the function take


z1=x+y
z2=x-y
on solving this eq. we can get value of x = z1+z2 and y =
2

z1z2
2

so inverse of function in terms of x and y is -1


f (x,y) = { x+y , xy }
2

-- neha pawar

GATE1996_8

top

Let F be the collection of all functions f: {1, 2, 3} {1, 2, 3}. If f and g F, define an equivalence relation ~ by f~g if and only if f(3) = g(3).
a. Find the number of equivalence classes defined by ~.
b. Find the number of elements in each equivalence class.

Total number of functions = 3 * 3 * 3 = 27 as each of 1, 2, and 3 has 3 choice to map to.

Now, for the equivalence relation, we need the mapping of 3 to be fixed. So, with 3 -> 1, we can get 3 * 3 = 9 functions and similarly 9 each for
3 -> 2 and 3 -> 3.
a. So, total number of equivalence classes = 3, one each for 3 -> 1, 3 -> 2, and 3 -> 3.
b. Number of elements in each equivalence class = 9.
-- Arjun Suresh

On a set of n elements, how many relations are there that are both irreflexive and
antisymmetric? top
On a set of n elements, how many relations are there that are both irreflexive and antisymmetric?
Please explain how to calculate .

On a set S with n elements how many relations are there?


A relation consists of set of ordered pairs (a, b). Here a can be chosen in n ways and similarly b can be chosen in n ways. So, totally n 2
possible ordered pairs are possible for a relation. Now each of these ordered pair can either be present in the relation or not- 2 possibilities for
each of the n 2 pair. So, total number of possible relations =

2 (n

2)

.
Now, for a relation R to be reflexive, ordered pairs {(a, a) a S} , must be present in R. i.e.; the relation set R must have n ordered pairs
fixed. So, number of ordered pairs possible is n 2 n and hence total number of reflexive relations is equal to

2 (n

2 n)

.
Number of irreflexive relations is same as number of reflexive relations. In reflexive relations we always included n ordered pairs for
{(a, a) a S} , while in irreflexive relation we always omit thosen ordered pairs. So, the number of ordered pairs to choose for the relation
is the same for both reflexive as well as irreflexive relations which is

2 (n

2 n)

A relation becomes symmetric, if for ordered pair (a, b) in R, ordered pair (b, a) is also present in R. So, here, the total number of ordered
pairs possible is reduced from

n + n + + n to
n+n1+n2++1=

n(n+1)
2

So, total number of possible symmetric relations =

n(n+1)
2

.
A relation becomes anti-symmetric if for the ordered pairs (a, b) and (b, a) in R, a = b . i.e., the pairs (a, b) and (b, a) cannot be simultaneously
be in the relation unless a = b .
For the n pairs (a, a) in R, they can be either present in relation or absent. So, 2 possibilities for each giving2 n possible relations.
Number of pairs (a, b) in R such that a b equals number of ways of selecting 2 numbers fromn without repetition, equals
Now, for each of these pairs (a, b), there are 3 possibilities1. (a, b) and (b, a) not in R
2. (a, b) in R but (b, a) not in R
3. (a, b) not in R but (b, a) in R
So, total number of possibilities for all such pairs =3 (

n(n1)
2

And total number of anti-symmetric relations on a set of n elements becomes

n(n1)
2

(
2n 3

n(n1)
2

Finally, coming to your question, number of relations that are both irreflexive and anti-symmetric which will be same as the number of
relations that are both reflexive and antisymmetric is

n(n1)
2

We just have to always exclude n pairs being considered for (a, a) while calculating the possible relations for anti-symmetric case.

-- Arjun Suresh

GATE2008-IT_28 top
Consider the following Hasse diagrams.

Which all of the above represent a lattice?

1)

(i) and (iv) only

2)

(ii) and (iii) only

3)

(iii) only

4)

(i), (ii) and (iv) only

ans is (1)
hasse diagram is lattice when every pair of element have least upper bound and greatest lower bound.in fig 2 and 3 every element will not
have least upper bound and greatest lower bound so they are not lattice.
-- neha pawar

GATE2007-IT_23 top
A partial order P is defined on the set of natural numbers as follows. Here x/y denotes integer division.
i. (0, 0) P.
ii. (a, b) P if and only if a % 10 b % 10 and (a/10, b/10) P.
Consider the following ordered pairs:
i.
ii.
iii.
iv.

(101, 22)
(22, 101)
(145, 265)
(0, 153)

Which of these ordered pairs of natural numbers are contained in P?

A)

(i) and (iii)

B)

(ii) and (iv)

C)

(i) and (iv)

D)

(iii) and (iv)

Ans. D
For ordered pair (a, b), to be in P, each digit in a starting from unit place must not be larger than the corresponding digit in b.
This condition is satisfied by options
(iii) (145, 265) => 5 5, 4 < 6 and 1 < 2
and
(iv) (0, 153) => 0 < 3 and no need to examine further
-- Vikrant Singh

GATE2007-IT_76 top
Consider the sequence

defined by the recurrence relation

Suppose there exists a non-empty, open interval


sequence converges to the value?

such that for all

, where
satisfying

.
, the sequence converges to a limit. The

A)
B)
C)
D)

Since it converges, we can write:

or

Solving for x:

So both A) and B) can be the values.


-- Ashis Kumar Sahoo

GATE2006-IT_2 top
For the set N of natural numbers and a binary operation f : N x N N, an element z N is called an identity for f, if f (a, z) = a = f(z, a), for all a
N. Which of the following binary operations have an identity?
I. f (x, y) = x + y - 3
II. f (x, y) = max(x, y)
III. f (x, y) = xy

A)

I and II only

B)

II and III only

C)

I and III only

D)

None of these

Answer: A

I. Identity element is 3.
II. Identity element is 1.
III. There is no identity element. (xy yx , when x y)
-- Jon Snow

GATE2006-IT_24 top
What is the cardinality of the set of integers X defined below?
X = {n | 1 n 123, n is not divisible by either 2, 3 or 5}

A)

28

B)

33

C)

37

D)

44

No's divisible by 2 in X = 61

[ = integer(123/2) ]

No's divisible by 3 in X = 41
No's divisible by 5 in X = 24
No's divisible by 2 and 3 .i,e by 6 = 20
No's divisible by 2 and 5 i.e by 10 = 12
No's divisible by 3 and 5 , i.e by 15 = 8
No's divisible by 2 and 3 and 5 ..ie by 30 = 4

No's divisible by either 2 or 3 or 5 = N(AUBUC) = N(A) +N(B)+N(C) -N(AB)-N(BC)-N(AC)+ N(ABC)


= 61 +41+24 -20-12-8 +4 = 90
X = { n ,1 n 123, n is not divisible by either 2, 3 or 5 }
Cardinality = 123 - 90 = 33

-- Praveen Saini

GATE2005-IT_31 top
Let f be a function from a set A to a set B, g a function from B to C, and h a function from A to C, such that h(a) = g(f(a)) for all a A. Which of
the following statements is always true for all such functions f and g?

A)

g is onto => h is onto

B)

h is onto => f is onto

C)

h is onto => g is onto

D)

h is onto => f and g are onto

Let h be onto (onto means co-domain = range). So, h maps to every element in C from A. Since h(a) = g(f(a)), g should also map to all
elements in C. So, g is also onto -> option (C).

-- Arjun Suresh

GATE2005-IT_33 top

Let A be a set with n elements. Let C be a collection of distinct subsets of A such that for any two subsets S
1 and S2 in C, either S1 S2 or S2
S1. What is the maximum cardinality of C?

1)

2)

n+1

3)

2n-1 + 1

4)

n!

Let's take an example set {a,b,c}


Now lets try to create the required set of subsets, say S.
Let's start by adding sets of size 1 to S. We can only add one of the sets {a}, {b}, {c}.
Lets say we add {a}, so S now becomes {{a}}
Now lets add sets of size 2 to S. Again we see that we can only add one of {a,b}, {a,c} or {b,c}, and we cannot add {b,c} since we already
added {a}.
Continuing this way we see we can add only one set for a all size till n.
So the awnser should be 2) n+1 ( include the empty set )
-- Omesh Pandita

maths_mock_test4 top

2 is correct answer. fig 2, b and c have {f,g} as upperbound. but for the graph to be a lattice it should have a least upper bound. Since b and c
have two upper bounds they cannot have a least upper bound<which is always unique for a pair for vertices>. In other words we cannot say
which one is least one out of the pair {f,g}. therefore it is not a join semilattice(every pair of element should have a least upper bound).
henceforth it is also not a lattice
-- Madhur Rawat

GATE2015-1_5 top
If g(x) = 1 x and h(x) =
A.

h(x)
g(x)

x ,
x1

then

g(h(x))
h(g(x))

is:

B.
C.
D.

1
x
g(x)
h(x)
x
(1x) 2

option a) is correct.
x
g(h(x)) = g( x1
)

= 1
1
= x1

x
x1

h(g(x)) = h(1 x)
= 1x
x
g(h(x))
h(g(x))

x
(1x)(x1)

h(x)
g(x)

option A)
-- GateMaster Prime

GATE2015-2_GA_9 top
If p, q, r, s are distinct integers such that:

f(p, q, r, s) = max (p, q, r, s)


g(p, q, r, s) = min (p, q, r, s)
h(p, q, r, s) = remainder of (p q)/(r s) if (p q) > (r s)
or remainder of (r s)/(p q) if (r s) > (p q)
Also a function fgh(p, q, r, s) = f(p, q, r, s) g(p, q, r, s) h(p, q, r, s)
Also the same operations are valid with two variable functions of the form f(p, q)
What is the value of fg(h(2, 5, 7, 3), 4, 6, 8) ?

It is given that

remainder of

if

or remainder of

remainder of

Again, it is given that


Also,

max

and
max

min
and min

Answer:
-- Shyam Singh

GATE2015-2_9 top
The number of divisors of 2100 is ____.

Answer: 36
2100 = 7*3*22*52
Hence, total number of factors will be = (1+1)*(1+1)*(2+1)*(2+1) = 2*2*3*3 = 36,
because any factor is obtained by multiplying the prime factors zero or more times. (one extra for zero)

if

-- Jon Snow

GATE2015-2_18 top
The cardinality of the power set of {0, 1, 2, , 10} is _______

Answer: 2048
Number of elements in set = 11.
Therefore, cardinality of power set = 211 = 2048.
-- Jon Snow

GATE2015-2_26 top
Let f(x) = x(1/3) and A denote the area of region bounded byf(x) and the X-axis, when x varies from -1 to 1. Which of the following
statements is/are TRUE?

I. f is continuous in [-1, 1]
II. f is not bounded in [-1, 1]
III. A is nonzero and finite

A.
B.
C.
D.

II only
III only
II and III only
I, II and III

Answer: C
I. False.
II. True.
III. True. An area is always positive, while the definite integral might be composed of several regions, some positive and some negative. A
definite integral gets you the net area, because any part of the graph that is below the x-axis will give you a negative area. So, a definite
integral is not necessarily the area under the curve, but the value of the area above the x-axis less the area under the x-axis. So, A is nonzero and finite.
-- Jon Snow

GATE2015-1_16 top
For a set A, the power set of A is denoted by 2 A . If A = {5, {6}, {7}} , which of the following options are TRUE?
I.
II.
III.
IV.

2A
2A
{5, {6}} 2 A
{5, {6}} 2 A

A.
B.
C.
D.

I and III only


II and III only
I, II and III only
I, II and IV only

Power set of A consists of all subsets of A and from the definition of a subset, is a subset of any set. So, I and II are TRUE.
5 and {6} are elements of A and hence {5, {6} } is a subset of A and hence an element of 2A. An element of a set is never a subset of the set.
For that the element must be inside a set- i.e., a singleton set containing the element is a subset of the set, but the element itself is not. Here,
option IV is false. To make IV true we have to do as follows:
{5, {6} } is an element of 2A. So, { {5, {6} }} 2A.

So, option C.
-- Arjun Suresh

GATE2015-2_54 top
Let X and Y denote the sets containing 2 and 20 distinct objects respectively andF denote the set of all possible functions defined fromX to
Y . Let f be randomly chosen from F . The probability of f being one-to-one is ______.

For a function, the first element in X has 20 choices (to map to) and the second element also has 20 choices. For a one-to-one function the
second element has only 19 choices left after 1 being taken by the first. So, required probability
= 20 * 19 / (20 * 20) = 0.95
-- Vikrant Singh

GATE2015-1_39 top
Consider the operations

f (X, Y, Z) = X'YZ + XY' + Y'Z' and g (X, Y, Z) = X'YZ + X'YZ' + XY


Which one of the following is correct?
A.
B.
C.
D.

Both {f} and {g} are functionally complete


Only {f} is functionally complete
Only {g} is functionally complete
Neither {f} nor {g} is functionally complete

g is preserving 0 as when all inputs are zero, output is always 0 and so g cannot be functionally complete.
f is not preserving 0.
f is not preserving 1. (when all inputs are 1, output is 0).
f is not linear as in XY' only one (odd) input needs to be 1 and in X'YZ two inputs (even) needs to be 1.
f is not monotone as changing Y from 0 to 1, can take f from 1 to 0.
f is not self dual as f(X, Y, Z) ~f(~X, ~Y, ~Z)
So, f satisfies all 5 conditions required for functional completeness and hence B is the answer.
http://cs.ucsb.edu/~victor/ta/cs40/posts-criterion.pdf
-- Arjun Suresh

GATE2015-3_2 top
Let # be the binary operator defined as
X#Y = X'+Y' where X and Y are Boolean variables.
Consider the following two statements.
(S1) (P#Q)#R = P#(Q#R)
(S2) Q#R = (R#Q)
Which are the following is/are true for the Boolean variables P, Q and R?

A.
B.
C.
D.

Only S1 is true
Only S2 is true
Both S1 and S2 are true
Neither S1 nor S2 are true

Answer=B
(P#Q)#R=(P'+Q')#R

=P.Q+R'
whereas
P#(Q#R)=P'+(Q#R)'
=P'+(Q'+R')'
=P'+QR
-- overtomanu

GATE2015-3_5 top
The number of 4 digit numbers having their digits in non-decreasing order (from left to right) constructed by using the digits belonging to the set
{1, 2, 3} is ________.

you can arrive at a solution by constructing a graph for each starting digit. for example root 3 means - starting with 3 it can have 3 child 1,2,3
and the construction goes
3 can three children 1, 2,3
2 can have two children 1, 2
1 can have only 1 as child. Graph need to be done till three levels
and finally count total number of leaves
-- Sankaranarayanan P.N

GATE2015-3_23 top
Suppose U is the power set of the setS = {1, 2, 3, 4, 5, 6} . For any T U , let |T | denote the number of elements in T and T denote the
complement of T . For any T , R U let T R be the set of all elements inT which are not in R. Which one of the following is true?

A.
B.
C.
D.

X U, (|X| = |X |)
X U, Y U, (|X| = 5, |Y | = 5 and X Y = )
X U, Y U, (|X| = 2, |Y | = 3 and XY = )
X U, Y U, (XY = Y X )

Answer D
As X and Y U, X and Y are subsets of S
Option A is wrong consider X={1,2} therefore X'={3,4,5,6} |X|=2 and |X'|=4
Option B is wrong as any two possible subsets of S with 5 elements should have atleast 4 elements in common.Hence X intersection Y not
null
Option C is wrong, consider X={1,2} y={3,4,5} and X\Y={1,2} which is not null
-- overtomanu

GATE2015-3_41 top
Let R be a relation on the set of ordered pairs of positive integers such that((p, q), (r, s)) R if and only if p s = q r. Which one of the
following is true about R?

A.
B.
C.
D.

Both reflective and symmetric


Reflective but not symmetric
Not reflective but symmetric
Neither reflective nor symmetric

The key trick here is to realize that the relation is of the form :
{ordered pair, ordered pair} and not simply ordered pair.
Ok, so for reflexive

(not possible for any positive integers b and a)


but that is a contradiction hence it is not reflexive.
now, for symmetric

so it is symmetric.
hence C is the correct option.

-- Tamojit Chatterjee

Combinatory top
GATE2008_24 top
Let P =
i and Q = 1i2k i , where k is a positive integer. Then
1i2k
i odd

(A) P
(B) P
(C) P
(D) P

i even

= Qk
= Q+k
=Q
= Q + 2k

Substitute k=3 then we get p=9 and q=12 on verifying we get option A.
-- kireeti

GATE2002_13 top
a. In how many ways can a given positive integern 2 be expressed as the sum of 2 positive integers (which are not necessarily distinct).
For example, for n = 3 the number of ways is 2, i.e., 1+2, 2+1. Give only the answer without any explanation.
b. In how many ways can a given positive integern 3 be expressed as the sum of 3 positive integers (which are not necessarily distinct).
For example, for n = 4 , the number of ways is 3, i.e., 1+2+1, 2+1+1. Give only the answer without explanation.
c. In how many ways can a given positive integern k be expressed as the sum of k positive integers (which are not necessarily distinct).
Give only the answer without explanation.

a. n= 2 (1+1) n=3(1+2, 2+1) n=4(1+3,3+1,2+2) n=5(1+4,4+1,2+3,3+2)


so x1+x2=n , x1,x2>0 (no.of integral sol)
This is same as number of ways of putting n-2 (as we can't have 0 for either x1 or x2) identical balls into two distinct bins, which is obtained by
putting a divider across n-2 balls and taking all possible permutations with n-2 being identical. i.e., (n-2 + 1)!/(n-2)! = (n-1). We can also use
the following formula
n-2+2-1C

2-1

=n-1C 1

b. n=3(1+1+1) n=4(1+1+2,1+2+1,2+1+1) n=5(1+1+3,1+3+1,3+1+1,2+2+1,2+1+2.,1+2+2)


so x1+x2+x3=n , x1,x2,x3>0 (no.of integral sol)
Here, we can permute n-3 items with 2 dividers which will give (n-3 + 2)!/(n-3)!2!
= (n-1)!/(n-1-2)!2!
=n-1C 2
c. n-k+k-1C k-1 =n-1C k-1
-- Supromit Roy

GATE2003_4

top

Let A be a sequence of 8 distinct integers sorted in ascending order. How many distinct pairs of sequences, B and C are there such that
(i) each is sorted in ascending order,
(ii) B has 5 and C has 3 elements, and
(iii) the result of merging B and C gives A?
(A) 2 (B) 30 (C) 56 (D) 256

answer - C
select any 3 elements from given 8 elements - 8C 3

-- ankitrokdeonsns

GATE2003_5

top

n couples are invited to a party with the condition that every husband should be accompanied by his wife. However, a wife need not be
accompanied by her husband. The number of different gatherings possible at the party is
(A) 2n C n 2 n (B) 3 n (C)

(2n)!
2n

(D) 2n C n

Possible outcome for a couple:


1. only wife comes
2. both come
3. none come
Thus 3 possibilities for each couple, so 3 x 3 x 3 x ... n times = 3 n
-- Palash Nandi

GATE2005_35 top
How many distinct binary search trees can be created out of 4 distinct keys?

A.
B.
C.
D.

5
14
24
42

answer - B
number of distinct BSTs = 2nC n/(n + 1)
-- ankitrokdeonsns

GATE1998_1.23 top

no of strings of length 1 = n
no of strings of length 2 = n-1
no of strings of length 3 = n-2
.
.
.
no of string of length n = 1
total = n + (n -1) + (n - 2) + (n - 2) + ..... + 1
= n(n+1)/2
-- Digvijay Pandey

GATE2014-1_49 top

A pennant is a sequence of numbers, each number being 1 or 2. An

n -pennant is a sequence of numbers with sum equal to n . For example, (1, 1, 2) is a 4(2), (1, 1) and the set of all 3-pennants is (2, 1), (1, 1, 1), (1, 2) . Note

pennant. The set of all possible 1-pennants is (1) , the set of all possible 2-pennants is

that the pennant (1, 2) is not the same as the pennant (2, 1) . The number of 10-pennants is________

Let we denote number of n-pennants by f(n), so f(10) is number of 10-pennants.


A 10-pennant means sum of numbers in sequence is 10. If we look at any 9-pennent, we can make it a 10-pennant by adding 1 into that
sequence. Similarly, we can make any 8-pennant a 10-pennant by adding 2 into that sequence.
So all 10-pennants can be formed by 8-pennants and 9-pennants, and no other pennant (since we can add only 1 or 2 into a sequence)
So f(10) = f(9) + f(8)
This is in fact a fibonacci sequence, in which F(1) = 1, f(2) = 2, so this sequence becomes
1, 2, 3, 5, 8, 13, 21, 34, 55, 89,..
So f(10) = 89.
-- Happy Mittal

GATE2014-2_49 top
The number of distinct positive integral factors of 2014 is _____________

First do prime factorization of 2014 - 21 x 191 x 531


Now to get a factor of 2014, we can choose any combination of the prime factors including 0. i.e; 02 and 21 are possible and similarly for other
prime factors also, there are 2 possibilities. So, total number of positive integral factors

= 222= 8
(When all the powers of prime factors are 0, we get 1 and when all the powers are maximum, we get the given number.)
-- Arjun Suresh

GATE1994_1.15 top

no. of substrings of length n is 1


no. of substrings of length n-1 is 2
no. of substrings of length n-2 is 3
so n(n+1)/2
-- Bhagirathi Nayak

GATE2008-IT_25 top
In how many ways can b blue balls and r red balls be distributed in n distinct boxes?

A)
B)

(n+b1)! (n+r1)!
(n1)! b! (n1)! r!
(n+(b+r)1)!

(n1)! (n1)! (b+r)!

C)
D)

n!
b! r!
(n+(b+r)1)!
n! (b+r1)

r red balls can be distributed into n distinct boxes in C(n+r-1,r) = .(n+r-1)! / (n-1)! r!
b blue balls can be distributed in C(n+b-1,b) = (n+b-1)! / (n-1)! b!
By product rule total ways are (n+b-1)! (n+r-1)! / (n-1)! b! (n-1)! r!
SO THE ANSWER IS A.

-- Madhu Veluguri

GATE2005-IT_46 top
A line L in a circuit is said to have a stuck-at-0 fault if the line permanently has a logic value 0. Similarly a line L in a circuit is said to have a
stuck-at-1 fault if the line permanently has a logic value 1. A circuit is said to have a multiple stuck-at fault if one or more lines have stuck at
faults. The total number of distinct multiple stuck-at faults possible in a circuit with N lines is

A)

3N

B)

3N - 1

C)

2N - 1

D)

Answer should be 3^N-1.


This is because the total possible combinations (i.e a line may either be at fault (in 2 ways i.e stuck at fault 0 or 1) or it may not be , so there
are only 3 possibilities for a line ) is 3^N. In only one combination the circuit will have all lines to be correct (i.e not at fault.) Hence 3^N-1. (as it
has been said that circuit is said to have multiple stuck up fault if one or more line is at fault )
Please Comment , if anyone finds it wrong.
-- Afaque Ahmad

How many strings of length 10 over the alphabet {a, b, c} have either exactly three a's or
exactly four b's? top

There are 10 places to be filled.


Case 1: Exactly 3 a's: We fill 3 places with 3 a's in 3C3 * 10C3 ways. Now, remaining 7 places can be filled using b or c in72ways.
Case 2: Exactly 4 b's: We fill 4 places with 4 b's in 4C4 * 10C4 ways. Remaining 6 places can be filled using a or c in62ways.
Case 3: Exactly 3 a's and exactly 4 b's: 10C3 * 7C4 * 13 = 4200
So, number of strings possible = Case 1 + Case 2 - Case 3 = 10C3 * 128 + 10C4 * 64 - 4200 = 24,600
-- Arjun Suresh

A professor writes 20 multiple-choice questions, each with the possible answer a, b, c, or


d, for a discrete mathematics test. If the number of questions with a, b, c, and d as their
answer is 8, 3, 4, and 5, respectively, how many different answer keys are possible, if the
questions can be placed in any order? top

We have to arrange 8 a's, 3 b's, 4 c's and 5 d's.. i.e Permutation to find possible number of answer keys that are possible=20! but the all a's
are identical, b's are identical , c's are identical and d's are identical, therefore Answer is = 20!/(8! . 3! . 4! . 5!)= 3491888400
-- Prateeksha Keshari

The maximum number of distinct subwords of the word "AXIOMATIZABLE" is: a)183 b) 111
c)92 d)88 top

Subwords means letters must be consecutive as in the word. Since, the given word has 13 letters we can have
13 subwords of 1 letter
12 subwords of 2 letters
11 subwords of 3 letters
....
1 subword of 13 letters
So, total number of subwords = 13 + 12 + ... + 1 = 13 * 7 = 91
No two consecutive letters are repeating in the given word. But there are 3 A's, and 2 I's. So, 3 subwords of length 1 are counted extra. So,
total number of distinct subwords = 91 - 3 = 88.
-- gatecse

How many ternary strings of length 4 have exactly one 1?

top

4 * 23 = 32
Of length 4, one we take for 1. Remaining 3 characters can be filled with 2 symbols in 23 = 8 ways. Now, the one can be placed in 4 ways
between the 3 characters giving 4 * 8 = 32 strings.
-- Arjun Suresh

How many seven digits number are there such that Digits are distinct integers taken from
{1, 2, ..., 9} and Digits 5 and 6 do not appear together (consecutively) top
1. How many seven digits number are there such that
1. Digits are distinct integers taken from {1, 2, ..., 9} and
2. Digits 5 and 6 do not appear together (consecutively)

Case 1: 5 and 6 appear together. Here, it can be 56 or 65. So, 2 ways and remaining we have 5 digits to chose from 7 and 6! ways (5 digits
plus 56 or 65) to arrange them. This gives 2! * 7C5 * 6! = 42 * 720
Total possible numbers = 9 P 7 = 7! * 36
So, our required answer = 7! * 36 - 42 * 720 = 151,200
-- Arjun Suresh

Graph Theory

top

GATE2012_38 top
Let G be a complete undirected graph on 6 vertices. If vertices of G are labeled, then the number of
distinct cycles of length 4 in G is equal to
(A) 15 (B) 30 (C) 90 (D) 360

From 6 vertices we can select 4 distinct vertices in6C 4 = 15 ways.


Now, with 4 vertices, we can form only 3 distinct cycles. [See below]
So, total no. of distinct cycles of length 4 = 15 * 3 = 45.
No. of cyclic permutations of n objects = (n-1)! and for n = 4, we get 3! = 6 ways. But number of distict cycles in a graph is exactly half the
number of cyclic permutations as there is no left/right ordering in a graph. For example a - b - c - d and a - d - c - b are different permutations
but in a graph they form the same cycle.
Since, 45 was not in the choice, marks were given to all in GATE.
-- gatecse

GATE1991_01,xv top
The maximum number of possible edges in an undirected graph withn vertices and k components is ______.

Hopefully it should be clear that in any such graph all components will be complete, i.e., have all possible edges. Thus the
only remaining question is how large each component should be?
If there are two components with a and b vertices, a > 1, b > 1 , then together they can have at most
( a2 ) + ( b2 ) =

1
2

(a2 a + b 2 b) edges.

However, if we place all but one of the vertices in a single component, we could have
( a+b1
) + ( 12 ) =
2
=

1
2

1
2

(a + b 1)(a + b 2)

(a + 2ab 3a + b 2 3b + 2) edges.
2

Subtracting the first quantity from the second gives


1
2

((2ab 3a 3b + 2) (a b))

= ab a b + a
= (a 1)(b 1) which is > 0

Hence it is better not to have two components with multiple vertices.


This leaves us with the answer that all components should have one vertex except one, which will have n k + 1 vertices, for
a total of ( nk+1
) edges.
2

in simple connected graph , number of edges ,


(n 1) e n.

(n1)
2

in simple unconnected graph with k component , number of edges ,


(n k) e (n k).

(nk+1)
2

note :- put k=1 then it will be connected graph .


reference @ http://www.quora.com/What-is-the-maximum-number-of-edges-in-graph-with-n-vertices-and-k-components
another
read
@
http://stackoverflow.com/questions/24003861/maximum-number-of-edges-in-undirected-graph-with-nvertices-with-k-connected-com

-- csegate2

GATE2003_8

top

Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G , the number of components in the resultant graph
must necessarily lie down between

A.
B.
C.
D.

k and n
k 1 and k + 1
k 1 and n 1
k + 1 and n k

If a vertex is removed from the graph G


Lower Bound: number of components decreased by one = k - 1 ( remove a vertex from 'n' isolated vertices)
Upper Bound: number of components = n-1 ( remove the center vertex of a star graph )
Therefore (C)
-- Danish

GATE2003_36 top
How many perfect matching are there in a complete graph of 6 vertices?
(A) 15

(B) 24

(C) 30

(D) 60

Note: To understand the solution please go through the definitions of perfect matching
The complete graph kn have a perfect matching only when n is even.. So let n=2m.
Let the vertices be V1 , V2 ,......,V2m.
v1 can be joined to any other 2m-1 vertices
v2 can be joined to any other 2m-3 vertices
Similarly go till V2m which will have only one vertex to be joined with..
No of Perfect matches= (2m-1)(2m-3)(2m-5).....(3)(1)
In the above question 2m=6
So No. of perfect matches=5*3*1=15
-- Hunaif

GATE2003_40 top
A graph G = (V , E) satisfies |E| 3|V | 6. The min-degree of G is defined as min vV {degree(v)}. Therefore, min-degree of G cannot be
(A) 3

(B) 4

(C) 5

(D) 6

Let the min-degree of G is x. then G has at least |v| *x/2 edges.


|v|*x/2 <= 3* |v| -6
for x=6, we get 0 <= 6, Therefore, min degree of G cannot be 6.
Correct answer is (D).
-- suraj

GATE2014-1_51 top
Consider an undirected graph G where self-loops are not allowed. The vertex set of G is {(i, j)
and (c, d) if |a c| 1 and |b d| 1 . The number of edges in this graph is______.

1 i 12, 1 j 12} . There is an edge between (a, b)

If you think of a 12 * 12 grid (like a chess board of size 12*12), then each each point (i,j), which is in ith row and jth column, is a vertex (i,j).
Now we are allowed to connect only those points which are atmost 1 distance apart (in both horizontal and vertical direction). So we will
connect only horizontal neighbours, vertical neighbours, and diagonal neighbours.
So horizontal edges on each row are 11 i.e. 11*12 = 132 horizontal edges. Similarly we have 132 vertical edges.
To count diagonal edges, think of 1*1 square boxes in which diagonals meet each other. There are 11*11 such square boxes, and each box
contains 2 diagonals, so total diagonals = 242.
So total edges = 132 + 132 + 242 = 506.
-- Happy Mittal

GATE2014-1_52 top
An ordered n tuple ( d1 , d2 , . . . . , dn ) with d1 d2 . . . dn is called graphic if there exists a simple undirected graph with
d1 , d2 , . . . , dn respectively. Which one of the following 6-tuples is NOT graphic?
(A)

(1, 1, 1, 1, 1, 1)

(B)

(2, 2, 2, 2, 2, 2)

n vertices having degrees

(C) (3, 3, 3, 1, 0, 0)
(D) (3, 2, 1, 1, 1, 0)

This can be solved using havel-hakimi theorem.


The idea is simple : Remove a vertex, which results into decrease of degree by 1 of each vertex which was connected to it. Keep removing
like this, and if we get any negative degree, the degree sequence was not possible.
We need not check (A) and (B) as they are clearly graphs : (A) is 3 disconnected edges, (B) is 2 disconnected triangles.
For (C), we remove first vertex of degree 3, and thus decrease degree by 1 of next 3 vertices, so we get (2,2,0,0,0), then we remove vertex of
degree 2, and decrease degree of next 2 vertices to get (1,-1,0,0). Since we get negative degree, original degree sequence is impossible.
For (D) : (3,2,1,1,1,0) -> (1,0,0,1,0). Now since this list is not sorted (which is required to apply further steps of algorithm), we sort it to get
(1,1,0,0,0). Then we continue our algorithm on this list to get (0,0,0,0), which is valid (4 isolated vertices).
So (C) is answer.
-- Happy Mittal

GATE2014-2_51 top
A cycle on

n vertices is isomorphic to its complement. The value of n is _____.

its n=5 only.


only C5 is isomorphic to its complement.

-- jayendra

GATE2014-3_3 top
Let G be a group with 15 elements. Let L be a subgroup of G . It is known that L G and that the
size of L is at least 4 . The size of L is __________.

Lagranges theorem : For any finite group G, the order (number of elements) of every subgroup L of G divides the order of G.
G has 15 elements.
Factors of 15 are 1,3,5, and 15.
Since given the size of L is atleast 4(1 and 3 eliminated) and not equal to G(15 eliminated) , the only size left is 5.
Size of L is 5.

-- Srinath Sri

GATE2014-3_51 top
If

G is the forest with n vertices and k connected components, how many edges does G have?
(A)

n/k

(B)

n/k

(C) n k
(D) n k

+1

A forest is an acyclic graph(with no cycle) , i.e all these components are a tree. With

k components there are k roots. And whenever a new node is

added to a tree only a singe edge is introduced.


With k roots , remaining nodes are (n-k) each of which introduces an edge. Hence there are (n-k)*1=(n-k) edges.

-- Srinath Sri

GATE1994_2.5

top

The number of edges in a regular graph of degree d and n vertices is ____________

in a complete graph which is (n-1) regular (where n is the no of vertices) has edges n(n-1)/2
n vertices are adjacent to n-1 vertices and an edge contributes two degree so dividing by 2.
so in d regular graph No of edges will be n*d/2
-- Manu Thakur

GATE1995_1.25 top

The minimum number of edges in a connected cyclic graph on n vertices is:


(a) n 1
(b) n
(c) n + 1
(d) None of the above

B.
For making a cyclic graph, the minimum number of edges have to be equal to the number of vertices.
-- Gate Keeda

GATE1995_24 top
Prove that in finite graph, the number of vertices of odd degree is always even.

In any finite graph,


Sum of degree of all the vertices = 2* number of egdes
sum of degree of all the verices with even degree + sum of degree of all the verices with odd degree = 2* number of egdes
even number + sum of degree of all the verices with odd degree = even number
It is possible iff Numbe of odd degree vertices are even.
-- suraj

GATE2008-IT_27 top
G is a simple undirected graph. Some vertices of G are of odd degree. Add a node v to G and make it adjacent to each odd degree vertex of G.
The resultant graph is sure to be

1)

regular

2)

complete

3)

Hamiltonian

4)

Euler

In any simple undirected graph, total degree of all vertices is even (since each edge contributes 2 degrees). So number of vertices having odd
degrees must be even, otherwise their sum would have been odd, making total degree also odd.
Now Single vertex v is connected to all these even number of vertices (which have odd degrees). So degree of v is also even. Moreover, now
degree of all vertices which are connected to v is increased by 1, hence vertices which had odd degree earlier now have even degree.
So now, all vertices in graph have even degree, which is necessary and sufficient condition for euler graph. So 4) is correct.
-- Happy Mittal

GATE2004-IT_37 top
What is the number of vertices in an undirected connected graph with 27 edges, 6 vertices of degree 2, 3 vertices of degree 4 and remaining of
degree 3?

A)

10

B)

11

C)

18

D)

19

sum of degree of all the vertices = 2 * number of edges

2*6 + 4*3 + 3*x = 27*2


x=10.
Number of vertices = 6 + 3 +x = 19
The correct answer is (D).
-- suraj

GATE2005-IT_56 top
Let G be a directed graph whose vertex set is the set of numbers from 1 to 100. There is an edge from a vertex i to a vertex j iff either j = i + 1
or j = 3i. The minimum number of edges in a path in G from vertex 1 to vertex 100 is

A)

B)

C)

23

D)

99

Edge set consists of edges from i to j using either


1) j = i+1 OR
2) j=3i.
Second option will help us reach from 1 to 100 rapidly.
The trick to solve this question is tothink in reverse way. Instead of finding a path from 1 to 100, try to find a path from 100 to 1.
The edge sequence with minimum number of edges is 1 - 3 - 9 - 10 - 11 - 33 - 99 - 100 which consists of 7 edges.
The answer is option 2.
-- Shridhar

Max no of edges in disconnected graph

top

In a simple undirected graph with n vertices what is maximum no of edges that you can have keeping the graph disconnected?
A) nC 2 -1
B) nC 2
C) n-1C 2
D n-1C2

-1

Ans is C) ....Please explain how?

Maximum number of edges in a complete graph =nC 2


Since we have to find a disconnected graph with maximum number of edges with n vertices. Therefore our disconnected graph will have only
two partions because as number of partition increases number of edges will decrease.
Now assume that First partition has x vertices and second partition has (n-x) vertices.
total number of edges = x C 2 +(n-x)C 2
=1/2*(2x2 -2nx + n2 -n),
It would be maximum at both extreme(at x=1 or x= n-1).
Therefore, total number of edges = nC 2 - (n-1) = n-1C 2
-- suraj

where , 1<= x <= n-1

Number of distinct graphs

top

Number of distinct graphs with p vertices and q edges ( p not equal to q) is always equal to
a) p
b) q
c)min(p,q)
d)max (p,q)
e) none of this

I think, None of this should be answer for this question. total no of distinct graphs will be
p(p-1)/2 C q
-- Manu Thakur

GATE2015-2_50 top
In a connected graph, a bridge is an edge whose removal disconnects the graph. Which one of the following statements is true?

A.
B.
C.
D.

A tree has no bridges


A bridge cannot be part of a simple cycle
Every edge of a clique with size 3 is a bridge (A clique is any complete subgraph of a graph)
A graph with bridges cannot have cycle

Ans B
In a cycle if we remove an edge, it will still be connected. So, bridge cannot be part of a cycle.
-- Vikrant Singh

GATE2015-1_54 top
Let G be a connected planar graph with 10 vertices. If the number of edges on each face is three, then the number of edges in G
is_______________.

By Euler formula for connected planar graph,


n-e+f=2
10 - 3f/2 + f = 2 (An edge is part of two faces)
f/2 = 8
f = 16
e = 3f/2 = 24
http://www.personal.kent.edu/~rmuhamma/GraphTheory/MyGraphTheory/planarity.htm
-- Arjun Suresh

graphs - bipartite

top

Q) For what value of n Kn can be bipartite


a)2
b)3
c)4

d) 5

Let G be a complete graph and G' is corresponding bipartite graph..


in bipartite graph der are two group of vertices. let call that group as group A, B respectively..
let a random edge 'e' connecting two vertices V1, V2.
Bipartite property says der is no edge 'e' for which V1 and V2 belongs to same group of vertices i.e. no edge in graph for which both V1 and
V2 belongs to A or both belongs to B..
obviously in complete graph der is an edge which connect every pair of vertices..
so a complete graph is bipartite only if it is complete graph of two vertices..
-- Digvijay Pandey

Linear Algebra top


GATE2007_25 top
Let A be a 4 4 matrix with eigen values -5,-2,1,4. Which of the following is an eigen value of the matrix

, where I is the 4 4 identity matrix?


A) -5

B) -7 C) 2 D) 1

Ans is (C) 2

Ax = x, where is the eigen value of A . Hence (A I)x = 0 or


|A I| = 0
So, for our given matrix, we have

This is a 2 2 block matrix where the first and last and the second and third elements are the same. So, applying the formula for
determinant of a block matrix as given here (second last case) https://en.wikipedia.org/wiki/Determinant#Block_matrices we get
|A I I| |A I + I| = 0
|A ( + 1)I| |A ( 1)I| = 0
Each of the eigen value of A is the solution of the equation |A I| = 0 ( being the eigen value of A). So, we can equate + 1 and 1
to any of the eigen value of A, and that will get our value of. If we take = 1 , we get = 2 , and that is one of the choice. For no other
choice, this equation holds. So, (c) 2 is the answer.

-- Keith Kr

GATE2008_28 top
How many of the following matrices have an eigenvalue 1?

[1
0

0 ][ 0
0 0

(A) one

1 ][ 1
0 1

1 ] and [ 1
1
1

(B) two

(C) three

0 ]
1

(D) four

Characteristic equation is |A I| = 0
(1)

(1 )() = 0
= 0, 1
Similarly, (2) = 0, 0
(3) 1
(4) = 0, 2
Therefore, Answer is (A) one
-- Keith Kr

0 = 0

GATE2004_27 top
Let A, B, C, D be n x n matrices, each with non-zero determinant. If ABCD = I, then B-1 is
A.
B.
C.
D.

D -1C -1A-1
CDA
ADC
Does not necessarily exist

Given
ABCD = I
multiply lhs,rhs by A-1
A -1 ABCD = A-1 I (position of A-1 on both sides should be left)
=> BCD = A-1
=> BCDD-1 = A-1 D -1
=> BC = A-1 D -1
=> BCC-1 = A-1 D -1 C -1
=> B = A-1 D -1 C -1
Now B-1 = (A-1 D -1 C -1 )-1
B -1 = CDA
-- Madhur Rawat

GATE1998_1.2

top

There are no solutions.


If we multiply 1st equation by 4, we get
4x + 8y = 20
But 2nd equation says
4x + 8y = 12
Clearly, there can not be any pair of (x,y), which satisfies both equations.
-- Happy Mittal

GATE1998_2.1

top

Ans D
-- Keith Kr

GATE1998_2.2

top

Answer is B
R2->R2 - R1
R3 -> R3 - R2
you will gt det = (a-b)*(a-c)*(b+c)
in matrix operations, you cannot multiply rows or columns. That will not yield the same matrix. So abc is not correct
-- Dhananjay

GATE2014-2_47 top
The product of the non-zero eigenvalues of the matrix is ____

Let Eigen value be X. Now, equating the determinant of the following to 0 gives us the values for X. To find X in the following matrix, we can
equate the determinant to 0. For finding the determinant we can use row and column additions and make the matrix a triangular one. Then
determinant will just be the product of the diagonals which should equate to 0.

1-X

0
0

1-X
1

1
1-X

1
1

0
0

1-X

1-X

R1 R1 + R5, R4 R4 - R3
2-X

2-X

0
0

1-X
1

1
1-X

1
1

0
0

-X

1-X

Taking X out from R4, 2-X from R1, (so, X = 2 is one eigen value)
1
0

0
1-X

0
1

0
1

1
0

1-X

0
1

0
0

1
0

-1
0

0
1-X

R2 R2 - R3, R5 R5 - R1
1

-X

0
0

1
0

1-X
1

1
-1

0
0

-X

C3 C3 + C4
1
0

0
-X

0
X

0
0

1
0

2-X

0
0

0
0

0
0

-1
0

0
-X

Taking X out from R2


1

-1

0
0

1
0

2-X
0

1
-1

0
0

-X

0
1
3-X
0
0

0
0
1
-1
0

1
0
0
0
-X

R3 R3 + R2
1
0
0
0
0

0
-1
0
0
0

Now, we got a triangular matrix and determinant of a triangular matrix is product of the diagonal.
So (3-X) (-X) = 0 => X = 3 or X = 0. So, X = 3 is another eigen value and product of non-zero eigen values = 2 * 3 = 6.
https://people.richland.edu/james/lecture/m116/matrices/determinant.html
-- Arjun Suresh

GATE2014-3_5 top
If

V 1 and V 2 are 4 -dimensional subspaces of a 6 -dimensional vector space V , then the smallest possible dimension of V 1 V 2 is _____.

A 6-dimensional vector space { a1,a2,a3,a4,a5,a6}


Let V1 be {a1,a2,a3,a4}
and V2 be {a3,a4,a5,a6}

V1V2 = {a3,a4}
This is the smallest possible dimension, which is 2.

The largest possible dimension will be 4 ,when V1 = V2

-- Srinath Sri

GATE1995_1.24 top

Ans is A.
we can eliminate all other rows using row 1. in the last only 1 row will be left.
rank = no of non zero rows = 1
-- jayendra

GATE2008-IT_29 top
If M is a square matrix with a zero determinant, which of the following assertion (s) is (are) correct?
(S1)
(S2)
(S3)
(S4)

Each row of M can be represented as a linear combination of the other rows


Each column of M can be represented as a linear combination of the other columns
MX = 0 has a nontrivial solution
M has an inverse

1)

S3 and S2

2)

S1 and S4

3)

S1 and S3

4)

S1, S2 and S3

Since M has zero determinant, its rank is not full i.e. if M is of size 3*3, then its rank is not 3. So there is a linear combination of rows which
evaluates to 0 i.e.

and there is a linear combination of columns which evaluates to 0 i.e.

Now any row Ri can be written as linear combination of other rows as :

Similar is the case for columns.


Now MX = 0 always has one solution : X = 0 (which is called trivial solution). Now if |M| = 0, then MX = 0 has non-trivial solutions also.
So (S1), (S2), and (S3) are true. So option 4) is correct.
-- Happy Mittal

GATE2004-IT_6 top
What values of x, y and z satisfy the following system of linear equations?

1
1
2

2
3
2

3 x 6
4
y = 8
3 z 12

A)

x = 6, y = 3, z = 2

B)

x = 12, y = 3, z = - 4

C)

x = 6, y = 6, z = - 4

D)

x = 12, y = - 3, z = 0

Correct answer is (C). It can be easily verified by keeping the value of variables in the equations.
-- suraj

GATE2004-IT_36 top
If matrix X = [

a
a2 + a 1

1 ] and 2 X + I = O (I is the identity matrix and O is the zero matrix), then the inverse ofX is
X
1a

[ 1 2a 1 ]
a
a
1

a
1 ]
[ 2
a
a a+1

A)
B)

C)

a
a2 + a 1

2
[a a+1
1

D)

1 ]
1a

a ]
1a

It's a very simple question, We need to calculate the inverse of a 2x2 matrix,
Inverse of a matrix A = A^-1 = Adjoint(A) / determinant of A
adjoint of A = [cofactors of A]^T, but for 2x2 matrix we have direct forumla:
A= a b
c d

is a 2x2 matrix then

Adjoint of A = d -b
-c a
|A| = ad-bc
so answer is (B)
-- Manu Thakur

GATE2015-2_5 top
The larger of the two eigenvalues of the matrix [ 4

5 ] is _______.
1

For finding the Eigen Values of a Matrix we need to build the Characteristic equation which is of the form,

Where A is the given Matrix.


is a constant
I is the identity matrix.
We'll have a Linear equation after solving
(4- ) (1- ) - 10 = 0
4 - 5 + 2 = 10
2

-5 - 6 = 0

( - 6) ( + 1) = 0
So

= -1 , 6.

6 is larger and hence is the Answer.

. Which will give us 2 roots for .

-- Gate Keeda

GATE2015-2_27 top
Perform the following operations on the matrix

3
7
13

4
9
2

45
105
195

i. Add the third row to the second row


ii. Subtract the third column from the first column.
The determinant of the resultant matrix is _____.

Ans Zero, row and column transformations doesn't affect determinant.


-- Vikrant Singh

GATE2015-3_15 top
In the given matrix

A.
B.
C.
D.

1
0
1

1
1
2

2
0 , one of the eigenvalues is 1. The eigenvectors corresponding to the eigenvalue 1 are
1

{a(4, 2, 1) a 0, a R}
{a(4, 2, 1) a 0, a R}
{a(2 , 0, 1) a 0, a R}
{a(2 , 0, 1) a 0, a R}

11
0
1

1
11
2

y + 2z = 0

2 0
= 0
0
11 1

1
0
2

2 x
0 y
0 z

x + 2y = 0
now consider each of the triplets as the value of x, y, z and put in these equations the one which satisfies is the answer.
why so because an eigen vector represents a vector which passes through all the points which can solve these equations.
so we can observe that only option B is satisfying the equations.
-- Tamojit Chatterjee

GATE2015-3_33 top
If the following system has non-trivial solution,

px + qy + rz = 0
qx + ry + pz = 0
rx + py + qz = 0,
then which one of the following options is TRUE?

A.
B.
C.
D.

pq+r
p+qr
p+q+r
pq+r

= 0 or p
= 0 or p
= 0 or p
= 0 or p

= q = r
= q = r
=q=r
= q = r

for non-trivial solution

|A| = 0
where |A| =

p
q
r

q
r
p

r
p = p (rq p 2 ) q (q 2 pr) + r (qp r2 )
q

= prq p 3 q 3 + prq + prq r3


= 3prq p 3 q 3 r3

= (p + q + r)3 + 3(p + q + r)(pq + qr + pr)

now if you check the options the only options where each individual condition can make|A| = 0 zero is C
-- Tamojit Chatterjee

Value of a^2+b^2 ?

top

Given equation is

(8 + i)50 = 3 49 (a + ib)

take the conjugate on both sides

(8 i)50 = 3 49 (a ib)

After multiplying both equations we will get,

9 50 = 3 98 (a2 + b 2 )

( a2 + b 2 ) = 9
-- suraj

Numerical Methods

top

GATE2012_28 top
The bisection method is applied to compute a zero of the function f(x) = x4 x3 x2 4 in the interval [1,9]. The method converges to a
solution after iterations.
(A) 1
(B) 3
(C) 5
(D) 7

Bisection method is exactly like binary search on a list.


In bisection method, in each iteration, we pick the mid point of the interval as approxiamation of the root, and see where are we, i.e. should
we choose left sub-interval, or right-subinterval, and we continue until we find the root, or we reach some error tolerance.
So in first iteration, our guess for root is mid point of [1,9] i.e. 5. Now f(5) > 0, so we choose left sub-interval [1,5] (as any value in right subinterval [5,9] would give more positive value of ).
In second iteration, we choose mid point of [1,5] i.e. 3, but again f(3) > 0, so we again choose left sub-interval [1,3].
In third iteration, we choose mid point of [1,3] i.e. 2, now f(2) = 0
So we found root in 3 iterations. So answer is option (B).
-- Happy Mittal

GATE2014-2_46 top
In the Newton-Raphson method, an initial guess of x0 = 2 is made and the sequence x0 , x1 , x2 is obtained for the function

0.75x3 2x2 2x + 4 = 0
Consider the statements
I. x3 = 0
II. The method converges to a solution in a finite number of iterations.
Which of the following is TRUE?
(A) Only I
(B) Only II
(C) Both I and II
(D) Neither I nor II

xn+1 = xn

f( xn )

f ( xn )

for Newton-Raphson method (See the link below)

f(x) = 0.75x3 2x2 2x + 4


f(2) = 2
f (x) = 2.25x2 4x 2
f (2) = 9 8 2 = 1
So, x1 = 2

x2 = x1

2
1

f( x1 )

f ( x1 )

= 22= 0
= 0

4
2

=2

Since x2 = x0 , we will get x3 = x1 = 0 .


So, x3 = 0 , and the method never converges. A choice.
https://www.math.ubc.ca/~anstee/math104/104newtonmethod.pdf
-- Arjun Suresh

GATE2015-3_50 top
The velocity v (in kilometer/minute) of a motorbike which starts form rest, is given at fixed intervals of timet (in minutes) as follows:
t

10

12

14

16

18

20

10

18

25

29

32

20

11

The approximate distance (in kilometers) rounded to two places of decimals covered in 20 minutes using Simpson's1/3 rd rule is ________.

The total distance covered is given by the area under the speed curve and can be calculated by integrating the speed curve equation in the
given range. In the question, exact speed function is not given, but the speed at different time instants is given.
Question is asking the distance covered in 20 minutes. According to the question, the motion starts at t = 0 and ends at t = 20. So the speed
function has to be integrated in the range t=0 to t=20. Therefore an additional point (t=0) has to be considered while integrating. After adding
t=0, number of points will be 11 and number of intervals will be 10. And the answer will be 309.33.
Distance

S=

(ba)
3n

[f(0) + 4(f(2) + f(6) + f(10) + f(14) + f(18))

+ 2(f(4) + f(8) + f(12) + f(16) + f(20))]

2
3

[0 + 4(10 + 25 + 32 + 11 + 2)

+ 2(18 + 29 + 20 + 5)]

= 309.33
Ref: http://www.saylor.org/site/wp-content/uploads/2011/11/ME205-7.2-TEXT2.pdf
-- ashishacm

Calculus top
GATE2007_1

top

Consider the following two statements about the functionf(x) = |x|:


P. f(x) is continuous for all real values of x.
Q. f(x) is differentiable for all real values of x .
Which of the following is TRUE?
(A) P is true and Q is false. (B) P is false and Q is true.
(C) Both P and Q are true. (D) Both P and Q are false.

ans is A. f(x)=|x| here for all values of x, f(x) exists. therefore it is continuous for all real values of x.
At x=0, f(x) is not differentiable. Because if we take the left hand limit here, it is negative while the right hand limit is positive.
Ref: http://math.stackexchange.com/questions/991475/why-is-the-absolute-value-function-not-differentiable-at-x-0
-- jayendra

GATE1998_1.4

top

(b) It is continuous but not differentiable at x=0 as left hand limit will be negative while the right hand limit will be positive but for differentiation,
both must be same.
-- Gate_15_isHere

GATE1998_8

top

(a) Find the points of local maxima and minima, if any, of the following function defined in 0 x 6 .

x3 6x2 + 9x + 15
(b) Integrate

x cos xdx

(a)
so
Now
f''(1) < 0, so x = 1 is point of local maxima, f''(3) > 0, so x = 3 is point of local minima.
Also the end points 0 and 6 are critical points. 0 is point of local minima, because it is to the left of x = 1 (which is point of maxima). Similarly x
= 6 is point of local maxima.
(b) Since xcosx is an odd function, by the properties of definite integration, answer is 0.

-- Happy Mittal

GATE2014-1_47 top
A function f(x) is continuous in the interval
(A) There exists a
(B) For every

[0, 2] . It is known that f(0) = f(2) = 1 and f(1) = 1 . Which one of the following statements must be true?

y in the interval (0, 1) such that f(y) = f(y + 1)

y in the interval (0, 1) ,f(y) = f(2 y)

(C) The maximum value of the function in the interval (0, 2) is 1


(D) There exists a

y in the interval (0, 1) such that f(y) = f(2 y)

Let's define a new function g,


g(y) = f(y) -f(y+1)
Since function f is continuous in [0,2], therefore g would be continuous in [0,1]
g(0) = -2, g(1) = 2
since g is continuous and goes from negative to positive value in [0,1]. therefore at some point g would be 0 in (0,1).
g=0 => f(y) = f(y+1) for some y in (0,1).

Therefore, correct answer would be (A).


-- suraj

GATE1997_4.1

top

Answer: B
For f(x) to be maximum
f'(x) = 4x - 2 = 0
So at x = 2, f(x) is maximum.
f(2) = 2(2)2 - 2(2) + 6 = 8 - 4 + 6 = 10

-- Jon Snow

GATE1995_1.21 top

ans is B.
if you consider x=0 then cosx=1
now if x= PI/4 = 0.785 then cosx=0.7071
for some x value x=cosx
after this x is increasing and cosx is decreasing. so we can say exactly 1 solution.

-- jayendra

GATE1995_25 top
a. Find the minimum value of 3 4x + 2x2 .
b. Determine the number of positive integers ( 720) which are not divisible by any of 2, 3 or 5.

f(x) = 3-4x+2x2
f'(x) = -4 + 4x = 0 => x=1
f''(x) = 4
2=1
f''(1) = 4>0, therefore at x=1 we will get mimimum value, which is : 3 - 4(1) + 2(1)

ans for B:

-- jayendra

GATE1996_3

top

Let f be a function defined by

x2
f(x) = ax2 + bx + c

x+d

for x 1
for 1 < x 2
for x > 2

Find the values for the constants a, b , c and d so that f is continuous and differentiable everywhere on the real line.

f is differentiable at 1 if

=> 2 = 2a+b - (1)


f is differentiable at 2 if

=> 4a+b = 1 - (2)


Solving (1) and (2), we get
a = -0.5, b = 3
Now f has to be continous on 1 also, so

=> 1 = a + b + c

=> c = -1.5
Similarly f has to be continous on 2 also, so

=> 4a+2b+c = 2+d


=> d = 0.5
So a = -0.5, b = 3, c = -1.5, d = 0.5
-- Happy Mittal

GATE2015-1_4 top
1

lim x x x is
A.
B.
C.
D.

0
1
Not defined

Apply an exponential of a logarithm to the expression.

Since the exponential function is continuous, we may factor it out of the limit.

Logarithmic functions grow asymptotically slower than polynomials.


Since

grows asymptotically slower than the polynomial as

approaches

Evaluate

:
Answer:
-- Shyam Singh

GATE2015-1_44 top
2/ cos(1/x)
x2

1/

dx =__________________________.

For the integrand

, substitute

This gives a new lower bound

and

and upper bound

Switch the order of the integration bounds of


Multiply the integrand by

so that the upper bound is larger.

Apply the fundamental theorem of calculus.


The antiderivative of

is

Evaluate the antiderivative at the limits and subtract.

Answer:
-- Shyam Singh

GATE2015-3_9 top
The value of lim x (1 + x2 )e

is

A. 0
B. 1
2
C. 1
D.

Apply an exponential of a logarithm to the expression.

Since the exponential function is continuous, we may factor it out of the limit.

The numerator of
Since

grows asymptotically slower than its denominator as approaches


grows asymptotically slower than

Evaluate

:
Answer:
-- Shyam Singh

as

approaches

.
:

GATE2015-3_45 top
If for non-zero x, af(x) + bf( 1 ) =
x

A.
B.
C.
D.

1
a 2 b 2
1
a 2 b 2
1
a 2 b 2
1
a 2 b 2

[ a(ln 2 25) +

47b
2

[ a(2 ln 2 25)
[ a(2 ln 2 25) +
[ a(ln 2 25)

af(x) + bf( 1x ) =

1
x

47b
2
47b
2

47b
2

1
x

25 where a a b then 12 f(x)dx is

]
]

25 --- (1)

Integrating both sides,

a 12 f(x)dx + b 12 f( 1x )dx = [log(x) 25x]21 = log 2 25 --- (2)


Replacing x by

1
x

in (1), we get

af( 1x ) + bf(x) = x 25
Integrating both sides, we get
2

a 12 f( 1x )dx + b 12 f(x)dx = [ x2 25x] =


2
1

47
2

--- (3)

Eliminate 12 f( 1x ) between (2) and (3) by multiplying (2) by a and (3) by b and subtracting

(a2 b 2 ) 12 f(x)dx = a(log 2 25) + b


12 f(x)dx =
Answer: A.

1
(a 2 b 2 )

1
(a 2 b 2 )

-- Shyam Singh

[a(log 2 25) +

[a(log 2 25) +

47b ]
2

47b
]
2

47
2

Programming top
GATE2013_42 top
What is the return value of f(p,p), if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas
the second parameter is passed by value.
int f (int &x, int c) {
c = c - 1;
if (c==0) return 1;
x = x + 1;
return f(x,c) * x;
}

In GATE 2013 marks were given to all as the same code in C/C++ produces undefined behavior. This is because * is not a sequence point in
C/C++. The correct code must replace
return f(x,c) * x;
with
res = f(x,c);
return res * x;
In this code, there will be 4 recursive calls with parameters (6,4), (7,3), (8,2) and (9,1). The last call returns 1. But due to pass by reference, x
in all the previous functions is now 9. Hence, the value returned by f(p,p) will be 9 * 9 * 9 * 9 * 1 = 6561.
-- Arjun Suresh

I have been struggling with pointers in multi-dimensional arrays. Please help me with this
code :- top
Explain the output :int b[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
int** p;
p = (int**)b;
cout << (long)*p << "\t" << (long)(*p+1) << "\t" << (long)(*p+2);
//long is used to print the output in decimal format instead of hex

Here, b is a 2D array and it contains 3*4 = 12 elements. Suppose address of b starts from 1000. Now the elements will be stored as:
1000-3: 1
1004-7: 2
1008-11: 3
1012-15: 4
1016-19: 5
....
1045-48: 12
Now, we declare p as int** and initialize it to 1000, the base address of b.
So, *p will have 1. (assuming a 32 bit architecture, on 64 bit architecture *p will be 8 bytes and the array element being int is only 4 bytes)
Now, *p+1, is pointer arithmetic. It will add 1 *sizeof(int) to *p. So, *p+1 will give 1 + 4 = 5. (This 5 is not the element 5 in the array)
Similarly, *p+2, will add 2*sizeof(int) = 2*4 = 8 to *p. So, *p+2 will give 1+8 = 9.
These are all valid only on a 32 bit compiler. On a 64 bit compiler, if we use
(long)*p
It will try to read 8 bytes from the start of the array.
Since,
1000-3: 1
1004-7: 2

From 1000, the content of memory will be (assuming a little endian machine)
0000 0001 0000 0000 0000 0000 0000 0000 | 0000 0010 0000 0000 0000 0000 0000 0000
This value in binary will be
0000 0010 0000 0000 0000 0000 0000 0000 0000 0001
= 2 33

+1

= 8589934593
So, the output will be 8589934593, 8589934597 and 8589934601
This output is entirely implementation dependent as it depends on the sizeof (int) and sizeof pointer and also depends on the endianness of the machine(if sizeof
(int) is different from sizeof pointer) .
For more details about pointer arithmetic you can see here:

http://gatecse.in/wiki/Chapter_3:_Pointers#Pointer_Arithmetic

-- Arjun Suresh

GATE1994_1.20 top
In which of the following cases is it possible to obtain different results for call-by-reference and call-by-name parameter passing methods?

(a) Passing a constant value as a parameter


(b) Passing the address of an array as a parameter
(c) Passing an array element as a parameter
(d) Passing an array

(c) Passing an array element as a parameter is the answer.


Consider this function call
{
....
a[] = {0,1,2,3,4};
i = 0;
fun(a[i]);
print a[0];
}
fun(int x)
{
int i = 1;
x = 8;
}

Output:
call-by-reference: 8
call-by-name: 0
In Call-by-name, each occurence of the formal parameter is replaced by the actual argument text. So, the function fun will be executed like:
{
int i = 1;
a[i] = 8; //a[1] is changed to 8 and not a[0]
}

A very good read: http://courses.cs.washington.edu/courses/cse341/03wi/imperative/parameters.html


-- Arjun Suresh

GATE2008_18 top
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.
B.
C.
D.

x
x
x
x

= 3, y = 4, z
= 6, y = 5, z
= 6, y = 3, z
= 5, y = 4, z

=2
=3
=5
=5

Using option A : x=3, y=4, z=2


a=(3>4)? No
therefore don't evaluate the first part and check second part ((y>z)?y:z)
(4>2)? Yes
a= value of y =4
Answer is (A) x=3, y=4, z=2
-- Keith Kr

GATE2008_61 top
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 string is
terminated by a new line character.
void reverse(void) {
int c;
if(?1) reverse();
?2
}
main() {
printf("Enter text"); ptintf("\n");
reverse(); printf("\n");
}

A. ?1 is (getchar() != \n)
?2 is getchar(c);
B. ?1 is ((c = 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);

Here we are using the '=' operator which has less priority than '!=' operator. So (c=getchar()) has to be in brackets and after reversing the
string we use function putchar(c) for printing the character So option (d) is the right answer
-- Kalpna Bhargav

GATE1991_09,a,b top
(a) Consider the following pseudo-code (all data items are of type integer):

procedure P(a, b, c);


a := 2;
c := a + b;
end {P}
begin
x := 1;
y := 5;
z := 100;
P(x, x*y, z);
Write ('x = ', x, 'z = ', z);
end

Determine its output, if the parameters are passed to the Procedure P by


i. value
ii. reference
iii. name
(b) For the following code, indicate the output if
i. static scope rules
ii. dynamic scope rules
are used
var a,b : integer;
procedure P;
a := 5;
b := 10;
end {P};
procedure Q;
var a, b : integer;
P;
end {Q};
begin
a := 1;
b := 2;
Q;
Write ('a = ', a, 'b = ', b);
end

(a)
1. Pass by value: Function cannot modify a variable in the calling function. So,
x = 1, z = 100
2. Pass by reference: An alias of the variable (a different name but having same memory location) is used to pass the variable to a function.
So, whatever change occurs for the variable in the called function is reflected in the calling function.
x = 2, z = 7 (2 + 5)
3. Pass by name: The expression used to call a function is copy pasted for each formal parameter. So, the body of P becomes,
x := 2;
z := x + x*y;

So, printed value will be


x = 2, z = 12
(b) In static scoping, if a variable is not found in the local scope, its looked upon in global scope. In dynamic scoping, if a variable is not found
in local scope, its looked upon in the function which called the current executing one.
1. a = 5, b = 10
2. a = 1, b = 2
(The modification in Q, happens to the variables in P but in main we use the global variables)
-- Arjun Suresh

GATE2000_1.11 top
The following C declarations
struct node {
int i:

float j;
};
struct node *s[10];
define s to be

a.
b.
c.
d.

An array, each element of which is a pointer to a structure of type node


A structure of 2 fields, each field being a pointer to an array of 10 elements
A structure of 3 fields: an integer, a float, and an array of 10 elements
An array, each element of which is a structure of type node

(a) is the answer. [] has greater precedence than * in C. So, s becomes an array of pointers.
-- gatecse

GATE2001_2.18 top
Consider the following three C functions:
[P1]
int *g(void)
{
int x = 10;
return (&x);
}

[P2]
int *g(void)
{
int *px;
*px = 10;
return px;
}

[P3]
int *g(void)
{
int *px;
px = (int*) malloc (sizeof(int));
*px = 10;
return px;
}

Which of the above three functions are likely to cause problems with pointers?
A.
B.
C.
D.

Only P3
Only P1 and P3
Only P1 and P2
P1, P2 and P3

[P1] may cause an error because function is returning the address of locally declared variable.
[P2] will cause a problem because px is an int pointer that is not assigned with any address and we are doing dereferencing.
[P3] will work because memory in bytes of size of int will be reserved and its address will be stored in px that can be further use, once function
execution completes, this m/m will still exist in Heap until we free it using free() function.
hence answer is C
-- Manu Thakur

GATE2002_2.8

top

Consider the following declaration of a two-dimensional array in C:


char a[100][100];
Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a [40][50] is

A.
B.
C.
D.

4040
4050
5040
5050

answer is (b)

Formula to evaluate 2-d array's location is:---loc(a[i][j]) = BA + [(i-lb1)*NC+(j-lb2))*c


where BA= Base Address
NC= no. of columns
C= memory size allocated to data type of array
a[lb1.....ub1] [lb2..... ub2]
here BA=0 , NC =100,

c=1,

a[0.....99][0......99] so lb1=0 , lb2=0

loc(a[40][50])= 0+ [ (40-0)*100 + (50-0)]*1


= 0+[4000+50]*1 = 4050
-- Kalpna Bhargav

GATE2003_2

top

Assume the following C variable declaration


int *A[10], B[10][10];

Of the following expressions


I.
II.
III.
IV.

A[2]
A[2][3]
B[1]
B[2][3]

which will not give compile-time errors if used as left hand sides of assignment statements in a C program?
A.
B.
C.
D.

I, II, and IV only


II, III, and IV only
II and IV only
IV only

A is an array of pointers to int, and B is a 2-D array.


A[2] =
can take a pointer
A[2][3] =
can take an int
B[1] =
B[1] is the base address of array and it cannot be changed as array in C is a constant pointer.
B[2][3] =
can take an integer
So, A is the answer.
-- Arjun Suresh

GATE2004_1

top

The goal of structured programming is to


A.
B.
C.
D.

have well indented programs


be able to infer the flow of control from the compiled code
be able to infer the flow of control from the program text
avoid the use of GOTO statements

Answer is (c) The goal of structured programming is to able to infer the flow of control from the program text . It means user can execute the
code according to his requirement. C and Pascal are good example of structured programming. In structured programming control passes
one instruction to another instruction in sequential manner.
Avoiding the use of GOTO statements is not the goal of structured programming, it (avoiding the use of GOTO) is one of the requirements for
a program to be structured.
-- Kalpna Bhargav

GATE2004_31 top
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.
B.
C.
D.

5
6
7
8

answer is 7.as,
f(1):n=2,i=2
f(2):n=4,i=3
f(4):n=7,i=4
f(7):print(n)===>>> 7<ans>
-- sumit kumar singh dixit

GATE1998_2.13 top

function f(x) calling only for one time and f(x)*f(x) replacing value of f(x) = 6*6 ;
for above given algorithm
C++ program is :
#include <iostream>
using namespace std;
int x , result;
int f (int x)
{
x=x+1;
return x;
}
int main ()
{
x=5;
result = f(x)*f(x);
cout << "The result is " << result;
}
and the output is "The result is 36".
ref@ cpp.sh/3ojt

.....> click on "RUN"

-- csegate2

GATE1998_2.15 top
Faster access to non-local variables is achieved using an array of pointers to activation records called a
A.
B.
C.
D.

stack
heap
display
activation tree

it is C
properties of displays
1> Use a pointer array to store the activation records along the static chain.
2> Fast access for non-local but may be complicated to maintain.
3> Calling a subprogram in the same level simply replace and restore.
4> Calling a subprogram in the higher level add an entry and may need to save the old pointers.
5> Calling a subprogram in the lower level shrink the pointer and restore it when the subprogram returns.
http://users.dickinson.edu/~wahlst/356/ch10.pdf
-- sumit kumar singh dixit

GATE2012_36 top
Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted.
Program main;
Var ...
Procedure A1;
Var ...
Call A2;
End A1
Procedure A2;
Var ...
Procedure A21;
Var ...
Call A1;
End A21
Call A21;
End A2
Call A1;
End main.

Consider the calling chain: Main -> A1 -> A2 -> A21 -> A1
The correct set of activation records along with their access links is given by

Since, Activation records are created at procedure entry time and destroyed at procedure exit time.
therefore here Calling sequence is given as ,
Main->A1->A2->A3->A1
now A1,A2 are defined under Main...So A1,A2 Access link are pointed to main
A21 is Defined under A2 hence its Access link will point to A2
-- Kalpish Singhal

GATE2006_56 top
Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.
subroutine swap(ix,iy)
it = ix
L1 : ix = iy
L2 : iy = it
end
ia = 3
ib = 8
call swap (ia, ib+5)
print *, ia, ib
end

S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell to swap
S2: On execution the code will generate a runtime error on line L1
S3: On execution the code will generate a runtime error on line L2
S4: The program will print 13 and 8
S5: The program will print 13 and -2
Exactly the following set of statement(s) is correct:
(A) S1 and S2
(B) S1 and S4
(C) S3
(D) S1 and S5

S1 and S4 are correct. There won't be any runtime error for the given code using pass by reference.
-- Arjun Suresh

GATE2006_57 top
Consider this C code to swap two integers and these five statements: the code
void swap (int *px, int *py) {
*px = *px - *py;
*py = *px + *py;
*px = *py - *px;
}

S1: will generate a compilation error


S2: may generate a segmentation fault at runtime depending on the argumentspassed
S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process
S4: implements the swap procedure correctly for some but not all valid inputpointers
S5: may add or subtract integers and pointers
(A) S1
(B) S2 and S3
(C) S2 and S4
(D) S2 and S5

s1 is false . s2 is true ,depending on the argument passed it may generate segmentation fault s3 is false bcz implementation is having some
problem ...let x=3 and i want to implement SWAP[x,x] now ans would be 0 but that must be remain x problem is bcz we are not checking
whether both pointer are pointing the same address or different so s4 is true s5 is obviously false so Option(c) is right
-- Kalpna Bhargav

GATE2014-2_11 top
Suppose n and p are unsigned int variables in a C program. We wish to set p to n C 3 . If n is large, which one of the following statements is most likely to set p
correctly?

(A) p = n * (n-1) * (n-2) / 6;


(B) p = n * (n-1) / 2 * (n-2) / 3;
(C) p = n * (n-1) / 3 * (n-2) / 2;
(D) p = n * (n-1) * (n-2) / 6.0;

B)
In c, * and / have the same precedence and are left associative.
Evaluation of n*(n-1)*(n-2) might exceed the unsigned int range.
So a) and d) are eliminated.
n*(n-1) is always divisible by 2.(Gives an integer value). Where as it is not always divisible by 3.(You dont always get an integer..truncation
possible, less accuracy)
c) eliminated.
In option b)
n*(n-1)/2 gives an integer value.
This integer value multiplied by (n-2) again gives an integer value.
Which when divided by 3 gives an integer value(Sets p correctly).
Reason : n*(n-1)*(n-2) is the multiplication of 3 consecutive numbers. which is divisible by 2 as well as 3.
Hence ( n*(n-1)/2*(n-2) ) is divisible by 3.
-- Srinath Sri

GATE2014-3_42 top
Consider the C function given below. Assume that the array listA contains n(>

0) elements, sorted in ascending order.

int ProcessArray(int *listA, int x, int n)


{
int i, j, k;
i = 0;
j = n-1;
do {
k = (i+j)/2;
if (x <= listA[k])
j = k-1;
if (listA[k] <= x)
i = k+1;
}while (i <= j);
if (listA[k] == x)
return(k);
else
return -1;
}

Which one of the following statements about the function P rocessArray is CORRECT?

(A) It will run into an infinite loop when x is not in listA.


(B) It is an implementation of binary search.
(C) It will always find the maximum element in
(D) It will return 1 even when x is present in

listA.
listA.

B)....
-- Siddhartha Datta

GATE2012_48,49 top
Common Data for Questions 48 and 49:
Consider the following C code segment.
int a, b, c = 0;
void prtFun(void);
main()
{
static int a = 1;
/* Line 1 */
prtFun();
a += 1;
prtFun();
printf( \n %d %d , a, b);
}
void prtFun(void)
{
static int a = 2;
/* Line 2 */
int b = 1;
a += ++b;
printf( \n %d %d , a, b);
}

Q.48 What output will be generated by the given code segment?


(A)
3

4
4

1
2

(B)
4

(C)
4
6

2
2

(D)
3
5

1
2

Q.49 What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;

(A)
3
4

1
1

(B)
4

6
6

1
1

(C)
4

6
2

2
0

(D)
4

4
2

2
0

48.
main
a=1
prtFun()
a=2
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a = a+1 --> 1+1 -->2 (local static a is taken)
prtFun()
a=4 // previous value in the function is retained bcos of static
b=1
a= a + ++b = 4+2 = 6
b=2
printf --> 6 2
back to main
a=2
b = 0 (initial value of global b. in prtFun local b is only updated)
printf --> 2 0
Answer: C

49
main
a=1
prtFun()
a=2
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a = a+1 --> 1+1 -->2
prtFun()
a=1 //previous a is lost
b=1
a= a + ++b = 2+2 = 4
b=2
printf --> 4 2
back to main
a=2
b = 0 (initial value of global b. in prtFun local b is only updated)
printf --> 2 0
Anwer: D
-- Sankaranarayanan P.N

GATE2010_11 top
What does the following program print?
#include<stdio.h>
void f(int *p, int *q) {
p=q;
*p=2;
}
int i=0, j=1;
int main() {
f(&i, &j);
printf("%d %d\n", i,j);
return 0;
}

(A) 2 2
(B) 2 1
(C) 0 1
(D) 0 2

p=q; -- now p and q are pointing to same address i.e. address of j


*p=2; -- value of j will be updated to 2
hence answer is (D) 0 2

-- Manu Thakur

GATE2010_14 top
Which languages necessarily need heap allocation in the runtime environment?
(A) Those that support recursion.
(B) Those that use dynamic scoping.
(C) Those that allow dynamic data structure.
(D) Those that use global variables.

Those that allow dynamic data structure.


malloc etc uses memory from heap area

-- Sankaranarayanan P.N

GATE2008-IT_13 top
Match the programming paradigms and languages given in the following table.
Paradigms

A.

I-c, II-d, III-b, IV-a

B.

I-a, II-d, III-c, IV-b

C.

I-d, II-c, III-b, IV-a

D.

I-c, II-d, III-a, IV-b

Languages

(I)

Imperative

(a)

Prolog

(II)

Object Oriented

(b)

Lisp

(III)

Functional

(c)

C, Fortran 77, Pascal

(IV)

Logic

(d)

C++, Smalltalk, Java

A is correct. Lisp is a pure functional language and Prolog is a logic language. Other languages are well known.
-- Arjun Suresh

GATE2008-IT_49 top
What is the output printed by the following C code?
# include <stdio.h>
int main ()
{
char a [6] = "world";
int i, j;
for (i = 0, j = 5; i < j; a [i++] = a [j--])
printf ("%s\n", a);
}

A)

dlrow

B)

Null string

C)

dlrld

D)

worow

char a[6] =
w

a[0]

r
1

l
2

d
3

\0
4

When Loop will execute first time,


a[0] =a[5]
a[0] =`\0`
printf(%s, a) , the string starting at address a prints the string starting with `\0` and it indicates the end of string ,so it will print null string.
so option (B)
-- Mitali

GATE2008-IT_50 top

Consider the C program below. What does it print?


# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
int tmp;
tmp = a; a = b; b = tmp;
}
void swap3 (int*a, int*b)
{
int tmp;
tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
int num1 = 5, num2 = 4, tmp;
if (num1 < num2) {swap1 (num1, num2);}
if (num1 < num2) {swap2 (num1 + 1, num2);}
if (num1 > = num2) {swap3 (&num1, &num2);}
printf ("%d, %d", num1, num2);
}

A)

5, 5

B)

5, 4

C)

4, 5

D)

4, 4

Answer: C
Only
if (num1 > = num2) {swap3 (&num1, &num2);}
statement works, which in turn swaps num1 and num2.
-- Jon Snow

GATE2008-IT_51 top
Consider the C program given below. What does it print?
#include <stdio.h>
int main ()
{
int i, j;
int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
for(i = 0; i < 3; i++) {
a[i] = a[i] + 1;
i++;
}
i--;
for (j = 7; j > 4; j--) {
int i = j/2;
a[i] = a[i] - 1;
}
printf ("%d, %d", i, a[i]);
}

A)

2, 3

B)

2, 4

C)

3, 2

D)

3, 3

Answer is (c) 3,2

first 2 variable integer type declared named i,j


then an int type array a[8] declared and initialized.
a[0]

a[1]

a[2]

a[3]

a[4]

a[5]

a[6]

a[7]

then for loop started


i=0 i<3 (true)
a[0]=a[0]+1 = 1+1=2
i++
i++
i=2 i<3 (true)
a[2]=a[2]+1 = 3+1=4
i++
i++
i=4 i<3 (false)
i-- (i=3)

now another for loop started where in loop integer type variable named i declared

Block Scope: A Block is a set of statements enclosed within left and right braces ({ and } respectively). Blocks may be nested in C
(a block may contain other blocks inside it). A variable declared in a block is accessible in the block and all inner blocks of that
block, but not accessible outside the block.
What if the inner block itself has one variable with the same name?
If an inner block declares a variable with the same name as the variable declared by the outer block, then the visibility of the outer
block variable ends at the point of declaration by inner block

so here inner block int i has the scope in this block only and outer block int i visibility is not allowed in that block
j=7 j>4(true)
int i = 7/2=3
a[3]=a[3]-1=4-1=3
j=6 j>4(true)
int i = 6/2=3
a[3]=a[3]-1=3-1=2
j=5 j>4(true)

int i = 5/2=2
a[2]=a[2]-1=4-1=3
j=4 j>4(false)

now when the for loop ends its variable named i scope is also end and the outer block variable now visible
so the output would be:----

3,2

-- Kalpna Bhargav

GATE2008-IT_52 top
C program is given below:
# include <stdio.h>
int main ()
{
int i, j;
char a [2] [3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}};
char b [3] [2];
char *p = *b;
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
*(p + 2*j + i) = a [i] [j];
}
}
}

What should be the contents of the array b at the end of the program?

A)

a
c
e

b
d
f

B)

a
b
c

d
e
f

C)

a
e
d

c
b
f

D)

a
d
b

e
c
f

The correct answer is option (B)


first integer type two variables declared i and j
then an integer type 2-d array a[2][3] is declared and initialized and 2-d array b[3][2] is created but not initialized. i.e
address

value

address

value

a[0]0[] 2000

b[0][0] 3000

garbage value

a[0][1] 2001

b[0][1] 3001

garbage value

a[0][2] 2002

b[1][0] 3002

garbage value

a[1][0] 2003

b[1][1] 3003

garbage value

a[1][1] 2004

b[2][0] 3004

garbage value

a[1][2] 2005

b[2][1] 3005

garbage value

now the char type pointer is declared and the base address of array b is put in it. so p=3000
now the for loop is started where i is initialized to 0 ,so
i=0 : i<2 (true)
j=0; j<3 (true)
*(3000+2*0+0) =a [0][0] => *(3000) = a
j++
j=1; j<3 (true)
*(3000+2*1+0) =a [0][1] => *(3002) = b
j++
j=2; j<3 (true)

*(3000+2*2+0) =a [0][2] => *(3004) = c


j++
j=3; j<3 (false)
i++
i=1 : i<2 (true)
j=0; j<3 (true)
*(3000+2*0+1) =a [1][0] => *(3001) = d
j++
j=1; j<3 (true)
*(3000+2*1+1) =a [1][1] => *(3003) = e
j++
j=2; j<3 (true)
*(3000+2*2+1) =a [1][2] => *(3005) = f
j++
j=3; j<3 (false)
i++
now the values in array b is
b[0][0] 3000

b[0][1] 3001

b[1][0] 3002

b[1][1] 3003

b[2][0] 3004

b[2][1] 3005

hence the output will be (B) choice.


Note:
*(p + 2*j + i)
p + sizeofinner dimension * j + i, hence is same as p[j][i]. Hence with this statement we can identify that the code is transposing the matrix a
and storing in b using pointer p.
-- Kalpna Bhargav

GATE2007-IT_32 top
Consider the following C program:
#include <stdio.h>
#define EOF -1
void push (int); /* push the argument on the stack */
int pop (void); /* pop the top of the stack */
void flagError ();
int main ()
{
int c, m, n, r;
while ((c = getchar ()) != EOF)
{ if (isdigit (c) )
push (c);
else if ((c == '+') || (c == '*'))
{
m = pop ();
n = pop ();
r = (c == '+') ? n + m : n*m;
push (r);
}
else if (c != ' ')
flagError ();
}
printf("% c", pop ());
}

What is the output of the program for the following input ?


52*332+*+

A)

15

B)

25

C)

30

D)

150

B) 25
let first part
5 ----push
2------push
push------5*2=10. (pops 5 and 2)
push 3
push 3
push 2
push 3+2 = 5 (pops 2 and 3)
push 5*3 = 15 (pops (5 and 3)
push 15 + 10 = 25 (pops (15 and 10)
-- Arpit Dhuriya

GATE2007-IT_33 top
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods
of parameter passing.
int i ;
program main ()
{
int j = 60;
i = 50;
call f (i, j);
print i, j;
}
procedure f (x, y)
{
i = 100;
x = 10;
y=y+i;
}

Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
A)

Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70

B)

Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70

C)

Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60

D)

Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70

Correct answer is (d)


CALL BY VALUE :- i as global variable declared. Then in main() a local variable j as integer declared i.e j=60 And global variable i initialized to
50 by i=50. Now procedure f called and values of i and j are passed to it. i.e., in f(i,j) -> f(x, y) content of memory location of i (here 50) is
copied to memory location of x (which is different from i) and content of memory location of j (here, 60) is copied to memory location of y.
Then in f(x,y) i=100 changes the global i to 100, X= 10 changes the local X from 50 to 10 and Y= y+ i means y=60+100=160. Now when
return back to main, i and j will be 100 and 60 respectively.
CALL BY REFERENCE:- Now procedure f called and passed reference of i and j to it. i.e., in f(i,j) -> f(x, y) x and y are new names (aliases)
pointing to the same memory location of i and j respectively. So, i = 100 changes the global i to 100 and x= 10 means x as well as global i =10
(as the i being passed is the global variable and x and i share the same address).
y= y+ i means y = 60+10=70 and this changes the value of j also to 70 as j and y have the same address. Now when return back to main, i
and j will be 10 and 70 respectively.
-- Kalpna Bhargav

GATE2007-IT_34 top

Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping.
int i ;
program main ()
{
i = 10;
call f();
}
procedure f()
{
int i = 20;
call g ();
}
procedure g ()
{
print i;
}

Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then, x and y are

A)

x = 10, y = 10

B)

x = 20, y = 10

C)

x = 10, y = 20

D)

x = 20, y = 20

In static scoping, the scope of an identifier is determined by its location in the code, and since that doesn't change, the scope doesn't either. In dynamic scoping,
the scope is determined by the sequence of calls that has led to the use of an identifier, and since that can be different each time that use is reached, is dynamic.
so here.
option C must be the answer
as,
under static scoping:x=10(global i)
under dynamic scoping:y=20(according to the sequence of calls,i.e 20)

-- sumit kumar singh dixit

GATE2007-IT_35 top
Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the
following statements:
i.
ii.
iii.
iv.

Static scope facilitates w1 bindings.


Dynamic scope requires w2 bindings.
Early bindings w3 execution efficiency.
Late bindings w4 execution efficiency.

The right choices of wl, w2, w3 and w4 (in that order) are

A)

Early, late, decrease, increase

B)

Late, early, increase, decrease

C)

Late, early, decrease, increase

D)

Early, late, increase, decrease

Static scoping can do early binding (during compile time). Early binding increases efficiency.
Dynamic scoping requires late binding (during execution time). Late binding decreases efficiency as this binding needs to be done at runtime.
(but it increases flexibility)
So, answer is (D)
-- Arjun Suresh

GATE2006-IT_50 top
Which one of the choices given below would be printed when the following program is executed?
#include <stdio.h>
void swap (int *x, int *y)
{
static int *temp;
temp = x;
x = y;
y = temp;
}
void printab ()
{
static int i, a = -3, b = -6;
i = 0;
while (i <= 4)
{
if ((i++)%2 == 1) continue;
a = a + i;
b = b + i;
}
swap (&a, &b);
printf("a = %d, b = %d\n", a, b);
}
main()
{
printab();
printab();
}

A)

a = 0, b = 3
a = 0, b = 3

B)

a = 3, b = 0
a = 12, b = 9

C)

a = 3, b = 6
a = 3, b = 6

D)

a = 6, b = 3
a = 15, b = 12

First of all the swap function just swaps the pointers inside the function and has no effect on the variables being passed.
Inside printab, a and b are added odd integers from 1-5, i.e., 1+3+5 = 9. So, in first call to printab, a = -3 + 9 = 6 and b = -6 + 9 = 3.
Static variables have one memory throughout program run (initialized during program start) and they keep their values across function calls.
So, during second call to printab, a = 6 + 9 = 15, b = 3 + 9 = 12.
Hence (D) choice.
-- Arjun Suresh

GATE2006-IT_51 top
Which one of the choices given below would be printed when the following program is executed?
#include <stdio.h>
int a1[] = {6, 7, 8, 18, 34, 67};
int a2[] = {23, 56, 28, 29};
int a3[] = {-12, 27, -31};
int *x[] = {a1, a2, a3};
void print(int *a[])
{
printf("%d,", a[0][2]);
printf("%d,", *a[2]);
printf("%d,", *++a[0]);
printf("%d,", *(++a)[0]);
printf("%d\n", a[-1][+1]);
}
main()
{
print(x);
}

A)

8, -12, 7, 23, 8

B)

8, 8, 7, 23, 7

C)

-12, -12, 27, -31, 23

D)

-12, -12, 27, -31, 56

a = {a1, a2, a3};


printf("%d,", a[0][2]);
a[0] is a1. So, this will print a1[2] = 8;
printf("%d,", *a[2]);
a[2] is a3. So, this will print *a3 = a3[0] = -12 ([] has greater precedence than *)
printf("%d,", *++a[0]);
a[0] which is a1 is incremented. a1 is a pointer to int (base address of an integer array) and so increment means adding sizeof(int) and hence
a1 now points to the second element in the array. So, *++a[0] prints second element of a1 which is 7 and now a1 starts from 7.
printf("%d,", *(++a)[0]);
++a will increment a, which being an array of pointers (to int) will add sizeof (pointer) to a. So, a now contains {a2, a3} and a[0] will be a2 and
*a2 will be the first element in a2 which is 23

printf("%d\n", a[-1][+1]);
a[-1] will subtract a size of pointer from the base address of a. Normally this results in invalid memory access, but since we have incremented
a previously, a[-1] is valid and will point to a1. So, a[-1][+1] will be a1[1] which has the value 8.
(a1 was incremented in 3 rd printf and hence starts from 7 and not 6. +1 is same as 1, just given to create confusion)
-- Arjun Suresh

GATE2004-IT_60 top
Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is
terminated by a new line character.
#include <stdio.h>
void wrt_it (void);
int main (void)
{
printf("Enter Text");
printf ("\n");
wrt_ it();
printf ("\n");
return 0;
}
void wrt_it (void)
{
int c;
if (?1)
wrt_it();
?2
}

A)

?1 is getchar() ! = '\n'
?2 is getchar(c);

B)

?1 is (c = 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);

it should be option D

?1 is (c = getchar()) ! = '\n'
?2 is putchar(c);
-- sumit kumar singh dixit

GATE2004-IT_61 top
Consider the following C program:
#include <stdio.h>
typedef struct {
char *a;
char *b;
} t;
void f1 (t s);
void f2 (t *p);
main()
{
static t s = {"A", "B"};
printf ("%s %s\n", s.a, s.b);
f1(s);
printf ("%s %s\n", s.a, s.b);
f2(&s);
}
void f1 (t s)
{
s.a = "U";
s.b = "V";
printf ("%s %s\n", s.a, s.b);
return;
}
void f2(t *p)
{
p -> a = "V";
p -> b = "W";
printf("%s %s\n", p -> a, p -> b);
return;
}

What is the output generated by the program ?

A)

AB
UV
VW
VW

B)

AB
UV
AB
VW

C)

AB
UV
UV
VW

D)

AB
UV
VW
UV

first print A B
f1 is call by value the changes applciable only for local
from f1 U V is printed
back in main A B is printed
then in f2 V W is printed
hence answer is B
-- Sankaranarayanan P.N

if-else condition based question


What's the "condition" so that the following code
snippet prints both HelloWorld !
if "condition"
printf ("Hello");

top

else
printf ("World");

Condition can be printf("Hello") != 5


So code snippet becomes,
if(printf("Hello") != 5)
printf("Hello");
else
printf("World");
-- prathams

Char pointer to access an int

top

main()
{
int i =300;
char *ptr=&i;
*++ptr=2;
printf("%d",i);
}

Here, we are modifying an integer variable using a char pointer. The modification happens to the second byte (from the left of the starting
location) and it is changed to 2.
i.e., 300 will be stored as (lower address on left) on a big endian machine
0 * 224

0 * 216

1 * 28

1 * 28

0 * 216

44 * 20

and as
44 * 20

0 *224

on a little endian machine.


In both the cases using the char pointer we point to the starting byte. And we are incrementing the starting byte by 2.
Ao, after the increment we have
0 * 224

2 * 216

1 * 28

44 * 20

on big endian architectures and

44 * 20

2 * 28

0 * 216

0 *224

on little endian architectures.


The respective values are 131372 and 556.
(This is the most common method of checking if an architecture is little endian or big endian)
-- Arjun Suresh

Consider the following program


int i = 1;
int main()
{
int a[]= { 0,1, 2} ;
f(a[i], i);
printf("%d", a[i]);
}

top

void f(int x, int y)


{
y++;
x=5*i;
}

In above function f() uses " call by name" technique, what is the output printed?
a) 2

b) 10

c) 5

d) 1

Using a C style creates confusion for call by name. The scope of variables comes from the function where it is called (dynamic scoping) in call
by name.
y++; i becomes 2
x = 5*i; a[2] becomes 10.
So, 10 should be printed.
-- Arjun Suresh

What is the output, explain

top

int main(void) {
char p[20];
char *s = "Gate015";
int length = strlen(s);
int i=0;
for(i=0;i<length;i++)
p[i]=s[length-i];
printf("%s",p);
return 0;
}

printf("%s",p);
%s prints all characters from the start address given by p till the first occurrence of '\0'; But p[0] = s[length - 0] = '\0'; So, nothing will be
printed.
The code can be corrected by
for(i=0;i<length;i++)
p[i]=s[length-i-1];
-- Arjun Suresh

please explain the reason for the "weird" false condition coming out from for conditional
checking. top
In this program the TOTAL_ELEMENTS calculates properly when not used in for loop. And the first printf prints properly.
But why the 2nd printf is not working even if the condition in the loop is true. TOTAL_ELEMENTS returns 7.
And -1<7-2 i.e -1<5 is true. So what is wrong here?
#include<stdio.h>
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
printf("Total= %d\n", TOTAL_ELEMENTS);
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);
return 0;
}

Due to implicit type casting.


When we operate on two different data types, the smaller one is implicitly casted to bigger one. And between signed and unsigned, unsigned
is ranked higher.
http://gatecse.in/wiki/Chapter_2:_Data_Types_and_Operators_in_C#Implicit_Type_Conversion
In the definition of TOTAL_ELEMENTS, sizeof, returns unsigned int, and unsigned int divided by unsigned int returns unsigned int. When
compared with d, an integer, d is promoted to unsigned and becomes 2n-1, where n is the number of bits used for storing an int. So, the
comparison here returns false.
-- Arjun Suresh

GATE2015-2_15 top
Consider the following function written in the C programming langauge
void foo(char *a) {
if (*a && *a != ' ')
foo(a+1);
putchar(*a);
}
}

The output of the above function on input "ABCD EFGH" is


A.
B.
C.
D.

ABCD EFGH
ABCD
HGFE DCBA
DCBA

Ans D as priority of != is greater than that of && in C.


-- Vikrant Singh

GATE2015-1_11 top
The output of the following C program is_____________.
void f1 ( int a, int b) {
int c;
c = a; a = b;
b = c;
}
void f2 ( int * a, int * b) {
int c;
c = * a; *a = *b; *b = c;
}
int main () {
int a = 4, b = 5, c = 6;
f1 ( a, b);
f2 (&b, &c);
printf ("%d, c - a - b);
}

here f1 will not change any values bcz it is call by value but f2 is call by referance and it swaps values of b and c and changes are also
reflected in main function...so 5-6-4= -5 hence answer is -5
-- target gate

GATE2015-1_35 top
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.
int main () {
unsigned int x [4] [3] =
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
printf ("%u, %u, %u, x + 3, * (x + 3), * (x + 2) + 3);
}

A. 2036, 2036, 2036

B. 2012, 4, 2204
C. 2036, 10, 10
D. 2012, 4, 6

Address of x is 2000.
x being a 2 D array,
x + 3 = x + 3 * sizeof its inner dimension
= 2000 + 3 * 3 * 4 (as inner dimension is 3 integers of size 4)
= 2000 + 36 = 2036.
*(x+3) returns the value at address 2036. But since x is 2-D array, one * will just return the 1D array which is the starting address of it, which is
2036 only.
(x + 2) = 2000 + 2 * 3 * 4 = 2024
*(x + 2) + 3 = 2024 + 3 * 4 = 2036 (The * changes the data type from 2D to 1D and hence + 3 will add 3*4 and not 3 * 3 * 4)
So, A.
-- Arjun Suresh

GATE2015-3_7 top
Consider the following C program segment.
# include <stdio.h>
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
}

What will be printed by the program?

A.
B.
C.
D.

12
120400
1204
1034

p = s1 + 2;
p now points to the third element in s1.
*p = '0';
The third element in s1 is made 0. So, 1234 becomes 1204. C choice.
-- Arjun Suresh

GATE2015-3_26 top
Consider the following C program
#include<stdio.h>
int main()
{
static int a[] = {10, 20, 30, 40, 50};
static int *p[] = {a, a+3, a+4, a+1, a+2};
int **ptr = p;
ptr++;
printf("%d%d", ptr-p, **ptr);
}

The output of the program is _______.

for ptr-p =1, as pointer increment adds the size of the data type and pointer subtraction gives the number of objects that can be held in
between the two addresses = diff(addr1, addr2)/ sizeof(data type)
and for **ptr = *(a+3) = a[3] = 40
-- Anoop Sonkar

GATE2015-3_48 top
Consider the following C program:
#include<stdio.h>
int main()
{
int i, j, k = 0;
j=2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k-=--j;
for (i=0; i<5; i++)
{
switch(i+k)
{
case 1:
case 2: printf("\n%d", i+k);
case 3: printf("\n%d", i+k);
default: printf("\n%d", i+k);
}
}
return 0;
}

The number of times printf statement is executed is _______.

j=2 * 3 / 4 + 2.0 / 5 + 8 / 5;
j = (((2 * 3) / 4) + (2.0 / 5) ) + (8/5); //As associativity of +,* and / are from left to right and + has less precedence than * and /.
j = ((6/4) + 0.4) + 1); //2.0 is double value and hence 5 is implicitly typecast to double and we get 0.4. But 8 and 5 are integers and hence 8/5
gives 1 and not 1.6
j = (1 + 0.4) + 1; // 6/4 also gives 1 as both are integers
j = 1.4 + 1; //1 + 0.4 gives 1.4 as 1 will be implicitly typecast to 1.4
j = 2.4; // since j is integer when we assign 2.4 to it, it will be implicitly typecast to int.
So, j = 2;
k -= --j;
This makes j = 1 and k = -1.
The variables j and k have values 1 and -1 respectively before the for loop. Inside the for loop, the variable i is initialized to 0 and the loop
runs from 0 to 4.
,

, default case is executed, printf count = 1

, default case is executed, printf count = 2

, case 2, case 3 and default case is executed, printf count = 5

, case 2, case 3 and default case is executed, printf count = 8

, case 3 and default case is executed, printf count = 10

, loop exits and the control returns to main


Answer:

-- Shyam Singh

GATE2015-3_54 top
Consider the following C program

#include<stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x=10;
int main()
{
int x=1;
x += f1() + f2 () + f3() + f2();
printf("%d", x);
return 0;
}
int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}

The output of the program is ______.

The variable x is initialized to 1 . First and only call to f1() returns 26. First call to f2() returns 51. First and only call to f3() returns 100 .
Second call to f2() returns 52 (The value of local static variable x in f2() retains its previous value 51 and is incremented by 1 ).

x = 1 + 26 + 51 + 100 + 52 = 230
Answer: 230
-- Shyam Singh

What is the output ? int x=8; x-=--x-x--; printf("%d",x);

top

There is a rule called "sequence point rule" in C. We are not allowed to modify a memory location more than once or read and write the same
location (reading other than for the purpose of getting a value to write) between two sequence points. If we do this, the result is "Undefined".
Reference: http://gatecse.in/wiki/Undefined_Value
-- Arjun Suresh

DS top
GATE2013_44 top
Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.
MultiDequeue(Q){
m=k
while (Q is not empty) and (m > 0) {
Dequeue(Q)
m=m1
}
}

What is the worst case time complexity of a sequence of n queue operations on an initially empty
queue?
(A) (n)
(B) (n + k)
(C) (nk)
(D) (n 2 )

There are three possible operations on queue- Enqueue, Dequeue and MultiDequeue. MultiDequeue is calling Dequeue multiple times based
on a global variable k. Since, the queue is initially empty, whatever be the order of these operations, there cannot be more no. of Dequeue
operations than Enqueue operations. Hence, the total no. operations will be n only.
-- Arjun Suresh

GATE2008_62 top
The following C function takes a single-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 function completes execution?
struct node {
int value;
struct node *next;
};
void rearrange(struct node *list) {
struct node *p, *q;
int temp;
if (!list || !list -> next) return;
p = list; q = list -> next;
while(q) {
temp = p -> value; p->value = q -> value;
q->value = temp; p = q ->next;
q = p? p ->next : 0;
}
}

A.
B.
C.
D.

1, 2 ,3, 4, 5, 6, 7
2, 1, 4 ,3, 6, 5, 7
1, 3, 2, 5, 4, 7, 6
2, 3, 4, 5, 6, 7, 1

The loop is interchanging the adjacent elements of the list. But after each interchange, next interchange starts from the unchanged elements
only (due to p = q -> next;).
1st iteration 1 2 3 4 5 6 7
=> 2 1 3 4 5 6 7
2nd iteration 2 1 4 3 5 6 7
3rd iteration 2 1 4 3 6 5 7

p pointing to null q pointing to 7, as p is false hence q=p? p->next:0; will return q=0 ending the loop
-- Manali

GATE1991_01,ix

top

41673258
-- Keith Kr

GATE1991_01,viii top

This is straightforward. The nodes of the given tree are given in square boxes. The weights associated with the nodes are the numbers
example 15,9,10 etc.
Weighted path length = sigma(for(each node in the tree) (path length)*(weight of the node) ).
So answer (written in path_length*weight form) = 4*2 + 4*4 + 4*5 + 4*7 + 3*9 + 3*10 + 1*15 =144
-- arvchamp

GATE1991_03,vii top
03. Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:

Lets try something different when you read the word pop then delete the last pushed element and print it ..now delete the push word which we
have already executed ..now go on from left to right and do the same
-- Bhagirathi Nayak

GATE2002_2.12 top

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

A. log2 n
B. log 4 n
3

C. log3 n
D. log 3 n
2

Total number of nodes can be described by the recurrence


T(n) = T((n-1)/3)) + T(2(n-1)/3) + 1
T(1) = 1
As this makes maximum nodes go to one subtree and that is what we want to get the maximum height with a given number of nodes.
Now, the height of the tree will be
H(n) = H(2/3(n-1)) + 1
H(1) = 0
We can draw a recurrence tree and the cost at each level is 1, and the height will be log(3/2)n.
So, D option is the answer.
-- Arjun Suresh

GATE2003_6

top

Let T (n) be the number of different binary search trees on n distinct elements.
Then T (n) = nk=1 T (k 1)T (x), where x is

A.
B.
C.
D.

nk+1
nk
nk1
nk2

The summation is for each node, if that node happens to be the root. When a node is root, it will have (k-1) nodes on the left sub tree (k being
any number) and correspondingly (n-k) elements on the right sub tree. So, we can write recurrence T(k-1) * T(n-k) for the number of distinct
binary search trees, as the numbers on left and right sub trees form BSTs independent of each other. Hence, answer is B.
Knowing the direct formula can also help in getting the answer but is not recommended.
http://gatecse.in/wiki/Number_of_Binary_trees_possible_with_n_nodes
-- Arjun Suresh

GATE2003_19 top
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 in-order traversal sequence of the resultant tree?

A. 7 5 1 0 3 2 4 6 8 9
B. 0 2 4 3 1 6 5 9 8 7
C. 0 1 2 3 4 5 6 7 8 9

D. 9 8 6 4 2 3 0 1 5 7

In-order traversal returns the elements in sorted order.


Therefore, it's option C
-- Gate_15_isHere

GATE2006_13 top
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored
at X[i], 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
(A) log2 n
(B) n
(C) 2n + 1
(D) 2 n 1

should be D...
Since binary tree can be of any form, the worst case happens for right skewed binary tree. Now, root goes to index 1, its child goes to index 3,
its child goes to index 7 and so on the nth vertex goes to 2n - 1 th index of array.
-- Shaun Patel

GATE2004_3

top

A single array A[1 .. MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top 2
(top < 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. (top1 = MAXSIZE / 2) and (top2 = MAXSIZE / 2 + 1)


B. top1 + top2 = MAXSIZE
C. (top1 = MAXSIZE / 2) or (top2 = MAXSIZE)
D. top1 = top2 - 1

ans d)
Since the stacks are growing from opposite ends, initially top1 = 1 and top2 = MAXSIZE. Now, to make the space usage most efficient we
should allow one stack to use the maximum possible space as long as other stack doesn't need it. So, either of the stack can grow as long as
there is space on the array and hence the condition must be top1 = top2 - 1;
-- Aditi Dan

GATE2004_7

top

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?
I. 9679, 1989, 4199 hash to the same value
II. 1471, 6171 hash to the same value
III. All elements hash to the same value

IV. Each element hashes to a different value

A.
B.
C.
D.

I only
II only
I and II only
III or IV

option c is correct because the last digit of every digit given is equal in i and ii
-- Bhagirathi Nayak

GATE2004_36 top
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.
B.
C.
D.

rear node
front node
not possible with a single pointer
node next to front

The pointer points to the Rear node.


EnQueue: Insert newNode after Rear, and make Rear point to the newly inserted node:
//struct node *newNode;
newNode->next = rear->next;
rear->next = newNode;
rear=newNode;

DeQueue: Delete the Front node, and make the second node the front node.
//rear->next points to the front node.
//front->next points to the second node.
struct node* front;
front = rear->next;
rear->next = front->next;
free(front);

-- Pragy Agarwal

GATE2007_38 top
The following postfix expression with single digit operands is evaluated using a stack:
823^/23*+51*Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are

A.
B.
C.
D.

6, 1
5, 7
3, 2
1, 5

push 8 so stack is 8
push 2 so stack is 8 2
push 8 2 3
^ pop 3 and 2 perform opn 2^3 and push to stack. stack is 8 8
/ pop 8 and 8 perform 8/8 and push result to stack . stack is 1
push 2 stack is 1 2
push 3 stack is 1 2 3
* pop 3 and 2 perform by 2*3 and push . stack is 1 6

hence answer is A
-- Sankaranarayanan P.N

GATE2007_43 top
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 ofn?
A.
B.
C.
D.

3
4
5
6

Sum of degrees in tree = L + I * (n+1) - 1 = 10n + 50 (Each leaf node has degree 1 and all internal nodes have degree k+1, except root which
has degree k)
So, number of edges = 5n + 25 (Number of edges in a graph (hence applicable for tree also) is half the sum of degrees as each edge
contribute 2 to the sum of degrees)
In a tree with n nodes we have n-1 edges, so with 41+10 = 51 nodes, there must be 50 edges.
So, 5n + 25 = 50
5n = 25 => n = 5

-- Arjun Suresh

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

23

4
5

15

6
7
8

18

9
B.
0
1
2

12

13

4
5

6
7
8

18

C.
0
1
2

12

13

23

18

15

D.
0
1
2

2, 12

13, 3,
23

4
5

5, 15

6
7
8

18

C is the correct option ..directly from the definition of linear probing. In linear probing, when a hashed location is already filled, locations are

linearly probed until a free one is found.


http://courses.cs.washington.edu/courses/cse326/00wi/handouts/lecture16/sld015.htm
-- Bhagirathi Nayak

GATE2009_59,60 top
Consider a binary max-heap implemented using an array.
59. Which one of the following array represents a binary max-heap?
A.
B.
C.
D.
60.
A.
B.
C.
D.

{25, 12, 16, 13, 10, 8, 14}


{25, 14, 13, 16, 10, 8, 12}
{25, 14, 16, 13, 10, 8, 12}
{25, 14, 12, 13, 10, 8, 16}
What is the content of the array after two delete operations on the correct answer to the previous question?

{14, 13, 12, 10, 8}


{14, 12, 13, 8, 10}
{14, 13, 8, 12, 10}
{14, 13, 12, 8, 10}

Taking the given array as level order traversal, we can build binary tree.
(A) 13 comes as child of 12, which is not allowed in a binary max-heap
(B) 16 comes as child of 14 violating max-heap property
(C) is a valid binary max-heap as all children are smaller than their parent
(D) 16 comes as child of 12, violating max-heap property
60. During delete, the root element is removed, replaced with the last element and heap property is corrected by pushing the root downwards.
So, for first delete,
25 14 16 13 10 8 12 -> 12 14 16 13 10 8 -> 16 14 12 13 10 8 (the element not satisfying max-heap property is exchanged with the largest of its
children) (heap property satisfied)
Second delete:
16 14 12 13 10 8 -> 8 14 12 13 10 -> 14 8 12 13 10 -> 14 13 12 8 10 (heap property satisfied)
http://homepages.ius.edu/RWISMAN/C455/html/notes/Chapter6/heapify.htm

-- Arjun Suresh

GATE2005_5

top

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

as we our area of interest is only the 50 numbers so take An array of 50 numbers where A[0] corresponds to 51...A[49] corresponds to 100
then after reading an input just increment the counter in correct position as said above

-- Bhagirathi Nayak

GATE2005_33 top
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 in-order 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, 9, 15, 29

in order traversal of b binary search tree returns the element in sorted order - ascending (inorder is left parent then right. in a bst left is less
than parent and right is greater than parent). In this option 1 is the only sorted list. hence it is the only possiblity
-- Sankaranarayanan P.N

GATE2005_34 top
A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is: 10, 8, 5, 3, 2. Two new elements 1 and 7 are
inserted into 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
(B) 10, 8, 7, 2, 3, 1, 5
(C) 10, 8, 7, 1, 2, 3, 5

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

ans is D....whenever we insert an element in heap,it will always inserted in last level from left to right..so here we insert element 1 and 7 as a
child of node 5.then we perform heapify algorithm until we get the min/max heap..so here finally in above question we get the heap whose
level order traversal is 10,8,7,3,2,1,5
Initial heap:

After insert of 1

After insert of 7

-- neha pawar

GATE2013_7

top

Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of n
nodes?
(A) O(1 )
(B) O(log n )
(C) O(n )
(D) O(n log n )

Best case:O(log n) Worst case:O(n) worst case occurs when the bst is left or right skewed then we have to go through all the elements if the
element is to be placed to in the bottom most level
-- Bhagirathi Nayak

GATE1998_2.14 top

A [ LB1..............UB1,LB2.................UB2 ]
BA = Base address.
C = size of each element.
Row major order.
Loc(a[i][j]) = BA + [ (i-LB 1) (UB 2 - LB2 + 1) + (j - LB2) ] * C.
Column Major order

Loc(a[i][j]) = BA + [ (j-LB 2) (UB 1 - LB1 + 1) + (i - LB1) ] * C.


substituting the values. answer is A.

-- Gate Keeda

GATE1998_20 top
Draw the binary tree with node labels a, b, c, d, e, f and g for which the inorder and postorder traversals result in the following sequences:
Inorder: a f b c d g e
Postorder: a f c g e d b

binary tree
-- Anu

GATE2006_49 top
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) {
if (stack-empty(S2)) then
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 order on an empty queue Q. Letx and y be the number of push and
pop operations performed respectively in the process. Which one of the following is true for allm and n ?
(A) n + m x < 2n and 2m y 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

Answer is (a)
The order in which insert and delete operations are performed matters here.
The best case: Insert and delete operations are performed alternatively. In every delete operation, 2 pop and 1 push operations are
performed. So, total m+ n push (n push for insert() and m push for delete()) operations and 2m pop operations are performed.

The worst case: First n elements are inserted and then m elements are deleted. In first delete operation, n + 1 pop operations and n push
operation are performed. Other than first, in all delete operations, 1 pop operation is performed. So, total m + n pop operations and 2n push
operations are performed (n push for insert() and m push for delete())
-- Kalpna Bhargav

GATE2014-1_40 top
Consider a hash table with 9 slots. The hash function is h(k) = k mod 9. The collisions are resolved by chaining. The following 9 keys are
inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
(A) 3, 0, and 1
(B) 3, 3, and 3
(C) 4, 0, and 1
(D) 3, 0, and 2

So, Maximum & minimum chain lengths are 3 & 0 respectively.


Average chain length = (0+3+1+1+0+1+2+0+1)/9 = 1 .
So, Ans is A

-- Jayesh Malaviya

GATE2014-2_41 top
Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH
and POP instructions. Which one of the following statements is TRUE (with respect to this modified stack)?
(A) A queue cannot be implemented using this stack.
(B) A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.
(C) A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.
(D) A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

(C) is the answer. While ENQUEUE we REVERSE the stack, PUSH the element and then again REVERSE the stack. For DEQUE we simply
POP the element.
(Option (B) can be used to get the first element from the stack by doing a POP after REVERSE. But we have to restore the stack using
REVERSE (otherwise next POP won't work) which means ENQUEUE actually needs 3 instructions and not 2)
-- Arjun Suresh

GATE2014-3_40 top

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are
unfilled after the first 3 insertions?
(A)

(97 97 97)/100 3

(B)

(99 98 97)/100 3

(C) (97 96 95)/100 3


(D) (97 96 95/(3!

100 3 )

We have 100 slots each of which are picked with equal probability by the hash function (since hashing is uniform). So, to avoid first 3 slots, the
hash function has to pick from the remaining 97 slots. And repetition is allowed, since chaining is used- meaning a list of elements are stored
in a slot and not a single element.
So, required probability =

97
100

97
100

97
100

= (97 97 97)/100 3
-- Arjun Suresh

GATE1997_4.7

top

Implementing stack using priority queue require first element inserted in stack will be deleted at last, and to implement it using deletemin()
operation of queue will require first element inserted in queue must have highest priority.
So the keys must be in strictly decreasing order.
-- Suraj Kaushal

GATE1994_1.14 top
Which of the following permutations can be obtained in the output (in the same order) using a stack assuming that the input is the sequence
1, 2, 3, 4, 5 in that order?
(a) 3, 4, 5, 1, 2
(b) 3, 4, 5, 2, 1
(c) 1, 5, 2, 3, 4
(d) 5, 4, 3, 1, 2

push 1 push 2 push 3 pop 3 push 4 pop 4 push 5 pop 5 pop 2 pop 1 then o/p is 3,4,5,2,1 option b
-- Sankaranarayanan P.N

GATE1995_2.21 top

It will be B.
It will use a maximum 4 level stack.
-- Gate Keeda

GATE1995_6

top

There are only Five such binary trees.


One with C as root and left child as A and right child B.
Second with C as root, B as left child and A as again left child of B.
Third with C as root, B as left child and A as right child of B.
Fourth with C as root, B as right child and A as right child of B.
Fifth with C as root, B as right child and A as left child of B.
-- Gate Keeda

GATE1996_1.12 top

A.
i) and iv) are false.
http://en.wikipedia.org/wiki/List_(abstract_data_type)#Operations
-- Gate Keeda

GATE1996_1.13 top

C.
http://en.wikibooks.org/wiki/Data_Structures/Hash_Tables#Chaining
-- Gate Keeda

GATE1996_1.14 top

B.
a,b,c will become unbalanced with Balance factor as +2,+2,+2 respectively. Balance factor should be -1,0,+1.
Balance factor = Height(LST) - Height(RST).
-- Gate Keeda

GATE1996_1.15 top

C.
Left-->Right-->Root.
Ref: http://gateoverflow.in/2718/gate1996_1-14
-- Gate Keeda

GATE1996_2.11 top
The minimum number of interchanges needed to convert the array into a max-heap is
89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70
(a) 0
(b) 1
(c) 2
(d) 3

"The minimum number of interchanges needed to convert the array


89, 19, 40, 17, 12, 10, 2, 5, 7, 11, 6, 9, 70
into a heap with the maximum element at the root node is:"
This is the correction.
Answer: C.
Only element 70 violates the rule. Hence, it must be shifted to its proper position.
Step1: swap(10, 70)
Step2: swap(40, 70)
Hence, only 2 interchanges are required.
-- Gate Keeda

GATE1996_2.14 top

B.
Root will be 50. now insert one by one, greater to 50 in the right sub tree, lesser in left sub tree.
Or you can simply count the number looking at the i/p. less than 50 are 7. more than 50 are 4.
-- Gate Keeda

GATE2008-IT_71 top
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
I.
II.
III.
IV.

81, 537, 102, 439, 285, 376, 305


52, 97, 121, 195, 242, 381, 472
142, 248, 520, 386, 345, 270, 307
550, 149, 507, 395, 463, 402, 270

Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could
have encountered them in the search?

A)

II and III only

B)

I and III only

C)

III and IV only

D)

III only

Answer: D
I. no need to go from 285 to 376 as 273 is less than 285.
II. no need to go from 381 to 472 as 273 is less than 381.
IV. no need to go from 395 to 463 as 273 is less than 395.
-- Jon Snow

GATE2008-IT_72 top
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
I.
II.
III.
IV.

81, 537, 102, 439, 285, 376, 305


52, 97, 121, 195, 242, 381, 472
142, 248, 520, 386, 345, 270, 307
550, 149, 507, 395, 463, 402, 270

Which of the following statements is TRUE?

A)

I, II and IV are inorder sequences of three different BSTs

B)

I is a preorder sequence of some BST with 439 as the root

C)

II is an inorder sequence of some BST where 121 is the root and 52 is a leaf

D)

IV is a postorder sequence of some BST with 149 as the root

it should be C)
Inorder sequences are sorted. In preorder traversal root comes first and in postorder traversal root comes last.
-- Sneha Goel

GATE2008-IT_76 top
A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three respectively. The degree of a node is defined as the
number of its neighbours.
n3 can be expressed as

A)

n1 + n2 - 1

B)

n1 - 2

C)

[((n1 + n2)/2)]

D)

n2 - 1

assume the above tree so value of n1 is 3 n2 =1 n3 =1 check with options now u vil get option B as correct
-- Shreyans Dhankhar

GATE2008-IT_77 top
A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three respectively. The degree of a node is defined as the
number of its neighbours.
Starting with the above tree, while there remains a node v of degree two in the tree, add an edge between the two neighbours of v and then
remove v from the tree. How many edges will remain at the end of the process?

A)

2 * n1 - 3

B)

n2 + 2 * n1 - 2

C)

n3 - n2

D)

n2 + n1 - 2

from above tree we will get the tree below

now check with the options u vil get a as answer


-- Shreyans Dhankhar

GATE2007-IT_29 top
When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20, 40, 50, 70 80, 90 are traversed, not
necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to
the node containing the value 60?

A)

35

B)

64

C)

128

D)

5040

10, 20, 40, 50, 70 80, 90


In BST search we if we go from say 10 to 40 while searching for 60, we will never encounter 20. So, 10, 20, 40 and 50 visited, means they are
visited in order. Similarly, 90, 80 and 70 are visited in order. So, our required answer will be

(Since only one permutation is valid for both the smaller set of number as well as larger set of numbers)

7!
4!3!

= 35
-- Arjun Suresh

GATE2006-IT_44 top
Which of the following sequences of array elements forms a heap?

A)

{23, 17, 14, 6, 13, 10, 1, 12, 7, 5}

B)

{23, 17, 14, 6, 13, 10, 1, 5, 7, 12}

C)

{23, 17, 14, 7, 13, 10, 1, 5, 6, 12}

D)

{23, 17, 14, 7, 13, 10, 1, 12, 5, 7}

for a heap(max heap) parent should be greater than or equal to children. in a heap of [1..n] left child of ith node will be at 2*i th position and
right child will be at 2*i+1 position
so for given options we can verify it
option C seems to be following the property
-- Sankaranarayanan P.N

GATE2006-IT_45 top
Suppose that we have numbers between 1 and 100 in a binary search tree and want to search for the number 55. Which of the following
sequences CANNOT be the sequence of nodes examined?

A)

{10, 75, 64, 43, 60, 57, 55}

B)

{90, 12, 68, 34, 62, 45, 55}

C)

{9, 85, 47, 68, 43, 57, 55}

D)

{79, 14, 72, 56, 16, 53, 55}

in option C search sequence progress in ...47,68,43,..


at 47 we see that search key 55 is greater and it will be on right side of 47. so in further comparison a value less than 47 will not come
hence option c is wrong
-- Sankaranarayanan P.N

GATE2006-IT_71 top
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. The index of the parent
of element X [i], i 0, is
A.
B.
C.
D.

i / 2
(i - 1)/2
i/2
i/2 - 1

option D
left child of ith element will be at 2*i+1 and right child at 2(i+1)
-- Sankaranarayanan P.N

GATE2006-IT_73 top
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If the root node is at
level 0, the level of element X[i], i 0, is

A) log 2 i
B)
C)

log 2 (i +
1)
log 2 (i +
1)

D) log 2 i

Floor(log(i+1)) draw the tree and realise that the last element at each level is the best choice to arrive at a conclusion
-- Bhagirathi Nayak

GATE2004-IT_53 top
An array of integers of size n can be converted into a heap by adjusting the heaps rooted at each internal node of the complete binary tree
starting at the node (n - 1) /2, and doing this adjustment up to the root node (root node is at index 0) in the order (n - 1)/2, (n - 3)/ 2, ....., 0.
The time required to construct a heap in this manner is

A)

O(log n)

B)

O(n)

C)

O (n log log n)

D)

O(n log n)

it shud be O(n).
-- Sneha Goel

GATE2004-IT_54 top
Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD, respectively?

A)

B)

C)

D)

inorder traversal is left node right


preorder is node left right

answer: D
-- Sankaranarayanan P.N

The number of different insertion sequences on the numbers

top

The number of different insertion sequences on numbers {1, 14, 26, 44, 60, 71} on an initially empty hash table H of size 6 and a hash function
x%6 with linear probing scheme for collision resolution such that the end hash table should look like 60, 1, 14, 26, 44, 71 (The indices of
numbers from left to right are 0 to 5) are ________

14, 26 and 44 mod 6 = 2 and hence in any input sequence they must come in sequence (otherwise their sequence changes in the end result).
Now, we have 6 places to fill these 3 numbers and this can be done in 6P3 = 120 ways. There are 3! = 6 permutations possible for 14, 26 and
44 and out of these only 1 is valid. So, valid permutations for these 3 numbers = 120/6 = 20.
Now, we have 3 places to fill in 3 remaining numbers. This can be done in 3! = 6 ways. So, total ways = 20*6 = 120.
-- Arjun Suresh

GATE2005-IT_12 top
The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the right subtree of the root contains p nodes.
The first number to be inserted in the tree must be
A.
B.
C.
D.

p
p+1
n-p
n-p+1

from 1,...n elements p elements are on the right. so root or first inserted will be at n-p
-- Sankaranarayanan P.N

GATE2005-IT_13 top
A function f defined on stacks of integers satisfies the following properties. f() = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and
integers i.
If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?

A)

B)

C)

D)

I hope this helps!

-- Shridhar

GATE2005-IT_16 top
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and the hash function used is key
% 10. If the values 43, 165, 62, 123, 142 are inserted in the table, in what location would the key value 142 be inserted?

A)

B)

C)

D)

43 in loc 3
165 in loc 5
62 in loc 2
123 in loc 4 ( collission and next free space)
142 in loc 6 (collision in 2, and 3,4,5 already occupied)
hence answer D
-- Sankaranarayanan P.N

GATE2005-IT_50 top
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is
h > 0, then the minimum number of nodes in the tree is

A)

2h - 1

B)

2h - 1 + 1

C)

2h - 1

D)

2h

it should be B)
-- Sneha Goel

GATE2005-IT_54 top
The following C function takes a singly-linked list of integers as a parameter and rearranges the elements of the list. The list is represented as
pointer to a structure. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of
the list after the function completes execution?
struct node {int value; struct node *next;);
void rearrange (struct node *list) {
struct node *p, *q;
int temp;
if (!list || !list -> next) return;
p = list; q = list -> next;
while (q) {
temp = p -> value;
p -> value = q -> value;
q -> value = temp;
p = q -> next;
q = p ? p -> next : 0;
}
}

A)

1, 2, 3, 4, 5, 6, 7

B)

2, 1, 4, 3, 6, 5, 7

C)

1, 3, 2, 5, 4, 7, 6

D)

2, 3, 4, 5, 6, 7, 1

i think it's B) 2 1 4 3 6 5 7:
as,
p and q are swapping each other.where q is p->next all the time.
-- sumit kumar singh dixit

GATE2005-IT_55 top
A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-order and the values in each node printed out,

the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in post-order, the sequence obtained would be

A)

8, 7, 6, 5, 4, 3, 2, 1

B)

1, 2, 3, 4, 8, 7, 6, 5

C)

2, 1, 4, 3, 6, 7, 8, 5

D)

2, 1, 4, 3, 7, 8, 6, 5

Answer is D.

-- Gate Keeda

GATE2015-2_17 top
Consider a complete binary tree where the left and right subtrees of the root are max-heaps. The lower bound for the number of operations to
convert the tree to a heap is

A.
B.
C.
D.

(log n)
(n)
(n log n)
(n 2 )

Ans A
Max-Heapify(root)
-- Vikrant Singh

GATE2015-1_10 top
Which of the following is/are correct in order traversal sequence(s) of binary search tree(s)?
I.
II.
III.
IV.

3, 5, 7, 8, 15, 19, 25
5, 8, 9, 12, 10, 15, 25
2, 7, 10, 8, 14, 16, 20
4, 6, 7, 9, 18, 20, 25

A.
B.
C.
D.

I and IV only
II and III only
II and IV only
II only

option A is right .. chek for left root right rule


-- Anoop Sonkar

GATE2015-2_38 top
Consider the C program below
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode) {
case -1: size = val; break;
case 0: if (stkTop < size ) A[stkTop++]=val; break;
default: if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20]; A=B; stkTop = -1;
stkFunc (-1, 10);
stkFunc (0, 5);
stkFunc (0, 10);
printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}

The value printed by the above program is ________.

Answer: 15
The code is pushing 5 and 10 on stack and then popping the top two elements and printing their sum.
Refer here: http://ideone.com/kIUdQT
-- Jon Snow

GATE2015-1_23 top
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
A.
B.
C.
D.

(log n) for both insertion and deletion


(n) for both insertion and deletion
(n) for insertion and (log n) for deletion
(log n) for insertion and (n) for deletion

option b, both happens when the BST is skewed.


-- GATERush

GATE2015-1_25 top
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 5
are
A.
B.
C.
D.

63 and 6, respectively
64 and 5, respectively
32 and 6, respectively
31 and 5, respectively

option A is correct because height 5 means level 6 so maximum node = 2^l -1 =2^6 -1=63
and for minimum, at each level only single node so total 6
-- Anoop Sonkar

GATE2015-1_32 top
Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4.
Array index

Value

40

30

20

10

15

16

17

Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
A.
B.
C.
D.

40, 30, 20, 10, 15, 16, 17, 8, 4, 35


40, 35, 20, 10, 30, 16, 17, 8, 4, 15
40, 30, 20, 10, 35, 16, 17, 8, 4, 15
40, 35, 20, 10, 15, 16, 17, 8, 4, 30

Heap is complete binary tree. To insert a new element, we put it at the end of the tree and move up towards root till heap property is satisfied.
Here, 35 comes as child of 15, with the path 40-30-15-35. So, we swap 15, 35 and then 30, 35 to get the new path 40-35-30-15. So, new
heap will be 40 35 20 10 30 16 17 8 4 15.
-- Arjun Suresh

GATE2015-3_12 top
The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is

A.
B.
C.
D.

284
213
142
71

we have to keep symbol into stack and when we get two operands followed by operator ..we will apply operator on last two operands

symbol

stack

10

10

(keep in stack)

10 5

(keep in stack)

10 5 + = 10+5 = 15 ( apply operator on last 2 operands)

60

15 60

(keep in stack)

15 60 6

(keep in stack)

15 60 6 / = 15 10

( apply operator on last 2 operands)

15 10 * = 150

( apply operator on last 2 operands)

150 8

(Keep in stack)

150 8 - = 150 - 8 = 142 (apply operator on last 2 operands)

So answer is 142

-- Praveen Saini

GATE2015-3_13 top
While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest
level is

A.
B.
C.
D.

65
67
69
83

option B.... 67 because it is on level 3 and 83 is on level2


-- Anoop Sonkar

GATE2015-3_17 top
Given that hash table T with 25 slots that stores 2000 elements, the load factora for T is _________.

load factor =total no element/total no of slots 2000/25 =80


-- Anoop Sonkar

GATE2015-3_19 top
Consider the following array of elements.

89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100


The minimum number of interchanges needed to convert it into a max-heap is

A.
B.
C.
D.

4
5
2
3

first interchange 15-100


2nd 50-100
3rd 89-100
so total interchange 3 so option D is correct.
-- Anoop Sonkar

GATE2015-3_25 top
Consider a binary tree T that has 200 leaf nodes. Then the number of nodes in T that have exactly two children are ______.

Let number of nodes with exactly two children be x, and with exactly one children be y.

Total degree = 200 + 3x + 2y - 1 (As all nodes with 2 children have degree 3 except the root)
No. of nodes = x + y + 200
No. of edges = Total degree/2 = (200 + 3x + 2y - 1)/2
No. of edges in a tree = No. of nodes - 1
So, (200 + 3x + 2y -1) = 2x +2y + 400 - 2
x = 199
-- Arjun Suresh

Is it correct?

top

void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
i = delete(Q);
f(Q);
push(s, i);
}
}

Let size of queue n and it is full filled.


Then function f(queue Q) will be called n times and every function call having a local variable i. (Untill last function call i.e. queue is empty all i
variable should preserved).
So total n function call we need n local variable i.

Additional storage is not constant. It is order of n.


-- Digvijay Pandey

simple uniform hashing

top

why in open address hash table with load factor =n/m<1, the expected number of probes in an unsuccessful search is at most 1/(1-)
assuming uniform hashing ?

Expected number of probes

E[X] = 1 P (1) + 2 P (2) +


Here, P (x) denotes the probability of having x number of probes in an unsuccessful search (In probing a search fails as soon as we reach an
empty slot). Probability of a probe going to an occupied slot is = n and this reduces for consecutive probes as both n and m decreases by
m
1 each. Still, we can say probability of having at least i probes, say Q(i) < (i1) as (i 1) probes must be going to occupied slots.
Now, we can try to put this Q term inside the expectation formula. Probability of having exactly i probes is equal to probability of having at
least (i) probes minus probability of having at least i + 1 probes. i.e., P (i) = Q(i) Q(i + 1)
Thus,

E[X] = Q(1) Q(2) + 2Q(2) 2Q(3) +


= Q(1) + Q(2) +
< 0 + 1 +
1
= 1

-- Arjun Suresh

GATE 1989

top

A hash table with ten buckets with one slot per bucket is shown in the following figure with the symbols s1 to s7 entered into it using some hashing function with
linear probing.The worst case number of comparison required when the symbol being searched is not in the table is

No of comparison in worst case if an element not in hash table is size of largest cluster +1..
Size of largest cluster is 4 (s6, s3, s7, s1)
No ofcomparison is 4 + 1 = 5
-- Digvijay Pandey

Brought to you by GATE Overflow


http://gateoverflow.in/

You might also like