Automata

88
1 Non Deterministic Automata

Transcript of Automata

Page 1: Automata

1

Non Deterministic Automata

Page 2: Automata

2

1q 2q

3q

a

a

a

0q

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 3: Automata

3

1q 2q

3q

a

a

a

0q

Two choices

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 4: Automata

4

No transition

1q 2q

3q

a

a

a

0q

Two choices No transition

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 5: Automata

5

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 6: Automata

6

a a

0q

1q 2q

3q

a

a

a

First Choice

Page 7: Automata

7

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 8: Automata

8

a a

0q

1q 2q

3q

a

a

a “accept”

First Choice

Page 9: Automata

9

a a

0q

1q 2q

3q

a

a

Second Choice

a

Page 10: Automata

10

a a

0q

1q 2qa

a

Second Choice

a

3q

Page 11: Automata

11

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

Page 12: Automata

12

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

Page 13: Automata

13

Observation

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

Page 14: Automata

14

Example

aa is accepted by the NFA:

0q

1q 2q

3q

a

a

a

Page 15: Automata

15

Lambda Transitions

1q 3qa0q

1q a

Page 16: Automata

16

a a

1q 3qa0q

2q a

Page 17: Automata

17

a a

1q 3qa0q

2q a

Page 18: Automata

18

a a

1q 3qa0q

2q a

(read head doesn’t move)

Page 19: Automata

19

a a

1q 3qa0q

2q a

Page 20: Automata

20

a a

1q 3qa0q

2q a

“accept”

String is acceptedaa

Page 21: Automata

21

Language accepted: }{aaL

1q 3qa0q

2q a

Page 22: Automata

22

Another NFA Example

0q 1q 2qa b

3q

Page 23: Automata

23

a b

0q 1q 2qa b

3q

Page 24: Automata

24

0q 2qa b

3q

a b

1q

Page 25: Automata

25

a b

0q 1qa b

3q2q

Page 26: Automata

26

a b

0q 1qa b

3q2q

“accept”

Page 27: Automata

27

0qa b

a b

Another String

a b

1q 2q 3q

Page 28: Automata

28

0qa b

a b a b

1q 2q 3q

Page 29: Automata

29

0qa b

a b a b

1q 2q 3q

Page 30: Automata

30

0qa b

a b a b

1q 2q 3q

Page 31: Automata

31

0qa b

a b a b

1q 2q 3q

Page 32: Automata

32

0qa b

a b a b

1q 2q 3q

Page 33: Automata

33

0qa b

a b a b

1q 2q 3q

Page 34: Automata

34

a b a b

0qa b

1q 2q 3q

“accept”

Page 35: Automata

35

ab

ababababababL ...,,,

Language accepted

0q 1q 2qa b

3q

Page 36: Automata

36

Another NFA Example

0q 1q 2q0

11,0

Page 37: Automata

37

*10

...,101010,1010,10,

L

0q 1q 2q0

11,0

Language accepted

Page 38: Automata

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

Page 39: Automata

39

10 1, qq

0

11,0

Transition Function

0q 1q 2q

Page 40: Automata

40

0q

0

11,0

},{)0,( 201 qqq

1q 2q

Page 41: Automata

41

0q

0

11,0

1q 2q

},{),( 200 qqq

Page 42: Automata

42

0q

0

11,0

1q 2q

)1,( 2q

Page 43: Automata

43

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

10 ,* qaq

Page 44: Automata

44

540 ,,* qqaaq

0q

5q4q

3q2q1qa

aa

b

Page 45: Automata

45

0320 ,,,* qqqabq

0q

5q4q

3q2q1qa

aa

b

Page 46: Automata

46

Formally

wqq ij ,*It holds

if and only if

there is a walk from towith label

iq jqw

Page 47: Automata

47

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

Page 48: Automata

48

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

Page 49: Automata

49

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaaba

Page 50: Automata

50

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLaba

Page 51: Automata

51

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

Page 52: Automata

52

FormallyThe language accepted by NFA is:

where

and there is some

M

,...,, 321 wwwML

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

Fqk (final state)

Page 53: Automata

53

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

Page 54: Automata

54

Equivalence of NFAs and DFAs

Page 55: Automata

55

Equivalence of Machines

For DFAs or NFAs:

Machine is equivalent to machine

if

1M 2M

21 MLML

Page 56: Automata

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

Page 57: Automata

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

Page 58: Automata

58

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

Page 59: Automata

59

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

YES!

Page 60: Automata

60

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

Page 61: Automata

61

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

NFAs and DFAs have the same computation power

Page 62: Automata

62

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Page 63: Automata

63

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Proof: Every DFA is also an NFA

Page 64: Automata

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

Page 65: Automata

65

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Page 66: Automata

66

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Proof: Any NFA can be converted to anequivalent DFA

Page 67: Automata

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

Page 68: Automata

68

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 69: Automata

69

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

Page 70: Automata

70

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

Page 71: Automata

71

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

a

Page 72: Automata

72

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

Page 73: Automata

73

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 74: Automata

74

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 75: Automata

75

NFA to DFA: Remarks

We are given an NFA

We want to convert it to an equivalent DFA

With

M

M

)(MLML

Page 76: Automata

76

If the NFA has states

the DFA has states in the powerset

,...,, 210 qqq

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

Page 77: Automata

77

Procedure NFA to DFA

1. Initial state of NFA:

Initial state of DFA:

0q

0q

Page 78: Automata

78

Example

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 79: Automata

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

Page 80: Automata

80

Exampe

a

b

a

0q 1q 2q

NFA

0q 21,qqa

DFA

},{),(* 210 qqaq

210 ,, qqaq

Page 81: Automata

81

Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet,

untilno more transitions can be added.

Page 82: Automata

82

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 83: Automata

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

Page 84: Automata

84

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Fq 1

Fqq 21,

Page 85: Automata

85

Theorem Take NFA M

Apply procedure to obtain DFA M

Then and are equivalent :M M

MLML

Page 86: Automata

86

Finally

We have proven

Languages acceptedby NFAs

Languages acceptedby DFAs

Page 87: Automata

87

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular Languages

Page 88: Automata

88

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular LanguagesRegular Languages