1 / 24

State Minimization

State Minimization. Section 2.5 Fri, Oct 7, 2005. Minimizing a DFA. To minimize a DFA is to find an equivalent DFA that has the least possible number of states.

tonygreco
Download Presentation

State Minimization

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. State Minimization Section 2.5 Fri, Oct 7, 2005

  2. Minimizing a DFA • To minimize a DFA is to find an equivalent DFA that has the least possible number of states. • If the DFA is going to be used to write a program (e.g., a compiler) or to design hardware, then there may be a significant benefit in minimizing it before implementing it.

  3. Indistinguishable States • Let M be a DFA. Two states p and q are called indistinguishable if the DFA obtained by making p the initial state is equivalent to the DFA obtained by making q the initial state. • Write p ≡ q. • This is an equivalence relation on K. • Why?

  4. Distinguishing States • We say that a string wdistinguishes states p and q if • (p, w) M* (f, e), for some final state f, and • (q, w) M* (u, e) for some nonfinal state u, • or vice versa. • Therefore, two states are indistinguishable if there is no string that distinguishes them.

  5. Minimizing a DFA • The problem is to determine which states are distinguishable and which are indistinguishable. • To minimize a DFA, we want to identify its equivalence classes of indistinguishable states and replace them with single states.

  6. The Relation ≡n • Let p and q be states. Define the relation p ≡nq to mean that p and q are not distinguishable by any string w with |w| n. • That is, no sequence of up to n moves will distinguish p and q. • This, too, is an equivalence relation. • Clearly, p ≡0q if and only if p, qF or p, q F.

  7. Properties of ≡n • The following are obvious: • For all n 0, if p ≡ q, then p ≡nq. • For all n 0, if p ≡nq then p ≡ q. • For all n 1, if p ≡nq, then p ≡n – 1q. • But it is not the case that if p ≡n – 1q, then p ≡nq.

  8. Another Property of ≡n • Theorem: For any two states p and q and any n 1, p ≡nq if and only if • p ≡n – 1q, and • for all a Σ, δ(p, a) ≡n – 1 δ(q, a). • This theorem characterizes the relation ≡n entirely in terms of the relation ≡n – 1 and the function . • It leads to an algorithm to determine which states are indistinguishable.

  9. The Minimization Algorithm • Initialize the equivalence classes for ≡0 as F and K – F. • For n = 0, 1, 2, …, compute the equivalence classes of ≡n from ≡n – 1 and , as described in the previous theorem. • Repeat this until, for some n, the classes of ≡n are the same as the classes of ≡n – 1. • This must eventually happen. • Why?

  10. The Minimization Algorithm • At that point, the equivalence classes of ≡nare the equivalence classes of ≡. • Why? • Replace each equivalence class of states under ≡ by a single state.

  11. a b b a b 2 3 4 5 6 a a b a a b 1 a a a b b b 7 8 9 10 b a, b Example of Minimization • Minimize the following DFA.

  12. Example: The ≡0 Partition • The relation ≡0 partitions K into two classes. {1, 2, 3, 4, 5, 6, 7, 8, 9}, {10}

  13. Example: The ≡1 Partition • Apply the “a-transitions” to each class: {2, 6, 8, 5, 10, 10, 2, 5, 4}, {10} • Apply the “b-transitions” to each class: {7, 3, 9, 3, 7, 3, 9, 7, 10}, {10}

  14. Example: The ≡1 Partition • The a-transitions indicate that 5 and 6 are in a different class than 1, 2, 3, 4, 7, 8, and 9. • The b-transitions indicate that 9 is in a different class than 1, 2, 3, 4, 5, 6, 7, and 8. • The partition of ≡1 is {1, 2, 3, 4, 7, 8}, {5, 6}, {9}, {10}

  15. Example: The ≡2 Partition • Apply the a-transitions to these classes: {2, 6, 8, 5, 2, 5}, {10, 10}, {4}, {10} • Apply the b-transitions to these classes: {7, 3, 9, 3, 9, 7}, {7, 3}, {10}, {10} • The a-transitions split {1, 2, 3, 4, 7, 8} into {1, 3, 7} and {2, 4, 8}. • The b-transitions split {1, 2, 3, 4, 7, 8} into {1, 2, 4, 8} and {3, 7}.

  16. Example: The ≡2 Partition • Combining these, we get the ≡2partition {1}, {3, 7}, {2, 4, 8}, {5, 6}, {9}, {10}. • Apply the a-transitions to these classes: {2}, {8, 2}, {6, 5, 5}, {10, 10}, {4}, {10}. • Apply the b-transitions to these classes: {7}, {9, 9}, {3, 3, 7}, {7, 3}, {10}, {10}. • This produces no new classes.

  17. Example: The ≡3 Partition • Therefore, these are the classes of ≡, namely {1}, {2, 4, 8}, {3, 7}, {5, 6}, {9}, {10}.

  18. a b b a b 2 3 4 5 6 a a b a a b 1 a a a b b b 7 8 9 10 b a, b Example of Minimization • Combine states 2, 4, and 8 into one state.

  19. a b b a b 2 3 4 5 6 a a b a a b 1 a a a b b b 7 8 9 10 b a, b Example of Minimization • Combine states 2, 4, and 8 into one state.

  20. a b b a b 2 3 4 5 6 a a b a a b 1 a a a b b b 7 8 9 10 b a, b Example of Minimization • Combine states 3 and 7 into one state.

  21. a b b a b 2 3 4 5 6 a a b a a b 1 a a a b b b 7 8 9 10 b a, b Example of Minimization • Combine states 5 and 6 into one state.

  22. a 248 56 a, b a a b 1 b a 10 a b b 37 9 b Example of Minimization • Replace each of these classes with a single class.

  23. Example of Minimization • Now we can see that the language of this DFA is {w *w contains aaa or bbb}.

  24. Example • Find a minimal DFA that accepts the language {w* | w contains 010 and 101}.

More Related