Lecture 5
Lecture 5
Chapter-2
contents
When n is exactly 2
a,b
When n is exactly 3
a,b
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..
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
When n is at most 3
a,b
a,b
ɸ
b a a,b
Ending with ‘a’
Start a
S0 S1
b
Contd..
Start a
S0 S1
b
b
a,b
Contd..
Start a
S0 S1
b a b
ɸ S2
a,b
b
Contd..
a b
Start a b
S0 S1 S2
a
b
a,b
Try!!!
1 equivalence
2 equivalence
3 equivalence
0 1
→{q0 ,q4} {q1, q7} {q3, q5}
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…
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
ae ae bh c
1 0
bh 0
df 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?