Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan."— Presentation transcript:

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

2 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

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

4 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

5 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)*10 1 1 q0q0 q1q1 q2q2 0 0 0 1 Fig 3.3 (p.81)

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

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

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

9 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 11010 accepted by the NFA?

10 1/29/02CSE460 - MSU10 Exercise 9.1. 0 1 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

11 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} 13254 a,b a b a (a)Give the transition diagram

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

13 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 }…

14 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 }

15 1/31/02CSE460 - MSU15 Example - Equivalent DFA 1 1 q0q0 q1q1 q2q2 0 0 0 1 1 1 {q 0 }{q 0,q 1 } {q 0,q 2 } 0 0 0 1 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

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

17 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).

18 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

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

20 1/31/02CSE460 - MSU20 Exercise 9.5. 0 {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:

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

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


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

Similar presentations


Ads by Google