Professional Documents
Culture Documents
2
Lecture 4
FA
FA Without
FA With Output
Output
• The transitions are deterministic i.e. there should be only one state to which
we can transit from current state on each input. Thus the automata cannot be
in more than one state at any time
• The transitions are non deterministic so the automata can be in more than one
state at any time
▪ Input =∑ ={0, 1}
▪ Language
L= {000, 111, 101, 001, 110, 011, 010…………..}
▪ Possible States :
qs 🡪 length is 0
q0 🡪 length is 1
q1 🡪 length is 2
q2 🡪 length is 3
q3 🡪 length is greater than 3
▪ Q= {qs, q0, q1 ,q2 , q3}
∑
0 1
Q
-->qs (len=0) q0 q0
q0 (len=1) q1 q1
q1 (len=2) q2 q2
q2* (len=3) q3 q3
q3 (len>3) q3 q3
11 Lecture 4: DFA Design
Transition Diagram
Simulation: Simulation:
(qs, 001) (qs, 1011)
(q0,01) (q0,011)
(q1,1) (q1,11)
(q2,ε) (q2,1)
Accept (q3,ε)
Reject
▪ Input =∑ ={0, 1}
▪ Language
L= {0, 011, 110, 00011, 10100, 0011011..............}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 odd 0 and even 1
q1 🡪 even 0 and odd 1
q2 🡪 even 0 and even 1
q3 🡪 odd 0 and odd 1
▪ Q= {qs, q0, q1 ,q2, q3 }
State/ Input 0 1
--> qs q0 q1
q1 (even, odd) q3 q2
q2 (even, even) q0 q1
q3 (odd, odd) q1 q0
State/ Input 0 1
String = 10100
(qs,10100) --> qs q0 q1
(q1, 0100)
(q3, 100)
q0* (odd, even) q2 q3
(q0, 00)
(q2, 0)
q1 (even, odd) q3 q2
(q0,ε)
q2 (even, even) q0 q1
Accept
q3 (odd, odd) q1 q0
▪ Input =∑ ={a, b}
▪ Language
L= {baa, abaa,abbaa,aabaab....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ba’
q3 🡪 substring as ‘baa’
▪ Q= {qs, q0, q1 ,q2, q3 }
▪ Input =∑ ={a, b}
▪ Language
L= {aba, aaba,aabab,aabab....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ab’
q3 🡪 substring as ‘aba’
▪ Q= {qs, q0, q1 ,q2, q3 }
State/ Input a b
🡪qs q0 q1
q0 q0 q2
q1 q0 q1
q2 q3 q1
q3* q3 q3
STF
Consider string= bbaa
State/ Input a b
-(qs, bbaa)
-(q1, baa) 🡪qs q0 q1
-(q1, aa) q0 q0 q2
-(q0,a) q1 q0 q1
-(q0, ε) q2 q3 q1
q3* q3 q3
No/Reject
▪ Input =∑ ={a, b}
▪ Language
L= {baa, abaa,abbaa,aabaa....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ba’
q3 🡪 substring as ‘baa’
▪ Q= {qs, q0, q1 ,q2, q3 }
▪ Input =∑ ={a, b}
▪ Language
L= {abab, aabab,aabab,baaabab....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ab’
q3 🡪 substring as ‘aba’
q4 🡪 substring as ‘abab’
▪ Q= {qs, q0, q1 ,q2, q3, q4 }
State/ Input a b
🡪qs q0 q1
q0 q0 q2
q1 q0 q1
q2 q3 q1
q3 q0 q4
q4* q3 q1
▪ Input =∑ ={a, b}
▪ Language
L= {a, bba, bb, bbab,aa, ab, aba..............}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring “a”
q1 🡪 substring “b”
q2 🡪 substring “bb”
qϕ 🡪 substring “bbb
▪ Q= {qs, q0, q1 ,q2, qϕ }
String 1= abbab
(qs,abbab) State/ a b
(q0, bbab) Input
(q1, bab) --> qs q0 q1
(q2,ab)
(q0, b)
q0* (a) q0 q1
(q1,ε)
Accept
String 2= abbba q1* (b) q0 q2
(qs,abbba)
(q0, bbba) q2* (bb) q0 qϕ
(q1, bba)
(q2,ba) qϕ (bbb) qϕ qϕ
(qϕ , a)
(qϕ ,ε)
Reject
qϕ
▪ Input =∑ ={a, b}
▪ Language
L= {abb, abbaa, abbab, ...................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘ab’
q2 🡪 substring as ‘abb’
qr 🡪 reject state starts with ‘b’
If no matching substring found for any state then transit to reject state
q0 (a) qr q1 aa ab
qɸ
▪ Input =∑ ={a, b}
▪ Language
L= {abb, abbaa, abbab, ba, baa, bab,...................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘ab’
q2 🡪 substring as ‘b’
q3 🡪 substring as ‘ba’
qr🡪 reject state
If no matching substring found for any state then transit to reject state
q0 (a) qr q1 aa ab
State/ Input a b
Consider string= abba
-(qs, abba)
🡪qs (ε) q0 q2
-(q0, bba)
-(q1, ba)
-(q1, a) q0 (a) qr q1
-(q1, ε)
Yes q1 * (ab) q1 q1
• Equivalent states:
• States are equivalent to each other if they have same transition for
the particular input.
• Equivalent states
{q1, q2}
• IF q1 and q2 are equivalent then
Delete entry for q2 from the transition table
In this modified table ,replace each occurrence of q2 by q1
State\ a b
State\ a b
Input
Input
--> q1 q1 q2
-->q1 q1
q2 q1
q2 q1 q2
q3 * q2 q1 q3
q3* q2 q3
• Equivalent states
{q1, q2}
• IF q1 and q2 are equivalent then
Delete entry for q2 from the transition table
In this modified table ,replace each occurrence of q2 by q1
State\ a b
State\ a b
Input
Input
--> q1 q1 q2
-->q1 q1 q1
q2 q1 q2
q3 * q1 q3
q3* q2 q3
q4 q1 q3
q4 q2 q3
Not Equivalent
• Equivalent states
{q2, q4}
• IF q2 and q4 are equivalent then
Delete entry for q4 from the transition table
In this modified table ,replace each occurrence of q4 by q2
State\ a b State\ a b
Input Input
--> q1 q3 q2
-->q1 q3 q2
q2 q3 q4
q2 q3 q2
q3* q2 q1 q3* q2 q1
q4 q3 q4
• Equivalent states
{q1, q2}
• IF q1 and q2 are equivalent then
Delete entry for q2 from the transition table
In this modified table ,replace each occurrence of q2 by q1
State\ a b
State\ a b
Input
Input
-->q1 q3 q2
-->q1 q3 q1
q2 q3 q2
q3* q1 q1
q3* q2 q1
State\ 0 1 State\ 0 1
Input Input
🡪p x y 🡪p x y
q r q q r q
r s p r s p
s * s p s * s p
t r q t r q
x* t z x* t z
y r q y r q
z* t z z* t z
• Non-determinism
Given a current state of the machine and input symbol to be read, the next
state is not uniquely determined.
• NFA consist of finite set of states, one state is called start state and there
can be one/more final states.
• In NFA, from each state on each I/P symbol there can be 0,1 or more
transition.
q0 ∈ Q is start state
• It becomes some times simpler to draw NFA for a particular problem than
drawing a DFA.
• E.g. Strings ending in 10
• The NFA is
• If any one path leads to accepting state and entire input is consumed then
machine accepts the string.
• NFA has same capacity as DFA.
• It just adds simplicity to DFA.
State\ 0 1
Stat 0 1 Input
e\
Inpu 🡪p q q
t q p q, r
🡪p q q q, r p, s p, q, r
q* p q,r p, s p, q p,q
r s p p,q,r p,q,s p,q,r
s * p p p,q p,q q,r
δ ({ q,r}, 0)= δ (q, 0) U δ (r, 0)= p,q,s p,q p,q,r
{p} U {s}= {p,s}
• The original final state remains final in the converted DFA and also the states in which
original state is combined becomes final state
State\ 0 1
Input
🡪p q q
q* p q, r
q, r* p, s p, q, r
p, s* p, q p,q
p,q,r* p,q,s p,q,r
p,q* p,q q,r
p,q,s* p,q p,q,r
0 1 0 1
🡪p p,q p 🡪p p,q p
p, q p, q, r p, r
q r r
p,q,r p,q,r,s p,r
r s -
p, r p,q,s p
s * s s
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
▪ Input =∑ ={0, 1}
▪ Language
L= {000, 111, 101, 001, 110, 011., 0011, 1100, 000111..................}
▪ Possible States :
qs 🡪 length is 0
q0 🡪 length is 1
q1 🡪 length is 2
q2 🡪 length is equal or greater than 3
69 Practice Problems
Transition Table
∑
0 1
Q
-->qs (len=0) q0 q0
q0 (len=1) q1 q1
q1 (len=2) q2 q2
q2* (len=3) q2 q2
70 Practice Problems
Transition Diagram
Simulation: Simulation:
(qs, 001) (qs, 1011)
(q0,01) (q0,011)
(q1,1) (q1,11)
(q2,ε) (q2,1)
Accept (q2,ε)
Accept
71 Practice Problems
Example 11: Design DFA which accepts string with length at-most three over
∑ ={0,1}
▪ Input =∑ ={0, 1}
▪ Language
L= {0, 1, 00, 10, 000, 111, 101, 001, 110, 011...................}
▪ Possible States :
qs 🡪 length is 0
q0 🡪 length is 1
q1 🡪 length is 2
q2 🡪 length is 3
q3 🡪 length is greater than 3
▪ Q= {qs, q0, q1 ,q2 , q3}
72 Practice Problems
Transition Table
∑
0 1
Q
-->qs (len=0) q0 q0
q0 * (len=1) q1 q1
q1 * (len=2) q2 q2
q2* (len=3) q3 q3
q3 (len>3) q3 q3
73 Practice Problems
Transition Diagram
Simulation: Simulation:
(qs, 01) (qs, 1011)
(q0,01) (q0,011)
(q1,ε) (q1,11)
Accept (q2,1)
(q3,ε)
Reject
74 Practice Problems
Example 12. Design a DFA which accepts strings containing odd number of a’s and
any number of b’s over ∑ = { a, b }
▪ Input =∑ ={a, b}
▪ Language
L= {a, ab, ba, abaa, aaab,bab,ababba....................}
▪ Possible States :
qs 🡪 not even or not odd
q0 🡪 odd number of ‘a’s and any number of ‘b’s
q1 🡪 even number of ‘a’s and any number of ‘b’s
Q= {qs, q0, q1}
75 Practice Problems
Transition Table
State/ Input a b
--> qs q0 q1
q0 * (odd ‘a’) q1 q0
q1 (even ‘a’) q0 q1
76 Practice Problems
Transition Diagram
77 Practice Problems
Simulation
String = bbabaa
State/ a b
(qs,bbabaa)
Input
(q1,babaa)
(q1,abaa) --> qs q0 q2
(q0,baa)
(q0,aa) q0* q1 q0
(q1,a)
(q0,ε) q1 q0 q1
Accept
78 Practice Problems
Example 13: Design DFA that accepts string containing “ab” as a substring over ∑
={a,b}
▪ Input =∑ ={a, b}
▪ Language
L= {ab, aab,bab,aabb....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ab’
▪ Q= {qs, q0, q1 ,q2 }
79 Practice Problems
Transition Table
80 Practice Problems
Transition Diagram
81 Practice Problems
Simulation
82 Practice Problems
Example 14: Design DFA that accepts strings starting with “ba” over ∑ ={a,b}
▪ Input =∑ ={a, b}
▪ Language
L= {ba, baa, bab,babaa....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘b’
q1 🡪 substring as ‘ba’
qr🡪 reject state starts with ‘a’
83 Practice Problems
Transition Table
If no matching substring found for any state then transit to reject state
STF
State/ Input a b Processing
q0 (b) q1 qr ba bb
84 Practice Problems
Transition Diagram
qɸ
85 Practice Problems
Simulation
86 Practice Problems
Example 15: Design DFA that accepts strings ending with “ab” over ∑ ={a,b}
▪ Input =∑ ={a, b}
▪ Language
L= {ab, aab,bab,abab....................}
▪ Possible States :
qs 🡪 no symbol accepting
q0 🡪 substring as ‘a’
q1 🡪 substring as ‘b’
q2 🡪 substring as ‘ab’
▪ Q= {qs, q0, q1 ,q2 }
87 Practice Problems
Transition Table
STF delete possible prefix and apply for final state also
State/ Input a b Processing
🡪qs (ε) q0 q1 ε.a ε.b
q0 (a) q0 q2 a. a a. b
q1 (b) q0 q1 b. a b. b
q2* (ab) q0 q1 a b. a abb
88 Practice Problems
Transition Diagram
89 Practice Problems
Simulation
90 Practice Problems
Example 16:
Q. Consider given transition diagram and convert that to minimized DFA.
Transition Table :
a b
🡪 q0 {q0, q1} q0
q1 - {q1, q2}
q2* {q2, q3} q3
q3 q3 -
91 Practice Problems
Example 16 : (cont..)
Converted DFA :
NFA DFA
a b a b
🡪 q0 {q0, q0 🡪 q0 {q0, q1} q0
q1}
{q0,q1} {q0, q1} {q0,q1, q2}
q1 - {q1,
q2} {q0,q1,q2}* {q0,q1,q2, {q0,q1,q2,
q2* {q2, q3} q3 q3} q3}
{q0,q1,q2,q {q0,q1,q2,q {q0,q1,q2,
q3 q3 - 3}* 3} q3}
92 Practice Problems
Example 16 : (cont..)
Equivalent States: a b
🡪 q0 {q0, q1} q0
{q0,q1} {q0, q1} {q0,q1, q2}
{q0,q1,q2}* {q0,q1,q2, {q0,q1,q2,
q3} q3}
{q0,q1,q2,q {q0,q1,q2,q {q0,q1,q2,
Minimized DFA:
3}* 3} q3}
a b
🡪 q0 {q0, q1} q0
{q0,q1} {q0, q1} {q0,q1, q2}
{q0,q1,q2}* {q0,q1,q2}* {q0,q1,q2}
*
93 Practice Problems
Example 17:Convert Given NFA to Minimized DFA
NFA DFA
a b
a b
🡪 q0 {q0, q1} q1
🡪 q0 { q0, q1
q1} q1* q2 q2
q1* q2 q2 {q0, q1}* {q0, q1, {q1, q2}
q2}
q2 q0 q2
q2 q0 q2
{q1, q2}* {q0, q2} q2
{q0, q2} {q0, q1} {q1, q2}
{q0, q1, {q0, q1, {q1, q2}
q2}* q2}
94 Practice Problems
Example 17: (cont..)
Minimized DFA:
a b
🡪 q0 {q0, q1} q1
q1* q2 q2
{q0, q1}* {q0, q1} {q1, q2}
q2 q0 q2
{q1, q2}* {q0, q2} q2
{q0, q2} {q0, q1} {q1, q2}
95 Practice Problems
Thank You