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

Nondeterministic Finite Accepter (NFA)

Alphabet = {a}

Non Deterministic Automata

q1

q0

q2

q3
1

Nondeterministic Finite Accepter (NFA)

Nondeterministic Finite Accepter (NFA)

Alphabet = {a}
Two choices
a

q0

Alphabet = {a}

q1

Two choices
a

q2

q0

q1

q2

No transition

q3

q3

No transition

First Choice

First Choice

a a

a a

q0

q1

q2

q0

q3

q1

q2

q3
5

1
PDF created with pdfFactory Pro trial version www.pdffactory.com

First Choice

First Choice
a a

a a
All input is consumed
a

q0

q1

q2

q0

q1

q2

accept

q3

q3
7

Second Choice

Second Choice

a a

a a

q0

q1

q2

q0

q1

q2

q3

q3
9

10

Second Choice

Second Choice

a a

a a
Input cannot be consumed
a

q0

q1

q3

q2

q0

No transition:
the automaton hangs

q1

q2

q3
11

reject
12

2
PDF created with pdfFactory Pro trial version www.pdffactory.com

Example

An NFA accepts a string:


when there is a computation of the NFA
that accepts the string

aa

is accepted by the NFA:


accept
q1

All the input is consumed and the automaton


is in a final state

q0

q2

q0

q1 a

q3

q3

q2

reject

because this computation


accepts aa
13

14

Rejection example

First Choice

q0

q1

q2

q0

q1

q2

q3

q3
15

16

First Choice

Second Choice

a
reject
a

q0

q1

q2

q0

q3

q1

q2

q3
17

18

3
PDF created with pdfFactory Pro trial version www.pdffactory.com

Second Choice

Second Choice

q0

q1

q2

q1

q0

q2

q3

q3

reject

19

20

Example
An NFA rejects a string:
when there is no computation of the NFA
that accepts the string

is rejected by the NFA:


reject

All the input is consumed and the


automaton is in a non final state

q0

q1 a

21

q0

reject

q1 a

q2

q3

All possible computations lead to rejection

22

Rejection example

First Choice

a a a

a a a

q0

q3

The input cannot be consumed

q2

q1

q2

q0

q3

q1

q2

q3
23

24

4
PDF created with pdfFactory Pro trial version www.pdffactory.com

First Choice

First Choice
a a a

a a a
Input cannot be consumed
a

q0

q1

q2

No transition:
the automaton hangs

q3

q0

q1

q2

q3

25

26

Second Choice

Second Choice

a a a

a a a

q0

reject

q1

q2

q0

q1

q2

q3

q3
27

28

Second Choice

Second Choice

a a a

a a a
Input cannot be consumed
a

q0

q1

q3

q2

q0

No transition:
the automaton hangs

q1

q2

q3
29

reject
30

5
PDF created with pdfFactory Pro trial version www.pdffactory.com

aaa

is rejected by the NFA:

Language accepted:

reject
a

q0

q1

q2

q0

q1 a

q3

q3

q2

q0

reject

q1

L = {aa}
q2

q3

All possible computations lead to rejection

31

32

Lambda Transitions
a a

q0

q1

q2

q3

q0

q1

q2

q3

33

34

(read head doesnt move)


a a

a a

q0

q1

q2

q3

q0

35

q1

q2

q3

36

6
PDF created with pdfFactory Pro trial version www.pdffactory.com

all input is consumed


a a

a a

accept

q0

q1

q2

q3

q0
String

q1

q2

q3

aa is accepted

37

38

Rejection Example
a a a

q0

a a a

q1

q2

q3

q0

q1

q2

q3

39

40

(read head doesnt move)


a a a

q0

a a a

q1

q2

q3

q0

q1

q2

q3

No transition:
the automaton hangs
41

42

7
PDF created with pdfFactory Pro trial version www.pdffactory.com

Input cannot be consumed


a a a
Language accepted:

L = {aa}

reject

q0
String

q1

q2

q3

q0

q1

q2

q3

aaa is rejected
43

44

Another NFA Example

a b

q0

q1

q2

q3

q0

q1

q2

q3

45

a b

q0

46

a b

q1

q2

q3

q0

q1

q2

q3

47

48

8
PDF created with pdfFactory Pro trial version www.pdffactory.com

Another String

a b

a b a b

accept

q0

q1

q2

q3

q0

q1

q2

q3

49

a b a b

q0

50

a b a b

q1

q2

q3

q0

q1

q2

q3

51

a b a b

q0

52

a b a b

q1

q2

q3

q0

q1

q2

q3

53

54

9
PDF created with pdfFactory Pro trial version www.pdffactory.com

a b a b

q0

a b a b

q1

q2

q3

q0

q1

q2

q3

55

56

Language accepted

L = {ab, abab, ababab, ...}

a b a b

= {ab}+
accept

q0

q1

q2

q3

q0

q1

q2

q3

57

58

Another NFA Example

Language accepted

L (M ) = {, 10, 1010, 101010, ...}


= {10} *

q0

q1

0, 1 q
2

q0

q1

0, 1 q
2

59

60

10
PDF created with pdfFactory Pro trial version www.pdffactory.com

Remarks:

NFAs are interesting because we can


express languages easier than DFAs

The symbol never appears on the


input tape
Extreme automata:

NFA

M1
q0

M2

L( M1 ) = {}

L( M 2 ) = {}

q0

DFA

M1

q2

q1

q0
q0
61

L ( M1 ) = {a}

M = (Q, , , q0 , F )
Set of states, i.e.

{q0 , q1, q2}

Input aplhabet, i.e.

{a, b}

Initial state

F:

Final states

L ( M 2 ) = {a}

q0

q1

0, 1 q
2

(q1,0) = {q0 , q2}

64

(q0 , ) = {q0 , q2}

62

63

q0

q1

(q0 , 1) = {q1}

: Transition function

q0 :

a
a

Transition Function

Formal Definition of NFAs

Q:

M2

q1

0, 1 q
2

q0

q1

0, 1 q
2

65

66

11
PDF created with pdfFactory Pro trial version www.pdffactory.com

Extended Transition Function *

* (q0 , a ) = {q1}

(q2 ,1) =
0

q0

q1

q5

q4

0, 1 q
2

a
a

q0

q0

a
b

q2

q3

q0

68

a
b

q1

q3
70

The Language of an NFA M

F = {q0 ,q5 }

q j * (qi , w)

q5

q4
a

q0

if and only if
there is a walk from
with label w

q2

69

Formally
It holds

q3

q5

q4

q1

* (q0 , ab ) = {q2 , q3 , q0 }

q5
a

q2

* (q0 , aa ) = {q4 , q5 }

q1

67

q4

a
b

q1

q2

q3

qi

to

qj

* (q0 , aa ) = {q4 , q5 }
71

aa L(M )
72

12
PDF created with pdfFactory Pro trial version www.pdffactory.com

F = {q0 ,q5 }

q0

F = {q0 ,q5 }

q5

q4

q5

q4

a
b

q1

q2

q3

q0

a
b

q1

q2

q3

* (q0 , ab ) = {q2 , q3 , q0 }

* (q0 , abaa) = {q4 , q5 }

ab L(M )

aaba L (M )

73

F = {q0 ,q5 }

q5

q4
a

q0

74

a
b

q1

q5

q4
q2

q3

q0

q1

* (q0 , aba ) = {q1}

a
q2

q3

L( M ) = {aa} {ab}* {ab}+ {aa}

aba L( M )
75

76

Formally
The language accepted by NFA

w L(M )

is:

L( M ) = {w1, w2 , w3 ,...}

* (q0 , w)
qi

w
where

q0

* (q0 , wm ) = {qi , q j ,...}

qk

w
w

and there is some

qk F

qk F

qj

(final state)
77

78

13
PDF created with pdfFactory Pro trial version www.pdffactory.com

Equivalence of Machines
For DFAs or NFAs:

Equivalence of NFAs and DFAs

Machine
if

M1

is equivalent to machine

M2

L ( M1 ) = L ( M 2 )

79

Example

L( M1 ) = {10} *

NFA

q1

q0

0, 1

machines

NFA

M2

0,1

q2

and

are equivalent

M2
0

M1

q0

q1

0, 1

q2

DFA

M2

q0

q1

q2

81

Equivalence of NFAs and DFAs

NFAs

M1

0,1

q1
0

Question:

L( M1 ) = L(M 2 ) = {10}*

q2

DFA

L( M 2 ) = {10} *

Since

M1

q0

80

82

Equivalence of NFAs and DFAs

DFAs ?

Question:

Same power?
Accept the same languages?

NFAs

DFAs ?

YES!

Same power?
Accept the same languages?

83

84

14
PDF created with pdfFactory Pro trial version www.pdffactory.com

We will prove:
Languages
accepted
by NFAs

Step 1

Languages
accepted
by DFAs

Languages
accepted
by NFAs

A language accepted by a DFA


is also accepted by an NFA

85

Step 2

NFA

M
q0

DFA

DFA

q1

q2

{q0 }

87

88

NFA

M
q0

DFA

{q0 }

NFA to DFA
a
a
q
q1
2
b

M
q0

Proof: Any NFA can be converted to an


equivalent DFA

NFA

86

NFA to DFA
a

Languages
accepted
by DFAs

A language accepted by an NFA


is also accepted by a DFA

Proof: Every DFA is trivially an NFA

NFAs and DFAs have the same


computation power

Languages
accepted
by NFAs

Languages
accepted
by DFAs

NFA to DFA
a
a
q
q1
2
b

{q0 }

{q1, q2 }

{q1, q2 }

89

90

15
PDF created with pdfFactory Pro trial version www.pdffactory.com

NFA

M
q0

DFA

NFA to DFA
a
a
q
q1
2
b

NFA

q0

{q0 }

DFA

NFA to DFA
a
a
q
q1
2
b

{q0 }

{q1, q2 }

{q1, q2 }

91

NFA

NFA to DFA
a

M
q0

q1

92

NFA

M
q0

q2

NFA to DFA
a
L( M ) = L(M )
a

q
q
1

b
DFA

b
a

{q0 }

DFA

{q0 }

{q1, q2 }

{q1, q2 }

b
a, b

a, b

93

94

NFA to DFA: Remarks


If the NFA has states
We are given an NFA

q0 , q1, q2 ,...

We want to convert it
to an equivalent DFA M

the DFA has states in the powerset

, {q0 }, {q1}, {q1, q2 }, {q3 , q4 , q7 },....


With

L( M ) = L (M )
95

96

16
PDF created with pdfFactory Pro trial version www.pdffactory.com

Procedure NFA to DFA


NFA

1.

Example
a

M
q0

Initial state of NFA:

q1

q0

q2

b
DFA

Initial state of DFA:

{q0 }

{q0}
97

98

Procedure NFA to DFA

2. For every DFAs state {qi , q j ,...,qm}

NFA

Exampe
a

M
q0

Compute in the NFA

q1

q2

b
* (q0 , a ) = {q1, q2 }

* (qi , a ),

* (q j , a ),

= {qi , qj ,..., qm }

DFA M

...

{q0 }

Add transition to DFA

({qi , q j ,..., qm }, a ) = {qi , qj ,..., qm }

{q1, q2 }

({q0 }, a ) = {q1, q2 }
99

100

Procedure NFA to DFA


NFA

Example
a

M
q0

Repeat Step 2 for all letters in alphabet,


until
no more transitions can be added.

q1

q2

b
DFA

{q0 }

{q1, q2 }

101

a, b
102

17
PDF created with pdfFactory Pro trial version www.pdffactory.com

Procedure NFA to DFA

3. For any DFA state {qi , q j ,..., qm }

NFA

Example
a

M
q0

q1

q2

q1 F

b
If some

qj

is a final state in the NFA


DFA

{q0 }

Then, {qi , q j ,..., qm }


is a final state in the DFA

b
a

{q1, q2 }
{q1, q2 } F

b
a, b

103

Take NFA

Theorem

Finally

We have proven

Apply procedure to obtain DFA

Then

104

and

Languages
accepted
by NFAs

are equivalent :

Languages
accepted
by DFAs

L( M ) = L(M )
105

106

We have proven
Languages
accepted
by NFAs

We have proven

Languages
accepted
by DFAs

Languages
accepted
by NFAs

Regular Languages

Regular Languages

107

Languages
accepted
by DFAs
Regular Languages

108

18
PDF created with pdfFactory Pro trial version www.pdffactory.com

We have proven
Languages
accepted
by NFAs
Regular Languages

Languages
accepted
by DFAs
Regular Languages

Thus, NFAs accept the regular languages


109

19
PDF created with pdfFactory Pro trial version www.pdffactory.com

You might also like