1 / 25

CSC 3130: Automata theory and formal languages

Fall 2009. The Chinese University of Hong Kong. CSC 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

hide
Télécharger la présentation

CSC 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 2009 The Chinese University of Hong Kong CSC 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 • This is big, isn’t there a smaller DFA for this? 0 0 q000 1 0 q00 1 q001 q0 1 … 0 q01 … qe 1 q101 q10 0 … 1 q1 … 1 q11 1 q111 1

  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 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 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 together 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 q1 x x q0 1 0 1 q00 x q01 0 qe 1 0 q01 q10 0 1 1 x q10 q1 0 1 q11 q11 x x x x x x qe q0 q1 q00 q01 q10 1  q1 is distinguishable from qe, q0, q00, q10 On transition 1, they go to distinguishable states

  19. 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  q01 is distinguishable from qe, q0, q00, q10 On transition 1, they go to distinguishable states

  20. Example of DFA minimization 0 q0 A 0 q00 q1 x x A q0 1 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  Merge states not marked distinguishableqe, q0, q00, q10 are equivalent → group Aq1, q01 are equivalent → group B q11 cannot be merged → group C

  21. 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

  22. Food for thought • Why does method find all distinguishable pairs? w1 w2 wk-1 wk … q x x x x w1 w2 wk-1 wk … q’ Because we work backwards

  23. Food for thought • 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

  24. Food for thought • 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’

  25. Food for thought • 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