1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.

Slides:



Advertisements
Similar presentations
Non-Deterministic Finite Automata
Advertisements

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)
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
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
Introduction to Computability Theory
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Finite Automata and Non Determinism
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.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
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.
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)
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
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.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
Theory of Languages and Automata
1 Chapter 2 Finite Automata (part b) Windmills in Holland.
Athasit Surarerks THEORY OF COMPUTATION 07 NON-DETERMINISTIC FINITE AUTOMATA 1.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Lecture Notes 
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Lecture #5 Advanced Computation Theory Finite Automata.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Theory of Computation Automata Theory Dr. Ayman Srour.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Language Recognition MSU CSE 260.
CIS Automata and Formal Languages – Pei Wang
Non Deterministic Automata
Nondeterministic Finite Automata
Single Final State for NFA
Chapter 2 FINITE AUTOMATA.
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Hierarchy of languages
Non-Deterministic Finite Automata
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
Non Deterministic Automata
CSE 2001: Introduction to Theory of Computation Fall 2009
Finite Automata.
Chapter Five: Nondeterministic Finite Automata
Discrete Math II Howon Kim
CSCI 2670 Introduction to Theory of Computing
Language Recognition (12.4)
CSCI 2670 Introduction to Theory of Computing
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
CHAPTER 1 Regular Languages
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan State University

1/29/02CSE460 - MSU2 Introduction An NFA is a more general FA  Easier to construct  More useful in proving theorems  In general less states  Less cumbersome,more readable Relax some FA rules  Maps a symbol and a state to a set of 0, 1 or more next states  NFA can be in several states at once vs. FA in exactly 1 state NFAs, as a whole, accept same languages as FAs: Regular  No more powerful than FAs

1/29/02CSE460 - MSU3 Definition of FA - Reminder Definition A finite automaton is a 5-tuple M=(Q, ,q 0, ,A) Q is a finite set of states  is a finite alphabet of input symbols q 0  Q is the initial state A  Q is the set of accepting states  : Q x   Q is the transition function, which maps every state and input symbol to a next state. A string x is accepted by an NFA, if after processing x, at least one of the active states is an accepting state.

1/29/02CSE460 - MSU4 Outline Example NFA Formal Definition of NFA  Extended Transition Function Exercise Equivalence of NFAs and FAs  Example Construction of Equivalent FA  Theorem Summary

1/29/02CSE460 - MSU5 Example - NFA 0,1 10 q0q0 q1q1 q2q2 Language accepted by above NFA? Set of strings that end with 10. L = (0+1)* q0q0 q1q1 q2q Fig 3.3 (p.81)

1/29/02CSE460 - MSU6 Example - Processing Input String q0q0 q0q0 q0q0 q0q0 q0q0 q0q0 q1q1 q2q2 q1q1 q1q1 q2q2 stuck Input string: Adapted from J.E.Hopcroft 2001

1/29/02CSE460 - MSU7 Formal Definition of NFA Definition A nondeterministic finite automaton NFA is a 5- tuple M = (Q, , q 0, A,  ), where Q is a finite set of states  is a finite alphabet of input symbols q 0  Q is the initial state A  Q is the set of accepting states  : Q x   2 Q is the transition function, which maps every state and symbol to a set (possibly empty) of next states A string x is accepted by an NFA, if after processing x, at least one of the active states is an accepting state.

1/29/02CSE460 - MSU8 Extended Transition Function for NFAs Definition The extended transition function is the function  *: Q x  *  2 Q defined as follows. For any q  Q,  *(q,  ) = {q} For any y   *, a  , and q  Q, let q1=  *(q, y),  *(q, ya) = U p  q1  (p,a) Union of sets  (p,a) for each possible p in set  *(q,y)  *(q,x) is the set of active states of NFA after starting in state q and processing the symbols of x.

1/29/02CSE460 - MSU9 Example – Extended Transition Function Input 11010, what is  *(q 0,11010)?  *(q 0,  ) = {q 0 }  *(q 0,1) =  (q 0,1) = {q 0,q 1 }  *(q 0,11) =  (q 0,1) U  (q 1,1) = {q 0,q 1 } U  = {q 0,q 1 }  *(q 0,110) =  (q 0,0) U  (q 1,0) = {q 0 } U {q 2 } = {q 0,q 2 }  *(q 0,1101) =  (q 0,1) U  (q 2,1) = {q 0,q 1 }U  ={q 0,q 1 }  *(q 0,11010) =  (q 0,0) U  (q 1,0) = {q 0 }U{q 2 } ={q 0,q 2 } Is accepted by the NFA?

1/29/02CSE460 - MSU10 Exercise q0q0 q1q1 q2q2 0,1 0 0 q3q3 (a)Why this finite automata is nondeterministic? (q 0, 0) lead to three next states (b)Does NFA accept a string as long as there is a path to accepting state? yes (c) What is the next state from state q0 on input 0? States: q 0, q 1, q 3 (d) Give all possible paths for strings 01, 011, 00. For string 01 there are three paths: q 0 q 0 q 0, q 0 q 1 q 3, q 0 q 3 q 3 (e) Is the string 000 accepted by the above NFA? Yes (f) Give all strings that are accepted by the above NFA. Those that end with 00

1/29/02CSE460 - MSU11 Exercise 9.2. ab 1{1,2}{1} 2{3} 3{4} 4{5}  5  (b)  *(1,ab)?  *(1,a) = {1,2}  *(1,ab)=  *(1,b) U  *(2,b) = {1} U {3} = {1,3} a,b a b a (a)Give the transition diagram

1/29/02CSE460 - MSU12 Exercise ,1 0 q0q0 q1q1 Draw the transition diagram of an NFA for the regular expression: (0+1)* 0 (0+1)* 0,1

1/29/02CSE460 - MSU13 Example - Equivalent FA of NFA Q 1 =2 Q ={ ,{q 0 },{q 1 },{q 2 },{q 0,q 1 },{q 0,q 2 },{q 1,q 2 },{q 0,q 1,q 2 }} Initial state: {q 0 } A 1 = {{q 2 }, {q 0,q 2 }, {q 1,q 2 }, {q 0,q 1,q 2 }} The transition function is defined as follows:  1 ( , 0)=  1 ( , 1) =   1 ({q 0 },0) = {q 0 }  1 ({q 0 },1) = {q 0,q 1 }  1 ({q 1 },0) = {q 2 }  1 ({q 1 },1) =   1 ({q 2 },0) =   1 ({q 2 },1) =   1 ({q 0,q 1 },0) = {q 0,q 2 }  1 ({q 0,q 1 },1) = {q 0,q 1 }…

1/31/02CSE460 - MSU14 Example - Transition Table 01  {q 0 } {q 0,q 1 } {q 1 }{q 2 }   {q 0,q 1 }{q 0,q 2 }{q 0,q 1 } {q 0,q 2 }{q 0 }{q 0,q 1 } {q 1,q 2 }{q 2 }  {q 0,q 1,q 2 }{q 0,q 2 }{q 0,q 1 }

1/31/02CSE460 - MSU15 Example - Equivalent DFA 1 1 q0q0 q1q1 q2q {q 0 }{q 0,q 1 } {q 0,q 2 } Compare to original DFA? {q 2 }{q 1 } 0  1 0,1 {q 1,q 2 } 0 1 {q 0,q 1,q 2 } 1 0 0,1

1/31/02CSE460 - MSU16 Equivalence of NFAs and FAs Theorem For any NFA M = (Q, , q 0, A,  ) accepting a language L, there is a deterministic FA M 1 =(Q 1, , q 1, A 1,  1 ) that also accepts L. Proof idea: How would an FA simulate an NFA? It needs to keep track of all branches by remembering all active states at given points in the input; add, remove states as NFA operates. If the NFA has k states, there are 2 k subsets of states that need to be considered.

1/31/02CSE460 - MSU17 Proof – by Construction For any NFA M=(Q, , q 0, A,  ), let’s construct an FA M 1 =(Q 1, , q 1, A 1,  1 ):  Set of states: Q 1 = 2 Q  Initial state: q 1 = {q 0 }  Transition function: for q  Q 1, a  :  1 (q,a)=U p  q  (p,a) Union of the sets  (p,a) for each possible p in q (subset of Q).  Set of accepting states: A 1 = {q  Q 1 | q  A   } {q  Q 1 | q contains an accepting state of M} To prove that FA M 1 accepts the same language as NFA M, we need to prove that for any string x  *,  1 *(q 1,x)=  *(q 0,x).

1/31/02CSE460 - MSU18 Proof (cont.) Basis step:  1 *(q 1,  )= q 1 = {q 0 } =  *(q 0,  ) Induction hypothesis:  1 *(q 1,x) =  *(q 0,x) Statement to be shown: for any a ,  1 *(q 1, xa) =  *(q 0, xa)  1 *(q 1,xa) =  1 (  1 *(q 1, x), a) by recursive def. of  1 *() for FA =  1 (  *(q 0, x), a) by induction hypothesis = U p  *(q0, x)  (p, a) by def. of  1 () for equiv. FA =  *(q 0, xa) by recursive def. of  *() for NFA

1/31/02CSE460 - MSU19 Exercise 9.4. (a) Why does a single state in FA correspond to one or more states in NFA?  To keep track of all states where NFA can be at a given point. The initial state? {q 0 } (b)  1 ({q 0 }, 0) = ? {q 0,q 1 } (c) An accepting state of FA must contain an accepting state of the NFA. Why does it also allow non accepting states of NFA?  If NFA ends up in an accepting state, then the string is accepted even though other paths may lead to nonaccepting states.

1/31/02CSE460 - MSU20 Exercise {q 0 }{q 0,q 1 } 1 0,1 0 q0q0 q1q1 Q 1 =2 Q ={ ,{q 0 },{q 1 },{q 0,q 1 }} Initial state: {q 0 } A 1 = {{q 1 }, {q 0,q 1 }}  1 ( , 0) =  1 ( , 1) =   1 ({q 0 },0) =  (q 0,0) = {q 0,q 1 }  1 ({q 0 },1) =  (q 0,1) = {q 0 }  1 ({q 1 },0) =  (q 1,0) = {q 1 }  1 ({q 1 },1) =  (q 1,1) = {q 1 }  1 ({q 0,q 1 },0) =  (q 0,0) U  (q 1,0) = {q 0,q 1 } U {q 1 } = {q 0,q 1 }  1 ({q 0,q 1 },1) =  (q 0,1) U  (q 1,1) = {q 0 } U {q 1 } = {q 0,q 1 } The transition diagram of the NFA is: The transition diagram of the FA is then:

1/31/02CSE460 - MSU21 Summary NFAs are more general, and more practical than FAs Yet, NFAs recognize same class of languages as FAs (regular languages) For every state and input symbol, the transition function associates a set of states  NFA can be in 1 or more active states at once  NFA may get stuck (go to dead state) A string x is accepted by an NFA, if after processing x, at least one of the active states is an accepting state For every NFA, one can construct an equivalent FA, that recognizes the same language.

1/31/02CSE460 - MSU22 What Next? Extend NFA a little further  NFA-  : allow  -transitions Kleene’s Theorem