Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.

Similar presentations


Presentation on theme: "CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization."— Presentation transcript:

1 CSC 3130: Automata theory and formal languages Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130 The Chinese University of Hong Kong DFA minimization Fall 2009

2 Example Construct a DFA over alphabet {0, 1} that accepts those strings that end in 111 This is big, isn’t there a smaller DFA for this? 0 1 … … … … qq qq qq q  q  q  q  q  q  q  q  0 1 0 1 0 1 1 1 1 1 0

3 Smaller DFA 1 0 0 0 0 1 qq qq qq qq 11 Can we do it with 3 states?

4 Even smaller DFA? Suppose we had a 3 state DFA M for L … let’s imagine what happens when: By the pigeonhole principle, on two of these inputs M ends in the same state M inputs: , 1, 11, 111

5 Pigeonhole principle Here, balls are inputs, bins are states: Suppose you are tossing m balls into n bins, and m > n. Then two balls end up in the same bin. 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.

6 A smaller DFA Suppose M ends up in the same state after reading inputs x = 1 and y = 11 Then after reading one more 1 –The state of x1 = 11 should be rejecting –The state of y1 = 111 should be accepting … but they are both the same state! M inputs: , 1, 11, 111 1, 11 11, 111 “ends in 111”

7 A smaller DFA Suppose M ends up in the same state after reading inputs x =  and y = 1 Then after reading 11 –The state of x1 = 11 should be rejecting –The state of y1 = 111 should be accepting … but they are both the same state! M inputs: , 1, 11, 111 , 1 11, 111 “ends in 111”

8 No smaller DFA! After looking at all possible pairs for x, y, x ≠ y we conclude that So, this DFA is minimal There is no DFA with 3 states for L 1 qq qq qq qq 11 1 0 0 0 0 ( , 1)( , 11)( , 111) (1, 11)(1, 111)(11, 111)

9 DFA minimization We will show how to turn any DFA for L into the minimal DFA for L 0 1 … … … … qq qq qq q  q  q  q  q  q  q  q  0 1 0 1 0 1 1 1 1 1 0 1 qq qq qq qq 11 1 0 0 0 0

10 Minimal DFAs and distinguishable states First, we have to understand minimal DFAs: 1 0 0 0 0 1 qq qq qq qq 11 rejectaccept minimal DFA every pair of states is distinguishable

11 Distinguishable states Two states q and q’ are distinguishable if q q’ w1w1 w1w1 w2w2 w2w2 wkwk wkwk w k-1 … … on the same continuation string w 1 w 2...w k, one accepts, but the other rejects reject accept

12 Examples of distinguishable states distinguishable by 01 (q 0, q 2 ) (q 0, q 3 ) (q 0, q 1 ) (q 1, q 3 ) (q 2, q 3 ) (q 1, q 2 ) distinguishable by 1 distinguishable by  distinguishable by 1 distinguishable by  0 0 1 qq qq qq qq 01 0 1 1 DFA is minimal

13 Examples of distinguishable states distinguishable by  qq qq qq qq 0 1 0 1 0, 1 q0q0 qq qq 0 1 (q 1, q 3 ) (q 2, q 3 ) (q 0, q 3 ) (q 0, q 2 ) (q 0, q 1 ) (q 1, q 2 ) distinguishable by  distinguishable by 0 indistinguishable indistinguishable pairs can be merged

14 Examples of distinguishable states distinguishable by  (q 1, q 2 ) (q 0, q 3 ) (q 0, q 2 ) (q 0, q 1 ) (q 2, q 3 ) (q 1, q 3 ) distinguishable by  indistinguishable qq qq qq qq 1 0, 1 0 q  q  0, 1

15 Finding (in)distinguishable states Rule 1: Rule 2: q q’ If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable (x) x q1q1 q1’q1’ x x q2q2 q2’q2’ aa If (q 1, q 1 ’) are marked, Mark (q 2, q 2 ’) as distinguishable (x) Rule 3: Unmarked pairs are indistinguishable Merge them together

16 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 qq qq q  q  q  q  qq qq qq q  q 

17 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 xxxxxx qq qq q  q  q  q  qq qq qq q  q   q 11 is distinguishable from all other states

18 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 x x x x x x xxxx qq qq q  q  q  q  qq qq qq q  q   q 1 is distinguishable from q , q 0, q 00, q 10 On transition 1, they go to distinguishable states

19 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 x x x x x x x x x x x x xx qq qq q  q  q  q  qq qq qq q  q   q 01 is distinguishable from q , q 0, q 00, q 10 On transition 1, they go to distinguishable states

20 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 A x A x A x x A x A x x B x x x A x x xx qq qq q  q  q  q  qq qq qq q  q   Merge states not marked distinguishable q , q 0, q 00, q 10 are equivalent → group A q 1, q 01 are equivalent → group B q 11 cannot be merged → group C A B C

21 Example of DFA minimization 0 1 qq qq qq q  q  q  q  0 1 0 1 1 0 0 1 1 0 0 1 A x A x A x x A x A x x B x x x A x x xx qq qq q  q  q  q  qq qq qq q  q  1 qq qq qCqC 1 1 0 0 0 minimized DFA: A B C

22 Food for thought Why does method find all distinguishable pairs? q q’ w1w1 w1w1 w2w2 w2w2 wkwk wkwk w k-1 … … x xxx Because we work backwards

23 Food for thought Why are there no inconsistencies when we merge? A q3q3 q7q7 q1q1 B q5q5 q2q2 C q6q6 a a Because we only merge indistinguishable states w w

24 Food for thought Why is there no smaller DFA? M q q’ v v’v’ smaller DFA M’ q’’ v, v’ Suppose there is By the pigeonhole principle this must happen:

25 Food for thought Why is there no smaller DFA? But then M smaller DFA M’ q q’ v v’v’ q’’ v, v’ w w ? w Every pair of states is distinguishable q’’ cannot exist!


Download ppt "CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization."

Similar presentations


Ads by Google