Finite Automata: Theory of Computation
Finite Automata: Theory of Computation
Finite Automata: Theory of Computation
FINITE AUTOMATA
Contents: Introduction, Finite automata and its working ,Types of finite automata, DFA,
NFA,NFA to DFA conversion, NFA with ε- Transitions, NFA with ε to DFA conversion, DFA
minimization , Finite automata with output: Moore machine and Mealy machine, Conversion of
Moore machine to Mealy machine, Conversion of Mealy machine to Moore machine.
Finite automata:
A finite automaton is considered to be a mathematical model of a machine or a system. The finite
automaton plays the role of a language acceptor. It takes input string and decides whether the
string will be accepted or rejected. It just produces answer “yes” if machine accepts the string
otherwise it produces “no” answer.
Input tape a a b b
Read head
Formal definition:
An FA can be expressed mathematically as,
M= (Q, ∑, δ, q0, F)
where ,
Q: finite set of states
∑: finite set of input symbols
δ: state transition function as, Q X ∑→Q
q0: an initial state q0 Q
F: finite set of final states
In automata theory the transition function can be described by following two ways
1] Transition diagram or transition graph
2] Transition table
➢ Transition diagram or transition graph
A diagrammatical representation of an FA is known as transition diagram. In transition diagram,
a state is represented by a circle, and the transition between states is indicated by directed lines
connecting the circles. Different notation used in transition diagram is as follows.
Initial state
Intermediate state
Final state
Example:
➢ Transition table:
A transition table is a tabular representation of transition function. The row of the table
corresponds to the state, and the column corresponds to the inputs. The entry for the row
corresponding to state q and the column corresponding to input ‘a’ is the state ∂(q,a).
• In transition table initial state is represented by →
• Final state is represented by ‘*’
Example: In this e.g. states are q1, q2 and input are 0&1.for q1 state 0 transition goes to q2 state.
∑
Q 0 1
→q1 q2 q1
q2* q2 q1
FA with final state &no o/p FA with o/p & no final state
Types of FA:
There are two types of FA with no output.
1. Deterministic Finite Automata (DFA)
An finite automata is said to be an deterministic if from every vertex of its transition
graph, there is an unique input symbol which takes the vertex state to the required next
state i.e. there has to be an unique transition on input symbol.
0 1 1
q0 q1
01 0
1
q2
Fig: An DFA accepting all the string that ends with ‘0’
0 1
q0 q1 q2
Fig: An NFA accepting all the string that ends with ‘01’
Examples on DFA:
1] Design a DFA for string containing odd number of a’s.
Solution: Let M= (Q, ∑, δ, q0, F)
∑={a}
The language accepted by this DFA over alphabet , ∑ = { a } is,
L = {a, aaa, aaaaa, aaaaaaa,………}
In a string of a’s no of a’s can be even or odd. so it is represented by 2 states.
Q={q0,q1}
Transition Table: ∑ a
Q
Even no of a’s →q0 q1
Odd no of a’s q1* q0
Transition Diagram: a
q0 q1
a
Simulation:
Let L=aaa
δ (q0, aaa)
= δ ( q1, aa)
= δ (q0,a)
= q1 (Accept)
2] Design a DFA for language of strings with odd number of a’s and any number of b’s
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet , ∑ = { a,b } is
L = {a, ab, ba,bab,aaab, abb, , ……….}
In this string there are two cases as follows:
1. Even number of a’s and any number of b’s (q0 state)
2. Odd number of a’s and any number of b’s (q1 state)
Q = {q0, q1}
Transition Table:
∑
b
Q a
Even a’s any b’s →q0 q1 q0
Odd a’s any b’s q1* q0 q1
Transition Diagram:
Simulation:
Let L=baaa
δ (q0,baaa)
= δ ( q0, aaa)
= δ (q1,aa)
= δ (q0,a)
= q1 (Accept)
3] Design a DFA for language of string with odd number of 0’s and even number of 1’s.
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { 0,1 }
The language accepted by this DFA over alphabet, ∑ = { 0, 1 } is
L = {011 ,01010, 0101011,……………..}
In this string there are four cases as follows:
1. Even number of 0’s and even number of 1’s (q0 state)
2. Even number of 0’s and odd number of 1’s (q1 state)
3. Odd number of 0’s and even number of 1’s (q2 state)
4. Odd number of 0’s and odd number of 1’s (q3 state)
Q = {q0, q1, q2, q3 }
Transition diagram:
Transition table
∑
0 1
Q
→q0 q2 q1
q1 q3 q0
q2* q0 q3
q3 q1 q2
Simulation:
Let L=01100
δ (q0,01100)
= δ (q2, 1100)
= δ (q0, 100)
= δ (q2,00)
= δ (q0,0)
= q2 (Accept)
4] Design DFA which accepts string with exactly four alphabets.
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = { a,b } is
L = {aaab,baba,bbaa,……………}
As string length is four so it requires five states, .here q5 state is dead state which is used for
satisfying the DFA constraints.
Q={q0.q1,q2,q3,q4,q5}
Transition Diagram:
Transition Table:
∑
Q a b
→q0 q1 q1
q1 q2 q2
q2 q3 q3
q3 q4 q4
q4* q5 q5
q5 q5 q5
Simulation:
Let L=aaab
δ (q0,aaab)
= δ (q1,aab)
= δ (q2, ab)
= δ (q3,b)
= q4 (Accept)
5] Design DFA for language of string if it ends in a double letter over ∑={a,b}
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = { a,b } is
L = {aa,bb,abb,baa,bbaa,……………}
As string ends with double letter so there are two final states one is ending with ‘aa’ and other is
ending with ‘bb’.
Q={q0,q1,q2,q3 }
Transition Diagram:
Transition Table:
∑
Q a b
a →q0 q2 q1
q1 q0 q3
b
aa q2* q2 q1
q3* q0 q3
bb
Simulation:
Let L=aaabb
= δ (q0,aaabb)
= δ (q2,aabb)
= δ (q2, abb)
= δ (q2,bb)
= δ (q1,b)
= q3(Accept)
6] Design DFA for language of string if it contains at least one occurrence of double letter
over ∑={0,1}
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { 0,1 }
The language accepted by this DFA over alphabet, ∑ = {0, 1} is
L = {00,11,0110,1001,…………..}
As string containing at least one occurrence of double letter means anywhere in the string 00 or
11 should be present, so there are two final states one is with 0 occurrence read as ‘00’ and other
with 1 occurrence as ‘11’.
Q={q0,q1,q2,q3 }
Transition Diagram:
Transition Table:
∑
Q 0 1
0 →q0 q2 q1
q1 q0 q3
1
00 q2* q2 q2
11 q3* q3 q3
Simulation:
Let L=1001
= δ (q0,1001)
= δ (q1,001)
= δ (q0, 01)
= δ (q2,1)
= q2 (Accept)
7]Design FA for a string does not contain any occurrence of three consecutive b’s.
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = {a,b} is
L = {b, bb, bba, a, ab, abb, ababa, …….}
Q = {q0, q1, q2, q3 }
Transition Diagram
Transition Table
∑
Q a b
a →q0* q0 q1
b q1* q0 q2
bb q2* q0 q3
bbb q3 q3 q3
Simulation:
Let L=ababa
= δ (q0,ababa)
= δ (q0,baba)
= δ (q1, aba)
= δ (q0,ba)
= δ (q1,a)
= q0(Accept)
8] Design FA to accept string that contains at least one occurrence of substring ‘bba’.
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = { a,b } is
L = {bba, abba, bbaa, bbba, , bbab, abababbaa, …….}
As FA containg atleast one occurrence of substring ‘bba’ so for reading three alphabet it requires
four states.
Q = {q0, q1, q2, q3 }
Transition Diagram :
Transition Table:
∑
Q a b
a →q0 q0 q1
b q1 q0 q2
bb q2 q3 q2
bba q3* q3 q3
Simulation:
Let L=bbba
= δ (q0,bbba)
= δ (q1,bba)
= δ (q2, ba)
= δ (q2,a)
= q3 (Accept)
Transition Table:
∑
Q 0 1
0 →q0 q0 q1
1 q1 q2 q4
10 q2 q3 q0
101/110 q3* q3 q3
11 q4 q3 q4
Simulation:
Let L=0110
= δ (q0,0110)
= δ (q0,110)
= δ (q1, 10)
= δ (q4,0)
= q3 (Accept)
10] Design DFA to check the i/p is valid if it ends with ‘100’over ∑ = {0,1 }
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { 0,1 }
The language accepted by this DFA over alphabet, ∑ = {0,1 } is
L = {100, 0100, 1100, , 10100, 01100, ,…………….}
For traversing the given sequence 100 from initial state q0 it requires four states.
Q = {q0, q1, q2, q3}
Transition Diagram:
Transition table:
∑
Q 0 1
0 →q0 q0 q1
1 q1 q2 q1
10 q2 q3 q1
100 q3* q0 q1
Simulation:
Let L=10100
= δ (q0,10100)
= δ (q1,0100)
= δ (q2,100)
= δ (q1, 00)
= δ (q2,0)
= q3 (Accept)
11] Design DFA in which the i/p is valid if it ends in either ‘101’or ‘110’over ∑ = {0,1 }
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { 0,1 }
The language accepted by this DFA over alphabet, ∑ = {0,1 } is
L = {101, 110, 0101, 1101, 0110, 1110, 01101, 10110, ……….}
Q = {q0, q1, q2, q3, q4, q5}
Transition Diagram:
Transition Table:
∑
Q 0 1
0 →q0 q0 q1
1 q1 q2 q4
10 q2 q0 q3
101 q3* q2 q4
11 q4 q5 q4
110 q5* q0 q3
Simulation:
Let L=1101
= δ (q0,1101)
= δ (q1,101)
= δ (q4, 01)
= δ (q5,1)
= q3 (Accept)
12] Design a FA such that if the second last symbol is ‘a’ over ∑={a,b}
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = {a,b } is
L = {aa, ab, abab, abaa, , abaaa, ……….}
As there are two final states one is ending with aa and other is ending with ab because we want
second last symbol is ‘a’.
Q = {q0, q1, q2, q3 }
Transition Diagram:
Transition Table:
∑
Q a b
a →q0 q2 q3
b q1 q0 q1
aa q2* q2 q3
ab q3* q0 q1
Simulation:
Let L=abaa
= δ (q0,abaa)
= δ (q2,baa)
= δ (q3, aa)
= δ (q0,a)
= q2 (Accept)
Transition Diagram:
Transition Table:
∑
Q 0 1
dead q2 q2 q2
Simulation:
Let L=1010
= δ (q0, 1010)
= δ (q1,010)
= δ (q0, 10)
= δ (q1,0)
= q0 (Accept)
14] Design a DFA to accept language of Set of all strings with odd number of 1’s followed
by even number of 0’s
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { 0,1 }
The language accepted by this DFA over alphabet, ∑ = {0,1 } is
L = {100,10000, 11100,111110000, ….}
Q = {q0, q1, q2,q3 }
Transition Diagram:
Transition table:
∑
Q 0 1
→q0 q3 q1
q1* q2 q0
q2 q1 q3
q3 q3 q3
Simulation:
Let L=100
= δ (q0, 100)
= δ (q1,00)
= δ (q2, 0)
= q1 (Accept)
15] Design a DFA that accepts a set of all strings with which begin and ends with different
letters ∑ = { x, y, z }
Solution: : Let M= (Q, ∑, δ, q0, F)
∑ = { x,y,z }
The language accepted by this DFA over alphabet, ∑ = { x, y, z } is
L = ,xy, xz, zy,zx, yz, yx,xxyz, yxxz, ……….}
Q = {q0, q1, q2, q3, q4, q5, q6,q7,q8}
Transition table:
∑
Q x y z
xx →q0 q0 q1 q2
xy q1* q0 q1 q2
q1
xz q2* q0 q1 q2
yx q3* q3 q4 q5
q4 q3 q4 q5 q3
yy
yz q5* q3 q4 q5
zx q6* q6 q7 q8
q6
zy q7* q6 q7 q8
zz q8 q6 q7 q8
∑
Q x y z
→q0 q0 q1 q1
q1* q0 q1 q1
q3* q3 q4 q3
q4 q3 q4 q3
q6* q6 q6 q8
q8 q6 q6 q8
Transition diagram:
Transition diagram:
Transition table:
∑
Q 0 1
→q0* qo q1
q1 q2 q3
q2 q4 q0
q3 q1 q2
q4 q3 q4
Simulation:
Let L=101
= δ (q0, 101)
= δ (q1,01)
= δ (q2, 1)
= q0 (Accept)
Transition Table:
∑
Q {0,3,6,9} {1,4,7} {2,5,8}
→q0* q0 q1 q2
q1 q1 q2 q0
q2 q2 q0 q1
Simulation:
Let L=363
= δ (q0, 363)
= δ (q0,63)
= δ (q0, 3)
= q0 (Accept)
Transition Table:
∑
Q 0 1
→q0* q0 q1
q1 q2 q3
q2 q0 q1
q3 q2 q3
Simulation:
Let L=1100
= δ (q0, 1100)
= δ (q1,100)
= δ (q3, 00)
= δ (q2, 0)
= q0 (Accept)
Transition Table:
∑
Q 0 1 2
→ q0* q0 q1 q2
q1 q3 q4 q0
q2 q1 q2 q3
q3 q4 q0 q1
q4 q2 q3 q4
Simulation:
Let L=2102
= δ (q0, 2102)
= δ (q2,102)
= δ (q2, 02)
= δ (q1, 2)
= q0 (Accept)
Transition Table:
∑
x
Q
q0 q1
q1 q2
q2 q0
21] Obtain DFA to accept the strings which contains exctly three a’s over ∑ ={a, b}
Solution-
The above DFA accepts all strings with exactly three a’s and any number of b’s. Hence first we
traverse string ”aaa”.
State q0 is initial state.
As these three a’s are not necessarily consecutive threes, a string may contains any number of b’s
in between. Hence add self transition on input symbol ‘b’ on each state.
q3
Transition Diagram
Transition Table
∑
a b
Q
q0 q1 q0
q1 q2 q1
q2 q3 q2
q3 q3 q3
q1 q2 q3
3
Prepared By: Rohini Patil Page 23
Theory of computation
1. No transition
In the following automaton, if the string starts with ‘0’ then the string is rejected. Therefore, in
this example, no transition is given for initial state ‘q0’ on input symbol ‘0’.
NFA has same capacity as DFA; it just adds simplicity to DFA. The main reason to draw NFA
is, it becomes sometimes simpler to draw NFA for a particular problem than drawing a DFA.
Consider an example to draw finite automata that accepts strings ending in ‘01’.
The DFA for above problem is:
We can observe from above two transition diagrams that NFA is quite simpler than the DFA.As
we can omit some of transitions in NFA; it is easy to draw NFA with only necessary transitions.
The main issue with NFA is how does it know which arrow to follow? Either it guesses and
somehow makes the right choice or it tries multiple possibilities in parallel and one of them will
turn out as right choice.
Consider a string “011010” as an input to NFA.
It can try following configurations:
q0→ q0 → q1→ reject
q0→ q0 →q0→ q1→q2→ reject
q0→ q0 →q0→ q0 →q0→ q1→q2→ accept
q0→ q0 →q0→ q0 →q0→q0→ reject
If one of the paths lead to accepting state and entire input is consumed then machine accepts the
string.
Equivalence of NFA and DFA
The NFA and DFA have same capabilities. For every NFA there exists equivalent DFA which
accepts the same language. So we can convert the given NFA to its equivalent DFA. The method
of conversion is explained below.
1. Start with initial state of given NFA.
2. Find the transitions of this state on each input symbol.
3. If any new state is encountered then add it to DFA and GOTO step 2.
4. Repeat this till no new state is encountered.
Example 1
Consider NFA as
M=({q0,q1}, {0,1}, δ, q0, {q1})
Q={q0,q1}
∑={0,1}
δ is given in following table
Prepared By: Rohini Patil Page 25
Theory of computation
∑
0 1
Q
q1 * ϕ {q0,q1}
Solution:
1. Start with initial state ‘q0’ and find its transitions on input ‘0’ and ‘1’.
δ(q0,0)={q0,q1} and δ(q0,1)=q1
2. We get two new combinations of states here as {q0,q1}and {q1}. Now, find their
transitions on input ‘0’ and ‘1 and add them to the resultant DFA.
δ({q0,q1},0)= δ(q0,0) U δ(q1,0)={q0,q1}U ϕ = {q0,q1}
δ({q0,q1},1)= δ(q0,1) U δ(q1,1)={q0,q1}U {q1}= {q0,q1}
δ(q1, 0)= ϕ and δ(q1,1)= {q0,q1}
3. There is no new state generated from above transitions so we will stop here. The
transition table is given below represents all the above transitions.
∑
0 1
Q
→q0 {q0,q1} {q1}
q1* ϕ {q0,q1}
Example 2
Construct NFA that accepts a set of all strings over {a, b} ending with “abb”. Convert
this NFA to equivalent DFA
Solution-
First we traverse “abb” from start state q0 to final state. As NFA considers any single path, the
NFA is given as below.
The NFA is:
For above NFA, some transitions are missing so its also a DFA. The transition table for DFA is
given below.
Conversion to DFA:
a b
Q
→q0 q1 q0
q1 - q2
q2 - q3
q3 - -
It is deterministic It is non-deterministic
For each state for given input there is For each state for given input the next
a unique next state state is not uniquely determined
DFA minimization
The DFA can be minimized if it consists of equivalent states. The two states are equivalent if
there are same transitions on the same input symbol. The DFA can be minimized by removing
equivalent states. The rules for the minimization are:
1. Replace one non-final state by its equivalent non-final state only.
2. Replace one final state by its equivalent final state only.
3. Cannot replace initial state by any other state.
4. Replacing state ‘B’ by ‘A’ means deleting the row for state ‘B’ from the transition table
and replacing every entry of ‘B’ by ‘A’.
→p {q,r} q
q* r {q,r}
r s p
s* ϕ p
Ans-
1. Start from initial state ‘p’ and find its transitions on input ‘0’ and ‘1’.
δ(p,0)={q, r} and δ(p,1)=q
2. Here, we get two new combinations of states here as {q, r} and {q}. Now, find their
transitions on input ‘0’ and ‘1 and add them to the resultant DFA.
δ({q,r},0) = δ(q,0) U δ(r,0) = {r} U {s} = {r,s}
δ({q,r},1) = δ(q,1) U δ(r,1) = {q,r} U {p} = {p,q,r}
δ(q,0)={r} and δ(q,1)={q, r}
3. Now, we get the new states as: {r}, {r, s} and {p, q, r}. Similar to above step we will find
their transitions and add them to DFA.
δ({r,s},0) = {s}
δ({r,s},1) = {p}
δ({p,q,r},0) = {q,r,s}
δ({p,q,r},1) = {p,q,r}
δ(r,0)={s} and δ(r,1)={p}
4. The new states that can be added to DFA are {s} and {q, r, s}. Let us find their
transitions.
δ({q,r,s},0) = {r,s}
δ({q,r,s},1) = {p,q,r}
δ(s,0)= ϕ and δ(s,1)={p}
The transition table for DFA is given in figure
∑
0 1
Q
→p {q,r} q
{r,s}* s p
q* r {q,r}
r s p
s* ϕ p
5. As ‘q’ and‘s’ are final states in given NFA. All following states are final states in the
resultant DFA.
In above DFA state {q,r,s} and {q,r} are equivalent as both of them have same transitions on all
input symbols. So we can remove one of them. We can replace {q, r, s} by {q,r}. To do so delete
the row of {q,r,s} and replace each entry of {q,r,s } by{q,r}.The states {r,s } and{r} also have
similar transitions, but we cannot replace {r,s} by ‘r’ ,as {r,s} is final state and ‘r’ is non-final
state.
{r,s} S p
q r {q,r}
r s p
s Φ p
Example 2
Convert following NFA to equivalent DFA
{p,r} {p,q,s} p
{p,q,r,s}* {p,q,r,s} {p,r,s}
{p,q,s}* {p,q,r,s} {p,r,s}
{p,r,s}* {p,q,s} {p,s}
{p,s}* {p,q,s} {p,s}
q r r
r s ϕ
s* s s
In above DFA state {p,r,s} can be replaced by {p,s}as both are equivalent. Similarly {p,q,r,s}
can be replaced by {p,q,s}.The modified table after replacement is given below.
∑
0 1
Q
→p {p,q} p
{p,q} {p,q,r} {p,r}
{p,q,r} {p,q,s} {p,r}
{p,r} {p,q,s} p
{p,q,s}* {p,q,s} {p,s}
{p,s}* {p,q,s} {p,s}
q r r
r s ϕ
s* s s
From above table we can observe that we can replace state {p,q,s} by {p,s}and the modified
table is:
∑
0 1
Q
→p {p,q} p
{p,q} {p,q,r} {p,r}
{p,q,r} {p,s} {p,r}
{p,r} {p,s} p
{p,s}* {p,s} {p,s}
q r r
r s ϕ
s* s s
Example 3
Convert the following NFA to DFA (DEC-2011)
M=({p,q,r,s,t}, {0,1}, δ, p, {s,t}) (05 MARKS)
δ is given in following table
∑
0 1
Q
p {p,q} p
q {r, s} t
r {p,r} t
s* ϕ ϕ
t* ϕ ϕ
Solution:
Start from initial state ‘p’. A new state {p, q} is generated on input symbol ‘0’ from state ‘p’.
δ({p,q},0) = δ(p,0) U δ(q,0) = {p,q} U {r,s} = {p,q,r,s}
δ({p,q},1) = δ(p,1) U δ(q,1) = {p} U {t} = {p,t}
A new state {r,s} is generated on input symbol ‘0’ from state ‘q’.
δ({r,s},0) = δ(r,0) U δ(s,0) = {p,r} U { ϕ } = {p,r}
δ({r,s},1) = δ(r,1) U δ(s,1) = {t} U { ϕ } = {t}
A new state {p, r} is generated on input symbol ‘0’ from state ‘r’.
δ({p,r},0) = δ(p,0) U δ(r,0) = {p,q} U {p,r} = {p,q,r}
δ({p,r},1) = δ(p,1) U δ(r,1) = {p} U {t} = {p,t}
new states {p, q, r, s}, {p, t} and {p,q,r} are generated
δ({p,q,r,s},0) = {p,q,r,s}
δ({p,q,r,s},1) = {p,t}
δ({p, t},0) = {p, q}
δ({p, t},1) = {p}
δ({p,q,r},0) = {p,q,r,s}
δ({p,q,r},1) = {p,t}
Transition table for DFA is
∑
0 1
Q
p {p,q} p
q {r, s} t
r {p,r} t
s* ϕ ϕ
{r,s} {p,r} t
{p,t} {p,q} p
t* ϕ ϕ
In above DFA state {p,q,r} can be replaced by {p,q} as both are non final states, similarly final
state {r,s} can be replaced by final state {r}. Final state {p,q,r,s} cannot be replaced by non final
state {p,q}. Similarly final state {p,t} cannot be replaced by initial state {p}.
∑
0 1
Q
p {p,q} p
q r t
r {p,r} t
s* ϕ ϕ
{p,t} {p,q} p
t* ϕ ϕ
Example 4
Convert the given NFA to equivalent DFA
P is initial state and r and s are the final states
δ is given in following table
∑
0 1
Q
→p {p,r} {q}
q* {r,s} {p}
r {p,s} {r}
s* {q,r} {}
Ans-
1. Start from initial state ‘p’ and find its transitions on input ‘0’ and ‘1’.
δ(p,0)={p, r} and δ(p,1)=q
2. Here, we get two new combinations of states here as {p, r} and {q}. Now, find their
transitions on input ‘0’ and ‘1 and add them to the resultant DFA.
δ({p,r},0) = δ(p,0) U δ(r,0) = {p,r} U {p,s} = {p,r,s}
δ({p,r},1) = δ(p,1) U δ(r,1) = {q} U {r} = {q,r}
δ(q,0)={r,s} and δ(q,1)={p}
3. Now, we get the new states as: {p}, {q,r},{r,s} and {p, r, s}. Similar to above step we
will find their transitions and add them to DFA.
δ({q,r},0) = {p,r,s}
δ({q,r},1) = {p,r}
δ({r,s},0) = {p,q,r,s}
δ({r,s},1) = {r}
δ({p,r,s},0) = {p,q,r,s}
δ({p,r,s},1) = {q,r}
δ(p,0)={p,r} and δ(p,1)={q}
4. The new states that can be added to DFA is {p, q, r, s}. Let us find its transitions.
δ({p,q,r,s},0) = {p,q,r,s}
δ({p,q,r,s},1) = {p,q,r}
δ(r,0)= {p,s} and δ(r,1)={r}
δ(s,0)= {q,r} and δ(s,1)={}
5. The new states that can be added to DFA is {p, q, r}. Let us find its transitions.
δ({p,q,r},0) = {p,r,s}
δ({p,q,r},1) = {p,q,r}
R* {p,s} {r}
s* {q,r} {}
6. As ‘q’ and‘s’ are final states in given NFA. All following states are final states in the
resultant DFA.
• ε-closure of a state
ε-closure of state ‘q’ is set of states ‘p’ such that there is a path “from q to p” labelled ‘ε’
directly or indirectly. It is a set of states with distance zero from state ‘q’. The state itself is
included in its ε-closure.
Example 1
For the DFA in figure, we will find out the ε-closure of all states.
ε-closure of q0={q0,q1,q2}
In ε-closure of q0 the state q0 itself will be included.
There is a path with label ‘ε’ from q0 to q1 so q1 is included.
There is a path with label ‘ε’ from q1 to q2 i.e. there is ε-path from q0 to q2 indirectly as
q0→q1→q2. Therefore q2 is also included in ε-closure of q0.
Similarly, we can find,
ε-closure of q1={q1,q2}
ε-closure of q2={q2}
Q ε a b c
→p q,r - q r
q - p r p,q
r* - - - -
Solution:
1. Find ε-closure of all states:
ε-closure of p={p, q, r}
ε-closure of q={q}
ε-closure of r={r}
2. Now, we will start with state’ p’ its ε-closure is {p, q , r}. Find transitions of {p,q,r} on
each input symbol.
δ({p, q, r}, a)= δ(p, a) δ(q, a) δ(r, a) ={p}
δ({p, q, r}, b)= δ(p, b) δ(q, b) δ(r, b) ={q, r}
δ({p, q, r}, c)= δ(p, c) δ(q, c) δ(r, c) ={p, q, r}
3. From this we get two new states as {q, r} and {p, q, r} which we will add to resultant
DFA. Let us take state {q, r} first and find its ε-closure.
ε-closure(q, r)= ε-closure(q) ε-closure(r) ={q} {r}={q, r}
Find transitions of {q , r} on each input symbol
δ({q, r}, a)= δ(q, a) δ(r, a) ={p}
δ({q, r}, b)= δ(q, b) δ(r, b) ={r}
δ({q, r}, c)= δ(q, c) δ(r, c) ={p, q}
Here, we get again two new states as {r} and {p, q} which will be added to resultant
DFA.
4. Next we will take state {p, q, r}, its ε-closure is :
ε-closure(p, q, r)= ε-closure(p) ε-closure(q) ε-closure(r)
={p, q, r} {q} {r}={p, q, r}
We have already calculated the transitions of {p, q ,r} on each input symbol in step no.2
5. Next we will take state {r}, its ε-closure is {r}.
δ({r}, a)= δ({r}, b)=δ({r}, c)= {}
6. Next we will take state {p,q}, its ε-closure is :
ε-closure(p, q)= ε-closure(p) ε-closure(q) ={p, q, r} {q}={p, q, r}
We have already calculated the transitions of {p, q ,r} on each input symbol in step no.2
7. Next we will take state {q,r}, its ε-closure is :
ε-closure(q, r)= ε-closure(q) ε-closure(r) ={q} {r}={q, r}
We have already calculated the transitions of {q ,r} on each input symbol in step no.3
8. The states will be considered as final state if its ε-closure consists of final state of the
given NFA. Thus in the resultant DFA the states {q, r}, {p, q, r},{r} and {p, q} will
become final states.
There is no new state remaining to be added to the resultant DFA so we will stop here. All above
explained transitions are shown in following table.
X y= ε-closure(X) δ(y, a) δ(y, b) δ(y, c)
→p p,q,r p q, r p, q, r
q,r * q,r p r p,q
p,q,r* p,q,r p q, r p, q, r
r* r - - -
p,q* p,q,r p q, r p, q, r
We can observe from the above table that states {p, q, r} and {p, q} are equivalent so we can
replace them. The minimized DFA is shown below:
a b c
→p p q,r p,q
q,r* p r p,q
r* - - -
p,q* p q,r p,q
Example 2
Convert the given ε-NFA to equivalent minimized DFA.
Q ε a b C
→p - p q R
q p q r - -
r q r - P
Solution:
1. Find ε-closure of all states:
ε-closure of p={p}
ε-closure of q={p, q}
ε-closure of r={p, q, r}
2. Now, we will start with state’ p’ its ε-closure is {p}. Find transitions of {p} on each input
symbol.
δ({p}, a)= {p}
δ({p}, b)= {q}
δ({p}, c)= {r}
From this we get two new states as {q} and {r} which we will add to resultant DFA.
3. Let us take state {q}, its ε-closure is {p, q}. Find transitions of {p, q} on each input
symbol.
δ({p, q}, a)= δ(p, a) δ(q, a) ={p, q}
δ({p, q}, b)= δ(p, b) δ(q, b) ={q, r}
δ({p, q}, c)= δ(p, c) δ(q, c) ={r}
Here, we get again two new states as {q, r} and {p, q} which will be added to resultant
DFA
4. Next we will take state {r}, its ε-closure is {p, q, r}. Find transitions of {p, q, r} on each
input symbol.
δ({p, q, r}, a)= δ(p, a) δ(q, a) δ(r, a) ={p, q, r}
δ({p, q, r},b)= δ(p, a) δ(q, b) δ(r, b) ={q, r}
δ({p, q, r}, a)= δ(p, c) δ(q, c) δ(r, c) ={p, r}
Here, we get again two new states as {p, r} and {p, q, r} which will be added to resultant
DFA
5. Next we will take state {p,q}, its ε-closure is :
→p p P q r
q p, q p, q q, r r
r* p, q, r p, q, r q, r p, r
p, q p, q p, q q, r r
q, r* p, q, r p, q, r q, r p, r
p, r* p, q, r p, q, r q, r p, r
p, q, r* p, q, r p, q, r q, r p, r
From the table we can observe that the states {q} and {p, q} are equivalent so we can replace
{p, q} by {p}. Similarly states {r},{q, r},{p, r} and {p, q, r} are equivalent so we can replace
them and can minimize the DFA as shown below.
→p p Q r
q q q, r r
r* r R r
∑
Q 0 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
• From above table put ‘X’ for row and column of final state
C X X
D X
E X
F X
G X
H X
A B C D E F G
B X
C X X
D X X X
E √ X X X
F X X X √ X
G X X X X X X
H X √ X X X X X
A B C D E F G
We get following equivalent pairs as (D, F) ,(B, H) and (A, E)
Thus the minimized DFA is :
∑
0 1
Q
→A B F
B G C
C* A C
F C G
G G A
→A B C
B D E
C F G
D D E
E F G
F* D E
G F G
Solution:
B √
C X X
D √ √ X
E X X √ X
F X X X X X
G X X √ X √ X
A B C D E F
The equivalent pairs we get are (AB),(AD)(BD) (A ,B,D)
(EG),(CG),(CE) (C,E,G)
(A ,B,D) (C,E,G),F
The minimized DFA is,
∑ 0 1
Q
→A A C
C F C
F* A C
∑
a b
Q
→q0 q1 q3
q1 q0 q3
q2 q1 q4
q3* q5 q5
q4 q3 q3
q5* q5 q5
Note: if more than one final states are there then do not put ‘X’ for their combination. First
check the transitions and then decide.
Solution: Here two final states i.e.q3,q5 so put ‘X’ for row and column of q3 and q5.
While doing this, we will not put ‘X’ for (q3, q5) pair.
Because, δ(q3,a) = δ(q5,a) =q5
δ(q3,b)= δ(q5,b)=q5
Both transitions are equal.
q1 X
q2 X X
q3 X X X
q4 X X X X
q5 X X X √ X
q0 q1 q2 q3 q4
The minimized DFA is:
∑ a b
Q
→q0 q1 q3
q1 q0 q3
q2 q1 q4
q3* q3 q3
q4 q3 q3
b X
c X X
d X X X
e X X X X
f X X X X X
g X X X X X X
h X X X X X X X
a b c d e f g
As equivalent states are not present in above DFA, it cannot be minimized any more. Hence
given DFA is minimized DFA
E* B C
After constructing table we get two pair that are equivalent i.e.(A,D) and (C,E)therefore there are
three states (A,D) (C,E),B
The minimized DFA is ,
∑ 0 1
Q
→A B C
B B A
C* B C
Here state A and C cannot be merged because one is final and other is non final.
Finite Automata with Output,Such machines do not have final states. Both machine generates
output for every input and can be categorized as,
1. Moore machine
2. Mealy machine.
➢ Moore Machine:
It is a machine with finite no of states and for which output symbol at a given time depends on
present state of machine. In Moore machine the output symbol is associated with each state.
Formal definition: A Moore machine can be expressed as,
M=(Q,∑,∆,δ,λ ,q0)
Q : Finite set of states
∑: Input alphabet
∆:Output alphabet
δ: State transition function Q X ∑ →Q
λ: Machine function/Output Function Q→ ∆
q0: initial state
Example:
qB qC qB b
qC qB qA a
➢ Mealy Machine:
It is a machine with finite no of states and for which output symbol at a given time depends on
present input symbol and present state of machine. In Mealy machine the output symbol is
associated with each transition.
Formal definition: A Mealy machine can be expressed as,
M=(Q,∑,∆,δ,λ ,q0)
qC qA qB qC c b
1] Design Moore and Mealy machine to find 1’s complement of a binary number .
Solution:
Moore Machine: Let M=(Q,∑,∆,δ,λ ,q0) be the required machine.
∑={0,1}
∆={0,1}
As we have two output symbols so require two states to represent them.
Hence Q={q0,q1}
q0 which gives output “0” .
q1 which gives output “1” .
Transition Table:
∑
0 1 o/p
Q
→q0 q1 q0 0
q1 q1 q0 1
Transition Diagram:
Mealy Machine:
For mealy machine we require just two transitions. One is to convert 0 to 1 and other to convert 1
to 0.
State transition table δ= Output table λ=
∑ ∑
0 1 0 1
Q Q
q0 →q0 0
→q0 q1 1
q0 0
q1 q1 q1 1
Transition Diagram:
2] Design Moore and Mealy machine consisting of strings from from ∑ * , where ∑ ={0,1} ,
and ending with “00” or “11” OR (0+1)*(00+11)
Solution:Let ∑ ={0,1}
Let us assume ,∆={Y,N}
If string is accepted it gives “Y” output otherwise it gives “N” output.
Moore Machine: We have to check whether the string is ending with “00” or “11”.
Transition table:
∑
0 1 o/p
Q
q0 q1 q3 n
q1 q2 q3 n
q2 q2 q3 y
q3 q1 q4 n
q4 q1 q4 y
Mealy Machine:
State transition table δ= Output table λ=
∑ ∑
0 1 0 1
Q Q
q2 →q0 n
→q0 q1 n
q2 n
q1 q1 q1 y
q2 q2 n y
q2 q1
Transition Diagram:
1 C
q1 q2 q4
10 C
q2 q0 q3
101 A
q3 q2 q4
11 C
q4 q5 q4
110 B
q5 q0 q3
Transition diagram:
Mealy Machine:
State transition table δ= Output table λ=
∑ ∑
0 1 0 1
Q Q
→q0 q0 q1 →q0 C C
q1 q2 q4 q1 C C
q2 q0 q3 q2 C A
q3 q2 q4 q3 C C
q4 q5 q4 q4 B C
q5 q0 q3 q5 C A
Transition diagram:
4] Design Moore and Mealy machine for finding Residue mod 3 for binary numbers.
Solution:
May-14(CBGS)
Moore Machine: Let M=(Q,∑,∆,δ,λ ,q0) be the required machine.
∑={0,1}
∆={0,1,2}
When the number is divided by 3, the remainder is either 0 or 1 or 2.
For constructing DFA, string may have following four different possibilities:
1. Remainder is 0 (state q0)
2. Remainder is 1 (state q1)
3. Remainder is 2 (state q2)
Transition Diagram: Transition Table:
∑ o/p
Q 0 1
→q0 q0 q1 0
q1 q2 q0 1
q2 q1 q2 2
Mealy Machine:
State transition table δ= Output table λ=
∑ ∑
0 1 0 1
Q Q
→q0 q0 q1 →q0 0 1
q1 q2 q0 q1 2 0
q2 q1 q2 q2 1 2
Transition Diagram:
Moore machine:
As output to state q1 are different therefore this state is splitted as [q10] and [q11]
Transition diagram: Transition Table:
∑ o/p
Q 0 1
→q0 q0 q10 0
7] Design Moore and Mealy machine to convert each occurrence of “100” by”101”.
Solution:
Moore Machine: Let M=(Q,∑,∆,δ,λ ,q0) be the required machine.
∑={0,1}
∆={0,1}
Q={q0,q1,q2,q3}
Transition Table:
∑ o/p
0 1
Q
→q0 q0 q1 0
q1 q2 q1 1
q2 q3 q1 0
q3 q0 q1 1
Transition Diagram:
Mealy machine:
State transition table δ= Output table λ=
∑ ∑
0 1 0 1
Q Q
→q0 q0 q1 →q0 0 1
q1 q2 q1 q1 0 1
q2 q3 q1 q2 1 1
q3 q0 q1 q3 0 1
Transition Diagram:
1 q1 q2 q1 1
10 q2 q3 q1 0
100 q3 q4 q1 0
1000 q4 q0 q1 1
Transition Diagram:
2 q2 q0 q1 q2 2
12 q3 q4 q1 q2 2
120 q4 q0 q1 q2 2
Transition Diagram:
b q1 q0 q1 ɛ
aa q2 q0 q3 ɛ
aab q3 q0 q1 0
Transition Diagram:
Transition table:
State transition table δ=
∑
(0,0) (0,1) (1,0) (1,1)
Q
→q0 q0 q0 q0 q1
q1 q0 q1 q1 q1
Output table λ=
∑
(0,0) (0,1) (1,0) (1,1)
Q
→q0 0 1 1 0
q1 1 0 0 1
Transition Diagram:
12]Design Mealy machine to to o/p even and odd depending on the no of 1’s encountered
are Even and odd over Σ={0,1}
Solution: Let M=(Q,∑,∆,δ,λ ,q0) be the required machine.
∑={0,1}
∆={Even,odd}
Q={q0,q1}
Transition Diagram:
13] Design Mealy machine to change each occurrence of “abb” to “aba” over Σ={a,b}
Solution:Let M=(Q,∑,∆,δ,λ ,q0) be the required machine.
∑={a,b}
∆={a,b}
Q={q0,q1,q2,q3}
State transition table δ= Output table λ=
∑ ∑
a b a b
Q Q
→q0 q0 q2 →q0 a b
q1 q0 q1 q1 a b
q2 q0 q3 q2 a a
q3 q0 q1 q3 a b
Transition Diagram:
In above diagram we see all incoming transition to state q0 is ‘1’therefore output of q0 is ”1”
Similarly, output of q1 is ”0” and output of state q2 will be “1”.
Now, for q3 state incoming transitions have two different output symbols as “0” and”1”.
Therefore, we will split the state q3 as [q3 0] and [q3 1].The output of state [q3 0] will be “0”
and output of [q3 1] will be “1”.
May-2014(CBGS)
1 Differentiate between NFA and DFA. 05
2 Give applications of finite automata 02
3 Compare and contrast Mealy and Moore machine. Design Moore 10
machine to find residue modulo 3 for binary numbers
4 Construct NFA that accepts a set of all strings over {a, b} ending with 10
“abb”. Convert this NFA to equivalent DFA
Dec-2014(CBGS)
1 State and Prove Equivalence of NFA and DFA 05
2 Design DFA to accept the strings over Σ={a,b}that begins with’aa’ but 10
not ends with ‘aa’.
3 Design Moore and Mealy machine to Decrement a binary number 10
May-2014
1 Distinguish between NFA and DFA. 05
2 Design a DFA to check whether a given number is divisible by 4. 08
3 Define NDFA with an example. 02
4 Design Moore machine for the language (0+1)*(00+11) and convert it 10
to Mealy machine.
Dec-2014
1 Design a FSM that check if a given decimal no is even 05
2 What are the steps to convert Moore machine to Mealy machine. 10
Design Moore and Mealy machine to change each occurrence of 100 to
101
May-13
1 Differentiate between Moore and Mealy Machine with proper examples 10
and usage carry out conversions of Moore M/C to Mealy M/C
DEC-13
1 Define with examples Moore and Mealy Machine. 05
2 Design a finite state machine to determine whether a ternary number 10
with base 3 is divisibly by 5.
3 Design Mealy machine for the language (0+1)*(00+11) and convert it 10
to Moore machine.
4 Convert following NFA with epsilon moves to minimum state DFA 10
May-12
1 Compare and contrast Moore and Mealy Machine. 05
2 Convert following NFA to DFA. 10
DEC-12
1 Q. 1 What is a finite automaton? Give finite automata accepting 05
(a,b)*(baaa)
2 Design finite state machine to add 2 binary numbers of equal length. 10
3 Differentiate between Moore and Mealy Machine. 05
4 Write short note on applications of FA. 02
MAY-11
1 Differentiate between 10
1. NFA and DFA
2. Moore and Mealy Machine.
2 Find a minimum state finite automata equivalent to following automata- 10
0 1
→a b a
b a c
c d b
d* d a
e d f
f g e
g f g
h h d
3 Convert following NFA with epsilon moves to minimum state DFA 10
accepting the same language
t* ø ø
3 Obtain DFA to accept the strings which contains exctly three a’s over ∑ 8
={a, b}
4 Give Moore and Mealy machine to change each occurrence of substring 10
120 to 121 over ∑ ={0, 1, 2}
5 Minimize the following DFA 10
a b
→q0 q1 q3
q1 q0 q3
q2 q1 q4
q3* q5 q5
q4 q3 q3
q5* q5 q5
May-10
DEC-10
1 Design Moore and Mealy machine to change each occurrence of 10
substring abb to aba.
2 Design DFA to accept languages 10
Set of all strings with odd number of 1’s followed by even number of
0’s
Set of all strings which begin and end with different letters ∑ ={x, y, z}