Non-Deterministic Finite Automata

Post on 21-Jan-2016

129 views 7 download

Tags:

description

Non-Deterministic Finite Automata. Nondeterministic Finite Automaton (NFA). Alphabet =. Alphabet =. Two choices. Alphabet =. Two choices. No transition. No transition. First Choice. First Choice. First Choice. First Choice. All input is consumed. “accept”. Second Choice. - PowerPoint PPT Presentation

transcript

1

Non-Deterministic Finite Automata

2

1q 2q

3q

a

a

a

0q

}{aAlphabet =

Nondeterministic Finite Automaton (NFA)

3

1q 2q

3q

a

a

a

0q

Two choices

}{aAlphabet =

4

No transition

1q 2q

3q

a

a

a

0q

Two choices No transition

}{aAlphabet =

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 automatonis in an accepting state

There is a computation:

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

OR

For each computation:

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 does not 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

(redundant state)

61

Remarks:

•The symbol never appears on the input tape

0q2M

0q1M

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

•Simple automata:

62

0q

2q

1qa

a

a

0q 1qa

}{=)( 1 aML

2M1M

}{=)( 2 aML

NFA FA

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

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

Accepting 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 ,* : there is a walk from to with label

iq jqw

iq jq

w

kw 211 2 k

iq jq

72

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

F

73

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

F

74

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaabaF

75

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLabaF

76

0q

5q4q

3q2q1qa

aa

b

}{* aaabML

77

FormallyThe language accepted by NFA is:

where

and there is some

M

,...,, 321 wwwML

},,...,,{),(* 0 kjim qqqwq

Fqk (accepting state)

78

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq