GATE
COMPUTER SCIENCE & INFORMATION TECHOLOGY
501++ Previous questions along with extensively TESTED problems/solutions [1...
INTRODUCTION
The GATE examination is conducted by the IITs and IISc for entrance to
postgraduate studies. It is also used ...
CONTENTS
CHAPTER 0
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
CHAPTER 7
CHAPTER 8
CHAPTER 9
CHAPTER 10
CH...
DETAILED CONTENTS
CHAPTER 0 INTRODUCTION
CHAPTER 1

DISCRETE MATHEMATICS
CHAPTER 1.1
CHAPTER 1.2
CHAPTER 1.3
CHAPTER 1.4
C...
CHAPTER 4.4

CHAPTER 4.5

CHAPTER 4.5
CHAPTER 5

RELATIONAL ALGEBRA
AND RELATIONAL
CALCULUS
TRANSACTION
PROCESSING AND
CON...
CHAPTER 8

DATA
STRUCTURES
CHAPTER 8.1
CHAPTER 8.2

GRAPHS

CHAPTER 8.7

HASHING

CHAPTER 9.1

CONCEPTS

CHAPTER 9.2

PROG...
CHAPTER 11

COMPUTER ORGANISATION
CHAPTER
11.1

MEMORY
ORGANISATION

CHAPTER
11.2

INSTRUCTION
PIPELING

CHAPTER INPTUT/OU...
CHAPTER 1
MATHEMATICS

Page 8 of 345
1.1 MATHEMATICAL
LOGIC
[GATE CSE 2013—MATHEMATICAL LOGIC]
QUESTION 1.1.1
What is the logical translation of the following ...
The statement F!P is !FV!P = !(F&P) matches (D) only.
Answer is (D).

**********
[GATE CSE 2013—PREDICATE CALCULUS]
QUEST...
n Boolean variables?

(A) n2 (B) 2n (C) 2**2n (D) 2**n2

Answer: (C )

Explanation: The domain has 2n groups of variables ...
1.2 COMBINATORICS
[QUESTION FROM GATE CSE 2013 COMBINATORICS]
QUESTION 1.2.1
Consider an undirected random graph of eight ...
Connected(x) be a predicate which denotes that x is connected. Which of
the following first order logic sentences DOES NOT...
1.3 GRAPH THEORY
[GATE CSE 2013—GRAPH THEORY]
QUESTION 1.3.1
Consider an undirected random graph of eight vertices. The pr...
[GATE C SE 2013—GRAPH THEORY]
QUESTION 1.3.2
Which of the following statements are TRUE for undirected graphs?
P Number of...
P is true and Q is true.
For every edge degree goes up by 2. So the sum of degrees is always even.
So to ensure an even nu...
SOLUTION
We will use the method of elimination.
(1) Consider the graph.

e

e’

The line graph is given below

The line gr...
********

QUESTION 1.3.4
. [DISCRETE MATHS]
Let Graph(x) be a predicate which denotes that x is a graph. Let
Connected(x) ...
1.4 SET THEORY AND
ALGEBRA
[GATE 2013]
QUESTION 1.4.1
A binary operation ⊕on aq set of integers is defined as 𝑥 ⊕ 𝑦 = 𝑥 2 ...
********

QUESTION 1.4.2[DISCRETE MATHEMATICS]
Let S be a set of n elements. The number of ordered pairs in the largest
an...
1.5 LINEAR ALGEBRA
[QUESTION GATE 2008 EIGENVALUES]
QUESTION 1.5.1
How many of the following matrices have an eigenvalue?
...
1.6 PROBABILITy
[GATE 2013 PROBABILITY]
QUESTION 1.6.1
Suppose p is the number of cars per minute passing through a certai...
1.7 NUMERICAL METHODS
[GATE CSE 2013]
QUESTION

1.7.1

The smallest integer that can be represented by an 8-bit number in ...
1
(A) 1
1

𝑥(𝑥 + 1)
𝑦(𝑦 + 1)
𝑧(𝑧 + 1)

0
(C) 0
1

𝑥− 𝑦
𝑦− 𝑧
𝑧

1
(B) 1
1

𝑥2 − 𝑦2
𝑦2 − 𝑧2
𝑧2

𝑥+1
𝑦+1
𝑧+1

𝑥2 + 1
𝑦2 + 1
𝑧...
QUESTION 1.7.3
Which one of the following functions is continuous at x=3?

{

2
𝑥−1

(A) f(x) =

(C) f(x)=

{

𝑖𝑓 𝑥 = 3
𝑖𝑓...
f(x)

0

The value of

0.09
3
0

0.36

0,81

1.44

2.25

3.24

4.41

5.76

𝑓 𝑥 𝑑𝑥 𝑐𝑜𝑚𝑝𝑢𝑡𝑒𝑑 𝑢𝑠𝑖𝑛𝑔 𝑡𝑕𝑒 𝑡𝑟𝑎𝑝𝑒𝑧𝑜𝑖𝑑𝑎𝑙 𝑟𝑢𝑙𝑒 𝑖𝑠

...
(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.
Answer:...
Iteration 3. x(3) = 1.7/2 + 9/(8*1.7)=.85 + 9/16.8=.85 +.82=1.67
Iteration 4. x(4) = 1.67/2 + 9/(8*1.67)=approx.835 + 27/4...
1.8 CALCULUS
[GATE CSE 2011 Q21 MATHEMATICS]
QUESTION 1.8.1
Given i= −1, what will be the evaluation of the definite integ...
CHAPTER 2
THEORY
OF
COMPUTATION

Page 30 of 345
2.1 FINITE AUTOMATA
AND
REGULAR SETS

GATE CSE QUESTIONS IN THE THEORY OF COMPUTATION]
QUESTION 2.1.1
Consider the languag...
Consider the DFA given below

1

1
0

0
0,1

Which of the following are FALSE?
1.
2.
3.
4.

Complement of L(A) is context ...
The set accepted is (11*0 +0)(0+1)*=(11*0+0)(0+1)*(ε+ anything)
=(11*0+0)(0+1)*(0*1*)
So (2) is correct.
The examiner guar...
QUESTION 2.1.5
Is the language generated by the grammar G regular? If so, give a regular expression for
it, else prove oth...
From an examination of the three regular expressions t contains a 0 wheras the other two
do not. So L(t) cannot be a subse...
Let L be the language of all binary strings in which the third symbol from the right is a 1. Give
a non-deterministic fini...
********

QUESTION 2.1.11
Q2(xx) In which of the cases stated below is the following statement true?
"For every nondetermi...
********
QUESTION 2.1.12
Given that a language L1 is regular and that the language L1 U L2 is regular, is te
language L2 a...
SOLUTION 2.1.16
ANSWER I
(iv)

This says even number of 0s plus odd no of 0s i.e. 0*

(ii) This says evenumbr of 0s
(iii) ...
q12

q02

q00

q02

q12

q00

qij means i gives extra number of a's and j gives extra number of b's
********
QUESTION 2.1....
********
QUESTION 2.1.21
Which of the following sets can be recognized by a deterministic finite automaton?
(a) The number...
(d) Multi-tape Turing machines are equivalent to single-tape Turing machines.
SOLUTION Q2.1.21
Q1.11 ANSWER-------------(B...
*********
QUESTION 2.1.24
Which of the following statements is false?
(a) Every finite subset of a non-regular set is regu...
q3

q1

q2

q4

q3

q4
********

QUESTION 2.1.26
CS6 (a) Given that A is regular and (AUB) is regular, does it follow that...
QUESTION 2.1.28
Construct a minimal finite state machine that accepts the language over{0,1}, of all strings
that contain ...
QUESTION 2.1.30
Given an arbitrary non-deterministic finite automaton(NFA) with N states, the maximum
number of states in ...
CS2.6 Consider the following languages:
L1 = {ww|w in {q,b}*}
L2 = {wwR| w in {a,b}*, wR is the reverse of w}
:3 = { 0^2i|...
be considered to optionally start with a 0, contain sequences of 0's separted by a 1 or we
can consider any string in (0+1...
(a* +b* +c*)=(a+b+c+other strings)*=(a+b+c)*
for (B) we have the standard identity (r*s*)*=(r+s)*
for (D) we have (a*b*+c*...
(b) Modify the transition diagram obtained in part (a) to obtain a transition diagram for a
maachie that recognizes (L1L2)...
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 str...
1011A101
1011A111

1101A001
1101A011
1101A101
1101A111

1111A001
1111A010
1111A101
1111A111
The first fout are aceepted. I...
Let the language accepted by M be L. Let L1 be the language accepted by the NFA M1,
obtained by changing the accepting sta...
Which of the following is TRUE?
(A) Every subset of a regular set is regular.
(B) Every finite subset of a non-regular set...
2.2 CFLS
[GATE CSE 2013—CONTEXT FREE LANGUAGES]
QUESTION 2.2.1
Consider the following languages
𝐿1 = {𝑜 𝑝 1 𝑝 0 𝑟 |𝑝, 𝑞, 𝑟...
Answer is (D).

********
QUESTION 2.2.2

A context free grammar is ambiguous is:
(A) The grammar contains useless non-term...
If we are to consider all semantically correct programs then the class of context sensitive
languages are sufficient to de...
B = { <p,q,r>| p in F; p, r in Q}
C = { <p,q,r>| p, q, r in Q; there exists s in §* such that f(p,s) is in F)}
D = { <p,q,...
SOLUTION Q2.2.7
ANSWER---CEIL(LOG2(L))+1
If we have l as a power of 2 then the derivation tree with the leaves removed is ...
Hari :

noun

Obtain a parse-tree for the given sentence.
SOLUTION 2.2.8
The sentence is "Ram sold the pen to Hari"
The le...
G: S------------->aB
B-------------->bC
C------------->xB
C---------->c
SOLUTION 2.2.9
The given grammar is a right linear...
SOLUTION 2.2.11
ANSWER (C)
Consider strings of lenght 1 and 2 to find out the correct formula by elimination.
********
QUE...
The above grammar is
(a) context-free

(b) regular

(c) context-sensitive

(d) LR(k)

SOLUTION 2.2.13
ANSWER-------(C)
The...
SOLUTION Q2.2.15
ANSWER--------------(D)
The first three are three standard cfls which are not regular, by the pumping lem...
ANSWER--------------(B)
(A) is excluded as init contains 0011
(C) is excluded as init contains 00000
(D) is allowed as ini...
S--------->ABAC|ABC|BAC|BC|AC|AAC|C
A--------->aA|A
B--------->bB|B
C-------->D
After the elimination of the unit producti...
for (3) add{(q1,aa),(q2,e)}
for (4) add {(q1,bb),(q2,e))
********
QUESTION 2.2.20
Which of the following languages over {a...
P------------->epsilon
Q----------->cQd
Q--------->epsilon
R---------->dRe
R---------->epsilon
where S,P,Q,R are non-termi...
********

QUESTION 2.2.22
Let M = ({q0,q1},{0,1},{z0,x},f,z0,0) be a pushdown automaton where f is given by
f(q0,1.z0) = {...
4. In R6, one more 0 is rejected, and the PDA ends up in state q0.
5. R2 allows the stack to be emptied allowing the PDA t...
So the set generated is L={an bm|n.m>1, |n-m|>1]

Q(b). The new grammar is
P1: S1--------------->aS1 ba S1b
P2: S1--------...
QUESTION 2.2.26
Q1.6 Let Ld be the set of all languages accepted by a PDA by final state and Le be the set of
all language...
SOLUTION 2.2.28
ANSWER--------(B)
L is (00)+ as the 0's always occur in pairs.
(D) is not correct as the grammar is a cfg....
The nodes denote the states while the edges denote the moves of the pda. The edge labels
are of the for d, s/s' where d is...
Q(b) q0 and q1 will be push states where for every 0 in the input we nondeterministially
push one or two 0's onto the stac...
QUESTION 2.2.32
The language accepted by a Pushdown Automaton in which the stack is limited to 10 items
is best described ...
automata and this excludes (C). The concatentation of any two strings of balanced
parenthesis is a balanced parenthesis st...
(D) {w|Nb(w) =3k, k in {0,1,2,---}}
SOLUTION 2.2.35
ANSWER------(C)
S----->b+ by the first set of rules S--->bS|S, this el...
QUESTION 2.2.37
[THEORY OF COMPUTATION]
The language L = { 0i21j |I>=0} over the alphabet {0, 1, 2} is
(A) not recursive
(...
2.3 TURING MACHINES
AND
R.E. SETS
[GATE CSE 2013 TURING MACHINES & UNDECIDABILITY]
QUESTION 2.3.1
Which one of the followi...
TURING RECOGNISABLE LANGUAGES

TURING DECIDABLE
LANGUAGES
NDTM=DTM
RECURSIVE SETS-CLOSED
UNDER UNIO, INTERSECTION
AND COMP...
The recursive languages are a superset of the cfls. Only we are ignoring epsilon which
cannot be in any csl or recursive s...
********
QU3STION 2.3.6
Which of the following three statements are true? Prove your answer.
(i) The union of two recursiv...
We just run a turing machine designed to compute pi to better and better approximations.
If it happens to yield a x-block ...
QUESTION 2.3.9
ANSWER-------------(B) AND (C)
The deterministic and nondeterministic models of the pushdown automata are n...
(c) What key property relates the behaviour of M on w to the behaviour of M' on x?
SOLUTION 2.3.11
(a) M operates with inp...
(a) L is recursive
(b) L is recursively enumerable but not recursive
(c) L is not recursively enumerable
(d) Whether L is ...
Consider two languages L1 and L2 each on the alphabet X. Let f:X--->X be a polynomial
time computable bijection such that ...
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...
Here <M, w, i> is a triplet, whose first component, M is an encoding of a Turing Machine,
second component, w, is a string...
2.4 UNDECIDABILITY
[GATE CSE 2013—UNDECIDABILITY]
QUESTION 2.4.1
Which of the following is/are undecidable?
1.
2.
3.
4.

G...
Answer is (D).

********
QUESTION 2.4.2
Which of the following problems are undecidable?:
(A) Membership problem in contex...
Q3(vii) ANSWER----(B) AND (D)
No nontrivial problem is decidable for an arbitary turing machine. Given an arbitrary
turing...
{aj bj cm|j,m>1} but the latter cannot.
********
QUESTION 2.4.5
Which of the following statements is false?
(A) The Haltin...
(A) the set of all strings is a regular set which is countably infinite. We can enumerate all
strings in increasing order ...
(P2) Does a given context free grammar generate an infinite number of strings.
Which of the following is true?
A. Both (P1...
*********

QUESTION 2.4.9
THEORY OF COMPUTATION] [TOPIC:UNDECIDABILITY]
Which of the following problems is undecidable?
(A...
CHAPTER 3
COMPILER
DESIGN

Page 98 of 345
3.1 LEXICAL ANALYSIS

Page 99 of 345
3.2 PARSING
[QUESTIONS ON LANGUAGE PROCESSORS—PARSING]
QUESTION 3.2.1
What is the maximum number of reduce moves that can ...
So by elimination the answer is (B), granting the examiner one more right to his typographical errors and
making choice (B...
No conflicts arise and the states can be merged.
Answer is (D).

********
Question 2.2.3
. [LANGUAGE PROCESSORS]
Which of ...
3.3 SYNTAX DIRECTED
TRANSLATION

Page 103 of 345
3.4 CODE GENERATION
AND
CODE OPTIMISATION
[GATE CSE 2013—CODE OPTIMISATION]
QUESTION 3.4.1
Common data for two questions
T...
d = d * d,
e = e * e,
}
Question 1.
Suppose the instruction set architecture of the
processor has only two registers. The ...
x= c * c;
if(x > a){
d = c * a;

USE c FROM MEMORY,

e = c + a;

LOAD INTO R2

y = a * a;
}else {
d = c *a;

USE c FROM ME...
CHAPTER 4
DBMS

Page 107 of 345
4.1 ER-DIAGRAMS

Page 108 of 345
4.2 FUNCTIONAL DEPENDENCIES
AND
NORMALISATION
[GATE CSE 2013—FUNCTIONAL DEPENDENCIES]
QUESTION 4.2.1
Statement for Linked ...
ANSWER FOR QUESTION 1IS (B)
ANSWER FOR QUESTION 2 IS (A)
QUESTION 4.2.1 WITH KEY AND SOLUTION
SOLUTION
For candidate key s...
4.3 SQL
[QUESTION GATE CSE 2011 SQL]
QUESTION 4.3.1
A database table y name Loan_Records is given below.
Borrower
Bank_Man...
4.4 RELATIONAL ALGEBRA
AND
RELATIONAL CALCULUS

Page 112 of 345
4.5 TRANSACTION
PROCESSING AND
CONCURRENCY CONTROL

Page 113 of 345
4.6 FILE STRUCTURES
AND
INDEXING
[GATE CSE 2013—INDEXING]
QUESTION 4.6.1
An index is clustered, if
(A) It is on a set of f...
CHAPTER 5
COMPUTER
NETWORKS

Page 115 of 345
5.1 FUNDAMENTALS OF CNW
[GATE CSE 2013 COMPUTER NETWORKS]
QUESTION 5.1.1
Assume that source S and destination D are connec...
(A) Encryption X ‘is private key followed by Y’s private key. Decryption X’s
public key followed by Y’s public key.
(B) En...
5.2 LAN
[GATE CSE 2013---LAN]
QUESTION 5.2.1
Determine the maximum length of the cable (in km) for transmitting data at a
...
The maximum length of the cable is thus 4/2 =2km.
Answer is (B).
********

Page 119 of 345
5.3 TCP/IP
[QUESTION FROM GATE CSE 2013]
QUESTION 5.3.1
The transport layer protocols used for real time multimedia file t...
5.4 APPLICATION LAYER
AND
ROUTING

Page 121 of 345
CHAPTER 6
OPERATING
SYSTEMS

Page 122 of 345
6.1 PROCESS MANAGEMENT
[QUESTIONS ON PROCESS MANAGEMENT]
[GATE C SE 2013]
QUESTION 6.1.1
A scheduling algorithm assigns pr...
By elimination the answer must be (B).
********

Page 124 of 345
6.2 DEADLOCK

Page 125 of 345
6.3 MEMORY MANAGEMENT

Page 126 of 345
6.4 FILE SYSTEM
AND
DEVICE MANAGEMENT

Page 127 of 345
CHAPTER 7
DAA

Page 128 of 345
7.1 ALGORITHM ANALYSIS
AND
ASYMPTOTIC NOTATION
QUESTION 7.1.1
.[DAA: ANALYSIS]
Consider the following segment of C –code:
...
1<=2,2<=2 TOTAL=2
A,B,D
3
1<=3,2<=3,4<=3 TOTAL=3
B,A
4
1<=4,2<=4,4<=4,8<=4 TOTAL=4
A,D excluding termination test
8
1<=8,2...
7.2 DIVIDE AND CONQUER
QUESTION 7.2.1
. [DAA: SORTING]

Which of the following sorting algorithms has the lowest worst-cas...
7.3 GREEDY METHOD

Page 132 of 345
7.4 DYNAMIC PROGRAMMING

Page 133 of 345
7.5 SEARCH,TRAVERSAL,
BRANCH & BOUND TECHNIQUES

Page 134 of 345
7.6 P=NP?

Page 135 of 345
CHAPTER 8
DATA
STRUCTURES

Page 136 of 345
8.1 ARRAYS

Page 137 of 345
8.2 STACKS AND QUEUES

Page 138 of 345
8.3 LINKED LISTS

Page 139 of 345
8.4 TREES
[GATE CSE DATA STRUCTURES]
QUESTION 8.4.1
Which one of the following is the tightest upper bound that represents...
[GATE CSE 2013—TREE TRAVERSAL]
QUESTION 8.4.2
The postorder traversal sequence of a binary search tree is 30, 20, 10, 15, ...
to leaf path. The maximum number of nodes in a binary tree of height h
is:

(A) 2h – 1 (B) 2h-1 -1 (C) 2h+1-1 (D) 2h+1
Ans...
*******

Page 143 of 345
8.5 GRAPHS

Page 144 of 345
8.6 HASHING

Page 145 of 345
CHAPTER 9
PROGRAMMING
LANGUAGES

Page 146 of 345
9.1 PROGRAMMING
LANGUAGE CONCEPTS
[GATE CSE 2013—PARAMETER PASSING CONVENTIONS]
QUESTION 9.1.1
What is the return value of...
The value returned 6x7x8x9=3024.
Answer is (A).
********

Page 148 of 345
CHAPTER 10
DIGITAL LOGIC

Page 149 of 345
10.1 BOOLEAN ALGEBRA
AND
K-MAPS
[GATE CSE 2013 BOOLEAN ALGEBRA]
QUESTION 10.1.1
Which one of the following expressions doe...
10.2 COMBINATONAL
CIRCUITS

Page 151 of 345
10.3 SEQUENTIAL CIRCUITS

Page 152 of 345
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Gatecseanswers501 see http://www.gateguru.org
Upcoming SlideShare
Loading in …5
×

Gatecseanswers501 see http://www.gateguru.org

997 views
866 views

Published on

1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
997
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Gatecseanswers501 see http://www.gateguru.org

  1. 1. GATE COMPUTER SCIENCE & INFORMATION TECHOLOGY 501++ Previous questions along with extensively TESTED problems/solutions [1ST ND EDITION 501++ QUESTIONS] [2 RD EDITION 1001++ QUESTIONS] TH [3 EDITION 1001++ QUESTIONS] [4 EDITION 2001++QUESTONS] SUBJECT WISE AND CHAPTER WISE ORGANISATION (1987-date) THE GOEDEL TURING SOCIETY OF INDIA Page 1 of 345
  2. 2. INTRODUCTION The GATE examination is conducted by the IITs and IISc for entrance to postgraduate studies. It is also used for recruitment purposes in Public Sectors and many Government agencies. The examination was started from the year 1987 and is held every February. It is held in various branches of study. In this exposition we have only considered the Computer Science and Engineering(CSE) aspects of the GATE examination. The actual GATE question papers from 1987-date are considered. These consist of some 2001+ questions. We are bringing out this exposition in two versions. Version 1 will have 501++ problems and version 2 will have 1001++ problems. For each problem three parts are considered. The first part is the question by itself. The second part is the question with the key. The third part is the question with key and text solution. The solutions and explanations have been extensively and intensively tested on thousands of students. Page 2 of 345
  3. 3. CONTENTS CHAPTER 0 CHAPTER 1 CHAPTER 2 CHAPTER 3 CHAPTER 4 CHAPTER 5 CHAPTER 6 CHAPTER 7 CHAPTER 8 CHAPTER 9 CHAPTER 10 CHAPTER 11 CHAPTER 12 CHAPTER 13 CHAPTER 14 INTRODUCTION DISCRETE MATHEMATICS THEORY OF COMPUTATION COMPILER DESIGN DBMS COMPUTER NETWORKS OPERATING SYSTEMS DAA DATA STRUCTURES PROGRAMMING LANGUAGES DIGITAL LOGIC COMPUTER ORGANISATION SOFTWARE ENGINEERING WEB TECHNOLOGIES GENERALAPTITUDE APPENDIX Page 3 of 345
  4. 4. DETAILED CONTENTS CHAPTER 0 INTRODUCTION CHAPTER 1 DISCRETE MATHEMATICS CHAPTER 1.1 CHAPTER 1.2 CHAPTER 1.3 CHAPTER 1.4 CHAPTER 1.5 CHAPTER 1.6 CHAPTER 1.7 CHAPTER 1.8 CHAPTER 2 THEORY OF COMPUTATON CHAPTER 2.1 CHAPTER 2.2 CHAPTER 2.3 CHAPTER 2.4 CHAPTER 3 MATHEMATICAL LOGIC COMBINATORICS GRAPH THEORY SET THEORY AND ALGEBRA LINEAR ALGEBRA PROBABILITY NUMERICAL METHODS CALCULUS FINITE AUTOMATA AND REGULAR SETS CONTEXT FREE LANGUAGES AND PUSH DOWN AUTOMATA CSGS, TURING MACHINES AND R.E. SETS UDECIDABILITY COMPILER DESIGN CHAPTER 3.1 CHAPTER 3.2 CHAPTER 3.3 CHAPTER 3.4 CHAPTER 4 LEXICAL ANALYSIS PARSING SDTS CODE GENERATION AND CODE OPTIMISATION CHAPTER 4.1 CHAPTER 4.2 E-R DIAGRAMS FUNCTIONAL DEPENDECIES AND NORMALISATION SQL DBMS CHAPTER 4.3 Page 4 of 345
  5. 5. CHAPTER 4.4 CHAPTER 4.5 CHAPTER 4.5 CHAPTER 5 RELATIONAL ALGEBRA AND RELATIONAL CALCULUS TRANSACTION PROCESSING AND CONCURRENCY CONTROL FILE STRUCTURESAND INDEXING COMPUTER NETWORKS CHAPTER 5.1 CHAPTER 5.2 CHAPTER 5.3 CHAPTER 5.4 CHAPTER 6.1 CHAPTER 6 FUNDAMENTALS LAN TCP/IP APPLICATION LAYER AND ROUTING PROCESS MANAGEMENT DEADLOCK MEMORY MANAGEMENT FILE SYSTEMS AND DEADLOCK OPERATING SYSTEMS CHAPTER 6.2 CHAPTER 6.3 CHAPTER 6.4 CHAPTER 7 DAA CHAPTER 7.1 CHAPTER 7.2 CHAPTER 7.3 CHAPTER 7.4 CHAPTER 7.5 CHAPTER 7.6 Page 5 of 345 ALGORITHM ANALYSIS AND ASYMPTOTIC NOTAION DIVIDE AND CONQUER GREEDY METHOD DYNAMIC PROGRAMMING SEARCH AND TRAVERSAL TECHNIQUES P?=?NP PROBLEM
  6. 6. CHAPTER 8 DATA STRUCTURES CHAPTER 8.1 CHAPTER 8.2 GRAPHS CHAPTER 8.7 HASHING CHAPTER 9.1 CONCEPTS CHAPTER 9.2 PROGRAMMING IN C CHAPTER 9.3 DIGITAL LOGIC TREES CHAPTER 8.6 CHAPTER 10 LINKED LISTS CHAPTER 8.4 PROGRAMMING LANGUAGES STACKS AND QUEUES CHAPTER 8.3 CHAPTER 9 ARRAYS PROGRAMMING IN PASCAL LIKE LANGUAGES BOOLEAN ALGEBRA AND KMAPS COMBNATIONAL CIRCUITS SEQUENSTIAL CIRCUITS NUMBER SYSTEMS CHAPTER 10.1 CHAPTER 10.2 CHAPTER 10.3 CHAPTER 10.4 Page 6 of 345
  7. 7. CHAPTER 11 COMPUTER ORGANISATION CHAPTER 11.1 MEMORY ORGANISATION CHAPTER 11.2 INSTRUCTION PIPELING CHAPTER INPTUT/OUTPUT 11.3 ORGANISAITION CHAPTER 11.4 CHAPTER 12 SECONDARY MEMORY AND DMA SOFTWARE ENGINEERING CHAPTER 12.1 CHAPTER 12.1 CHAPTER 13 TESTING WEB TECHNOLOGIES CHAPTER 14 SDLC CONCEPTS GENERALAPTITUDE CHAPTER NUMERICAL 14.1 ABILITY CHAPTER 14.2 APPENDIX Page 7 of 345 VERBAL ABILITY
  8. 8. CHAPTER 1 MATHEMATICS Page 8 of 345
  9. 9. 1.1 MATHEMATICAL LOGIC [GATE CSE 2013—MATHEMATICAL LOGIC] QUESTION 1.1.1 What is the logical translation of the following statemwnt? “None of my friends is perfect” 𝐴 ∃𝑥(𝐹 𝑥 ⌐P(x)) (B)∃𝑥 ⌐𝐹 𝑥 ⋀𝑃 𝑥 𝐶 ∃𝑥(⌐𝐹 𝑥 ⋀⌐P(x)) (D)⌐∃𝑥 𝐹 𝑥 ⋀𝑃 𝑥 QUESTION 1.1.1 WITH KEY ANSWER IS (D) QUESTION 1.1.1 WITH KEY AND SOLUTION SOLUTION We will use the method of elimination. We will use the childhood behavior of the Predicate Calculus. Consider a universe of a single element. We can dispense with the quantifiers. F(x) means friend(x). P(x) means perfect(x). Page 9 of 345
  10. 10. The statement F!P is !FV!P = !(F&P) matches (D) only. Answer is (D). ********** [GATE CSE 2013—PREDICATE CALCULUS] QUESTION 1.1.2 Which one of the foll9wing is NOT logically equivalent to ⌐∃𝑥(∀𝑦 𝛼 ⋀∀𝑧 𝛽 ) (A) ∀𝑥 ∃𝑧 (⌐𝛽) → ∀𝑦(𝛼)) (B) (C) ∀𝑥 ∀𝑦 (𝛼) → ∃𝑧(⌐𝛽)) (B) ∀𝑥 ∀𝑧 (𝛽) → ∃𝑦(⌐𝛼)) (D) ∀𝑥 ∃𝑦 (⌐𝛼) → ∃𝑧(⌐𝛽)) QUESTION 1.1.2 WITH KEY ANSWER IS (A) OR (D) QUESTION 1.1.2 WITH KEY AND SOLUTION SOLUTION Consider a universe of one element. The given statement is !αV!β. Choice (A) is βV!α, Choice (B) is !βV!α, Choice (C) is !αV!β, Choice (D) is αV!β The examiner has allowed two correct answers inadvertently. Answer is (A) or (D) depending on the examiner’s choice. His choice will never be known!! ******** Question 1.1.3.[DISCRETE MATHEMATICS] What is the maximum number of different Boolean functions involving Page 10 of 345
  11. 11. n Boolean variables? (A) n2 (B) 2n (C) 2**2n (D) 2**n2 Answer: (C ) Explanation: The domain has 2n groups of variables which can map onto 0 in the domain or 1 in the domain. So the number of functions is as in (C). ******** Page 11 of 345
  12. 12. 1.2 COMBINATORICS [QUESTION FROM GATE CSE 2013 COMBINATORICS] QUESTION 1.2.1 Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is ½. What is the expected number of unordered cycles of length 3? (A) 1/8 (B) 1 (C) 7 (D) 8 QUESTION 1.2.1 WITH KEY ANSWER IS (C) QUESTION 1.2.1 WITH KEY AND SOLUTION SOLUTION The number of ways three vertices can be chosen is C(8,3)=8!/(5!3!)=[8x7x6]/[3x2x1]. The probability of obtaining a triangle is (1/2)3=(1/8). The expected value is {[8x7x6]/[3x2x1]}x (1/8)=7. Answer is (C). ******** QUESTION 1.2.2 . [DISCRETE MATHS] Let Graph(x) be a predicate which denotes that x is a graph. Let Page 12 of 345
  13. 13. 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) ¬.(¬Graph(x)vConnected(x)) (D) .x(Graph(x).¬Connected(x)) Answer: (D) Explanation: The four choices can be read as: (A) Not for all graphs connectivity is there implies some graphs may not be connected. (B) There exists a graph that is not connected. (C) ¬PvQ is the same as P.Q. (D) All graphs are not connected. ******** Page 13 of 345
  14. 14. 1.3 GRAPH THEORY [GATE CSE 2013—GRAPH THEORY] QUESTION 1.3.1 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 cycles of length three? (A) 1/8 (B) 1 (C) 7 (D) 8 QUESTION 1.3.1 WITH KEY ANSWER IS (C) QUESTION 1.3.1 WITH KEY AND SOLUTION SOLUTION The number of ways three vertices can be chosen is C(8,3)=8!/(5!3!)=[8x7x6]/[3x2x1]. The probability of obtaining a triangle is (1/2)3=(1/8). The expected value is {[8x7x6]/[3x2x1]}x (1/8)=7. Answer is (C). ******** Page 14 of 345
  15. 15. [GATE C SE 2013—GRAPH THEORY] QUESTION 1.3.2 Which of the following statements are TRUE for undirected graphs? P Number of odd degree vertices is even. Q Sum of degrees of all vertices is even. (A) P only (B) Q only (C) Both P and Q QUESTION 1.3.2 WITH KEY ANSWER IS (C) QUESTION 1.3.2 WITH KEY AND SOLUTION SOLUTION We will use the method of elimination. We will use instantiation. Consider the graphs (1) The null graph P is true and Q is true. (2) The line graph. Page 15 of 345 (D) Neither P nor Q
  16. 16. P is true and Q is true. For every edge degree goes up by 2. So the sum of degrees is always even. So to ensure an even number the number of odd degree vertices are even. Answer is (C). ******** QUESTION 1.3.3 The line graph of a simple graph G is defined as follows …There is exactly one vertex v€ in L(G) for each edge e in G …For any two edges e and e’ in G, L(G) has an edge between v€ and v(e’), if and only if e and e’ are incident with the same vertex in G. Which of the following statements is/are true? (P) The line graph of a cycle is a cycle (Q)The line graph of a clique is a clique (R) The line graph of a planar graph is planar (S) The line graph of a tree is a tree (A) P only (B) P and R only (C) R only QUESTION 1.3.3 WITH KEY ANSWER IS (C)[?] QUESTION 1.3.3 WITH KEY AND SOLUTION Page 16 of 345 (D) P, Q and S only
  17. 17. SOLUTION We will use the method of elimination. (1) Consider the graph. e e’ The line graph is given below The line graph of a tree is not a tree. Choice S is excluded so this excludes Q as per the multiple choices allowed. Now we have to choose between (A), (B) and (C). (2) Consider the graph which is a cycle. The line graph will have diagonal edges and is not a cycle. Statement (P) is ruled out. By elimination the answer is (C). NOTE:- Can you spot the error in the above solution!!! Page 17 of 345
  18. 18. ******** QUESTION 1.3.4 . [DISCRETE MATHS] 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) ¬.(¬Graph(x)vConnected(x)) (D) .x(Graph(x).¬Connected(x)) Answer: (D) Explanation: The four choices can be read as: (A) Not for all graphs connectivity is there implies some graphs may not be connected. (B) There exists a graph that is not connected. (C) ¬PvQ is the same as P.Q. (D) All graphs are not connected. ********* Page 18 of 345
  19. 19. 1.4 SET THEORY AND ALGEBRA [GATE 2013] QUESTION 1.4.1 A binary operation ⊕on aq set of integers is defined as 𝑥 ⊕ 𝑦 = 𝑥 2 + 𝑦 2 . Which one of the follo2ing statements is TRUE about ⊕? (A) Commutative but not associative (B) Both commutative and associative (C) Associative but not commutative (D) Niether commutative nor associative QUESTION 1.4.1 WITH KEY ANSWER IS (A) QUESTION 1.4.1 WITH KEY/SOLUTION/PPT SOLUTION SOLUTION We will use the method of elimination. Instantiate the problem. Let x=0,y=1 and z=2. (0^2 + 1^2)^2 + 2^2=5 wheras 0^2 + (1^2 + 2^2)^2=25 So the operator is not associative. X^2 + y^2 is commutative. So the operator is commutative but not associative. Answer is (A). Page 19 of 345
  20. 20. ******** QUESTION 1.4.2[DISCRETE MATHEMATICS] Let S be a set of n elements. The number of ordered pairs in the largest and smallest equivalence relations on S are (A) n and n (B) n2 and n (C) n2 and 0 (D) n and 1 Answer: (B) The largest relation will be the one with all the elements in it and this will have n*n ordered pairs viz., (a,a) for every element a in the set S. The smallest relation will be the one where each element in the set is in its own class. The index of the relation now is n. ******** Page 20 of 345
  21. 21. 1.5 LINEAR ALGEBRA [QUESTION GATE 2008 EIGENVALUES] QUESTION 1.5.1 How many of the following matrices have an eigenvalue? 1 0 0 1 1 −1 , , 0 0 0 0 1 1 (A) One (B) Two 𝑎𝑛𝑑 −1 0 1 −1 (C) Three (D) Four QUESTION 1.5.1 WITH KEY ANSWER IS (B) ******** Page 21 of 345
  22. 22. 1.6 PROBABILITy [GATE 2013 PROBABILITY] QUESTION 1.6.1 Suppose p is the number of cars per minute passing through a certain road junction between 5PM and 6 PM, and p has a Poisson distribution with mean 3. What is the probability of observing fewer than 3 cars during any given minute in this interval? 𝐴 8/(2𝑒 3 ) (B) 9/(2𝑒 3 ) (C) 17/(2𝑒 3 ) (D) 26/(2𝑒 3 ) QUESTION 1.6.1 WTH KEY ANSWER IS (C) QUESTION 1.6.1 WITH KEY AND SOLUTION 𝑃 𝑝 < 3 = 𝑃 𝑝 = 0 + 𝑃 𝑝 = 1 + 𝑃(𝑝 = 2) = 𝑒 −𝜇 𝜇 0 0! + 𝑒 −𝜇 𝜇 1 1! + 𝑒 −𝜇 𝜇 2 2! = 𝒆−𝟑 + 𝒆−𝟑 𝑿 𝟑 + = 𝒆−𝟑 𝟏 + 𝟑 + 𝟗 𝟐 = (𝑤𝑕𝑒𝑟𝑒 𝞵 =3) 𝒆−𝟑 𝑿 𝟗 𝟐 𝟏𝟕 𝟐𝒆 𝟑 Answer is (C). ******** Page 22 of 345
  23. 23. 1.7 NUMERICAL METHODS [GATE CSE 2013] QUESTION 1.7.1 The smallest integer that can be represented by an 8-bit number in 2’s complement form is (A) -256 (B) -128 (C) -127 (D) 0 QUESTION 1.7.1 WITH KEY Answer is (B). QUESTION 1.7.1 WITH KEY, SOLUTION & PPT EXPLANATION Answer is (B). We will use the method of elimination. Half the values are positive and half negative. This rules out choices (A) and (D). One positive value goes for 0. So all the negative values -1 to -128 can be accommodated. Answer is (B). ******** [GATE 2013 NUMERICAL METHODS] QUESTION 1.7.2 1 Which one of the following does NOT equal 1 1 𝑥 𝑦 𝑧 𝑥2 𝑦2 ? 𝑧2 Page 23 of 345
  24. 24. 1 (A) 1 1 𝑥(𝑥 + 1) 𝑦(𝑦 + 1) 𝑧(𝑧 + 1) 0 (C) 0 1 𝑥− 𝑦 𝑦− 𝑧 𝑧 1 (B) 1 1 𝑥2 − 𝑦2 𝑦2 − 𝑧2 𝑧2 𝑥+1 𝑦+1 𝑧+1 𝑥2 + 1 𝑦2 + 1 𝑧2 + 1 2 (D) 2 1 𝑥+1 𝑦+1 𝑧+1 𝑥+ 𝑦 𝑦+ 𝑧 𝑧 𝑥2 + 𝑦2 𝑦2 + 𝑧2 𝑧2 QUESTION 1.7.2 WITH KEY ANSWER IS (A) QUESTION 1.7.2 WITH KEY, SOLUTION AND PPT SOLUTION This is the famous Vandermonde’s matrix. Let us instantiate the problem. Choose x=0, y=1 and z=2. The determinant of the given matrix is 1[(1*4) –(2*1) = 2 The choice (A) determinant is 1 1 1 𝑥(𝑥 + 1) 𝑦(𝑦 + 1) 𝑧(𝑧 + 1) 𝑥+1 𝑦+1 𝑧+1 The value is 1[(2*3)-(6*2)] – 0[---] + 1[1*6-1*2)] = 6-12 + 3-6 = -2 So choice (A) does not agree with the given matrix. So it is the answer by elimination. The examiner guarantees the other choices are wrong. Answer is (A). ******** [QUESTION ON FUNCTIONS—GATE CSE 2013] Page 24 of 345
  25. 25. QUESTION 1.7.3 Which one of the following functions is continuous at x=3? { 2 𝑥−1 (A) f(x) = (C) f(x)= { 𝑖𝑓 𝑥 = 3 𝑖𝑓 𝑥 > 3 𝑥+3 3 (B) f(x) = 𝑖𝑓 𝑥 < 3 𝑥 + 3 𝑖𝑓 𝑥 ≤ 3 𝑥 − 4 𝑖𝑓 𝑥 > 3 (D) f(x)= { 4 𝑖𝑓 𝑥 = 3 8 − 𝑥 𝑖𝑓 𝑥 ≠ 3 1 𝑥 3 −27 𝑖𝑓 𝑥 ≠ 3 QUESTION 1.7.3 WITH KEY ANSWER IS (A) QUESTION 1.7.3 WITH KEY AND SOLUTION SOLUTION Consider 3, 3+ε, 3-ε as values of x. Case (A)-----f(x)=2 for x=3, f(x)=2 + ε for x=3+ε, and finally f(x) = 2-ε for x=3-ε. As ε0 the value of f(x) tends to 2 in all cases. So f(x) is continuous at x=2. The examiner guarantees the other answers are wrong. Answer is (A). ******** [GATE CSE 2013—TRAPEZOIDAL RULE] QUESTION 1.7.4 X 0 0.3 0,6 0.9 1.2 1.5 Page 25 of 345 1.8 2.1 2.4 2.7 3.0
  26. 26. f(x) 0 The value of 0.09 3 0 0.36 0,81 1.44 2.25 3.24 4.41 5.76 𝑓 𝑥 𝑑𝑥 𝑐𝑜𝑚𝑝𝑢𝑡𝑒𝑑 𝑢𝑠𝑖𝑛𝑔 𝑡𝑕𝑒 𝑡𝑟𝑎𝑝𝑒𝑧𝑜𝑖𝑑𝑎𝑙 𝑟𝑢𝑙𝑒 𝑖𝑠 (A) 8.983 (B) 9.003 (C) 9.017 (D) 9.045 QUESTION 1.7.4 WITH KEY ANSWER IS (D) QUESTION 1.7.4 WITH KEY AND SOLUTION SOLUTION Apply the trapezoidal rule. The area under a trapezoid= (1/2)[sum of parallel sides] * height. 3 0 𝑓 𝑥 𝑑𝑥 = = 𝑕 [𝑓 2 0.3 2 𝑥0 + 𝑓 𝑥10 + 2(𝑓(𝑥1 ) + f(𝑥2 ) + ⋯ + 𝑓(𝑥9 ))] 9.00 + 2 25.65 = 0.045 Answer is (D). ******** QUESTION 1.7.5 [MATHS] Consider the following two statements about the function f(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? Page 26 of 345 7.29 9.00
  27. 27. (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. Answer: (A) Explanation: The only difficulty is at x=0. f(x) = 0 at x=0 so continuity is ensured. But f’(x) depends on how we approach the origin x=0 from negative values to 0 or positive values to 0, so it is not differentiable. ******** QUESTION 1.7.6 [NUMERICAL METHODS] Consider the series xn+1 = xn /2 + 9/(8xn), with x0 = 0.5 obtained from the Newton_Raphson method. The series converges to (A) 1.5 (B)v2 (C) 1.6 (D) 1.4 Answer: (A) Explanation: We will directly try out some iterations: Iteration 1. x(1) = .5/2 + 9/(8*.5) =.25 +9/4=2.5 Iteration 2. x(2) = 2.5/2 + 9/(8*2.5)=1.25 + 9/20=1.7 Page 27 of 345
  28. 28. Iteration 3. x(3) = 1.7/2 + 9/(8*1.7)=.85 + 9/16.8=.85 +.82=1.67 Iteration 4. x(4) = 1.67/2 + 9/(8*1.67)=approx.835 + 27/40=.835+.675=1.6 Iteration 5. x(5)=1.6/2 + 9/(8*1.6)=.8 + .7=1.5 So it appears to be 1.5 Now let us substitute 1.5 directly in the formula then we have X(n+1) = 1.5/2 + 9/(8*1.5)=.75 +.75= 1.5 So the iteration converges to 1.5, and the answer is (A). ********* Page 28 of 345
  29. 29. 1.8 CALCULUS [GATE CSE 2011 Q21 MATHEMATICS] QUESTION 1.8.1 Given i= −1, what will be the evaluation of the definite integral 𝜋/2 cos 𝑥+𝑖 sin 𝑥 0 cos 𝑥−𝑖 sin 𝑥 (A) 0 𝑑𝑥? (B) 2 (C) –i (D) i QUESTION 1.8.1 WTH KEY ANSWER IS (D) QUESTION 1.8.2 WITH KEY AND SOLUTION 𝜋/2 0 = = 𝑒 𝑖𝑥 𝑒 −𝑖𝑥 𝜋/2 0 𝑒 2𝑖𝑥 𝑓𝑜𝑟 0 𝑡𝑜 2𝑖 𝑒 2𝑖𝑥 𝑑𝑥 𝑑𝑥 = 𝜋 2 = 𝑒 𝜋𝑖 − 1 /[2𝑖] cos 𝜋 + 𝑖 ∗ 𝑠𝑖𝑛 𝜋 − 1 −2 −1 = = 2𝑖 2𝑖 𝑖 𝑖2 = = 𝑖 𝑖 ANSWER IS (D) ******** Page 29 of 345
  30. 30. CHAPTER 2 THEORY OF COMPUTATION Page 30 of 345
  31. 31. 2.1 FINITE AUTOMATA AND REGULAR SETS GATE CSE QUESTIONS IN THE THEORY OF COMPUTATION] QUESTION 2.1.1 Consider the languages 𝐿1 = 𝜑 𝑎𝑛𝑑 𝐿2 = 𝑎 . Which one of the following represents 𝐿1 𝐿∗ ? 2 (A) ,ε- (B) 𝜑 (C) 𝑎∗ (D) ,ε, a- QUESTION 2.1.1 WITH KEY ANSWER IS (A) QUESTION 2.1.1 WITH KEY & SOLUTION The set Φ is the anhillator. Φ*={ε}. The result is thus {ε}. Answer is (A). ******** [GATE CSE 2013---FINITE AUTOMATA AND REGULAR SETS] QUESTION 2.1.2 Page 31 of 345
  32. 32. Consider the DFA given below 1 1 0 0 0,1 Which of the following are FALSE? 1. 2. 3. 4. Complement of L(A) is context free 𝐿 𝐴 = 𝐿 11∗ 0 + 0 0 + 1 ∗ 0∗ 1∗ ) 𝐹𝑜𝑟 𝑡𝑕𝑒 𝑙𝑎𝑛𝑔𝑢𝑎𝑔𝑒 𝑎𝑐𝑐𝑒𝑝𝑡𝑒𝑑 𝑏𝑦 𝐴, 𝐴 𝑖𝑠 𝑡𝑕𝑒 𝑚𝑖𝑛𝑖𝑚𝑎𝑙 𝐷𝐹𝐴 A accepts all strings over {0, 1} of length at least 2 QUESTION 2.1.2 WITH KEY ANSWER IS (D) QUESTION 2.1.2 WITH KEY AND SOLUTION SOLUTION (1) L(A) is regular as a is a dfa. Its complement is a dfa and hence it is regular. All regular sets are context-free. So statement (1) is true. (2) The automata can be redrawn as 11*0 0 Page 32 of 345 0+1
  33. 33. The set accepted is (11*0 +0)(0+1)*=(11*0+0)(0+1)*(ε+ anything) =(11*0+0)(0+1)*(0*1*) So (2) is correct. The examiner guarantees one correct answer, So answer is (D). ******** QUESTION 2.1.3 Give the minimal DFA that performs as a mod-3 1's counter, i.e. outputs a 1 each time the number of 1's in the input sequence is a multiple of 3. SOLUTION 2.1.3 This is the standard modulo 3 machine. input:1 Output q0 q1 Nil q1 q2 Nil q2 q0 1 QUESTION 2.1.4 Is the class of regular sets closed under infinite union? Explain. SOLUTION 2.1.4 ANSWER-----NO Any formal language is the union(possibly infinite) of each of its elements treated as a singleton set. So the infinite union of regular sets need not be regular. ******** Page 33 of 345
  34. 34. QUESTION 2.1.5 Is the language generated by the grammar G regular? If so, give a regular expression for it, else prove otherwise. G: S------------->aB B-------------->bC C------------->xB C---------->c SOLUTION QUESTION 2.1.5 The given grammar is a right linear grammar so it generates a regular set. Construct a state diagram from the grammar, it is easily seen to yield a(bx)*bc as the set accepted by the finite automata. ******** QUESTION 2.1.6 Let r = 1(1+0)*, s = 11*0, t = 1*0 be three regular expressions. Which one of the following is true? (A)L(s) is a subset of L(r) and L(s) is a subset of L(t) (B) L(r) is a subset of L(s) and L(s) is a subset of L(t) (C) L(s) is a subset of L(t) and L(s) is a subset of L(r) (D) L(t) is a subset of L(s) and L(s) is a subset of L(r) SOLUTION 2.1.6 ANSWER--------(A) and (C) Page 34 of 345
  35. 35. From an examination of the three regular expressions t contains a 0 wheras the other two do not. So L(t) cannot be a subset of the other two sets. This excludes (D). L(r) contains 100 wheras the other two do not. So L(r) cannot be a subset of the other two. This excludes (B). Note that (A) and (C) are the same. ******** QUESTION 2.1.7 Which one of the following is the strongest correct statement about a finite language over some finite alphabet X? (A) It could be undecidable. (B) It is Turing machine recognizable (C) It is a regular language (D) None of the above SOLUTION 2.1.7 ANSWER------(D) The regular sets are the smallest class that contain all the finite sets. ******** QUESTION 2.1.8 Show that Turing machines, which have a read only input tape and a constant work size tape, recognize precisely the class of regular languages. SOLUTION 2.1.8 If we take a turing machine and take away its ink it becomes a 2DFA or 2NFA. We have the standard theorem that these accept only the regular sets. ******** QUESTION 2.1.9 Page 35 of 345
  36. 36. Let L be the language of all binary strings in which the third symbol from the right is a 1. Give a non-deterministic finite automaton that recognizes L. How many states does the minimised equivalent deterministic finite automaton have? Justify your answer briefly. SOLUTION 2.1.9 Q17(b) The nfa for the machine over {0,1} is given below: input 0 input 1 (start state) H H H,P P M M M *C *C *C ---------------------------- -------------------------- The equivalent minimal dfa has 8 states as can be shown by constructing the dfa and minimising it. This is the example of a nfa to dfa conversion which requires an exponential number of states. ******** QUESTION 2.1.10 Which of the following regular expression identities are true? (A) r(*) = r* (B) (r*S*)* = (r + s)* (C) (r + s)* = r* + s* (D) r*s* = r* + s* SOLUTION Q2.1.10 ANSWER (B) (A) seems to be a printing mistake r(*)=r (B) is a standard identity (r+s)*=(r*s*)* In (C) rs is present in the left hand side but not in the right hand side regular expression. In(D) rs is present in the left hand side but not in the right hand side regular expression. Page 36 of 345
  37. 37. ******** QUESTION 2.1.11 Q2(xx) In which of the cases stated below is the following statement true? "For every nondeterministic machine M1 there exists an equivalent deterministic machine M2 recognizing the same language". (A) M1 in a nondeterministic finite automaton. (B) M1 is a nondeterministic PDA (C) M1 is a nondeterministic Turing machine (D) For no machine M1 is the above statement True SOLUTION 2.1.11 ANSWER (A) AND (C) For the pda the nondeterministic model is more powerful than the deterministic one. {wwR} the language of palidromes is accepted by the former and not the latter. For the fa and turing machines the nondeterminsitic and deterministic models are equivalent. ******* QUESTION 2.1.11 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). SOLUTION 2.1.11 ANSWER----TRUE A full adder is nothing but a finite automata. It however depends on how we encode the problem. For example the set {0n 1m 0m+n |m,n>1} is not regular. Page 37 of 345
  38. 38. ******** QUESTION 2.1.12 Given that a language L1 is regular and that the language L1 U L2 is regular, is te language L2 always regular? Prove your answer. SOLUTION 2.1.13 ANSWER----no Let L1 be the regular set (0+1)* and L2 any formal language(not necessaily regular). Then the union is always regular. ******** QUESTION 2.1.14 Let X={0,1}, L=X* and R={0^n 1^n such that n > 0} then the languages LUR and R are respectively (a) Regular, Regular (b) Not Regular, Regular (c) Regular, Not Regular (d) Not Regular, Not Regular SOLUTION 2.1.15 ANSWER---------------(C) L U R is the same as the set of all strings over {0,1} and hence is regular. R is a standard cfl that is not regular. ******** QUESTION 2.1.16 Two of the following four regular expressions are equivalent which two? (e is the empty string). (i) (00)*(e+0) (ii) (00)* (iii) 0* (iv) 0(00)* (A) (i) and (ii) (B) (ii) and (iii) (C) (i) and (iii) (D) (iii) and (iv) Page 38 of 345
  39. 39. SOLUTION 2.1.16 ANSWER I (iv) This says even number of 0s plus odd no of 0s i.e. 0* (ii) This says evenumbr of 0s (iii) This says all 0s (iv) This says only odd no of 0s ******** QUESTION 2.1.17 Which one of the following regular expressions over {0,1} denotes the set of all strings not containing 100 as a substring? (A) 0*(1+0)* (B)0*1010* (C) 0*1*01 (D) 0*(10+1)* SOLUTION 2.1.17 Since epsilon does not contain 100 the answer is trivially (D). ******** QUESTION 2.1.18 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. SOLUTION 2.1.18 The minimal dfa has 6 states. A modulo 2 machine for a's and a modulo 3 machine for b's. The state transition table of the fa is given below> input : a input : b q00 q10 q01 q01 q11 q00 q10 q20 q11 q11 q01 q12 Page 39 of 345
  40. 40. q12 q02 q00 q02 q12 q00 qij means i gives extra number of a's and j gives extra number of b's ******** QUESTION 2.1.19 Given that L is a language accepted by a finite state machine, show that Lp and Lr are accepted by some finite state machines where Lp ={s|ss"in L for some string s"}, Lr={s|s obtained by reversing some string in L} S SOLUTION 2.1.19 Lp is nothing but init. Make all states of the fa final to accept Lp.For Ls make the final state the start state and the start state the final state and reverse the direction of the edges. Alternatives reverse the regular expression for L. ******** QUESTION 2.1.20 If the regular set A is represented by A=(01+1)* ant the regular set 'B' is represented by B= ((01)*1*)*, which of the following is true? (a) A is a proper subset of B (b) B is a proper subset of A (c) A and B are incomparable (d) A=B SOLUTION 2.1.20 ANSWER-----------(D) Note the regular expression identity (r+s)*=(r*s*)*. With t=01 and s=1 it is seen that both the regular expressios are the same. Page 40 of 345
  41. 41. ******** QUESTION 2.1.21 Which of the following sets can be recognized by a deterministic finite automaton? (a) The numbers 1,2,4,8,----------.2^n,-------------written in binary. (b) The umbrs 1.2.4.-------,2^n,--------------written in unary. (c) The set of binary strings in which the number of zeros is the same as the number of ones. (d) The st {1, 101, 11011, 1110111,--------} SOLUTION Q2.1.21 Q1.10ANSWER-------------(A) (A) The squares written in binary are 1,10,100,1000,----etc. The finite automata has merely got to recognise a 1 followed by any number of 0's. (B) The set {0^2^n|n>1} cannot be a regular set as shown by the weak form of the pumping lemma for regular sets. The squares cannot be in any arithmetic progression. (C) The strings with an equal number of 0's and 1's is a standard language which is a cfl and not a regular set. (D) But for the first element the set is {1n01n|n>1} which cannot be regular as is seen from the pumping lemma for regular sets. ******** QUESTION 2.1.21 Regarding the power of recognition of languages, which of the following statements is false? (a) The non-deterministic finite-state automata are equivalent to deterministic finite-state automata. (b) Non-deterministic Push-down automata are equivalent to deterministic push-down automata. (c) Non-deterministic Turing machines are equivalent to deterministic Turing machines. Page 41 of 345
  42. 42. (d) Multi-tape Turing machines are equivalent to single-tape Turing machines. SOLUTION Q2.1.21 Q1.11 ANSWER-------------(B) AND (C) The deterministic and nondeterministic models of the pushdown automata are not the same. The deterministic and nondeterministic models of finite auomata are the same and the same statement holds for turing machines. ******** QUESTION 2.1.22 Q1.12 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)* SOLUTION 2.1.22 ANSWER--(C) AND (D) In C after a 11 we will have a 00 only. The 0's occur in pairs. In D the 1's occur in pairs and an odd number of 1's are not possible. ******** QUESTION 2.1.23 Let L be the set of all binary strings whose last two symbols are the same. The number of states in the minimum state deterministic finite state automaton accepting L is (a) 2 (b) 5 (c) 8 (d) 3 SOLUTION 2.1.23 Q1.12 ANSWER--(C) AND (D) In C after a 11 we will have a 00 only. The 0's occur in pairs. In D the 1's occur in pairs and an odd number of 1's are not possible. Page 42 of 345
  43. 43. ********* QUESTION 2.1.24 Which of the following statements is false? (a) Every finite subset of a non-regular set is regular. (b) Every subset of a regular set is regular. (c) Every finite subset of a regular set is regular. (d) The intersection of two regular sets is regular. SOLUTION 2.1.24 ANSWER-----------(B) The subsets of the regular set (0+1)* are all the formal languages and hence not all regular. In the choices (A) and (C) we have finite sets which are automatically regular. In (D) we have the fact that the regular sets are closed under intersection. ******** QUESTION 2.1.25 Design a deterministic finite state automaton (using the minimum number of states) that recognizes the following language: L = {w in {0,1}*| w interpreted as a binary number (ignoring the leading 0's) is divisible by five} SOLUTION 2.1.25 This is the modulo 5 machine. input:0 input:1 q0 q0 q1 q1 q2 q3 q2 q4 q0 Page 43 of 345
  44. 44. q3 q1 q2 q4 q3 q4 ******** QUESTION 2.1.26 CS6 (a) Given that A is regular and (AUB) is regular, does it follow that B is necessarily regular? Justify your answer. (b) Given two finite automata M1, M2 outline an algorithm to decide if L(M1) is a strict subset of L(M2). SOLUTION 2.1.26 (a) ANSWER----NO If we choose A to be (0+1)* the B can be any formal language. (b) We must check for strings in L1'intersection L2 and L2'intersection L1. ******** QUESTION 2.1.27 Let S and T be languages over X={a,b} represented by the regular expressions (a+b*)* and (a+b)*, respectively. Which of the following is true? A. S is a proper subset of T B. T is a proper subset of S C. S = T D. S intersection T = empty set SOLUTION 2.1.27 Q1.4 ANSWER-----------(C) (a+b*) is the same as (a+b+b*)=(a+b)* ******** Page 44 of 345
  45. 45. QUESTION 2.1.28 Construct a minimal finite state machine that accepts the language over{0,1}, of all strings that contain neither the substring 00 nor the substring 11. SOLUTION Q2.1.28 The finite automat state transition diagram is given below. input: 0 input:1 *q0 Reject q1 *q1 q0 Reject Reject Reject Reject By examination we find all the states can be distinguished on some input string. So the minimal automata is the same as that given above. ******** QUESTION 2.1.29 Consider the following two statements: S1: {0^2n|n>=1} is a regular language. S2: {0^m1^n0^(m+n)|m>=1 and n>=1} is a regular language Which of the following statements 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 SOLUTION Q2.1.29 ANSWER----------(A) S1 is nothing but (00)+, a regular expression and hence denotes a regular set. S2 is not a regular set as seen from the pumping lemma for regular sets. ******** Page 45 of 345
  46. 46. QUESTION 2.1.30 Given an arbitrary non-deterministic finite automaton(NFA) with N states, the maximum number of states in an equivalent minimized DFA is at least A. N^2 B. 2^N C.2N D. N! SOLUTION 2.1.30 ANSWER-----(B) In the worst case we require the entire subset machine in converting a nfa to a dfa. ******** QUESTION 2.1.31 Consider a DFA over X= {a,b} accepting all strings which have number of a's divisible by 6 and the 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 SOLUTION Q2.1.31 ANSWER--------------(D) We have to take the product of a modulo 6 machine and a modulo 8 machine. ******** QUESTION 2.1.32 Page 46 of 345
  47. 47. CS2.6 Consider the following languages: L1 = {ww|w in {q,b}*} L2 = {wwR| w in {a,b}*, wR is the reverse of w} :3 = { 0^2i|i is an integer} L4 = {0^i^2| i is an integer} Which of the following languages are regular? A. Only L1 and L2 B. Only L2, L3 and L4 Only L3 and L4 D. Only L3 SOLUTION 2.1,31 ANSWER-------------(D) L1,L2 and L4 are standard non-regular sets. L3 is the set (00)* ******** QUESTION 2.1.32 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 SOLUTION 2.1.32 ANSWER----------(A) e (the empty string) is cumpulosily in 0*(10*)* and this excludes (B) and (C) as the answers. ). 0*(10*)* is the same as (0+1)* and this is the same as 1*(01*)*. Any string in (0+1)* can Page 47 of 345
  48. 48. be considered to optionally start with a 0, contain sequences of 0's separted by a 1 or we can consider any string in (0+1)* to start optionally with some 1's and followed by seuences of 1's separated by 0's. ******** QUESTION 2.1.33 The language {a^m 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 SOLUTION 2.1.33 Q87. ANSWER---------(B) One can easily design a dpda which pushes a's and b's onto the stack and for every c in the input it pops and a or a b. ******** SOLUTION 2.1.34 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*)* SOLUTION 2.1.34 ANSWER---------(c) Page 48 of 345
  49. 49. (a* +b* +c*)=(a+b+c+other strings)*=(a+b+c)* for (B) we have the standard identity (r*s*)*=(r+s)* for (D) we have (a*b*+c*)=(a+b+c+other strings)*=(a+b+c)* for C we have a is not a substring ******** QUESTION 2.1.35 Q2.10 The regular expression for the language recognized by the finite state automaton in the figure below is -------------------------------- SOLUTION 2.1.35 Answer is 0*1* ******** QUESTION 2.1.35 Given below are the transiton diagrams for two finite state machines M1 andM2 recognising languages L1 and L2 respectively. (a) Display the transition diagram for a machine that recognizes L1L2 obtained from transition diagrams for M1 and M2 by adding only& transitions and no new states. Page 49 of 345
  50. 50. (b) Modify the transition diagram obtained in part (a) to obtain a transition diagram for a maachie that recognizes (L1L2) by adding only e transitions and no new states. (Final states are enclosed in double circles). SOLUTION 2.1.35 The terminolgy of & transitions is not clear in the printed version of the paper available to me. For e moves simply put e transitions from state A to state C. A should be final as M2 accepts epsilon. ******** QUESTION 2.1.36 Consider the following deterministic finite state automaton M. Page 50 of 345
  51. 51. 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) 1 (b)5 (c) 7 (d) 8 SOLUTION Q2.1.36 ANSWER-------(C) Name the states of the finite automata left to right as A,B,C and D. The strings with the 1st, fourth and seventh bits as 1's will be 1001D001 1001D011 1001D101 1001D111 1011A001 1011A011 Page 51 of 345
  52. 52. 1011A101 1011A111 1101A001 1101A011 1101A101 1101A111 1111A001 1111A010 1111A101 1111A111 The first fout are aceepted. In the remaining three block of fours only the first string is accepted. ******** QUESTION 2.1.37 Consider the NFA M shown below: Page 52 of 345
  53. 53. Let the language accepted by M be L. Let L1 be the language accepted by the NFA M1, obtained by changing the accepting state of M to a non-accepting state and by changing the non-accepting state of M to accepting states. Which of the following statements is true? (a) L1 = {0,1}* - L (c) L1 is a subset of L (b) L1 = {0,1}* (d) L1 = l SOLUTION Q 2.1.37 ANSWER-------(B) By interchanging the final and nonfinal states of M we see that the new machine gives e as an element of L1 as the start state becomes a final state in the machine for L1. This excludes (C) and (D) from the answers. 1 is in L and L1 and this excludes (A) from the answer.The only choice left is (B). In the machine for L1 we have a complete finite automata where all the states i.e entries in the transititon table are final states. Thus l1 is (0+1)*. ********* QUESTIN 2.1.38 . [THEORY OF COMPUATION] [REGULAR SETS] Page 53 of 345
  54. 54. Which of the following is TRUE? (A) Every subset of a regular set is regular. (B) Every finite subset of a non-regular set is regular (C) The union of two non-regular sets is not regular (D) Infinite union of finite set is regular Answer: B Explanation: Every finite set is trivially a regular set. Choice A cannot be correct as any formal language is a subset of S* which is a regular set. Choice C cannot be correct as the union of two nonregular cfls, a cfl and its complement is necessarily regular e.g. take all the palidromes over some alphabet. An formal language can be looked upon as the infinite union of singleton sets consisting of one string in the language, so D cannot be correct. ******** Page 54 of 345
  55. 55. 2.2 CFLS [GATE CSE 2013—CONTEXT FREE LANGUAGES] QUESTION 2.2.1 Consider the following languages 𝐿1 = {𝑜 𝑝 1 𝑝 0 𝑟 |𝑝, 𝑞, 𝑟 ≥ 0 & 𝐿2 = {0 𝑝 1 𝑞 0 𝑟 |p,q,r≥ 0, 𝑝 ≠r Which one of the following statements is FALSE? (A) (B) (C) (D) 𝐿2 𝑖𝑠 𝑐𝑜𝑛𝑡𝑒𝑥𝑡 − 𝑓𝑟𝑒𝑒 𝐿1 ∩ 𝐿2 𝑖𝑠 𝑐𝑜𝑛𝑡𝑒𝑥𝑡 𝑓𝑟𝑒𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑚𝑒𝑛𝑡 𝑜𝑓 𝐿2 𝑖𝑠 𝑟𝑒𝑐𝑢𝑟𝑠𝑖𝑣𝑒 𝐶𝑜𝑚𝑝𝑙𝑒𝑚𝑒𝑛𝑡 𝑜𝑓 𝐿1 𝑖𝑠 𝑐𝑜𝑛𝑡𝑒𝑥𝑡 𝑓𝑟𝑒𝑒 𝑏𝑢𝑡 𝑛𝑜𝑡 𝑟𝑒𝑔𝑢𝑙𝑎𝑟 QUESTION 2.2.1 WITH KEY ANSWER IS (D) QUESTION 2.2.1 WITH KEY AND SOLUTION SOLUTION L1 is a regular set given by 0*1*0*. Its complement is also regular. Since cfls include regular sets L1 and its complement are both cfls. Hence (D) is false and it is the answer. The examiner guarantees one correct answer. Page 55 of 345
  56. 56. Answer is (D). ******** QUESTION 2.2.2 A context free grammar is ambiguous is: (A) The grammar contains useless non-terminals. (B) It produces more than one parse tree for some sentence. (C) Some production has two non-terminals side by side on the right-hand side. (D) None of the above. SOLUTION Q 2.2.2 ANSWER-----TRUE The regular sets are closed under practically all operations. Consider the reversal of a regular expression to show the closure of the regular sets under reversal. QUESTION 2.2.3 FORTRAN is a: (A) Regular language (B) Context-free language (C) Context-sensitive language (D) None of the above SOLUTION 2.2.3 ANSWER----(C) If we are to consider all semantically correct programs then the class of context sensitive languages are sufficient to describe FORTRAN. The regular languages cannot do parenthesis matching ant the cfls cannot do type checking. SOLUTION 2.2.3 ANSWER----(C) Page 56 of 345
  57. 57. If we are to consider all semantically correct programs then the class of context sensitive languages are sufficient to describe FORTRAN. The regular languages cannot do parenthesis matching ant the cfls cannot do type checking. ******** QUESTION 2.2.4 What is the type of the language L, where L = {a^n b^n | 0 < n <327the prime number} SOLUTION 2.2.4 The language L={an bn |0<n<327th prime number} is a finite set and hence regular. ******** QUESTION 2.2.5 Q15. Consider the DFA M and NFA M2 as defined in the figure below. Let the language accepted by the machine M be L. What language does the machine M2 accept, if (i) F2 = A? (ii) F2 = B? (iii) F2 = C? (iv) F2 = D? M = (Q,§,f,q0,F) M2 = (Q2,§,f2,q00,F2) where Q2 = (QxQxQ) U {q00} f2(q00,E)={<q0,q,q>| q e Q} f2(<p,q,r>,a) = <f(p,a),f(q,a),r> for all p,q,r i Q and a in § A = { <p,q,r>| p in F; q, r in Q} Page 57 of 345
  58. 58. B = { <p,q,r>| p in F; p, r in Q} C = { <p,q,r>| p, q, r in Q; there exists s in §* such that f(p,s) is in F)} D = { <p,q,r>| p in Q; q in F} SOLUTION 2.2.5 M2 has three copies of M. Case(i): F2=A. In this case the first copy behaves as the same as M and the other two are don't care conditions. So the language accepted is L. Case(ii): F2=B. In this case the second copy starts from any state and proceed to the output. So if the head of a string reaches a final state then we accept i.e. we accept any string of L that makes an excursion to the final state.. Case (iii) In this case we accept Init(L). Case (iv) r is not specified in the final states of M2 so we accept the empty set. ******* QUESTION 2.2.6 Context-free languages and regular languages are both closed under the operation(s) of: (A) Union (C) Concatenation (B) Intersection (D) Complementation SOLUTION 2.2.6 Q3(ii) ANSWER---------(A) AND (C) The regular sets and cfs are closed under the operations of union and concatenation. The operations of intersection and complementation preserve the regular sets as seen from the definition and properties of extended regular expressions. ******** QUESTION 2.2.7 What is the minimum height of the parse tree of a string of length in a language L whose grammar is in the Chomky-Normal form? Explain. Page 58 of 345
  59. 59. SOLUTION Q2.2.7 ANSWER---CEIL(LOG2(L))+1 If we have l as a power of 2 then the derivation tree with the leaves removed is a complete binary tree of height log2(l). For the leaves to be generated we add 1 to the height. In general l will be between two powers of two so we take the ceil of log2(l). ******** QUESTION 2.2.8 Consider a context-free grammar with the following production rules: S-------->NP VP NP--------->article NP1 NP--------->NP1 NP1--------->noun PP-----------> preposition NP NP----------> verb VP--------->verb NP VP----------->verb NP PP The following sentence is to be parsed using the above grammar. Ram sold the pen to Hari. Categories of terminal symbols are as given below: Ram : noun Sold : verb the : article pen noun to : : preposition Page 59 of 345
  60. 60. Hari : noun Obtain a parse-tree for the given sentence. SOLUTION 2.2.8 The sentence is "Ram sold the pen to Hari" The leftmost derivation is given below: S-------------------->NP VP --------------------->NP1 VP ------------------> noun VP --------------------->Ram VP -------------------->Ram verb NP PP ---------------->Ram sold NP PP -----------------> Ram sold article NP PP --------------------->Ram sold the NP PP --------------------> Ram sold the pen PP You can build the derivation tree from the above leftmost derivation. ----------------------> Ram sold the pen preposition NP ---------------------> Ram sold the pen to NP ---------------------> Ram sold the pen to NP1 ----------------------->Ram sold the pen to noun ----------------------->Ram sold the pen to Hari ******** QUESTION 2.2.9 Is the language generated by the grammar G regular? If so, give a regular expression for it, else prove otherwise. Page 60 of 345
  61. 61. G: S------------->aB B-------------->bC C------------->xB C---------->c SOLUTION 2.2.9 The given grammar is a right linear grammar so it generates a regular set. Construct a state diagram from the grammar, it is easily seen to yield a(bx)*bc as the set accepted by the finite automata. ******** QUESTION 2.2.10 Q3(xiv) Which one of the following is the strongest correct statement about a finite language over some finite alphabet X? (A) It could be undecidable. (B) It is Turing machine recognizable (C) It is a regular language (D) None of the above SOLUTION 2.2.10 ANSWER------(D) The regular sets are the smallest class that contain all the finite sets. ********* QUESTION 2.2.11 Q2(xviii) If G is a context-free grammar and w is a string of length l in L(G), how long is a derivation of w in G, if G is in the Chomky normal form? (A) 2l (B) 2l + 1 (C) 2l - 1 (D) l Page 61 of 345
  62. 62. SOLUTION 2.2.11 ANSWER (C) Consider strings of lenght 1 and 2 to find out the correct formula by elimination. ******** QUESTION 2.2.12 In which of the cases stated below is the following statement true? "For every nondeterministic machine M1 there exists an equivalent deterministic machine M2 recognizing the same language". (A) M1 in a nondeterministic finite automaton. (B) M1 is a nondeterministic PDA (C) M1 is a nondeterministic Turing machine (D) For no machine M1 is the above statement True SOLUTION 2.2.12 ANSWER (A) AND (C) For the pda the nondeterministic model is more powerful than the deterministic one. {wwR} the language of palidromes is accepted by the former and not the latter. For the fa and turing machines the nondeterminsitic and deterministic models are equivalent. ******** QUESTION 2.2.13 Q1.10 Consider a grammar with the following productions S----->aAb|bAc|aB S--->AS|b S----->Abb|ab bA-------->bdb|b Page 62 of 345
  63. 63. The above grammar is (a) context-free (b) regular (c) context-sensitive (d) LR(k) SOLUTION 2.2.13 ANSWER-------(C) The last rule has two symbols on the left hand side and the right hand sides of all the rules is as lone as or longer than the left hand side. ******** QUESTION 2.2.14 Which of the following definitions below generates the same language as L, where L = {x^n y^n|n>=1}? I. E----->xEy|xy (a) I only II.xy|(x+xyy+) (b) I and II III.x+y+ (c) II and III (d) II only SOLUTION Q2.2.14 ANSWER-------------(A) The language is a standard cfl which is generated by the productions in I. II gives a regular set and the given language is not regular. ******** QUESTION 2.2.15 Let L be a subset of X* where X={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 = {a^n b^n| n>=1} is regular. (C) L = {x | x has mores a's than b's} is regular. (D) L = {a^m b^n | m>=1, n>=1} is regular Page 63 of 345
  64. 64. SOLUTION Q2.2.15 ANSWER--------------(D) The first three are three standard cfls which are not regular, by the pumping lemma for regular sets. (E) represents a*b* which is regular. ******** QUESTION 2.2.16 If L1 and L2 are context free languages and R a regular set, one of the languages below is not necessarily a context-free language. Which one? (A) L1L2 (B) L1 intersection L2 (C) L1 intersection R (D) L1 U L2 SOLUTION Q2.2.16 ANSWER IS (B) ******** QUESTION 2.2.17 Define for a context-free language L over {0,1}, init(L)={u|uv in L for some v in {0,1}*}, in other words init(L) is the set of prefixes of L. Let L= {w|w is nonempty and has an equal number of 0.s and 1's} Then init(L) is (A) the set of all binary strings with an unequal number of 0's and 1's (B) the set of all binary strings including the null string (C) the set of all binary strings with exactly one more 0's than the number of 1's or one more 1 then the number of 0's. (D) None of the above SOLUTION 2.2.17 Page 64 of 345
  65. 65. ANSWER--------------(B) (A) is excluded as init contains 0011 (C) is excluded as init contains 00000 (D) is allowed as init contains any sequence of 0s and 1s in any order. ******** QUESTION 2.2.18 Let G be a context-free grammar where G= ({S,AB,C},{a,b,d},P,S} with the productions in P given below. S-------------->ABAC S--------------->aA|e S--------------->bB|e C--------->d (e denotes the null string). Transform the grammar G to an equivalent context-free grammar that has no eproductions and no unit productions. ( A unit production is of the form x----->y, where x and y are nonterminals). SOLUTION 2.2.18 Q11. Eliminating A------------>e we get the rules S--------->ABC|BAC|BC A--------->a By eliminating B----------->e we get the rules S----------->AC|AAC|C B---------->b After eliminating the e rules we get Page 65 of 345
  66. 66. S--------->ABAC|ABC|BAC|BC|AC|AAC|C A--------->aA|A B--------->bB|B C-------->D After the elimination of the unit production we get S---------->ABAC|ABC|BAC|BC|AC|AAC|d A----->aA|A B--------->bB|B C---------->D ******** QUESTION 2.2.19 Let Q = ({q1,q2},{a,b},{a,b,Z},f,{q1,q2},Z,0) be a push down automaton accepting by empty stack the language which is the set of all nonempty even palidromes over the set {a,b}. Below is an incomplete specification of the transitions for Q. Complete the specification. The top of the stack is assumed to be at the right end of the string representing the stack contents. (1) f(q1,a,Z) = {(q1,Za)} (2) f(q1,b,Z) = {(q1,Z)} (3) f(q1,a,a)= {-----------,-----------} (4) f(q1,b,b)={----------,------------} (5) f(q2,a,a)={(q2,e)} (6) f(q2,b,b)={(q2,e)} (7) f(q2,e,Z)={(q2,e)} SOLUTION Q2.2.19 The only rules to be added are those which guess the center of the string Page 66 of 345
  67. 67. for (3) add{(q1,aa),(q2,e)} for (4) add {(q1,bb),(q2,e)) ******** QUESTION 2.2.20 Which of the following languages over {a,b,c} is accepted by a deterministic push down automaton? (A) {wcwR| w in(1+b)*} (B) {wwR|w in {a,b,c}*} (C){a^n b^n c^n|n>=0} (D) { w| w is a palidrome over {a,b,c} Note:- wR is obtained by reversing the string "w". SOLUTION 2.2.20 ANSWER---------(A) (A) is a standard DCFL. Push the elements onto the stack for w and at c change from a push to a poping state. for wR pop the strings. If the stack becomes empty at the end then accept. (B) is a standard CFL which is not a DCFL. (C) is a standard csl which is not a CFL, as shown by the pumping lemma for CFLs. (D) includes palidromes of odd length so a dpda cannot guess the center of the string. ******** QUESTION 2.2.21 Consider the grammar S---------------->bSe S--------------->PQR P----------------->bPc Page 67 of 345
  68. 68. P------------->epsilon Q----------->cQd Q--------->epsilon R---------->dRe R---------->epsilon where S,P,Q,R are non-terminals with S being the start symbol; bc,c,d,e are terminal symbols and "epsilon" is the empty string. This grammar generates strings of the form b^i c^j d^k e^m for some i, j,k, m <=0. (a) what is the condition on the values of u, j, k ,m? (b) Find the smallest string that has two parse trees. SOLUTION 2.2.21 Q(a). Note that P---------->*bi ci, i>=0 Note that Q--------------->*cj dj, j>=0 Notes that R--------------->dk ek, k>=0 From the first production we have S-------->bSe---------->bPQRe So S-------------->b bi ci cj dj dk ek e=b^(1+1) c^(i+j) d^(j+k) e^k, i,j,k>=0 Q(b) Consider the string bcde. S------->bPQRe----------->b epsilon cQd epsilon e -------------->* bcde or we have the derivation S-------------->PQR--------->bc Q de------------->bcde Both the above can be formualted as two distinct leftmost derivations. So bcde has two parse trees. The language always has strings with an even number of strings. We cannot have a string of lenght 2 or 0. The pairs are b,c or c,d or d,e or b,e. So bcde is the shortest string which can have two derivations. Of course be can be generated by the grammar but it has a unique derivation tree. Page 68 of 345
  69. 69. ******** QUESTION 2.2.22 Let M = ({q0,q1},{0,1},{z0,x},f,z0,0) be a pushdown automaton where f is given by f(q0,1.z0) = {(q0,x,z0)} f(q0,e,z0) = {(q0,e)} f(q0,1,X) = {(q0,XX)} f(q1,1,X) = {(q1,e)} f(q0,0,X) = {(q1,X)} f(q1,0,z0) = {(q0,z0)} (a) What is the language accepted by this PDA by empty store? (b) Describe informally the working of the PDA? SOLUTION Q2.2.22 Let R1=f(q0,1,Z0)={(q0,XZ0)} R2=f(q1,e,Z0)={(q0,e)} R3=f(q0,1,X)={(q0,XX)} R4=f(q1,1,X)={(q1,e)} R5=f(q0,0,X)={(q1,X)} R6=f(q1,0,X0)={(q0,Z0)} 1. R1,R2 and R3 consume n>1 number of 1's and push an equal number of X's onto the pushdown store with the state remaining the same as q0. 2. R5 rejects a single 0 and the pda makes a transition to the state q1. 3. In R4 we consume n number of 1's and pop an equal number of X's from the stack with the PDA ending up in state q1. Page 69 of 345
  70. 70. 4. In R6, one more 0 is rejected, and the PDA ends up in state q0. 5. R2 allows the stack to be emptied allowing the PDA to accept The language accepted by empty stack is L={1^n 0 1^n 0| n > 1} ******** QUESTION 2.2.23 Let G1 =(N,T,P,S1) be a CFG where, N = {S1,A,B} T= {a,b} and P is given by S1---------->a S1 b S1-------->a Ab A--------->aA A-------->a S1---->aBb B---------->bB B---------->b What is L(G1)? (b) Use the grammar in Part(a) to give a CFG for L2 =(a^ib^ja^kb^l|i,j,k,l>=1, i=j or k = l} by adding not more than 5 production rules. (c) Is L2 inherently ambiguous? SOLUTION Q2.2.23 Q(a). The first choice of productions gives S---------->* an A bn or S--------------------->*am B bm A generates a+ and B generates b+ Page 70 of 345
  71. 71. So the set generated is L={an bm|n.m>1, |n-m|>1] Q(b). The new grammar is P1: S1--------------->aS1 ba S1b P2: S1------------------>aAb P3:A------------------------>aAb P4:A----------------->ab P5: S1-------------->aBb P6:B-------------->aBb P7:B----------->ab The rules P1,P2,P4, P6 and P7 have been added. ******** QUESTION 2.2.24 Context-free languages are closed under: (A) Union, intersection (B) Union, Kleene closure (C) Intersection, complement (D) Complement, Kleene closure SOLUTION Q2.2.25 ANSWER IS (A) and (B) ******** Page 71 of 345
  72. 72. QUESTION 2.2.26 Q1.6 Let Ld be the set of all languages accepted by a PDA by final state and Le be the set of all languages accepted by empty stack. Which of the following is true? (A) Ld = Le (B) Ld is a superset of Le (C) Ld is a subset of Le (D) None of the above Solution Q 2.2.26 The sets accepted by pda by final state or empty stack are alternative definitions for the sets accepted and in both cases it is the cfls that are accepted. ******** QUESTION 2.2.27 Show that the language L = {xcx|x in {0,1}* and c is a terminal symbol} is not context free, with c not the same as o or 1. SOLUTION 2.2.27 The language is not a cfl. Intersect the language with0*1*c0*1*, the resulting language can be shown not to be a cfl by an application of the pumping lemma. ******** QUESTION 2.2.28 Let L denote the language generated by the grammar S----->0S0|00. Which of the following is true? A. L = 0+ B. L is regular but not 0+ C. L is context free but not regular D. L is not context-free Page 72 of 345
  73. 73. SOLUTION 2.2.28 ANSWER--------(B) L is (00)+ as the 0's always occur in pairs. (D) is not correct as the grammar is a cfg. (A) is excluded as 00 is in the language generated. ******** QUESTION 2.2.29 Consider the grammar S----------------->aSAb S------------->e A--------------->bA A--------------->e where S, A are non-terminal symbols with S being the start symbol; a, b are terminal symbols and e is the empty string. This grammar generates strings of the form a^ib^j for some i,j>=0, where i and j satisfy some condition. What is the condition on the values of i and j? SOLUTION 2.2.29 By examination it seen that the first production will demand the same number of b's as a's.A can optionally yield extra b's. So we have j>i as the required condition. ******** QUESTI9N 2.2.30 CS8. A push down automaton (pda) is given in the following extended notation of finite state diagrams: Page 73 of 345
  74. 74. The nodes denote the states while the edges denote the moves of the pda. The edge labels are of the for d, s/s' where d is the ilnput symbol read and s, s' are the stack contents before and after the move. For example, the edge labeled , s/1.s denotes the move from state q0 to q0 in which the input symbol 1 is read and pushed to the stack. (a) Introduce two edges with appropriate labels in the above diagram so that the resulting pda accepts thelanguage {x2xR|x in {0,1}*, xR denotes reverse of x}, by empty stack (b) Describe a nondeterministic pda with three states in the above notation that accepts the language {0^n1^m|n <= m <= 2n} by empty stack. SOLUTION 2.2.30 Q(a) q0 is a push state which pushes 0's and 1's onto the stack. So we have del(q0,2,s)=(q0,2.s) q1 is a pop state so we have del(q1,2,2.s)=(q1,s) Page 74 of 345
  75. 75. Q(b) q0 and q1 will be push states where for every 0 in the input we nondeterministially push one or two 0's onto the stack. del(q0,0,s)={(q0,0.s),(q2,0.s)} del(q2,e,s)={(q0,0.s)} When a 1 occurs we nondeterministically unstack one or two 0's from the stack. del(q0,1,0.s)={(q1,s)} del(q0,e,s)={(q1,s)} In q1 the pop state we unstack one or two 0's for a 1 in the input. del(q1,1,0.s)={(q1,s),(q2,s)} del(q2,1,0.s)={(q1,s)} ******** QUESTION 2.2.31 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 context free languages is context free D. The complement of a context free language is context free SOLUTION Q2.2.31 ANSWER-------(B) The union of two cfls is a cfl. The deterministic and nondeterministic models of the pda are not the same. The cfls are not closed under intersection or complement. ******** Page 75 of 345
  76. 76. QUESTION 2.2.32 The language accepted by a Pushdown Automaton in which the stack is limited to 10 items is best described as A. Context Free B. Regular C. Deterministic Context Free D. Recursive SOLUTION 2.2.32 ANSWER----------(B) If the stack is limited to 10 items then the pda can remember the contents of the stack in its finite control. Thus the pda becomes a finite automata. Hence the language accepted is regular. ******** QUESTION 2.2.33 Let G =({S},{a,b},R,S) be a context free grammar where the rule set R is S---------->aSb|SS|e Which of the following statements is true? (a) G is not ambiguous. (b) There exist x, y in L(G) such that xy is not in L(G). (c) There is a deterministic pushdown automaton that accepts L(G). (d) We can find a deterministic finite state automaton that accepts L(G) SOLUTION Q2.2.33 Q51. ANSWER---------(C) e (the empty string) has an infinite number of derivation trees and this excludes (A). We can rewrite the grammar as S--------->(S)|SS|e and thus the language generated is nothing but the set of all balanced parentheses. Parenthesis matching cannot be done by a finite Page 76 of 345
  77. 77. automata and this excludes (C). The concatentation of any two strings of balanced parenthesis is a balanced parenthesis string and this excludes (B). Parentheses mathcing can be done by a dpda and hence ( C) is the answer. ******** QUE4STION 2.2.34 The language {a^m 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 SOLUTION 2.2.34 ANSWER---------(B) One can easily design a dpda which pushes a's and b's onto the stack and for every c in the input it pops and a or a b. ******** QUESTION 2.2.35 Q88. Consider the following grammar G: S---->bS|aA|b A---->bA|aB B---->bB|aS|a Let Na(w) and Nb(w) denote the number of a's and b's in a string w respectively. The language L(G) a subset of {a,b}+ generated by G is (A) {w|Na(w)>3Nb(w)} (B) {w|Nb(w) >3Na(w)} (C) {w|Na(w)=3k, k in {0,1,2,---}} Page 77 of 345
  78. 78. (D) {w|Nb(w) =3k, k in {0,1,2,---}} SOLUTION 2.2.35 ANSWER------(C) S----->b+ by the first set of rules S--->bS|S, this eliminates choices (A) and (D) S-------->aaa by S--->*aA---->*aaB--------->aaa and this eliminates (B) ******** QUESTION 2.2.36 Let M=(K,X,G,D,s,F) be a pushdown automaton, where K={s,f}, F={f}, X={a,b} and G={a} and D={((s,a,e),(s,a)),((s,b,e),(s,a)),((s,a,e),{f,e)),((f,a,a),(f,e)),((f,b,a).(f,e))} Which one of the following strings is not a member of L(M)? (A) aaa (B) aabab (C) baaba (D) bab SOLUTION 2.2.36 ANSWER------(B) The fastest way is to trace out all the strings. ANSWER-----(B) The move ð(A,a)=A demands the rule A---->aA and this excludes (A) and (C) The move ð(A,b)=B demands the rule A--->bB and this excludes (D) ********* Page 78 of 345
  79. 79. QUESTION 2.2.37 [THEORY OF COMPUTATION] The language L = { 0i21j |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 Answer: (B) Explanation: One can easily design a deterministic push down automata which scans the input left to right, when a 0 is encountered it stacks it, and moves to the right. When a 2 is encountered it switches from a stacking to a pop state and so long as a 1 comes in the input it pops a 0. When the input is exhausted and the stack is empty it goes to a final state. ******** Page 79 of 345
  80. 80. 2.3 TURING MACHINES AND R.E. SETS [GATE CSE 2013 TURING MACHINES & UNDECIDABILITY] QUESTION 2.3.1 Which one of the following statements is/are FALSE? 1. For every non-deterministic Turing machine, there exists an equivalent deterministic Turing machine 2. Turing recognizable languages are closed under union and complementation 3. Turing decidable languages are closed under intersection and complementation 4. Turing recognizable languages are closed under union and intersection (A) 1 and 4 only (B) 1 and 3 only (C) 2 only (D) 3 only QUESTION 2.3.1 WITH KEY ANSWER IS (C) QUESTION 2.3.1 WITH KEY AND SOLUTION SOLUTION We will consult a pseudo-Venn diagram. Page 80 of 345
  81. 81. TURING RECOGNISABLE LANGUAGES TURING DECIDABLE LANGUAGES NDTM=DTM RECURSIVE SETS-CLOSED UNDER UNIO, INTERSECTION AND COMPLEMENT R.E. SETS CLOSED UNDER UNION, AND COMPLEMENT INTERSECTION AND NOT UNDER COMPLEMENT NTM=DTM Answer is (C). ******** QUESTION 2.3.2 State the halting problem of Turing Machines. SOLUTION 2.3.2 It is undecidable whether a Turing Machine once started will halt. ******** Question 2.3.3 Recursive languages are: (A) a proper subset of context-free languages. (B) always recognisable by pushdown automata (C) also called Type 0 languages. (D) recognisable by Turing machines. SOLUTION Q2.3.3 ANSWER--(A) AND (D) Page 81 of 345
  82. 82. The recursive languages are a superset of the cfls. Only we are ignoring epsilon which cannot be in any csl or recursive set. pda can accept only the cfls, {an bn cn|n>1} is a csl and not a cfl and no pda can accept it. The r.e languages are the Type 0 languages which are a superset of the recursive sets. Turing machines accept all the recursive set and more(i.e. the r.e. sets also). ******** QUESTION 2.3.4 Show that Turing machines, which have a read only input tape and a constant work size tape, recognize precisely the class of regular languages. SLUTION 2.3.4 If we take a turing machine and take away its ink it becomes a 2DFA or 2NFA. We have the standard theorem that these accept only the regular sets. ******** QUESTION 2.3.5 In which of the cases stated below is the following statement true? "For every nondeterministic machine M1 there exists an equivalent deterministic machine M2 recognizing the same language". (A) M1 in a nondeterministic finite automaton. (B) M1 is a nondeterministic PDA (C) M1 is a nondeterministic Turing machine (D) For no machine M1 is the above statement True SOLUTION 2.3.5 ANSWER (A) AND (C) For the pda the nondeterministic model is more powerful than the deterministic one. {wwR} the language of palidromes is accepted by the former and not the latter. For the fa and turing machines the nondeterminsitic and deterministic models are equivalent. Page 82 of 345
  83. 83. ******** QU3STION 2.3.6 Which of the following three statements are true? Prove your answer. (i) The union of two recursive languages is recursive. (ii) The language {0^n | n is a prime } is not regular. (iii) Regular languages are closed under infinite union. SOLUTION Q2.3.6 ANSWER (i) AND (ii) The recursive sets are closed under union and the language of primes in unary is not regular. For the latter we see that the primes cannot be in any arithmetic progression and thus we cannot satisfy the weak form of the pumping lemma for regular sets. Any formal language is the infinite union of finite singleton sets, one set for each element of the language. Hence infinite union does not preserve the regular sets. ******** QUESTION 2.3.7 Given a set S = {x | there is an x-block of 5's in the decimal expansion of pi} (note: x-block is a maximal block of x successive 5's) Which of the following statements is true with respect to S? (i) S is regular (ii) S is recursively enumerable (iii) S is not recursively enumerable (iv) S is recursive SOLUTION 2.3.7 Q19(a) ANSWER (ii) Page 83 of 345
  84. 84. We just run a turing machine designed to compute pi to better and better approximations. If it happens to yield a x-block of 5's we stop. (i) is excluded as a fa cannot count. We cannot guarentee an algorithm at present and so this excludes S. ******** QUESTION 2.3.8 Let L be a language ove X i.e. L is a subset of X*. Suppose L satisfies the two conditions given belwo (i) L is in NP and (ii) For every n, there is exactly one string of length n that belongs to L. Let Lc be the complement of L ove X* and show that Lc is also in NP. SOLUTION Q2.3.8 For every n there is exactly one string in L. There are only a finite number of strings of length n. Create so many copies of the turing machine and run them one for each string of length n. One of the copies will terminate in polynomial time then terminate the others which accept strings in the complement of L. So we can decide if a string is in L or not in a polynomial amount of time so the complement of L is also in NP. ******** QUESTION 2.3.9 Regarding the power of recognition of languages, which of the following statements is false? (a) The non-deterministic finite-state automata are equivalent to deterministic finite-state automata. (b) Non-deterministic Push-down automata are equivalent to deterministic push-down automata. (c) Non-deterministic Turing machines are equivalent to deterministic Turing machines. (d) Multi-tape Turing machines are equivalent to single-tape Turing machines. Page 84 of 345
  85. 85. QUESTION 2.3.9 ANSWER-------------(B) AND (C) The deterministic and nondeterministic models of the pushdown automata are not the same. The deterministic and nondeterministic models of finite auomata are the same and the same statement holds for turing machines. ******** QUESTION 2.3.10 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. SOLUTION 2.3.10 ANSWER --------------(A) The recursive sets are closed under complement, wheras the r.e sets are not. The cfls are not closed under complement. ******** QUESTION 2.3.11 The aim of the following question is to prove that the language {M| M is the code of a Turing Machine which, irrespective of the input, halts and outputs a 1} is undecidable. This is to be done by reducing from the language {M',x|M' halts on x}, which is known to be undecidable. In parts (a) and (b) describe the tow main steps in the construction of M. In part(c) describe the key property which relates the behaviour of M on its input w to the behaviour of M' on x. (a) On input w, what is the first step that M must make? (b) On input w, based on the outcome of the first step, what is the second step that M must make? Page 85 of 345
  86. 86. (c) What key property relates the behaviour of M on w to the behaviour of M' on x? SOLUTION 2.3.11 (a) M operates with input w (b) When M halts it starts M' (c) Rice's theorem, the moidfied version of M' accepts the set of entire strings over the terminal vocabulary or the empty set depending on whether the universal lanugae accepted by M is decidable or not. ******** QUESTION 2.3.12 Ram and Shyam have been asked to show that a certain problem II is NP-complete. Ram shows a polynomial time reduction frin tge 3-SAT problem to II, and Shyam shows a polynomial time reduction fro II to 3-SAT. Which of the following can be inferred from these reductions? (a) II is NP-hard but not NP-complete (b) II is is NP, but is not NP-complete (c) II is NP-complete (d) II is neither NP-hard. nor in NP SOLUTION 2.3.12 ANSWER--------------------(C) 3-SAT is a standard NP-complete problem so both the problems are NP-complete. ******** QUESTION 2.3.13 Nobody knows yet if P=NP. Consider the language L defined as follows: L=(0+1)* if P=NP L=null set otherwise Which of the following statements is true? Page 86 of 345
  87. 87. (a) L is recursive (b) L is recursively enumerable but not recursive (c) L is not recursively enumerable (d) Whether L is recursive or not will be known after we find out if P=NP SOLUTION 2.3.13 ANSWER---------------(A) (0+1)* is a regular set and hence it is recursive, the null set is recursive. Hence whether P= NP or not both choices yield recursive as the answer. ******** QUESTION 2.3.14 If the strings of a language L can be effectively enumerated in lexicographic (i.e alphabetic) order, which of the following statements is true? (a) L is necessarily finite (b) L is regular but not necessarily finite (c) L is context free but not necessarily regular (d) L is recursive but not necessarily context free. SOLUTION 2.3.14 ANSWER-------------(D) It is a standard theorem that if we can lexicographically enumerate a r.e. set then the set is recursive. To check if a string is in the r.e. set we enumerate strings till we get some string of longer length accepted, then we can decide the membership problem. ******** QUESTION 2.3.15 Page 87 of 345
  88. 88. Consider two languages L1 and L2 each on the alphabet X. Let f:X--->X be a polynomial time computable bijection such that [for all x, x in L1 iff f(x) is in L2]. Further, let f^-1 be also polynomial time computable. Which of the following CANNOT be true? (a) L1 is in P and L2 is finite. (b) L1 is in NP and L2 is in P. (c) L1 is undecidable and L2 is decidable. (d) L1 is recursively enumerable and L2 is recursive. SOLUTION 2.3.15 ANSWER---------------(C) To see a simple solution let us take the special case of L1=L2=L. (A) It is possible now that L2 is finite and L1 is trivially in P, as every finite set is in P. (B) L2 in P means L1 can be in NP as every language in P is trivially in NP. (D) L2 is recursive and L1 in r.e. sets is possible as every recursive set is trivially r.e. So by elimination we have (C) as the answer. Evidently if L1 is undecidable then then it cannot be recursive like L2. ANSWER---------(A) Let us eliminate the cases. Consider the machine on blank tape then e is the input. On a B the machine halts. This excludes (B). It is easy to check that the machine loops on inputs 0 and 1. Thus (A) is the answer. ******** QUESTION 2.3.16 Page 88 of 345
  89. 89. 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 1 B q0 q1, 1, R q1, 1, R Halt q1 q1, 1, R q0, 1, L 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 tape square, then it writes a 1 on the same tape square, moves its tape head one position to the right and transitions to state q1. (a) M does not halt on any string in (0+1)+ (b) M does not halt on any string in(00+1)* (c) M halts on all strings ending in a 0 (d) M halts on all strings ending in a 1 SOLUTION 2.3.16 ANSWER---------(A) Let us eliminate the cases. Consider the machine on blank tape then e is the input. On a B the machine halts. This excludes (B). It is easy to check that the machine loops on inputs 0 and 1. Thus (A) is the answer. ******** QUESTION 2.3.17 Define languages L0 andL1 as follows: L0={<M,w,0>| M halts on w} L1={<M,w,1>| M does not halt on w} Page 89 of 345
  90. 90. 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 = L0 U L1. Which of the following is true? (a) L is recursively enumerable, but L' is not. (b) L' is recursively enumerable, but L is not (c) Both L and L' are recursive d) Neither L nor L' is recursively enumerable Note:-L' is the complement of L SOLUTION 2.3.17 ANSWER-------------(D) If L is r.e. then we have a turing machine M accepting it. Let M be an enumerator(any turing machine can be considered to be an enumerator). Then for any Turing Machine M' and input w' in a finite amount of time M will enumerate the string <M',w',0> or <M',w',1> thus deciding if M' on input w' halts or not. Such a machine cannot exist. Consider the complement of L=L', accepted by a turning machine M1. If a machine M1 exists then it will enumerate either< M',w',0> or <M',w',1> in a finite amount of time resolving the halting problem. So L' cannot be r.e. ******** Page 90 of 345
  91. 91. 2.4 UNDECIDABILITY [GATE CSE 2013—UNDECIDABILITY] QUESTION 2.4.1 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 (D) 2 and 3 only QUESTION 2.4.1 WITH KEY ANSWER IS (D) QUESTION 2.4.1 WITH KEY AND SOLUTION SOLUTION The case(1) is decidable. If the reduced cfg vanishes then the empty set is generated. This excludes choice (C). For (4) We can obtain the minimal dfa’s and check to see if the transition diagrams are isomorphic. This excludes choice (B). Only some turing machines accept regular sets. Not all of them or none of them. So by Rice’s theorem (3) is undecidable. The invalid computations of a turing machine are given by a cfl. If we can decide if this is Σ* then we can decide if the complement is empty. Then we can decide if the valid computations of a turing machine are empty, solving the halting problem. So (2) is undecidable. Page 91 of 345
  92. 92. Answer is (D). ******** QUESTION 2.4.2 Which of the following problems are undecidable?: (A) Membership problem in context-free languages. (B) Whether a given context-free language is regular. (C) Whether a finite state automation halts on all inputs. (D) Membership problem for type 0 languages. SOLUTION Q2.4.2 ANSWER---------(B) AND (D) The membership problem for cfls is decidable, we have the CYK algorithms or we have general parsing algorithms for cfls. The halting problem of fa is decidable trivially. It is undecidable if a given cfg is regular, or whether a turing machine accepts a particular string. ******** QUESTION 2.4.3 Q3(vii) It is undecidable whether: (A) an arbitrary Turing machine halts after 10*phi steps. (B) a Turing machine prints a specific letter. (D) a Turing machine computes the product of two numbers. Note:- Choice (C) is absent in the question paper copy available to me. SOLUTION 2.4.3 Page 92 of 345
  93. 93. Q3(vii) ANSWER----(B) AND (D) No nontrivial problem is decidable for an arbitary turing machine. Given an arbitrary turing machine we cannot decide if it prints a specific letter(the Printing problem) or computes the product of two numbers. We can decide if it halts after 10 *phi steps provided phi is a constant, not otherwise. Turing machines have the capability of multiplication, but whether a given turing machine will compute the product of two numbers is not decidable as we cannot decide anything for an arbitrary turing machine. So (D) depends on how the problem is posed. ********* QUESTION 2.4.4 Q1.16 Which of the following conversions is not possible (algorithmically)? (A) Regular grammar to context-free grammar (B) Non-deterministic FSA to deterministic FSA (C) Non-deterministic PDA to deterministic PDA (D) Non-deterministic Turing machine to deterministic Turing machine SOLUTION 2.4.4 ANSWER (A) AND (B) A regular grammar is trivially a context free grammar. There are algorithms to convert nfa and nondeterministic turing machines to deterministic machines accepting the same set. For finite automata it is the subset machine. For turing machines we number the moves and generate ordered sequences of integers and map the same to the moves. The nondeterminsitic pda is more powerful than a deterministic one. The former can accept {ai bn cn|i,n>1} U Page 93 of 345
  94. 94. {aj bj cm|j,m>1} but the latter cannot. ******** QUESTION 2.4.5 Which of the following statements is false? (A) The Halting problem of Turing machines is undecidable. (B) Determining whether a context free grammar is ambiguous is undecidable. (C) Given two arbitrary context free grammars G1 and G2 it is undecidable whether L(G1)=L(G2). (D) Given two regular grammars G1 and G2 it is undecidable whether L(G1)=L(G2). SOLUTION 2.4.5 ANSWER----------(d) The hating problem is undecidable for turing machines, the equivalence of cfs and ambiguity of a cfg are standard undecidable problems. The equivalence of fa is decidable. Convert each to the minimal dfa and see if the graphs are isomorphic. ******** QUESTIONJ 2.4.6 Give X={a,b}, which of the following sets is not countable? (A) Set of all strings over X (B) Set of all languages over X (C) Set of all regular languages over X (D) Set of all languages over X accepted by Turing machines SOLUTION Q2.4.6 ANSWER (B) The set of all formal languages is an uncountable set. Page 94 of 345
  95. 95. (A) the set of all strings is a regular set which is countably infinite. We can enumerate all strings in increasing order of length and within the same length put them in lexicograpic order. The we can number the strings we have enumerated. (C) All regular sets are given by all regular grammars. Regular grammars are a finite description so we can enumerate them. (D) A turing machine is a finite description over a finite alphabet. We can encode all turing machines as strings in the alphabet {0,1} and then enumerate all strings over the alphabet and throw away all illformed strings. ******** QUESTION 2.4.7 Q6.5 Which one of the following is not decidable? (A) Given a turing machine M, a string s and an integer k, M accepts s within k steps (B) Equivalence of two given turing machines (C) Language accepted by a given finite state machine is non-empty. (D) Language generated by a context-free grammar is non-empty. SOLUTION Q2.4.7 Q6.5 ANSWER ----------- (B) (A) Simply run the turing machine for k steps, then in a finite amount of time we know if s is accepted ornot. (C) and (D) form the reduced grammar, if all productions do not vanish the language generated is non-empty. (B) All nontrivial problems of turing machines are undecidable, so (B) is undecidable. The equivalence problem is decidable only for regular sets. ******** QUESTION 2.4.7 Consider the following decision problems: (P1) Does a given finite state machine accept a given string. Page 95 of 345
  96. 96. (P2) Does a given context free grammar generate an infinite number of strings. Which of the following is true? A. Both (P1) and (P2) are decidable. B.Neither (P1) nor (P2) is decidable C. Only (P1) is decidable D. Only (P2) is decidable SOLUTION 2.4.7 ANSWER-----------(A) For P1 simply trace the path through the state diagram of the finite automata. For P2 take the reduced grammar in the CNF and draw the graph of the grammar. If cycles exist the cfl is infinite else it is finite. ******** QUESTION 2.4.8 Consider the following problem X. Given a Turing machine M over the input alphabet X, any state q of M and a word w in X*, doe sthe computatio9n of M on w visit the state q? Which of the following statements about X is correct? A. X is decidable B. X is undecidable but partially decidable C. X is undecidable and not even partially decidable. D. X is not a decision problem. SOLUTION 2.4.8 ANSWER-----------(B) Just start the turing machine and sit in front of it. If it visits the state q we will know in a finite amount of time else we may never know. Page 96 of 345
  97. 97. ********* QUESTION 2.4.9 THEORY OF COMPUTATION] [TOPIC:UNDECIDABILITY] Which of the following problems is undecidable? (A) Membership problem of CFLs (B) Ambiguity problem of CFGs (C) Finiteness problem for FSAs (D) Equivalence problem for FSAs SOLUTION: Q6 Answer: (B) EXPLANATION: For the membership problem we have the CYK algorithm or any parsing algorithms of CFGs which uses backup. The finiteness problem of FSAs is to merely ensure that there is no cycle in the state diagram of the finite state machine. For any two regular sets L1 and L2 we have L1=L2 iff L1.L2’ U L2.L1’ is empty. Since the regular sets are closed under union and intersection the equivalence problem is decidable. A standard undecidability result is the determination of the ambiguity of CFGs. ******** Page 97 of 345
  98. 98. CHAPTER 3 COMPILER DESIGN Page 98 of 345
  99. 99. 3.1 LEXICAL ANALYSIS Page 99 of 345
  100. 100. 3.2 PARSING [QUESTIONS ON LANGUAGE PROCESSORS—PARSING] QUESTION 3.2.1 What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon moves and unit-production (i.e. of type A→ 𝜀 𝑎𝑛𝑑 𝐴 → 𝑎) to parse a string of n tokens? (A) n/2 (B) n-1 (C) 2n-1 (D) 2 𝑛 QUESTION 3.2.1 WITH KEY ANSWER IS (B) QUESTION 3.2.1 WITH KEY & SOLUTION SOLUTION Granting the examiner his right to typographical errors we correct unit productions as AB. Now to solve the problem use the method of elimination. Take the grammar Sa generating the set {a}. The grammar is trivially a LR(0) grammar with one reduce state. So n=1 tokens requires 1 reduce move in the finite automata. Page 100 of 345
  101. 101. So by elimination the answer is (B), granting the examiner one more right to his typographical errors and making choice (B) n-1. Answer is (B). ******** [GATE CSE 2013—PARSING] QUESTION 3.2.2 Consider the following two sets of LR(1) items of an LR(1) grammar 𝑋 → 𝑐, 𝑋, 𝑐|𝑑 𝑋 →. 𝑐𝑋, 𝑐|𝑑 𝑋 →. 𝑑, 𝑐|𝑑 𝑋 → 𝑐. 𝑋, $ 𝑋 →. 𝑐𝑋. $ 𝑋 → 𝑑. , $ Which of the two statements relating to the merging of the two sets in the corresponding LALR(1) parser is/are FALSE? 1. 2. 3. 4. Cannot be merged since look-ahead sets are different Can be merged but will result in a S-R conflict An be merged but will result in a R-R conflict Cannot be merged since goto on c will lead to different states (A) 1 only (B) 2 only (C) 1 and 4 only (D) 1,2,3 and 4 QUESTION 3.2.2 WITH KEY ANSWER IS (D) QUESTION 3.2.2 WITH KEY AND SOLUTION SOLUTION Page 101 of 345
  102. 102. No conflicts arise and the states can be merged. Answer is (D). ******** Question 2.2.3 . [LANGUAGE PROCESSORS] Which of the following is a top-down parser? (A) Recursive descent parser (B) Operator precedence parser (C) An LR(k) parser (D) An LALR(k) parser Answer: (A ) Explanation: A recursive descent parser is nothing but an LL(1) parser. ******** Page 102 of 345
  103. 103. 3.3 SYNTAX DIRECTED TRANSLATION Page 103 of 345
  104. 104. 3.4 CODE GENERATION AND CODE OPTIMISATION [GATE CSE 2013—CODE OPTIMISATION] QUESTION 3.4.1 Common data for two questions The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have at most 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 Page 104 of 345
  105. 105. d = d * d, e = e * e, } Question 1. 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 in the compiled code? (A) 0 (B) 1 (C) 2 (D) 3 QUESTION 2 What is the minimum number of registers needed in the instruction set architecture of the processor to compile the code segment without any spill to the memory? Do not apply any other optimization than register optimizing register allocation (A) 3 (B) 4 (C) 5 (D) 6 QUESTION 3.4.1 WITH KEY QUESTION 1 IS (B) & QUESTION 2IS (A) QUESTION 3.4.1 WITH KEY AND SOLUTION SOLUTION Use the following code motion: c = a + b; R1 HAS a, R2 HAS b, SUM GOES TO R2, SPILL c FROM R2 HERE Page 105 of 345
  106. 106. x= c * c; if(x > a){ d = c * a; USE c FROM MEMORY, e = c + a; LOAD INTO R2 y = a * a; }else { d = c *a; USE c FROM MEMORY, d = d * d; LOAD INTO R2 e = c + a; e = e * e; } At most one spill is required. If a third register is there it can store c. No spills are needed with 3 registers, Answer for QUESTION1 IS (B). Answer for QUESTION 2 IS (A). ******** Page 106 of 345
  107. 107. CHAPTER 4 DBMS Page 107 of 345
  108. 108. 4.1 ER-DIAGRAMS Page 108 of 345
  109. 109. 4.2 FUNCTIONAL DEPENDENCIES AND NORMALISATION [GATE CSE 2013—FUNCTIONAL DEPENDENCIES] QUESTION 4.2.1 Statement for Linked Answer Questions Relation R has eight attributes ABCDEFGH. Fields of R contain only atomic values. 𝐹 = {𝐶𝐻 → 𝐺, 𝐴 → 𝐵𝐶, 𝐵 → 𝐶𝐹𝐻, 𝐸 → 𝐴, 𝐹 → 𝐸𝐺} Is a set of functional dependencies (FDs) so that F* is exactly the set of FDs that hold R. QUESTION 1 How many candidate keys does the relation R have? (A) 3 (B) 4 (C) 5 (D) 6 QUESTION 2 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 QUESTION 4.2.1 WITH KEY Page 109 of 345
  110. 110. ANSWER FOR QUESTION 1IS (B) ANSWER FOR QUESTION 2 IS (A) QUESTION 4.2.1 WITH KEY AND SOLUTION SOLUTION For candidate key select one of {A,B,E,F} follwed by D. So we have AD, BD, ED and FD, Answer for QUESTION 1 is (B). As ABC, BCFH, FEG are partial dependencies R is in 1NF. Answer for QUESTION 2 is (A). ******** Page 110 of 345
  111. 111. 4.3 SQL [QUESTION GATE CSE 2011 SQL] QUESTION 4.3.1 A database table y name Loan_Records is given below. Borrower Bank_Manager Ramesh Sunderajan Suresh Ramgopal Mahesh Sunderajan What is the output of the following SQL query? Loan_Amount 1(xxx).(x) 5(xxx).(x) 7(xx).(x) SELECT count(*) FROM( (SELECT Borrower, Bank_Manager FROM Loan_Records) AS S NATURAL JOIN (SELECT Bank_Manager, Amount FROM Loan_Records)AS T ; (A) 3 (B) 9 (C) 5 (D) 6 QUESTION 4.3.1 WITH KEY ANSWER IS (C) QUESTION 4.3.1 WITH KEY AND SOLUTION Page 111 of 345
  112. 112. 4.4 RELATIONAL ALGEBRA AND RELATIONAL CALCULUS Page 112 of 345
  113. 113. 4.5 TRANSACTION PROCESSING AND CONCURRENCY CONTROL Page 113 of 345
  114. 114. 4.6 FILE STRUCTURES AND INDEXING [GATE CSE 2013—INDEXING] QUESTION 4.6.1 An index is clustered, if (A) It is on a set of fields that form a candidate key (B) it is on a set of fields that include the primary key (C) The data records of the file are organized in the same order as the data entries of the index (D) The data records of the file are organized not in the same order as the data entries of the index QUESTION 4.6.2 WITH KEY ANSWER IS (C) QUESTION 4.6.3 WITH KEY AND SOLUTION An index is clustered if it is like a dictionary. Answer is (C). ******* Page 114 of 345
  115. 115. CHAPTER 5 COMPUTER NETWORKS Page 115 of 345
  116. 116. 5.1 FUNDAMENTALS OF CNW [GATE CSE 2013 COMPUTER NETWORKS] QUESTION 5.1.1 Assume that source S and destination D are connected through two intermediate routers labeled R. Determine how many times each packet has to visit the network layer and the data link layer during a transmission from S to D. S R R D (A) Network layer –4 times and Data link layer – 4 times (B) Network layer—4 times and Data link layer – 3 times (C) Network layer—4 times and Data link layer – 6 times (D) Network layer—2 times and Data link layer – 6 times QUESTION 5.1.1 WITH KEY ANSWER IS (C) QUESITON 5.1.1 WITH KEY ANSWER IS (C) ******* QUESTION 5.1.2 Using public key cryptography X adds a digital signature σ to message M, encrypts <M,σ>, and sends it to Y where it is decrypted. Which one of the following sequences of keys is used for the operations? Page 116 of 345
  117. 117. (A) Encryption X ‘is private key followed by Y’s private key. Decryption X’s public key followed by Y’s public key. (B) Encryption X ‘is public key followed by Y’s public key. Decryption X’s public key followed by Y’s private key. (C) Encryption X ‘is public key followed by Y’s private key. Decryption Y’s public key followed by X’s public key. QUESTION 5.1.2 WITH KEY ANSWER IS (D) QUESTION 5.1.2 WITH KEY AND SOLUTON SOLUTION X and Y should not have access to each other’s private key. By elimination (D) is the only solution. Answer is (D). ******** Page 117 of 345
  118. 118. 5.2 LAN [GATE CSE 2013---LAN] QUESTION 5.2.1 Determine the maximum length of the cable (in km) for transmitting data at a rate of 500Mbps in an Ethernet LAN with frames of size 10,000 bits. Assume the signal speed in the cable to be 2,00,000 km/s. (A) 1 (B) 2 (C) 2.5 QUESTION 5.2.1 WITH KEY ANSWER IS (B) QUESTION 5.2.1 WITH KEY AND SOLUTION SOLUTION The LAN transmits 500x106 bits in 1 sec. To transmit 10,000 bits it takes 1/(5x104) sec. The signal travels 2x105 km in 1 sec. In 1/(5x104) sec it travels [2x105]/[5x104]= 4 km. Page 118 of 345 (D) 5
  119. 119. The maximum length of the cable is thus 4/2 =2km. Answer is (B). ******** Page 119 of 345
  120. 120. 5.3 TCP/IP [QUESTION FROM GATE CSE 2013] QUESTION 5.3.1 The transport layer protocols used for real time multimedia file transfer, DNS and email, respectively are: (A) TCP, UDP,, UDP and TCP (B) UDP,TCP,TCP and UDP (C) UDP, TCP,UDP and TCP (D) TCP,UDP,TCP and UDP QUESTION 5.3.1 WITH KEY ANSWER IS (C) QUESTION 5.3.1 WITH KEY AND SOLUTION SOLUTION We will use the methode of elimination. Multimedia can lose a few bits of information and DNS is satisfied with UDP. So the answer is (C). ******** Page 120 of 345
  121. 121. 5.4 APPLICATION LAYER AND ROUTING Page 121 of 345
  122. 122. CHAPTER 6 OPERATING SYSTEMS Page 122 of 345
  123. 123. 6.1 PROCESS MANAGEMENT [QUESTIONS ON PROCESS MANAGEMENT] [GATE C SE 2013] QUESTION 6.1.1 A scheduling algorithm assigns priority proportional to the waiting time of a process. Every process starts with priority zero (the lowest priority). The scheduler re-evaluates the process priorities every T time units and decides the nex5 process to schedule. Which one of the following is TRUE if the processes have no I/O operations and all arrive at time zero? (A) This algorithm is equivalent to the first-come-first-serve algorithm. (B) This algorithm is equivalent to the round-robin algorithm. (C) This algorithm is equivalent to the shortest-job-first algorithm. (D) This algorithm is equivalent to the shortest-remaining-time-first algorithm. QUESTION 6.1.1 WITH KEY ANSWER IS (B) QUESTION 6.1.1 WITH KEY & SOLUTION We will use the method of elimination. Choice (A) is ruled ou7t as all the processes have come at the same time to zero. The algorithm does not worry about the requirements of the job insofar as its time requirements left or the overall time requirements. So choices (B) and (C) are ruled out, Page 123 of 345
  124. 124. By elimination the answer must be (B). ******** Page 124 of 345
  125. 125. 6.2 DEADLOCK Page 125 of 345
  126. 126. 6.3 MEMORY MANAGEMENT Page 126 of 345
  127. 127. 6.4 FILE SYSTEM AND DEVICE MANAGEMENT Page 127 of 345
  128. 128. CHAPTER 7 DAA Page 128 of 345
  129. 129. 7.1 ALGORITHM ANALYSIS AND ASYMPTOTIC NOTATION QUESTION 7.1.1 .[DAA: ANALYSIS] Consider the following segment of C –code: int j, n; j = 1; while ( j <= n) j = j *2; The number of comparisons made in the execution of the loop for any n > 0 is” (A) . log 2 n. + 1 (B) n (C) . log 2 n. (D) . log 2 n . +1 Answer: (A) Explanation: n comparisons Closest formula 1 1<=1,2<=1 TOTAL=2 ??????? 2 Page 129 of 345
  130. 130. 1<=2,2<=2 TOTAL=2 A,B,D 3 1<=3,2<=3,4<=3 TOTAL=3 B,A 4 1<=4,2<=4,4<=4,8<=4 TOTAL=4 A,D excluding termination test 8 1<=8,2<=8,4<=8,8<=8,16<=8 TOTAL=5 A ,D excluding termination test 5 1<=4,2<=4,4<=4,8<=4 TOTAL=4 A including termination test 6 1<=4,2<=4,4<=4,8<=4 TOTAL=4 A including termination test 12 1<=12,2<=12,4<=12,8<=12,16<=12 TOTAL=5 A including termination test ********* Page 130 of 345
  131. 131. 7.2 DIVIDE AND CONQUER QUESTION 7.2.1 . [DAA: SORTING] Which of the following sorting algorithms has the lowest worst-case complexity? (A) Merge sort (B) Bubble sort (C ) Quick sort (D) Selection sort Answer: (A) Explanation: ALGORITHM WORST CASE TIME COMPLEXITY MERGE SORT O(N LOG N) BUBBLE SORT O(N * N) QUICKSORT O(N * N) SELECTION SORT O(N * N) ******** Page 131 of 345
  132. 132. 7.3 GREEDY METHOD Page 132 of 345
  133. 133. 7.4 DYNAMIC PROGRAMMING Page 133 of 345
  134. 134. 7.5 SEARCH,TRAVERSAL, BRANCH & BOUND TECHNIQUES Page 134 of 345
  135. 135. 7.6 P=NP? Page 135 of 345
  136. 136. CHAPTER 8 DATA STRUCTURES Page 136 of 345
  137. 137. 8.1 ARRAYS Page 137 of 345
  138. 138. 8.2 STACKS AND QUEUES Page 138 of 345
  139. 139. 8.3 LINKED LISTS Page 139 of 345
  140. 140. 8.4 TREES [GATE CSE DATA STRUCTURES] QUESTION 8.4.1 Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary tree of n nodes? (A)) O(1) (B) O(log n) (C) O(n) (D) O(nlog n) QUESTION 8.4.1 WITH KEY ANSWER IS (C) QUESTION 8.4.1 WITH KEY AND SOLUTION Assume the elements to be inserted into the tree come in increasing order. Then we have a skewed tree. To insert a very large element into this requires walking down the tree. Time complexity is O(n). Answer is (C). ******** Page 140 of 345
  141. 141. [GATE CSE 2013—TREE TRAVERSAL] QUESTION 8.4.2 The postorder 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? QUESTION 8.4.2WITH KEY ANSWER IS (D) QUESTION 8.4.2 WITH KEY AND SOLUTION By trial and error the tree is as follows: 30 2 39 30 30 10 30 30 30 0 30 0 42 25 35 30 30 30 30 30 30 30 30 30 0 15 0 0 30 30 30 23 30 Answer is (D). 0 30 30 ************ 0 QUESTION 8.4.3 [DAA: ANALYSIS] The height of a binary tree is the maximum number of edges in any root Page 141 of 345
  142. 142. to leaf path. The maximum number of nodes in a binary tree of height h is: (A) 2h – 1 (B) 2h-1 -1 (C) 2h+1-1 (D) 2h+1 Answer: (C ) Explanation: For a single node tree consisting only of the root h=0, nodes =1: So this reduces the choice to A or C. For a three node complete binary tree h=1 and nodes =3 so this reduces the choice to C. ******** QUESTION 8.4.4 [DAA: DATA STRUCTURES] The maximum number of binary trees that can be formed with three unlabeled nodes is: (A) 1 (B) 5 (C ) 4 (D) 3 Answer : B Page 142 of 345
  143. 143. ******* Page 143 of 345
  144. 144. 8.5 GRAPHS Page 144 of 345
  145. 145. 8.6 HASHING Page 145 of 345
  146. 146. CHAPTER 9 PROGRAMMING LANGUAGES Page 146 of 345
  147. 147. 9.1 PROGRAMMING LANGUAGE CONCEPTS [GATE CSE 2013—PARAMETER PASSING CONVENTIONS] QUESTION 9.1.1 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 bt reference, wheras 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, } QUESTION 9.1.1 WITH KEY ANSWER IS (A) QUESTION 9.1.1 WITH KEY AND SOLUTION We will use the method of elimination, As x starts with value 5 and is incremented at least twice the answer must be a multiple of 6 and 7. Page 147 of 345
  148. 148. The value returned 6x7x8x9=3024. Answer is (A). ******** Page 148 of 345
  149. 149. CHAPTER 10 DIGITAL LOGIC Page 149 of 345
  150. 150. 10.1 BOOLEAN ALGEBRA AND K-MAPS [GATE CSE 2013 BOOLEAN ALGEBRA] QUESTION 10.1.1 Which one of the following expressions does NOT REPRESENT THE EXCLUSIVE nor of x and y? (A) xy + x’y’ (B) x⊕y’ (C) x’⊕y QUESTION 10.1.1 WITH KEY ANSWER IS (D) [QUESTION 10.1.1 WITH KEY AND SOLUTION] SOLUTION (A) EXCLUSIVE NOR(X,Y) = XY +X’Y’ (B) EXCLUSIVE OR(X,Y)=XY” + X’Y’ (C) EXCLUSIVE OR(X’,Y)=X’Y’ + XY (D) EXCLUSIVE OR (X’,Y’) = X’Y + XY’—IS THE ODD MAN OUT ANSWER IS (D) ******** Page 150 of 345 (D) x’⊕y’
  151. 151. 10.2 COMBINATONAL CIRCUITS Page 151 of 345
  152. 152. 10.3 SEQUENTIAL CIRCUITS Page 152 of 345

×