+ All Categories
Home > Documents > 1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)

1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)

Date post: 14-Dec-2015
Category:
Upload: wilson-gorman
View: 224 times
Download: 2 times
Share this document with a friend
85
1 Non Deterministic Automata
Transcript

1

Non Deterministic Automata

2

1q 2q

3q

a

a

a

0q

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

3

1q 2q

3q

a

a

a

0q

Two choices

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

4

No transition

1q 2q

3q

a

a

a

0q

Two choices No transition

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

5

a a

0q

1q 2q

3q

a

a

First Choice

a

6

a a

0q

1q 2q

3q

a

a

a

First Choice

7

a a

0q

1q 2q

3q

a

a

First Choice

a

8

a a

0q

1q 2q

3q

a

a

a “accept”

First Choice

All input is consumed

9

a a

0q

1q 2q

3q

a

a

Second Choice

a

10

a a

0q

1q 2qa

a

Second Choice

a

3q

11

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

12

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

Input cannot be consumed

13

An NFA accepts a string:when there is a computation of the NFAthat accepts the string

•All the input is consumed and the automaton is in a final state

14

Example

aa is accepted by the NFA:

0q

1q 2q

3q

a

a

a

“accept”

0q

1q 2qa

a

a

3q “reject”

because this computationaccepts aa

15

a

0q

1q 2q

3q

a

a

Rejection example

a

16

a

0q

1q 2q

3q

a

a

a

First Choice

17

a

0q

1q 2q

3q

a

a

a

First Choice

“reject”

18

Second Choice

a

0q

1q 2q

3q

a

a

a

19

Second Choice

a

0q

1q 2qa

a

a

3q

20

Second Choice

a

0q

1q 2qa

a

a

3q “reject”

21

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

• All the input is consumed and the automaton is in a non final state

• The input cannot be consumed

22

Example

a is rejected by the NFA:

0q

1q 2qa

a

a

3q “reject”

0q

1q 2qa

a

a

3q

“reject”

All possible computations lead to rejection

23

Rejection example

a a

0q

1q 2q

3q

a

a

a

a

24

a a

0q

1q 2q

3q

a

a

a

First Choice

a

25

a a

0q

1q 2q

3q

a

a

First Choice

a

a

No transition:the automaton hangs

26

a a

0q

1q 2q

3q

a

a

a “reject”

First Choice

a

Input cannot be consumed

27

a a

0q

1q 2q

3q

a

a

Second Choice

a

a

28

a a

0q

1q 2qa

a

Second Choice

a

3q

a

29

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

a

30

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

a

Input cannot be consumed

31

aaais rejected by the NFA:

0q

1q 2q

3q

a

a

a

“reject”

0q

1q 2qa

a

a

3q “reject”

All possible computations lead to rejection

32

1q 2q

3q

a

a

a

0q

Language accepted: }{aaL

33

Lambda Transitions

1q 3qa0q

2q a

34

a a

1q 3qa0q

2q a

35

a a

1q 3qa0q

2q a

36

a a

1q 3qa0q

2q a

(read head doesn’t move)

37

a a

1q 3qa0q

2q a

38

a a

1q 3qa0q

2q a

“accept”

String is acceptedaa

all input is consumed

39

a a

1q 3qa0q

2q a

Rejection Example

a

40

a a

1q 3qa0q

2q a

a

41

a a

1q 3qa0q

2q a

(read head doesn’t move)

a

42

a a

1q 3qa0q

2q a

a

No transition:the automaton hangs

43

a a

1q 3qa0q

2q a

“reject”

String is rejectedaaa

a

Input cannot be consumed

44

Language accepted: }{aaL

1q 3qa0q

2q a

45

Another NFA Example

0q 1q 2qa b

3q

46

a b

0q 1q 2qa b

3q

47

0q 2qa b

3q

a b

1q

48

a b

0q 1qa b

3q2q

49

a b

0q 1qa b

3q2q

“accept”

50

0qa b

a b

Another String

a b

1q 2q 3q

51

0qa b

a b a b

1q 2q 3q

52

0qa b

a b a b

1q 2q 3q

53

0qa b

a b a b

1q 2q 3q

54

0qa b

a b a b

1q 2q 3q

55

0qa b

a b a b

1q 2q 3q

56

0qa b

a b a b

1q 2q 3q

57

a b a b

0qa b

1q 2q 3q

“accept”

58

ab

ababababababL ...,,,

Language accepted

0q 1q 2qa b

3q

59

Another NFA Example

0q 1q 2q0

11,0

60

{ }{ }*10=

...,101010,1010,10,λ=)(ML

0q 1q 2q0

11,0

Language accepted

61

Remarks:

•The symbol never appears on the input tape

0q2M

0q1M

{}=)M(L 1 }λ{=)M(L 2

•Extreme automata:

62

0q

2q

1qa

a a

a

0q 1qa

}{=)( 1 aML

2M1M

}{=)( 2 aML

NFA DFA

•NFAs are interesting because we can express languages easier than DFAs

63

Formal Definition of NFAs FqQM ,,,, 0

:Q

::0q

:F

Set of states, i.e. 210 ,, qqq

: Input aplhabet, i.e. ba,Transition function

Initial state

Final states

64

10 1, qq

0

11,0

Transition Function

0q 1q 2q

65

0q

0

11,0

},{)0,( 201 qqq

1q 2q

66

0q

0

11,0

1q 2q

},{),( 200 qqq

67

0q

0

11,0

1q 2q

)1,( 2q

68

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

10 ,* qaq

69

540 ,,* qqaaq

0q

5q4q

3q2q1qa

aa

b

70

0320 ,,,* qqqabq

0q

5q4q

3q2q1qa

aa

b

71

Formally

wqq ij ,*It holds

if and only if

there is a walk from towith label

iq jqw

72

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

73

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

74

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaaba

75

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLaba

76

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

77

FormallyThe language accepted by NFA is:

where

and there is some

M

,...,, 321 wwwML

,...},{),(* 0 jim qqwq

Fqk (final state)

78

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

79

Equivalence of NFAs and DFAs

80

Equivalence of Machines

For DFAs or NFAs:

Machine is equivalent to machine

if

1M 2M

21 MLML

81

Example

0q 1q 2q

0

11,0

0q 1q 2q

0

11

0

1,0

NFA

DFA

*}10{1 ML

*}10{2 ML

1M

2M

82

Since

machines and are equivalent

*1021 MLML

1M 2M

0q 1q 2q

0

11,0

0q 1q 2q

0

11

0

1,0

DFA

NFA 1M

2M

83

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

84

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

YES!

85

Languages acceptedby NFAs

Languages acceptedby DFAs

Regular LanguagesRegular Languages

Thus, NFAs accept the regular languages


Recommended