The Chinese University of Hong Kong Fall 2009

























- Slides: 25
The Chinese University of Hong Kong Fall 2009 CSC 3130: Automata theory and formal languages DFA minimization Andrej Bogdanov http: //www. cse. cuhk. edu. hk/~andrejb/csc 3130
Example • Construct a DFA over alphabet {0, 1} that accepts those strings that end in 111 0 0 q 0 1 qe 1 0 q 1 1 q 00 1 q 01 … q 10 q 11 1 … 1 1 q 001 … 0 q 000 q 101 … 0 q 111 1 • This is big, isn’t there a smaller DFA for this?
Smaller DFA 0 q 0 1 q 1 q 2 1 0 0 Can we do it with 3 states? q 3 1
Even smaller DFA? • Suppose we had a 3 state DFA M for L … let’s imagine what happens when: inputs: M e, 1, 111 • By the pigeonhole principle, on two of these inputs M ends in the same state
Pigeonhole principle Suppose you are tossing m balls into n bins, and m > n. Then two balls end up in the same bin. • Here, balls are inputs, bins are states: If you have a DFA with n states and you run it on m inputs, and m > n, then two inputs end up in same state.
A smaller DFA • Suppose M ends up in the same state after reading inputs x = 1 and y = 11 inputs: M e, 1, 111 1, 11 11, 111 “ends in 111” • Then after reading one more 1 – The state of x 1 = 11 should be rejecting – The state of y 1 = 111 should be accepting … but they are both the same state!
A smaller DFA • Suppose M ends up in the same state after reading inputs x = e and y = 1 inputs: M e, 1, 111 e, 1 11, 111 “ends in 111” • Then after reading 11 – The state of x 1 = 11 should be rejecting – The state of y 1 = 111 should be accepting … but they are both the same state!
No smaller DFA! • After looking at all possible pairs for x, y, x ≠ y (e, 1) (e, 111) (1, 111) (11, 111) we conclude that There is no DFA with 3 states for L • So, this DFA is minimal 0 q 0 1 q 1 0 0 q 2 1 q 3 1
DFA minimization 0 q 000 0 1 q 001 1 … q 01 1 q 10 q 0 0 0 qe 1 q 2 q 111 1 1 q 11 1 … 0 q 3 q 101 … q 00 1 … 1 0 q 1 1 0 0 0 q 0 We will show to turn any DFA for L into the minimal DFA for L
Minimal DFAs and distinguishable states • First, we have to understand minimal DFAs: reject accept 0 q 0 1 q 1 q 2 1 q 3 1 0 0 minimal DFA every pair of states is distinguishable
Distinguishable states • Two states q and q’ are distinguishable if q q’ w 1 w 2 … … wk-1 wk wk t p e c c a re t c je on the same continuation string w 1 w 2. . . wk, one accepts, but the other rejects
Examples of distinguishable states 0 q 0 1 1 1 q 1 0 (q 0, q 1) distinguishable by 01 (q 0, q 2) distinguishable by 1 (q 0, q 3) distinguishable by e (q 1, q 2) distinguishable by 1 (q 1, q 3) distinguishable by e (q 2, q 3) distinguishable by e 0 q 2 1 q 3 0 DFA is minimal
Examples of distinguishable states 0 q 0 0, 1 q 3 (q 0, q 3) distinguishable by e (q 1, q 3) distinguishable by e (q 2, q 3) distinguishable by e (q 1, q 2) distinguishable by 0 (q 0, q 1) indistinguishable 0 q 01 1 0, 1 q 2 0, 1 1 1 0, 1 q 1 0 q 2 q 3 indistinguishable pairs can be merged
Examples of distinguishable states 0 q 0 0, 1 q 2 q 01 1 q 1 0, 1 q 3 0, 1 (q 0, q 2) distinguishable by e (q 1, q 2) distinguishable by e (q 0, q 3) distinguishable by e (q 1, q 3) distinguishable by e (q 0, q 1) indistinguishable (q 2, q 3) indistinguishable 0, 1 q 23
Finding (in)distinguishable states Rule 1: Rule 2: q x q’ q 1 x q 1 ’ a q 2 Rule 3: a x q 2 ’ If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable (x) If (q 1, q 1’) are marked, Mark (q 2, q 2’) as distinguishable (x) Unmarked pairs are indistinguishable Merge them together
Example of DFA minimization 0 0 0 q 0 1 0 q 1 q 00 1 q 1 1 1 qe q 01 1 q 10 0 q 11 1 q 00 q 01 q 10 q 11 1 qe q 0 q 1 q 00 q 01 q 10
Example of DFA minimization 0 0 0 q 0 1 0 q 1 q 00 1 q 1 1 1 qe q 01 1 q 10 0 q 11 1 q 00 q 01 q 10 q 11 1 x x x qe q 0 q 1 q 00 q 01 q 10 q 11 is distinguishable from all other states
Example of DFA minimization 0 0 0 q 0 1 0 q 1 q 00 1 q 1 1 1 qe q 01 1 q 10 0 q 11 1 q 00 x q 01 q 10 q 11 1 x x x x x qe q 0 q 1 q 00 q 01 q 10 q 1 is distinguishable from qe, q 00, q 10 On transition 1, they go to distinguishable states
Example of DFA minimization 0 0 0 q 0 1 0 q 1 q 00 1 q 1 1 1 qe q 01 1 q 10 0 q 11 1 x q 00 q 01 x x q 10 x x x x q 11 1 x x x qe q 0 q 1 q 00 q 01 q 10 q 01 is distinguishable from qe, q 00, q 10 On transition 1, they go to distinguishable states
Example of DFA minimization 0 0 A 0 q 0 1 B 0 q 1 q 00 q 1 1 1 qe q 01 1 q 10 0 1 C q 11 1 q 00 q 01 q 10 q 11 1 A x A x x B x x A x x x qe q 0 q 1 q 00 q 01 q 10 Merge states not marked distinguishable qe, q 00, q 10 are equivalent → group A q 1, q 01 are equivalent → group B q 11 cannot be merged → group C
Example of DFA minimization 0 0 A 0 q 0 1 B 0 q 1 q 00 q 1 1 1 qe q 01 1 q 10 0 q 01 1 0 1 q 00 0 q 11 C q 11 A x A x x B x x A x x x qe q 0 q 1 q 00 q 01 q 10 1 0 minimized DFA: q. A 1 0 q. B 0 1 q. C 1
Food for thought • Why does method find all distinguishable pairs? q x q’ w 1 w 2 x w 2 … … wk-1 wk x wk Because we work backwards x
Food for thought • Why are there no inconsistencies when we merge? B q 5 a A q 1 q 2 q 3 q 7 w a C q 6 w Because we only merge indistinguishable states
Food for thought • Why is there no smaller DFA? Suppose there is By the pigeonhole principle this must happen: v q v’ q’ M smaller DFA M’ q’’ v, v’
Food for thought • Why is there no smaller DFA? But then v v’ q q’ w w Every pair of states is distinguishable M smaller DFA M’ q’’ v, v’ q’’ cannot exist! w ?

























