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

Post on 01-Apr-2015

222 views 0 download

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

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”

13

Observation

An NFA accepts a stringifthere is a computation of the NFAthat accepts the string

14

Example

aa is accepted by the NFA:

0q

1q 2q

3q

a

a

a

15

Lambda Transitions

1q 3qa0q

1q a

16

a a

1q 3qa0q

2q a

17

a a

1q 3qa0q

2q a

18

a a

1q 3qa0q

2q a

(read head doesn’t move)

19

a a

1q 3qa0q

2q a

20

a a

1q 3qa0q

2q a

“accept”

String is acceptedaa

21

Language accepted: }{aaL

1q 3qa0q

2q a

22

Another NFA Example

0q 1q 2qa b

3q

23

a b

0q 1q 2qa b

3q

24

0q 2qa b

3q

a b

1q

25

a b

0q 1qa b

3q2q

26

a b

0q 1qa b

3q2q

“accept”

27

0qa b

a b

Another String

a b

1q 2q 3q

28

0qa b

a b a b

1q 2q 3q

29

0qa b

a b a b

1q 2q 3q

30

0qa b

a b a b

1q 2q 3q

31

0qa b

a b a b

1q 2q 3q

32

0qa b

a b a b

1q 2q 3q

33

0qa b

a b a b

1q 2q 3q

34

a b a b

0qa b

1q 2q 3q

“accept”

35

ab

ababababababL ...,,,

Language accepted

0q 1q 2qa b

3q

36

Another NFA Example

0q 1q 2q0

11,0

37

*10

...,101010,1010,10,

L

0q 1q 2q0

11,0

Language accepted

38

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

39

10 1, qq

0

11,0

Transition Function

0q 1q 2q

40

0q

0

11,0

},{)0,( 201 qqq

1q 2q

41

0q

0

11,0

1q 2q

},{),( 200 qqq

42

0q

0

11,0

1q 2q

)1,( 2q

43

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

10 ,* qaq

44

540 ,,* qqaaq

0q

5q4q

3q2q1qa

aa

b

45

0320 ,,,* qqqabq

0q

5q4q

3q2q1qa

aa

b

46

Formally

wqq ij ,*It holds

if and only if

there is a walk from towith label

iq jqw

47

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

48

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

49

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaaba

50

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLaba

51

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

52

FormallyThe language accepted by NFA is:

where

and there is some

M

,...,, 321 wwwML

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

Fqk (final state)

53

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

54

Equivalence of NFAs and DFAs

55

Equivalence of Machines

For DFAs or NFAs:

Machine is equivalent to machine

if

1M 2M

21 MLML

56

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

57

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

58

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

59

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

YES!

60

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

61

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

NFAs and DFAs have the same computation power

62

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

63

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Proof: Every DFA is also an NFA

64

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Proof: Every DFA is also an NFA

A language accepted by a DFAis also accepted by an NFA

65

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

66

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Proof: Any NFA can be converted to anequivalent DFA

67

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Proof: Any NFA can be converted to anequivalent DFA

A language accepted by an NFAis also accepted by a DFA

68

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q

69

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

70

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

71

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

a

72

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

73

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

74

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

75

NFA to DFA: Remarks

We are given an NFA

We want to convert it to an equivalent DFA

With

M

M

)(MLML

76

If the NFA has states

the DFA has states in the powerset

,...,, 210 qqq

,....,,,,,,, 7432110 qqqqqqq

77

Procedure NFA to DFA

1. Initial state of NFA:

Initial state of DFA:

0q

0q

78

Example

a

b

a

0q 1q 2q

NFA

DFA

0q

79

Procedure NFA to DFA

2. For every DFA’s state

Compute in the NFA

Add transition

},...,,{ mji qqq

...

,,*

,,*

aq

aq

j

i

},...,,{ mji qqq

},...,,{},,...,,{ mjimji qqqaqqq

80

Exampe

a

b

a

0q 1q 2q

NFA

0q 21,qqa

DFA

},{),(* 210 qqaq

210 ,, qqaq

81

Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet,

untilno more transitions can be added.

82

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

83

Procedure NFA to DFA

3. For any DFA state

If some is a final state in the NFA

Then, is a final state in the DFA

},...,,{ mji qqq

jq

},...,,{ mji qqq

84

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Fq 1

Fqq 21,

85

Theorem Take NFA M

Apply procedure to obtain DFA M

Then and are equivalent :M M

MLML

86

Finally

We have proven

Languages acceptedby NFAs

Languages acceptedby DFAs

87

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular Languages

88

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular LanguagesRegular Languages