Download presentation
Presentation is loading. Please wait.
Published byGrant Chapman Modified over 5 years ago
1
DFA minimization The Chinese University of Hong Kong Fall 2011
CSCI 3130: Automata theory and formal languages DFA minimization Andrej Bogdanov
2
Example L = {w: w ends in 111} Isn’t there a smaller one?
3
Smaller DFA L = {w: w ends in 111} Can we do it with 3 states? 1 q0 q1
1 q0 q1 q2 q3 1 Can we do it with 3 states?
4
Even smaller DFA? L = {w: w ends in 111}
Suppose we had a 3 state DFA for L There are 4 inputs but 3 states On two of these inputs M ends in the same state M inputs: e, 1, 11, 111
5
Pigeonhole principle Suppose you are tossing 4 balls into 3 bins. Then two balls end up in the same bin. Take 4 inputs and feed them into a 3 state DFA. Then two inputs end up in the same state.
6
✘ A smaller DFA L = {w: w ends in 111}
Suppose inputs x = 1, y = 11 lead to same state Then after reading one more 1 The state of x1 = 11 should be rejecting The state of y1 = 111 should be accepting M 1, 11 inputs: 1 e, 1, 11, 111 11, 111 “ends in 111” ✘
7
✘ A smaller DFA L = {w: w ends in 111}
Suppose inputs x = e, y = 1 lead to same state Then after reading 11 The state of x1 = 11 should be rejecting The state of y1 = 111 should be accepting M e, 1 inputs: 1 e, 1, 11, 111 11, 111 ✘
8
No smaller DFA! After looking at all possible pairs (x, y) we conclude that So, this DFA is minimal (e, 1) (e, 11) (e, 111) (1, 11) (1, 111) (11, 111) There is no DFA with 3 states for L 1 q0 q1 q2 q3
9
DFA minimization 1 … qe q0 q1 q00 q10 q01 q11 q000 q001 q101 q111 1 q0 q1 q2 q3 We now show how to turn any DFA for L into the minimal DFA for L
10
Minimal DFAs and distinguishable states
First, we have to understand minimal DFAs: reject accept 1 1 1 q0 q1 q2 q3 1 every pair of states is distinguishable minimal DFA
11
Distinguishable states
Two states q and q’ are distinguishable if accept w1 w2 wk-1 wk … q reject w1 w2 wk-1 wk … q’ on the same continuation string w1w2...wk, one accepts, but the other rejects
12
Examples of distinguishable states
1 1 1 1 q0 q1 q2 q3 (q0, q1) distinguishable by 01 (q0, q2) distinguishable by 1 (q0, q3) distinguishable by e DFA is minimal (q1, q2) distinguishable by 1 (q1, q3) distinguishable by e (q2, q3) distinguishable by e
13
Examples of distinguishable states
q0 q1 q2 q3 1 0, 1 q01 q2 q3 1 0, 1 (q0, q3) distinguishable by e (q1, q3) distinguishable by e indistinguishable pairs can be merged (q2, q3) distinguishable by e (q1, q2) distinguishable by 0 (q0, q2) distinguishable by 0 (q0, q1) indistinguishable
14
Examples of distinguishable states
q0 q2 0, 1 q01 q23 0, 1 1 q1 0, 1 q3 0, 1 (q0, q2) distinguishable by e (q1, q2) distinguishable by e (q0, q3) distinguishable by e (q1, q3) distinguishable by e (q0, q1) indistinguishable (q2, q3) indistinguishable
15
Finding (in)distinguishable states
If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable (x) Rule 1: q x q’ q1 x q1’ q2 q2’ a If (q1, q1’) are marked, Mark (q2, q2’) as distinguishable (x) Rule 2: x Rule 3: Unmarked pairs are indistinguishable Merge them into groups
16
Example of DFA minimization
q0 q00 q1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 qe q0 q1 q00 q01 q10 1
17
Example of DFA minimization
q0 q00 q1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 q11 is distinguishable from all other states
18
Example of DFA minimization
q0 q00 q1 1 q0 1 1 q01 q00 qe 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 Look at pair qe, q0 Neither (q0, q00) nor (q1, q01) are distinguishable
19
Example of DFA minimization
q0 q00 q1 x q0 1 1 q01 q00 qe 1 1 q01 q10 1 1 q10 q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 Look at pair qe, q1 (q1, q11) is distinguishable
20
Example of DFA minimization
q0 q00 q1 x x q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 After going thru the whole table once Now we make another pass
21
Example of DFA minimization
q0 q00 q1 x x 1 q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 Look at pair qe, q0 Neither (q1, q00) nor (q1, q01) are distinguishable
22
Example of DFA minimization
q0 q00 q1 x x q0 1 1 q01 q00 x 1 qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 Look at pair qe, q00 Neither (q0, q00) nor (q1, q01) are distinguishable
23
Example of DFA minimization
q0 q00 q1 x x q0 1 1 q01 q00 x qe 1 q01 x x x q10 1 1 q10 x x q1 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1 In the second pass, nothing changes So we are ready to apply Rule 3
24
Example of DFA minimization
q0 q00 q1 x x q0 q01 q00 x qe q01 x x x q10 q10 x x q1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 Merge unmarked pairs into groups
25
Example of DFA minimization
q0 A q00 q1 x x q0 A q01 q00 A A x qe q01 x x B x q10 q10 A A x A x q1 B q11 q11 x x x x x x C qe q0 q1 q00 q01 q10 Merge unmarked pairs into groups
26
Example of DFA minimization
q0 A q00 q1 x x q0 A 1 1 q01 q00 A A x qe 1 q01 x x B x q10 1 1 q10 A A x A x q1 1 B q11 q11 x x x x x x C qe q0 q1 q00 q01 q10 1 1 qA qB qC minimized DFA:
27
Example of DFA minimization
1 qA qB qC How do we know this DFA is minimal? 1 e qB qC qA Answer: All pairs are distinguishable
28
Why it works Why do we end up finding all distinguishable pairs?
wk-1 wk … q x x x x w1 w2 wk-1 wk … q’ Because we work backwards
29
Why it works Why are there no inconsistencies when we merge?
B w q5 a A q2 q3 q1 q7 a C q6 Because we only merge indistinguishable states
30
Why it works Why is there no smaller DFA? Suppose there is
By the pigeonhole principle this must happen: M q q’ v v’ smaller DFA M’ q” v, v’
31
Why it works Why is there no smaller DFA? But then M smaller DFA M’ v
q w q” w ? v, v’ v’ q’ w Every pair of states is distinguishable q” cannot exist!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.