1 / 31

CSCI 3130: Automata theory and formal languages

Fall 2010. The Chinese University of Hong Kong. CSCI 3130: Automata theory and formal languages. DFA minimization. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Example. Construct a DFA over alphabet {0, 1} that accepts those strings that end in 111.

pollacke
Télécharger la présentation

CSCI 3130: Automata theory and formal languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Example • Construct a DFA over alphabet {0, 1} that accepts those strings that end in 111 Isn’t there a smaller one?

  3. Smaller DFA 0 1 1 1 1 q0 q1 q2 q3 0 0 0 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: e, 1, 11, 111

  5. Pigeonhole principle • Here, balls are inputs, bins are states: Suppose you are tossing n + 1 balls into n bins, and Then two balls end up in the same bin. If you have a DFA with n states and you run it on n + 1 inputs, then two of them 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 more1 • The state of x1 = 11 should be rejecting • The state of y1 = 111 should be accepting … but they are both the same state! 1, 11 M inputs: 11, 111 e, 1, 11, 111 “ends in 111”

  7. A smaller DFA • Suppose M ends up in the same state after reading inputs x = e 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! e, 1 M inputs: 11, 111 e, 1, 11, 111 “ends in 111”

  8. 0 1 1 1 1 q0 q1 q2 q3 0 0 0 No smaller DFA! • After looking at all possible pairs for x, y, x ≠ ywe 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

  9. 0 1 1 1 1 q0 q1 q2 q3 0 0 0 DFA minimization 0 0 q000 1 0 q00 1 q001 q0 1 … 0 q01 … qe 1 q101 q10 0 … 1 q1 … 1 q11 1 q111 1 We will show how to turn any DFA for L into the minimal DFA for L

  10. Minimal DFAs and distinguishable states • First, we have to understandminimal DFAs: reject accept 0 1 1 1 1 q0 q1 q2 q3 0 0 0 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 0 1 1 0 1 q0 q1 q2 q3 0 0 (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. q2 q2 0 0 q0 0 0, 1 0, 1 q01 1 1 q1 1 q3 q3 0, 1 0, 1 Examples of distinguishable states (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 0 q2 q0 0, 1 0, 1 q23 q01 1 0, 1 0, 1 q3 q1 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 rejectingMark(q, q’) as distinguishable (x) Rule 1: x q q’ x q1 q1’ If (q1, q1’) are marked,Mark(q2, q2’) as distinguishable (x) a a Rule 2: x q2 q2’ Unmarked pairs are indistinguishable Merge them into groups Rule 3:

  16. Example of DFA minimization 0 q0 0 q00 q1 q0 1 0 1 q00 q01 0 qe 1 0 q01 q10 0 1 1 q10 q1 0 1 q11 q11 qe q0 q1 q00 q01 q10 1

  17. Example of DFA minimization 0 q0 0 q00 q1 q0 1 0 1 q00 q01 0 qe 1 0 q01 q10 0 1 1 q10 q1 0 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 0 q0 0 q00 0 q1 1 q0 1 0 1 q00 q01 0 qe 1 0 q01 q10 0 1 1 q10 q1 0 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 0 q0 0 q00 x q1 q0 1 0 1 q00 q01 0 qe 1 0 1 0 q01 q10 0 1 1 q10 q1 0 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 0 q0 0 q00 q1 x x q0 1 0 1 q00 x q01 0 qe 1 0 x x x q01 q10 0 1 1 x x q10 q1 0 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 0 q0 0 q00 0 q1 x x 1 q0 1 0 1 q00 x q01 0 qe 1 0 x x x q01 q10 0 1 1 x x q10 q1 0 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 0 q0 0 q00 q1 x x q0 1 0 0 1 q00 x q01 0 1 qe 1 0 x x x q01 q10 0 1 1 x x q10 q1 0 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 0 q0 0 q00 q1 x x q0 1 0 1 q00 x q01 0 qe 1 0 x x x q01 q10 0 1 1 x x q10 q1 0 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 q00 x q01 qe x x x q01 q10 x x q10 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 q00 A A x q01 qe x x B x q01 q10 A A x A x q10 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 0 q0 A 0 q00 q1 x x q0 1 A 0 1 q00 A A x q01 0 qe 1 0 x x B x q01 q10 0 1 1 A A x A x q10 q1 0 1 B q11 q11 x x x x x x C qe q0 q1 q00 q01 q10 1 0 1 1 minimized DFA: qA qB qC 1 0 0

  27. Example of DFA minimization How do we know this DFA is minimal? qB 1 0 Answer: All pairs are distinguishable qC e e 1 1 qA qB qC 1 qA qB 0 0

  28. Why it works • Why do we end up finding all distinguishable pairs? w1 w2 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 q5 w a A q2 q3 q1 q7 a C w 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 smaller DFA M’ v q q’’ v, v’ v’ q’

  31. Why it works • Why is there no smaller DFA? But then M smaller DFA M’ v w q q’’ w ? v, v’ v’ q’ w Every pair of states is distinguishable q’’ cannot exist!

More Related