0% found this document useful (0 votes)
0 views43 pages

Lecture 5

The document discusses the design and minimization of Deterministic Finite Automata (DFA) with various examples, including DFAs that accept strings of exact, at least, and at most lengths. It also covers the concept of state equivalence and the Myhill-Nerode theorem for DFA minimization. Additionally, it provides methods for drawing DFAs and minimizing them using the table-filling method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views43 pages

Lecture 5

The document discusses the design and minimization of Deterministic Finite Automata (DFA) with various examples, including DFAs that accept strings of exact, at least, and at most lengths. It also covers the concept of state equivalence and the Myhill-Nerode theorem for DFA minimization. Additionally, it provides methods for drawing DFAs and minimizing them using the table-filling method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Finite automata

Chapter-2
contents

 Examples of DFA design


 DFA minimization
Examples of DFA
 Example 1: Design a DFA to accept strings over Ʃ={a,b} with length exactly n.

 When n is exactly 2
a,b

Start a,b a,b


S0 a,b S1 S2 ɸ

 When n is exactly 3
a,b

Start a,b a,b


S0 a,b S1 a,b S2 S3 ɸ
Contd..

 For exactly 2, Total number of states= 4, that is 2+2.


 That is 2+2, where the first 2 is the length of the strings and the last 2 for
empty string and dead state.
 For exactly 3, total number of states=5, that is 3+2
 Therefore, for exactly n, the total number of states will be n+2.

a,b

Start a,b a,b a,b


S0 a,b S1 a,b S2 … Sn ɸ
Examples of DFA
 Example 2: Design a DFA to accept strings over Ʃ={a,b} with length at least n.

 When n is at least 2 a,b

Start a,b
S0 a,b S1 S2

 When n is exactly 3
a,b

Start a,b
S0 a,b S1 a,b S2 S3
Contd..

 For at least 2, Total number of states= 3, that is 2+1.


 That is 2+2, where the first 2 is the length of the strings and 1 is for empty
string.
 For at least 3, total number of states=4, that is 3+1
 Therefore, for at least n, the total number of states will be n+1.
a,b

Start a,b
S0 S1 S2 … a,b Sn
a,b a,b
Examples of DFA
 Example 3: Design a DFA to accept strings over Ʃ={a,b} with length at most n.

 When n is at most 2
a,b

Start a,b a,b


S0 a,b S1 S2 ɸ

 When n is at most 3
a,b

Start a,b a,b


S0 a,b S1 a,b S2 S3 ɸ
Contd..

 For at most 2, Total number of states= 4, that is 2+2.


 That is 2+2, where the first 2 is the length of the strings and the last 2 for
empty string and dead state.
 For at most 3, total number of states=5, that is 3+2
 Therefore, for at most n, the total number of states will be n+2.

a,b

Start a,b a,b a,b


S0 a,b S1 a,b S2 … Sn ɸ
Examples of DFA
 Example 4: Design a DFA to accept strings over Ʃ={a,b}.
a,b
 Starting with ‘a’
Start a
S0 S1
b

ɸ

b a a,b
Ending with ‘a’
Start a
S0 S1
b
Contd..

 Starting & Ending with ‘a’

Start a
S0 S1
b
b

a,b
Contd..

 Starting & Ending with ‘a’

Start a
S0 S1

b a b

ɸ S2

a,b
b
Contd..

 Starting with ‘a’ & Ending with ‘b’

a b

Start a b
S0 S1 S2
a
b

a,b
Try!!!

 Draw a DFA that accepts equal number of ab and ba over Ʃ= {a,b}.


 Draw a DFA for the set of all strings ending in 010 over Ʃ= {0,1}.
 Draw a DFA for the set of all strings ending in acb over Ʃ= {a,b,c}.
 Draw a DFA for the set of all strings starting with b and ending with c over Ʃ= {a,b,c}.
 Draw a DFA for the set of all strings with two consecutive 0’s followed by two consecutive
1’s over Ʃ= {0,1}
DFA Minimization

 Minimization of DFA is required to obtain the minimal version of any DFA


which consists of the minimum number of states possible.
 Two states ‘A’ and ‘B’ are said to be equivalent if
 δ(A,X)=F and δ(B,X)=F, or, δ(A,X) ≠ F and δ(B,X) ≠ F; where ‘X’ is any input string
 If |X|=0, then A and B are said to be 0 equivalent
 If |X|=1, then A and B are said to be 1 equivalent
 If |X|=2, then A and B are said to be 2 equivalent
 ….
 If |X|=n, then A and B are said to be n equivalent
Contd…
Equivalence Theorem-Example 1

 Using equivalence theorem, we have


 0 equivalence

 1 equivalence

 2 equivalence

 3 equivalence

 Since P3=P2, we stop.


Contd…
Equivalence Theorem-Example 2
 Using equivalence theorem, we have 0 1
 0 equivalence →q0 q1 q5
P0={q0, q1, q3, q4, q5, q6, q7} {q2} q1 q6 q2
 1 equivalence *q2 q0 q2
P1={q0, q4, q6} { q1, q7} {q3, q5} {q2} q3 q2 q6
 2 equivalence q4 q7 q5
P2={q0, q4} {q6} { q1, q7} {q3, q5} {q2} q5 q2 q6
 3 equivalence q6 q6 q4
P3={q0, q4} {q6} { q1, q7} {q3, q5} {q2} q7 q6 q2
 Since P3=P2, we stop.
Contd…

0 1
→{q0 ,q4} {q1, q7} {q3, q5}

{q6} {q6} {q0 ,q4}


{q1, q7} {q6} {q2}
{q3, q5} {q2} {q6}
*{q2} {q0 ,q4} {q2}
Equivalence Theorem-Example 3
(More than one final states)
 Using equivalence theorem, we have
 0 equivalence
P0={a, b, f} {c, d, e}
 1 equivalence
P1={a, b} {f} {c, d, e}
 2 equivalence
0 1
P2={a, b} {f} {c, d, e}
→a b c
 Since P2=P1, we stop.
b a d
0 1
*c e f
→{a,b} {a,b} {c,d,e
*d e f
}
{f} {f} {f} *e e f

*{c,d,e {c,d,e {f} f f f


Equivalence Theorem – Example 4
When there are unreachable states involved

 A state is said to be unreachable if there is no way it can be reached


from the initial state.

0 1
→A B C
*B D E
*C E D
D G G
E G G
F D E Unreachable
*G G G state
Contd…
0 1
 Using equivalence theorem, we have
→A B C
 0 equivalence
*B D E
P0={A,D,E} {B,C,G}
*C E D
 1 equivalence
D G G
P1= {A,D,E} {B,C}{G}
E G G
 2 equivalence
*G G G
P2={A} {D,E} {B,C} {G}
 3 equivalence 0 1
P3={A} {D,E} {B,C} {G} →{A} {B,C} {B,C}
 Since P3=P2, we stop. {D,E} {G} {G}
*{B,C {D,E} {D,E}
}
*{G} {G} {G}
Myhill-Nerode Theorem (Table-Filling
Method)
 Input: DFA
 Output: Minimized DFA
 Steps:
1. Draw a table for all pairs of states (P,Q)
2. Mark all pairs where P ∈ F and Q ∉ F
3. If there are any unmarked pairs (P,Q) such that [δ(P,x),δ(Q,x)] is marked,
then mark [P,Q] where ‘x’ is an input symbol
Repeat this until no more markings can be made
4. Combine all the unmarked pairs and make them a single state in the
minimized DFA.
Table-Filling Method-Example 1
Contd…

 Step-1: Create the pairs of all the states involved in DFA.


 Step 2: Mark all pairs where P ∈ F and Q ∉ F
Contd…
 Step 3: If there are any unmarked pairs (P,Q) such that [δ(P,x),δ(Q,x)] is
marked, then mark [P,Q] where ‘x’ is an input symbol
Repeat this until no more markings can be made
Contd…

 Continued Step 3.
Contd…

 Continued Step 3.
Contd…

 Step 4: Combine all the unmarked pairs and make them a single state
in the minimized DFA.
Table Filling Method- Example 2

0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
1. Initialize table entries:
Unmarked, empty list f

a b c d e f g
Contd…

0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
2. Mark pairs of final &
nonfinal states f

a b c d e f g
Contd…

0 1

0 1 0
a b c d d(b,0) ? d(a,0)
0 1 b
1 d(b,1) ? d(a,1)
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
Contd…

0 1

0 1 0
a b c d g ? b Maybe.
0 1 b
1 c ? f No!
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
Contd…
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
Contd…
0 1

0 1 0
a b c d d(e,0) ? d(a,0)
0 1 b
1 d(e,1) ? d(a,1)
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

a b c d e f g
Contd…

0 1

0 1 0
a b c d h ? b Maybe.
0 1 b
1 f ? f Yes.
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f

h
(a,e)
a b c d e f g
Contd…

0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

g
(g,a)

h
(a,e)
a b c d e f g
Contd…

0 1

0 1 0
a b c d b Need to mark.
1 0 1
0 1 So, mark (g,a) also.
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

g
(g,a)

h
(a,e)
a b c d e f g
Contd…

0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
3. For each unmarked
pair & symbol, … f
(g,a)

h
(a,e)
a b c d e f g
Contd…

0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
4. Combine all unmarked
pairs of states. f
0 1

0 1 g
ae ae bh c
1 0
bh 0
df 1 h
df g (a,e)
1
0 a b c d e f g
Contd…
0 1

0 1 0
a b c d b
1 0 1
0 1
1 1 0
e f g h c
1 0

0
d

e
5. Delete unreachable
states. f
0 1

0 1 g
ae bh c
1 0
None. 0
1 h
f g (a,e)
1
0 a b c d e f g
Questions?

You might also like