CSE 311 Foundations of Computing I

Slides:



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

4b Lexical analysis Finite Automata
CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
CMPS 3223 Theory of Computation
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Finite Automata CPSC 388 Ellen Walker Hiram College.
CSE 311: Foundations of Computing Fall 2013 Lecture 23: Finite state machines and minimization.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Introduction to Computability Theory
1 Introduction to Computability Theory Discussion1: Non-Deterministic Finite Automatons Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
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.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
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.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Non-Deterministic Automata Regular Expressions.
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
NFA ε - NFA - DFA equivalence. What is an NFA An NFA is an automaton that its states might have none, one or more outgoing arrows under a specific symbol.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
CSE 311 Foundations of Computing I Lecture 23 Finite State Machines Autumn 2012 CSE 3111.
CSE 311 Foundations of Computing I Lecture 21 Finite State Machines Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 21 Finite State Machines Spring
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
Lexical Analysis Constructing a Scanner from Regular Expressions.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
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.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
CSE 311 Foundations of Computing I Lecture 24 Finite State Machines Autumn 2012 CSE 3111.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Theory of Computation Automata Theory Dr. Ayman Srour.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
NFAε - NFA - DFA equivalence
Non Deterministic Automata
CSE 311 Foundations of Computing I
Chapter 2 FINITE AUTOMATA.
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
CSE 311 Foundations of Computing I
Non-Deterministic Finite Automata
Nondeterministic Finite Automata
Non Deterministic Automata
CSE 311: Foundations of Computing
CSE 311: Foundations of Computing
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
CSE 311 Foundations of Computing I
Chapter 1 Regular Language
Presentation transcript:

CSE 311 Foundations of Computing I Lecture 25 Finite State Machines: Output and Minimization Autumn 2012 Autumn 2012 CSE 311

Announcements Reading assignments 7th Edition, Sections 13.3 and 13.4 6th Edition, Section 12.3 and 12.4 5th Edition, Section 11.3 and 11.4 Autumn 2012 CSE 311

State Machines with Output Vending Machine Enter 15 cents in dimes or nickels Press S or B for a candy bar Autumn 2012 CSE 311

Vending Machine, Final Version B,S D N 15 B,S B,S B,S D D B D S 0’ B 5 N 10 N N N D 15’ N B N S B,S D N D N 0” S B 15” D S D

State Minimization Many different FSMs (DFAs) for the same problem Take a given FSM and try to reduce its state set by combining states Algorithm will always produce the unique minimal equivalent machine (up to renaming of states) but we won’t prove this Autumn 2012 CSE 311

State minimization Recognizing strings with odd length s1 s2 s3 s0 0,1 Autumn 2012 CSE 311

State minimization algorithm Put states into groups based on their outputs (or whether they are final states or not) Repeat the following until no change happens If there is a symbol s so that not all states in a group G agree on which group s leads to, split G into smaller groups based on which group the states go to on s G2 G1 G3

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) If there is a symbol s so that not all states in a group G agree on which group s leads to, split G based on which group the states go to on s Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) If there is a symbol s so that not all states in a group G agree on which group s leads to, split G based on which group the states go to on s Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) If there is a symbol s so that not all states in a group G agree on which group s leads to, split G based on which group the states go to on s Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) If there is a symbol s so that not all states in a group G agree on which group s leads to, split G based on which group the states go to on s Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Put states into groups based on their outputs (or whether they are final states or not) If there is a symbol s so that not all states in a group G agree on which group s leads to, split G based on which group the states go to on s Autumn 2012 CSE 311

State Minimization Example present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 2 1 3 S0 [1] S2 [1] S4 [1] S1 [0] S3 S5 state transition table Can combine states S0-S4 and S3-S5. In table replace all S4 with S0 and all S5 with S3 Autumn 2012 CSE 311

state transition table Minimized Machine present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S3 0 S2 S1 S3 S2 S0 1 S3 S1 S0 S0 S3 0 2 S0 [1] S1 [0] 1 2 3 1,3 3 1,2 state transition table S2 [1] S3 [0] 1 2 3 Autumn 2012 CSE 311

Another way to look at DFAs Definition: The label of a path in a DFA is the concatenation of all the labels on its edges in order Lemma: x is in the language recognized by a DFA iff x labels a path from the start state to some final state s0 s2 s3 s1 1 0,1 Autumn 2012 CSE 311

Nondeterministic Finite Automaton (NFA) Graph with start state, final states, edges labeled by symbols (like DFA) but Not required to have exactly 1 edge out of each state labeled by each symbol - can have 0 or >1 Also can have edges labeled by empty string  Definition: x is in the language recognized by an NFA iff x labels a path from the start state to some final state s0 s2 s3 s1 1 0,1 Autumn 2012 CSE 311

Design an NFA to recognize the set of binary strings that contain 111 or have an even # of 1’s Autumn 2012 CSE 311

Finite state machines and regular expressions Every regular expression can be recognized by a NFA Every NFA can be converted into an equivalent regular expression Every NFA can be converted into an equivalent DFA 1 and 3 will be sketched in class Autumn 2012 CSE 311

NFAs and DFAs Every DFA is an NFA DFAs have requirements that NFAs don’t have Can NFAs recognize more languages? No! Theorem: For every NFA there is a DFA that recognizes exactly the same language Autumn 2012 CSE 311

Conversion of NFAs to a DFAs Proof Idea: The DFA keeps track of ALL the states that the part of the input string read so far can reach in the NFA There will be one state in the DFA for each subset of states of the NFA that can be reached by some string Autumn 2012 CSE 311

Conversion of NFAs to a DFAs New start state for DFA The set of all states reachable from the start state of the NFA using only edges labeled  f e b a  a,b,e,f DFA NFA Autumn 2012 CSE 311

Conversion of NFAs to a DFAs For each state of the DFA corresponding to a set S of states of the NFA and each symbol s Add an edge labeled s to state corresponding to T, the set of states of the NFA reached by starting from some state in S, then following one edge labeled by s, and then following some number of edges labeled by  T will be  if no edges from S labeled s exist 1 f e b  c d g  1 1 b,e,f c,d,e,g 1 Autumn 2012 1 CSE 311

Conversion of NFAs to a DFAs Final states for the DFA All states whose set contain some final state of the NFA c e b a a,b,c,e DFA NFA Autumn 2012 CSE 311

Example: NFA to DFA c a b  0,1 1 NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA a,b c a b  0,1 1 NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA a,b c a b  0,1 1 1 c NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA a,b a c b c b,c b 1  1 1 0,1 NFA DFA Autumn 2012 a,b c a b  0,1 1 1 1 c b b,c NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA  a,b a c b c b,c b 1 1  1 1 0,1 NFA DFA  a,b c a b  0,1 1 1 1 1 c b b,c NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA  a,b a c b c b,c b 0,1 1 1  1 1 0,1 NFA DFA  a,b c a b  0,1 1 1 1 1 c b b,c NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA  a,b a c b c b,c a,b,c b 0,1 1 1  1 1 1 0,1 NFA  a,b c a b  0,1 1 1 1 1 c b 1 b,c a,b,c NFA DFA Autumn 2012 CSE 311

Example: NFA to DFA  a,b a c b c b,c a,b,c b 0,1 1 1  1 1 1 0,1 1  a,b c a b  0,1 1 1 1 1 c b 1 1 b,c a,b,c NFA DFA Autumn 2012 CSE 311

Exponential blow-up in simulating nondeterminism In general the DFA might need a state for every subset of states of the NFA Power set of the set of states of the NFA n-state NFA yields DFA with at most 2n states We saw an example where roughly 2n is necessary Is the 10th char from the end a 1? The famous “P=NP?” question asks whether a similar blow-up is always necessary to get rid of nondeterminism for polynomial-time algorithms Autumn 2012 CSE 311