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, Equivalence of
Moore and Mealy machine: Conversion of Moore machine to Mealy machine, Conversion of
Mealy machine to Moore machine, application of FA.
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&[Link] 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’
Formal definition:
M= (Q, ∑, δ, q0, F)
where ,
Q: finite set of states
∑: finite set of input symbols
δ: transition function as, Q X ∑Q
q0: initial state q0 Q
F: finite set of final states
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
b q1 q0 q3
aa
q2* q2 q1
bb q3* q0 q3
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, ….}
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
yy q4 q3 q4 q5 q3
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)
17] Design DFA to accept the strings over Σ={a,b}that begins with’aa’ but not ends with
‘aa’.
Solution: Let M= (Q, ∑, δ, q0, F)
∑ = { a,b }
The language accepted by this DFA over alphabet, ∑ = {a,b } is
L = {aab,aaba,aabb ……….}
Transition diagram:
Transition table:
18] Design finite state machine to add 2 binary numbers of equal length./To implement
binary adder.
Solution:
I={ (0,0)(0,1)(1,0)(1,1) }
O={0,1}
S={q0,q1}
STF is given as,
∑
(0,0) (0,1) (1,0) (1,1)
Q
q0 q0 q0 q0 q1
q1 q0 q1 q1 q1
∑
(0,0) (0,1) (1,0) (1,1)
Q
q0 0 1 1 0
q1 1 0 0 1
Transition diagram:
Solution:
Soluion:
Solution:
q0* q0 q1 q2
q1 q1 q2 q0
q2 q2 q0 q1
Transition Diagram:
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
Transition Diagram:
Simulation:
Let L=2102
= δ (q0, 2102)
= δ (q2,102)
= δ (q2, 02)
= δ (q1, 2)
= q0 (Accept)
Transition Table:
∑
Q 0
q0* q1
q1 q2
q2 q0
Example:
Transition Diagram: Transition table:
∑
0 1
Q
qA qA qB
qB ϕ {qB,qC}
qC* qB qA
In above diagram or from transition table we see that there are from qB to 1 transition goes to
two different states.
Difference between DFA and NFA
DFA NFA
It is deterministic It is non-deterministic
For each state for given input symbol For each state for given input symbol
there is only one transition. there can be 0,1 or more transition.
Example Example
Example 1: Consider NFA as M=({q0,q1}, {0,1}, δ, q0, {q1})into equivalent DFA, where
δ is given by,
∑
0 1
Q
q1 * ϕ {q0,q1}
Solution:
1. As, δ(q0,0)={q0,q1} -------New state
δ(q0,1)={q1}
2. δ({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)= ϕ
δ(q1,1)= {q0,q1}----already exists
3. Here no new state is generated so we will stop here. Here ‘q1’ is final state so every
combination with state’q1’ will become final state. The transition table is shown below.
∑
0 1
Q
q0 {q0,q1} {q1}
q1* ϕ {q0,q1}
∑
0 1
Q
q1 * {q1} {q1}
q2 ϕ {q1,q2}
Solution:
1. As, δ(q0,0)={q0,q1} -------New state
δ(q0,1)={q2}
2. δ({q0,q1},0)= δ(q0,0) U δ(q1,0)={q0,q1}U ϕ = {q0,q1}
δ({q0,q1},1)= δ(q0,1) U δ(q1,1)={q2}U {q1}= {q2,q1}-------New state
3. δ({q2,q1},0)= {q1}
δ({q2,q1},1)={q1,q2}
4. δ(q1, 0)= {q1}
δ(q1,1)= {q1}
δ(q2, 0)= ϕ
δ(q2,1)= {q1,q2}
q2 ϕ {q1,q2}
DFA minimization:
The DFA can be minimized if it consists of equivalent states. If their both transition are
equivalent then that state can be merged. The rules for the minimization are:
1. Initial state cannot be replaced by any other state.
2. Replace one final state by its equivalent final state only.
3. Replace one non-final state by its equivalent non-final state only.
Example : Convert following NFA to equivalent DFA
M=({p,q,r,s}, {0,1}, δ, p, {s}) δ is given in following table
∑
0 1
Q
p {p,q} p
q r r
r s ϕ
s* s s
Solution:
1. δ(p,0)={p, q} -----New state
δ(p,1)=p
2. δ({p,q},0) = {p,q,r}-----New state
δ({p,q},1) ={p,r}-----New state
3. δ({p,q,r},0) = {p,q,r,s}-----New state
δ({p,q,r},1) = {p,r}
4. δ({p, r},0) = {p,q,s}-----New state
δ({p, r},1) = {p}
5. δ({p,q,r,s},0) = {p,q,r,s}
δ({p,q,r,s},1) = {p,r,s}-----New state
6. δ({p,q,s},0) = {p,q,r,s}
δ({p,q,s},1) = {p,r,s}
7. δ({p,r,s},0) = {p,q,s}
δ({p,r,s},1) = {p,s}-----New state
8. δ({p, s},0) = {p,q,s}
δ({p, s},1) = {p,s}
The transition table is:
∑
0 1
Q
p {p,q} p
q r r
r s ϕ
s* s s
{p,q} {p,q,r} {p,r}
{p,q,r} {p,q,r,s} {p,r}
{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}
∑
0 1
Q
p {p,q} p
q r r
r s ϕ
s* s s
{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}
{p,q,s} {p,s} Resultant table is:
∑
0 1
Q
A p {p,q} p
B q r r
C r s ϕ
D s* s s
E {p,q} {p,q,r} {p,r}
F {p,q,r} {p,s} {p,r}
G {p,r} {p,s} p
H {p,s}* {p,s} {p,s}
∑
0 1
Q
p {p,q} p
q {r, s} t
r {p,r} t
s* ϕ ϕ
t* ϕ ϕ
Solution:
1. δ({p,q},0) = {p,q,r,s}------New state
δ({p,q},1) = {p,t}-----New state
2. δ({r,s},0) = {p,r}-----New state
δ({r,s},1) = {t}-----New state
3. δ({p,q,r,s},0) = {p,q,r,s}
δ({p,q,r,s},1) = {p,t}
4. δ({p, t},0) = {p, q}
δ({p, t},1) = {p}
5. δ({p,r},0) = {p,q,r}----New state
δ({p,r},1) ={p,t}
6. δ({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* ϕ ϕ
t* ϕ ϕ
{r,s}* {p,r} t
{p,t} {p,q} p
∑
0 1
Q
p {p,q} p
q r t
r {p,r} t
s* ϕ ϕ
t* ϕ ϕ
{p,t} {p,q} p
p {q,r} q
q* r {q,r}
r s p
s* ϕ p
Solution:
1. δ(p,0)={q, r} -------New state
δ(p,1)=q
2. δ({q,r},0) = {r,s}-------New state
δ({q,r},1) ={p,q,r}-------New state
3. δ(q,0)={r}
δ(q,1)={q, r}
4. δ({r,s},0) = {s}
δ({r,s},1) = {p}
5. δ({p,q,r},0) = {q,r,s}-------New state
δ({p,q,r},1) = {p,q,r}
6. δ(r,0)={s} δ(r,1)={p}
7. δ({q,r,s},0) = {r,s}
δ({q,r,s},1) = {p,q,r}
8. δ(s,0)= ϕ δ(s,1)={p}
The transition table for DFA is given in figure
∑
0 1
Q
p {q,r} q
q* r {q,r}
r s p
s* ϕ p
{r,s}* s p
∑
0 1
Q
p {q,r} q
q* r {q,r}
r s p
s* Φ p
∑
ε a b c
Q
p Φ p q r
q p q r Φ
r* q r Φ P
Solution:
1. ε-closure of p={p}
ε-closure of q={p, q}
ε-closure of r={p, q, r}
2. δ({p}, a)= ε-closure { δ (ε-closure p),a}={p p }={p}
δ({p}, b)= ε-closure { δ (ε-closure p),b}={p q }={p q}
δ({p}, c)= ε-closure { δ (ε-closure p),c}={p r }={p r}
3. δ({q}, a)= ε-closure { δ (ε-closure q),a}
= ε-closure (δ {p q},a)
={pq}
δ({q}, b)= ε-closure { δ (ε-closure q),b}
= ε-closure (δ {pq},b)
={pqr]
δ({q}, c)= ε-closure { δ (ε-closure q),c}
= ε-closure (δ {pq},c)
={pqr}
4. δ({r}, a)= ε-closure { δ (ε-closure r),a}
= ε-closure (δ {pqr},a)
={p qr}
δ({r}, b)= ε-closure { δ (ε-closure r),b}
= ε-closure (δ {pqr},b)
={pqr}
δ({r}, c)= ε-closure { δ (ε-closure r),c}
= ε-closure (δ {pqr},c)
={pqr}
Following table shows NFA without ε moves.
∑
a b c
Q
p p pq pqr
q pq pqr r
If we have to convert into equivalent DFA then use the NFA to DFA conversion method.
∑
ε a b c
Q
p {q,r} Φ q r
q Φ p r {p,q}
r* Φ Φ Φ Φ
Solution:
1. ε-closure of p={p, q, r}
ε-closure of q={q}
ε-closure of r={r}
2. δ({p}, a)= ε-closure { δ (ε-closure p),a}
= ε-closure (δ {pqr},a)
= ε-closure (Φ p Φ)
={pqr}
δ({p}, b)= ε-closure { δ (ε-closure p),b}
= ε-closure (δ {pqr},b)
= ε-closure (q r Φ) ={qr}
δ({p}, c)= ε-closure { δ (ε-closure p),c}
= ε-closure (δ {pqr},c)
= ε-closure (r pq Φ)
={pqr}
3. δ({q}, a)= ε-closure { δ (ε-closure q),a}
= ε-closure (δ { q},a)
= ε-closure (p)
={pqr}
δ({q}, b)= ε-closure { δ (ε-closure q),b}=
= ε-closure (δ {q},b)
= ε-closure (r)
={r}
δ({q}, c)= ε-closure { δ (ε-closure q),c}
= ε-closure (δ {q},b)
= ε-closure (pq)
={pqr}
4. δ({r}, a)= ε-closure { δ (ε-closure r),a}
= ε-closure (δ {r}a)
=Φ
δ({r}, b)= ε-closure { δ (ε-closure r),b}
= ε-closure (δ {r},b)
=Φ
δ({r}, c)= ε-closure { δ (ε-closure r),c}
= ε-closure (δ {r},c)
=Φ
Following table shows NFA without ε moves.
∑
a b c
Q
p pqr qr pqr
q pq r pqr
Φ Φ Φ
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
For (E, C) pair, there is already ‘X’ in table so put ‘X’ in (G, H) column.
Next take the pair (F, H)
δ(F,0) =C
δ(H,0) =G
For (C, G) pair, one is final state and other is non final so put ‘X’ in table
Next take the pair (F, G)
δ(F,0) =C
δ(G,0) =G
For (C, G) pair, one is final state and other is non final so put ‘X’ in table
The above procedure is repeated for remaining pair.
For (D, F) pair
δ(D,0) = δ(F,0) =C
δ(D,1)= δ(F,1)=G
As both transitions are equal put ‘√’.
Similarly ,
δ(B,0) = δ(H,0) =G
δ(B,1)= δ(H,1)=C
As both transitions are equal put ‘√’.
For (A, E) pair
δ(A,1) = δ(E,1) =F
δ(A,0)=B and δ(E,1)=H
As, for (B, H) pair we have already marked as equivalent pair so put ‘√’ for (A, E) pair.
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, so 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
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.
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:
State transition Diagram: Transition Table:
∑
0 1 o/p
Q
qA qA qB a
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)
Q : Finite set of states
∑: Input alphabet
∆:Output alphabet
δ: State transition function Q X ∑ Q
λ: Machine function/Output Function Q X ∑ ∆
q0: initial state
Example:
qC qB b a
qB qB
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}
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 q1 1 0
q1 q1
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
q0 q1 q2 q0 n n
q2 q1 y n
q1 q1
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)
∑ 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:
Dec-14(CBGS)
Theory of computation
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:
∑ 0 1 o/p
Q
0 q0 q0 q1 0
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:
Q={q0,q1}
q0 which gives no carry, q1 which gives carry
In qo state In q1 state
0+0 =0 no carry 0+0+carry=1 no carry
0+1=1 no carry 0+1+carry=0 carry
1+0=1 no carry 1+0+carry=0 carry
1+1=0 carry 1+1+carry=1 carry
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”.
In above diagram we see all incoming transition to state q1 is ‘n’ therefore output of q1 is ”n”
Similarly, output of q2 is ”y” and output of state q0 will be “either n or y ”.
Now, for q3 state incoming transitions have two different output symbols as “n” and”y”.
Therefore, we will split the state q3 as [q3n] and [q3y].similarly for q4 it is[q4n] and [q4y].
It is the base for the formal languages and these formal languages are useful of the
programming languages.
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.
May-12
1 Compare and contrast Moore and Mealy Machine. 05
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 Design Mealy machine for the language (0+1)*(00+11) and convert it 10
to Moore machine.
4 Design DFAto accept following languages over Σ={0,1} 10
L={w|w starts with 0 and has odd length and start with 1 has even
length}
L={Every odd position of w is 1}
DEC-11
1 Design finite state machine to accept exactly two strings baa and ab. 5
2 Convert the following NFA to DFA 5
∑
0 1
Q
p {p,q} p
q {r, s} t
R {p,r} t
s* ø ø
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
1 Define DFA and state applications of Finite Automata in brief. 05
2 Obtain DFA to accept strings of a’s and b’s with even no of a’s and 10
even no of b’s.
3 Give Mealy and Moore machine for input from ∑={0,1} if theinput 10
ends in 101, output should be x, if input ends in 110 and output should
be y, otherwise output should be z.
4 Minimize the following DFA, where q0 is start state and q3 and q5 are 10
final states
a b
q0 q1 q3
q1 q0 q3
q2 q1 q4
q3* q5 q5
q4 q3 q3
q5* q5 q5
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}