Section 4.1 of Martin Textbook
This presentation is the property of its rightful owner.
Sponsored Links
1 / 22

Nondeterminism-NFA PowerPoint PPT Presentation


  • 55 Views
  • Uploaded on
  • Presentation posted in: General

Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan State University. Nondeterminism-NFA. Introduction. An NFA is a more general FA Easier to construct  More useful in proving theorems

Download Presentation

Nondeterminism-NFA

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Nondeterminism nfa

Section 4.1 of Martin Textbook

CSE460 – Computability & Formal Language Theory

Comp. Science & Engineering

Michigan State University

Nondeterminism-NFA

CSE460 - MSU


Introduction

CSE460 - MSU

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


Definition of fa reminder

CSE460 - MSU

Definition of FA - Reminder

Definition A finite automaton is a 5-tuple M=(Q,,q0,,A)

Q is a finite set of states

 is a finite alphabet of input symbols

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


Outline

CSE460 - MSU

Outline

Example NFA

Formal Definition of NFA

Extended Transition Function

Exercise

Equivalence of NFAs and FAs

Example Construction of Equivalent FA

Theorem

Summary


Nondeterminism nfa

CSE460 - MSU

Example - NFA

0,1

1

0

q0

q1

q2

Language accepted by above NFA?

Set of strings that end with 10. L = (0+1)*10

1

0

0

1

q0

q1

q2

1

Fig 3.3 (p.81)

0


Nondeterminism nfa

CSE460 - MSU

Example - Processing Input String

Input string: 11010

q0

q0

q0

q0

q0

q0

q1

q1

q1

stuck

q2

q2

stuck

1

1

0

1

0

Adapted from J.E.Hopcroft 2001


Formal definition of nfa

CSE460 - MSU

Formal Definition of NFA

Definition A nondeterministic finite automaton NFA is a 5-tuple M = (Q, , q0, A, ), where

Q is a finite set of states

 is a finite alphabet of input symbols

q0 Q is the initial state

A  Q is the set of accepting states

: Q x  2Q 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.


Extended transition function for nfas

CSE460 - MSU

Extended Transition Function for NFAs

Definition The extended transition function is the function *: Q x *  2Q defined as follows.

For any q  Q, *(q, ) = {q}

For any y *, a , and q  Q, let q1= *(q, y),

*(q, ya) = Up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.


Example extended transition function

CSE460 - MSU

Example – Extended Transition Function

Input 11010, what is *(q0,11010)?

*(q0,) = {q0}

*(q0,1) = (q0,1) = {q0,q1}

*(q0,11) = (q0,1) U(q1,1) = {q0,q1} U  = {q0,q1}

*(q0,110) = (q0,0) U(q1,0) = {q0} U {q2} = {q0,q2}

*(q0,1101) = (q0,1) U(q2,1) = {q0,q1}U ={q0,q1}

*(q0,11010) = (q0,0) U (q1,0) = {q0}U{q2} ={q0,q2}

Is 11010 accepted by the NFA?


Nondeterminism nfa

CSE460 - MSU

Exercise 9.1.

0,1

0

0

q0

q1

q2

0

1

0,1

q3

0,1

  • Why this finite automata is nondeterministic? (q0, 0) lead to three next states

  • 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: q0, q1, q3

    (d) Give all possible paths for strings 01, 011, 00.

    For string 01 there are three paths: q0q0q0, q0q1q3, q0q3q3

    (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


Exercise 9 2

Exercise 9.2.

Give the transition diagram

b

a,b

1

2

3

4

5

a

a,b

a,b

a

(b) *(1,ab)?

*(1,a) = {1,2}

*(1,ab)= *(1,b) U*(2,b)

= {1} U {3}

= {1,3}

CSE460 - MSU


Nondeterminism nfa

CSE460 - MSU

Exercise 9.3.

Draw the transition diagram of an NFA for the regular expression: (0+1)* 0 (0+1)*

0,1

0,1

0

q0

q1


Example equivalent fa of nfa

CSE460 - MSU

Example - Equivalent FA of NFA

Q1=2Q={,{q0},{q1},{q2},{q0,q1},{q0,q2},{q1,q2},{q0,q1,q2}}

Initial state: {q0} A1= {{q2}, {q0,q2}, {q1,q2}, {q0,q1,q2}}

The transition function is defined as follows:

1(, 0)= 1(, 1) = 

1({q0},0) = {q0}1({q0},1) = {q0 ,q1}

1({q1},0) = {q2}1({q1},1) = 

1({q2},0) = 1({q2},1) = 

1({q0,q1},0) = {q0,q2}1({q0,q1},1) = {q0,q1}…


Example transition table

Example - Transition Table

CSE460 - MSU


Nondeterminism nfa

CSE460 - MSU

Example - Equivalent DFA

{q0,q1,q2}

1

0,1

1

0

0

1

0

1

{q0}

{q0,q1}

{q0,q2}

1

{q1,q2}

0,1

1

0

{q1}

{q2}

0

0

Compare to original DFA?

1

0

0

1

q0

q1

q2

1

0


Equivalence of nfas and fas

CSE460 - MSU

Equivalence of NFAs and FAs

Theorem For any NFA M = (Q, , q0, A, ) accepting a language L, there is a deterministic FA M1=(Q1,, q1, A1,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 2k subsets of states that need to be considered.


Proof by construction

CSE460 - MSU

Proof – by Construction

For any NFA M=(Q, , q0, A, ), let’s construct an FA M1=(Q1, , q1, A1, 1):

Set of states: Q1 = 2Q

Initial state: q1= {q0}

Transition function: for q Q1, a: 1(q,a)=Upq(p,a)

Union of the sets (p,a) for each possible p in q (subset of Q).

Set of accepting states: A1= {q Q1 | q  A}

{q Q1 | q contains an accepting state of M}

To prove that FA M1 accepts the same language as NFA M, we need to prove that for any string x *, 1*(q1,x)=*(q0,x).


Proof cont

CSE460 - MSU

Proof (cont.)

Basis step: 1*(q1, )= q1= {q0} = *(q0, )

Induction hypothesis: 1*(q1,x) = *(q0,x)

Statement to be shown: for any a , 1*(q1, xa) = *(q0, xa)

1*(q1,xa) = 1(1*(q1, x), a) by recursive def. of 1*() for FA

= 1(*(q0, x), a) by induction hypothesis

= Up*(q0, x)(p, a) by def. of 1() for equiv. FA

= *(q0, xa) by recursive def. of *() for NFA


Exercise 9 4

CSE460 - MSU

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? {q0}

(b) 1({q0}, 0) = ? {q0,q1}

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


Nondeterminism nfa

CSE460 - MSU

Exercise 9.5.

0,1

0,1

The transition diagram of the NFA is:

0

q0

q1

Q1=2Q={,{q0},{q1},{q0,q1}} Initial state: {q0} A1= {{q1}, {q0,q1}}

1(, 0) = 1(, 1) = 

1({q0},0) = (q0,0) = {q0 ,q1}1({q0},1) = (q0,1) = {q0}

1({q1},0) = (q1,0) = {q1}1({q1},1) = (q1,1) = {q1}

1({q0,q1},0) = (q0,0) U(q1,0) = {q0,q1} U {q1} = {q0,q1}

1({q0,q1},1) = (q0,1) U(q1,1) = {q0} U {q1} = {q0,q1}

0,1

1

The transition diagram of the FA is then:

0

{q0}

{q0,q1}


Summary

CSE460 - MSU

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.


What next

CSE460 - MSU

What Next?

Extend NFA a little further

NFA-: allow -transitions

Kleene’s Theorem


  • Login