0% found this document useful (0 votes)
23 views12 pages

Toc 2

Uploaded by

gebode6537
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views12 pages

Toc 2

Uploaded by

gebode6537
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Example: DFA

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’

Example: DFA Example: DFA


 w {a,b}* w {a,b}*
 L = {w; starts with a}
 L = {w; ends with a}
 Remember: Some trap/D state will be there for the
 Remember: if the sequence is spoiled, it will come back
strings starting with b
to some non-final state.
 Three states will be there, doesn't contains ‘a’; doesn’t  Two states
starts with ‘a’; starts with ’a’

Example: DFA Example: DFA


w {a,b}* w {a,b}*

 L = {w; |w| ≤ 2}  L = {w; |w| ≥ 2}


 L={aa, ab, ba, bb, aaa…bbb….}
 L={ε,a,b,aa,ab,ba,bb}
 (n+1) states will be there
 (n+2) states will be there
Example: DFA Example: DFA
w {a,b}* w {a,b}*
L={w ; |w| mod 3 = 0}
 L = {w; |w| ≥ 2}  (n+1) states will be there
 L = {w; |w| ≤ 2}  (n+2) states will be there
 L = {w; |w| = 2}  (n+2) states will be there

Example: DFA Example: |w| mod y = x


• What about the following: • What about the following:
• w {a,b}* • w {a,b}*

L={w ; |w| mod 3 = 1} L={w ; |w| mod y = x}


L={1,4,7,10,13,16,19,22,25,28,31,34,…..} Where ‘x’ is the remainder when |w| is divided by the number ‘y’.

Remember: the number of states will always be equal to ‘y’.


L={w ; |w| mod 3 = 2} Reason being the possible remainders will be {0 to y-1 }, making this
L={2,5,8,11,14,17,20,23,26,29,32…….....}
equal to y number of states i.e., one state for each remainder.

Example: DFA Example


w {a,b}* • What about the following:
• w {a,b}*
L={w ; na(w) = 2}
L={w ; na(w) ≤ 2}; (n+2) states

L={w ; na(w) ≥ 2}; (n+1) states


Example: Binary number Example: Binary number
w {0,1}* 0 1  w ∈ {0,1}*
L = { w | wb mod 4 = 0}  L = { w | wb mod 4 = 0}
*q0 q0 q1 q0 q1 q2 q3
 Is this language finite
q1 q2 q3 or infinite??

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…

Example: Binary number


What about the following: Example: Design a DFA for L(M2)
w {0,1}* ∑ = {0,1}
L(M2) = {w | w ends in 1}
L = { w | w mod 4 = 1}
First identify the strings in the set L(M2)
L = { w | w mod 4 = 2}  Write the smallest possible string of |w|=1

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

Example: Ternary number Example: (w)k mod m


What about the following:
w {0,1,2}* • Base k number {0,1,2,3……………(k-1)} mod m.

L = { w | w mod 4 = 1} • There will be k number of inputs and m number of states.

L = { w | w mod 4 = 2}

L = { w | w mod 4 = 3}

Example: Counting a’s, b’s Example: Cross product method


w {a,b}* L1: na(w) mod 2 = 0 L2: nb(w) mod 2 = 0
namod2=0 a b
*A B A
nbmod2=0 a b
L = { w | na(w) mod 2= 0 and nb(w) mod 2= 0} B A B *C C D
D D C
No. of states will be (m x n)
L1={na(w) mod 2= 0}; L2={nb(w) mod 2= 0}
L1: No. of States=?????
L a b
L1: No. of States=two namod2=0 a b nbmod2=0 a b *AC BC AD
L2: No. of states:????? *A
B
B
A
A
B
x *C
D
C
D
D
C
 AD BD AC
BC AC BD
L2: No. of States=two BD AD BC
Example: Counting a’s, b’s Example: Counting a’s, b’s
 Ea and Eb; Only one final state is there {ee}  Ea and Eb; Only one final state is there {ee}
 Ea or Eb; Three final states will be there {ee, eo, oe}
 Oa and Eb; Only one final state is there {oe}  Ea or Eb; Three final states will be there {ee, eo, oe}
 Ea and Ob; Only one final state is there {eo}
 Oa and Ob; Only one final state is there {oo}
 Oa or Ob; Three final state is there {oo,eo,oe}

Example: Counting a’s, b’s Example: Cross product method


w {a,b}* w {a,b}*
L = { w | na(w) mod 3= 0 and nb(w) mod 2= 0}
L = { w | na(w) mod 3= 0 and nb(w) mod 2= 0} No. of states (3x2)=6
No. of states (3x2)=6 L1: {na(w) mod 3= 0}; L2: {nb(w) mod 2= 0}
L1: {na(w) mod 3= 0}; L2: {nb(w) mod 2= 0} L1: {A,B,C}
L1: No. of States=????? L2: {D,E}
L1: No. of States=three L1xL2: {A,B,C}X{D,E} = {AD,AE,BD,BE,CD,CE}
L2: No. of states:?????
L2: No. of States=two

Example: Cross product method Example: Cross product method

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

Example: Cross product method Example: Counting a’s, b’s


na(w) mod 3= 0
Three states for mod3: 0 remainder, 1 remainder, 2 remainder

Even b’s
L a b
*AD BD AE
AE BE AD
BD CD BE
BE CE BD
CD AD CE
CE AE CD

Example: Counting a’s, b’s Example: Counting a’s, b’s


na(w) mod 3= 0 nb(w) mod 2= 0
Three states for mod3: 0 remainder, 1 remainder, 2 remainder Only Two states: 0 remainder and 1 remainder

odd b’s
Example: Counting a’s, b’s Example: Counting a’s, b’s
w {a,b}* w {a,b}*

L = { w | na(w)mod3=0 and nb(w)mod2=0}  L = { w | na(w)mod3 > nb(w) mod 2}


 |a1|/3 = a; |a2|/3 = aa; |a4|/3 |b4|/2 = ab0;
No. of states (3x2)=6
 L= {a1, a2, a4, a5, a7, aba, aabb≈aa, abbab≈aab,
bbbaa≈baa, bbaa≈aa……………………….}
L a b
AD(00) BD(10) AE(01)
Final states: {10, 20, 21} AE(01) BE(11) AD(00)
*BD(10) CD(20) BE(11)
BE(11) CE(21) BD(10)
*CD(20) AD(00) CE(21)
*CE(21) AE(01) CD(20)

Example: Counting a’s, b’s Example: Counting a’s, b’s


w {a,b}* w {a,b}*

L = { w | na(w)mod3 = nb(w) mod 2} L = { w | na(w)mod3 < nb(w) mod 2}

 L={ab, ba, aaa≈ε, bb≈ε, aaabb≈ε,…………….} L = {aaabbb≈b, aaba≈b…………}


L a b
L a b
AD(00) BD(10) AE(01)
Final States: {00, 11} *AD(00) BD(10) AE(01)
L ≠ {ab, aabb, aab, abb, abbb, } *AE(01) BE(11) AD(00)
AE(01) BE(11) AD(00)
BD(10) CD(20) BE(11)
BD(10) CD(20) BE(11)
BE(11) CE(21) BD(10)
*BE(11) CE(21) BD(10)
CD(20) AD(00) CE(21) Final States: {01} CD(20) AD(00) CE(21)
CE(21) AE(01) CD(20)
CE(21) AE(01) CD(20)

Example: Counting a’s, b’s Example: Counting a’s, b’s


w {a,b}* w {a,b}*
L = { w | na(w)mod3=0 and nb(w)mod2=1} L = { w | na(w)mod3=0 and nb(w)mod3=0}
L = { w | na(w)mod3=1 and nb(w)mod2=1} L = { w | na(w)mod3=1 and nb(w)mod3=0}
L = { w | na(w)mod3=2 and nb(w)mod2=1} L = { w | na(w)mod3=2 and nb(w)mod3=0}
L = { w | na(w)mod3=1 and nb(w)mod2=0} L = { w | na(w)mod3=0 and nb(w)mod3=1}
L = { w | na(w)mod3=2 and nb(w)mod2=0} L = { w | na(w)mod3=1 and nb(w)mod3=1}
L = { w | na(w)mod3 > nb(w)mod3} L = { w | na(w)mod3=2 and nb(w)mod3=1}
L = { w | na(w)mod3 = nb(w)mod3} L = { w | na(w)mod3=0 and nb(w)mod3=2}
L = { w | na(w)mod3 < nb(w)mod3} L = { w | na(w)mod3=1 and nb(w)mod3=2}
L = { w | na(w)mod3=2 and nb(w)mod3=2}
Example: DFA Example: DFA
Q. DFA that accepts all decimal nos. which are divisible by six. Q. DFA that accepts all decimal nos. which are divisible by six.
Give the following: Give the following:
 the input ∑  the input ∑
 no. of states in the DFA &  no. of states in the DFA &
 the final state  the final state

Sol. Input ∑ = ???? Transition Table:


 Input ∑ = {0,1,2,3,4,5,6,7,8,9} {0,1,2,3,4,5,6,7,8,9} i/p’s over {q0, q1, q2, q3, q4, q5} states makings
No. of states = ???? this total of ____________ cells or table entries.
 No. of states = {q0, q1, q2, q3, q4, q5} = Six
i.e. {0 to 5} x {0 to 9} = 60 cells or table entries
Final state = ???
 Final state = {initial state}

Example: DFA Example: binary nos. divisible either by two or three


Q. Design a DFA that accepts all binary nos. which are divisible No. of states = 2x3 = six = {q0, q1, q2, q3, q4, q5}
Either by two or three
By two but not by three
L1 = {no. divisible by two}
By three but not by two
L2 = {no. divisible by three}
Not by two or three

Sol. No. of states = ???

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}

L1 = {0, 2, 4, 6, 8, 10, 12, 14…………..} L1 = {0, 2, 4, 6, 8, 10, 12, 14…………..}


L2 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33,……..} L2 = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33,……..}

L= {0,2,3,4,6,8,9,10,12,14,15,18,21…………}

Final state/s: {no. divisible by two} U {no. divisible by three}


Final state/s: {q0, q2, q3, q4}
Example: binary nos. divisible either by two or three Example: binary nos. divisible either by two or three
L1 = {no. divisible by two} Final state/s: {no. divisible by two} U {no. divisible by three}
L2 = {no. divisible by three} Final state/s: {q0, q2, q3, q4}
L= {0,2,3,4,6,8,9,10,12,14,15,18,21…………} DFA: ????
L 0 1
0 1
0mod2 *AD AD BE
0
0mod3 1
Final state/s: {no. divisible by two} U {no. divisible by three} *AE AD BE
*A A B *D D E
Final state/s: {q0, q2, q3, q4} X  *BD CD AE
B C A E D E BE CD AE
C B C *CD BD CE
DFA: ???? CE BD CE

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}

Example: DFA Example: DFA


Q. Design a DFA that accepts all base four nos. which are divisible Q. Design a DFA that accepts all base four nos. which are divisible
by either by two or three but not by five. by either by two or three but not by five.

Sol. No. of states = ??? Sol. Set of Final states = ???


Input ∑ = ???
Input ∑ = {0,1,2,3} No. of states = 2x3x5 = thirty = {q0, q1, q2, q3, q4,q5………..q29}
No. of states = 2x3x5 = thirty = {q0, q1, q2, q3, q4,q5………..q29} L = {2,3,4,6,8,9,12,14,16,18,21,22,24,26,27,28,32………..}
L = {L1} U {L2} – {L3} F = {q2,q3,q4,q6,q8,q9,q12,q14,q16,q18,q21,q22,q24,q26,q27,q28}
L = {0,2,4,6,8…} U {0,3,6,9,12…..} – {0,5,10,15,20…..} sixteen final states in the set

L = {2,3,4,6,8,9,12,14,16,18,21,22,24,26,27,28,32………..}

Example: DFA Example: DFA


Q. Design a DFA that accepts all base four nos. which are divisible Q. Design a DFA that accepts all hexadecimal nos. which are
by either by two or three but not by five. divisible by three but not by five and seven.

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}

Example: DFA Example: DFA


L = { w | w contains ‘a’ as second symbol from LHS}

L = { w | anbmcl, n,m,l ≥ 0}
L = { w | w contains ‘a’ as third symbol from LHS}

L = { w | w contains ‘a’ as second symbol from RHS}

L = { w | anbmcl, n,m,l ≥ 1}

Example: DFA Complemented Finite Automata

w ∈ {a}; L = { w | an, n≥0, n≠3}


• By interchanging the final and non-final states
of the given FA we will get complemented FA
w ∈ {a}; L = { w | an, n≥0, n≠2, n≠4}
Complemented Finite Automata
• language of all strings over {0, 1} that do not contain a pair
Number of a‘s not divisible by three
of 1's that are separated by an odd number of 0's.

q0 q1 q2
q0 q1 q2

DFA Class Assignment-I


All strings that do not end with aa. 1) {w | w begins with 1 and ends with 0 } 9) {w | w every odd position of w is a
All strings that contain an even number of b’s. 2) {w l w contains at least three 1s} 1}
3) {w l w contains the substring 0101, i.e.,
All strings which do not contain the substring ba. w = xO1O1y for some x and y}
10) {w | w contains at least two 0’s and
at most one 1}
4) {w | w has length at least 3 and its
11) {epsilon, 0}
third symbol is 0}
12) {w | w contains an even number of
5) {w l w starts with 0 and has odd length,
or starts with 1 and has even length} 0’s, or contains exactly two 1’s}
6) {w | w doesn't contain the substring 13) The empty set
110} 14) All strings except the empty string
7) {w | w the length of w is at most 5}
8) {w l w is any string except 11 and 111}

DFA Class Assignment-I

In all parts I/p = {a, b}

15) {w | w has at least three a's and at least two b's}

Family of FA
16) {w | w has at exactly two a's and at least two b's}

17) {w l w has an even number of a's and one or two b's}

18) {w l w has an even number of a's and each a is followed by at least one b}

19) {w | w has an even number of a's and one or two b's}

20) {w | w has an odd number of a's and ends with a b}

21) {w | w has an even length and an odd number of a's} Submit by:

You might also like