Non-Deterministic Finite Automata (NFA)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Non-deterministic Finite Automata (NFA)

Models of Computation

NFA versus DFA


In a DFA, at every state , for every symbol , there is a unique -transition

This is not necessarily so in an NFA. At any state, an NFA may have multiple -transitions, or none.

We may think of the non-determinism as a kind of parallel computation wherein several processes can be running concurrently. When the NFA splits to follow several choices, that corresponds to a process forking into several children, each proceeding separately. If at least one of these accepts, then the entire computation accepts.

Models of Computation

    

are labelled by symbols from

. I.e. an NFA may have -transitions.

In a DFA, transition arrows are labelled by symbols from

i.e. there is a unique

such that

; in an NFA, they

Example: All strings containing a 1 in third position from the end


0 ' ) % # ! &$"  1 2) ( ( 

NFAs are more compact - they generally require fewer states to recognize a language.
Models of Computation 3

Example:

is a multiple of 2 or 3

Using -transitions and non-determinism, a language dened by an NFA can be easier to understand.

Models of Computation

888 77B4

588 97B4

8 58 69B4

88 5 7A@4

8 55 6764

58 5 9664

558 79B4

555 7764

DFA:

0 0
4

1 3) 0

1 2) 0

0 ) )

NFA:

Denition: NFA

Models of Computation

Some denitions and notations

(not necessarily all distinct) such that

Models of Computation

hc&D u2 x " 3B u x yr

c e e hdD x rre

cb dD

For

where each

c h&D

c c h&D u h&D u u3 x 62B6rrrI u 6 I u x I e e e I u u x e e e u D 3y6rrwvtsa

-transitions in

from

to

iff there are

C D qpi

iff

or there is a sequence

h rre e e

cg &D e f

where

is a nal state. Here

is dened by: of one or more

, the language accepted by

W V I T I S I I GE XAUB66RQPHFD

Fix an NFA

. , consists of all strings over satisfying

W I E S pnm y6y9y& q7D x

    i$w

For

we dene

G HE

presented as a relation, i.e. a subset of

GfvWWiuhgf   E G

 G tlk

r se

Note:

r pnm W G w qoD XHE j

G lk

 hdD c

W C `9E

cb T dD B

(v)

G e yXS

(iv)

is the set of nal states. is the power set of . Equivalently can be

W G XHE j

W     E ighgf

G T iB

(iii)

(ii)

(i)

is a nite set of states is a nite alphabet is the start state is the transition function

W V I T I S I I G dAU6AQHE

A nondeterministic nite automaton (NFA) is a 5-tuple

where

before or after each one.

Models of Computation

Equivalence of NFAs and DFAs: The Subset Construction

Observation. Every DFA is an NFA! Say two automata are equivalent if they accept the same language. Theorem(Determinization). Every NFA has an equivalent DFA. Proof. Fix an NFA DFA , we construct an equivalent

Models of Computation

in

iff

in

D W C `E

such that

W uC j E

c e e e e e dD rrrrre B

c E &D 9$Xe D 

W z AI z 6I z AI z QI z HFD  V   S   GE W ~A{6}6X|QX{HFD C z V I z I z S I z I z GE

 D z V e ppt~3z  ~ qoD m G pn

c dD u

 z G k e pnm } q7D z  G

c dD r

hdD c

e pn z 2X qoD m

C j

z pn | qoD m

x 6BrrrI u I e e e

exist

such that

cb dD

u x e e e u D 3yArrwpa

Exercise. Writing

cb dD

that

(thus, by abuse of notation, we write , we have

).

is equivalent to: there

qpDWaI9 S E $a

G d

Note: In case

is a DFA, for any

and

, there is a unique

$a

cb e G &D 2F ~9 S  D W a I E

We shall sometimes write

, for

symbols in

occur in the correct order, but with 0 or more -transitions

There is a sequence of transitions from

cb &D

Intuitively

means: to in in which the

. such

z 

z  V

 z

C j

C j

z V ~ x

c e e e e e &D rrBrre
. Suppose

c &D u

c &D r

z
sequence of

W uC j E Y

  z 3e D z W`E C  Y k W C v`E Y

1 3)

5 B64 ) 0 ) 1 8 5 @r4 64 ) 0 8 B4 ( 5 64 C ) 0 C j
DFA

8 @r4 0

NFA

Note. State

 T Urq

Models of Computation

Suppose

Proof of

Example. All words that begin with a string of 0s followed by a string of 1s.

is redundant.

. Then

for some

. Hence

z  &

WuCE Y WuC j E  Y z V ~&

z V{ h&D c

c h&D z

and so,

Now take any non-null

x rre u p e e D

Since

is deterministic, feeding

x I e e e I u y6rrr

-transitions

e e e e e rrBrre

z  C j

where

-transitions

i.e.

to it results in the sequence of

in

 W `C

in

 W uC

D D

& u

c E u &D 9$Xe  c E &D 9}z  X& e

By denition of

. . .

, from (1), we have . . .

, and so

e e rre $
,

u $ u

z  S

Models of Computation

. Then there is a

, and so , (2) (1)


9

10

Proof of Suppose

equivalently, for some

. Hence

Now suppose some non-null of

. I.e. there is a sequence containing some

-transitions of the form (2) with . Now since with

i.e. with

, by denition of in

, there is some

. Working backwards in this way, we can

build up a sequence of

-transitions like (1), until we deduce that -transitions with

Thus we get a sequence of

, and hence

Models of Computation

Closure under regular operations revisited

Using nondeterminism makes some proofs much easier. Theorem. Regular languages are closed under union.

of (the respective state transition graphs of)

Models of Computation

u C

start state of

and

and

, and a -transition from

to each

adding a new start state

to the disjoint union

W E C

 W u E C

Dene

that accepts

u wC

Take NFAs

and

by

W`CE $ Y u &D c z

D  w

h&D c

V x C z C f x dD u x C c x 2 x z  S x i  V x z  W `C j E x Arre u p e e D Y W`E C  Y z e  z 3d~V

. Then

i.e.

V x z B

V hc&D z z z  z  V W`C j E  Y W`CE kWuC j E Y Y WC j E  Y x x iB f f u x u x zV x C j u C

 V x z i

, and hence

because

. Thus (2) shows that

, or

11

12

Theorem. Regular languages are closed under concatenation.

of

Models of Computation

Theorem. Regular languages are closed under star. First attempt:

accepts

from each accepting state to the start state.

What is wrong with this?

Models of Computation

accepting, and by adding a new -transition

u C

Obtain

u C W u V I u I u S I I u GE D u QA6r6RQHFwC

Take an NFA

that

. Construct

that accepts .

from

by making the start state

e e e rr$ u u  u D u    

C C

of

. The accepting states of

are those

u C

each accepting state of

to the start state

state of

, and by adding an -transition from

u C

by making the start state of

the start

be obtained from the disjoint union of

u C W E C

e W u E C

An NFA

that accepts

u C

Take NFAs

and

can and


13 14

( 8 (

( ( 0 )
E.g.

W u E C Y 9F D W E E 9FD W t9E
which is not in

( 0 )
The above construction gives the NFA

Consider the two-node two-edge NFA

u C

that accepts

 vlUe

(namely the language

dened by the regular expression

But

accepts

The NFA

accepts

accepts

W u C AwE

Models of Computation

Take an NFA

W u AI u 6I u 6RQI u hFD u C V S I GE

Dene

W U T RAI T 66RQ2 T lHE   u V I S I I   u G

where

Second (correct) attempt:

C C

Proof: Regular languages are closed under star

).

that accepts

and

u V

and

 D

and

 D

and

 D

and

 D

T D Bpi D T pi u V d u V d u d G  u &

D W I E u69S  u   W I E u &69qS W I E u 69qS W I 69E u S

Models of Computation

16 15

u {

You might also like