Unit-1 Notes TOC
Unit-1 Notes TOC
Finite Automata
I Automaton O
N U
{States} T
P
P
U U
T T
Characteristics of an automaton:
Input (I/P): Input is taken in each clock pulse. For each single instance of time t1, t2, t3, …, tn the input
are taken as I1, I2, I3, …, In. As there are n number of input lines, n number of inputs will be taken in each
single time instant. Input for each input line is finite and taken from a set called set of input alphabet Σ.
Output (O/P): Output is generated in each clock pulse. For each single instance of time t1, t2, t3, …,
tm, the outputs are generated as O1,O2,O3,…, Om. Output generated from each output line is finite and
belongs to a set called Output alphabet set.
State: At any discrete instant of time the automaton can be in one of the states q1, q2, q3, …, qn. State
belongs to a set called ‘State’ Q.
State transition: At any instant of time the automaton must be in one of the states that belong to the set
Q. By getting input in a clock pulse the automaton must reside in a state. The state, in which the automaton
will reside by getting that particular input, is determined by state transition. The state transition is a func-
tion of present state and present input, which produces the next state. The function is represented as δ.
Finite Automata 119
Output relation: Like state transition for state there is a relation for output. Output depends either
on present state and present input or present state only depending on type of machine.
Q. Define finite automata. Why it is called finite?
Ans. Finite automata (Singular: automaton) are the machine format of regular expression, which is
the language format of type 3 grammar. A finite automata is defined as M = {Q, Σ, δ, q0, F}.
Where Q: Finite non-empty set of states.
Σ : Finite non-empty set of input symbols.
δ : Transitional function.
q0: Beginning state.
F : Finite non-empty set of final states.
Finite automata are a type of finite state machines. It has finite number of states. Finite automata can be
thought of a finite state machine without output.
Q. Describe the graphical and tabular representation of finite automata.
Ans. Finite automata can be represented in two ways. (a) Graphical and (b) Tabular.
a b a
q0 q1 q2
a b
Here
Q: {q0, q1, q2}
Σ: {a, b}
δ: δ(q0, a) q1
δ(q0, b) q2
δ(q1, a) q0
δ(q1, b) q2
δ(q2,a) q2
δ(q2,b) q1
q0 : {q0}
F : {q2}
Q. Describe the block diagram or mechanical diagram of finite automaton. Describe each of
the components.
Ans.
¢ $ Input Tape
Reading Head
Finite
Control
Input tape: Input tape contains the input symbol. It is divided into several squares, which contain
single character of the input alphabet. Both left and right end of the input tape contain end markers. Be-
tween two end markers the input string is placed. This string is needed to be processed from left to right.
Finite Automata 121
Reading Head: The head scans each square in the input tape and reads the input from the tape. The
head can move from left to right or right to Left. But most of the cases the head moves from left to right.
For two way finite automata and Turing machine the head can move in both directions.
Finite Control: Finite control can be considered as a control unit of a finite automaton. An automa-
ton always resides in a state. The reading head scans the input from the input tape and sends it to finite
control. In this finite control, it is decided that ‘the machine is in this state and it is getting this input, so
it will go to this state’. The state transition relations are written in this finite control.
Input
State
0 1
➞q0 q0 q1
q1 q2 q3
q2 q0 q3
q3 q1 q
122 Automata Theory and Formal Languages
Ans. For the given FA Q = {q0, q1, q2, q3}, Σ = {0, 1}, Beginning State is q0 and final state is q3
The transitional functions are given in the table.
For checking whether a string is accepted by a FA or not we assume that the input string is given
input in the beginning state q0. However, single input is given in each of the clock pulses. Therefore, at
first the left most character is given input to the beginning state. From the transitional function given in
the table the next state is determined. The next character of the input string is treated as input to the state
just achieved. And it will process similarly till the string is finished or such a condition is arrived so that
there is no transitional function mentioned in the table.
If the string is finished and the state achieved is final state then the string will be declared accepted
by the machine. If it does not happen then the string will be declared not accepted.
δ (q0, 011001) δ (q0, 11001)
δ (q1, 1001)
δ (q3, 001)
δ (q1, 01)
δ (q2, 1)
q3
q3 is the final state of the FA. Therefore the two conditions for acceptability of a string by a FA are ful-
filled. Hence the string 011001 is accepted by the given finite automata.
Q. Test whether the strings 010010, 01010 are accepted by the finite automata given below or not.
1 0 1 0
q0 q1 q2
Ans.
δ (q0, 010010) δ (q1, 10010)
δ (q1, 0010)
δ (q2, 010)
δ (q1,10)
δ (q1,0)
q2
q2 is the final state of the FA. Hence the string 010010 is accepted by the FA.
δ (q0, 01010) (q1, 1010)
(q1, 010)
(q2, 10)
(q0, 0)
q1
Finite Automata 123
The q1 is not final state of the FA. The String is finished. But the machine has not come to the final state.
Hence the string is not accepted by the FA.
NS
PS
0 1
➞q0 q0, q1 q2
q1 q2 q1
q2 q1 q2
Here for the state q0 for input 0 it can to q0 or q1. Hence it is an example of NFA.
Q. Test whether the string ‘00101’ is accepted by the following finite automata or not.
0 0 1 0 1
q0 q1 q2
0
1
124 Automata Theory and Formal Languages
Ans. In the previous given FA, we are seeing that from q0 for input 0 it can go to q0 and q1. That is
for q0 for input 0 there are two paths. Let draw a transaction diagram to clarify:
q0 1 q2 0 q1 1 q1
0
q0
0 0
1 0 1
q1 q1 q2 q2
q0
0
q1
0 1 0
q2 q2 q1 1 q1
In the transaction diagram from q0 for input string 00101 we are getting three paths. For the string
00101 the last state we are getting as q1, q2, q1. Among them q2 is the final state. That is for the string
00101 from q0 we can reach to final state. Hence the string 00101 is accepted by the FA.
However, if someone follow path 1 and path 3, it will not be possible to reach to the final state. Then
it can be declared that the string not accepted by the FA. That means it depends on the path which is
being followed by the FA.
A String w є Σ* is accepted by a NFA if δ(q0, w) contains some final state.
Therefore, the string 00101 is accepted by the FA.
Q. Why do we need to convert a NFA to a DFA?
Ans. For a DFA, δ is a transitional function mapping Q X Σ Q, where |Q| = 1.
For a NFA δ is a transitional function mapping Q X Σ 2Q, 2Q is the power set of Q.
For a NFA for a single input given to a single state the machine can go to more than one state. Hence
for a NFA it will be hard to decide for a string to be accepted by the NFA or not.
If a NFA can be converted to a DFA then this type of problem will not arise.
Implies that we have to convert Q X Σ 2Q to Q⬘ X Σ Q⬘, where Q is the finite set of states for a
NFA and Q⬘ is the set of states for the converted DFA.
Q. What is the process of converting a NFA to a DFA?
Ans.
(i) Start from the beginning state of the NFA. Consider the state within [ ].
(ii) Place the next states for the beginning state for the given inputs. Put them also in [ ].
(iii) If any new combination of state appears, which is not yet taken in present state column; take that
combination of state in the present state column.
(iv) If in the present state column more than one state appears, the next state for that combination will
be the combination of the next states for each of the states.
(v) If no new combination of state appears, which is not yet taken in the present state column, stop the
process.
(vi) Beginning state for the constructed DFA will be the beginning state of the NFA.
(vii) Final state or final states for the constructing DFA will be the combination of states containing at
least one final state.
Finite Automata 125
NS
PS
0 1
➞q0 q0, q1 q2
q1 q2 q1
q2 q1 q2
Solve:
NS
PS
0 1
[q0] [q0, q1] [q2]
[q0, q1] [q0, q1, q2] [q1, q2]
[q1, q2] [q1, q2] [q1, q2]
[q0, q1, q2] [q0, q1, q2] [q1, q2]
[q2] [q1] [q2]
[q1] [q2] [q1]
Lets replace [q0] as A, [q0, q1] as B, [q1, q2] as C, [q0, q1, q2] as D, [q2] as E and, [q1] as F
Then the constructed finite automata will be
NS
PS
0 1
A B E
B D C
C C C
D D C
E F E
F E F
In the finite automata, we see that in a single state, for a single input, the machine can go to only one
state. Therefore, it is a DFA.
The beginning state is [q0] i.e. A. The final states are [q1, q2] i.e. C, [q0, q1, q2] i.e. D, and [q2] i.e. E.
126 Automata Theory and Formal Languages
0,1
0 1
A B C
1 0
1
1
D E
0
0
0 F
1
Next Stage
Present Stage
0 1
➞q0 q0, q1 q0
q1 q2 q1
q2 q3 q3
q3 – q2
Solve:
NS
PS
0 1
[q0] [q0, q1] [q0]
[q0, q1] [q0, q1, q2] [q0, q1]
[q0, q1, q2] [q0, q1, q2, q3] [q0, q1, q3]
[q0, q1, q3] [q0, q1, q2] [q0, q1, q2]
[q0, q1, q2, q3] [q0, q1, q2, q3] [q0, q1, q2, q3]
Let replace [q0] as A, [q0, q1] as B, [q0, q1, q2] as C, [q0, q1, q3] as D, [q0, q1, q2, q3] as E.
Finite Automata 127
NS
PS
0 1
➞A B A
B C B
C E D
D C C
E E E
In the finite automata, we see that in a single state, for a single input, the machine can go to only one
state. Hence it is a DFA.
Beginning state is A. Final state is D and E.
The transaction diagram for the DFA will be as follows.
1 1
0 0
A B C
0
1 0, 1
E D
Next Stage
Present Stage
a b
➞q0 q0, q1 q2
q1 q0 q1
q2 – q0, q1
Ans.
NS
PS
a b
[q0] [q0, q1] [q2]
[q0, q1] [q0, q1] [q1, q2]
[q1, q2] [q0] [q0, q1]
[q2] [–] [q0, q1]
[–] [–] [–]
128 Automata Theory and Formal Languages
Here for the state q2 for input ‘a’ in the given NFA no state was mentioned. Therefore, we have taken it a
new state [–], when converting from NFA to DFA. For the new state [–] as no next state was mentioned
we have taken the same state [–] for both the inputs a and b.
(Soon we shall learn that these types of states are called dead state)
Let replace [q0] by A, [q0, q1] by B, [q1, q2] by C, [q2] by D, and [–] by E. The tabular representation will
become:
NS
PS
a B
A B D
B B C
C A B
D E B
E E E
In the finite automata, we see that in a single state, for a single input, the machine can go to only one
state. Therefore, it is a DFA. Beginning state is A; Final states are C and D.
The transaction diagram for the DFA is as follows:
a
a
A
B
b b b
b a
E D C
a
a, b
1 1 0. 1
ε
q0 q1 ε q2
0
Finite Automata 129
The previous finite automata contain two null moves. Hence the previous FA is NFA with null move.
From the definition of NFA we know for a NFA from a single state, for a single input the machine can
go to more than one state, i.e. Q X Σ 2Q, where 2Q is the power set of Q.
From a state by getting e input the machine is confined into that state. A finite automata with null
move must contain at least one e move. For this type of finite automata for input e the machine can go
to more than one states. (One is that same state and another state is the e-transaction next state). Hence
a finite automata with e move can be called as a NFA.
For the previous finite automata
δ(q0, e) q0 and δ(q0, e) q1
δ(q1, e) q1 and δ(q1, e) q2
A NFA with e move can be defined as
MNFA null = {Q, Σ, δ, q0, F }.
Where Σ : Set of input alphabets including e and
δ is a transitional function mapping Q X Σ 2Q 2Q is the power set of Q.
q1
However, it is not clearly understandable how any combination of a, b, c can appear. However, if we
represent a transitional diagram as follow:
a b c
ε ε
q0 q1 q2
ε ε
ε `
Then it is clearly understandable that the string can start with a or b or c, and for the null transitions
from any state we can move to any other state with no input. Therefore, if c comes after ‘a’, we can go
from q0 to q2 easily with no input. Same thing can occur for all the other states.]
130 Automata Theory and Formal Languages
0 1 2
q0 ε q1 ε q2
Ans. There are three null moves existing in the previous transitional diagram. The transitions are (i)
From q0 to q1 (ii) From q1 to q2 (iii) From q0 to q2. We have to remove these null transitions step by step.
Step I: (a) Between state q0 and q1, there is a null move. If we want to remove that null transition,
we have to find all the edges starting from q1.The edges are q1 to q1 for input 1, and q1 to q2 for input є.
(b) Duplicate all these transitions starting from the state q0, keeping the edge label same. The q0 is
initial state, hence make q1 also an initial state. The modified transitional diagram will be
0 1 2
q0 1 q1 ε q2
Step II: (a) Between q1 and q2 there is a null transaction. If we want to remove that null transition,
we have to find all the edges starting from q2.The edge is q2 to q2 for input 2.
(b) Duplicate the transition starting from the state q1, keeping the edge label same. The q1 is initial
state, hence make q2 also an initial state. The q2 is the final state, hence make q1 also final state. The
modified transitional diagram will be
0 1 2
q0 1 q1 2 q2
ε
Finite Automata 131
Step III: (a) Between q0 and q2 there is a null transaction. If we want to remove that null transition,
we have to find all the edges starting from q2. The edge is q2 to q2 for input 2.
(b) Duplicate the transition starting from the state q0, keeping the edge label same. The q0 is initial
state, hence make q2 also an initial state. The q2 is the final state, hence make q0 also final state. The
modified transitional diagram:
0 1 2
q0 1 q1 2 q2
This the equivalent DFA obtained from the NFA with null transaction.
Q. Convert the following NFA with null move to an equivalent DFA.
B ε
ε a
D
A ε c
b b
C
Ans. In the given NFA with є move, there are three є transitions: from A to B, from B to D, and from
B to C. We will remove the three є transitions step by step.
Step I: There is a є transition from A to B. If we want to remove that є transition, we have to find all
the edges starting from B. The edges are B to C for input c and B to D for input є.
Duplicate the transition starting from the state A, keeping the edge label same. A is initial state, so
make B also an initial state. The modified transaction diagram:
B ε
a
ε
ε D
A c
b,c b
C
Step II: Again there are three є transactions in the NFA. These are from A to D, from B to D and
from C to B. Lets remove the є transaction from B to D. The edge starting from D is D to D for input a.
Duplicate the transition starting from the state B, keeping the edge label same. As B is the initial state
132 Automata Theory and Formal Languages
D will be also initial state. As D is the final state so B will be also final state. The modified transaction
diagram will be
B a
a
ε
ε D
A c
b,c b
C
Step III: Now we are going to remove the є transaction from A to D. The edge starting from D is D
to D for input a. Duplicate the transition starting from the state A, keeping the edge label same. As A is
the initial state D will be also initial state. As D is the final state so A will be also final state. The modi-
fied transaction diagram will be
B a
a
ε
a D
A c
b,c b
C
Step IV: There is only one є transaction from C to B. To remove this, find the edges starting from B.
There are two, From B to D for input a and from B to C for input c. Start these edges from C. B is final
state so make C as final state. The modified transitional diagram will be.
B a
a
a D
A c
b,c a,b
C
This the equivalent DFA obtained from the NFA with null transaction.
Finite Automata 133
q0 0 q1 1 q2
For example, for the previous finite automata from q0 for input 0 there is a path to go to q1. But there
is no path mentioned from q0 for input 1. Same thing happens for q2 also for input 0. Now let a string
101 is given to test the acceptability of the string by the finite automata.
According to the condition of the acceptability, the first condition i.e. the string will be totally tra-
versed is not fulfilled. Obviously the second condition is not fulfilled.
We have to decide that the string is not accepted by the finite automata without traversing the string totally!
For making the string totally traversed we have to include an extra state, let qf , where the control will
go from the states for which there is only one path for one input. In the state qf for the inputs there will
be self loop. Here qf is the dead state.
By including dead state the finite automata will become
1
q0 0 q1 1 q2
1 0
qf
0, 1
Now if we test for the acceptability of 101, the transitions are as follows
δ(q0, 101) δ(δ(q0 , 1), 01) δ(δ(qf , 0), 1) δ(qf , 1) qf .
String is totally traversed and reached to qf . qf is not the final state, so the string is not accepted by the FA.
In the case we have seen that the string is finished [dead] by confined into qf. For this reason qf is
called dead state.
134 Automata Theory and Formal Languages
I/P=0 I/P=1
PS
NS O/P NS O/P
A D 0 B 0
B A 1 D 0
C B 1 A 1
D D 1 C 0
For Moore machine the output depends on present state only. As in a machine for present state there is
only one Present state column, so there will be only one output column.
Finite Automata 135
NS
PS O/P
I/P=0 I/P=1
A A B 0
B A C 0
C A C 1
Q. Describe the transitional diagram representation of Mealy machine and Moore Machine.
Ans. Mealy machine is one type of finite automata with output. Hence the transitional diagram will
be like finite automata but output will be mentioned. For a Mealy Machine the output depends on pres-
ent state and present input. Hence, for a Mealy machine the transitional arc will be labeled with both
input and output.
Example:
1/0 1/0
0/1 0/1
0/1
0/0 D
A
1/0
1/1
C
Output of Moore machine depends only on the present state. For Moore machine the states will be la-
beled with state name and output.
Example:
0
1
A/0 B/0
0
0 1
C/1
1
136 Automata Theory and Formal Languages
0/1
1/0
Q. Design a Moore Machine which will determine the residue mod-3 for each binary string
treated as binary integer.
Ans. Binary string consists of two types of alphabet 0 and 1. Binary integer means the decimal
equivalent of a binary string as integer numbers are taken as decimal. Residue mod-3 means the re-
minder that we get when the decimal equivalent of the binary number is divided by 3.
If a decimal number is divided by 3 we can get only 3 types of reminders, these are 0 or 1 or 2. We
are constructing a Moore Machine, where output depends only on the present state. So, for three types
of reminders (output) three states are needed.
Lets consider state q0 is producing output 0, state q1 is producing output 1 and state q2 is producing
output 2. Now we need to construct the transitional arcs. Before construction take a table containing
binary equivalent of decimal numbers from 0 to 9 and the reminders for each of them, when divided
by 3.
Input 0, output is 0. Therefore, transitional function will be δ(q0, 0) q0, because q0 state produce output
0. Input 1, output 1, Hence, transitional function will be δ(q0, 1) q1, because q1 state produce output 1.
Input 10, output is 2. Hence, transitional function will be δ(q1,0) q2, because q2 state produce output 2.
Input 11, output is 0. So, transitional function will be δ(q1, 1) q0. By this process all the transitional
functions can be produced.
Finite Automata 137
0 1
1 0
q0/0 q1/1 q2/2
1 0
Q. Design a Mealy Machine which will determine the residue mod-3 for each binary string
treated as binary integer.
Ans. The machine is a Mealy machine, so outputs depend on present state and present input.
For input 0, output is 0. Transitional function will be δ(q0, 0) q0 and output function λ is q0 X 0 0.
For input 1, output 1. Transitional function will be δ(q0, 1) q1 and output function λ is q0 X 1 1.
For input 10, output is 2. So, transitional function will be δ(q1,0) q2, and output function λ is q1 X 0
2. For input 11, output is 0. Hence, transitional function will be δ(q1, 1) q0, and output function λ
will be q1 X 0 0. By this process all the transitional functions will be constructed. The Mealy machine
for this is
0/0
1/2
1/1 0/2
q0 q1 q2
1/0 0/1
Q. Design a Moore machine which counts the occurrence of substring aba in a given input
string.
Ans. It is one type of sequence detector. When the string aba will occur as a substring then
output 1 will produced. For all the other cases output 0 will be produced (Overlapping sequences are
also accepted).
We have to design a Moore machine, i.e. output depends only on the present state. For a string
length of 3 we need four states if from a state with single input the machine goes to another new state.
Let name the states as q0, q1, q2, q3. Except q3 all the states produce output 0. In state q0, we can get
two types of input a or b. If we get ‘a’ then there is a chance to get ‘aba’. So it will move forward to
q1. If we get ‘b’ then there is no chance to get ‘aba’ so it will confine to the same state. In q1, again
two types of input can occur, ‘a’ and ‘b’. If we get ‘a’, then by considering this ‘a’ there is a chance
to get ‘aba’. So it will confine to the same state. If we get b then we are two step forward to get ‘aba’.
Hence the machine will move forward to state q2. In q2 if we get ‘b’ then there is no chance to get
‘aba’ except starting from the beginning. Hence it will go to q0. If we get ‘a’, we have got the string
aba. Machine will go to state q3. In q3 if we get ‘a’, then again there is a chance to get ‘aba’. From
q0, by getting ‘a’ the machine has moved forward to q1. So from q2 by getting ‘a’ the machine will
go to q1. If we get ‘b’ then by considering the previous ‘a’ again there is a chance to get ‘aba’, so the
machine will move to state ‘q2’.
From the above discussions the transitional functions can easily be derived. As it is Moore
machine the outputs are included with the state (Output depends only on the present state not on the
present input) so there is no need to derive the output functions. The Moore machine for the above
problem:
138 Automata Theory and Formal Languages
a
b a
a b a
q0/0 q1/0 q2/0 q3/1
b
b
Q. Design a Mealy machine which counts the occurrence of substring aab in a given input
string.
The machine will be Mealy machine, i.e. output depends on the present state and present input.
(Discussions will be like previous)
The machine:
a/0
b/0
a/ 0
q0 a/0 b/1
q1/0 q2/0 q3/1
b/0
a/0
b/0
NS
PS O/P
I/P=0 I/P=1
➞q0 q3 q1 0
q1 q1 q2 1
q2 q2 q3 0
q3 q3 q3 0
Solve:
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q3 0 q1 1
q1 q1 1 q2 0
q2 q2 0 q3 0
q3 q3 0 q3 0
In the Moore Machine, for q1 as a present state the output is 1. So in the constructing Mealy Machine
for q1 as a next state the output will be 1.
In the Moore Machine, for q2 as a present state the output is 0. Hence in the constructing Mealy Ma-
chine for q2 as a next state the output will be 0.
Q. Construct Mealy Machine equivalent to the given Moore Machine.
NS
PS O/P
I/P=0 I/P=1
➞q0 q1 q2 1
q1 q3 q2 0
q2 q2 q1 1
q3 q0 q3 1
Solve:
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q1 0 q2 1
q1 q3 1 q2 1
q2 q2 1 q1 0
q3 q0 1 q3 1
140 Automata Theory and Formal Languages
NS
PS O/P
I/P=0 I/P=1
➞q0 q1 q0 0
q1 q1 q2 0
q2 q3 q0 0
q3 q1 q2 1
Solve:
I/P=0 I/P=1
PS
NS O/P NS O/P
q0 q1 0 q0 0
q1 q1 0 q2 0
q2 q3 1 q0 0
q3 q1 0 q2 0
(For a Mealy machine with m number of states and n number of output, the Moore machine will be of n
number of outputs but not more than mn + 1 number of states.)
Q. Convert the given Mealy Machine to an equivalent Moore Machine.
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q0 1 q1 0
q1 q3 1 q3 1
q2 q1 1 q2 1
q3 q2 0 q0 1
Solve:
Look into the next state and output columns of the given Mealy Machine. For I/P 0 for q1 as a next state
output is 1. For I/P 1 for q1 as a next state output is 0. Same thing happens for q2 as a next state for input
0 and input 1. So the state q1 will be broken as q10 and q11 and the state q2 will be broken as q20 and q21.
After breaking the modified Mealy Machine will be
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q0 1 q10 0
q10 q3 1 q3 1
q11 q3 1 q3 1
q20 q11 1 q21 1
q21 q11 1 q21 1
q3 q20 0 q0 1
For present state q0 for input 1 the next state will be q10, because there is no q1 in the modified Mealy
Machine. It has been broken into q10 and q11 depending on the output 0 and 1, respectively. For present
state q0 for input 1 the output is 0. Hence the next state will be q10. Same cases occur for the others also.
For the broken states the next states and outputs will be same as the original, from where the broken
states have come.
From this the Moore Machine will be
NS
PS O/P
IP=0 IP=1
➞q0 q0 q10 1
q10 q3 q3 0
q11 q3 q3 1
q20 q11 q21 0
q21 q11 q21 1
q3 q20 q0 1
142 Automata Theory and Formal Languages
For Moore machine beginning state q0 and the output is 1. That means with null length input (no input)
we are getting an output 1. Therefore, the Moore machine accepts 0 length sequence (Because here
output depends only on the present state] which is not acceptable for mealy machine. To overcome this
situation we must add a new beginning state qb with same transactions as q0 but output 0. By including
the new state the Moore Machine will be.
NS
PS O/P
IP=0 IP=1
➞qb q0 q10 0
q0 q0 q10 1
q10 q3 q3 0
q11 q3 q3 1
q20 q11 q21 0
q21 q11 q21 1
q3 q20 q0 1
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q2 z0 q1 z1
q1 q0 z0 q2 z0
q2 q0 z1 q2 z1
Solve:
For q0 for input 0 the outputs differs. For q2 for input 0 and 1 the output differs. Therefore the states will
be broken as q00, q01, and q20, q21. According to the new states the modified mealy machine:
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q00 q20 z0 q1 z1
q01 q20 z0 q1 z1
q1 q00 z0 q20 z0
q20 q01 z1 q21 z1
q21 q01 z1 q21 z1
Finite Automata 143
I/P=0
PS O/P
I/P=0 I/P=1
➞q00 q20 q1 z0
q01 q20 q1 z1
q1 q00 q20 z1
q20 q01 q21 z0
q21 q01 q21 z1
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q2 0 q1 0
q1 q0 1 q3 0
q2 q1 1 q0 1
q3 q3 1 q2 0
Ans. In the next state column of the given Mealy machine the output differs for q1 and q3 as next
state. Hence the states will be divided as q10, q11, and q30, q31, respectively. After dividing the states the
modified Mealy machine will be
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q2 0 q10 0
q10 q0 1 q30 0
q11 q0 1 q30 0
q2 q11 1 q0 1
q30 q31 1 q2 0
q31 q31 1 q2 0
In the next state column of the modified mealy machine q0 as a next state output was 0. So for the
constructing Moore Machine for present state q0 output will be 0. Same for present state q2 the output
will be 0. For the divided states like q10, q11 there is no need to mention the output as they were divided
according to the distinguished output. So the constructing Moore machine will be
144 Automata Theory and Formal Languages
NS
PS O/P
I/P=0 I/P=1
➞q0 q2 q10 1
q10 q0 q30 0
q11 q0 q30 1
q2 q11 q0 0
q30 q31 q2 0
q31 q31 q2 1
To get rid of the problem of occurrence of null string, we need to include another state let qa with same
transactions as of q0 but with output 0.
The modified final Moore machine equivalent to the given Mealy machine will be
NS
PS O/P
I/P=0 I/P=1
➞qa q2 q10 0
q0 q2 q10 1
q10 q0 q30 0
q11 q0 q30 1
q2 q11 q0 0
q30 q31 q2 0
q31 q31 q2 1
Q. Describe the process of conversion of Mealy machine from a given Moore machine.
Ans. Let a Moore machine Mo is to be converted to an equivalent Mealy machine MC. There are
certain steps for this conversion.
Step I: For a Moore machine each state is labeled with output, as for Moore machine output depends
only on the present state. For the conversion, let take a state S; which is labeled with output O. Look
into the incoming edges to the state S. These incoming edges are labeled by the input alphabets of the
Moore machine. These incoming edges will be relabeled by the input alphabet as well as the output of
the state S. The output for the state will be removed.
Finite Automata 145
i1 i1/O
i2 S/ O O1 i2/O S O1
i3 i3/O
Step II : Keep the outgoing edges from the state S as it was. (The outgoing edge of a state must be
incoming edge of some other state.)
Step III: Repeat these steps for each of the states. By this we will get the Mealy machine equivalent
Moore machine.
Q. Convert the following Moore machine into equivalent Mealy Machine.
a,b
B/1
a a
b
A/0
C/0
Ans.
(a) In this machine A is the beginning state. Hence start from A. For A there are two incoming arc, from
C to A with input b and one in the form of start state indication with no input. State A is labeled with
output 0. As the start state indication contains no input, it is useless, keep it as it is.
Modify the label of the incoming edge from C to B including the output of state A. Hence the label of
the incoming state will be C to A with label b/0.
(b) State B is labeled with output 1. The incoming edges to the state B are from A to B with input a, B
to B with input a and b, and C to B with input a.
Modify the labels of the incoming edges including the output of state B. Hence the labels of the incom-
ing states will be A to B with label a/1, B to B with label a/1 and b/1, and C to B with label a/1.
(c) State C is labeled with output 0. There is only one incoming edge to this state, from A to C with
input b.
The modified label will be b/0.
146 Automata Theory and Formal Languages
a/1, b/1
a/1 a/1
b/0
A
C
b/0
a
b a
b
b
Ans. State A is labeled with output 0. The incoming edged to this state are C to A for input b, A to
A for input b, and one as start state indication with no input. Ignore the edge with start state indication.
Modify the labels of the incoming edges by including the output of state A. So the modified labels
will be, from A to A with label b/0, and from C to A with label b/0.
State B is labeled with output 0. The incoming edges to this state are, A to B for input a, B to B for
input a, D to B for input a. The modified labels will be, A to B with label a/0, B to B with label a/0, D
to B with label a/0.
State C is labeled with output 0. The incoming edges to this state are B to C for input b, and D to C
for input b. The modified labels will be B to C with label b/0, D to C with label b/0.
State D is labeled with output 1. The incoming edge to this state is C to D for input a. The modified
labels will be from C to D with label a/1.
The Mealy machine equivalent to the given Moore machine:
a/0
b/0 a/0
b/0
b/0
Finite Automata 147
I1/ O1 I1/ O2
S
I2/ O2
I2/ O2
I2/ O1
In the transitional diagram for state S, incoming edges are labeled as I1/O1, I2/O2, and I2/O1 and the
outgoing edges are labeled as I1/O2 and I2/O2. For state S for incoming edges we are getting two types
of output O1 and O2. These types of cases the state S will be divided into n number of parts, where n =
number of different outputs for the incoming edges to the state. The output edges will be repeated for all
the divided states. The transitional diagrams for the above case will be
I1/ O2 I1/ O2
I1
SO1/O1 I2 SO2/O2
I2 I2/ O2 I2/ O2
Step II: If a state has a loop and that state also need to be divided like follows:
I1/ O1
I1/ O2
S S1
I1/ O2
I2/ O1
(Here for input I1, output is O1 as well as O2. Hence the state S needs to be divided. The S has a loop with
input I2 and output O1.) The state S will be divided into two states SO1 and SO2. As the loop for input I2
is labeled with output O1, Hence there will be a loop on state SO1. However, this loop is not possible on
SO2, because it produces output O2. Hence, there will be a transition from SO2 to SO1 with input label I2.
148 Automata Theory and Formal Languages
I2
SO1/ O2 I2 SO2/ O2
I1
I1/ O2 I1/ O2
S1
Step III: Repeat the steps I and II. By this we will get the Moore machine equivalent Mealy machine.
Q. Convert the following Mealy machine to an equivalent Moore machine.
q0 b/1 q1
a/0 a/1
b/1 b/0
q2
a/0
Ans. For state q0, there are two incoming states, q0 to q0 with label a/0 and q2 to q0 with label b/1.
Two incoming edges are labeled with two different outputs 0 and 1. Hence the state q0 need to be divided
into two states let q00 and q01. There will be a loop for input ‘a’ on q00. There will a transition from q01
to q00 with input label ‘a’. From both the states there will be transitions to state q1 with label b/1. The
modified machine will be
q00/0 b/1
q1
a/1
a
b/0
b/1
a
a/0
q01/1 q2
b
For all the other states q1 and q2 the outputs for all the incoming edges are 1 and 0, respectively. Hence
there is no need to divide the states, the final Moore machine:
Finite Automata 149
q00/0 b
q1/1
a
a
b
b
a
a
q01/1 q2/0
b
1/0
q1 q2
0/1
q3 q4
1/0
Ans. The machine contains four states. Lets start from the state q1. The incoming edges to this state
are from q2 to q1 with label 0/1 and from q3 to q1 with label 1/1. There is no difference of the outputs of
the incoming edges to this state therefore in the constructing Moore machine the output for this state
will be 1. The modified machine:
1/0
q1 q2
0 0
0/0 1 1/0
0/1
0/1
q3 q4
1/0
Consider the state q2. This state contains two incoming edges, from q1 to q2, with label 1/0 and q3 to q2,
with label 0/1. There are two different outputs we are getting for two incoming edges (q1 to q2 output 0,
q3 to q2 output 1). Therefore the state q2 will be divided into two, let name them q20 and q21. The outgoing
edges are duplicated for both the states generated from q2.
150 Automata Theory and Formal Languages
1 q20
0
q1
0 0 1/0
0
q21
1 1
0/0 0
1/0
q3 q4
1/0
0/1
Consider state q3. The incoming edges to this state are, from q1 to q3 with label 0/0 and from q4 to q3
with label 1/0. There is no difference of the outputs of the incoming edges to this state, therefore in the
constructing Moore machine the output for this state will be 0. The modified machine:
1 q20
0
q1
0 0 1/0
0
q21
1 1
0 0
1/0
q3
q4
0 1
0/1
Consider the state q4. This state contains three incoming edges, from q20 to q4, with label 1/0, from q21
to q4, with label 1/0 and q4 to q4 with label 0/1. There are two different outputs we are getting for two
incoming edges (q20 to q4 output 0, q21 to q4 output 0, q4 to q4 output 1). Hence the state q4 will be divided
into two, let name them q40 and q41.
The modified Moore machine:
1 q20
0
q1
0 0 1
0
q21
1 1
0 0
1
q3 q40
0 1 0
1
q41
1
0
Finite Automata 151
Q. Define dead state, inaccessible state, equivalent state, distinguishable state and k-equiva-
lence in case of finite automata.
Ans. Dead State: A state qi is called dead state if qi is not a final state and for all the inputs to
this state the transitions confined to that state. In mathematical notation, we can denote qi ∉ F and
δ(qi, Σ) qi.
Inaccessible state: The states which can never be reached from the initial state are called in acces-
sible state.
1 0
q1 1 q2 0 q3 0,1 qa
0,1 1
0
qd
Equivalent State: Two states qi and qj of a finite automata M are called equivalent if δ(qi, x) and
δ(qj, x) both produces final states or both of them produces non-final states for all x є Σ*. It is denoted
by qi ≡ qj.
Distinguishable State: Two states qi and qj of a finite automata M are called distinguishable if for a
minimum length string x, for δ(qi, x) and δ(qj, x) one produces final state and another produces non-final
state or vice versa for all x є Σ*.
K-equivalent: Two states qi and qj of a finite automata M are called k-equivalent (k ⱖ 0) if δ(qi, x)
and δ(qj, x) both produces final states or both of them produces non-final states for all x є Σ* of length
k or less.
152 Automata Theory and Formal Languages
Q. Construct a minimum state automaton from the transitional table given below.
NS
PS
I/P=0 I/P=1
➞q0 q1 q2
q1 q2 q3
q2 q2 q4
q3 q3 q3
q4 q4 q4
q5 q5 q4
Solve:
In the finite automata, the states are {q0, q1, q2, q3, q4, q5, }. Name this set as S0
S0: {q0, q1, q2, q3, q4, q5 }. All of the states are 0 equivalent.
In the finite automata, there are two types of states final state and non-final states. Hence divide the set
of states into two parts Q1 and Q2.
Q1 = {q0, q1, q2}, Q2 = {q3, q4, q5},
S1: {{q0, q1, q2}, {q3, q4, q5 }}.
States belong to same subset are 1-equivalent because they are in the same set for string length 1. States
belong to different subsets are 1-distinguishable.
For input 0 and 1, q0 is going to q1 and q2, respectively. Both of the states belong to same subset. For
q1 and q2 for input 0 and 1 the next states are q2, q3, and q2, q4, respectively. For both of the states for input
0 the next state belong to one subset and for input 1 the next state belong to another subset. Therefore,
q0 can be distinguished from q1 and q2.
The next states for input 0 and 1 for states q3, q4, q5 belong to same subset. Hence they cannot be
divided.
S2: {{q0},{q1, q2 }, {q3, q4, q5 }},
q0 is the single state in the subset. Hence it cannot be divided.
For states q1, q2 for input 0 and 1 for both of the cases one state belong to one subset and another state
belong to another subset. Hence they cannot be divided.
The next states for input 0 and 1 for states q3, q4, and q5 belong to same subset. Hence they cannot be
divided.
Therefore in the next step
S3: {{q0}, {q1, q2 }, {q3, q4, q5 }}
S2 and S3 equivalent.
As step (n-1) and step n are same so we will stop here.
In the minimized automata number of states are 3.
Finite Automata 153
NS
PS
I/P=0 I/P=1
{q0} {q1} {q2}
{q1, q2} {q2} {q3, q4}
{q3, q4, q5} {q3, q4, q5} {q3, q4, q4}
However, {q1}, {q2}, {q3, q4} do not exist under the column of state. They are not states of the mini-
mized finite automata, but they are subset of the states. In the next state columns by replacing the subsets
by proper state the modified table will be.
NS
PS
I/P=0 I/P=1
{q0} {q1, q2} {q1, q2}
{q1, q2} {q1, q2} {q3, q4, q5}
{q3, q4, q5} {q3, q4, q5} {q3, q4, q5}
As q0 is the beginning state of the original finite automata {q0} will be the beginning state of minimized
finite automata. As q3, q4, and q5 are the final states of the original finite automata so the set of the states
containing any of the states as element will be final state. Here all the states are contained in a single
set {q3, q4, q5 }, hence it is the final state. By replacing {q0} as A, {q1, q2} as B and {q3, q4, q5 } as C, the
modified minimized finite automata will be.
Next State
PS
I/P=0 I/P=1
➞A B B
B B C
C C C
0
0,1
0,1 1
A B C
154 Automata Theory and Formal Languages
Q. Construct a minimum state automaton from the transitional table given below.
NS
PS
I/P=0 I/P=1
A F B
B C G
C C A
D G C
E F H
F G C
G E G
H C G
Ans. In the finite automata the states are {A,B,C,D,E,F,G,H }. Name this set as S0
S0: {A,B,C,D,E,F,G,H }. All of the states are 0 equivalent.
In the finite automata there are two types of states final state and non-final states. Hence divide the set
of states into two parts Q1 and Q2.
Q1 = {C}, Q2 = {A,B,D,E,F,G,H},
S1: {{C} {A,B,D,E,F,G, H}}.
States belong to same subset are 1-equivalent because they are in the same set for string length 1. States
belong to different subsets are 1- distinguishable.
The C is single state, hence it cannot be divided. Among the states {A,B,D,E,F,G,H} for {B,D,F,H}
for input either 0 or 1, the next state belong to {C} which is different subset (From B with input 0 goes
to C, from D with input 1 goes to C, from F with input 1 goes to C, H with input 0 goes to C).
For the other states {A,E,G} for input either 0 or 1 the next state belongs to Q2.
So Q2 can be divided into two parts {A,E,G} and {B,D,F,H}. Let name them Q3 and Q4.
The divided sets will be
S2: {{C}, {A,E,G}, {B,D,F,H}}.
Consider the subset of states {A,E,G}. A and E with input 0 and 1 both go to F,B and F,H, respectively,
i.e. to the subset {B,D,F,H}. The G with input 0 and 1 go to E,G, i.e. the same subset. Hence {A,E,G}
will be divided into two subsets {A,E} and {G}.
The subset {B,D,F,H} can be divided depending on the input and next state combination. B and H
produce next state C and G for input 0 and 1, respectively.
The D and F produce next state G and C for input 0 and 1, respectively. Hence the set {B,D,F,G} will
be divided into two subsets {B,H} and {D,F}.
The divided sets will be
S3: {{C}, {A,E}, {G}, {B,H}, {D,F}}.
Finite Automata 155
The subsets cannot be divided further. Hence these are the states of minimized DFA. Lets rename the
subsets as q0, q1, q2, q3 and q4. Initial state was A, hence here initial state is {A,E}, i.e. q1. Final state was
C, hence here final state is {C}, i.e. q0. The tabular representation of minimized DFA is
NS
PS
I/P=0 I/P=1
q0 q0 q1
➞q1 q4 q3
q2 q1 q2
q3 q0 q2
q4 q2 q0
(a) Mark X at p, q in lower triangular part such that p is final state and Q is non-final state.
(b) Make distinguished pair combination of the non-final states. If there are n number of non-final
states there will be nC2 number of distinguished pairs.
Take a pair (p, q) and find (r, s), such that r = δ(p, a) and s = δ(q, a). If in the place of (r, s) there is X or
x, in the place of (p, q) there will be x.
(c) If (r,s) is neither X nor x, then (p,q) will be 0.
(d) Repeat b and c for final states also.
Step III: The combination of states where there is 0, they will be the states of the minimized ma-
chine.
Q. Minimize the following DFA using Myhill Nerode theorem.
NS
PS
I/P=a I/P=b
➞A B E
B C D
C H I
D I H
E F G
F H I
G H I
H H H
I I I
A — — — — — — — — —
B — — — — — — — —
C — — — — — — —
D — — — — — —
E — — — — —
F — — — —
G — — —
H — —
I —
A B C D E F G H I
Finite Automata 157
Step II: (a) The following combinations are the combination of beginning and final state.
(A,C), (A,D), (A,F), (A,G), (B,C), (B,D), (B,F), (B,G), (E,C), (E,D), (E,F), (E,G), (H,C), (H,D),
(H,F), (H,G), (I,C), (I,D), (I,F), (I,G).
Put X in these combinations of states.
The modified matrix:
A — — — — — — — — —
B — — — — — — — —
C X X — — — — — — —
D X X — — — — — —
E X X — — — — —
F X X X — — — —
G X X X — — —
H X X X X — —
I X X X X —
A B C D E F G H I
(b) The pair combination of non-final states are (A,B), (A,E), (A,H), (A,I), (B,E), (B,H), (B,I), (E,H),
(E,I), (H,I).
r = δ(A,a) B s = δ(B,a) C, in the place of (B,C) there is X. Hence in the place of
(A, B) there will be x.
Same like (r,s) = δ((A, E), (a) (B, F) (there is X). In the place of (A,E) there will be x.
(r,s) = δ((A,H), (a) (B,H) (neither X nor x). In the place of (A,H) there will be 0.
(r,s) = δ((A,I), (a) (B,I) (neither X nor x). In the place of (A,I) there will be 0.
(r,s) = δ((B,E), (a) (C,F) (neither X nor x). In the place of (B,E) there will be 0.
(r,s) = δ((B,H), a) (C,H) (there is X). In the place of (B,H) there will be x.
(r,s) = δ((B,I), (a) (C,I) (there is X). In the place of (B,I) there will be x.
(r,s) = δ((E,H), (a) (F,H) (there is X). In the place of (E,H) there will be x.
(r,s) = δ((E,I), (a) (F,I) (there is X). In the place of (E,I) there will be x.
(r,s) = δ((H,I), (a) (H,I) (neither X nor x). In the place of (H,I) there will be 0.
(c) The pair combination of final states are (C,D), (C,F), (C,G), (D,F), (D,G), (F,G).
(r,s) = δ((C,D), (a) (H,I) (neither X nor x). In the place of (C,D) there will be 0.
(r,s) = δ((C,F), (a) (H,H) (There is dash, neither X nor x). In the place of (C,F) there will be 0.
(r,s) = δ((C,G), (a) (H,H) (neither X nor x). In the place of (C,G) there will be 0.
(r,s) = δ((D,F), (a) (I,H) (neither X nor x). In the place of (D,F) there will be 0.
(r,s) = δ((D,G), (a) (I,H) (neither X nor x). In the place of (D,G) there will be 0.
(r,s) = δ((F,G), (a) (H,H) (neither X nor x). In the place of (F,G) there will be 0.
158 Automata Theory and Formal Languages
B x
C X X
D X X 0
E x 0 X X
F X X 0 0 X
G X X 0 0 X 0
H x x X X x X X
I x x X X x X X 0
A B C D E F G H
The combination of entries 0 are the states of the modified machine. The states of the minimized ma-
chine are [A], [B,E], [C,D], [C,F], [C,G], [D,F], [D,G], [F,G], [H,I].
For the minimized machine M '
Q' = ({A}, {B,E}, {C,D,F,G}, {H,I}).
[C,D], [C,F], [C,G], [D,F], [D,G] and [F,G] are grouped into single state [C,D,F,G] because all the pre-
vious combination of states are produced from these 4 states taking 2 states in a group.
Σ = {a,b}.
δ' :
NS
PS
a b
{A} {B,E} {B,E}
{B,E} {C,D,F,G} {C,D,F,G}
{C,D,F,G} {H,I} {H,I}
{H,I} {H,I} {H,I}
q'0 : {A}.
F ' : {C,D,F,G}.
Q. Minimize the following finite automata by Myhill Nerode Theorem.
NS
PS
I/P=a I/P=b
➞A B F
B A F
C G A
D H B
E A G
F H C
G A D
H A C
Here F,G,H are final states.
Finite Automata 159
Ans.
Step I: Divide the states of the DFA into two subsets Final (F) and non-final (Q–F).
F={E,F,G}, Q–F = {A,B,C,D}
Make a two-dimensional matrix labeled at left and button by the states of the DFA.
A — — — — — — — —
B — — — — — — —
C — — — — — —
D — — — — —
E — — — –
F — — —
G — —
H —
A B C D E F G H
Step II: (a) The following combinations are the combination of beginning and final state.
(A,E), (A,F),(A,G),(B,E), (B,F),(B,G),(C,E),(C,F),(C,G),(D,E),(D,F),(D,G)
Put X in these combinations of states.
The modified matrix will be
B
C
D
E
F X X X X X
G X X X X X
H X X X X X
A B C D E F G
(b) The pair combination of non-final states are (A,B), (A,C), (A,D), (A,E), (B,C), (B,D), (B,E), (C,D),
(C,E), (D,E).
r = δ(A,a) B s = δ(B,a) A , in the place of (A,B) there is neither X nor x. Hence in the place of
(A,B) there will be 0.
Same like (r,s) = δ((A,C), a) (B,G) (there is X). In the place of (A,C) there will be x.
(r,s) = δ((A,D), (a) (B,H) (there is X). In the place of (A,D) there will be x.
(r,s) = δ((A,E), (a) (B,A) (there is neither X nor x). In the place of (A,E) there will be 0
(r,s) = δ((B,C), (a) (A,G) (there is X). In the place of (B,C) there will be x.
(r,s) = δ((B,D), (a) (A,H) (there is X). In the place of (B,D) there will be x.
(r,s) = δ((B,E), (a) (A,A) (there is neither X nor x, only dash). In the place of (B,E) there will be 0.
(r,s) = δ((C,D), (a) (G,H) (there is neither X nor x). In the place of (C,D) there will be 0.
(r,s) = δ((C,E), (a) (G,A) ) (there is X). In the place of (C,E) there will be x.
(r,s) = δ((D,E), (a) (H,A) (there is X). In the place of (D,E) there will be x.
160 Automata Theory and Formal Languages
(c) The pair of combinations of final states are (F,G), (F,H), (G,H)
(r,s) = δ((F,G), (a) (A,H) (there is X). In the place of (F,G) there will be x.
(r,s) = δ((F,H), (a) (H,A) (there is X). In the place of (F,H) there will be x.
(r,s) = δ((G,H), (a) (A,A) (there is neither X nor x, there is only dash). In the place of (G,H) there
will be 0.
The modified table:
B 0
C X X
D X X 0
E 0 0 X X
F X X X X X
G X X X X X X
H X X X X X X 0
A B C D E F G
The combination of entries 0 are the states of the modified machine. The states of the minimized ma-
chine are (A,B), (A,E), (B,E) ,(C,D), (G,H), i.e. (A,B,E), (C,D), (G,H) and (F) (As F is a Final state of
the machine but it is left in the state combinations).
(A,B, E) for input ‘a’ give output (A,B,A) and for input ‘b’ give output (F,F,G), where (F,F) belong
to one set and (G) belong to another set. Therefore, it will be divided into (A,B), (E).
The states of the minimized machines are (A,B) ,(E), (C,D), (G,H) and (F). Let name them as S1, S2,
S3, S4, S5.
For the minimized machine M'
Q = {S1, S2, S3, S4, S5},
Σ = {a,b}.
State table (Transitional function δ)
NS
PS
a b
S1 S1 S5
S2 S1 S4
S3 S4 S1
S4 S1 S3
S5 S4 S3
¢ $ Input Tape
Reading Head
Finite
Control
Example:
Consider a 2DFA, M given in the table
NS
PS
0 1
➞A A, R B, R
B B, R C, L
C A, R C, L
Let a string 101001 is given to check whether it is accepted by the 2DFA or not.
(A,101001) (B, 01001R) (B, 1001R) (C,01001L) (A,1001R) (B,001R) (B, 01R)
(B,1R) (C,01L) (A, 1R) B
We have reached to the final state and the string is finished. Therefore the string 101001 is accepted by
the 2DFA.
Q. Mention some applications of finite automata:
Ans. Finite automata can be applied in different fields of computer science and in different engi-
neering fields. Some of them are spelling checkers and advisers, multi-language dictionaries, minimal
perfect hashing and text compression. Perhaps the most traditional application is found in compiler
construction where such automata can be used to model and implement efficient lexical analyzers.
6. For a NFA for some cases for a single input given to a single state the machine goes to more than
one states, i.e. Q X Σ 2Q.
7. NFA can be constructed to an equivalent DFA.
8. A finite automata is called a NFA with null move if there exists a null transaction, i.e. Q X e Q.
9. Dead state is a state where the control can enter and confined till the input ended, but no way to
come out from that state.
10. In Mealy Machine output depends on present state and present input.
11. In Moore Machine output depends on only present state.
12. Myhill Nerode Theorem is used to minimize a finite automata.
13. Two way finite automata are machines which can traverse (read) an input string in both directions
(Left and right).
14. Finite automata is used in designing Lexical analyzer.
SOLVED PROBLEMS
1. Test whether the following string is accepted by the following finite automata or not.
(a) 0001101 (b) 01010
NS
PS
0 1
➞q0 q2 q3
q1 q0 q2
q2 q1 q3
q3 q3 q1
Ans.
(a) δ (q0, 0001101) δ (q2, 001101)
δ (q1, 01101)
δ (q0, 1101)
δ (q3, 101)
δ (q1, 01)
δ (q0, 1)
q3.
As q3 is the final state so the string is accepted by the given finite automata.
(b) δ (q0, 01010) δ (q2, 1010)
δ (q3, 010) δ (q3, 10)
δ (q1, 0)
q0
The q0 is a non-final state. Hence the string is not accepted by the given finite automata.
Finite Automata 163
2. Test whether the following string is accepted by the following finite automata or not.
(a) 0111100 (b) 11010
1
0
0 q1 1
q0 q2
0
1 0
q3
Ans.
(a) δ (q0, 0111100) δ (q1, 111100)
δ (q2, 11100)
δ (q0, 1100)
δ (q3, 100)
δ (q3, 00)
δ (q2, 0)
q2.
The q2 is the final state. Therefore, the string is accepted by the given finite automata.
(b) δ (q0, 11010) δ (q3, 1010)
δ (q3, 010)
δ (q2, 10)
δ (q0, 0)
q1
q1 is a non-final state. Therefore, the string is not accepted by the given finite automata.
3. Test whether the string 10010 is accepted by the following NFA or not.
NS
PS
a=0 a=1
➞A B A, C
B B C
C A, D B
D D B
164 Automata Theory and Formal Languages
Ans.
1 0
0 B C
A
0 D
C
0 1 0
1 D D B B
A
A
A
0
B 0 1 0
B C
For the string 10010 we are getting terminal state as D which is a final state for two cases. Therefore,
the string is accepted by the NFA.
4. Convert the following NFA into an equivalent DFA.
NS
PS
a=0 a=1
➞q0 q0, q1 q0
q1 q2, q3 q1
q2 q3 q3
q3 – q2
Ans. This is an NFA because here for present state q0 with input 0 the control moves to q0, q1.
NS
PS
a=0 a=1
[q0] [q0, q1] [q0]
[q0, q1] [q0, q1, q2, q3] [q0, q1]
[q0, q1, q2, q3] [q0, q1, q2, q3] [q0, q1, q2, q3]
For simplification let replace [q0] by A, [q0, q1] by B, [q0, q1, q2, q3] by C. Here A is the initial state
and C is the final state as it contains the state q3.
The simplified DFA is
NS
PS
a=0 a=1
➞A B A
B C B
C C C
Finite Automata 165
NS
PS
a=0 a=1
➞q0 q0, q1 q0, q2
q1 q3 –
q2 – q3
q3 q3 q3
Ans.
NS
PS
a=0 a=1
[q0] [q0, q1] [q0, q2]
[q0, q1] [q0, q1, q3] [q0, q2]
[q0, q2] [q0, q1] [q0, q2, q3]
[q0, q1, q3] [q0, q1, q3] [q0, q2, q3]
[q0, q2, q3] [q0, q1, q3] [q0, q2, q3]
For simplification let replace [q0] by A, [q0, q1] by B, [q0, q2] by C, [q0, q1, q3] by D and [q0, q2, q3]
by E. Here A is the initial state and D and E are the final state as they contains the state q3.
The simplified DFA is
NS
PS
a=0 a=1
➞A B C
B D C
C B E
D D E
E D E
q0 ε q1 ε q2
Ans. In the given automata there are two ∊ moves, from q0 to q1 and from q1 to q2. If we want to
remove the first ∊ moves, from q0 to q1 then, we have to find all the edges starting from q1.The edges are
q1 to q1 for input a, and q1 to q2 for input є.
166 Automata Theory and Formal Languages
Duplicate all these transitions starting from the state q0, keeping the edge label same. The q0 is initial
state, so make q1 also an initial state. The q1 is the final state, therefore make q0 as final state. The modi-
fied transitional diagram:
a
b
q0 a q1 ε q2
b
ε
Again there are two ∊ moves, from q0 to q2 and from q1 to q2. If we want to remove the null transition
from q0 to q2, we have to find all the edges starting from q2. The edges are q2 to q0 for input b. Duplicate
this transition starting from the state q0, keeping the edge label same. The modified transitional diagram:
(As in q0 there is a loop with label b, we need not to make another loop with the same label.)
a
b
q0 a q1 ε q2
If we want to remove the null transition from q1 to q2, we have to find all the edges starting from q2. The
edges are q2 to q0 for input b. Duplicate this transition starting from the state q1, keeping the edge label
same. Here q1 is initial state, hence make q2 also an initial state. The modified transitional diagram:
a
b
a
q0 q1 q2
b
6. Convert the following Moore machine to equivalent Mealy machine by tabular format.
NS
PS O/P
I/P=0 I/P=1
➞q0 q2 q1 0
q1 q0 q3 1
q2 q3 q4 1
q3 q4 q1 0
q4 q4 q2 1
Finite Automata 167
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q2 1 q1 1
q1 q0 0 q3 0
q2 q3 0 q4 1
q3 q4 1 q1 1
q4 q4 1 q2 1
7. Convert the following Moore machine to equivalent Mealy machine by tabular format.
NS
PS O/P
I/P=0 I/P=1
➞q0 q1 q3 1
q1 q0 q2 0
q2 q4 q1 0
q3 q4 q3 1
q4 q3 q1 0
Ans.
The equivalent Mealy machine is
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q1 0 q3 1
q1 q0 1 q2 0
q2 q4 0 q1 0
q3 q4 0 q3 1
q4 q3 1 q1 0
8. Convert the following Mealy machine to equivalent Moore machine by tabular format.
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q1 1 q2 1
q1 q3 0 q0 1
q2 q4 0 q3 1
q3 q1 0 q4 0
q4 q2 1 q4 0
Ans. In the next state column of the given Mealy machine the output differs for q1 and q3 as next
state. Therefore, the states will be divided as q10, q11 and q30, q31, respectively. After dividing the states
168 Automata Theory and Formal Languages
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q11 1 q2 1
q10 q30 0 q0 1
q11 q30 0 q0 1
q2 q4 0 q31 1
q30 q10 0 q4 0
q31 q10 0 q4 0
q4 q2 1 q4 0
NS
PS O/P
I/P=0 I/P=1
➞q0 q11 q2 1
q10 q30 q0 0
q11 q30 q0 1
q2 q4 q31 1
q30 q10 q4 0
q31 q10 q4 1
q4 q2 q4 0
To get rid of the problem of occurrence of null string, we need to include another state let qa with same
transactions as of q0 but with output 0.
The modified final Moore machine equivalent to the given Mealy machine is
NS
PS O/P
I/P=0 I/P=1
qa q11 q2 0
q0 q11 q2 1
q10 q30 q0 0
q11 q30 q0 1
q2 q4 q31 1
q30 q10 q4 0
q31 q10 q4 1
q4 q2 q4 0
Finite Automata 169
9. Convert the following Mealy machine to equivalent Moore machine by tabular format.
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q0 1 q1 0
q1 q3 1 q3 1
q2 q1 1 q2 1
q3 q2 0 q0 1
Ans. In the next state column of the given Mealy machine the output differs for q2 and q3 as next
state. Therefore the states will be divided as q10, q11 and q20, q21, respectively. After dividing the states the
modified Mealy machine will be
I/P=0 I/P=1
PS
NS O/P NS O/P
➞q0 q0 1 q10 0
q10 q3 1 q3 1
q11 q3 1 q3 1
q20 q11 1 q21 1
q21 q11 1 q21 1
q3 q20 0 q0 1
I/P=0
PS O/P
I/P=0 I/P=1
➞q0 q0 q10 1
q10 q3 q3 0
q11 q3 q3 1
q20 q11 q21 0
q21 q11 q21 1
q3 q20 q0 1
To get rid of the problem of occurrence of null string, we need to include another state let qa with
same transactions as of q0 but with output 0.
The modified final Moore machine equivalent to the given Mealy machine:
I/P=0
PS O/P
I/P=0 I/P=1
➞qa q0 q10 0
q0 q0 q10 1
q10 q3 q3 0
q11 q3 q3 1
q20 q11 q21 0
q21 q11 q21 1
q3 q20 q0 1
170 Automata Theory and Formal Languages
10. Convert the following Moore machine into equivalent Mealy Machine by transitional
format.
b
a
A a B b C
1 0 0
b a
a b
D
1
Ans.
(a) In this machine A is the beginning state. Therefore start from A. For A there are three incoming
arc, from A to A with input b and one in the form of start state indication with no input and the last
is from D to A with input a. State A is labeled with output 1. As the start state indication contains
no input, it is useless, keep it as it is.
Modify the label of the incoming edge from D to A and from A to A including the output of state A.
Hence the label of the incoming state will be D to A with label a/1 and A to A with label b/1.
(b) State B is labeled with output 0. The incoming edges to the state B are from A to B with input a,
D to B with input b. Modify the labels of the incoming edges including the output of state B. So
the labels of the incoming states will be A to B with label a/0, D to B with label b/0.
(c) State C is labeled with output 0. There are two incoming edges to this state, from B to C with
input b and from C to C with input a. The modified label will be B to C with label b/ 0, and C to
C with label a/ 0.
(d) State D is labeled with output 1. There are two incoming edges to this state, from B to D with
input a, and from C to D with input b. The modified label will be B to D with label a/1, and C to
D with label b/1. The converted Mealy machine:
b/ 1
a/ 0
A a/ 0 b/ 0
B C
b/ 0 a/ 1
a/1 b/ 1
D
Finite Automata 171
11. Convert the following Mealy machine into equivalent Moore Machine by transitional
format.
a/ 1
b/ 0
A a/ 0
B C
b/ 1
b/ 0 a/ 0
a/ 0
D
b/ 1
Ans. The machine contains four states. Lets start from the state A. The incoming edges to this state
are from D to A with label a/0. There is no difference of the outputs of the incoming edges to this state
so in the constructing Moore machine the output for this state will be 0.
a/ 1
b/ 0
A a/ 0
B C
0
b/ 1
b/ 0 a/ 0
a/ 0
D
b/ 1
For the state B, the incoming edges are B to B with label a/1, from A to B with label a/0 and from C to
B with label b/1.
There are two different outputs we are getting for two incoming edges (B to B output 1, A to B
output 0). So, the state B will be divided into two, lets name them B0 and B1. The outgoing edges are
duplicated for both the states generated from B. The modified machine:
a
B1 b/ 0
1
b
a
b/ 0
A a B0 C
0 0
b/ 0
a/ 0
a
D
b/ 1
172 Automata Theory and Formal Languages
For the state A, the incoming edges to this state are from B0 to C with label b/0 and B1 to C with label
b/0. There is no difference of the outputs of the incoming edges to this state so in the constructing Moore
machine the output for this state will be 0.
a
B1 b
1
b
a
b
A a B0 C
0 0 0
b/ 0
a/ 0
a
D
b/ 1
For the state D, the incoming edges are A to D with label b/0, from C to D with label a/0 and from D to
D with label b/1.
There are two different outputs we are getting for two incoming edges (D to D output 1, C to D output
0). So, the state D will be divided into two, let name them D0 and D1. The outgoing edges are duplicated
for both the states generated from D. The modified machine:
a
B1 b
1
b
a
b
A a B0 C
0 0 0
b
a
a
a
D0
0
D1 b
1
b
Finite Automata 173
NS
PS
I/P=a I/P=b
➞A B F
B A F
C G A
D H B
E A G
F H C
G A D
H A C
Here F,G,H are final states.
Ans. In the Finite automata the states are {A,B,C,D,E,F,G,H }. Name this set as S0.
In the finite automata, there are two types of states Final State and Non-Final States. So divide the set
of states into two parts Q1 and Q2.
States belong to same subset are 1-equivalent because they are in the same set for string length 1.
States belong to different subsets are 1- distinguishable.
The next states of F are H and C. The next states of G and H are A, D and A, C, respectively.
A, D and A, C belong to the same subset but H and C are belong to different subset. Hence, F, G, H
are divided into {F}, {G, H}.
For input 0 the next states of A, B, C, D and E are B, A, G, H and A, respectively. For input 1 the next
states of A, B, C, D and E are F, F, A, B and G, respectively. Hence, the set {A, B, C, D, E } is divided
into {A, B, E} and {C, D}.
S3: {{F} {G, H} {A, B} {E} {C, D}} = {{A, B}, {C, D}, {E}, {F}, {G, H}}
The set further is not dividable. So these are the states of minimized DFA. Let rename the subsets
as q0, q1, q2, q3 and q4. Initial state was A, Hence here initial state is {A,B}, i.e. q0. Final state were
F, G and H, hence here final states are {F}, i.e. q3 and {G,H}, i.e. q4. The tabular representation of
174 Automata Theory and Formal Languages
minimized DFA is
NS
PS
I/P=0 I/P=1
➞q0 q0 q3
q1 q4 q0
q2 q0 q4
q3 q4 q1
q4 q0 q1
13. Design a Mealy and Moore Machine for detecting a sequence 1010 where overlapping
sequences are also accepted. The Moore Machine that you have got, convert it to Mealy
Machine. Are any differences coming? How will you prove that the two Mealy machines
are equivalent?
Ans.
The Mealy Machine is
1/0 1/0
0/0
0/0 1/0
A B C D
1/0
0/1
0/0
1
0 1
1 0 1 0
A/0 B/0 C/0 D/0 E/1
0 1
The converted Mealy machine from the given Moore Machine is (By using transactional format)
Finite Automata 175
0/0
1/0
0/0 1/0
1/0 0/0 1/0 0/1
A B C D E
0/0 1/0
This is surely different from the previously constructed Mealy Machine in number of states and in
transactions.
But these two Mealy machines are equivalent. This can be proved by finding the equivalent partitions
of the second machine.
The tabular format of the previous machine is
NS, z
PS
x=0 x=1
A A, 0 B, 0
B C, 0 B, 0
C A, 0 D, 0
D E, 1 B, 0
E A, 0 D, 0
P0 = {A,B,C,D,E},
P1 = {A,B,C,E}{D},
P2 = {A,B}{C,E}{D},
P3 = {A}{B}{C,E}{D},
P4 = {A}{B}{C,E}{D}.
Rename the states as S1, S2, S3, S4
NS, z
PS
x=0 x=1
S1 (A) S1, 0 S2, 0
S2 (B) S3, 0 S2, 0
S3 (C, E) S1, 0 S4, 0
S4 (D) S3, 1 S2, 0
EXERCISES
1. Test whether the following strings are accepted by the given finite automata or not.
(a) 01010 (b) 1010100 (c) 0100101
NS
PS
a=0 a=1
➞q0 q1 q2
q1 q3 q2
q2 q2 q3
q3 q3 q0
2. Test whether the following strings are accepted by the given finite automata or not.
(a) 100010 (b) 0001101 (c) 1000
0
0, 1
q0 1 q1 1 q2
0
0 1
q3
178 Automata Theory and Formal Languages
3. Test whether the following string 101001 is accepted by the given finite automata or not taking all
possible combination of transitional path.
0
1
q0 1 q1 0 q2
1 1
0
0
0
q3
0 1 1 a q1 a
q0 q1 q2
ε q0 b ε q2
ε
ε q3 b
0
8. Convert the following Moore Machine into equivalent Mealy machine by transitional format.
0
1
0 1
1 0 1 0
A/0 B/0 C/0 D/0 E/1
0 1
9. Convert the following Mealy Machine into equivalent Moore machine by transitional format.
1/0
A B C D
1/0 0/1
0/0
10. Minimize the following finite automata by finding equivalent state method..
(a) NS (b) NS
PS PS
I/P=0 I/P=1 I/P=0 I/P=1
➞A E C ➞A B H
B C A B F D
C B G C D E
D G A D C F
E F B E D C
F E D
F C C
G D G
G C D
H C A
180 Automata Theory and Formal Languages
NS
PS
I/P=0 I/P=1
➞A B F
B G C
C A C
D C G
E H F
F C G
G G E
H G C
17. The states which can never be reached from the initial state are called ________ state.
18. A relation R in set S is called equivalence relation if it is ________, ________ and ________.
19. A relation R in set S is ________ if for x,y in S, yRx whenever xRy.
20. A relation R in set S is ________ if for x,y and z in S, xRz whenever xRy and yRz.
21. R is ________ then for all x,y and z , xRy => xzRyz.
22. Myhill-Nerode Theorem is used for ________.
23. A two way finite automata is like Finite Automata but can traverse in ________.
24. Lexical analyzer is designed by ________.
25. Maximum number of states of a DFA converted from a NFA with n states is ________.
26. A Finite Automata recognizes ________ language.
ANSWERS