Você está na página 1de 51

239

Theory of Computation

This Chapter “Theory of Computation” is taken from our:

ISBN : 9789386629029
240

5
Page - 239 - 288

THEORY OF COMPUTATION

C Ø Regular languages and finite automata

O Ø

Ø
Context free languages and Push-down automata

Recursively enumerable sets and Turing machines, Undecidability.

N
T
E
N
T
S
241
ALPHABET AND STRINGS
An alphabet is a finite non-empty set of symbols. It is denoted by a letter å.
• å = {0, 1} is a binary alphabet.
• å = {A, B, ........, Z; a, b, c, ........., z} is an english alphabet.
A string over an alphabet å is a sequence of any number of symbols from å.
• 0, 1, 11, 00 and 011 are strings over {0, 1}.
• Hey, Hello and Hi are strings over english alphabet.
If w is a string over å, the length of w, written as | w| is the number of symbols
that it contains
• Let å = {a, b, ..........., z}.
• |hello| = 5; |hey| = 3; |hi| = 2.
The string of length zero is called the empty string and is written as e. In other
words, e is a string containing no symbol.
OPERATIO NS ON STRINGS
1. Concatenation
Let string x of length a and string y of length b, the concatenation of x and
y, written as xy, is the string obtained by appending y to the end of x, as in
x1 x2, ........ xa y1 y2, ...... yb. and the length of concatenated string will be a + b.
• å being English alphabet, Hello. John = Hello John.
The concatenation of string x for n times, where n ³ 0 is denoted by xn.
• x0 = e, x1 = x, x2 = xx, .............
2. Substring
Let x and y be strings over an alphabet å. The string x is called substring of
y if there exist strings m and n over å such that y = mxn, m and n can be empty
strings. e is a substring of every string and for every string x, x is a substring
of x itself.
• e, concat, nation and concatenation are substring of concatenation.
3. Reverse
The reverse of string x, written as xr is the string obtained by writing x in the
opposite order.
• (hello)r = olleh; (concatenation)r = noitanetacnoc
The set of strings created from any number of symbols in an alphabet å
is denoted by å*.
• Let å = {0, 1}, å* = {e, 0, 1, 00, 01, 10, 11, .........}.
The set of strings created from at least one symbol in an alphabet å is
denoted by å+.
• Let å = {0, 1}, å+ = {0, 1, 00, 01, 10, 11, ............}.
L A NG U A G E
A language over an alphabet å is a set of strings over å. Let å = {0, 1} be the
alphabet.
• Le = {w Î å*| the number of 1’s in w is even}
The above language Le contains all the strings over å having even number
1’s. e, 0, 00, 11, 000, 101, 110, 1111, 0000, 1100, 0011, ............ are in Le.
BASIC operations like Complementation, Union, Intersection, Concatenation
can be applied on languages. We will look into it afterwards.
FINITE AUTOMATA
A finite automata is a 5-tuple (Q, å, d, q0, F), where
1. Q is a non-empty finite set called states.
2. å is a non-empty finite set called alphabet.
3. d : Q × å ® Q is the transition function.
4. q0 Î Q is the start state.
5. F Í Q is the set of accept states.
242
Let’s have a look at the diagram below, also called state diagram.
State diagram represents an automation say M. M is having three states, labelled q1, 1
0
q2, q3 which is nothing but Q = {q1, q2, q3}. The start state, q1 is indicated by the
arrow pointing at it from nowhere. The accept state, q2, is the one with a double circle. 1 0
The arrows going from one state to another are called transitions. When this automation q1 q q3
2
receives an input string, it processes that string and produces an output. The output
0, 1
is either accept or reject. If after reading the last symbol of string, automation is at
accept state then the output is accept, otherwise rejected. State diagram
For example, when the input is feeded at string 1101 to the machine M shown above,
the processing proceeds as follows:–
1. Start in state q1.
2. Read 1, follow transition from q1 to q2.
3. Read 1, follow transition from q2 to q2.
4. Read 0, follow transition from q2 to q3.
5. Read 1, follow transition from q3 to q2.
6. ACCEPT because M is in accept state q2 at the end.
Formally the above machine can be written as M = (Q, å, d, q1, F) where,
® Q = {q1, q2, q3} 0 1
® å = {0, 1}
q1 q1 q 2
® d is described as
q 2 q3 q 2
® q1 is the start state, and
q3 q 2 q 2
® F = {q2}
• If A is the set of all strings that machine M accepts, we say that A is the
language of machine M and write L(M) = A. We say the M recognizes A or
that M accepts A.
• A machine may accept several strings, but it always recognizes only one
language. If the machine accepts no strings, it still recognizes one language
called empty language f.
• In the previous example,
A = {w|w contains at least one 1 and an even number of 0 s follow the last
1}.
• A language is called regular language if some finite automation recognizes it.
Language A defined above is a regular language because M recognizes A.
Designing Finite Automata (DFA)
Let’s look at a simple example to understand how to design an automation. Suppose
that the alphabet is {0, 1} and that the language consists of all strings with an odd
number of 1’s. We have to construct a finite automation M to recognize this language.
To construct the automation for this language, remember one thing that whether the
number of 1’s seen so far is even or odd and keep track of this information as read
new symbols. If you read 1, flip the answer, but if you read a 0, leave the answer as
it is. After this, we evaluate what are the finite list of possibilities. Here there are two.
One is when number of 1’s are even and other when they are odd. Now we assign
a state to each of the possibilities, say qeven and qodd. Next you need to assign the
transitions by seeing how to go from one possibility to another upon reading a
symbol. So, if state qeven represent the even possibility and qodd represent odd
possibility, you would set the transition to flip state on a 1 and stay put on is 0.
Finally, start state will be the state qeven because initially there are 0 number of 1’s
0 0
and 0 is an even number. Accept state will be qodd because you have to accept when
you have seen an odd number of 1s. In figure is the corresponding automata. 1
Note: In GATE examination, you will be asked either to determine the string accepted q even qodd
by automation or the correct design of automation for a given string. 1
243
Example 1. Consider a following deterministic finite state automaton M

1 0 0, 1
q0 0 q1 0 q2 1 q3

Let S denotes the set of seven bit binary string S in which the first, the fourth
and the last bits are 1. The number of string in S theat are accepted by M is
(a) 1 (b) 5
(c) 7 (d) 8
Sol. (c) The string S will be defined as
1xy1zw1 (7 digits)
Here, the values of x, y, z and w can be either 0 or 1.
As shown in figure the machine will jump to next state only after the receiving
input 0 or 1. So, the next value will be 0 thus S is fixed to
(replacing x) 10 y 1 z w 1 (State q1)
or (replacing x) 11 y 1 z w 1 (state q0)
For sequence 10 y z w 1 the machine is on state q2. Thus, we have two values
of S that is
(replacing y) 1001 z w 1 (State q3)
or (replacing y) 1011 z w 1 (State q0)
For string 1001 z w 1 the string will be
(replacing y) 1101 z w 1 (State q0)
or (replacing y) 1111 z w 1 (State q0)
For string 1001 z w (State q3) the machine is on state q3. Thus, the next string
will be
(replacing z) 10010 w 1 (State q3)
(replacing z) 10011 w 1 (State q3)
For string 1011 z w 1 (State q0)
The value of z can be only 0 otherwise the machine will not reach to final state
thus the string S will be
(replacing z) 10110 w 1 (State q1)

In this case the value of w will also be 0 to jump to state q3 so that on


receiving 1 to machine could jump on final state. Thus the string will be
(replacing w) 1011001 S.
For string 1101 z w 1 (state q0) the value of z will be 0 and w will also be 0.
So that the machine could reach to (replacing z, w) 1101001 S

and 1111001 S (replacing z, w) for string 100 10w (state q3) teh value of w
will be so that the machine could reach final state. Thus, the string will be
(replacing z, w) 1001011 S
For string 10011 w 1 (State q3) the machine is on state q3. So, it is on final
state and the input w can be either 0 or 1. As both transactions are available
on final state. Thus, the string can be
or 1001101 S

1001111 S
Non-Deterministic Finite Automata (NFA)
So far, every step of a computation follows in a unique way from the preceding step.
When the machine is in a given state and reads the next input symbol, we know the
next state (using transition), i.e. it is determined. This is called deterministic computation.
In a non-deterministic machine, several choices may exist for the next state at any
244
point. Also, the automation can choose to make a transition from one state to another
without reading any symbol. This type of transition is shown below.

q1 e q2

Formally, a non-deterministic finite automation is a 5-tuple (Q, å, d, q0, F), where


1. Q is a non-empty finite set of states.
2. å is a non-empty finite alphabet.
3. d: Q × åe ® P(Q) is the transition function. Also, Q × å Þ 2Q.
4. q0 Î Q is the start state.
5. F Í Q is the set of accept states.
For example, NFA drawn below can be formally written as:–
1. Q = {q1, q2, q3, q4}
2. å = {0, 1}
3. d is given as

0 1 e
q1 { q1} { q1, q 2 } f
q2 { q3 } f { q3 }
q3 f { 4}
q f
q4 {q4 } {q 4 } f

4. ql is the start state.


5. F = {q4}
0, 1 0, 1

q1 1 q2 0, e q3 1 q4

Step of type (i): a

Step of type (i): b

Step of type (ii): a/b

a
E

Step of type (iv): (a/b)*


245

a
E
E

E
b

Step of type (iii): (a/b)*a

a
E
a E E

E
b

Figure 1 : Steps in constructing an NFAE for (a|b)*a


Some important points to remember:
1. Any DFA is also an NFA.
2. For each NFA, there exist an equivalent DFA.
3. Taking into account above two points, a language is regular if and only if some
NFA recognizes it.
4. If n is the number of states in NFA, then the equivalent DFA will have 2n state
including f state.
Converting NFA to DFA
Let’s have a look at the NFA(N) below that we will be converting in DFA(D).

b a
e

a 2 3
a, b

To construct a DFA(D) that is equivalent to N, we first need to determine D’s states.


Since N is having 3 states, D’s states will be 23 = 8. Now label each of D’s state with
the subset of N’s state. Thus D’s state set is
{f, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}.
The start state of D is the state that are reachable from 1 by travelling along e arrows.
An e arrow goes from 1 to 3, so start state is {1, 3}. Accept states of D are the states
containing N’s accept state, i.e. {{1}, {1, 2}, {1, 3}, {1, 2, 3}}. Now, we determine D’s
246
transition function. In D, state {2}
goes to {2, 3} on input a, because a b
in N, state Z goes to both 2 and 3 a, b f {1} {2} {1, 2}
on input a and we can’t go farther
from 2 or 3 along e arrows. State
{2} goes to {3} on input b. Similarly,
state {1} goes to f on input a, b b b
(a) a,
b
because no a arrows exit it in N. a
Continuing in this way, we obtain
the diagram of D. a
The above DFA can be simplified
a
by removing the unwanted states. {3} {1, 3} a {2, 3} {1, 2, 3}
In this case, they are {1} and {1, 2}
because there are no arrows b b
pointing at these states and also
none of them are start state and Diagram of D
hence they can’t be reached. So,
the simplified DFA will be (a)
a, b
FINITE AUTOMATA WITH OUTPUTS
Under finite automata we have two other machines. (a) Mealy
a b
machine and (b) Moore machine. These machines produces some {1, 3} {3} f
output also at every state.
(i) Mealy Machine
A mealy machine is a tuple b
(Q, S, D, d, l, q0) where b b
a
Q = finite set of states
S = finite non-empty set of input alphabets a
D = the set of output alphabets
a
d = transition function defined as Q × S ® Q. {2} {2, 3} {1, 2, 3}
l = the output function defined as S × Q ® D means at any
b
state the value of current state and current input defines
the output Simplified DFA
q0 = initial state
0/a

q0 q1

0/b

Here, in the given mealy machine when input 0 is applied to state q0 it


produces output a and when 0 is applied to state q1 it produces the output
b. The transition table will be represented as

State Input 0
Next state Output
® q0 q1 a
q1 q0 b

In case of Mealy machine output is ^ if input is ^.


(ii) Moore Machine
Moore machine is a set of six tuples (Q S, D, l q0) where,
Q = set of states
S = set of inputs
247
D = set of outputs
0
d = transition function defined as Q × S ® Q
l = output function defined as Q ® D means only the current state of automata
q0/a q1/b will define the output
q0 = the initial state
0 As we can illustrate the Moore machine in following example.
Herre, q0 state will generate output a and q1 state will generate output b. The
transition table will be given as

State Input = 0 Output


q0 q1 a
q1 q0 b
Finite automata from regular expressions
Given a regular expression r, over an alphabet å say, we wish to construct a DFA
M with alphabet of input symbol å and with the property tht for each u Î å*, u
matches r iff u is accepted by M–so that L(r) = L(M).
Note that by the Theorem on Slide 18 it is enough to construct an NFAE N
with the property L(N) = L(r). For then we can apply the subset construction to N
to obtain a DFA M = PN with L(M) = L(PN) = L(N) = L(r). Working with finite automata
that are non-deterministic and have e-transitions simplifies that construction of a
suitable finite automaton from r.
Let us fix on a particular alphabet å and from now on only consider finite
automata whose set of input symbols is å. The construction of an NFAE for each
regular expression r over å proceeds by recursion on the syntactic structure of the
regular expression, as follows.
(i) For each atomic form of regular expression, a (a Î å), e, and 0 , we give
an NFAE accepting just the strings matching that regular expression.
(ii) Given any NFAEs M1 and M2, we construct a new NFAE, Union (M1,
M2) with the property
L(Union (M1, M2)) = {u | u Î L(M1) or u Î L(M2)}.
Thus L(r1|r2) = L(Union (M1, M2)) when L(r1) = L(M1) and L(r2) = L(M2).
(iii) Given any NFAEs M1 and M2 , we construct a new NFAE, Concat
(M1, M2) with the property.
L(Concat(M1, M2)) = {u1u2 | u1 Î L(M1) and u2 Î L(M2)}.
Thus L(r1r2) = L(Concat (M1, M2)) when L(r1) = L(M1) and L(r2) = L(M2).
(iv) Given any NFAE M, we construct a new NFAE, Star (M) with the property
L(Star(M)) = {u1u2...un | n ³ 0 and each ui Î L(M)}.
Thus L(r*) = L(Star(M)) when L(r) = L(M).
Thus starting with step (i) and applying the constructions in steps (ii)-(iv) over
and over again, we eventually build NFAEs with the required property for
every regular expression r.
Put more formally, one can prove the statement
for all n ³ 0, and for all regular expressions of size £ n, there exists an
NFAE M such that L(r) = L(M)
by mathematical induction on n, using step (i) for the base case and steps (ii)-
(iv) for the induction steps. Here we can take the size of a regular
expression to be the number of occurrences of union (– | –),
concatenation (– –), or star (–*) in it.
248
Example 2. Convert the following Mealy machine to Moore machine.

Input
0 1
State
Next Next
Output Output
state state
q1 q3 0 q2 0
q2 q1 1 q4 0
q3 q2 1 q1 1
q4 q4 1 q3 0
Sol. Here, if any stae have same output for all input values like in our example, q1
state have output 1 only for both 0 and 1 input. thus, the state will be written
as it is. If state has different output for different input like for state q2 for input
0 output is 1 and for input 1 output is 0. In this case state q2 will be divided
in i parts. Where it is total number of inputs. Here q2 will be divided into two
parts q20 and q21. q20 will define the output 0 and q21 will define the output
1. Same thing will be done for state q4. Thus, the transition table will be written
as
State 0 1 Output
q1 q3 q2 1
q 20 q1 q 40 0
q 21 q1 q 40 1
q3 q 21 q1 0
q 40 q 41 q3 0
q 41 q 41 q3 1
Example 3. Convert the folllowing Moore machine into Mealy machine.
State 0 1 Output
q1 q1 q2 0
q2 q1 q3 1
q3 q1 q3 1
Sol. The conversion is simple. Copy the output associated with each state to the
place where state is written. Thus, the example output of q1 state is 0.
Thus, q, × 0 will generate the output 0.
And output of q2 state is then the transaction
q1 × 1 ® q2 will generate the output 1.
q1 × ® 1
And the new transaction table will be
State 0 1
Next state Output Next state Output
q1 q1 0 q2 1
q2 q1 0 q3 1
q3 q1 0 q3 1
Example 4. Convert the following Mealy machine into Moore machine.

0/z1 0/z2
q1 q2

0/z1
1/z1 1/z1
q1

1/z2
249
Sol. The transition table of given Mealy machine will be as
State 0 1
Next state Output Next satate Output
q1 q2 z1 q3 z1
q2 q2 z2 q3 z1
q3 q2 z1 q3 z2
The corresponding Moore machine will be
0 1 Output
q1 q2z 1 q2z 1 z1
q2z 1 q2 z 2 q3z 1 z1
q2z 2 q2z 2 q3z 1 z2
q3z 1 q2z 1 q3z 2 z1
q3z 2 q2z 1 q3z 2 z2
0
0 0

q 1/ ^ q2z1/z1 q2z2/z2

0
1
1
0 1

q3z2/z2 q3z2/z1 1
1
Example 5. Construct a minimum automaton equivalent to finite automaton described
by
State 0 1
® q0 q1 q5
q1 q6 q2
q2 q0 q2
q3 q2 q6
q4 q7 q5
q5 q2 q6
q6 q6 q4
q7 q6 q2
Sol. Step 1 Make separate set of final states and non-final states, i.e.,
{q0, q1, q3, q4, q5, q6, q7} {q2}
Step 2 Further in a given set check whether for two given state, the next state
for a given input belongs to same set. If yes then keep these two states in
same set. Other wise, these two state will be in different set. For example, states
q0 and q1 form set 1. State q1 for input 0 and q1 generates q6 for input 0.q1
and q6 belongs to same set. Now for input 1 q0 generates q5 and q1 generates
q2. q5 and q2 are in different set. q0 and q1 will be in different set.
Here, notice that q1 generates q1 for input 0 and q5 for input 1. q1 and q5 both
are intermediate states and belongs to set 1. Thus, all states that generate
intermediate states for both inputs 0 and 1 will be in set of q0 thus we will
have the 1 set as
{q0, q4, q6}
Next q1 generates state q6 for input 0 which is intermediate state and generates
state q2 for input 1 which intermediate state for input 0 and any final state for
input 1 will be set of q1, thus we will have a set
{q1, q7}
Similarly, q3 generates q2 for input 0 which belongs to set 2 and generate q6
250
for input 1 which belongs to set 1. Thus, all states that generate any state that
belongs to set 2 for input ‘0’ and any state that belongs to set 1 for input 1
will be in set of q3. Thus, we get set as
{q3, q5}
Thus, in next step we will get the set as
{q0, q4, q6}, {q1, q7}, {q3, q5}, {q2} Þ Q2'

Applying the previously described process of this newly generated set Q2' ,
we get
{q0, q4} {q6} {q1, q7} {q3, q5}, {q2} Þ Q3'
By applying the same process, we get
{q0, q4} {q6} {q1, q7} {q3, q5} {q2} Þ Q4'

Q3' = Q4'
Thus, Q’ = [{q0, q4} {q6} {q1, q7} {q3, q5} {q2}]
The transaction table will be
State 0 1
® {q0, q4} {q1, q7} {q3, q5}
{q6} {q6} {q2}
{q1, q6} {q6} {q2}
{q3, q5} {q2} {q6}
{q 2} {q0, q4} {q2}
Here, the state q0 or q4 will be represented as {q0, q4} the state q3 or q5 will
be represented as {q3. q5} and state q1 or q7 or q5 will be represented as
{q3, q5} and state containing q0 will be represented as {q1, q7} the state
containing q0 will be considered as initial state and the state containing any
final state will be considered as final state.
CLOSURE PRO PERTI ES OF REGULAR LA NGUAGES
Regular languages are closed under the following operations:–
1. Union ® If A1 and A2 are regular, then A1 È A2 is also regular.
2. Intersection ® If A1 and A2 are regular, then A1 Ç A2 is also regular.
3. Concatenation ® If A1 and A2 are regular, then A1 o A2 is also regular.
4. Star ® If A is regular language, then A* is also regular.
REGU LA R EX PRESSI ON
The regular expressions are useful for representing certain sets of string in an
algebraic fashion. Formal definition of regular expressions is as follows:–
1. Any terminal symbol, i.e. symbols å including ^ and f are regular expression.
When, we view a in å as a regular expression, we denote it by a.
% % %
2. The union of two regular expressions R1 and R2 written as R1 + R2 also a
regular expression.
3. The concatenation of two regular expressions R1 and R2 written as R1 R2 is
also a regular expression.
4. The iteration of a regular expression R, written as R* is also a regular expression.
5. If R is a regular expression, then (R) is also a regular expression.
6. The regular expression over å are precisely those obtained successively by
the application of the rules 1 to 5 once or several times.
In regular expressions, the order of operation is closure (*), concatenation (•)
and then union (+).
For example, below are the regular expressions and their corresponding regular
language.
251
® 0*10* = {w| w contains a single 1}
® 1*(01*)* = {w| every 0 in w is followed by at least one 1}
® å*1å* = {w| w contains at least one 1}
Any regular expression can be converted into a finite automation that recognizes the
language, it describes and vice versa. Some basic conversions from regular expression
to finite automation (M) are shown below:–
• If r = e, M is
e
s f or s

• If r = f, M is s

• If r = {a} for some a Î å, M is a


s f
• If r = r1 + r2, then M is

r1
e S1 f1
s
e r2
S2 f2

• If r = r1 . r2, then M is

S1 f1 e S2 f2

r1 r2
• If r = r1, then M is
e

e r1
S S1 f1

e
Using the above basic rules / examples, any regular expression can be converted into
a finite automata.
Let’s look at an example for better understanding
r = (ab È a)*
To convert the regular expression (ab È a)* into a finite automation, we will first
convert the regular expressions that are combined to get this one.

a a o
b
b o

a e b
ab o

a e b
e o
ab È a e
a
o

e
a e b
e o
(ab È a)* e
o e
a o
e
252
In this way, we can build NFA from a regular expression. Now let’s convert a DFA
into a regular language. For converting this, we have to follow a very simple procedure
shown below:–
R2

R1
qj
R3
qr R1R2*R 3 È R4 qr
qi qi

R4
We have to remove states one by one to get only two states and therefore
corresponding regular expression. Also, first we have to add two extra states, one
start and one accept. Then we can start removing other states. For example,

s 1 a
1 a

b Two extra
b
states
2 a, b e
a 2 aÈ b

s e a
s 1

a* b (a È b)* b (a È b)*
a
a

Properties (Identities) of regular expression


1. f+ R= R
2. f R + Rf = f
3. ^R = R ^ = R
4. ^ * = ^ and f * = ^
5. R+R=R
6. R*R*=R*
7. RR * = R * R
8. (R*)* = R*
9. ^ + RR * = ^ + R * R = R*
10. (PQ) * P = P (QP) *
11. (P + Q)* = (P * Q*) = ( P* + Q*)*
12. (P + Q) R = PR + QR and R (P + Q) = RP + RQ
Arden’s Theorem
Let P and Q be two regular expressions over S. If P does not contain Ù, then the
following equation in R, namely
R = Q + RP
has a unique solution, i.e., R = QP*
equivalence of two regular expressions
Prove that (1 + 00* 1) + (1 + 00*1) (0 +10 * 1) * (0 + 10 * 1)
is equal to 0 * 1(0 + 10 * 1)*
Þ (1 + 00* 1) + (1 + 00 *1) (0 + 10* 1)* (0 + 10 * 1)
Þ (1 + 00 * 1) Ù + (1 + 00 * 1) (0 + 10 * 1) * (0 + 10* 1)
{R . Ù = R}
253
= (1 + 00 * 1) (Ù + (0 + 10 * 1) (0 + 10 * 1))
= (1 + 00 * 1) (0 + 10 * 1)* (ÙRR* = R*)
= (Ù. 1 + 00 * 1) (0 + 10 * 1) *
= (Ù + 00 *) Ù (0 + 10* 1)*
= 0* 1(0 + 10 * 1)*
= R.H.S.

Regular expressions over an alphabet å

• each symbol a Î å is a regular expression


• e is a regular expression
• is a regular expression
• if r and s are regular expressions, then so is (r|s)
• if r and s are regular expressions, then so is r|s
• if r is a regular expression, then so is (r)*
Every regular expression is built up inductively, by finitely many
applications of the above rules.

(N.B. we assume e, , (, ), |, and * are not symbols in å.)

We assume implicity that the alphabet å does not contain the six symbols
e 0/ ( ) | *
Then, concretely speaking, the regular expressions over Î form a certain set
of strings over the alphabet obtained by adding these six symbols to Î.
However it makes things more readable if we adopt a slightly more abstract
syntax, dropping as many brackets as possible and using the convention that
– * binds more tightly than – –, binds more tightly than – | –.
So, for example, r|st* means (r|s(t)*), not (r|s)(t)*, or ((r|st))*, etc.

Matching strings to regular expressions

• u matches a Î å iff u = a
• u matches e iff u = e
• no string matches
• u matches r|s iff u matches either r or s
• u matches rs iff it can be expressed as the concatenation of two
strings, u = vw, with v matching r and w matching s
• u matches r* iff either u = e , or u matches r, or u can be expressed
as the concatenation of two or more strings, each of which matches
r

The definition of ‘u matches r*, on Slide 6 is equivalent to saying


for some n ³ 0, u can be expressed as a concatenation of n strings,
u = u1u2....un, where each ui matches r.
254
The case n = 0 just means that u = e (so e always matches r*); and the case
n = 1 just means that u matches r (so any string matching r also matches r*). For
example, if å = {a, b, c} and r = ab, then the strings matching r* are
e, ab, abab, ababab, etc.
Note that we didn’t include a regular expression for the ‘*’ occurring in the
UNIX examples on Slide 1. However, once we know which alphabet we are referring
to, å = {a1, a2,....,an} say, we can get the effect of * using the regular expression
(a1|a2|...|an)*

Examples of matching, with å = {0, 1}

• 0|1 is matched by each symbol in å


• 1(0|1)* is matched by any string in å* that starts with a ‘1’
• ((0|1)*(0|1))* is matched by any string of even length in å*
• (0|1)*(0|1)* is matched by any string in å*
• (e|0)(e|1)|11 is matched by just the strings e, 0, 1, 01, and 11
• 1|0 is just matched by 0

Examples based on Design of regular expression


Example 6. Design a regular expression for inputs a and b {a, b} that contains exactly
2 a’s.
Sol. Here, the description defines that there will be only 2 a’s. In between number
of b’s is not defined so b can be present in string or b may not be present
in the string. This can be represent as b * thus,
R = b * ab * ab *
Example 7. Design a regular expression for inputs a and b that contains atleast 2a’s.
Sol. Here at least 2a’s should be there in string irrespective of position. For string
length more than 2 the sequence of a, b is not defined. If the sequence and
length of inputs a, b are not defined it is represented as
(a + b) *
Thus regular will be written as
(a + b)* a (a + b)* b (a + b)
Example 8. Design a regular expression over strings a and b that contains at most
2 a’s.
Sol. Here, the string can have either 1 a or 2 a’s or string will have no a’s.
For string containing 2 a’s regular expression will be
b* ab* ab*
For string containing 2 a’s the regular expression will be b* ab* ab* for string
containing no as the regular expression will be.
Thus, the regular expression for language containing at most 2 a’s will be
R = b* ab* + b* ab* ab* + b*
Example 9. Find the regular expression containing the sub-string aa.
Sol. The regular expression will be as
(a + b)* aa(a + b)*
Rules for Regular Expressions
1. RÈf=R
2. Roe=R
3. f* = e
4. e* = e
255
Example 10. Find the regular expression defined by following DFA

a
q1 q2
b

a b a

q3 b q4
a, b

Sol. The equations for states will be


q1 = Ù+ q2b + q3a
q2 = q1a
q3 = q1b
q4 = q3b + q2a + q4a + q4b
For final state q1 equation is
q1 = Ù + q2b + q3a
= Ù + q1ab + q1ba
(By putting value q2 = q1a and q3 = a1b)
= Ù + q1 (ab + ba)
q1 = Ù (ab + ba)*
(ab + ba)*
(By Arden theorem Q = Ù, p = (ab + ba), R = Q + RP has solution R = QP*)
Construction of Finite Automata from Regular Expression
For regular expression (a + b) the FA will be
a
a, b
or
b
For regular expression ab the FA will be
a b

For regular expression a* the FA will be


a

Ecample 11. Construct the finite4 automata for regular expression (0 + 1)* (00 + 11)
( 0 + 1)*
(0 + 1)* (00 + 11)* (0 + 1)*

(0 + 1)*
(0 + 1)*
00 + 11
Þ
256
(0.1)*
(0 + 1)*
00 11
Þ

(0 + 1)* 0 0 (0 + 1)*

Sol.

1
1

PUMP ING LEMMA


If A is a regular language, then there is a number P (the pumping length) where, if
S is any string in A of length at least P, then S may be divided into three pieces,
S = xyz, satisfying the following conditions:–
1. For each i ³ 0, xy2z Î A
2. | y| > 0, and
3. | xy| £ P.
• If a language does not satisfy these conditions, then it is a non-regular
language.

How to use the Pumping Lemma to prove


that a language L is not regular

For each l ³ 1, find some w Î L of length ³ l so that

no matter how w is split into three, w = u1vu2,


(†)
with length (u1v) £ l and length (v) ³ 1.
there is some n ³ 0 for which u1vnu2 is not in L.

Slide 31

Examples

def
(i) L1 = {anbn | n ³ 0} is not regular.
[for each l ³ 1,a f b f Î L1 is of length ³ l and has property (†) on
Slide 31.]
def
(ii) L2 = {w Î {a, b}* | w a palindrome} is not regular.
[For each l ³ 1, afbaf Î L1 is of lenght ³ l and has property (†).]

(iii) L3 = {ap | p prime} is not regular.


def
[For each l ³ 1, we can find a prime p with p > 2l and then ap Î L3
has length ³ l and has property (†).]
257
CONTEXT FREE LA NGUAGES
The class of context free languages generalizes the class of regular languages, i.e.
every regular language is a context free language. The reverse of this is not true.
Informally, a context free language (CFL) is a language generated by a context free
grammar (CFG). A CFG is a set of rules for deriving (or generating) strings (or
sentences) in a language.
Informally, a CFG consists of:–
— A set of replacement rules, each having a LHS and a RHS.
— Two types of symbols, variables and terminals.
— LHS of each rule is a single variable (no terminals).
— RHS of each rule is string of zero or more variables and terminals.
— A string consists of only terminals.
Formally, a CFG is a 4-tuple (V, å, R, S), where
1. V is a finite set called variables.
2. å is a finite set, disjoint from V, called terminals.
3. R is a finite set of rules, with each rule being a variable and a string of variables
and terminals.
4. S Î V is the start variable.
For example,
G = ({S}, (a, b), R, S), set of rules R is,
S ® a S b | S S | e. This can be also written as
S®aSb
S®SS
S®e
This grammar generates strings such as abab, aaabbb and aababb.
• All the strings generated by the grammar constitute the language of the
grammar and is called context free language (CFG).
Chomsky Normal Form
A context free grammar is in Chomsksy Normal Form if every rule is of the form.
A ® BC
A®a
where, a is any terminal and A, B and C are any variables except B and C may not
be the start variable. In addition, the rule S ® e, where S is the start material is
allowed.
Backus Naur Form
It is quite likely that the same non-terminal will appear on the left-hand side of several
productions in a context-free grammar. Because of this, it is common to use a more
compact notation for specifying productions, called Backus-Naur Form (BNF), in
which all the productions for a given non-terminal are specified together, with the
different right-hand sides being separated by the symbol ‘|’. BNF also tends to use
the symbol ‘;;=’ rather than ‘®’ in the notation for productions. An example of a
context-free grammar in BNF is given
Example of Backus-Naur Form (BNF)

Terminals:
x ¢ + – * ( )
Non-terminals:
id op exp
Start symbol:
exp
Productions:
id ::= x | id¢
op ::= + | – | *
exp ::= id | exp op exp | (exp)
258
Push Down Automata
Push Down Automata are like non-deterministic finite automata but have an extra
component called a stack. The stack provides additional memory beyond the finite
automata provides.
Formally, a push down automata is a 6-tuple (Q, å, G, d, q0, F), where
1. Q is the set of states.
2. å is the input alphabet.
3. G is the stack alphabet.
4. d : Q × åe × Ge ® P (Q × Ge) is the transition function.
5. q0 Î Q is the start state, and
6. F Í Q is the set of accept states.
Below is the description of PDA that recognizes the language {0n 1n | n ³ 0}. Let M1
be (Q, å, G, d, q1, F), where
Q = {q1, q2, q3, q4}
å = {0, 1}
G = {0, $} $ = This signifies that stack is empty
F = {q1, q4} and
d is given by the following table, where in blank entries signify f.

Input 0 1 e
Stock 0 $ e 0 $ e 0 $ e
q1 {(q2, $)}
q2 {(q2, 0)} {(q3, e )}
q3 {(q3, e )} {(q4, e )}
q4

We can also use a state diagram to describe a PDA, as shown below:–

e, e ® $
q1 q2 0, e ® 0

1, 0 ® e CFL

q4 q3 1, 0 ® e
e, $ ® e
Regular
Languages
• A language is context free if and only if some push down automata recognizes
it.
• Every regular language is context free language.

Pumping Lemma for CFL


If A is a CFL, then there is a number P (the pumping length) where, if S is any string
in A of length at least P, then S may be divided into five pieces S = uvwxy satisfying
the conditions:–
1. for each i ³ 0, uv2wx2y Î A,
2. | vx| > 0, and
3. | vwx | £ P.
259
TU RING M ACHINES
A turing machine is a 7-tuple (Q, å, G, d, q0, qaccept, qreject), where
1. Q is the set of states.
2. å is the input alphabet not containing the blank symbol, .
3. G is the tape alphabet, where Î G and å Í G.
4. d : Q × G ® Q × G × {L, R} is the transition function.
5. q0 Î Q is the start state.
6. qaccept Î Q is the accept state.
7. qreject Î Q is the reject state, where qreject ¹ qaccept.
Initially M (turing machine) receives its input w Î å* on the leftmost n squares of
the tape and rest of the tape is blank, i.e. filled with blank symbol. The head starts
from the leftmost square of the tape. Once M has started, the computation proceeds
according to the rules described by the transition function. If M ever tries to move
its head to the left off the left hand end of the tape, the head stays in the same place
for that move, even though the transition function indicates L. The transition continues
until it enters either the accept or reject states at which point it halts. If neither occurs,
M goes on forever. As a TM computes, changes occur in the current state, current
tape content and current head location. A setting of these three items is called a
CONFIGURATION.

q7

1 0 1 0 1 1 1 0 U U U ........
• The above diagram shows a TM with configuration 10101q7 110.
Let C1 and C2 be configuration of M. C1 yields C2 if M is in configuration
C2 after running M in configuration C1 for one step. Suppose d(q1, b) = (q2,
C, L), then aaq1 bb yields aq2 acb. Let w Î å* and M be a turing machine.
M accepts w if there are configs Co, Ci, ..........., Ck, s.t.
— Co = q0 w
— Ci yields Ci + 1 for i = 0, ........., k-1, and
— Ck contains the accept state qaccept.
• A Turing Machine M recognizes a language L if M accepts exactly those
strings in L.
• A language L is called recognizable or recursively enumerable if some TM
recognizes L.
• A TM decides a language L if M accepts all strings in L and rejects all strings
not in L.
• A language is called decidable or recursive if some TM decides L.
• L is decidable if and only if both L and Ø L are recognizable.
Example 12: Construct a Turing machine which will accept the set of strings over
å = {a, b} beginning with a ‘a’ and ending with a ‘b’.
Sol: M = (k, å, G, d, q0, F) where
a b a b b ........ x x a b b ........
K = {q0, q1, q2, q3}; F = {q3}
å = {a, b}; G = {a, b, X, b }
d is defined as follows:– q0 q2
d (q0, a) = (q1, X, R) x b a b b ........ x x x b b ........
d (q1, a) = (q1, X, R)
d (q1, b) = (q2, X, R) q1 q1
d (q2, a) = (q1, X, R) x x x x b ........ x x x x b ........
d (q2, b) = (q2, X, R)
d (q2, b ) = (q3, halt) q2 q3
260
Let us see how the machine accepts abab.
It can be seen that after initially reading ‘a’, the machine goes to state q1.
Afterwards, if it sees a ‘a’ it goes to state q1; if it sees ‘b’ it goes to q2. Hence
when it sees the leftmost blank symbol, if it is in state q2, it accepts as this
means that the last symbol read is a ‘b’.
Multitape Turing Machines
A multitape turing machine is like an ordinary turing machine with several tapes. The
transition function is changed to allow for reading, writing and moving the heads on
some or all of the tapes simultaneously.
• Every multitape turing machine has an equivalent single-tape turing machine.
Closure Properties of Recursive Languages
• If L is a recursive language over å, the L is recursive.
• If L1 and L2 be recursive languages over å. Then L1 È L2 is recursive.
• If L1 and L2 be recursive languages over å. The L1 Ç L2 is recursive.
Closure Properties of Recursively Enumerable Languages
• If L1 and L2 are recursively enumerable languages over å.
Then L1 È L2 is also recursively enumerable.
Context Decidable Turing
• If L1 and L2 are recursively enumerable languages over å. Regular
Free Recognizable
Then L1 Ç L2 is also recursively enumerable.
• If L is a recursive language, then L is recursively enumerable.
• Relationship among classes of languages is shown below:–
Halting Problem
• If a machine loops on input <M, w>, i.e. M loops on w, then this machine does
not decide the corresponding language. If the algorithm had some way to
determine that M was not halting on w, it could reject. Hence, this type of
problem is called halting problem. In other words, language is undecidable.
• A language is decidable if it is Turing-recognizable and co-Turing-recognizable.
(We say this if it is the complement of a Turing-recognizable language).
261

1. Consider the following two problems on undirected graphs: 6. Consider the machine M: [2006, 1 mark]
a — Given, G (V, E), does G have an independent set of size a
|V| – 4? b b
b — Given, G (V, E), does G have an independent set of size 5? a b b
Which one of the following is true? [2006, 1 mark]
(a) a is in P and b is NP-complete a a
(b) a is NP-complete b is in P
(c) Both a and b are NP-complete a, b
(d) Both a and b are in P
2. Consider the languages: [2006, 1 mark] The language recognized by M is
L1 = {WWR | W Î {0, 1)*} (a) {W Î (a, b)* | every a in W is followed by exactly two
L2 = {W # WR | W Î {0, 1)*} where # is a special symbol b’s}
L3 = {W W | W Î {0, 1)*} (b) {W Î (a, b)* | every a in W is followed by at least two
Which one of the following is true? b’s}
(a) L1 is a deterministic CFL (c) {W Î (a, b)* | W contains the substring abb}
(b) L2 is a deterministic CFL (d) {W Î (a, b)* | W does not contain aa as a substring}
(c) L3 is a CFL but not a deterministic CFC 7. Consider three decision problems P1, P2 and P3. It is known
(d) L3 is a deterministic CFL that P1 is decidable and P2 is undecidable. Which one of the
3. Let L1 be a recursive language, and let L2 be a recursively following is true? [2006, 1 mark]
enumerable but not a recursive language. Which one of the (a) P3 is decidable if P1 is reducible to P3
following is true? [2006, 1 mark] (b) P3 is undecidable if P3 is reducible to P2
(c) P3 is undecidable if P2 is reducible to P3
(a) L1 is recursive and L2 is recursively enumerable (d) P3 is decidable if P3 is reducible to P2’s complement
(b) L1 is recursive and L2 is not recursively enumerable 8. Consider the regular language L = (111 + 111111)*. The
minimum number of states in any DFA accepting this language
(c) L1 and L2 are recursively enumerable is [2006, 1 mark]
(a) 3 (b) 5
(d) L1 is recursive enumerable and L2 is recursive (c) 8 (d) 9
4. Consider the languages [2006, 1 mark] 9. Let L1 be a regular language, L2 be a deterministic context-
free language and L3 a recursively enumerable but not
{ } {
L1 = a n b n cm | n, m > 0 and L2 = a n b m cm | n, m > 0 } recursive language. Which one of the following statements
is false? [2006, 1 mark]
Which one of the following statements is false? (a) L1 Ç L2 is a deterministic CFL
(a) L1 Ç L2 is a context-free language (b) L2 Ç L1 is recursive
(b) L1 È L2is a context-free language (c) L1 Ç L2 is context-free
(c) L1 and L2 are context-free language (d) L1 Ç L2 Ç L3 is recursively enumerable
(d) L1 Ç L2 is a context-sensitive language 10. Consider the following statements about the context-free
5. Let Nf and Np denote the classes of languages accepted by grammar: [2006, 1 mark]
non-deterministic finite automata and non-deterministic push- G = {S ® SS, S ® ab, S ® ba, S ® Î}
down automata, respectively. Let Df and Dp denote the classes 1. G is ambiguous.
of languages accepted by deterministic finite automata and 2. G produces all strings with equal number of a’s and b’s.
deterministic push-down automata respectively. Which one 3. G can be accepted by a deterministic PDA.
of the following is true? [2006, 1 mark]
Which combination below expresses all the true statements
(a) Df Ì Nf and Dp Ì Np about G?
(b) Df Ì Nf and Dp = Np (a) 1 only (b) 1 and 3
(c) Df = Nf and Dp = Np
(c) 2 and 3 (d) 1, 2 and 3
(d) Df = Nf and Dp Ì Np
262
11. Let SHAM3 be the problem of finding a Hamiltonian cycle in 17. The minimum state automation equivalent to the above FSA
a graph G = (V, E) with |V| divisible by 3 and DHAM3 be the has the following number of states [2007, 2 marks]
problem of determining if a Hamiltonian cycle exists in such (a) 1 (b) 2
graphs. Which one of the following is true? [2006, 1 mark] (c) 3 (d) 4
18. Which of the following languages is regular?
(a) Both DHAM3 and SHAM3 are NP-hard
(b) SHAM3 are NP-hard but DHAM3 is not
(c) DHAM3 is NP-hard, and SHAM3 is not
(a) {WW | W Î{0,1} }
R +
[2007, 2 marks]

(d) Neither DHAM3 nor SHAM3 is NP-hard


12. For S Î (0 + 1) * let d(s) denotes the decimal value of s (e.g.,
(b) {WW X | X, W Î{0,1} }
R +

{WXW | X, W Î {0,1} }
d(101) = 5) [2006, 1 mark]
R +
Which one of the following statements is true? (c)
(a) L is recursively enumerable but not recursive
(b) L is recursively but not context-free
(c) L is context-free but not regular
(d) {XWW | X, W Î {0,1} }
R +

(d) L is regular 19. The language L = {0i21i | i ³ 0} over the alphabet {0, 1, 2} is
13. If s is a string over (0 + 1)* then let n 0(s) denotes the number (a) not recursive [2007, 2 marks]
of 0’s in s and n1(s) the number of 1’s in s. Which one of the
(b) is recursive and is a deterministic CFL
following languages is not regular? [2006, 1 mark]
(c) is a regular language
(a) L = {s Î (0 + 1)* | n0(s) is a 3-digit prime}
(b) L = {s Î (0 + 1)* | for every prefix s¢ of s, (d) is not a deterministic CFL but a CFL
| n0(s¢) – n1(s¢) £ 2} 20. A minimum state deterministic finite automaton accepting
(c) L = {s Î (0 + 1)* | n0(s) – n1(s)| £ 4 the language L = {W | W Î {0, 1}*, number of 0’s and 1’s in
(d) L = {s Î (0 + 1)* | n0(s) mod 7 = n 1(s) mod 5 = 0} W are divisible by 3 and 5, respectively as. [2007, 2 marks]
14. Let L1 = {0n+m1n0m |n, m ³ 0}, L2 = {0n+m1n + m0m |n, m ³ 0},
and L3 = {0n+m1n + m 0n + m |n, m ³ 0}. Which of these (a) 15 states (b) 11 states
languages is/are not context free? [2006, 1 mark] (c) 10 states (d) 9 states
(a) L1 only (b) L3 only 21. Which of the following is true? [2007, 1 mark]
(c) L1 and L2 (d) L2 and L3
15. Let S be an NP-complete problem and Q and R be two other (a) Every subset of a regular set is regular
problems not known to be in NP. Q is polynomial time (b) Every finite subset of a non-regular set is regular
reducible to S and S is polynomial time reducible to R. Which
(c) The union of two non-regular sets is regular
one of the following statements is true? [2006, 1 mark]
(a) R is NP-complete (b) R is NP-hard (d) Infinite union of finite sets is regular
(c) Q is NP-complete (d) Q is NP-hard 22. Which of the following problems is undecidable?
Common Data for Questions 16 and 17 :
(a) Membership problem for CFGs [2007, 1 mark]
Consider the following Finite State Automation:
(b) Ambiguity problem for CFGs
q3 (c) Finiteness problem for FSAs
(d) Equivalent problem for FSAs
b 23. Which of the following are regular sets? [2008, 2 marks]
{nm }
a
b b 1. a n b 2m | n ³ 0, m ³ 0
a b 2. {a n bm | n = 2m}
q0
a
q1 q2
3. {a b | n ¹ m}
a
4. {xcy | x, y,Î {a, b} *}
(a) 1 and 4 (b) 1 and 3
16. The language accepted by this automation is given by the
regular expression [2007, 2 marks] (c) 1 only (d) 4 only
(a) b * ab * ab * ab (b) (a + b)* 24. Match the List I with List II and select the correct answer
(c) b* a (a + b)* (d) b * ab * ab * using the codes given below the lists. [2008, 2 marks]
263
List I List II (c) (d)
a b a b
E. Checking that P. L = {anbmcndm |m ³ 1, m, ³ 1|}
identifiers are ®P Q S ®P S Q
declared before their
F. Number of formal Q. X ® XbX | XcX | dxf | g Q R S Q S R
parameters in the R(F) Q P R(F) Q P
declaration of a
function agrees with S Q P S Q P
the number of actual 27. Which of the following statements is false? [2008, 2 marks]
parameters in use of (a) Every NFA can be converted to an equivalent DFA
that function (b) Every non-deterministic turing machine can be
G. Arithmetic R. L = {WcW | W Î (a | b)*} converted to an equivalent deterministic turing machine
expressions with (c) Every regular language is also a context-free language
matched pairs of (d) Every subset of a recursively enumerable set is
parentheses recursive
H. Palindromes S. X ® bXb |cXc| e
28. If L and L are recursively enumerable, then L is
(a) E - P, F - R, G - Q, H - S [2008, 1 mark]
(b) E - R, F - P, G - S, H - Q (a) regular (b) context-free
(c) E - R, F - P, G - Q, H - S (c) context-sensitive (d) recursive
(d) E - P, F - R, G - S, H - Q 29. Which of the following are decidable? [2008, 1 mark]
25. Which of the following statements are true? [2008, 2 marks] 1. Whether the intersection of two regular languages is
1. Every left-recursive grammar can be converted to a infinite.
right-recursive grammar and vice-versa. 2. Whether a given context-free language is regular.
2. All e-productions can be removed from any context- 3. Whether two push-down automata accept the same
free grammar by suitable transformations. language.
4. Whether a given grammar is context-free
3. The language generated by a context-free grammar all
(a) 1 and 2 (b) 1 and 4
of whose productions are of the form X ® W or X ®
(c) 2 and 3 (d) 2 and 4
WY (where, W is a string of terminals and Y is non- 30. Which of the following is true for the language {ap | p is a
terminal), is always regular. prime}? [2008, 1 mark]
4. The derivation trees of strings generated by a context- (a) It is not accepted by a turning machine
free grammar in Chomsky Normal Form are always (b) It is regular but not context-free
binary trees. (c) It is context-free but not regular
(a) 1, 2, 3 and 4 (b) 2, 3 and 4 (d) It is neither regular nor context-free, but accepted by a
(c) 1, 3 and 4 (d) 1, 2 and 4 turing machine
26. Given below are two finite state automata (® indicates the 31. 1
start state and F indicates a final state) [2008, 2 marks] 0
0 0
a b a b

®1 1 2 ®1 2 2 1
Y: Z:
The above DFA accepts the set of all strings over {0, 1} that
2 (F) 2 1 2 (F) 1 1
(a) begin either with 0 or 1 [2009, 2 marks]
Which of the following represents the product automation (b) end with 0
Z × Y? (c) end with 00
(d) contain the substring 00
(a) (b)
a b a b 32. Let L1 = L1 Ç L 2 , where L1 and L2 are languages as defined
below
®P Q R ®P S Q
Q R S Q R S
{ }
L1 = a m b m c a n b n | m, n ³ 0

R(F) Q P R(F) Q P L 2 = {a i b jck | i, j, k ³ 0}

S Q P S P Q Then L is [2009, 2 marks]


264
(a) not recursive 39. Consider the languages L1 = {0i1j | i ¹ j}, L2 = {0i1j | i = j},
(b) regular L3 = {0i1j | i = 2j + 1 j}, L4 = {0i1j | i ¹ 2j}. Which one of the
(c) context-free but not regular following statements is true? [2010, 2 marks]
(d) recursively enumerable but not context-free (a) Only L2 is context-free
33. Given the following state table of an FSM with two states A (b) L2 and L3 are context-free
and B, one input and one output (c) L1 and L2 is context-free
Present Present Input Next Next Output (d) All are context free
State A State B State A State B 40. Let L = {W Î (0, 1) * | W has even number of 1s}, i.e., L is the
0 0 0 0 0 1 set of all bit strings with even number of 1’s. Which one of
0 1 0 1 0 0 the regular expressions below represents L?
1 0 0 0 1 0 [2010, 2 marks]
1 1 0 1 0 0 (a) (0* 10* 1)* (b) 0 * (10* 10*)*
0 0 1 0 1 0 (c) 0 * (10 *1)* 0* (d) 0 * 1(10 * 1) * 10 *
0 1 1 0 0 1 41. Let L1 be a recursive language. Let L2 and L3 be languages
1 0 1 0 1 1
that are recursively enumerable but not recursive. Which of
1 1 1 0 0 1
the following statements is not necessarily true?
If the initial state is A = 0, B = 0, what is the minimum length
[2010, 1 mark]
of an input string, which will take the machine to the state
A = 0, B = 1 with output = 1? [2009, 2 marks] (a) L2 – L1 is recursively enumerable
(a) 3 (b) 4 (b) L1 – L3 is recursively enumerable
(c) 5 (d) 6 (c) L 2 Ç L1 is recursively enumerable
34. Match all items in List I with correct options from those
(d) L 2 È L1 is recursively enumerable
given in List II [2009, 1 mark]
42. Consider the languages, L1, L2 and L3 as given below

{ }
List I List II
L1 = 0p1q | p, q Î N [2011, 2 marks]
P. Regular expression 1. Syntax analysis

L 2 = {0 p1q | p, q Î N and p = q} and


Q. Push-down automata 2. Code generation
R. Dataflow analysis 3. Lexical analysis

L3 = {0 p1q 0 r | p, q, r Î N and p = q = r}
S. Register a llocation 4. Code optimization
(a) P - 4, Q - 1, R - 2, S - 3 (b) P - 3, Q - 1, R - 4, S - 2
(c) P - 3, Q - 4, R - 1, S - 2 (d) P - 2, Q - 1, R - 4, S - 3 Which of the following statements is not true?
35. Which one of the following is false? [2009, 1 mark] (a) Push Down Automata (PDA) can be used to recognize
(a) There is unique minimal DFA for every regular language L1 and L2
(b) Every NFA can be converted to an equivalent PDA (b) L1 is a regular language.
(c) Complement of every context-free language is recursive (c) All the three languages are context-free
(d) Every non-deterministic PDA can be converted to an (d) Turning machines can be used to recognize all the
equivalent deterministic PDA languages
36. Which one of the following languages over th e 43. A deterministic finite automation (DFA)D with alphabet c
alphabet {0 1} is described by the regular expression (0 + 1) = {a, b} is given below. [2011, 2 marks]
* 0(0 + 1) * ? [2009, 1 mark]
(a) The set of all strings containing the substring 00
b b a, b
(b) The set of all strings containing at most two 0’s p q r
(c) The set of all strings containing at least two 0’s
(d) The set of all strings that begin and end with either 0 or 1.
37. S ® aSa |bSb| a | b; The language generated by the above a a
grammar over the alphabet {a, b} is the set of
[2009, 1 mark] a, b a, b
(a) all palindromes s t
(b) all odd length palindromes
(c) strings that begin and with the same symbol Which of the following finite state machines is a valid minimal
(d) all even length palindromes DFA which accepts the same language as D?
38. Let W be any string of length n in {0, 1}*. Let L be the set of (a)
b b a, b
all sub-strings of W. What is the minimum number of states p q r
in a non-deterministic finite automaton that accept L?
[2010, 2 marks]
a a
(a) n – 1 (b) n
(c) n + 1 (d) 2n – 1
a, b
265
a, b (a) (b) bd + bc
s bd
(b) (c) bd + abcd (d) bd + bc + cd
a, b b 48. A list of n strings, each of length n, is sorted into lexicographic
p q
a order using the merge-sort algorithm. The worst case running
time of this computation is [2012, 2 marks]
r a, b (a) O (n log n) (b) O (n2 log n)
(c) O (n2 + log n) (d) O (n2)
a, b 49. The worst case running time to search for an element in a
(c) a, b
a, b balanced binary search tree with n2n elements is
p b
q r [2012, 1 mark]
(a) Q (n log n) (b) Q (n2n)
(d)
b (c) Q (n) (d) Q (log n)
p q 50. The recurrence relation capturing the optimal execution time
of the Towers of Hanoi problem with n discs is
[2012, 1 mark]
a a (a) T(n) = 2T (n – 2) + 2 (b) T(n) = 2T (n – 1) + n
(c) T(n) = 2T (n/2) + 1 (d) T(n) = 2T (n – 1) + 1
s a, b 51. Let W(n) and A(n) denote respectively, the worst case and
average case running time of an algorithm executed on an
44. Definition of a language L with alphabet {a} is given as
input of size n. Which of the following is always true?
following and n is a positive integer constant. What is the
[2012, 1 mark]
minimum number of states needed in a DFA to recognize L ?
(a) A(n) = W (W(n)) (b) A(n) = Q (W(n))
[2011, 2 marks]
(c) A(n) = O (W(n)) (d) A(n) = o (W(n))
(a) k + 1 (b) n + 1
(c) 2n + 1 (d) 2k + 1 52. Consider the languages L1 = F and L2 = {a}. Which one
45. Which of the following pairs have different expressive of the following represents L1 L2* È L1*?
power? [2011, 1 mark]
(a) Deterministic Finite Automata (DFA) and Non- [2013, 1 Mark]
deterministic Finite Automata (NFA) (a) {e} (b) F
(b) Deterministic Push Down Automata (DPDA) and Non- (c) a* (d) (e, a)
deterministic Push Down Automata (NPDA)
(c) Deterministic single-tape turing machine and non- 53. Which of the following statements is/are false?
deterministic single tape turing machine 1. For every non-deterministic Turing machine, there
(d) Single-tape turing machine and multi-tape turing exists an equivalent deterministic Turing machine.
machine 2. Turing recognisable languages are closed under
46. Let P be a regular language and Q be a context free language union and complementation.
such that Q Í P . For example, let P be the language 3. Turing decidable languages are closed under
represented by the regular expression p*q* and Q be intersection and complementation.

( Qn pn qn n Î N ) . Then which of the following is always


4. Turing recognisable languages are closed under
union and intersection. [2013, 1 Mark]
(a) 1 and 4 only (b) 1 and 3 only
regular? [2011, 1 mark]
(c) 2 only (d) 3 only
(a) P Ç Q (b) P – Q 54. Which of the following is/are undecidable?
(c) å * - P (d) å * - Q 1. G is a CFG. Is L(G) = F?
47. What is the minimal form of the Karnaugh map shown below? 2. G is a CFG. Is L(G) = å*?
Assume that X denotes a don’t care term. [2012, 2 marks] 3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
ab [2013, 2 Marks]
cd 00 01 11 10
(a) 3 only (b) 3 and 4 only
00 1 X X 1 (c) 1, 2 and 3 only (d) 2 and 3 only
55. Which one of the following is TRUE ?
01 X 1
[2014, Set-1, 1 Mark]
11 (a) Thelanguage L = {anbn| ³ 0} is regular..
(b) The language L = {an| n is prime} is regular.
10 1 X (c) The language L = {w | w has 3k + 1b's for some k Î N
with S = {a, b}} is regular.
(d) The language L = {ww | wÎ S* with S = {0, 1}} is
regular.
266
56. Consider the finite automaton in the following figure. 60. Let A £ m B denotes that language A is mapping reducible
(also known as many-to-one reducible) to language B. Which
0,1 1 one of the following is FALSE?
[2014, Set-2, 1 Mark]
q0 1 q1 0,1 q2 0,1 q3 (a) If A £m B and B is recursive then A is recursive.
(b) If A £m B and A is undecidable then B is undecidable.
Which is the set of reachable states for the input string (c) If A £m B and B is recursively enumerable then A is
0011? [2014, Set-1, 1 Mark]
recursively enumerable.
(a) {q0, q1, q2} (b) {q0, q1}
(c) {q0, q1, q2, q3} (d) {q3} (d) If A £m B and B is not recursively enumerable then A
57. Let L be a language and L be its complement. Which one is not recursively enumerable.
of the following is NOT a viable possibility? 61. Let < M > be the encoding of a Turing machine as a string
[2014, Set-1, 2 Marks] over S = {0, 1}. Let L = {<M>| M is a Turing machine that
accepts a string of length 2014}. Then, L is
(a) Neither L nor L is recursively enumerable (r.e.). [2014, Set-2, 2 Marks]
(b) One of L and L is r.e. but not recursive; the other is (a) decidable and recursively enumerable
not r.e. (b) undecidable but recursively enumerable
(c) Both L and L are r.e. but not recursive. (c) undecidable and not recursively enumerable
(d) decidable but not recursively enumerable
(d) Both L and L are recursive.
62. Let L1 = {w Î {0, 1}*| w has at least as many occurrences of
58. Which of the regular expressions given below represent the
(110)’s as (011)’s}. Let L2 = {w Î{0, 1}* | w has at least as
following DFA? [2014, Set-1, 2 Marks]
many occurrences of (000)’s as (111)’s}. Which one of the
0 1 following is TRUE? [2014, Set-2, 2 Marks]
0
(a) L1 is regular but not L2
(b) L2 is regular but not L1
(c) Both L1and L2 are regular
1 (d) Neither L1 nor L2 are regular
63. The length of the shortest string NOT in the language (over
I 0*1(1+00*1)*
S= {a, b}) of the following regular expression is
II 0*1*1+11*0*1
______________. [2014, Set-3, 1 Mark]
III (0+1)*1
a*b* (ba)*a*
(a) I and II only (b) I and III only
(c) II and III only (d) I, II, and III S*
64. Let S be a finite non-empty alphabet and let 2 be the
59. If L1 = {an | n ³ 0} and L2 = {bn | n ³ 0}, consider power set of S*. Which one of the following is TRUE?
[2014, Set-2, 1 Mark] [2014, Set-3, 1 Mark]
(I) L1.L2 is a regular language
S*
(II) L1.L2 = {anbn | n ³ 0} (a) Both 2 and S* are countable
2S * is countable and S* is uncountable
Which one of the following is CORRECT?
(b)
(a) Only (I) (b) Only (II)
(c) Both (I) and (II) (d) Neither (I) nor (II) (c) 2S * is uncountable and S* is countable
S*
(d) Both 2 and S* are uncountable
267

1. Context-free languages and regular languages are both (iii) Only L2 is accepted by deterministic PDA.
closed under the operations (s) of (a) only (i) (b) (i) and (ii)
(i) Union (ii) Intersection (iii) Concatenation (c) (i) and (iii) (d) All three
(a) (i) and (ii) only (b) (ii) and (iii) only 10. Let L1 and L2 are regular sets defined over the alphabet
(c) (i) and (iii) only (d) all of the above å * . Mark the false statement
2. Let r1 = ab*c* & r2 = ( a * b Ú c ) * and r3 = ( a Ú b Ú c ) * (a) L1 È L 2 is regular (b) L1 Ç L 2 is not regular
Then which of the following is true
(a) w = ac belongs to L(r 2) and L(r3) but not L(r1) (c) å * - L1 is regular (d) L1 * is regular
(b) w = ac belongs to L(r 3) only 11. Which of the following functions are computable with
(c) w = ac belongs to L(r 1), L(r2) and L(r3) turning Machine?
(d) w = ac belongs to L(r 1) and L(r3) but not L(r2) (a) n*(n – 1)*(n – 2)*...*2*1*
3. Let å = {a, b} (b) [log2 n]
r1 = a ( a Ú b ) * (c) n
22
r2 = b ( a Ú b) * (d) all of the above
Which of the following is true? 12. Let L1 = {anbncn, n ³ 0}
(a) L ( r1 ) = L ( r2 ) = å * (b) L ( r1 ) Ç L ( r2 ) = {l} L2 = {a2nb2nc2n, n ³ 0}
(c) L ( r1 ) È L ( r2 ) = å * (d) L(r1) È L(r2) È {l} = S* L3 = {a2nb2ncn, n ³ 0}
4. Which of the following statements are true? (a) L1 Í L 2 and L3 Í L 2 (b) L2 Í L1 and L 2 Í L3
(i) abcd Î L((b * a)* (d*c*)*)
(ii) abcd Î L((d*c*b*a)*) (c) L2 Í L1 but L 2 Ë L3 (d) L1 Í L 2 and L 2 Í L3
(iii) abcd Î L((a*b*c*d)*) 13. Which of the following regular expression does not represent
(a) (i) and (iii) only (b) (ii) and (iii) only strings beginning with atleast one 0 and ends with at least
(c) (i) and (ii) only (d) all of the above one 1?
5. Which of the following regular expression corresponds to (a) 0*1* (b) 00*(0 + 1)*1
the language of all strings over the alphabet {a, b} that do (c) 0(0 + 1)*1 (d) None of the above
14. The following CFG
not end with ab.
S ® aS | bS | a | b
(a) (a + b)* (aa + ba + bb)
is equivalent to the regular expression
(b) (a + b)* (aa + ba + bb) + a + b + l 1. (a* + b*) 2. (a + b)+
(c) b*ab*a 3. (a + b) (a + b)* 4. (a + b)* (a + b)
(d) b*aab* (a) 2 and 3 only (b) 2, 3 and 4
6. How many minimum number of states are required in the (c) All of the above (d) 3 and 4 only
DFA{over the alphabet {a, b}) accepting all the strings with
15. The Moore machine has six tuples ( Q, å , D, d, l, d 0 ) .
the number of a’s divisible by 4 and number of b’s divisible
by 5? Which of the following is true?
(a) 20 (b) 9 (a) d is the output function
(c) 7 (d) 15 (b) d is the transition function S into Q
(c) l is the transition function S × Q into Q
7. How many states does the DFA constructed for the set of
(d) l is the output function mapping Q into D.
all strings ending with “00”, have?
(a) 2 (b) 3 16. Suppose r1 =Î , r2 = 0*1* , which of the following
(c) 4 (d) 5 statement is true about r1 and r 2?
8. Let X = {0, 1}, L = X* and R = {0n1n/n>0} then the language (a) r1 is not regular expression, while r2 is a regular
(b) r1 and r2 both are regular expression
L È R and R respectively
(a) Regular, Regular (b) Non regular, Regular (c) r1 is regular expression, but r 2 is not
(d) Neither r1 nor r2 are regular expressions
(c) Regular, Not regular (d) Not regular, Not Regular
9. Consider L1 = 0 1 , L2 = 0 c 1n
n n n 17. If L1 is regular and L2 is CFL over å * which of the following
Which of the following statements are correct? statement is incorrect?
(i) L1 and L2 are accepted by non-deterministic PDA. (a) L1 È L2is CFL (b) L1 Ç L 2is regular
(ii) L1 and L2 are accepted by deterministic PDA.
(c) L1 * is regular (d) None of the above
268
25. The statement, “ATM can’t solve halting problem” is
18. å * over {0, 1} and 2å * are respectively.
(a) True (b) False
(a) Uncountably infinite and uncountably infinite (c) Still a open question (d) None of these
(b) Countably infinite and uncountably infinite 26. Any given transition diagram has an equivalent
(c) Countably infinite and countably infinite (a) regular expression (b) NDFSM
(d) None of the above (c) DFSM (d) all of these
19. Which of the following languages is/are context free? 27. The FSM shown in the figure accepts
1. {a b c d | n ³ 1, m ³ 1}
n n m m

2. {a n bmcmdn | n ³ 1, m ³ 1}
3. {a n bmcn dm | n ³ 1, m ³ 1} (a) all strings (b) no strings

4. {a m bn cmdn | n ³ 1, m ³ 1} 28.
(c) Î-alone (d) none of these
The FSM shown in the figure accepts
(a) 1 and 2 (b) 3 and 4
(c) 2 and 4 (d) 1, 2, 3 and 4 a, b
20. Consider the machine M shown below
a, b

a
S1 S3
a (a) all stings (b) no strings
Sc b a (c) Î-alone (d) none of these
29. CFLs are not closed under
b S2 S4
b (a) Union (b) Concatenation
(c) Closure (d) Intersection
a, b
L(M) = ? 30. The set A = {anbnan | n = 1, 2, 3...} is an example of a language
(a) L(M) = {words starting with aa or bb} that is
(b) L(M) = {words ending with aa or bb} (a) regular (b) not context-free
(c) L(M) = {words containing aa or bb as a subword} (c) context-free (d) none of these
(d) None of these 31. Consider the two regular languages L1 =(a + b)* a and L2 =
21. The regular expression for “Binary numbers that are b (a + b)*. The intersection of L1 and L2 is given by
multiples of two” is (a) (a + b)* ab (b) ab(a + b)*
(a) (0 | 1) * 1 (b) (0 | 1)*0 (c) a(a + b)* b (d) b(a + b)*a
(c) (1 | 0) * 1 (d) (1 | 0)*00 32. Which of the following languages over {a, b, c} is accepted
22. Which of the string is accepted by given NDFA? by deterministic push down automata?
a (a) {w | w is palindrome over {a, b, c}}
(b) {w wR | w Î {a, b, c}*}
(c) {anbncn | n ³ 0}
Start c (d) {wCwR | w Î{a, b}*}
33. Consider the FA shown in the figure given below, where
“–” is the start and “+” is the ending state.
The language accepted by the FA is
b
(a) c. ( a È b ) *
a
(b) c.a * b *
(c) c.(ab)* (d) None of these b – + a
23. Consider the language b
L1 = {anbmcndm | n ³ 1, m ³ 1} and (a) (a + b)*b (b) (a + b)*a
L2 = {anbmcmdn | n ³ 1, m ³ 1} (c) a*b (d) a*b*
(a) Both L1 and L2 are context free 34. Regarding the power of recognizing the languages, which
(b) L1 is not context free but L2 is context free of the following statements is false?
(c) both are not context free (a) The NDFA are equivalent to DFA
(d) L1 is context free but L2 is not context free (b) NDPDA are equivalent to DPDA
24. The following GFG (c) NDTMs are equivalent to DTMs
S ® aS | bS | a | b and S ® aS| bS | a | b | l is equivalent to (d) Multiple tape TMs are equivalent to single tape TMs
regular expressions 35. If "w Î å * it can determined in finite time, whether or not
(a) (a + b) and l + a + b respectively
(b) (a + b) (a + b)* and (a + b)* respectively w Î L, the L is
(c) (a + b) (a + b) and (l + a + b)(l + a + b) respectively (a) decidable (b) undecidable
(d) None of these (c) non-deterministic (d) intractable
269
36. Consider the transition diagram of DFA as given below. 41. (a + b)*a (a + b)*
1 (a) strings of odd length having a at the middle
q0 q1 (b) all strings containing a and b
1
(c) all strings of odd length
(d) all strings containing atleast one ‘a’
0 0 0 0
42. Let L be the set of all strings over {0, 1} of length 6 or less.
1 Write a simple RE corresponding to L.
q2 q3 (a) (a + 1)* (b) (0 + 1)6
1 (c) (0 + 1 + Î)* (d) (0 + 1 + Î)6
Which is the language of the given DFA? 43. Given the R.E. described by the following NFA.
(a) L = {Î}
0
(b) L = {} 1 2
(c) L = {w|w has equal no. of 1’s and 0’s} Start q0 Î Î
q1 q2
(d) none of these
37. Let S = (0, 1), then an automation A accepting only those (a) (0 1 2)* (b) (0 + 1 + 2)*
words from S having an odd number of 1’s requires
(c) 0*1*2* (d) None of these
_________ states including the start state.
44. [(a + b) (a + b)]*
(a) 2 (b) 3
(c) 4 (d) 5 (a) all strings
38. Design an FSM to check whether a given unary number is (b) all strings of even length
divisible by 3. (c) all strings in which group of 2 symbols has both the
symbols same but grouping must be done left to right
q4 starting from first symbol
(a) 1 q1 (d) all strings in which group of 2 symbols has both the
q0
Start
symbols same but grouping must be done right to left
1
1 starting from last symbol.
45. If a DFA is represented by the following transition table,
q2 q3
then how many states does the corresponding minimal DFA
1 1 contains?
(b) q0 q1 q4
Start State Input
0 1
1 1
(start) ® A B C
q2 q3 B B D
1
1 1 C B C
(c) q0 q1 q3
Start D B E
(final) ® E B C
1 1 (a) 2 (b) 3
q2 (c) 4 (d) 5
46. G = {(a, b), {S}, S, {S ® b/Sa/aS/SS})
1 1
(d) q0 q1 q3 Which of the following are true?
Start
(i) aabbaa Î G
1 (ii) G is ambiguous
1 (iii) regular expression corresponding to G is ba*
q2
(a) (i) and (ii) only (b) (ii) and (iii) only
39. The given transition table is for the FSM that accepts a (c) (i) and (iii) only (d) all of the above
string if it ends with ‘aa’. Which is the final states? 47. Which languages does the following DFA accept?
d a b b 1
a, b
start q 0 q2 a
a
q0 q1 q2 0 3

q1 q1 q2 b
a
q2 q0 q2 b 2
(a) q 0 (b) q 1 (a) (ab)* (b) (ab + bb)*
(c) q 2 (d) can’t be determined (c) (ab + ba)* (d) (aa + bb)*
40. A minimum state DFA accepting the same language has 48. Which of the following statements are false?
how many states? (a) The regular expression (1 + 10)* denotes all strings of
(a) 1 (b) 2 0’s and 1’s beginning with ‘1’ and not having two
(c) 3 (d) 4 consecutive O’s
270
(b) The regular expression (0 + 1)*011 denotes all strings 1. (q0, 0) = (q1, X, R)
of O’s and 1’s ending with 011. 2. (q0, Y) = (q3, Y, R)
(c) The regular expression OO (1 + 10)* denotes all strings 3. (q1, 0) = (q1, 0, R)
of O’s and 1’s atleast two consecutive O’s 4. (q1, 1) = (q2, Y, L)
(d) The regular expression (O + Î) (1 + 10)* denotes all 5. (q1, Y) = (q1, Y, R)
strings of O’s and 1’s that do not have two consecutive 6. (q2, 0) = (q2, 0, L)
O’s 7. (q2, X) = (q0, X, R)
49. Which of the following languages can’t be accepted by a 8. (q2, Y) = (q2, Y, L)
deterministic PDA? 9. (q3, Y) = (q3, Y, R)
(a) The set of palindromes over alphabet {a, b} 10. (q3, B) = (q4, B, R)
(b) The set of strings of balanced parenthesis Which of the following is true about M?
(c) L = {WcWR | W in (0 + 1)*} (a) M halts on L having 100 as substring
(d) L = {0n 1n | n ³ 0} (b) M halts on L having 101 as substring
50. Which language does the following PDA accept (c) M halts on = 0n1n, n ³ 0
M = {{q0, q1}, {0, 1}, {z0, x}, d, q0, z0, f} and d is given by (d) M halts on L not having 1100 substring
d (q0, 0, z0) = (q0, xz0) 56. Consider the following regular grammar,
R1 = (a|b)*
d (q0, 0, x) = (q0, xx)
R2 = (a* | b*)*
d (q0, 1, x) = (q1, x)
R3 = (Î a | b*)*
d (q1, 1, x) = (q1, Î)
Minimized deterministic finite automata of which R1, R2 and
d (q1, Î, z0) = (q0, Î)
R3 are exactly same except state names?
(a) L = {0n 1n | n ³ 0} (b) L = {0n 1n | n ³ 1} (a) DFA for R1 and R2 are similar
(c) L = {0n 1n + 1 | n ³ 0} (d) L = {0n 1n + 1 | n ³ 1} (b) DFA for R2 and R3 are similar
51. Which of the following statement must always be true for A (c) DFAS for R1, R2 and R3 are different
and B? Suppose A and B are two sets of strings from S*, (d) DFAS for R1, R2 and R3 are similar
such that B Í A 57. Consider the following machine M
(i) if A is finite then, B is finite a
(ii) if A is regular then, B is regular b a a
(iii) if A is context free then, B is context free Start S
0 S1 a S2 S3
b
S4
(a) (i) only (b) (ii) only b
b b
(c) (iii) only (d) All three
52. Consider the following grammar G a
S ® aA, A ® (aA, bB), B® (bB, c, cC), C® (c, cC) Which is the language L(M) accepted by this machine?
Which of the following is L(G)? (a) L(M) = {Set of all words starting with aabb}
(a) L(G) = a*b*c* (b) L(G) = aa*b*c* (b) L(M) = {Set of all words having aabb as a subword}
(c) L(G) = aa*bb*cc* (d) L(G) = (abc)* (c) L(M) = {Set of all words ending with aabb}
53. Consider the following set of languages (d) L(M) = {Set of all words with exactly one occurance of
L1 = ambn | n = m2 aabb}
L2 = ambmcmdn |m, n, > 0 58. If L1 and L2 are a pair of complementary languages. Which
L3 = ambmcndn | m, n > 0 of the following statement is not possible?
Which of the above language is not context free? (a) Both L1 and L2 are recursive
(a) L1 and L3 (b) L2 and L3 (b) L1 is recursive and L2 is recursively enumerable but
(c) L1 and L2 (d) All L1, L2 and L3 not a recursive
54. L1 has the following grammar
(c) Neither L1 nor L2 recursively enumerable
S ® aB/BA
(d) One is recursively enumerable but not recursive, the
A ® bAA/aS/a
other is not recursively enumerable.
B ® b/bS/aBB
L2 has the following grammar 59. Consider the grammar consisting of 7 productions
S ® Sba/a S ® aA | aBB
Which of the following statement is true about? A ® aaA | l
B ® bB | bbC
L3 = L1 Ç L2 and L4 = L1L1 * ? C®B
(a) Both L3 and L4 are not context free After elimination of Unit, useless and l-productions, how
(b) L3 is context free but L4 is not many production remain in the resulting grammar?
(c) Both L3 and L4 are context free (a) 2 (b) 3
(d) L4 is context free, but not L3 (c) 4 (d) 5
55. Let M be a turing machine has Q = {q0, q1, q2, q3, q4} a set
60. Referring to Turing machine in previous question, what will
of states, input alphabets {0, 1}. The tape alphabets are {0,
1, B, X, Y}. The symbol B is used to represent end of input be the output when the input is I1 = 0100 and I2 = 0010?
string. The final state is q4. The transistions are as follows. (a) I1 = 0 and I2 = Blank (b) I1 = Blank and I2 = 0
(c) I1 = 1 and I2 = 1 (d) None of the above
271
61. Suppose L1 and L2 are two language over å * 70. P, Q, R are three languages. If P and R are regular and if PQ
= R, then
L = å * - ( ( å * - L1 ) È ( å * - L 2 ) ) (a) Q has to be regular (b) Q can not be regular
L1 and L2 are CFL. (c) Q need not be regular (d) Q has to be a CFL
Which of the following statement is true? 71. The Travelling Salesman Problem (TSP) is
1. L is necessarly CFL (a) NP but not NP complete
2. L may or may not be CFL (b) NP complete
3. L1 Í L1 (c) Neither NP nor NP-complete
(a) only 2 (b) 1 and 3 (d) None of these
(c) 2 and 3 (d) All are correct 72. Which of the following is false?
62. In string of length n, how many proper prefixes can be (a) PATH is a P class problem
generated (b) Djikstra’s algorithm is a problem in P
(a) 2n (b) n (c) CLIQUE is a NP class problem
(c) n(n + 1)/2 (d) n – 1 (d) RELPRIME is a NP class problem
63. The following CFG 73. If there is an NP-complete langauge L whose complement is
S ® aB | bA in NP, then the complement of any language in NP is in
A ® ba | aS | bAA (a) NP
(b) P
B ® b | bS | aBB
(c) Both (a) and (b)
generates strings of terminals that have
(d) None of these
(a) equal number of a’s and b’s
74. What is the regular expression for the language generated
(b) odd number of a’s and even number of b’s by S ® aS | bA, A ® d | ccA
(c) even number of a’s and even number of b’s (a) a*bd
(d) odd number of a’s and even number of a’s (b) a*(bd) (bcc)*d
64. The regular expression 0* (10*) denotes the same set as (c) a*b(cc)*d
(a) (1*0)*1* (b) 0 + (0 + 10)* (d) None of these
(c) (0 + 1)*10(0 + 1)* (d) None of the above 75. Consider the grammar S ® PQ | SQ | PS, P ® x, Q ® y. To get
65. Consider the following deterministic finite state automation string of n terminals, the number of productions to be used is
M. (a) n 2 (b) 2n
1 0 (c) 2n + 1 (d) 2n – 1
0, 1
76. Which of the following can be recognized by a DFA?
1 0
(a) The number of 1, 2, 4, --- 2n ---written in binary
1
(b) The number of 1, 2, 4, --- 2n ---written in unary
1 (c) The set of binary strings in which the number of 0’s is
Let S denote the set of seven bit binary strings in which the same as the number of 1’s
first, the forth and the last bits are 1. The number of strings (d) The set {0, 101, 11011, 111011, ---}
is S that are accepted by M is 77. Give a RE for the set of strings which are either all b’s or else
(a) 1 (b) 5 there is an ‘a’ followed by some b’s also containing Î.
(c) 7 (d) 8 (a) b* + ab* (b) (Î + a)b+
66. The diagoalization language, Ld is a (c) b* + ab* + Î (d) (Î + a)b+ + Î
(a) recursive language 78. Given an arbitary non-deterministic finite automaton (NFA)
(b) recursive enumerable but not recursive with N states, the maximum number of states in an equivalent
minimized DFA is at least.
(c) non-recursivity - enumerable (non-RE) language
(a) N 2 (b) 2N
(d) both (b) and (c) (c) 2N (d) N!
67. Time taken by one tape TM to simulate n moves of k-tape. 79. Consider a DFA over å = {a, b} accepting all strings which
TM is have number of a's divisible by 6 and number of b's divisible
(a) O(n) (b) O(nk) by 8. What is the minimum number of states that the DFA
(c) O(n ) 2 (d) none of these will have?
68. Which of the following is true? (a) 8 (b) 14
(a) PDA with 2 stacks is equivalent to TM (c) 15 (d) 48
(b) Regular expression can represents only some of the 80. Consider the following languages :
languages. L1 = {ww | w Î {a, b} * }
(c) Both (a) and (b) L2 = {wwR | w Î {a, b} * wR is the reverse of w}
(d) neither (a) nor (b) L3 = {02i | i is an integer}
69. L Î NP does not obviously imply that L4 = {0i2 | i is an integer}
(a) L’ Î NP (b) both (a) and (c) Which of the languages are regular?
(c) L’ Î P (d) none of these (a) Only L1 and L2 (b) Only L2, L3 and L4
(c) Only L3 and L4 (d) Only L3
272
81. Consider the following problem x. (a) G is not ambiguous
Given a Turing machine M over the input alphabet å, any (b) There exist x, y, Î L (G) such that xy Î / L(G)
state q of M.
(c) There is a deterministic pushdown automaton that
And a word w Î å* does the computation of M on w visit
the state q? accepts L (G)
Which of the following statements about x is correct? (d) We can find a deterministic finite state automaton that
(a) x is decidable accepts L(G)
(b) x is undecidable but partially decidable 88. Consider the following two statements :
(c) x is undecidable and not even partially decidable S1 : {02n| n ³ 1|} is a regular language
(d) x is not a decision problem S2 : {0m 1n 0m + n | m ³ 1 and n ³ 1|} is a regular language
82. The language accepted by a Pushdown Automaton in which
the stack is limited to 10 items is best described as Which of the following statements is incorrect?
(a) Context free (b) Regular (a) Only S1 is correct
(c) Deterministic Context free (d) Recursive (b) Only S2 is correct
83. Ram and Shyam have been asked to show that a certain (c) Both S1 and S2 are correct
problem P is NP-complete. Ram shows a polynomial time (d) None of S1 and S2 is correct
reduction from the 3-SAT problem to P, and Shyam shows 89. Which of the following statements true?
a polynomial time reduction from II to 3-SAT. Which of the (a) If a language is context free it can be always be accepted
following can be inferred from these reduction? by a deterministic push-down automaton.
(a) P is NP-hard but not NP-complete (b) The union of two context free language is context free.
(b) P is in NP, but is not NP-complete (c) The intersection of two context free language is context
(c) P is NP-complete free
(d) P is neither Np-hard, nor in NP (d) The complement of a context free language is context
84. Nobody knows yet if P = NP. Consider the language L
free
defined as follows
90. The smallest finite automaton which accepts the language
ì(0 + 1) * if P = NP {x|} length of x is divisible by 3} has
L=í
î O othervise (a) 2 states (b) 3 states
Which of the following statements is true? (c) 4 states (d) 5 states
(a) L is recursive 91. The C language is :
(b) L is recursively enumerable but not recu (a) A context free language
(c) L is not recursively enumerable (b) A context sensitive language
(d) Whether L is recursive or not will be known after we (c) A regular language
find out if P = NP (d) Parsable fully only by a Turing machine
85. If the strings of a language L can be effectivley enumerated 92. The language accepted by a Pushdown Automaton in which
in lexicographic (i.e., alphabetic) order, which of the the stack is limited to 10 items is best described as
following statements is true? (a) Context free (b) Regular
(a) L is necessarily finite (c) Deterministic Context free (d) Recursive
(b) L is regular but not necessarily finite 93. Ram and Shyam have been asked to show that a certain
(c) L is context free but not necessarily regular problem P is NP-complete. Ram shows a polynomial time
(d) L is recursive but not necessarily context free reduction from the 3-SAT problem to P, and Shyam shows
86. Consider the following deterministic finite state automaton a polynomial time reduction from to 3-SAT. Which of the
M.
following can be inferred from these reduction?
(a) P is a NP-hard but not NP-complete
(b) P is in NP, but is not NP-complete
(c) P is NP-complete
(d) P is neither Np-hard, nor in NP
94. Nobody knows yet if P = NP. Consider the language L
defined as follows

Let S denote the set of seven bit binary strings in which the ì(0 + 1) * if P = NP
first, the fourth, and the last bits are 1. The number of strings L=í
in S that are accepted by M is î O othervise
(a) 1 (b) 5 Which of the following statements is true?
(c) 7 (d) 8 (a) L is recursive
87. Let G = ({S}, {a, b} R, S be a context free grammar where (b) L is recursively enumerable but not recu
the rule set R is (c) L is not recursively enumerable
S®aSb|SS|e (d) Whether L is recursive or not will be known after we
Which of the following statements is true? find out if P = NP
273
95. If the strings of a language L can be effectively enumerated 99. Consider the NFAM shown below.
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
96. Consider the following deterministic finite state automaton
M.

Let the language accepted by M be L. Let L1 be the language


accepted by the NFAM 1 , 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 (b) L1 = {0, 1}*
Let S denote the set of seven bit binary strings in which the (c) L1Í L (d) L1 = L
first, the fourth, and the last bits are 1. The number of strings 100. The problems 3-SAT and 2-SAT are
in S that are accepted by M is (a) both in P
(a) 1 (b) 5 (b) both NP-complete
(c) 7 (d) 8 (c) NP-complete and in P respectively
97. Let G = ({S}, {a, b} R, S be a context free grammar where the (d) undecidable and NP-complete respectively
rule set R is 101. The following finite state machine accepts all those binary
strings in which the number of 1’s and 0’s are respectively
S®a S b|S S|e
Which of the following statements is true?
(a) G is not ambiguous
(b) There exist x, y, Î L (G) such that xy Î / 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)
98. A single tape Turing Machien 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 (a) divisible by 3 and 2 (b) odd and even
transition function of M is described in the following table (c) even and odd (d) divisible by 2 and 3
102. The language {am bm+n| m, n £ 1} is
0 1 B (a) regular
0 1,1,R (b) context-free but not regular
q q Q1,1,R Halt (c) context sensitive but not context free
q1 q1,1R Q 0,1,L qH0, B, L (d) type-0 but not context sensitive
103. Consider the flowing grammar C
The table is interpreted as illustrated below. S ® bS | aA | b
The entry (q1,1,R) in row q0 and column 1 signifies that if M A ® bA | aB
B ® bB | aS | a
is in state q0 and reads 1 on the current tape square, then it
Let Na (W) and Nb (W) denote the number of a’s and b’s in
writes 1 on the same tape square, moves its tape head one
a string W respectively. The language L(G) Í {a, b}+
position to the right and transitions to state q1.
generated by G is
Which of the following statements is true about M? (a) {W | Na (W) > 3Nb (W)}
(a) M does not halt on nay string in (0 + 1) +
(b) {W | Nb (W ) > 3N a (W )}
(b) M dies not halt on any string in (00 + 1)*
(c) M halts on all string ending in a 0 (c) {W | N a (W ) = 3k , k Î{0,1, 2,...}}
(d) M halts on all string ending in a 1
(d) {W | Nb (W ) = 3k , k Î {0,1,2,...}}
274
104. Consider three decision problem P1, P2 and P3. It is known (a) 00 11 22 (b) 11 22
that P1 is decidable and P2 is undecidable. Which one of (c) 21 (d) 22
the following is TRUE? Directions for 110, 111 and 112:
Consider the transition diagram of an DFA as given below:
(a) P3 is decidable if P1 is reducible to P3
(b) P3 is undecidable if P3 is reducible to P2
(c) PL3 is undecidable if P2 is reducible to P3
(d) P3 is decidable if P3 is reducible to P2’s complement
105. Consider the machine M

110. Which should be the final state(s) of the DFA if it should


accept strings starting with ‘a’ and ending with ‘b’?
(a) q 0 (b) q 1
(c) q0, q1 (d) q 3
111. Which of the following strings will be accepted it q0 and q1
are accepting states?
1. ababab 2. babaaa 3. aaaba
The language recognised by M is
(a) {W Î {a, b}* / every a in w is followed by exactly two (a) 1, 2 (b) 2, 3
b's} (c) 1, 3 (d) None of these
(b) {W Î {a, b}* / every a in w is followed by at least two 112. Which of the following represents the set of accepting states
b's} if the language to be accepted contains strings having the
(c) {W Î {a, b}* / w contains the substring ‘abb’ same starting and ending symbols?
(d) {W Î {a, b}* / w does not contain ‘aa’ as a substring} (a) {q0} (b) {q0, q3}
106. Let L1 be a recursive language, and let L2 be a recursively (c) {q3} (d) {q3, q1}
enumerable but not a recursive language. Which one of the Directions for 113 and 114:
following is TRUE? Consider grammar G
(a) L1 is recursive and L2 is recursively enumerable S ® AB, A ® aAA/Î, B ® bBB/Î.
113. Find the nullable symbols in the given grammar
(b) L1 is recursive and L2 is not recursively enumerable (a) A (b) B
(c) L1 and L2 are recursively enumerable (c) A, B and S (d) A and B
(d) L1 is recursively enumerable and L2 is recursive 114. If G1 is constructed from G, after eliminating Î-productions,
then G1 is given by
107. Consider the languages
(a) S ® AB (b) S ® AB | A | B
L1 = {WW R | W Î{0,1}*} A ® aAA | aA A ® aAA | aA
B ® bBB | bA B ® bBB | bB
L2 = {W #W R | W Î{0,1}*}, where # is a special symbol (c) S ® AB (d) S ® AB | A | B
L3 = {WW | W Î{0,1}*} A ® aAA | aA | a A ® aAA | aAa
Which one of the following is TRUE? B ® bBB| bB | b B ® bBB | bB | b
(a) L1 is a deterministic CFL Directions for 115, 116 and 117
(b) L2 is a deterministic CFL The ‘value’ of a R.E. r over å , denoted by val(r), is defined as
(c) L3 is a CFL, but not a deterministic CFL follows:
(d) L3 is a deterministic CFL 1. val (f) = 0
2. val (Î) = 0
Directions for 108 and 109:
Consider the following NFA with Î moves. 3. val (a) = 0, "a Î å
4. val ((rs)) = val ((r + s)) = max (val(r), val(s))
5. val ((r*)) = val (r) + 1
Find the value of the following R.E.
115. (a(a + a*aa))
108. If the given NFA is converted to NFA without Î-moves, (a) 0 (b) 1
which of the following denotes the set of final states? (c) 2 (d) None of these
(a) {q2} 116. (a(a + a*aa) + aaa)*
(b) {q1, q2 } (a) 1 (b) 2
(c) {q0, q1, q2} (c) 3 (d) 4
(d) can’t be determined
109. Which of the following strings will not be accepted by the 117. (a*b*b*b*) where å = {a, b}
given NFA? (a) 2 (b) 3
(c) 4 (d) none of these
275

PAST GATE QUESTIONS EXERCISE (A) L1 I L2 is CFL is true


1. (a) (B) L3 I L1 is recursive, not necessary so false.
2. (b ) In all the options there is linear relationship among (C) & (D) are also true.
strings so all CFL’s , but L1 & L3 can be accepted by 10. (b) Due to S ® S this Grammar is ambiguous right hand
PDA, L2 can be accepted by deterministic CFL due to side has twoNon terminals. Also the strings like aaabbb
presence of special symbol D which tells the middle of have equal no. of a’s & b’s but can’t be produced by
the string, so deterministic. this grammar. So 2 is false.
3. (b ) The rules here used will be. Statement 3 is true since it is a CFG so accepted by
All those languages which are recursive their PDA.
complements are also recursive. 11. (a) There is a difference between SHAM3 and DHAM3
So option (A) & (B) can be correct. that SHAM3 is used for finding a Hamiltonian cycle in
Now languages which are recursively enumerable but a graph but DHAM3 is the problem of determining if a
not recursive, their complements can’t be recursively graph exists in a Hamiltonian cycle. Also it is given
that |V| is divisible by 3, hence the problem can be
enumerable.
reduced from 3 SAT which further determines that
So only option (B) is correct
SHAM3 and DHAM3 are NP hard.
Hence (B) is correct option
12. (d) Given that, d(s) mod 5 = 2 and d(s) mod 7 ¹ 4}
4. (a) L1 and L2 are context-free languages and therefore
Both the languages are regular languages, since there
L1 Ç L 2 may or may not be context-free, since CFLs exists deterministic finite automata for both of them.
are not closed under intersection. Now, let us look at We also have an algorithm to check the regular nature
L1 Ç L 2 . of the language therefore L is regular.
L1 Ç L 2 = {anbncn | n > 0} 13. (c) Option (A), (B) & (D) can be accepted by DFA, & there
which is clearly not context-free but is context sensitive. is no linear relationship between the no. of 0’s &1’s in
5. (d) We know that, the languages accepted by non- the string but in (C)n0(S) - n1(S) <=4 can’t be accepted
deterministic finite automata are also accepted by by DFA, we require a PDA.
deterministic finite automata. This may not be in the So not regular.
case of context-free languages. 14. (d) The language is context free or not, this can be proved
by finding out the grammar for all the languages.
Therefore, Df = Nf and Dp Ì N p
6. (b) a is followed by two or more than 2b’s so the language { }
L1 = 0 n + m1n 0 m | n, m ³ 0
recognized by M is {W Î {a, b} * | . The production for L1 as follows:
7. (c) Option (c) S ® 0S0 0A1 e
According to the option, P2 is reducible to P3.
Also it gives that P2 is undecidable. A ® 0A1 e
From (a) and (b) ; Now, we need to apply these values of the production
P3 is undecidable. individually to generate
8. (d) Given language L = (1111 + 11111)*. Here, we can see
that more than eight 1’ can be generated by the 0 n + m n 0m
combination of 111 and 11111. Therefore, number of
states = 8 + 1 = 9. that is,
These can be represented as 0m0n1n0m ® To prove
1 1 1 1 1
Applying 0S0 (m times)
1
S ® 0 S0, S ® 0mS0m
1 Applying, S ® 0A1
® S ® 0m 0A1 0m
Here applying, A ® 0 A1, n – 1 times
1
S ® 0m 0 0n–1 A1n–1 10m
1
® S ® 0m 0n1n0m
Hence, proved, so L1 is context-free.
9. (b) L1 is regular language Going through the same procedure, we can see that
L2 is CFL. two comparisons are made in the L2 language, So it is
L3 is recursively enumerable but not REC. not context-free.
276
L3 ® Going through the same procedure again, we can 21. (b) Finite subset of non-regular set is regular as we know
see that two comparisons are made in the L3 language, that Pumping Lemma can be applied on all the finite
so it is not context free. sets that states that all finite sets are regular. Infinite
15. (a) S is NP complete and a NP complete problem is union of finite set is not regular because regular sets
reducible to some unknown problem then that problem can never be closed under infinite union.
is also NP complete. So S ® D, R the R is NP complete. 22. (b) Finite state automata (FSA) has no undecidability CFL
16. (b) The FSA as obtained in the previous question is b* a membership problem is also decidable.
(a + b)* So option (B) i.e Ambiguity of CFL cannot be
The minimum number of states are thus given by decidable.
b a, b 23. (a) Lets gather some knowledge for the regular expressions
before going to True or False. The regular sets are
defined in such a way that they have to follow some
q0 q1 conventions. Conventions on regular expressions
a
q0 and q1 are the state: that are required at most and 1. Bold face is not used for regular expressions when the
hence the minimum number of states is 2 (q0 and q1). expression is not confusing. So, for example, (r + s) is
17. (c) The behaviour as per the given PDA is an seen below used instead (r + s).
q0 to q1 ® b*a 2. The operation * has precedence over concatenation,
q1 to q2 ® (a + b) * which further has precedence over union (+). Thus,
Regular expression = b * a (a + b)* the regular expression (a + b(c*))) is written as a + bc*.
18. (c) Lets study the regular language. 3. The concatenation of k r’s, where r is regular expression,
Convenstions on regular expressions is written as rk. Thus, for example rr = r2. The language
1. Bold face is not used for regular expressions when the corresponding to rk is Lkr , where Lr is language
expression is not confusing. So, for example, (r + s) is
corresponding to the regular expression r. For a
used instead (r + s).
2. The operation * has precedence over concatentation, recursive definition of Lkr .
which further has precedence over union (+). Thus, 4. The (r+) is used as a regular expression to represent
the regular expression (a + b(c*))) is written as a + bc*.
3. The concatenation of k r’s, where r is regular expression, L+r .
is written as rk. Thus, for example rr = r2. The language Based on the concept, only 1 and 4 are found to be
corresponding to r k is Lkr , where Lr is language regular since in 1, L can be written as a* (bb)* and 4, (a
corresponding to the regular expression r. For a + b) * c(a + b)* can be written for the 4.
24. (c) The matched sequence is as given
recursive definition of Lkr .
4. The (r+) is used as a regular expression to represent List I List II
L+r . E. Checking that identifiers R. L = {WCW | W Î (a | b)*}
Since, language L can be expressed as are declared before their
r = [0 (0 + 1) * 0] + [1 (0 + 1) * 1] use.
and follows the above convention, therefore is regular F. Number of formal P. L = {anbmcndm |m ³ 1, m, ³ 1|}
19. (b) L = {Oi i2li | i > 0}, this language can’t be accepted parameters in the
byDFA to regular, but it is recursive & can be declaration of a function
accepted by PDA to CFL. agrees with the number
20. (a) It is given that the 0’s and 1’s are divisible by 3 and 5 of actual parameters in
and we know that 3 and 5 do not have any factor other use of that function
than themselves or 1 i.e., these cannot be further
breakdown. G. Arithmetic expressions Q. X ® XbX | XcX | dxf | g
Therefore, number of states = 3 × 5 = 15 with matched pairs of
The schematic representation is as follows: parentheses
1 H. Palindromes S. X ® bXb |cXc| e
1 1 1 1
1 2 3 4 5 25. (d) Statement 1 True: Left recursive and right recursive
0 0 grammar can be converted into each other.
0 0
0
0 0 0 0 Statement 2 True: All e-productions can be removed
from many context-free grammar by suitable
0 6 1 7 1 8 1 9 1 10 transformations.
Statement 3 False: The language is not always regular
0 0
0 0 0 since given the property of the context-free grammar
that the right side of the productions have any one of
1 1 1
11 12 13 14 1 15 the following.
X X X X X
277
1. single-terminal Statement 2 Undecidable: It is not decidable since the
2. non-terminal followed by a terminal language is context-free.
3. l Statement 3 Undecidable: It is also undecidable that
Statement 4 False: The derivation trees in CNF are whether two push-down automata accept the same
binary trees. language.
26. (a) Given: Transition table for Y and Z Statement 4 Decidable: If the LHS of each production
The number of states of Z = 2 has one and only one variable then it is a context-free
The number of states of Y = 2 grammar.
Z× Y 30. (d) (d) {aPPis a prime no.}
a b a, b This prime no. is extra constraint so this language is
a neither LFG nor RG but it can be accepted by turing
1 2 1 2 machine.
b a, b

Y Z 31. (c) 1
No. of states of the product of Z and Y = 2 × 2 = 4 1 0
Now, the states as per the given options are P, Q, R
and S. The finite state automata is 0 0
q0 q1 q2

a b
1
®P S R

Q R S
State Input Output
R(F) Q P q0 to q0 1, 0 00
S Q P q1 to q0 1, 0 00
q2 to q0 1, 0 00
Table for Z × Y is
Therefore, the above DFA ends with 00.
a b
32. (c) It is given that L = L1 Ç L 2
® (1, 2) (2, 1) (2, 2)
Let’s first analyze the given language and check
(1, 2) (2, 2) (2, 1) whether it is context-free or not. The context-free
languages are defined as below–
(2, 1) (1, 1) (1, 2)

F(2, 2) (1, 2) (1, 1)


n n
{ }
A context-free language is L = a b : n ³ 1 that is

27. (d) Option (a) True: Non-deterministic finite automata can the language of all non-empty even-length strings. It
be converted into the deterministic finite automata. consists of
Option (b) True: With reference to option (a), same is 1. the entire first halves of which are a’s.
with the non-deterministic turing machine. 2. the entire second halves of which are b’s.
Option (c) True: Regular language is always context- L is generated by the grammar S ® aSb | ab, and is
free but the reverse is not true. accepted by the push-down automation M = ({q0, q1,
Option (d) False: We know that a set is a subset of qf}, {a, b}, {a, z), d q0, {qf}) where d is defined as
itself and hence, every subset of recursively enumerable
d(q0, a, z) = (q0, a)
set is not recursive.
d(q0, a, a) = (q0, a)
28. (b) As per the theorem, a language is recursive if that
d(q0, b, a) = (q1, x)
language and its complement are r ecursively
enumerable. Therefore, L is recursive. d(q1, b, a) = (q1, x)
29. (b) Statement 1 Decidable: The algorithm can be used to d(q1, l, z) = (qf, z)
check the finiteness/infiniteness on the DFA and also d (state1, read pop) = (state2, push)
the two given DFAs, a product DFA can be where z is initial stack symbol and x means pop action.
constructed. Here, in we are given, where a and b are of equal lengths
278
and followed by c which is of different length. This The common feature in the accepting languages can
definitely shows that the languages are context-free be seen that they consist of atleast two 0’s.
but not regular. 37. (b) Given grammar S ® aSabSbab.
33. (a) The initial state = 00 The strings generated through this grammar is
Final state required = 01 definitely palindromes,but not all it can only generate
palindromes of odd length only so (A) & (D) are false,
Let us construct the transition diagram for the given.
(B) is correct.
00 01 01
Also it can generate palindromes which start and end
0 0
0 1 2 with same symbol, but not all strings eg. aabababba.
Initial state Final state 38. (c) L is the set of all substrings of w where w ! {0,1})
We get the total number of states to be 3 when getting Any string in L would have length 0 to n, with any no.
the desired output. The transition diagram can further of 1’s and 0’s
The NDFA
be elaborated as below.
There can be 4 states 00, 01, 10, 11.
With this, the FSM can be designed as
0/1
1/0
00 01
1/1

1/1 1/1 0/0 Here n = 4


So to accept all the substrings the no. of states
required are n + 1 = 4 + 1 = 5
11 0/0 10 Hence (c) is correct option.
39. (d) These sort of languages are accepted by PDA, so all
The desired output is obtained with the input string should be context free languages. L2 & L3 are definitely
101, however, the concern is number of states which CFL since accepted by stockof PDA.
we found to be 3. And also L1 & L4 are linear comparisons of i & j so can
34. (b) Regular expressions are meant for lexical analysis to also be represented using PDA. So all are context free
define tokens.Pushdown Automata is used to accept languages.
context free language which are used for syntax 40. (b) It is given that L is the set of all bit strings with even
analysis. number of 1’s so the regular expression should exhibit
Data flow analysis is a technique for code optimization. the same.
Register allocation is used for code generation. Now, the min string should be e and the string should
be e, 0, 11, 101, ...
So P-3, Q-1, R-4, S-2.
The string obtained from such expression is 0* (10* 10
35. (d) (a) true, since minimal DFA for every regular language
*)*
is possible.
41. (b) L1 ® recursive
(b) true, NFA can be converted into an equivalent
L2,L3 ® recursively enumerable but not recursive.
PDA. So L1 can be recursive enumerable.
(c) CG’S are not recursive but their complements are. RE - RE = RE
(d) false, since non deterministic PDA represents, non So L1 - L3 is recursively enumerable.

{ }
deterministic
CFG, since NDCFG and CFG are proper subsets so 42. (c) L1 = 0 p1q | p, q Î N is regular language
conversion required.
36. (c) We are given with the relation
(0 + 1) * 0(0 + 1)* 0(0 + 1)*
{ }
L2 = 0p1q | p, q Î N and p = q is context-free
language
Here, the accepting languages are
L = {00, 000, 100, 001, 010, 0000, 0001, 1000, 1001, 0100, { }
L3 = 0p1q 0 r | p, q, r Î N and p = q = r is not
1100, 0010, 0011, 0110, 0101, 1010, ...}
context-free.
279
43. (a) As state (s) and (t) both are final states and accepting that the smallest disc is at the top position and the
a* + b*, we can combine both states and we will get largest disc is at the lowest position.
Mo
ve f
b b r om
p q r a, b A to C

a a
n – 1 discs n – 1 discs
a, b move from
s move from
A to B
B to C

Peg A Peg B Peg C


44. (b) As n is constant atleast n + 1 states will required to
design ank. For this, we can recursion algorithm. Firstly, we have
45. (b) DPDA and NPDA because an NPDA cannot be to move all upper n – 1 discs from peg A to B, then last
converted into DPDA. largest disc moved from peg A to C, then again (n – 1)
46. (c) å * - P and å * - P is the complement of P and discs moved from peg B to C.
Algorithm
complement of regular language is also regular.
function (n, A, B, C)
47. (b) {
ab function (n – 1, A, C, B);
cd 00 01 11 10
A®C
00 1 X X 1 function (n – 1, B, A, C);
01 X 1 }
Then, the recurrence relation for this problem is
11 T(n) = 2T(n – 1) + 1
51. (c) As we have given,
10 1 X
A(n) ® Average case complexity
W(n) ® Worst case complexity
As we know that average case will always be less than
b 'c'+ b ' d ' or bc + bd
or equal to worst case complexity.
48. (b) Given, there are n strings and length of each string is n.
A (n) £ W (n)
Normal recurrence relation for merge sort is
T(n) = 2T (n/2) + Cn Consider option (a):
Here, we need n comparisons to compare two strings A(n) = W (W(n))
i.e., 2 elements of set. \ It says W(n), worst case complexity is less than the
So, recurrence relation will be average case complexity which is wrong because W
T(n) = 2T (n/2) + Cn2 asymptotic notation shows (³) sign. Hence, this option
By solving this using master method, we will get is false.
T(n) = O (n2) Consider option (b)
49. (c) Time complexity to search an element in a balanced A(n) = q (W(n))
binary search tree is \ It says A(n), worst case complexity is same as worst
= log [number of elements in binary search tree] case complexity because q notation shows equality
= log [n × 2n] sign. Hence, this is false.
= log n + log 2n Consider option (c)
= log n + n log 2 A(n) = O (W(n))
\ It says that average case complexity A(n) is less
= log n + n (Q while log2 2 = 1) than or equal to W(n) worst case complexity. Hence,
= q (n) this option is correct.
50. (d) Tower of Hanoi problem with n discs are follows: Consider option (d)
We have given n discs in peg A and we have to move A(n) = O (W(n))
all n discs from A to C peg. We will take help of extra \ It says that A(n) is strictly less than W (n), so this
peg B and we arrange all the n discs in peg C as follows option is false.
280
52. (a) Considering the languages L1 = f and L2 = {a} q0 is the initial state. q4 is the final state.
For all languages L it is known that f . L = f FA state remains same when input symbol is “a” at
Suppose, $ a string s Î f.L any point of time.
When 1st ‘b’ is read, state is changed from q0 to q1.
$ s' such that s = s' . s" When 2nd ‘b’ is read, state is changed from q1 to q2.
and s¢Î fs¢¢Î L When 3rd ‘b’ is read, state is changed from q2 to q3.
But s¢Î f Q f is an empty language. & when 4th ‘b’ is read, state is changed from q3 to
q4.
\ f. L= f
If no more ‘b’ is encountered, the string is accepted
{e} Í L* for all languages L.
when last input symbol is read.
As it means taking letters from the language and
However if 5th “b” is there is string, state is changed
concatenating them ‘0’ times creating a ‘0’ length
from q1 to q2 so that to accept the string 2 more bs
string which is possible for all languages.
must be there in the string at least.
\ e is in f*
Continuing in this way only those strings are
L1 . L2 = f
and L1 = {e} accepted that has 3k + 1 (k Î N ) number of b’s. (i.e.
L1 . L2 * È L*1 = (L1 . L2) È L*1 4, 7, 10 ... number of b’s).
\ f È {e} = {e} 56. (a) Following paths can be taken by the finite Automaton
53. (c) 1. Non-deterministic Turing Machine can be for the input string “0011”:––
simulated by a deterministic Turing Machine with q0 uuuuuuuuu
0 rq0 uuuuuuuuu
0 rq0 uuuuuuuur
1 q0 uuuuuuuur
1 q0
exponential time true.
2. Turing recongnizable language are “not” closed Reachable states
under complementation. For any Turing recognizable {q0 }
language the Turing Machine ‘T’ recognizing ‘L’ may
not terminate on inputs q0 uuuuuuuuu
0 rq0 uuuuuuuuu
0 rq0 uuuuuuuur
1 q0 uuuuuuuur
1 q1
x Ï L - False {q0, q1}
3. Turing decidable languages are CLOSED under
0 rq0 uuuuuuuuu
q0 uuuuuuuuu 0 rq0 uuuuuuuur
1 q1 uuuuuuuur
1 q2
union and complementation. It is easy to determine
if turing machine is decidable-True (q0, q1, q2)
So, answer is option (c) only 2. We note that no other path is possible for the input
54. (d) 1. G is a CFG. Is L(G) = f? string “0011”.
Decidable So, finally union of all three cases gives us the set
2. G is a CFG. Is L(G) = S * ? of Reachable states which is {q0, q1, q2}
Undecidable
57. (c) Both L and L are recursively enumerable but not
3. M is a Turing Machine. Is L (M) regular?
recursive.
Undecidable.
4. A is a DFA and N is an NFA. Is L(A) = L(N)? Set of recursive languages is subset of the set of
Decidable. recursively enumerable languages.
Hence, the correct answer is (d) 2 and 3 only. So, if a language is recursive, It must be R.E. also.
55. (c) We know that a language L is regular if an equivalent (A) May be true as a language L and its complement L
finite Automaton can be constructed for it.
need not be recursively enumerable.
DFA can be constructed for L as follows:–
Note that L contains the strings that has 3k + 1 (B) May be true if L is r.e. but not recursive and L is not
number of b’s (that is 4, 7, 10, .......n ...... no. of b’s recursively enumerable
and any no. of a’s)
(D) May be true as L and L both can be recursive.
a a a a a However (C) is not possible because if Both L and L
are recursively enumerable than by a well known
q0 q1 q2 q3 q4 theorem of complexity theory either L or L has to be
b b b b
recursive.

b
281
58. (d) I, II and III. PRACTICE EXERCISE
Given DFA : 1. (c) Regular and context free languages are both closed
under union and concatenation while only regular is
O O closed under intersection.
1
\ Ans is (c)
2. (d) ac Î L(r1), since we can take b* as Î and c* as c
q0 q1
ac Î L(r 3 ), since ( a È b È c) * includes all
combinations of a, b, c.
1
ac Ï L ( r2 ) since when ever (a* b + c)* is taken to
(I) 0*1 (1 + 00 * 1)* it represents the given DFA include a, “a is always followed by b”.
using following transition:
a*b = b, ab, aab, .... & so on.
O* :– 1 q0 ® q0
\ Ans is (d)
1 :– q0 ® q1
3. (d) L(r1) is the Language starting with ‘a’.
(1 + 00 * 1) * :– q1 ® q0 ® q0 ® q1
L(r2) is the Language starting with ‘b’.
(1 +) (0) (0*) (1)
So, the string is accepted. Since any word belonging to å * either starts with “a”
(II) 0 * 1 * 1 + 11 * 0 * 1 :- or starts with “b” or is “l”, therefore
Following transition occurs :–
L ( r1 ) Ç L ( r2 ) Ç {l} = å *
0 * :– q0 ® q0
1 * :– q0 ® q0 (if 1 is absent) or 1 * : q0 ® q1 (if 1 is present) So, Ans is (d)
(1 + 11*) : q0 ® q1 q1 ® q1 4. (d) Note that
0 * :– q1 ® q1 (if 0 is absent) q1 ® q0 (if 0 is present) (b*a*) = (a*b*)* = (a* + b*)* = (a + b)*
1 :– q1 ® q1 q0 ® q1 so for (a) L ((b*a*)* (d*c*)* gives all the combinations
final state is q1 , this string is also accepted. of a and b followed by all the combinations of c & d.
(III) (0 + 1) * 1 :– Following transition occurs :– for (b) L((d*c*b*a*)*) = (a + b + c + d)*
(0 + 1) * :– q0 ® q0 ® q1 for (c) L((a*b*a*c*d*)*) = (a + b + c + d + a*)*
(0 +) (1) = (a + b + c + d)*
1 :– q1 ® q1 5. (b) Choice ‘a’ is incorrect since it does not include the
Ans final state is q1, so this string is also accepted. Hence string “a”, “b” and “l” (all of which do not end
(d) is true. with ab).
59. (a) None of choices ‘c’ or ‘d’ accept the string ‘a’, So they
60. (d) If B is not recursively enumerable then A need not be can’t be represent specified language.
recursively enumerable. 6. (a) For DFA accepting all the strings with number of ‘a’
61. (b) The language is recursive enumerable and it is
divisible by 4, four states are required similarly for DFA
undecidable
accepting all the strings with number of b’s divisible
62. (a) L1 is regular but L2 is not
by 5, five states are required and for their combination,
63. 3
states will be multiplied So 5 × 4 = 20 states will be
a * b * (ba) * a *
required.
Length O is present (as it accepts Î)
7. (b) The DFA will be
Length 1 is present (a, b)
Length 2 is present (aa, ab, ba, bb)
Length 3 is not present (bab not present) 1 0 0
Start
\ it is 3
1
64. (c) S* is countabily finite
1
2S * is power set of S*
The powerset of countabily infinite set is For these kind of problems the required number of
uncountable states are always equival to “the length of the string
\ 2S* is uncountable and S* is countable. that it is ending with” + 1
282
8. (c) Since L = X* = {0, 1}* = (0 + 1)* & R = {0n 1n | n > 0}, (a) L1 È L 2 is CFL
LUR produces (0 + 1)* which is regular language and R
(b) L1 Ç L 2 is not regular
is not regular as there is no regular expression for that.
(c) L1 * is regular
9. (b) Since L1 and L2 both are accepted by deterministic
Hence the correct Ans. is (b)
PDA (in both cases, no guessing is required for the
18. (b) Since å * is all the combinations of 0 and 1 and yet it
push and pop operations while operating the stack)
since these languages are accepted by DPDA, it will is enumerable and belongs to the category of countably
also be accepted by NPDA. infinite. But for 2å * which is the power set of
10. (b) Regular languages are closed under union, intersection, å * which is infinite. By diagonalisation argument,
complementation, kleen closure, concatenation. power set of any countably infinite set is always
According to closure properties so all of a, b, c, & d are
uncountable, hence 2å * belongs to uncountably
regular. Notice that, S* – L1 = Lc1 so, set L1 Ç L 2 is infinite set.
19. (a) Here for the languages (i) and (ii) we can design a PDA
also regular. Hence they are CFL.
11. (d) All of the above functions are total recursive functions. In (iii) and (iv) we cannot conclude that no(a) = no(c)
The total recursive functions are like recursive and no(b) = no(d) using only one stack memory so
language. Turing machine halts on each and every input they can’t CFL.
of recursive language. All of the above functions are 20. (c) Only option (c) satisfies the given machine, hence L(M)
turing computable. = {words containing aa or bb as a subword}
21. (b) Binary no. that are multiples of two is
12. (c) L1 = {anbncn, n ³ 0} = {l, abc, a2b2c2, ....}
L = {0, 10, 100, 1000, 110, 100, ...}
L2 = {a2nb2nc2n, n ³ 0} = {l, a2b2c2, a4b4c4, ....}
i.e. strings ending with 0
L3 = {a2nb2ncn, n ³ 0} = {l, a2b2c2, a4b4c2, ....} \ (b) (0/1)* 0 is the correct answer.
as we can easily see that
a
(i) L1 contains all the words generated by L2 and also it
contains some extra strings also.
Start c
22. (a)
\ L1 Ê L 2 ( or L2 Í L1 )
T

(ii) Since only l is common in L2 and L3


b
Hence L 2 Ë L3
The language generated by the above DFA is starting
13. (a) 1. 0*1* does not ensure at least one 0 at the with c followed by any no. of a’s & b’s.
beginning and one 1 at the end.
2. 00*(0 + 1)*1 ensures the specified condition. Hence L = c ( a È b ) *
3. 0(0 + 1)*1 ensures the specified condition. 23. (b) Since L1 cannot be recognized by PDA but L2 can be
14. (b) The given grammer is context-free. It is not proper since recognized by a PDA. L1 is not context free but L2 is
context free.
it includes an ?-production. A typical derivation in this
For L2 = {anbmcmdn | n ³ 1, m ³ 1}
grammar is
a’s are pushed into stack, then b’s are pushed then b’s
S ® aSa ® aaSaa ® aabSbaa ® aabbaa. are popped from the stack checking with each arrival
This makes it clear that L(G) = {wwR : w Î {a, b}*}. of corresponding c. After all b’s are popped and if no.
The language is context-free. of b’s popped = no. of c’s arrived then, as a will be at
15. (d) According to the definition of Moore machine (d) is top of stack, when the first d arrives.
the only correct option. So, no of b’s = no. of c’s [m = m]. Similarly when d’s
arrive, we can check that
16. (b) 1. r1 =Î is a regular expression representing a set
No. of a’s = No. of d’s [n = n], by poppping an a for
{Î}. It is a regular expression. every d and checking that at end of input stack is empty.
2. r2 = 0*1* is a regular expression. This can’t be done in the case of L1, since after pushing
17. (b) Since L1 and L2 are regular and context free languages a’s & then b’s, when c’s appear in input, they have to
respectively CFL are closed under regular È, Ç , be compared with a’s which are unfortunately at the
bottom of the stack and cannot be popped to do a
therefore comparison.
283
24. (b) The DFA’s construction for the grammars

S ¾¾ ® aS | bS | a | b | l are
® aS | bS | a | b and S ¾¾
respectively.
36. (d) The given FA accepts all combinations of even number
of 0’s and 1’s.
37. (a) The automation given below, accepts the words with
odd of 1’s.
The required languages are 0 0
L1 = (a + b) (a + b)* 1
L2 = (a + b)* Start Start
25. (a) ATM cannot solves the halting problem because it 1
cannot find in finite time that for the given word the clearly, the automation requires only 2 states. Hence
machine will halt or not the correct option is (a).
26. (d) Since every language can be represented through 38. (d) The unary number has a single symbol and the length
regular expression and its equivalent machine. Also of the string is its value. So we have to accept strings
for the every deterministic machine there exist its where, no of 1’s divisible by 3. On first symbols of
equivalent non-deterministic machine. number (i.e.), we will move to remainder 1 state, (q1)
27. (c) The FSM shown accept only Î. Also it is the starting when next input is received we move to remainder 2
as well as final state and no other input is there. state (q2) and on next we move to 0 remainder state (i.e.
28. (b) The FSM shown has no final states to accepts strings. q3) as shown in the choice (1).
Hence, it accepts no strings. 39. (b) Drawing the FSM for the given transition diagram
Hence, option (b) is correct. we can clearly see that if ‘q1’ is the final state then only
29. (d) It follows from the closure properties of CFL’s. CFL’s the given FSM can generate words which are all ending
are closed under È , concatenation & *, but not under with “aa”.
Ç and LC.
30. (b) For set A = {anbnan | n = 1, 2, 3....} A
the no. of comparisons are 2. first one for checking
a
No. of a = No. of b and, second one for again checking a
No. of b = No. of a’s following the b’s Start a q0 q1
As we know, a pda can do only one of these a
comparisons. Hence the given language is not context b b
free. b
31. (d) Here L1 = (a + b)* a is nothing but set of all strings of q2
a and b ending with a.
L2 = b(a + b)* is set of all strings of a & b starting with b
b.
The intersection of L1 and L2 is set of all strings starting 40. (c) The minimum state DFA accepting the above language
with b and ending with a. is
\ L1 Ç L 2 = b(a + b)*a
b a
32. (d) Here
a a
(a) is not correct because we can’t find the middle of Start q0 q1
palindrome, without guessing. b
(b) is also not correct because of same reason.
33. (b) This is a standard DFA for all strings ending with “a”. b
Hence the language is (a + b)*a. 41. (d) (a + b)* means all combination of ‘a’ and ‘b’. Hence ‘a’
34. (b) Regarding the power of recognizing of languages in (a + b)* a(a + b)* signifies that at least one ‘a’ must
(a) NDFA has same power as DFA be there.
(b) NDTMs are equivalent to DTMs 42. (d)
(c) Multiple tape TMs are equivalent to single tape 43. (c) Clearly 0’s followed by 1’s followed by 2’s being
TMs accepted so choice (c) 0*1*2* is correct.
Only DPDA Í NPDA in the power. 44. (b) (a + b) (a + b) generates all the 2 length strings aa, ba,
35. (a) Since "w Î å * whether or not w Î L , so L is ab & bb. So [(a + b)(a + b)]* will generates all the even
decidable. can be determined in finite time. length strings, including l.
284
45. (c) Drawing the dfa corresponding to the given transition (c) L = {WcWR/W in (0 + 1)*}
table. (d) L = {0n 1n | n ³ 0}
in each of the above the PDA can deterministically
0 separate the push and pop operations.
0 1 But it cannot do the same in case (a), since it has to
A B D guess middle of palindrome, In DPDA we can’t do
0 guessing. NDPA is required for this.
1 0
50. (b) The transition function
0
d ( q 0 , 0, z 0 ) = ( q0 , xz0 )
C 1 E represents that when input is 0, stack top is z0 and
current state is q0 than the stack top becomes xz0 and
1
state remains at q0.
The given set of transition functions checks for number
Use dfa minimisation algorithm
of 0’s followed by No. of 1’s. Whenever a “0” comes,
The corresponding minimum state dfa for this langauge
stack top become x and when the “1” come it is removed
can be constructed as
from stack Top. If at the end No input is left and stack
1 is empty than the word is accepted.
0
0
Hence, (b) L = {0n 1n | n ³ 1} is correct
1 1
q0 q1 q2 q3 51. (a) It is possible to have a subset of regular language which
0
is not regular and a subset of CFL which is not CFL,
1 0
but a subset of finite set has to be finite.
For example.
1. L = (0 + 1)* is regular. Let Ls = {0n 1n}
Only 4 states are needed.
46. (a) Two derivation trees are possible for aabba as given Here Ls Í L . But Ls is not regular.
below 2. L = (0 + 1)* is regular and hence also CFL. Consider
S S Ls = {0n 1n 0n | n ³ 0} Here Ls Í L , but Ls is not a CFL.
a S
a S 52. (c) The given grammar is right linear.
S S
S S S
a S a a
S
a a b
SS S a
b c
bb b a b c
S A B C
Therefore (i) and (ii) are both true. a
Choice (iii): ‘aba’ is also accepted by the given c
grammar. Therefore (iii) is false.
47. (b)
b x
1 a 3 a, b
Start a
0

b
a
b c
b
2 a b c
S A B C

We can clearly see that any no. of loops of “ab” and a


“bb” can be accepted and ‘0’ is the accepting state.
48. (c) The given regular expression 00(1 + 10)* is not
complete to denotes all strings of 0’s and 1’s with 53. (c) L1 = ambn | n = m2
atleast two consecutive 0’s. L2 = ambmcmdn | m, n > 0
The correct regular expression must be
L3 = ambmcndn | m, n > 0
(0 + 1)*00 (0 + 1)*
49. (a) Deterministic PDA can accept In L1, n = m2 cannot be checks in stack as m2 is a
(b) The set of all strings of balanced parenthesis. nonlinear function. Hence it is not CFL.
285
L2 requires 2 comparisons on no. as itself. Therefore the remaining productions left after removing
Þ no. of a’s = no. of b’s and no. of c’s. This cannot useless, unit and l-productions
be done by single stack. S ¾¾
® aA | a, A ¾¾
® aa | aaA
L3 requires 2 comparisons, but only one at a time is 60. (a) The TM carries out the functions of (m – n) in (0 m 10n)
required
® when m ³ n, the output is difference between m and n.
Þ no. of a’s = no. of b’s and no. of c’s = no. of d’s.
® when m < n, the output is blank.
This cannot be done by single stack.
54. (c) L1 and L2 are context free languages. We can see that 61. (c)
L2 is in fact a regular language having regular 62. (b) Suppose, S = aaab, | s | = 4 . The prefixes are
expression a(ba)*. Sp = {l, a, aa, aaa, aaab}. Here aaab is not a proper
L1 is a language containing strings having equal prefix.
number of a’s and b’s Note: The proper prefix of string S is a prefix, which is
not same as string S.
Þ L3 = L1 Ç L 2 is a context free language.
A string of length 4 has 4 proper prefixes. A string of
Q class of context free languages is closed under length 5 has 5 proper prefixes. For a string of length n,
concatenation and kleene closure. Therefore L4 = therefore we can have ‘n’ proper prefixes.
L1.L1* is a context free.
63. (a) The following CFG
55. (c) Drawing the equivalent turing machine we have
S ® aB | bA
A ® ba | aS | bAA
0, 0, R
Y, Y, R B ® b | bS | aBB
0, X, R
q0 q1 q2 0, 0, L by observing the given CFG we can see that with each
1, Y, L Y, Y, L non-terminal, number of a’s and b’s get equalled.
Y, Y, R The language is the strings of terminals that have equal
X, X, R number of a’s and b’s
64 (a) Rule: a* (a*b)* = a*(ba*)* ¹ (a + b)*
q3 q4
B, B, R So, 0* (10*) * = 1* ( 01*) *

Y, Y, R 65. (c) The strings with the first, 4th and 7th bits as ‘1’ will
look in the following format
56. (d) R1 = (a | b)* = (a + b)* ...(1) 1 _ _ 1 _ _ 1.
R2 = (a* | b*)* = (a* + b*) = (a + b)* ...(2) So, there can be 16 possible combinations for the
R3 = (Î | a | b*)* = (Î + a + b)* = (a + b)* ...(3) above format. But in the given DFA, only 7 strings of
these will be accepted. They are,
Clearly from (1), (2) and (3)
1. 1001001
57. (b) Clearly, we can observe that the minimum string
accepted is aabb. 2. 1001011
The corresponding L(M) = {W/W Î (a + b)* aabb 3. 1001101
(a + b)*} 4. 1001111
58. (b) The correct statement follows from following theorem: 5. 1011001
Theorem: If L1 and L2 is a pair of complementary 6. 1101001
language then either
7. 111001
· Both L1 and L2 are recursive.
66. (b) Diagonalization language, Ld is defined as
· Neither L1 and L2 are recursively enumerable.
Ld = {TM that accepts its own code}
· One is recursively enumerable but not recursive,
the other is not RE. Ld is clearly RE but not REC.
Option (b) is not possible, since if L1 is recursive, then 67. (c) Single tape turing machine can simulate n-moves of
k-tape TM in O(n2)
L2 = Lc1 will also be recursive. 68. (b) Since 0* (10*) = 0* (1*0*)* for
59. (c) B and C are useless, since they are not generating any (a) (1*0) 1* = (1*0*)1*
terminal.
286
(b) 0 + (0 + 10)* = 0 + (0* 1*0*) =(0*1*0*) Hence its running time is O(n) (its input is encoded in
(c) (0 + 1)* 10(0 + 1)* binary).
69. (b) L Î NP does not imply that L’ Î NP. Since, closure of Conclusion
NP under complementation is as yet unresolved RELPRIME € P
problem. Also L Î NP does not imply L’ Î P, unless L
73. (c) If there is an NP-complete language whose complement
Î P, which may or may not be so.
is in NP. Then the set NP = CO-NP which implies NP =
70. (c) P, Q and R be three languages P.
Let P = (a + b)* i.e. NP = CO-NP = P
Q = ab So complements of any language is NP will in NP as
Then PQ = (a + b)* ab = R well P.
Here P, Q and R are regular. So, both (a) & (b) are true choice (c) is correct.
Let P=f 74. (c) S ® a S/bA, A ® d/cc A
Q = {anbn | n ³ 0}
PQ = R = f a cc
Here P and R are regular but Q is not b d
S A x
So Q need not to be regular
71. (b) Proof : First, we have to prove that TSP belongs to NP. We can clearly see that X is a final state. And the
If we want to check a tour for credibility, we check that corresponding language regular expression is
the tour contains each vertex once. Then we sum the a*b(cc)*d
total cost of the edges and finally we check if the cost
75. (d) Let start with S and develop some string
is minimum. This can be completed in polynomial time
thus TSP belongs to NP. Secondly we prove that TSP 1. S ® PQ using S ® PQ
is NP-hard. One way to prove this is to show that 2. S ® xQ using P ® x
Hamiltonian cycle TSP (given that the Hamiltonian cycle
3. S ® xy using Q ® y
problem is NP-complete). Assume G = (V, E) to be an
instance of Hamiltonian cycle. An instance of TSP is Hence n = 2 and number of productions required is 3
then constructed. We create the complete graph = Now check n2 i.e. 22 ¹ 3 eliminates (a)
(V, P £ G¢E¢), where E¢ = {(i, j) : i, j Î Vand i ¹ j. Thus, the
2n = 2.2 = 4 ¹ 3 \ eliminates (a)
cost function is defined as:
2n + 1 = 2.2 + 1 = 8 ¹ 3 \ eliminates (b)
t(i , j ) = 10.1 Î/ Î j) (i, if 1, j) (i, if 0EE
2n – 1 = 2.2 – 1 = 3 = 3
Now suppose that a Hamiltonian cycle h exists in G. It
76. (a) For (a) we can construct a DFA
is clear that the cost of each edge in h is 0 in Gas each
edge belongs to E. Therefore, h has a cost of 0 in G ¢¢.
Thus, if graph G has a Hamiltonian cycle then graph G 1
A B
has a tour of 0 cost. ¢ 0
Conversely, we assume that G' has a tour h' of cost at 0 1
most 0. The cost of edges in E' are 0 and 1 by definition.
B 0,1
So each edge must have a cost of 0 as the cost of h' is
0. We conclude that h' contains only edges in E.
So we have proven that G has a Hamiltonian cycle if which will recognize the series
and only if G' has a tour of cost at most 0. 1, 2, 4, ....2n .... in binary as
Thus TSP is NP-complete. 1, 10, 100, 1000, ...
72. (d) Euclidean algorithmfor finding gcd(x, y):
ì 2n ü
function gcd(hx, yi) Choice (b) is í1 ; n ³ 0 ý
î þ
if (y = = 0) return x else return gcd(hy, x mod yi)
Choice (c) is {w | n 0 (w) = n3 (w)}
Theorem
Choice (d) is {1n 01n, n ³ 0}
The Euclidean algorithm called on input hx, yi runs in
time DFA’s cannot be constructed for b, c and d since these
are not regular languages.
O(log(x + y)).
287
77. (d) The required regular expression is 87. (c) (A) Incorrect since the production has same non
r = b+ + ab+ + Î terminal in both sides, so definitely ambiguous.
(B) Since S”SS this leads to conjunction of every
= (Î + a)b+ + Î
possible string to make a valid string in L(G).
r = b* + ab+ (C) Context free languages are accepted by push
78. (c) In DFA the no. of states are always more than NFA, so down automata so true.
if NFA has N states DFA will have 2N states. (D) The language is not regular so DFA is not
79. (c) The valid strings will be where no. of a's 6, 12, 18, 24 possible.
No. of b's = 8,16,24 88. (a) S1 can be represented using a DFA so it is regular S1 is
correct.
S2 can’t be represented by DFA but it requires PDA to
accept. So is S2 is CFG not regular. S2 is false.
89. (b) (A) It is not necessary at all.
(B) {an bn} U {an bn cn} = {an bn cn} always true
No. of states = 7 for a so correct.
(C) {an bn} I {an} = {an} not CFG so false.
(D) Not necessary.
90. (b)

No. of states = 9 Start & end are same (a) so the minimum no. of states
Total 9+7–1 = 15 required are 3.
1 subtracted due to 2 final states. If string traversal doesn’t stop at (a) then string length
80. (c) L1 would be accepted by PDA so can’t be regular. is not divisible by 3.
L2 similarly can’t be accepted by DFA so not regular. 91. (a) C language is context free language entirely based upon
L3 & L4 both require only finite no of zeros. the productions.
So both regular. 92. (b) Pushdown Automaton uses stock as data structure &
81. (a) Since it is possible to create a turing machine for the
languages accepted by PDA is regular.
problem, 20 this problem is decidable.
93. (c) A problem is said to be NP- complete, if it is both NP &
82. (b) Pushdown Automaton uses stock as data structure &
languages accepted by PDA is regular. NP hard.
83. (c) A problem is said to be NP- complete, if it is both NP & 3-SAT problem is NP complete so a reduction of
NP hard. 3-SAT problem is NP complete so a reduction 3-SAT problem to P & P to 30-SAT.
of 3-SAT problem to P & P to 30-SAT. So this infers that P is NP complete, since it is reducible
So this infers that P is NP complete, since it is reducible
to a NP complete problem.
to a NP complete problem.
84. (a) A language L is said to be recursive if there exists any 94. (a) A language L is said to be recursive if there exists any
rule todetermine whether an element belong to language rule to determine whether an element belong to
or not, if languagecan be accepted by turning machine. language or not, if language can be accepted by turning
So there exist the rules so L is recursive. machine.
85. (b) Since L can be effectively enumerated so L has to be So there exist the rules so L is recursive.
regular, but is doesn't mean that the decisions are finite.
95. (b) Since L can be effectively enumerated so L has to be
86. (c) The strings accepted by the given automata are of type.
Option regular, but is doesn’t mean that the decisions are finite.
12 34567 96. (c) The strings accepted by the given automata are of type.
1--1--1 Option
These four blank spaces can have 0 or 1, so total 12 34567
24 = 6 strings are possible, but the given automata does 1--1--1
not accept all of those.
These four blank spaces can have 0 or 1, so total 24 = 6
1. 1 1 1 1 0 0 1
2. 1 1 0 1 0 0 1 strings are possible, but the given automata does not
3. 1 0 1 1 0 0 1 accept all of those.
4. 1 0 0 1 0 0 1 1. 1 1 1 1 0 0 1
5. 1 0 0 1 0 0 1 2. 1 1 0 1 0 0 1
6. 1 0 0 1 1 0 1 3. 1 0 1 1 0 0 1
7. 1 0 0 1 1 1 1
288
4. 1 0 0 1 0 0 1 2. S ® bA ® abA– ® abbA– ® abbaB ® abbaa
5. 1 0 0 1 0 0 1 3. abbaB ® abbaaS ® abbaab
6. 1 0 0 1 1 0 1 From (2) option (D) is false also from (1), (2) & (3) (a),
7. 1 0 0 1 1 1 1 (b) & (d) are false.
97. (A) Incorrect since the production has same non terminal So only (C) satisfy
in both sides, so definitely ambiguous. 104. (c) P1 ® decidable
(B) Since S”SS this leads to conjunction of every possible P2 ® undecidable
string to make a valid string in L(G). If P1 or P2 is reducible to P3 then P3 also has same
(C) Context free languages are accepted by push down properties as P1 & P2.
automata so true. So if P2 is reducible to P3 then P3 is also undecidable.
98. (a) This turning machine starts at 90 if it doesn’t get any 105. (b) From the given FSM, it is clear that a not necessity
input symbol but B then it halts. followed by only 2b due to self loop at final state. But
So if (00 + 1) *is chosen then the M/C can halt. Option at least 2b’s are there. abb substring not always,
(b) is wrong. Similarly aa not always.
Option (c) & (d) are possible but not necessary. 106. (b) The rules here used will be.
Option (a) (0 + 1) * 1 or more occurrence of 0 or 1. All those languages which are recursive their
So 0, 1, 00, 01, 10, 11........are valid strings & the machine complements are also recursive.
doesn’t halt for them. So option (a) & (b) can be correct.
99. (a) L is accepted by M(NFA) but NFA M1 has Now languages which are recursively enumerable but
not recursive, their complements can’t be recursively
enumerable. So only option (b) is correct
107. (b) In all the options there is linear relationship among
strings so all CFL’s, but L1 & L3 can be accepted by
PDA, L2 can be accepted by deterministic CFL due to
presence of special symbol D which tells the middle of
the string, so deterministic.

So this accept L1. 108. (c) The given NFA when converted to NFA without Î-
L1 will accept not only L but also substrings of L. moves.
So L1 is a subset of L
100. (c) 3 SAT problem is both NP & NP hard so it is NP 0 1
2
complete, but 2 SAT problem is solvable in Polynomial 1
Start q0 q1 2 q2
time so it is in class P.
0 1
101. (a) Due to the 3 one’s in the upper edges & 3 one’s in
1 2
lower edges to reach to final state the no of 1’s is always 0
divisible by 3 & 0’s are always in pair in forward &
back edge so, no of zero’s is divisible by 2.
102. (b) Language {an bn cm + n / m, n ³ 1} is a context free Note: The previous state from which there is an Î-
language since it can be represented by pushdown Move, if it goes to the final state then it also becomes
automata, but it is not regular since DFA can’t count the final state as well.
the no. of a’s & b’s and then check the sum for 109. (c) From the above NFA we can clearly see that it accepts
occurrence of c. strings only if “0 followed by 1 followed by 2” i.e. strings
103. (c) S ® bS | aA |b like 2 followed by 0 or b and 1 followed by - are not
A ® bA | aB accepted. Clearly, (c) is the correct option.
B ® bB | aS | a 110. (b) 111. (c) 112. (b)
Let Na(w) & Nb(w) denote of a’s &b’s in strings.
113. (c) Since both A and B are nullable therefore S is also
Some valid strings are
nullable. Therefore all A, B and S are nullable.
1. S ® bS ® bbS ® bbb (any no. of b)
289
114. (d) 116. (b) val ((a(a + a*aa) + aaa)*) = val (a(a + a*aa) + aaa)*)
115. (b) Val (a, (a + a*aa)) = max (val (a), val (a + a* aa)) = max (val (a*a + a*aa)),
= max (0, val (a + *aa) val ((aaa)) + 1
val (a) = 0 = max (1, 0) + 1
= val (a + a*aa) =1+ 1=2
= max (val (a), val (a*aa)) 117. (a) Val (a*b*b*b*)* = val (a*b*b*b*) + 1
= max (0 val (a*aa)) = val (a* + b* + b* + b*) + 1
= val (a*aa) = max (val (a*), val (b*)) + 1
= max (val (a*), val (aa)) = max (val(a) + 1 +, val (b) + 1)) + 1
= max (val (a*), 0) = max (1, 1) + 1
= val (a*) =1+ 1=2
= val (a) + 1 = 0 + 1
=1

Você também pode gostar