Theory of Computation
Theory of Computation
CHAPTER
2
Finite Automata (FA)
(i) Derterministic Finite Automata (DFA)
A DFA, M Q, q0 , , F ,
Where, Q = set of states (finite)
q0 Q = the start/initial state
= input alphabet (finite)
(use only those symbols which create a particular string)
F Q = the set of final state
(Final state can be 0 (no final state) or more than 1 or it can have all states as final states.
= transition function (responsible for making the transition/movement from one state to other state
If machine halt at any final state that means it is accepting that string and if it halts at any other state it
simply rejects the string.
Note: Behaviour of the machine is controlled by ‘ ’ responsable for switching of state from one to other
state.
:Q Q where, Q = input state, = input alphabet
e.g. qi , a q j where, qi = state, a = reading and qj = move to other state
www.careerendeavour.com
Note: Deterministic (exactly one choice)
(If you are at a state of read the input then after that you have to do the movement)
Total : On every state we need to define the transition for every symbol of input alphabet i.e. we need
to explain explicitly that where you want go after reading input.
Notations:
(i) State : qi (ii) Initial state : q0 (iii) Final state : qs
whenever, initial state becomes final state, null string is accepted.
a
Note: (i) a
*
q0
*
2 3
Therefore, total a , a, a , a ,........
a
(ii) q0
a
qi
†
2 3
Therefore, a a, a , a ,..........
a,b
*
(iii) q0
a, b , a, b, a 2 , b 2 , ab, ba.......... (universal language)
Finite Automata 15
a,b
(iv) a,b
q0 qi
a, b a, b, a 2 , b 2 , ab, ba.......
(not final, so can’t accept (a))
a
(v) q0 qi
a
a
(vi) a
q0 q1
(vii) a
q0 qi
L a 2 n1 | n 0
L a n
| n is odd # L a, a3 , a 5 , a 7 ,..........
L a n
| n mod 2 1
Although a given FA corresponds to only one language, a given language can have many FAs that accept it.
Note that you must always be careful about the empty string: should the FA accept or not. In the preceding
example, the empty string is accepted because the start state is also an accept state.
Another useful technique is remembering specific symbols. In the next example you must forever remember the
first symbol; so the FA splits into two pieces after the first symbol.
www.careerendeavour.com
16 Finite Automata
SOLVED PROBLEMS
(ii) L a | n 0 and n 4
n
(iii) L a | n mod 5 2
n
(iv) L w a | w mod 7 1
*
a
Soln. (i) q0 , a, a , a .......
2 3
a b
Therefore, q0
b
qi , b, b , b ....... ab, a b, a b , ab .....
2 3 2 2 2 2
a b a,b
Therefore, b a
q0 qi q3
(Total concept follow, we need to define each and every state explicity in DFA).
n
(ii) L a | n 0 and n 4
0, a, a , a , a , a ,.........
2 3 5 6
q0 a
a
a a a a a
q0 q1 q2 q3 q4 q5
a a
q4
(iv) L w a | w mod 7 1
*
w am a n mod 7 1
w n 0,1, 2, 3, 4,5, 6 Total 7 states
Finite Automata 17
a a a a a
q0 q1 q2 q3 q4 q5
a a
q6
2.
L2 a b c
a m n p
b c | m 1, n 1, p 1
a b c
a b c
q0 q1 q2 q3
c
a
b,c
a,b
Temp
a,b,c
3. Design a DFA for the following language:
(Set of all binary strings which starts with 1010)
1010w | w 0,1 *
1,0
1 0 1 0
q0 q1 q2 q3 q4
1
0 1
0
q5
0,1
4. Design a DFA that ends with 1010
1
www.careerendeavour.com
1 1
0
1 0 1 0
q0 q1 q2 q3 q4
0
0
5. Design a DFA for the following over a, b
(i) The set of all strings containing exactly 3 a’s.
b b b b
a a a
q0 q1 q2 q3
a
Trap
(a,b)
18 Finite Automata
(ii) Atleast 3 a’s:
b b b b,a
a a a
q0 q1 q2 q3
Example : Transition table for the FA that accepts all binary strings that begin and end with the same symbol.
Input
0 1
S A C
A A B
State
B A B
C D C
D D C
0 1
q0 q0
q1
1
q1 q2
q3
0 0
1 0 1
q0 q1 q2 q3 1 q2 q4
q0
q3 q1
q2
0
0 q4 q3
q4
q4
*
1 the language L = x a, b , length of n is multiple of 3.
Example: The smallest DFA accepts
[GATE-2002]
q0 a,b q1 a,b q2
www.careerendeavour.com
a,b
(a) 2 (b) 3 (c) 4 (d) 5
Soln. (b)
Example: Consider the machine M [GATE-2005]
b a b
a b
a a
a,b
The language recognized by above machine is:
*
(a) w a, b / every a in w, is followed by exactly two b's
(b) w a, b
*
every a in w, is followed by at least two b's
(c) w a, b
*
w contains the substring 'abb'
Finite Automata 19
*
(d) w a, b w does not contain 'aa' as a substring
Soln. (b)
Combining the machines:
M1 M2
L1 L2
L1 complement of a FSM
I = the machine of language L is given
O = the machine of language L
Steps:
(i) Make the final states to non-final states and
(ii) Non-final states to final states (Final non-final)
Problem: Design a DFA which accepts the set of all binary string which does not starts with 1101.
(0, 1)
1 1 0 1
q0 q1 q2 q3 q4
Soln.
0
1 0
0
Temp
0,1
(0, 1)
1 1 0 1
q0 q1 q2 q3 q4
1 0
www.careerendeavour.com
1 1
q5
0,1
*
Problem: Design a DFA for L w a, b | N a w is even AND Nb w is even
b a a
b
a b
A B C D
Soln.
a b
L1 L1
L1 L2 m n
a a
A B ; C C . Therefore, BC
Here, first we will check that on A state, as we read ‘a’ we move to B on C state, as we read ‘a’ we
move to C.
Therefore, AC state complex move to BC state.
20 Finite Automata
b b
A A ; C D
b a
B B B A b
b a
D C C C AC AD
b
b a
B B B A a a a b
b
b a
D C D D BC BD
b a
A A A B b
b a
D C D B
If L1 machine have m state and L2 machine have n state, then the combined machine L1 L2 h a v e
m×n state.
• If the OR operation is applied then
*
L w a, b | N a w is even OR N b w is even
b b a a
a b
A B C D
a b
L1 L2
Therefore, the number of final states will change.
As here, A and C are final state, so where the A and C come, it will become final state
AC AD
b
a a a a
b
BC BD
www.careerendeavour.com
b
• L1 L2 w | w L1 and w L2
So, L1 is final and L2 is non final > L1 and L2
If L2 L1 BC will be final.
• L1 L2 L1 L2 L2 L1
L1 L2 = AD and BC both will be final states.
Q q 0 , q1
• In NFA we have zero (0) choice, one choice, or more than one choice depending upon the states, so
it is called non-deterministic.
Transition in NFA :
a qj qj
qi qi
a qk qk
a b
e.g. q0
q1 For a*b*
a b
* *
e.g. q0 b q1 Also for a b
Note: If in DFA, all the states are final states, then langauge is considered as universal language.
* *
a, b . But, in NFA, if all the states are final states then it is not necessary that it is a universal
language (like a*b*).
a
www.careerendeavour.com
b c
q0 q1 q1
(2) b c
c
In NFA, trap state is not considered becuase if transition is not defined for a particular I/P symbol or a
state, then given string is rejected automatically through the machine i.e. check for abaab.
a b a b
e.g. q0 qf or q0 qf qk
a a b
The machine rejects abaab.
Problem: Design an NFA over 0,1 accepting the set of all binary strings ending with 110.
1,0
Soln. q0 q1 q2 qf
1 1 0
Here, we need not to think about other transitions.
22 Finite Automata
e.g. 110110
10110
q0 q1 q2 q3 qf
0,1 0,1 0,1 0,1
Problem: Design a NFA over 0,1 accepting the set of all binary strings which start and end with
different symbol.
1, 0
q1 q3
1 0
Soln. q0
0
q2 q4
1
1, 0
www.careerendeavour.com
Note: We can construct the same NFA through more than one machine, but we apply the shortest states
NFA.
Problem: Define NFA that accepts all binary strings where the last symbol is 0 or which contain only 1’s?
Soln. Here is one:
0
A B C D
1
0,1
*
Problem: Define NFA for a* ab ,
Finite Automata 23
a
Soln. a b
D 0,1
A
0,1 1 1
C
For example, consider the state {A, B, D}. On a 1, the NFA, if in state A, can go to states A or C, if
in state B dies, and if in state D stays in state D. Thus, on a 1 the DFA goes from {A, B, D} to {A, C, D}. Both
of these are accept states because they contain D.
0 0
AB ABD
A 0 1 0 1
www.careerendeavour.com
1
AC
1 ACD
1
If there are -transitions, then you have to adjust the process slightly. Do the following:
(i) The start state becomes the old start state and every state reachable from there by -transitions.
(ii) When one calculates the states reachable from a state, one includes all states reachable by -transitions
after the destination state.
This is the result of applying the preceding algorithm to the NFA given in figure below.
0
A B C D
1
0,1
The start state consists of A and the two states you can reach by transitions, the state is thus {A, B, C}
24 Finite Automata
ABC
0 CD 0
1 0 0 1
AC C
q0 0/1
Problem: Design a mealy machine which increments the given binary number by 1
Soln. Assume, reading of symbols should be from right to left.
(1/1)
www.careerendeavour.com
q1
0/1 1/0 0/0
0/1
q0 (0, 0) OR q0 q0
1/0
q2
(1/0)
Finite Automata 25
1 0 1 0 0 1 0 1 0 1
0 0 1 0 0 0 0 1 0 0
So, now we will count the number of 1’s
Therefore, 2(2 times 101 come)
0
0
www.careerendeavour.com
1
1
q/0
0 q/0
1 q/0
2 q/1
3
1 0 1
0
Mealy Machine:
• Input string w w n then output string = n
Moore Macine:
• Input string w w n then output string n 1
Problem: Design a Moore machine which finds the remainder of decimal representation of a binary number
when divided by 3.
Soln. Remainder 0,1, 2
0,1....... binary
26 Finite Automata
0 1
q/0
0 q/1
1
1
0
0
q/2
2
0
0/0
0/0
Mealy to Moore (Conversion): www.careerendeavour.com
a/0 (Mealy machine) a (Mealy machine)
b/1 a/0
qi
a/0 qi0/0
c/1 b
a/0
qi1/1
b
• When there are two different output, we need to split the state into two, as there are two output.
• When all the incoming transition output are same then we need not to split the state, we just simply put that
transition output into the state output.
Finite Automata 27
Example:
a
a/0 (Mealy)
a/1
qi0/0
qi
a/1
b/1
b
b/1
Decision Properties:
(1) Finiteness/Infiniteness
(2) Emptyness/non-emptyness
(3) Equalness
1. Finiteness / Infiniteness:
The steps to check the condition are as follows:
(a) Select the state which can’t be reached by the initial state and delete them.
(b) Select those states from which we can’t reach to final state and delete them.
(c) If the resulting machine is free from cycles and self loops then the machine accepts finite language else the
machine accepts infinite language.
Example:
0,1 0,1
q0 1 q1 q2 q0 1 q1 0 q2
0
www.careerendeavour.com
1 0
q3 q4
q0 1 q1 0 q2 0
1 0 q0 1 q1 0 q2
0
1 No cycle or self loop so accept
q3 q4 finite language
0
1
28 Finite Automata
2. Emptyness/non-emptyness:
• The steps to check the condition is given below
(a) Select the state which can’t be reached from the initial state and delete them.
(b) If the resulting machine is free from final state then it will accept empty language otherwise non-empty
language
1
0,1
q0 1 q1 0 q2 q0 1 q1
Example:
0,1 0
The machine doesn’t contain final state so accepts empty langauge.
Example:
0 1 0
0,1
q0 1 q1 q2 q0 1 q1
0
0,1
The machine contains final state so accepts non-empty language.
3. Equalness:
Two finite state machines M1 and M2 are said to be equal if both machines accepts same set of strings i.e.
M1 M 2 if L M1 L M 2
• Equal machines need not to contain same set of states
• Two machines M1 and M2 are said to be isomorphic to each other if both of them
• accepts same language
• contains same number of states
• have the same properties.
Steps to check the equalness of two machine is given below:
(a) Construct the transition table that contains pair of initial states (P, Q) where, P is from machine M1 and Q is
from machine M2.
(b) Construct the transition table
(c) In the construction process, we get any pair of the form (final, non-final) or (non-final, final), stop constructing
the table and declares that the machines are not equal else after completion of the table if no such condition
www.careerendeavour.com
generated the machines are equal.
Example:
a
b
A B a b
b a
M1 : M2 : P Q R
b b a a
C D b a
a
b
a b
A, P A, P C, Q
C, Q D, R A, P
D, R B, R D, R
B, R D, Q A, R
State (A, R) is (final, non-final) so both the machines are not equal.
Finite Automata 29
1 0
1
0 1 1 0
1
0
0 1
1 0 0
We can see that it is not possible to ever visit state 2. States like this are called unreachable. We can simply
remove them from the automaton without changing its behaviour. (This will be, indeed, the first step in our
minimization algorithm.) In our case, after removing state 2, we get the automaton on the right.
As it turns out, however, removing unreachable states is not sufficient. The next example is a bit more
subtle (see the automaton on the left).
1
0
1 1
0
0 1 1
0 0, 2 1
1 0
2 0
We now formalize the above idea. Let A be a finite automaton. We will say that w * distinguishes between
two states p, q Q if either p, w F & q, w F , or p, w F & q, w F . Two states p, q Q
are called distinguishable iff there is a word that distinguishes between them. States that are indistinguishable
will also be sometimes called equivalent.
Lemma-1: Suppose that B is a DFA without unreachable states. Then B is minimum if and only if all pairs of
states are distinguishable.
www.careerendeavour.com
Lemma-2: State indistinguishability is an equivalence relation.
Lemma-3: Let p, a p ' and q, a q ' . Then, if p ', q ' distinguishable then so are p, q.
To minimize A, after removing unreachable states, we will find the equivalence classes of the indistinguishability
relation and join all states in each class into one state of the new automaton A. To determine transitions, if X is
an equivalence class, we pick any q X and define X, a Y where Y is the equivalence class that
contains q,a .
To determine which states are equivalent, we will use the following method. Instead of trying to
figure out which states are indistinguishable, we will try to figure out which states are distinguishable. Clearly, if
p F and q F then p, q are distinguishable, since they can be distinguished by . Then we iteratively exam-
ine all pairs of states. For each pair p, q we do this. If we find a symbol a, such that p, q and q, a are
distinguishable, then we mark p, q as distinguishable as well. We iterate this untill no more pairs are marked.
When we are done, the non-marked pairs are equivalent. The complete algorithm is given below.
30 Finite Automata
Cb 00 *0, Ce 0*100*
Cc 00 *1, Cf 0*10*1 0 1 *
L is the union of three of these classes, Cc, Cd and Ce.
The relation RL for L has xRLy, if and only if either
(i) x and y each have no 1’s.
0
Start a b
1 0 1
C1 Cb Cc C2
c d Cd
1 0
1 Ca
0 Ce
C3=Cf
e f
0 www.careerendeavour.com
1
0,1 Diagram showing R is a refinement of R .
M L
DFA M accepting L.
Minimization Algorithm:
Step-I: Remove unreachable states.
Step-II: Mark the distinguishable pairs of states. To chieve this task, we first mark all pairs p, q where p F
and q F as distinguishable. Then, we proceed as follows.
repeat
for all non-marked pairs p, q do
for each letter a do
if the pair p, a , q,a is marked.
then mark p, q
untill no new pairs are marked.
Step-III: Construct the reduced automaton  .
We first determine the equivalence classes of the indistinguishability relation. For each state q, the equivalence
class of q consists of all states p for which the pair p, q is not marked in Step-II.
The states of  are the equivalence classes. The initial state q̂ 0 is this equivalence class that contains
q0. The final states F̂ are these equivalence classes that consist of final states of A. The transition function ̂ is
defined as follows. To determine ˆ X, a , for some equivalence class X, pick any q X and set ˆ X, a Y ,
Y is the equivalence class that contains q,a .
a,b
B
a a,b A
E
a,b
A D
A
a,b b
b a
C
G
b
F a
www.careerendeavour.com
Step-1: Unreachable states in above diagram:
F and G are unreachable states, So, we will remove them.
So, now the DFA will look like
B
a a,b a,b
A D
A A
E
a,b
a,b
b
C
B
C
(Here, E and A are distinguishable, so, we have to put ‘x’
D × × × cross-mark in there common box). Similarly, in others.
E × × ×
A B C D
Now, the transition function is considered to find out another way of distinguishable state and it helps to fill the
remaining particular state in the table.
So, A, a B
Distinguishable state
C, a D
A, b C
Distinguishable state
C, b D
A, a B
Distinguishable state
B, b D Non-distinguishable
B × state
A, a B C ×
Distinguishable state
B, a D D × × ×
E × × ×
B, a D
A B C D
Distinguishable state
C, a D
D, a E
Distinguishable state
E, a E
D, b E
Distinguishable state
E, b E
www.careerendeavour.com
As in the above table, we will merge ‘B’ and ‘C’ and ‘D’ and ‘E’ because they both are the non-distinguishable
state.
a,b
A BC D,E
a,b a,b
(Minimised DFA)
e.g. q0 q1
q0 q1 q2
(NFA)
• -clousere q :
The set of all states reachable from ‘q’ by taking transitions including ‘q’
-closure q 0 q 0 , q1 , q 2
-closure q1 q1 , q 2
-closure q 2 q 2
Firstly: We will consider ‘q0’ as the initial state of an equivalent DFA i.e. q 0 , q1 , q 2 initial state.
Now, we need to tell all the transitions a, b, c with respect to initial state of -closure q 0
If we read ‘a’ at q0:
q 0 , q1, q 2 , a -closure q 0 , a -closure q1 , a -clouser q 2 , a
q1 , q 2 , b -clouser q q1 , q 2
read ‘c’
q1 , q 2 , c closure q 2 q 2
q 2 , a trap state
read ‘b’
q 2 , b trap state
read ‘c’
34 Finite Automata
q 2 , b -closuer q 2 q 2
a b a,b,c
b a
q0, q1, q2 q1, q2 trap
c
c a,b
q2
www.careerendeavour.com
Finite Automata 35
SOLVED PROBLEMS
1. State True or False with one line explanation. A FSM (Finite State Machine) can be designed to add two
integers of any arbitrary length (arbitrary number of digits).
[GATE-1994]
Soln. FALSE, A FSM (Finite State Machine) can’t be desgined to add two integers of any arbitrary length because
FSM have finite memory and can’t store integer of any arbitrary length.
2. A finite state machine with the follows state table has a single input X and a single output Z.
0/0 1/1
A B
1/1
1/0 1/0 0/1
0/0
D C
0/1
0 1
q2
0,1
So the numbers 1, 2, 4, 8,...., 2n.... written in binary can be recognized by a deterministic finite state automaton.
4. Let L be the set of all binary strings whose last two symbols are the same. The number of states in the minimum
state deterministic finite state automaton accepting L is
(a) 2 (b) 5 (c) 8 (d) 3
[GATE-1998]
Ans. (b)
Soln. The number of states in the minimum state deterministic finite state automaton accepting all binarystrings whose
last two symbols are the same is 5.
0
0
B C
0 1
A 0 1
0
www.careerendeavour.com
D
1
E
1
5. Consider the regular expression (0 + 1) (0 + 1)...n times. The minimum state finite automaton that recognizes
the language represented by this regular expression contains
(a) n states (b) n + 1 states (c) n + 2 states (d) None of these
[GATE-1999]
Ans. (b)
Soln. The minimum state finite automaton that recognizes the language represent by regular expression (0 + 1) (0 +
1) .... n times is n + 1.
The language contains strings with exactly length n.
(n + 1) states are required to count length upto n. No trap state is required since we are making minimal FA, not
minimal DFA. For example, for n = 2 the design is shown below.
q0 0, 1 q1 0, 1 q2
Finite Automata 37
6. Given an arbitrary non-deterministic finite automaton (NFA) with N states, the maximum number of states in an
equivalent minimized DFA is at least [GATE-2001]
2 N
(a) N (b) 2 (c) 2N (d) N!
Ans. (b)
Soln. For an arbitrary NFA with N states, the maximum number of states in an equivalent minimized DFA is 2N.
7. Consider a DFA over {a, b} accepting all strings which have number of a’s divisible by 6 and number of
b’s divisible by 8. What is the maximum number of states that the DFA will have ? [GATE-2001]
(a) 8 (b) 14 (c) 15 (d) 48
Ans. (d)
Soln. A DFA over = {a, b} accepting all strings which have number of a’s divisible by 6 and number of b’s divisible
by 8 is a grid machine (product automata) having 6 × 8 = 48 states.
8. The finite state machine described by the following state diagram with A as starting state, where an arc label is
x/y and x stands for 1-bit input and y stands for 2-bit output
0/01
A 0/01
B 0/10
C
(a) Outputs the sum of the present and the previous bits of the input
(b) Outputs 01 whenever the input sequence contains 11
(c) Outputs 00 whenever the input sequence contains 10
(d) None of the above
[GATE-2002]
Ans. (a)
Soln. The state diagram represents the FSM which outputs the sum of the present and previous bits of the input.
State A represents last bit a 0 and B and C represents last bit is 1.
9. The smallest finite automaton which accepts the language L = {x | length of x is divisible by 3} has
(a) 2 states (b) 3 states (c) 4 states (d) 5 states
[GATE-2002]
Ans. (b)
Soln. www.careerendeavour.com
The minimal finite automaton with 3 states which accepts the language L = {x | length of x is divisible by 3} is
as follows:
q0 0, 1 q1 0, 1 q2
0, 1
1 0 0, 1
0 0 1
Let S denote the set of seven bit binary strings in which the first, the fourth, and the last bits are 1. The number
of strings in S that are accepted by M is
(a) 1 (b) 5 (c) 7 (d) 8
[GATE-2003]
38 Finite Automata
Ans. (c)
Soln. The given bit pattern can be represented as:
1 1 1
The four blanks can be filled in 24 = 16 ways. Therefore there are 16 such strings in this pattern. Not all of these
are accepted by the machine. The strings and its acceptance is given below:
accepted
1 0 0 1 0 0 1
1 0 0 1 0 1 1
1 0 0 1 1 0 1
1 0 0 1 1 1 1
1 0 1 1 0 0 1
1 1 0 1 0 0 1
1 1 1 1 0 0 1
Only these seven strings given above are accepted. The other strings (9 of them) in this pattern are rejected,
since they dont reached the final state.
11. Consider the NFA M shown below:
q1
0 1
1, 0
q2 q3
0
1, 0
Let the language accepted by M be L. Let L1 be the language accepted by the NFA M1, obtained by changing
the accepting state of M to a non-accepting state and by changing the non accepting state of M to accepting
states. Which of the following statements is true? [GATE-2003]
(a) L1 {0, 1}* L (b) L1 {0, 1}* (c) L1 L (d) L1 L
Ans. (b)
Soln. The given machine M is
www.careerendeavour.com
q 1
0 1
1,0
q2 q0
0
1,0
q1
0 1
1,0
q2 q0
0
1,0
Finite Automata 39
In the case of DFA, L(M) L(M) but in the case of NFA this is not true. In fact L(M) and L(M) have no
connection.
To find L1 L(M) we have to look at M and directly find its languages.
L1 L(M) (0 1) (0 1) * .... (0 1) * .... (0 1) *.
12. Let M (K, , , s, F) be a finite state automaton, where K {A, B}, {a, b}, s A, F {B} ,
(A, a) A, (A, b) B, (B, a) B and (B, b) A and (B, b) A
A grammar to generate the language accepted by M can be specified as G (V, , R, S) , where V K ,
and S A.
Which one of the following set of rules will make L(G) L(M) ?
(a) {A aB, A bA, B bA, B aA, B )
(b) {A aA, A bB, B aB, B bA, B )
(c) {A bB, A aB, B aA, B bA, B )
(d) {A aA, A bA, B aB, B bA, A )
[GATE-2004]
Ans. (b)
Soln. (A, a) A, A aA
(A, b) B, A bB
(B, a) B, B aB
(B, b) A, B bA
B is final state, so B .
13. The following finite state machine accepts all those binary strings in which the number of 1’s and 0’s are
respectively.
1
1 1
0 0 0 0 0 0
www.careerendeavour.com 1 1
(a) divisible by 3 and 2 (b) odd and even (c) even and odd (d) divisible by 2 and 3
[GATE-2004]
Ans. (a)
Soln. The given finite state machine accepts any string w (0, 1) * in which the number of 1’s is multiple of 3 and the
number of 0’s is multiple of 2.
14. Consider the non-deterministic finite automaton (NFA) shown in the figure.
0
0 Y
X 0 0 1
1
0
Z
1
40 Finite Automata
State X is the starting state of the automaton. Let the language accepted by the NFA with Y as the only
accepting state be L1. Similarly, let the language accepted by the NFA with Z as the only accepting state be L2.
Which of the following statements about L1 and L2 is TRUE ?
(a) L1 L2 (b) L1 L2 (c) L2 L1 (d) None of these
[IT-2005]
Ans. (a)
Soln. Writing Y and Z interms of incoming arrows (Arden’s method), we get
Y X0 Y0 Z1
Z X0 Z1 Y0
Clearly, Y = Z.
15. Consider the machine M
b a b
a b b
a a
a, b
The language recognized by M is
(a) {w {a, b}* | every a in w is followed by exactly two b’s}
(b) {w {a, b}* every a in w is followed by at least two b’s}
(c) {w {a, b}* w contains the substring ‘abb’
(d) {w {a, b}* w does not contain ‘aa’ as a substring}
[GATE-2005]
Ans. (b)
Soln. (a) is false, since M is accepting “abbb”.
(b) is true
(c) is false, since “abba” contains “abb” as a substring, but is being rejected by the machine.
(d) is false, since does not contain “aa” as a substring, but is being rejected by M.
16. The following diagram represents a finite state machine which takes as input a binary number from the least
significant bit www.careerendeavour.com
0/0 0/1
1/0
1/1
Q0 Q1
Which one of the following is TRUE ?
(a) It computes 1’s complement of the input number [GATE-2005]
(b) It computes 2’s complement of the input number
(c) It increments the input number
(d) It decrements the input number
Ans. (b)
0/0 0/1
1/0
1/1
Soln.
Q0 Q1
The given machine, executes the algorithm for 2’s complement when input is given from LSB.
Finite Automata 41
17. In the automaton below, s is the start state and t is the only final state.
b
s t
b
a
a a
b
Consider the strings u = abbaba, v = bab and w = aabb. Which of the following statements is true ?
(a) The automaton accepts u and v but not w (b) The automaton accepts each of u, v, and w
(c) The automaton rejects each of u, v, and w (d) The automaton accepts u but rejects v and w
[IT-2006]
Ans. (d)
Soln. u = abbaba: Accepted by automata.
v = bab: Not accepted by automata
w = aabb: Not accepted by automata.
18. A minimum state determinsitic finite automaton accepting the language L {w | w (0, 1)* , number of 0’s and
1’s in w are divisible by 3 and 5, respectively} has [GATE-2007]
(a) 15 states (b) 11 states (c) 10 states (d) 9 states
Ans. (a)
Soln. L {w | s {0, 1}* number if 0’s and 1’s in w are divisible by 3 and 5 respectively}. The minimum state
deterministic finite automaton accepting the language L has 3 × 5 15 states.
1
q1 1 q2 1 q3 1 q4 1 q5
0 0 0 0 0 0 0 0 0 0
1
q6 1 q7 1 q8 1 q9 1 q10
www.careerendeavour.com
0 0 0 0 0
1
X
X 1 X 1 X 1 X 1
q11 q12 q13 q14 q15
b a b
b
a
q0 q1 q2 b
a
a
19. The language accepted by this automaton is given by the regular expression
(a) b*ab *ab *ab * (b) (a b)* (c) b * a (a b) * (d) b*ab*ab *
[GATE-2007]
42 Finite Automata
Ans. (c)
Soln.
q3
b a b
b
a
q0 q1 q2 b
a
a
q3 is unreachable from starting state and hence can be deleted to give the following diagram:
b b
a
q0 q1 q2 b
a
a
q0 is the initial state. From q0 to q1 the regular expression is b*a. After that, every combination of a and b is
accepted by q1 or q2. So q1 and q2 together can be collapsed into a permanent accept state and now the
diagram becomes.
b a,b
q0 q1
a
r b * a (a b)*
20. The minimum state automaton equivalent to the above FSA has the following number of states
(a) 1 (b) 2 (c) 3 (d) 4
[GATE-2007]
Ans. (b)
Soln. The minimum state FSA is given below for the regular expression b*a(a + b)*
So FSA contains minimum two states q0 and q1.
21. Consider the following DFA in which s0 is the state and s1, s3 and the final states.
www.careerendeavour.com
S 1
x y
x y
S0 S2
y x
y x
S3
y y y y
x
q10 q11
x
q01 is final state mean where number of x is even and number of y is odd. q10 is final state mean where number
of x is odd and number of y is even.
22. Consider the following finite automata P and Q over the alphabet {a, b, c}. The start states are indicated by a
double arrow and final states are indicated by a double circle. Let the languages recognized by them be
denoted by L(P) and L(Q) respectively.
P
b
a b b
p0 p1 p2 p3
a b
a
Q
c
b a a
q0 q1 q2 q3
b b
a
The automaton which recognizes the languages L(P) L(Q) is:
b
a b
r0 www.careerendeavour.com
r 1 r r 2 3
(a)
a c
b
b
a b
r0 r1 r2 r3
(b)
a c
b
b
a b b
r0 r1 r2 r3
(c)
a c
b
44 Finite Automata
c
a b b
r0 r1 r2 r3
(d)
a c
b
a, b a, b
S1 S1
a a a a
S0 b a S3 S0 b a S3
(c) (d)
b
S2
www.careerendeavour.com
b b
S
b
2
a, b a, b
[IT-2007]
Ans. (a)
Soln. The language of the given regular expression R is ‘containing the substring aa or bb’. Option (a) is the correct
machine for this language.
24. Which deterministic finite automaton accepts the language represented by the regular expression R?
S1 a S3 a
a
S0 b a b a
(a)
b
S2 b S4 b
Finite Automata 45
S1 a S3 a
a
b
S0 a b
(b)
a
b
S2 b S4 b
S1 S1
a a a b
b a
S0 S3 a, b S0 S3 a, b
(c) b (d) b
a b b a
S2 S2
[IT-2007]
Ans. (a)
Soln. In option (a) S3 and S4 together act as a permanent accept and can therefore be collapsed into a single
permanent accept state as shown below:
S1
a, b a b
S0 b a S3 a, b
b b
S2
This machine clearly accepts all strings containing the substrings ‘aa’ or ‘bb’, which is same as regular expres-
sion R.
25. Which one of the regular expressions given below defines the same language as defined by the regular expres-
sion R ? www.careerendeavour.com
(a) (a(ba) * b(ab)*) (a b) +
(b) (a(ba) * b(ab)*) * (a b) *
(c) (a(ba) *(a bb) b(ab) * (b aa)) (a b) *
(d) (a(ba) *(a bb) b(ab) *(b aa)) (a b)+
[IT-2007]
Ans. (c)
Soln. R = (a + b)*(aa + bb) (a + b)* has following equivalent DFA
q1
a a a,b
q0 b a q3
b b
q2