1 / 20

DFA Minimization

DFA Minimization. Note these slides are not mine. http://faculty.kutztown.edu/spiegel “Minimal”? Minimal number of states. “Unique”? A minimal DFA for a given language is unique up to renaming of states. Build equivalence relation on states:

niesha
Télécharger la présentation

DFA 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. DFA Minimization • Note these slides are not mine. • http://faculty.kutztown.edu/spiegel • “Minimal”? • Minimal number of states. • “Unique”? • A minimal DFA for a given language is unique up to renaming of states.

  2. Build equivalence relation on states: • p  q  (zS*, (p,z)F (q,z)F) • I.e., iff for every string z, one of the following is true: z z p p or z z q q DFA Minimization: Algorithm Idea Equate & collapse states having same behavior.

  3. DFA Minimization: Algorithm Build table to compare each unordered pair of distinct states p,q. Each table entry has • a “mark” as to whether p & q are known to be not equivalent, and • a list of entries, recording dependences: “If this entry is later marked, also mark these.”

  4. DFA Minimization: Algorithm • Initialize all entries as unmarked & with no dependences. • Mark all pairs of a final & nonfinal state. • For each unmarked pair p,q & input symbol a: • Let r=d(p,a), s=d(q,a). • If (r,s) unmarked, add (p,q) to (r,s)’s dependences, • Otherwise mark (p,q), and recursively mark all dependences of newly-marked entries. • Merge unmarked pairs of states. • Delete inaccessible states.

  5. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example • Initialize table entries: • Unmarked, empty list

  6. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example • Mark pairs of final and • non-final states

  7. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example d(b,0) ? d(a,0) d(b,1) ? d(a,1) • For each unmarked • pair and symbol, …

  8. 1 0 0 1 0 Maybe. No! a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example g ? b c ? f • For each unmarked • pair and symbol, …

  9. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example • For each unmarked • pair and symbol, …

  10. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example d(e,0) ? d(a,0) d(e,1) ? d(a,1) • For each unmarked • pair and symbol, …

  11. 1 0 0 1 0 Maybe. Yes. a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f g h a b c d e f g DFA Minimization: Example h ? b f ? f • For each unmarked • pair and symbol, … (a,e)

  12. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f (g,a) g (g,a) h (a,e) a b c d e f g DFA Minimization: Example • For each unmarked • pair and symbol, …

  13. 1 0 0 1 0 a b c d Need to mark. b 0 1 1 So, mark (g,a) also. 0 1 1 1 0 e f g h c 0 1 d 0 e f g h (a,e) a b c d e f g DFA Minimization: Example • For each unmarked • pair and symbol, … (g,a) (g,a)

  14. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f (g,a) g h (a,e) a b c d e f g DFA Minimization: Example • For each unmarked • pair and symbol, …

  15. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f 1 0 g 0 1 ae bh c 0 1 0 h 1 (a,e) df g 1 a b c d e f g 0 DFA Minimization: Example • Merge unmarked • pairs of states. a  e b  h d  f

  16. 1 0 0 1 0 a b c d b 0 1 1 0 1 1 1 0 e f g h c 0 1 d 0 e f 1 0 g 0 1 ae bh c 0 1 0 h 1 (a,e) df g 1 a b c d e f g 0 DFA Minimization: Example • Delete unreachable • states. None.

  17. DFA Minimization: Notes Order of selecting state pairs was arbitrary, but all orders give the same result. Can delete unreachable states initially, instead. This algorithm: O(n2) time; Huffman (1954), Moore (1956). • Constant work per entry: initial mark test & possibly later chasing of its dependences. • More efficient algorithms exist, e.g., Hopcroft (1971).

  18. DFA Minimization: Correctness Why is new DFA no larger than old DFA? Only removes states, never introduces new states. Why is new DFA equivalent to old DFA? Only identify states that have same behavior.

  19. What About NFA Minimization? This algorithm does not find a unique minimal NFA. Is there a (not necessarily unique) minimal NFA for a given language? Of course.

  20. 0 0 0 0 NFA Minimization In general, minimal NFA’s not unique! Example NFAs for 0+: Both minimal, but not isomorphic.

More Related