0% found this document useful (0 votes)
13 views

3-Finite Automata

The document provides an overview of finite automata, detailing their structure, types (deterministic and non-deterministic), and functions such as string acceptance and rejection. It includes examples of deterministic finite acceptors (DFA) and their transition diagrams, illustrating how to design DFAs for various languages and conditions. Additionally, it discusses regular languages and provides examples of DFAs for specific language criteria, including divisibility by numbers and string patterns.
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)
13 views

3-Finite Automata

The document provides an overview of finite automata, detailing their structure, types (deterministic and non-deterministic), and functions such as string acceptance and rejection. It includes examples of deterministic finite acceptors (DFA) and their transition diagrams, illustrating how to design DFAs for various languages and conditions. Additionally, it discusses regular languages and provides examples of DFAs for specific language criteria, including divisibility by numbers and string patterns.
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/ 33

Finite Automata

Automata
• An automaton is an abstract model of a digital computer
• It has a mechanism for reading input from the input file
• It can produce output of some form
• It may have a temporary storage device, consisting of an unlimited number of cells, each
capable of holding a single symbol from an alphabet
• The automaton can read and change the contents of the storage cells.
• The automaton has a control unit, which can be in any one of a finite number of internal
states, and which can change state in some defined manner.
• An automaton whose output response is limited to a simple “yes” or “no” is called an
accepter.
• Presented with an input string, an accepter either accepts the string or rejects it.
• A more general automaton, capable of producing strings of symbols as output, is called a
transducer.
Automata
Finite Automata

Deterministic Non-
Finite Acceptor Deterministic
Finite Acceptor
Deterministic Finite Acceptor
DFA Example
String Acceptance or Rejection
• Check if 1001 belongs to the language generated by the automata

To solve this, remember the extended transition function ẟ*

(i.e.)
String Acceptance or Rejection

Check if 1001 belongs to the language generated by the automata

ẟ*(q0,1001)
=ẟ(ẟ*(q0, 100),1)
= ẟ(ẟ(ẟ*(q0,10), 0), 1)
= ẟ(ẟ(ẟ(ẟ*(q0,1), 0), 0), 1)
= ẟ(ẟ(ẟ(ẟ(ẟ*(q0,λ), 1), 0), 0), 1)
= ẟ(ẟ(ẟ(ẟ(q0, 1), 0), 0), 1)
= ẟ(ẟ(ẟ(q1, 0), 0), 1)
= ẟ(ẟ(q0, 0), 1)
= ẟ(q0, 1)
= q1 ∈ F q1 is a final state. Hence the string is accepted.
String Acceptance or Rejection

Check if 1011 belongs to the language generated by the automata


ẟ*(q0,1011)
=ẟ(ẟ*(q0, 101),1)
= ẟ(ẟ(ẟ*(q0,10), 1), 1)
= ẟ(ẟ(ẟ(ẟ*(q0,1), 0), 1), 1)
= ẟ(ẟ(ẟ(ẟ(ẟ*(q0,λ), 1), 0), 1), 1)
= ẟ(ẟ(ẟ(ẟ(q0, 1), 0), 1), 1)
= ẟ(ẟ(ẟ(q1, 0), 1), 1)
= ẟ(ẟ(q0, 1), 1)
= ẟ(q1, 1)
= q2 ∉ F q2 is a non-final state. Hence the string is rejected.
Language accepted by DFA
• The language accepted by a dfa M = (Q,Σ, δ, q0, F) is the set
of all strings on Σ accepted by M. In formal notation,

• The language rejected by a dfa M = (Q,Σ, δ, q0, F) is the set of all


strings on Σ rejected by M.
Regular Language
• A language L is called regular if and only if there exists some
deterministic finite accepter M such that
L = L(M)
(i.e.) if there exists a valid DFA
Representing DFA – Example 1
• Find a deterministic finite accepter that recognizes the set of all
strings on Σ = {a, b} starting with the prefix ab.
Language accepted {ab, aba, abb, abaa, ababab, …..}

a,b
a b
q0 q1 q2

b a
qt
a,b
Transition Diagram and Transition Table
a
b
a b
q0 q1 q2

b a
qt
States a b
a
b -> q0 q1 qt
M=({q0, q1, q2, qt}, {a, b}, ẟ, q0, {q2})
where ẟ is given as q1 qt q2
ẟ(q0,a)=q1 ẟ(q0,b)=qt
ẟ(q1,a)=qt ẟ(q1,b)=q2 * q2 q2 q2
ẟ(q2,a)=q2 ẟ(q2,b)=q2
ẟ(qt,a)=qt ẟ(qt,b)=qt qt qt qt
Example 2
• Design a DFA that starts with any number of a’s followed by the string
ba and ending with one or more a’s or b’s.
Language accepted {baa, abab, ababbb, abaaaa, ababab, …..}
a, b
a
b a a, b States a b
q0 q1 q2 q3
-> q0 q0 q1
b
q1 q2 qt
qt q2 q3 q3
a, b
* q3 q3 q3

qt qt qt
Example 3
• Draw the DFA to accept all strings on ∑ = {a, b} that ends with abb.
Language accepted {abb, ababb, abbabb, abbaabb, abababb, …..}

b
a

a b b
q0 q1 q2 q3

a
a

b
Example 4
• Show that 𝐿 = 𝑎𝑤𝑎 𝑤 ∈ 𝑎, 𝑏 ∗ } is regular.
Language accepted { aa, aabaa, abbba, aaaaa, ababababaa …..}

b a
a a
q0 q1 q2

b
b
qt
a, b
Example 5 Example 6
• All the strings on ∑ = {a, b} with • All the strings on ∑ = {a, b} with
exactly one a. atleast one a.
b b a, b
b a, b

a a
q0 q1 qt a
q0 q1
Example 7 Example 8
• All the strings on ∑ = {a, b} • All the strings on ∑ = {a, b} with
with no more than three a’s. atleast three a’s.
b b b
b b b

a a
a a q0 q1 q2
q0 q1 q2
a
a
a, b q3
b q3

a, b qt
Example 9 & 10
• DFA for 𝐿 = 𝑤 𝑤 ∈ 𝑎, 𝑏 and 𝑤 𝑚𝑜𝑑 5 ≠ 0}
a, b

a, b a, b a, b a, b
q0 q1 q2 q3 q4

• DFA for 𝐿 = 𝑤 𝑤 ∈ 𝑎, 𝑏 and 𝑛𝑎 𝑤 𝑚𝑜𝑑 3 > 1}


b b b

a a
q0 q1 q2

a
Example 11 & 12
• Show that 𝐿 = 𝑎𝑛 𝑛 ≥ 4 is regular on ∑={a}.
a

a a a a
q0 q1 q2 q3 q4

• Show that 𝐿 = 𝑎𝑛 𝑛 ≥ 0 and 𝑛 ≠ 4 is regular on ∑={a}.


a

a a a a a
q0 q1 q2 q3 q4 q5
Example 13
• DFA with condition left most symbol differs from right most symbol
on ∑={0, 1}
0 1
1
q1 q2
0
0
q0 1 0

1 0
q3 q4

1
Example 14
• Find a dfa that accepts all the strings on {0, 1}, except those containing
the substring 001.
1 0, 1

0 0 1
q0 q1 q2 q3

1 0
Runs – Example 15
• A run in a string is a substring of length atleast 2, as long as possible
and consisting entirely of same symbol.
• Example: Design a DFA for L={w | every run of a’s has length either 2
or 3} on ∑={a, b}

a, b
b

a a a a
q0 q1 q2 q3 qt
b
b
b
Example 16
• L={w | w has no runs of length less than 4} on ∑={a, b}
Modulo Problems – Example 1
• L={w | na(w)mod 2=0 and nb(w) mod 2=0} (i.e.) na(w) and nb(w) are
both even.
Language accepted {λ, abab, ababbb, abbabb, ababaa, abababba, …..}

a
00 a 10

b b b b
a

01 11
a
Example 2
• L={w | na(w) mod 3 >= nb(w) mod 2}
a a
00 10 20

b b b b b b

a a
01 11 21

a
Division by K problems
• Draw a DFA to accept the binary strings divisible by 5.
∑={0, 1}
ẟ(qi, d) = qj
j=((r*i)+d) mod k
where r is the radix (ex: decimal, binary..}
i is the current state from the set of states
d is the set of digits
k is the division factor
Example 1
• Draw a DFA to accept the binary strings divisible by 5.
∑={0, 1} i d j ẟ
d={0, 1} 0 0 0 ẟ(q0, 0) = q0
1 1 ẟ(q0, 1) = q1
k=5
1 0 2 ẟ(q1, 0) = q2
i = 0 to k-1 1 3 ẟ(q1, 1) = q3
r=2 2 0 4 ẟ(q2, 0) = q4
j=((r*i)+d) mod k 1 0 ẟ(q2, 1) = q0
3 0 1 ẟ(q3, 0) = q1
1 2 ẟ(q3, 1) = q2
4 0 3 ẟ(q4, 0) = q3
1 4 ẟ(q4, 1) = q4

Example 1 ẟ(q0, 0) = q0
ẟ(q0, 1) = q1
• Draw a DFA to accept the binary strings divisible by 5. ẟ(q1, 0) = q2
1
ẟ(q1, 1) = q3
0
ẟ(q2, 0) = q4
0
1 q1
q2
ẟ(q2, 1) = q0
q0
ẟ(q3, 0) = q1
0 1 1 0 ẟ(q3, 1) = q2
1
ẟ(q4, 0) = q3
ẟ(q4, 1) = q4
q3 0 q4
Example 2
• Obtain a DFA that accepts set of all strings when interpreted in
reverse as a binary string is divisible by 5
∑={0, 1} 1

d={0, 1} 0
0
k=5 1 q 1 q2
q0
i = 0 to k-1
1 0 1 0
r=2
1
j=((r*i)+d) mod k
q3 0 q4
Example 3
• DFA to accept the decimal strings divisible by 3.
Example strings: 393, 915, 7254 are accepted
Example strings: 593, 785, 9346 are rejected
d={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} It could be noted that, digits,
0, 3, 6, 9 mod 3 is 0
k=3
1, 4, 7 mod 3 is 1
i = 0 to k-1 2, 5, 8 mod 3 is 2
r=10 Hence digits can be grouped as
D1={0, 3, 6, 9}
j=((r*i)+d) mod k D ={1, 4, 7}
2
D3={2, 5, 8}
Example 3
• Draw a DFA to accept the binary strings divisible by 3.
j=((r*i)+d) mod k
i d j ẟ
r=10
D1 0 ẟ(q0, D1) = q0
k=3 0 D2 1 ẟ(q0, D2) = q1
• D1={0, 3, 6, 9} D3 2 ẟ(q0, D3) = q2
• D2={1, 4, 7} D1 1 ẟ(q1, D1) = q1
1 D2 2 ẟ(q1, D2) = q2
• D3={2, 5, 8} D3 0 ẟ(q1, D3) = q0
D1 2 ẟ(q2, D1) = q2
2 D2 0 ẟ(q2, D2) = q0
D3 1 ẟ(q2, D3) = q1
Example 3

• Draw a DFA to accept the binary strings divisible by 3. ẟ(q0, D1) = q0
ẟ(q0, D2) = q1
D1 ẟ(q0, D3) = q2
D1
D2 ẟ(q1, D1) = q1
q1 ẟ(q1, D2) = q2
q0 D1={0, 3, 6, 9} ẟ(q1, D3) = q0
D3
D2={1, 4, 7}
D2 D3
D3={2, 5, 8} ẟ(q2, D1) = q2
D3 ẟ(q2, D2) = q0
D2
ẟ(q2, D3) = q1
q2

D1
Example strings: 393, 915, 7254 are accepted
Example strings: 593, 785, 9346 are rejected
Exercises
1. L={aw1aaw2a : w1, w2 ∈ {a, b}*}
2. L={w1abbw2 : w1, w2 ∈ {a, b}*}
3. L={ban : n ≥ 1, n ≠ 4}
4. L={w | na(w) mod 3 = 0 and nb(w) mod 2 = 0}
5. L={w | na(w) mod 4 < nb(w) mod 6}
6. L={w | na(w) mod 2 <= nb(w) mod 4}
7. L = {w : there are exactly two runs of a’s of length 3} on {a, b}}
8. All strings on {0, 1} where the leftmost two symbols and the rightmost
two symbols are identical
9. All strings with atleast one b and exactly two a’s on {a, b}
10. All strings that contain substring 000, but not 0000 on {0,1}

You might also like