DFA Minimization Jeremy Mange CS 6800 Summer 2009.

Slides:



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

4b Lexical analysis Finite Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Lecture 24 MAS 714 Hartmut Klauck
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Regular Expressions and DFAs COP 3402 (Summer 2014)
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.
Compiler Construction
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 The scanning process Goal: automate the process Idea: –Start with an RE –Build a DFA How? –We can build a non-deterministic finite automaton (Thompson's.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
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.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
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,
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Lexical Analysis Constructing a Scanner from Regular Expressions.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Finite Automata Chapter 1. Automatic Door Example Top View.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Conversions Regular Expression to FA FA to Regular Expression.
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.
What do we know? DFA = NFA =  -NFA We have seen algorithms to transform DFA to NFA (trival) NFA to  NFA (trivial) NFA to DFA (subset construction)
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Compiler Construction Lecture Three: Lexical Analysis - Part Two CSC 2103: Compiler Construction Lecture Three: Lexical Analysis - Part Two Joyce Nakatumba-Nabende.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lexical analysis Finite Automata
Non Deterministic Automata
Two issues in lexical analysis
Recognizer for a Language
Finite Automata & Regular Languages
Chapter 2 FINITE AUTOMATA.
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
CSE322 Definition and description of finite Automata
Non Deterministic Automata
DFA Equivalence & Minimization
Finite Automata.
4b Lexical analysis Finite Automata
CSCI 2670 Introduction to Theory of Computing
4b Lexical analysis Finite Automata
Instructor: Aaron Roth
Chapter 1 Regular Language
Lecture 5 Scanning.
Lexical Analysis Uses formalism of Regular Languages
Presentation transcript:

DFA Minimization Jeremy Mange CS 6800 Summer 2009

DFA Deterministic Finite Automata (DFSA) (Q, Σ, δ, q 0, F) Q – (finite) set of states Σ – alphabet – (finite) set of input symbols δ – transition function q 0 – start state F – set of final / accepting states

DFA Often representing as a diagram:

DFA Minimization Some states can be redundant: The following DFA accepts (a|b)+ State s1 is not necessary

DFA Minimization So these two DFAs are equivalent:

DFA Minimization This is a state-minimized (or just minimized) DFA Every remaining state is necessary

DFA Minimization The task of DFA minimization, then, is to automatically transform a given DFA into a state-minimized DFA Several algorithms and variants are known Note that this also in effect can minimize an NFA (since we know algorithm to convert NFA to DFA)

DFA Minimization Algorithm Recall that a DFA M=(Q, Σ, δ, q 0, F) Two states p and q are distinct if p in F and q not in F or vice versa, or for some α in Σ, δ(p, α) and δ(q, α) are distinct Using this inductive definition, we can calculate which states are distinct

DFA Minimization Algorithm Create lower-triangular table DISTINCT, initially blank For every pair of states (p,q): If p is final and q is not, or vice versa DISTINCT(p,q) = ε Loop until no change for an iteration: For every pair of states (p,q) and each symbol α If DISTINCT(p,q) is blank and DISTINCT( δ(p,α), δ(q,α) ) is not blank  DISTINCT(p,q) = α Combine all states that are not distinct

Very Simple Example s0 s1 s2 s0s1s2

Very Simple Example s0 s1ε s2ε s0s1s2 Label pairs with ε where one is a final state and the other is not

Very Simple Example s0 s1ε s2ε s0s1s2 Main loop (no changes occur)

Very Simple Example s0 s1ε s2ε s0s1s2 DISTINCT(s1, s2) is empty, so s1 and s2 are equivalent states

Very Simple Example Merge s1 and s2

More Complex Example

Check for pairs with one state final and one not:

More Complex Example First iteration of main loop:

More Complex Example Second iteration of main loop:

More Complex Example Third iteration makes no changes Blank cells are equivalent pairs of states

More Complex Example Combine equivalent states for minimized DFA:

Conclusion DFA Minimization is a fairly understandable process, and is useful in several areas Regular expression matching implementation Very similar algorithm is used for compiler optimization to eliminate duplicate computations The algorithm described is O(kn 2 ) John Hopcraft describes another more complex algorithm that is O(k (n log n) )

Possible Exam Question Question: Inductively define when two states in a DFA are distinct. Answer: Two states p and q are distinct if p F and q F or vice versa, or for some α Σ, δ(p, α) and δ(q, α) are distinct

References Ullman, A. V., Hopcroft, J. E. and Ullman, J. D. (1974) The Design and Analysis of Computer Algorithms. Addison-Wesley. Hopcroft, J. (1971) An N Log N Algorithm for Minimizing States in a Finite Automaton. Stanford University. Parthasarathy, M. and Fleck, M. (2007) DFA Minimization. University of Illinois at Urbana-Champaign.