ATC Class work
Finite Automata book by Padma Reddy
https://books.google.co.in/books?id=RSODknf4pyIC&pg=PA54&lpg=PA54&dq=dfa+fo
r+mod+5+padma+reddy&source=bl&ots=VosvkNYa80&sig=ACfU3U2HY3WKDCFAooO
N7tVU-
kKEcWEN7Q&hl=en&sa=X&ved=2ahUKEwiC2ufIzK7sAhUYxDgGHcD0B0UQ6AEwDHoE
CAEQAg#v=onepage&q=dfa%20for%20mod%205%20padma%20reddy&f=true
Construct DFA which accepts strings of 0s and 1s where the value of each string is
represented as a binary number. only string representing modulo 5 must be accepted,
example – 0000, 0101, 1010, 1111, etc
Construct a DFA to accept strings of even number of a’s and b’s. process the accepted
and rejected strings
ATC Class work
A = (Q, Ʃ , 𝞭, q0, F)
difference between FA’s – DFA, NFA, ∈- NFA
DFA NFA ∈- NFA
𝞭:Qx ƩQ 𝞭 : Q x Ʃ 2Q 𝞭 : Q x Ʃ U {∈} 2Q
𝞭 (q, a) = p 𝞭 (q, a) = { p, r } 𝞭 (q, a) = { p, r}
𝞭 (q, ∈) = { s }
Convert NFA to DFA using Subset construction method
1] Design a NFA for accepting strings of 0’s and 1’s ending with substring 01, and
Convert NFA to DFA using Subset construction method
L = {01, 010, 001, 010101, ……………}
L’ = {00, 11, 0100, 0011, 0100, ……………}
Transition table for NFA, 𝞭N
𝞭N 0 1
->q0 { q0, q1} { q0 }
q1 ɸ { q2 }
*q2 ɸ ɸ
Ʃ = {0,1} same for both NFA and DFA
States (Q) in the given NFA is, n in no., n =3, QN= {q0, q1, q2}
States in DFA is 2n , so no. of states in DFA is 23 = 8
QD = { ɸ, q0, q1, q2, {q0, q1}, {q0, q2}, {q1, q2}, {qo, q1, q2} }
Transition table for DFA, 𝞭D
𝞭D 0 1
ɸ ɸ ɸ
->q0 { q0, q1} { q0 }
q1 ɸ { q2 }
*q2 ɸ ɸ
{q0, q1} {q0, q1} {q0, q2}
*{q0, q2} {q0, q1} {q0}
*{q1, q2} ɸ {q2}
*{qo, q1, q2} {q0, q1} {q0, q2}
({q0, q1}, 0) = (q0, 0) U (q1, 0) = {q0, q1} U ɸ = {q0, q1}
({q0, q1}, 1) = (q0, 1) U (q1, 1) = {q0 } U {q2} = {q0, q2}
fig. DFA constructed as per TT
throw-away states like – {q1}, {q2}, {q1, q2}, {q0, q1, q2} as they are not reachable from initial state q0.
fig. DFA constructed from the NFA
now trace this DFA for strings acceptance and rejection ð (q0, 001), ð (q0, 0011)
2] Design a NFA for accepting strings of 0’s and 1’s where symbol 1 is present at the
second last position, and Convert NFA to DFA using Subset construction method
L = {011, 010, 0010, 01010, ……………}
L’ = {00, 101, 0100, 00101, 0100, ……………}
Transition table for NFA
𝞭 0 1
->q0 { q0} { q0, q1 }
q1 { q2} { q2 }
*q2 ɸ ɸ
Ʃ = {0,1} same for both NFA and DFA
States (Q) in the given NFA is, n in no., n =3, QN= {q0, q1, q2}
States in DFA is 2n , so no. of states in DFA is 23 = 8
QD = { ɸ, q0, q1, q2, {q0, q1}, {q0, q2}, {q1, q2}, {qo, q1, q2} }
Transition table for DFA, 𝞭D
𝞭D 0 1
ɸ ɸ ɸ
->q0 { q0} { q0, q1 }
q1 { q2} { q2 }
*q2 ɸ ɸ
{q0, q1} {q0, q2} {q0, q1, q2}
*{q0, q2} {q0} {q0, q1}
*{q1, q2} {q2} {q2}
*{qo, q1, q2} {q0, q2} {q0, q1, q2}
({q0, q1}, 0) = (q0, 0) U (q1, 0) = {q0} U {q2} = {q0, q2}
({q0, q1}, 1) = (q0, 1) U (q1, 1) = {q0, q1 } U {q2} = {q0, q1, q2}
fig. DFA constructed as per TT
Throw-away states like – {q1}, {q2}, {q1, q2}, as they are not reachable from initial state q0.
fig. DFA constructed from the NFA
now trace this DFA for strings acceptance and rejection ð (q0, 001), ð (q0, 0011)
3] Convert to DFA the following NFA
𝞭 0 1
->p { p, q} {p}
q ɸ {r}
*r {p, r} {q}
ATC Class work
1] Design a NFA for accepting strings of 0’s and 1’s where symbol 1 is present at the
second last position, Ʃ ={0,1}
L = {011, 010, 0010, 01010, ……………}
L’ = {00, 101, 0100, 00101, 0100, ……………}
Transition table for NFA
𝞭 0 1
->q0 { q0} { q0, q1 }
q1 { q2} { q2 }
*q2 ɸ ɸ
2] Design a NFA for accepting strings of 0’s and 1’s ending with substring 01, Ʃ ={0,1}
DFA designed for the same problem statement
compare the design and list the features of NFA and DFA
Definition of NFA (NFSM)
M = ( Q, Ʃ, q0, 𝞭, F)
5 tuples
Q – set of states {q0, q1, q2 }
Ʃ = {0, 1}
q0 – initial state
F – set of final states, qf- final state (q2)
𝞭 – transition function 𝞭 (q, a) = {p , r}
’s return value is 0, 1,or more sates
𝞭 (state, input symbol) = subset of states
NFA example.
L = {01, 010, 001, 010101, ……………}
L’ = {00, 11, 0100, 0011, 0100, ……………}
Transition table for NFA
𝞭 0 1
->q0 { q0, q1} { q0 }
q1 ɸ { q2 }
*q2 ɸ ɸ
Processing of String - string (w) is accepted / rejected
ð – Extended transition function , arguments and return value are
ð (q, w) = {p, r},
ð (state, string) = subset of states
eg. check string 001 is accepted or rejected by the above NFA
ð (q0, 001) = ð ( 𝞭 (q0, 0), 01)
= ð ( ( {q0, q1} , 0), 01)
= ð ( (𝞭 ( q0, 0) U 𝞭 ( q1, 0) ), 01)
= ð ( (𝞭 ( {q0, q1} U ɸ ), 01)
= ð ( (𝞭 ({q0, q1}, 0 ), 1 )
= ð ( (𝞭 ( q0, 0) U 𝞭 ( q1, 0) ), 1)
= ð ( (𝞭 ( {q0, q1} U ɸ ), 1)
= ð ( (𝞭 ( {q0, q1} , 1)
= ð ( (𝞭 ( q0, 1) U 𝞭 ( q1, 1) ), ∈)
= {q0, q2}
= q2 is a final state
is {q0, q2} final state or nonfinal state
q2 is a final state , hence string ‘001 ‘ is accepted
ATC Class work
Solve the following:
1. Design a FSM to accept the strings of a’s and b’s starting with substring ab, the
language is with alphabet Ʃ = {a, b}, show the acceptance and rejection for strs.
L= {ab, ababaa, abb, abaaaaaaaaba…….} RL
L’ = { ba, aa, bb, bab, a, bba, aaab, ………..}
M – FA, Transition diagram of M
DFA
𝞭 – transition function 𝞭 (q, a) = p p - final or non final state
𝞭 (state, input symbol) = state
Processing of String - string (w) is accepted / rejected
ð – Extended transition function , ð (q, w) = p, arguments and return value are
ð (state, string) = state
eg. ð (q0, abb) = ð ( 𝞭 (q0, a), bb)
= ð ( (q1, b), b)
= ð ( (q2, b), ∈)
= q2
is q2 final state or nonfinal state
q2 is final state , hence string ‘abb ‘ is accepted
ð (q0, bab) = ð ( 𝞭 (q0, b), ab)
= ð ( (q3, a), b)
= ð ( (q3, b), ∈) = q3
is q3 final state or nonfinal state
q3 is nonfinal state , hence string ‘bab ‘ is rejected
𝞭 a b
->q0 q1 q3
q1 q3 q2
*q2 q2 q2
q3 q3 q3
Transition table
Transitions
(q1, a) = q3, 𝞭 (q1, b) = q2, (q2, a) = q2, 𝞭 (q2, b) = q2, (q3, a) = q3,…..
2. Design a DFSM (DFA ) to accept the language L = { awa : w ∈ {a, b}*}
L= {aa, aaa, aba, ababaa, abbbba, abaaaabbbaaaaba…….}
L’ = { ba, aab, bb, baba, bba, aaab, ………..}
Design a NFSM /NFA to accept strings of a’s and b’s ending with substring ab or ba
L= {ab, ba, abab, ababa, abbbab, abaaabba…….}
L’ = { ba, aab, bb, baba, bba, aaab, ………..}
3. Design a FSM to accept strings of 1’s and 0’s, that begins or ends or both with
substring 01
4. Design a FSM to accept strings of 0’s, 1’s and 2’s, beginning with a ‘0’, followed by
odd number of 1’s and ending with a ‘2’. the language is with alphabet Ʃ = {0, 1, 2}
Assignment questions
Solve the following: design and solution discussed in the class
1. Design a FSM (FA ) to accept the strings with substring of three consecutive 0’s of the
language with alphabet Ʃ = {0, 1}
L = { 000, 1000, 0001, 10000, 00011, 00010101000, ……..
L’ = {010, 101, 110, 0101, 0, 1, 01, 1011, 0011, 10011, ………. }
2. Design a FSM (FA ) to accept the language with strings of a’s and b’s having four a’s,
language with alphabet Ʃ = {a, b}
L ={ aaaa, bababaa, ababbbaa,
3. Design a FSM (FA ) to accept the language L = { w : na(w) <= 3, w ∈ {a, b}*}
L = {a, aa, aaa, ba, abb, abaa, ababa, …………}
4. Design a FSM (FA ) to accept the strings of a’s and b’s that do not have substring aba
of the language with alphabet Ʃ = {a, b}
L = { a, b, aa, aaabbb, abbb, abbabba, babba, abbbab, …………}
L’= { aba, ababa, ……………. }
5. Design a FSM (FA ) to accept the language L = { wbab / w ∈ {a, b}*}
L = {bab, abab, bbab, babbab, abbbabbab,
==========================================================
Design a FSM (FA ) to accept the strings with substring 010 of the language with
alphabet Ʃ = {0, 1}
L = { 010, 0100, 1010, 0011010, ……………………}
L’ = {000, 001, 010, 011 …. 110, 111, 0111110}
Design a FSM (FA ) to accept the strings of a’s and b’s ending with substring aab of the
language with alphabet Ʃ = {a, b}
L = { aab, baab, aaab, ababaab, …………….
L’ = ( aaa, aba, bab bba, aaaaba)
Design a FSM (FA ) to accept the strings of a’s and b’s do not ending with substring abb
of the language with alphabet Ʃ = {a, b}
L = { aaa, bbb,aba, bab, bba, babbab, abbaab, ababb, …………….
processing/ tracing the string for acceptance or rejection:
a b b a a
q0 q1 q2 q3 q1 q2
q2 is a final state so str abbaa is accepted
q3 is a nonfinal state so str abbaabb is rejected