DFA Minimization 1 2 Equivalent States Consider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed.

Slides:



Advertisements
Similar presentations
Lexical Analysis IV : NFA to DFA DFA Minimization
Advertisements

CSE 311 Foundations of Computing I
Reducing DFA’s Section 2.4. Reduction of DFA For any language, there are many DFA’s that accept the language Why would we want to find the smallest? Algorithm:
Lecture 24 MAS 714 Hartmut Klauck
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Finite Automata CPSC 388 Ellen Walker Hiram College.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Summary Showing regular Showing non-regular construct DFA, NFA
1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore.
Formal Language, chapter 9, slide 1Copyright © 2007 by Adam Webber Chapter Nine: Advanced Topics in Regular Languages.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
Transparency No Formal Language and Automata Theory Chapter 10 The Myhill-Nerode Theorem (lecture 15,16 and B)
1 Minimizing DFA’s By Partitioning 2 Minimizing DFA’s Lots of methods All involve finding equivalent states: –States that go to equivalent states under.
1 Minimization; Pumping Lemma. October 2, Agenda Minimization Algorithm Guarantees smallest possible DFA for a given regular language Proof of.
Regular Expression (EXTRA)
Lecture 18 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA and therefore a subset.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY For next time: Read 2.1 & 2.2.
Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Extra on Regular Languages and Non-Regular Languages
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CS311: Computational Theory
Overview of Previous Lesson(s) Over View  Strategies that have been used to implement and optimize pattern matchers constructed from regular expressions.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
Week 14 - Wednesday.  What did we talk about last time?  Regular expressions  Introduction to finite state automata.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Lexical Analysis III : NFA to DFA DFA Minimization Lecture 5 CS 4318/5331 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper.
Lexical Analysis: DFA Minimization Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Transition Diagrams Lecture 3 Wed, Jan 21, Building Transition Diagrams from Regular Expressions A regular expression consists of symbols a, b,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Pembangunan Kompilator.  A recognizer for a language is a program that takes a string x, and answers “yes” if x is a sentence of that language, and.
Decidable languages Section 4.1 CSC 4170 Theory of Computation.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions NFAs  DFAs.
Chapter 4 Properties of Regular Languages
Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein.
1 Decision Properties of Regular Languages General Discussion of “Properties” The Pumping Lemma Minimizing DFA.
Regular Expressions Fundamental Data Structures and Algorithms Peter Lee March 13, 2003.
MINIMIZATION May 12, Agenda 2  These slides are not mine www1.cs.solumbia.edu/~zeph/3261/L9/L9.ppt www1.cs.solumbia.edu/~zeph/3261/L9/L9.ppt.
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
1 Lexical Analysis Uses formalism of Regular Languages Uses formalism of Regular Languages Regular Expressions Regular Expressions Deterministic Finite.
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
 2005 SDU Lecture11 Decidability.  2005 SDU 2 Topics Discuss the power of algorithms to solve problems. Demonstrate that some problems can be solved.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
NFAε - NFA - DFA equivalence
The time complexity for e-closure(T).
Two issues in lexical analysis
Review: NFA Definition NFA is non-deterministic in what sense?
Jaya Krishna, M.Tech, Assistant Professor
Hierarchy of languages
CS 154, Lecture 4: Limitations on DFAs (I),
Transition Diagrams Lecture 3 Fri, Jan 21, 2005.
Minimizing DFA’s By Partitioning.
DFA Equivalence & Minimization
DFA Minimization: The Idea
Regular Language Equivalence and DFA Minimization
Presentation transcript:

DFA Minimization 1

2 Equivalent States Consider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed to be accepted later. Q: Do we need both states? a b 1 d 0,1 e 1 c g f

3 Equivalent States A: No, they can be unified as illustrated below. Q: Can any other states be unified because any subsequent string suffixes produce identical results? a b 1 d 0,1 e 1 cg f

4 Equivalent States A: Yes, b and f. Notice that if you’re in b or f then: 1. if string ends, reject in both cases 2. if next character is 0, forever accept in both cases 3. if next character is 1, forever reject in both cases So unify b with f. a b 1 d 0,1 e 1 cg f

5 Equivalent States Intuitively two states are equivalent if all subsequent behavior from those states is the same. Q: Come up with a formal characterization of state equivalence. a 0,1 d e 1 cg bf 0 0 1

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

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

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

9 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h Initialize table entries: Unmarked, empty list

10 DFA Minimization: Example fbcdeag h g f e d c b 2.Mark pairs of final & nonfinal states a e b f c g d h

11 DFA Minimization: Example a e b f c g d h For each unmarked pair & symbol, …  (b,0)  ?  (a,0)  (b,1)  ?  (a,1) fbcdeag h g f e d c b

12 DFA Minimization: Example g  ? b c  ? f fbcdeag h g f e d c b Maybe. No! a e b f c g d h For each unmarked pair & symbol, …

13 fbcdeag h g f e d c b DFA Minimization: Example a e b f c g d h For each unmarked pair & symbol, …

14 fbcdeag h g f e d c b DFA Minimization: Example a e b f c g d h  (e,0)  ?  (a,0)  (e,1)  ?  (a,1) 3.For each unmarked pair & symbol, …

15 fbcdeag h g f e d c b DFA Minimization: Example a e b f c g d h h  ? b f  ? f Maybe. Yes. (a,e) 3.For each unmarked pair & symbol, …

16 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h (a,e) (g,a) 3.For each unmarked pair & symbol, …

17 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h (a,e) (g,a) Need to mark. So, mark (g,a) also. 3.For each unmarked pair & symbol, …

18 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h (g,a) (a,e) 3.For each unmarked pair & symbol, …

19 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h Coalesce unmarked pairs of states. (a,e) a  e b  h d  f aebh df c g

20 DFA Minimization: Example fbcdeag h g f e d c b a e b f c g d h Delete unreachable states. (a,e) aebh df c g None.

21 DFA Minimization: Notes Order of selecting state pairs was arbitrary. All orders give same ultimate result. But, may record more or fewer dependences. Choosing states by working backwards from known non-equivalent states produces fewest dependences. Can delete unreachable states initially, instead. This algorithm: O(n 2 ) 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).

22 What About NFA Minimization? This algorithm doesn’t find a unique minimal NFA. Is there a (not necessarily unique) minimal NFA? ? ? Of course.

23 NFA Minimization In general, minimal NFA not unique! Example NFAs for 0 + : Both minimal, but not isomorphic

24 Minimizing DFA’s By Partitioning

25 Minimizing DFA’s Lots of methods All involve finding equivalent states: States that go to equivalent states under all inputs (sounds recursive) We will learn the Partitioning Method

26 Minimizing DFA’s by Partitioning Consider the following dfa Accepting states are yellow Non-accepting states are blue Are any states really the same?

27 S 2 and S 7 are really the same: Both Final states Both go to S6 under input b Both go to S3 under an a S 0 and S 5 really the same. Why? We say each pair is equivalent Are there any other equivalent states? We can merge equivalent states into 1 state

28 Partitioning Algorithm First Divide the set of states into Final and Non-final states Partition I Partition II a b S0S0 S1S1 S4S4 S1S1 S5S5 S2S2 S3S3 S3S3 S3S3 S4S4 S1S1 S4S4 S5S5 S1S1 S4S4 S6S6 S3S3 S7S7 *S 2 S3S3 S6S6 *S 7 S3S3 S6S6

29 Partitioning Algorithm Now See if states in each partition each go to the same partition S 1 & S 6 are different from the rest of the states in Partition I (but like each other) We will move them to their own partition a b S0S0 S 1 I S 4 I S1S1 S 5 I S 2 II S3S3 S 3 I S4S4 S 1 I S 4 I S5S5 S 1 I S 4 I S6S6 S 3 I S 7 II *S 2 S 3 I S 6 I *S 7 S 3 I S 6 I

30 Partitioning Algorithm a b S0S0 S1S1 S4S4 S5S5 S1S1 S4S4 S3S3 S3S3 S3S3 S4S4 S1S1 S4S4 S1S1 S5S5 S2S2 S6S6 S3S3 S7S7 *S 2 S3S3 S6S6 *S 7 S3S3 S6S6

31 Partitioning Algorithm Now again See if states in each partition each go to the same partition In Partition I, S 3 goes to a different partition from S 0, S 5 and S 4 We’ll move S3 to its own partition a b S0S0 S 1 III S 4 I S5S5 S 1 III S 4 I S3S3 S 3 I S4S4 S 1 III S 4 I S1S1 S 5 I S 2 II S6S6 S 3 I S 7 II *S 2 S 3 I S 6 III *S 7 S 3 I S 6 III

32 Partitioning Algorithm Note changes in S 6, S 2 and S 7 a b S0S0 S 1 III S 4 I S5S5 S 1 III S 4 I S4S4 S 1 III S 4 I S3S3 S 3 IV S1S1 S 5 I S 2 II S6S6 S 3 IV S 7 II *S 2 S 3 IV S 6 III *S 7 S 3 IV S 6 III

33 Partitioning Algorithm Now S 6 goes to a different partition on an a from S 1 S 6 gets its own partition. We now have 5 partitions Note changes in S 2 and S 7 a b S0S0 S 1 III S 4 I S5S5 S 1 III S 4 I S4S4 S 1 III S 4 I S3S3 S 3 IV S1S1 S 5 I S 2 II S6S6 S 3 IV S 7 II *S 2 S 3 IV S 6 V *S 7 S 3 IV S 6 V

34 Partitioning Algorithm All states within each of the 5 partitions are identical. We might as well call the states I, II III, IV and V. a b S0S0 S 1 III S 4 I S5S5 S 1 III S 4 I S4S4 S 1 III S 4 I S3S3 S 3 IV S1S1 S 5 I S 2 II S6S6 S 3 IV S 7 II *S 2 S 3 IV S 6 V *S 7 S 3 IV S 6 V

35 Partitioning Algorithm a b I III I *II IVV III I II IV V II Here they are:

36 V a a a a a b b b b b b