Toc 2
Toc 2
DFA w {a,b}*
L = {w; w contains a}
Construction {b} L
Only two states will be there, one contains ‘a’, the
other state doesn’t contains ‘a’
q0 q1 q2 q3 q2 q0 q1
??
Infinite R=0 R=1 R=2 R=3
q3 q2 q3 0000 0001 0010 0011
0100 0101 0110 0111
R=0 R=1 R=2 R=3 1000 1001 1010 1011
1100… 1101…. 1110… 1111…
L = { w | w mod 4 = 3}
Example: Design a DFA for L(M1) Example: Design a DFA for L(M3)
∑ = {0,1} ∑ = {0,1}
L(M1) = {w |w contains at least one 1 and an even L(M3) = {wl w is the empty string ɛ or ends in 0}
number of 0’s follow the last 1}
First identify the strings in the set L(M1) First identify the strings in the set L(M3)
Write the smallest possible string of |w|=1 Write the smallest possible string of |w|=1
Every string in the set satisfy both the conditions L={ɛ,0,000,10,010………}
Example: Ternary number Example: Ternary number
• (10)3 = 1x3+0=3 3n 33 32 31 30
L = { w | wt mod 4 = 0} 0 1 2
27 9 3 1 *q0 q0 q1 q2
w {0,1,2}*
q1 q3 q0 q1
• (20)3= 2x3+0=6
2 0 6 q2 q2 q3 q0
0 2 2 q3 q1 q2 q3
• (102)3= (10)3x3 + 2 = 3x3+2 = 11 1 1 2 14
2 2 2 26
• (201)3 = (20)3x3 +1 = 6x3+1 = 19 1 2 2 17
0 0 2 2 q0 q1 q2 q3
• (11)3 = 4 2 0 0 18
1 2 0 15
L = { w | w mod 4 = 2}
L = { w | w mod 4 = 3}
a b a b L a b a b a b L a b
*A B A *D D E *AD BD AE *A B A *D D E *AD BD AE
B C B E E D AE BE AD B C B E E D AE BE AD
C A C C A C BD CD BE
BE CE BD
Example: Cross product method Example: Cross product method
a b L a b L a b
a b
*A B A *AD BD AE *AD BD AE
*D D E
B C B AE BE AD AE BE AD
E E D
C A C BD CD BE BD CD BE
BE CE BD BE CE BD
CD AD CE CD AD CE
CE AE CD CE AE CD
Even b’s
L a b
*AD BD AE
AE BE AD
BD CD BE
BE CE BD
CD AD CE
CE AE CD
odd b’s
Example: Counting a’s, b’s Example: Counting a’s, b’s
w {a,b}* w {a,b}*
No. of states = 2x3 = six = {q0, q1, q2, q3, q4, q5}
Example: binary nos. divisible either by two or three Example: binary nos. divisible either by two or three
L1 = {no. divisible by two} L1 = {no. divisible by two}
L2 = {no. divisible by three} L2 = {no. divisible by three}
L= {0,2,3,4,6,8,9,10,12,14,15,18,21…………}
Example: binary nos. divisible by two but not by three Example: binary nos. divisible by two but not by three
L1 = {no. divisible by two} Final state/s: {q2, q4}
L2 = {no. divisible by three} DFA: ????
L 0 1
L1 = {0, 2, 4, 6, 8, 10, 12, 14…………..} AD BE
0
0mod3 1 0 1
0mod2 AD
L2 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33,……..} X AE AD BE
*A A B *D D E
L= L1-L2 = {2,4,8,10,14,…………} *BD CD AE
B C A E D E BE CD AE
C B C *CD BD CE
Final state/s: {Q-{q0,q1,q3,q5}} CE BD CE
Final state/s: {q2, q4}
Example: binary nos. divisible by three but not by two Example: binary nos. divisible by three but not by two
L1 = {no. divisible by two} Final state/s: {q3}
L2 = {no. divisible by three} DFA: ????
L 0 1
L1 = {0, 2, 4, 6, 8, 10, 12, 14…………..} AD BE
0 1
0mod3 0 1
0mod2 AD
L2 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33,……..} X *AE AD BE
*A A B *D D E
L= L2-L1 = {3,6,9,12,15,18,21,…………} BD CD AE
B C A E D E BE CD AE
C B C CD BD CE
Final state/s: {Q-{q0,q1,q2,q4,q5}} CE BD CE
Final state/s: {q3}
Example: binary nos. divisible not by two or three Example: binary nos. divisible not by two or three
L1 = {no. divisible by two} Final state/s: {q1,q5}
L2 = {no. divisible by three} DFA: ????
L 0 1
L1 = {0, 2, 4, 6, 8, 10, 12, 14…………..} AD BE
0
0mod3 1 0 1
0mod2 AD
L2 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33,……..} X AE AD BE
*A A B *D D E
L= {1,5,7,11,13,17,19,23,25,29,31,35,………..} BD CD AE
B C A E D E *BE CD AE
C B C CD BD CE
Final state/s: {Q-{q0,q2,q3,q4}} *CE BD CE
Final state/s: {q1,q5}
L = {2,3,4,6,8,9,12,14,16,18,21,22,24,26,27,28,32………..}
0
w4mod3=0
1 2 3
w mod5=0
0 1
4
2 3
w mod2=0
4
0 1 2 3 Sol. No. of states = ???
*A A B C A *F F G H I
Input ∑ = ???
X *D D E D E X G J F G H
B B C A B E D E D E Input ∑ = {0,1,2,3………15}
C C A B C H I J F G
No. of states = 3x5x7 = 105= {q0, q1, q2, q3, q4,q5………..q104}
I H I J F
L = {0,3,6,9,12…..} – {0,35,70,105,…..}
J G H I J
L = {3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51………..}
Example: DFA Example: DFA
What about the following:
w ∈ {a,b}
L = { w | anbm, n,m ≥ 1}
L = { w | w containing ba}
L = { w | anbm, n,m ≥ 0}
L = { w | w containing ba} (hint: complement of above lang.)
L = { w | anbmcl, n,m,l ≥ 1}
L = { w | anbmcl, n,m,l ≥ 0}
L = { w | w contains ‘a’ as second symbol from LHS}
L = { w | anbm, n,m ≥ 0}
L = { w | w contains ‘a’ as second symbol from RHS}
L = { w | w contains ‘a’ as third symbol from LHS}
w ∈ {a}; L = { w | an, n≥0, n≠3}
L = { w | anbm, n,m ≥ 1}
w ∈ {a}; L = { w | an, n≥0, n≠2, n≠4}
L = { w | anbmcl, n,m,l ≥ 0}
L = { w | w contains ‘a’ as third symbol from LHS}
L = { w | anbmcl, n,m,l ≥ 1}
q0 q1 q2
q0 q1 q2
Family of FA
16) {w | w has at exactly two a's and at least two b's}
18) {w l w has an even number of a's and each a is followed by at least one b}
21) {w | w has an even length and an odd number of a's} Submit by: