non deterministic automata

88
1 Non Deterministic Automata

Upload: chul

Post on 06-Feb-2016

26 views

Category:

Documents


0 download

DESCRIPTION

Non Deterministic Automata. Nondeterministic Finite Accepter (NFA). Alphabet =. Nondeterministic Finite Accepter (NFA). Alphabet =. Two choices. Nondeterministic Finite Accepter (NFA). Alphabet =. Two choices. No transition. No transition. First Choice. First Choice. First Choice. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Non Deterministic Automata

1

Non Deterministic Automata

Page 2: Non Deterministic Automata

2

1q 2q

3q

a

a

a

0q

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 3: Non Deterministic Automata

3

1q 2q

3q

a

a

a

0q

Two choices

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 4: Non Deterministic Automata

4

No transition

1q 2q

3q

a

a

a

0q

Two choices No transition

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 5: Non Deterministic Automata

5

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 6: Non Deterministic Automata

6

a a

0q

1q 2q

3q

a

a

a

First Choice

Page 7: Non Deterministic Automata

7

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 8: Non Deterministic Automata

8

a a

0q

1q 2q

3q

a

a

a “accept”

First Choice

Page 9: Non Deterministic Automata

9

a a

0q

1q 2q

3q

a

a

Second Choice

a

Page 10: Non Deterministic Automata

10

a a

0q

1q 2qa

a

Second Choice

a

3q

Page 11: Non Deterministic Automata

11

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

Page 12: Non Deterministic Automata

12

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

Page 13: Non Deterministic Automata

13

Observation

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

Page 14: Non Deterministic Automata

14

Example

aa is accepted by the NFA:

0q

1q 2q

3q

a

a

a

Page 15: Non Deterministic Automata

15

Lambda Transitions

1q 3qa0q

1q a

Page 16: Non Deterministic Automata

16

a a

1q 3qa0q

2q a

Page 17: Non Deterministic Automata

17

a a

1q 3qa0q

2q a

Page 18: Non Deterministic Automata

18

a a

1q 3qa0q

2q a

(read head doesn’t move)

Page 19: Non Deterministic Automata

19

a a

1q 3qa0q

2q a

Page 20: Non Deterministic Automata

20

a a

1q 3qa0q

2q a

“accept”

String is acceptedaa

Page 21: Non Deterministic Automata

21

Language accepted: }{aaL

1q 3qa0q

2q a

Page 22: Non Deterministic Automata

22

Another NFA Example

0q 1q 2qa b

3q

Page 23: Non Deterministic Automata

23

a b

0q 1q 2qa b

3q

Page 24: Non Deterministic Automata

24

0q 2qa b

3q

a b

1q

Page 25: Non Deterministic Automata

25

a b

0q 1qa b

3q2q

Page 26: Non Deterministic Automata

26

a b

0q 1qa b

3q2q

“accept”

Page 27: Non Deterministic Automata

27

0qa b

a b

Another String

a b

1q 2q 3q

Page 28: Non Deterministic Automata

28

0qa b

a b a b

1q 2q 3q

Page 29: Non Deterministic Automata

29

0qa b

a b a b

1q 2q 3q

Page 30: Non Deterministic Automata

30

0qa b

a b a b

1q 2q 3q

Page 31: Non Deterministic Automata

31

0qa b

a b a b

1q 2q 3q

Page 32: Non Deterministic Automata

32

0qa b

a b a b

1q 2q 3q

Page 33: Non Deterministic Automata

33

0qa b

a b a b

1q 2q 3q

Page 34: Non Deterministic Automata

34

a b a b

0qa b

1q 2q 3q

“accept”

Page 35: Non Deterministic Automata

35

ab

ababababababL ...,,,

Language accepted

0q 1q 2qa b

3q

Page 36: Non Deterministic Automata

36

Another NFA Example

0q 1q 2q0

11,0

Page 37: Non Deterministic Automata

37

*10

...,101010,1010,10,

L

0q 1q 2q0

11,0

Language accepted

Page 38: Non Deterministic 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: Non Deterministic Automata

39

10 1, qq

0

11,0

Transition Function

0q 1q 2q

Page 40: Non Deterministic Automata

40

0q

0

11,0

},{)0,( 201 qqq

1q 2q

Page 41: Non Deterministic Automata

41

0q

0

11,0

1q 2q

},{),( 200 qqq

Page 42: Non Deterministic Automata

42

0q

0

11,0

1q 2q

)1,( 2q

Page 43: Non Deterministic Automata

43

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

10 ,* qaq

Page 44: Non Deterministic Automata

44

540 ,,* qqaaq

0q

5q4q

3q2q1qa

aa

b

Page 45: Non Deterministic Automata

45

0320 ,,,* qqqabq

0q

5q4q

3q2q1qa

aa

b

Page 46: Non Deterministic Automata

46

Formally

wqq ij ,*It holds

if and only if

there is a walk from towith label

iq jqw

Page 47: Non Deterministic Automata

47

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

Page 48: Non Deterministic Automata

48

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

Page 49: Non Deterministic Automata

49

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaaba

Page 50: Non Deterministic Automata

50

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLaba

Page 51: Non Deterministic Automata

51

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

Page 52: Non Deterministic Automata

52

FormallyThe language accepted by NFA is:

where

and there is some

M

,...,, 321 wwwML

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

Fqk (final state)

Page 53: Non Deterministic Automata

53

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

Page 54: Non Deterministic Automata

54

Equivalence of NFAs and DFAs

Page 55: Non Deterministic Automata

55

Equivalence of Machines

For DFAs or NFAs:

Machine is equivalent to machine

if

1M 2M

21 MLML

Page 56: Non Deterministic 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: Non Deterministic 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: Non Deterministic Automata

58

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

Page 59: Non Deterministic Automata

59

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

YES!

Page 60: Non Deterministic Automata

60

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

Page 61: Non Deterministic Automata

61

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

NFAs and DFAs have the same computation power

Page 62: Non Deterministic Automata

62

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Page 63: Non Deterministic Automata

63

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Proof: Every DFA is also an NFA

Page 64: Non Deterministic 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: Non Deterministic Automata

65

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Page 66: Non Deterministic Automata

66

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 2

Proof: Any NFA can be converted to anequivalent DFA

Page 67: Non Deterministic 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: Non Deterministic Automata

68

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 69: Non Deterministic Automata

69

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

Page 70: Non Deterministic Automata

70

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

Page 71: Non Deterministic Automata

71

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

a

Page 72: Non Deterministic Automata

72

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

Page 73: Non Deterministic Automata

73

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 74: Non Deterministic Automata

74

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 75: Non Deterministic 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: Non Deterministic Automata

76

If the NFA has states

the DFA has states in the powerset

,...,, 210 qqq

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

Page 77: Non Deterministic Automata

77

Procedure NFA to DFA

1. Initial state of NFA:

Initial state of DFA:

0q

0q

Page 78: Non Deterministic Automata

78

Example

a

b

a

0q 1q 2q

NFA

DFA

0q

Page 79: Non Deterministic 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: Non Deterministic Automata

80

Exampe

a

b

a

0q 1q 2q

NFA

0q 21,qqa

DFA

},{),(* 210 qqaq

210 ,, qqaq

Page 81: Non Deterministic Automata

81

Procedure NFA to DFA

Repeat Step 2 for all letters in alphabet,

untilno more transitions can be added.

Page 82: Non Deterministic Automata

82

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Page 83: Non Deterministic 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: Non Deterministic Automata

84

Example

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Fq 1

Fqq 21,

Page 85: Non Deterministic Automata

85

Theorem Take NFA M

Apply procedure to obtain DFA M

Then and are equivalent :M M

MLML

Page 86: Non Deterministic Automata

86

Finally

We have proven

Languages acceptedby NFAs

Languages acceptedby DFAs

Page 87: Non Deterministic Automata

87

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular Languages

Page 88: Non Deterministic Automata

88

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular LanguagesRegular Languages