03a nondeterministic finite accepters

Post on 21-Apr-2017

227 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Non Deterministic Automata

2

{a}• Alphabet =

Nondeterministic Finite Accepter (NFA)

0q

1q

3q

2qa

a

a

3

{a}• Alphabet =

Nondeterministic Finite Accepter (NFA)

0q

1q

3q

2qa

a

a

Two choices

4

{a}• Alphabet =

Nondeterministic Finite Accepter (NFA)

0q

1q

3q

2qa

a

a

Two choices

No transition

No transition

5

Nondeterministic Finite Accepter (NFA)

0q

1q

3q

2qa

a

a

Input Stringa a

6

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a

7

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a

8

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a

All input is consumed

“accept"

9

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a

10

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a

11

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a

No further transition:the automaton hangs

12

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a

The input cannot be consumed

“reject"

13

NFA: Acceptance• An NFA accepts a string:

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

• all the input is consumed and 

• the automaton is in a final state.

14

Example

0q

1q

3q

2qa

a

a

is accepted by the NFA

“accept"

aa

0q

1q

3q

2qa

a

a“reject"

because this computation accepts 

15

Rejection Example

0q

1q

3q

2qa

a

a

Input Stringa

16

First Choice

0q

1q

3q

2qa

a

a

Input Stringa

“reject"

17

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa

18

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa

“reject"

19

NFA: RejectionAn NFA rejects a string:

when there  is no computation of the NFA that accepts the string:

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

• the input cannot be consumed

20

Example

0q

1q

3q

2qa

a

a

is rejected by the NFA

“reject"

a

0q

1q

3q

2qa

a

a“reject"

All possible computations leads to rejection 

21

Rejection Example

0q

1q

3q

2qa

a

a

Input Stringa a a

22

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a a

23

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a a

No transition; NFA hangs

24

First Choice

0q

1q

3q

2qa

a

a

Input Stringa a a

Input cannot be consumed

“reject"

25

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a a

No transition; NFA hangs

26

Second Choice

0q

1q

3q

2qa

a

a

Input Stringa a a

Input cannot be consumed

“reject"

27

Example

0q

1q

3q

2qa

a

a

is rejected by the NFA

“reject"

aaa

0q

1q

3q

2qa

a

a“reject"

All possible computations leads to rejection 

28

Language

0q

1q

3q

2qa

a

a

• Language accepted by the NFA: L {aa}

29

Lambda Transitions

0q 1q 2q 3qa a

30

Lambda Transitions

0q 1q 2q 3qa a

Input Stringa a

31

Lambda Transitions

0q 1q 2q 3qa a

Input Stringa a

32

Lambda Transitions

0q 1q 2q 3qa a

Input Stringa a

Read head does not move

33

Lambda Transitions

0q 1q 2q 3qa a

Input Stringa a

34

Lambda Transitions

0q 1q 2q 3qa a

Input Stringa a

String       is acceptedaa

“accept”

35

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

36

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

37

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

Read head does not move

38

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

39

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

No transition; NFA hangs

40

Rejection Example

0q 1q 2q 3qa a

Input Stringa a a

String        is rejectedaaa

“reject”

41

Language

0q 1q 2q 3qa a

Language accepted: L {aa}

42

Another NFA Example

0q 1q 2q 3qa b

Input Stringa b

43

Another NFA Example

0q 1q 2q 3qa b

Input Stringa b

44

Another NFA Example

0q 1q 2q 3qa b

Input Stringa b

45

Another NFA Example

0q 1q 2q 3qa b

Input Stringa b

“accept”

46

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

47

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

48

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

49

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

50

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

51

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

52

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

53

Another NFA Example

0q 1q 2q 3qa b

Another Input Stringa b a b

“accept”

54

Language Accepted

0q 1q 2q 3qa b

L ab, abab, ababab, ... ab

55

Another NFA Example

0q 1q 2q10,1

0

L(M) , 10, 1010, 101010, ... 10 *

Language accepted

56

Remarks

0q1M

1L(M )

• The        symbol never appears on the input tape 

• Extreme automata:

0q2M

2L(M )

57

Remarks

0q

1M

1L(M ) a

0q

2M

2L(M ) a

a0q 0q

a

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

aNFA DFA

58

Formal Definition of NFAs

0M Q, , , q , F

Q :

:

0q :

F :

Set of states,  i.e. 0 1 2q , q , q

: Input aplhabet, i.e. a, b

Transition function

Initial state

Final states

59

0 1q ,1 q

Transition Function 

0q 1q 2q10,1

0

60

1 0 2q , 0 q ,q

Transition Function 

0q 1q 2q10,1

0

61

1 0 2q , q ,q

Transition Function 

0q 1q 2q10,1

0

62

2q ,1

Transition Function 

0q 1q 2q10,1

0

63

Extended Transition Function 

0 1q ,a q

0q 1q 2q 3qa b

4q 5q

a a

64

Extended Transition Function 

0 4 5q ,aa q ,q

0q 1q 2q 3qa b

4q 5q

a a

65

Extended Transition Function 

0 0 2 3q ,ab q ,q ,q

0q 1q 2q 3qa b

4q 5q

a a

66

Formally

j iq q ,w

It holds

if and only if

there is a walk from        towith label 

iq jqw

67

The Language of an NFA

0 4 5q ,aa q ,q

M

aa L(M)

0 5F q ,q

0q 1q 2q 3qa b

4q 5q

a a

68

The Language of an NFA

0 2 3 0q ,ab q ,q ,q

M

ab L(M)

0 5F q ,q

0q 1q 2q 3qa b

4q 5q

a a

69

The Language of an NFA

0 4 5q ,abaa q ,q

M

abaa L(M)

0 5F q ,q

0q 1q 2q 3qa b

4q 5q

a a

70

The Language of an NFA

0 1q ,aba q

M

aba L(M)

0 5F q ,q

0q 1q 2q 3qa b

4q 5q

a a

71

The Language of an NFA

L(M) {aa} {ab} {ab} aa

M

0q 1q 2q 3qa b

4q 5q

a a

72

FormallyThe language accepted by NFA        is:

where

and there is some               (final state)  

M

1 2 3L M w ,w ,w ,...

0 m i j(q ,w ) {q ,q ,...}

kq F

73

0q kq

w

w

w

0(q ,w) w L M

kq F

iq

jq

Formally

74

1. Design an NFA for the language 

2. Design an NFA for the language 

3. Design an NFA for the language 

4. Design an NFA no more than 5 states for the language 

Exercises

75

5. Construct an NFA that accepts the language ∗

6. Construct an NFA with 3 states that accepts the language 

7. Find an NFA that accepts the language 

Exercises

top related