Top Banner
1 Theory of Automata & Formal Languages
240
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Flat

1

Theory of Automata &

Formal Languages

Page 2: Flat

2

BOOKS

Theory of computer Science: K.L.P.Mishra &

N.Chandrasekharan

Intro to Automata theory, Formal languages and computation: Ullman,Hopcroft

Motwani

Elements of theory of computation Lewis & papadimitrou

Page 3: Flat

3

Syllabus

Introduction

Deterministic and non deterministic Finite Automata, Regular Expression,Two way finite automata,Finite automata with output,properties of regular sets,pumping lemma, closure properties,Myhill nerode theorem

Page 4: Flat

4

Context free Grammar: Derivation trees, Simplification forms

Pushdown automata: Def, Relationship between PDA and context free language,Properties, decision algorithms

Turing Machines: Turing machine model,Modification of turing machines,Church’s thesis,Undecidability,Recursive and recursively enumerable languages Post correspondence problems recursive functions

Page 5: Flat

5

Chomsky Hierarchy: Regular grammars, unrestricted grammar, context sensitive language, relationship among languages

Page 6: Flat

6

CPU

input memory

output memory

Program memory

temporary memory

Page 7: Flat

7

CPU

input memory

output memoryProgram memory

temporary memory3)( xxf

compute xx

compute xx 2

2x

42*2 z82*)( zxf

Page 8: Flat

8

Automaton

CPU

input memory

output memory

Program memory

temporary memory

Automaton

Page 9: Flat

9

input memory

output memory

temporary memory

Finite

Automaton

Page 10: Flat

10

Different Kinds of Automata

Automata are distinguished by the temporary memory

• Finite Automata: no temporary memory

• Pushdown Automata: stack

• Turing Machines: random access memory

Page 11: Flat

11

input memory

output memory

Stack

Pushdown

Automaton

Pushdown Automaton

Programming Languages (medium computing power)

Push, Pop

Page 12: Flat

12

input memory

output memory

Random Access Memory

Turing

Machine

Turing Machine

Algorithms (highest computing power)

Page 13: Flat

13

Finite

Automata

Pushdown

Automata

Turing

Machine

Power of Automata

Page 14: Flat

14

Power sets

A power set is a set of sets

Powerset of S = the set of all the subsets of S

S = { a, b, c }

2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }

Observation: | 2S | = 2|S| ( 8 = 23 )

Page 15: Flat

15

Cartesian ProductA = { 2, 4 } B = { 2, 3, 5 }

A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 4) }

|A X B| = |A| |B|

Generalizes to more than two sets

A X B X … X Z

Page 16: Flat

16

RELATIONS R = {(x1, y1), (x2, y2), (x3, y3), …}

xi R yi

e. g. if R = ‘>’: 2 > 1, 3 > 2, 3 > 1

In relations xi can be repeated

Page 17: Flat

17

Equivalence Relations

• Reflexive: x R x

• Symmetric: x R y y R x

• Transitive: x R Y and y R z x R z

Example: R = ‘=‘

• x = x

• x = y y = x

• x = y and y = z x = z

Page 18: Flat

18

Equivalence ClassesFor equivalence relation R

equivalence class of x = {y : x R y}

Example:

R = { (1, 1), (2, 2), (1, 2), (2, 1),

(3, 3), (4, 4), (3, 4), (4, 3) }

Equivalence class of 1 = {1, 2}

Equivalence class of 3 = {3, 4}

Page 19: Flat

19

Example of Equivalence relationLet Z = set of integers

R be defined on it as:

R= {(x,y)| x Z, y Z and

(x - y)is divisible by 5}

This relation is known as

” congruent modulo 5”

Page 20: Flat

20

The equivalence classes are

[0]R= {…-10, -5, 0, 5,10,…}

[1]R = {…..,-9, -4, 1, 6, 11, 16….}

[2]R= {….-8, -3,2,7,12,17…..}

[3]R = {….-7, -2, 3, 8 ,13,…}

[4]R = {….-6,-1,4,9,14,19,….}

Z/R ={[0]R, [1]R, [2]R, [3]R, [4]R}

Page 21: Flat

21

PROOF TECHNIQUES

• Proof by induction

• Proof by contradiction

Page 22: Flat

22

Induction

We have statements P1, P2, P3, …

If we know

• for some k that P1, P2, …, Pk are true

• for any n >= k that

P1, P2, …, Pn imply Pn+1

Then

Every Pi is true

Page 23: Flat

23

Treesroot

leaf

parent

child

Trees have no cycles

Page 24: Flat

24

Proof by Induction• Inductive basis

Find P1, P2, …, Pk which are true

• Inductive hypothesis

Let’s assume P1, P2, …, Pn are true,

for any n >= k

• Inductive step

Show that Pn+1 is true

Page 25: Flat

25

root

leaf

Level 0

Level 1

Level 2

Level 3

Height 3

Page 26: Flat

26

Binary Trees

Page 27: Flat

27

Example

Theorem: A binary tree of height n

has at most 2n leaves.

Proof:

let l(i) be the number of leaves at level i

l(0) = 0

l(3) = 8

Page 28: Flat

28

Induction Step

hypothesis: l(n) <= 2n

Level

n

n+1

Page 29: Flat

29

We want to show: l(i) <= 2i

• Inductive basis

l(0) = 1 (the root node)

• Inductive hypothesis

Let’s assume l(i) <= 2i for all i = 0, 1, …, n

• Induction step

we need to show that l(n + 1) <= 2n+1

Page 30: Flat

30

hypothesis: l(n) <= 2n

Level

n

n+1

l(n+1) <= 2 * l(n) <= 2 * 2n = 2n+1

Induction Step

Page 31: Flat

31

Proof by Contradiction

We want to prove that a statement P is true

• we assume that P is false

• then we arrive at an incorrect conclusion

• therefore, statement P must be true

Page 32: Flat

32

Example

Theorem: is not rational

Proof:

Assume by contradiction that it is rational

= n/m

n and m have no common factors

We will show that this is impossible

2

2

Page 33: Flat

33

= n/m 2 m2 = n2

Therefore, n2 is evenn is even

n = 2 k

2 m2 = 4k2 m2 = 2k2m is even

m = 2 p

Thus, m and n have common factor 2

Contradiction!

2

Page 34: Flat

34

Basic Terms

Alphabet: A finite non empty set of elements.

={a,b,c,d,…z}

Page 35: Flat

35

• String: A sequence of letters

– Examples: “cat”, “dog”, “house”, …

– Defined over an alphabet:

zcba ,,,,

Language: It is a set of strings on some alphabet

Page 36: Flat

36

Alphabets and Strings

• We will use small alphabets:

• Strings

abbaw

bbbaaav

abu

ba,

baaabbbaaba

baba

abba

ab

a

Page 37: Flat

37

String Operations

m

n

bbbv

aaaw

21

21

bbbaaa

abba

mn bbbaaawv 2121

Concatenation

abbabbbaaa

Page 38: Flat

38

12aaaw nR

naaaw 21 ababaaabbb

Reverse

bbbaaababa

Page 39: Flat

39

String Length

• Length:

• Examples:

naaaw 21

nw

1

2

4

a

aa

abba

Page 40: Flat

40

Recursive Definition of Length

For any letter:

For any string :

Example:

1a

1wwawa

4

1111

111

11

1

a

ab

abbabba

Page 41: Flat

41

Length of Concatenation

• Example:

vuuv

853

8

5,

3,

vuuv

aababaabuv

vabaabv

uaabu

Page 42: Flat

42

Proof of Concatenation Length

• Claim:

• Proof: By induction on the length

– Induction basis:– From definition of length:

vuuv v

1v

vuuuv 1

Page 43: Flat

43

– Inductive hypothesis:

• for

– Inductive step: we will prove–

– for

vuuv

nv ,,2,1

1nv

vuuv

Page 44: Flat

44

Inductive Step

• Write , where

• From definition of length:

• From inductive hypothesis:

• Thus:

wav 1, anw

1

1

wwa

uwuwauv

wuuw

vuwauwuuv 1

Page 45: Flat

45

Empty String

• A string with no letters:

• Observations:

abbaabbaabba

www

0

Page 46: Flat

46

Substring

• Substring of string:

– a subsequence of consecutive characters

• String Substring

bbab

b

abba

ab

abbab

abbab

abbab

abbab

Page 47: Flat

47

Prefix and Suffix

• Prefixes Suffixes abbab

abbab

abba

abb

ab

a

b

ab

bab

bbab

abbabuvw

prefix

suffix

Page 48: Flat

48

Another Operation

• Example:

• Definition:–

n

n wwww

abbaabbaabba 2

0w

0abba

Page 49: Flat

49

The * Operation

• : the set of all possible strings from• alphabet

*

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

Page 50: Flat

50

The + Operation : the set of all possible strings from alphabet except

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

*

,,,,,,,, aabaaabbbaabaaba

Page 51: Flat

51

Language

• A language is any subset of

• Example:

• Languages:

*

,,,,,,,,*

,

aaabbbaabaaba

ba

},,,,,{

,,

aaaaaaabaababaabba

aabaaa

Page 52: Flat

52

Another Example

• An infinite language

}0:{ nbaL nn

aaaaabbbbb

aabb

ab

L Labb

Page 53: Flat

53

Operations on Languages

• The usual set operations

• Complement:

aaaaaabbbaaaaaba

ababbbaaaaaba

aaaabbabaabbbaaaaaba

,,,,

}{,,,

},,,{,,,

LL * ,,,,,,, aaabbabaabbaa

Page 54: Flat

54

Reverse

• Definition:

• Examples:

}:{ LwwL RR

ababbaabababaaabab R ,,,,

}0:{

}0:{

nabL

nbaL

nnR

nn

Page 55: Flat

55

Concatenation

• Definition:

• Example:

2121 ,: LyLxxyLL

baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

Page 56: Flat

56

Another Operation

• Definition:

• Special case:

n

n LLLL

bbbbbababbaaabbabaaabaaa

babababa

,,,,,,,

,,,, 3

0

0

,, aaabbaa

L

Page 57: Flat

57

More Examples

• }0:{ nbaL nn

}0,:{2 mnbabaL mmnn

2Laabbaaabbb

Page 58: Flat

58

Star-Closure (Kleene *)

• Definition:

• Example:

210* LLLL

,,,,

,,,,

,,

,

*,

abbbbabbaaabbaaa

bbbbbbaabbaa

bbabba

Page 59: Flat

59

Positive Closure

• Definition:

*

21

L

LLL

,,,,

,,,,

,,

,

abbbbabbaaabbaaa

bbbbbbaabbaa

bba

bba

Page 60: Flat

60

Finite AutomatonInput

String

Output

String

FiniteAutomaton

Page 61: Flat

61

Finite Accepter

Input

“Accept” or“Reject”

String

FiniteAutomaton

Output

Page 62: Flat

62

Transition Graph

initialstate

final state“accept”state

transition

Abba -Finite Accepter

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 63: Flat

63

Initial Configuration

1q 2q 3q 4qa b b a

5q

a a bb

ba,

Input Stringa b b a

ba,

0q

Page 64: Flat

64

Reading the Input

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

Page 65: Flat

65

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

Page 66: Flat

66

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

Page 67: Flat

67

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

Page 68: Flat

68

0q 1q 2q 3q 4qa b b a

Output: “accept”

5q

a a bb

ba,

a b b a

ba,

Input finished

Page 69: Flat

69

Rejection

1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

0q

Page 70: Flat

70

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

Page 71: Flat

71

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

Page 72: Flat

72

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

Page 73: Flat

73

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

Output:“reject”

a b a

ba,

Input finished

Page 74: Flat

74

Another Example

a

b ba,

ba,

0q 1q 2q

a ba

Page 75: Flat

75

a

b ba,

ba,

0q 1q 2q

a ba

Page 76: Flat

76

a

b ba,

ba,

0q 1q 2q

a ba

Page 77: Flat

77

a

b ba,

ba,

0q 1q 2q

a ba

Page 78: Flat

78

a

b ba,

ba,

0q 1q 2q

a ba

Output: “accept”

Input finished

Page 79: Flat

79

Rejection

a

b ba,

ba,

0q 1q 2q

ab b

Page 80: Flat

80

a

b ba,

ba,

0q 1q 2q

ab b

Page 81: Flat

81

a

b ba,

ba,

0q 1q 2q

ab b

Page 82: Flat

82

a

b ba,

ba,

0q 1q 2q

ab b

Page 83: Flat

83

a

b ba,

ba,

0q 1q 2q

ab b

Output: “reject”

Input finished

Page 84: Flat

84

• Deterministic Finite Accepter (DFA)

FqQM ,,,, 0

Q

0q

F

: Finite set of states

: input alphabet

: transition function

: initial state is a member of Q

: set of final states

: Q X Q

Page 85: Flat

85

Input Alphabet

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

ba,

Page 86: Flat

86

Set of States

Q

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

543210 ,,,,, qqqqqqQ

ba,

Page 87: Flat

87

Initial State

0q

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 88: Flat

88

Set of Final States

F

0q 1q 2q 3qa b b a

5q

a a bb

ba,

4qF

ba,

4q

Page 89: Flat

89

Transition Function

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

QQ :

ba,

Page 90: Flat

90

10 , qaq

2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q

Page 91: Flat

91

50 , qbq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 92: Flat

92

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

32 , qbq

Page 93: Flat

93

Transition Function

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b

0q

1q

2q

3q

4q

5q

1q 5q

5q 2q

2q 3q

4q 5q

ba,5q5q5q5q

Page 94: Flat

94

Extended Transition Function

*

QQ *:*

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 95: Flat

95

20 ,* qabq

3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q 2q

Page 96: Flat

96

40 ,* qabbaq

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 97: Flat

97

50 ,* qabbbaaq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 98: Flat

98

50 ,* qabbbaaq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Observation: There is a walk from to with label

0qabbbaa

1q

Page 99: Flat

99

Recursive Definition

)),,(*(,*

,*

awqwaq

qq

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 100: Flat

100

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

2

1

0

0

0

0

,

,,

,,,*

),,(*

,*

q

bq

baq

baq

baq

abq

Page 101: Flat

101

Languages Accepted by DFAs• Take DFA

• Definition:

– The language contains – all input strings accepted by

– = { strings that drive to a final state}

M

MLM

M ML

Page 102: Flat

102

Example

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

abbaML M

accept

Page 103: Flat

103

Another Example

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

abbaabML ,, M

acceptacceptaccept

Page 104: Flat

104

Formally

• For a DFA Language accepted by :

FqQM ,,,, 0

M

FwqwML ,*:* 0

alphabet transitionfunction

initialstate

finalstates

Page 105: Flat

105

Observation

• Language accepted by :

• Language rejected by :

FwqwML ,*:* 0M

FwqwML ,*:* 0M

Page 106: Flat

106

More Examples•

a

b ba,

ba,

0q 1q 2q

}0:{ nbaML n

accept trap state or dead state

Page 107: Flat

107

ML = { all strings with prefix }ab

a b

ba,

0q 1q 2q

accept

ba,3q

ab

Page 108: Flat

108

ML = { all strings without substring }001

0 00 001

1

0

1

10

0 1,0

Page 109: Flat

109

Regular Languages

• A language is regular if there is

• a DFA such that

• All regular languages form a language family–

LM MLL

Page 110: Flat

110

Example

• The language

• is regular:

*,: bawawaL

a

b

ba,

a

b

ba

0q 2q 3q

4q

Page 111: Flat

111

Non Deterministic Automata

Page 112: Flat

112

Non Deterministic Finite Accepter

FqQM ,,,, 0

: 2QQ

Page 113: Flat

113

1q 2q

3q

a

a

a

0q

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 114: Flat

114

1q 2q

3q

a

a

a

0q

Two choices

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 115: Flat

115

No transition

1q 2q

3q

a

a

a

0q

Two choices No transition

}{aAlphabet =

Nondeterministic Finite Accepter (NFA)

Page 116: Flat

116

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 117: Flat

117

a a

0q

1q 2q

3q

a

a

a

First Choice

Page 118: Flat

118

a a

0q

1q 2q

3q

a

a

First Choice

a

Page 119: Flat

119

a a

0q

1q 2q

3q

a

a

a “accept”

First Choice

All input is consumed

Page 120: Flat

120

a a

0q

1q 2q

3q

a

a

Second Choice

a

Page 121: Flat

121

a a

0q

1q 2qa

a

Second Choice

a

3q

Page 122: Flat

122

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

Page 123: Flat

123

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

Input cannot be consumed

Page 124: Flat

124

An NFA accepts a string:

when there is a computation of the NFAthat accepts the string

•All the input is consumed and the automaton is in a final state

Page 125: Flat

125

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

Page 126: Flat

126

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

Page 127: Flat

127

a

0q

1q 2q

3q

a

a

Rejection example

a

Page 128: Flat

128

a

0q

1q 2q

3q

a

a

a

First Choice

Page 129: Flat

129

a

0q

1q 2q

3q

a

a

a

First Choice

“reject”

Page 130: Flat

130

Second Choice

a

0q

1q 2q

3q

a

a

a

Page 131: Flat

131

Second Choice

a

0q

1q 2qa

a

a

3q

Page 132: Flat

132

Second Choice

a

0q

1q 2qa

a

a

3q “reject”

Page 133: Flat

133

Examplea 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

Page 134: Flat

134

Rejection example

a a

0q

1q 2q

3q

a

a

a

a

Page 135: Flat

135

a a

0q

1q 2q

3q

a

a

a

First Choice

a

Page 136: Flat

136

a a

0q

1q 2q

3q

a

a

First Choice

a

a

No transition:the automaton hangs

Page 137: Flat

137

a a

0q

1q 2q

3q

a

a

a “reject”

First Choice

a

Input cannot be consumed

Page 138: Flat

138

a a

0q

1q 2q

3q

a

a

Second Choice

a

a

Page 139: Flat

139

a a

0q

1q 2qa

a

Second Choice

a

3q

a

Page 140: Flat

140

a a

0q

1q 2qa

a

a

3q

Second Choice

No transition:the automaton hangs

a

Page 141: Flat

141

a a

0q

1q 2qa

a

a

3q

Second Choice

“reject”

a

Input cannot be consumed

Page 142: Flat

142

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

Page 143: Flat

143

1q 2q

3q

a

a

a

0q

Language accepted: }{aaL

Page 144: Flat

144

Lambda →Transitions

1q 3qa0q

2q a

Page 145: Flat

145

a a

1q 3qa0q

2q a

Page 146: Flat

146

a a

1q 3qa0q

2q a

Page 147: Flat

147

a a

1q 3qa0q

2q a

(read head doesn’t move)

Page 148: Flat

148

a a

1q 3qa0q

2q a

Page 149: Flat

149

a a

1q 3qa0q

2q a

“accept”

String is acceptedaa

all input is consumed

Page 150: Flat

150

a a

1q 3qa0q

2q a

Rejection Example

a

Page 151: Flat

151

a a

1q 3qa0q

2q a

a

Page 152: Flat

152

a a

1q 3qa0q

2q a

(read head doesn’t move)

a

Page 153: Flat

153

a a

1q 3qa0q

2q a

a

No transition:the automaton hangs

Page 154: Flat

154

a a

1q 3qa0q

2q a

“reject”

String is rejectedaaa

a

Input cannot be consumed

Page 155: Flat

155

Language accepted: }{aaL

1q 3qa0q

2q a

Page 156: Flat

156

Another NFA Example

0q 1q 2qa b

3q

Page 157: Flat

157

a b

0q 1q 2qa b

3q

Page 158: Flat

158

0q 2qa b

3q

a b

1q

Page 159: Flat

159

a b

0q 1qa b

3q2q

Page 160: Flat

160

a b

0q 1qa b

3q2q

“accept”

Page 161: Flat

161

0qa b

a b

Another String

a b

1q 2q 3q

Page 162: Flat

162

0qa b

a b a b

1q 2q 3q

Page 163: Flat

163

0qa b

a b a b

1q 2q 3q

Page 164: Flat

164

0qa b

a b a b

1q 2q 3q

Page 165: Flat

165

0qa b

a b a b

1q 2q 3q

Page 166: Flat

166

0qa b

a b a b

1q 2q 3q

Page 167: Flat

167

0qa b

a b a b

1q 2q 3q

Page 168: Flat

168

a b a b

0qa b

1q 2q 3q

“accept”

Page 169: Flat

169

ab

ababababababL ...,,,

Language accepted

0q 1q 2qa b

3q

Page 170: Flat

170

Another NFA Example

0q 1q 2q0

11,0

Page 171: Flat

171

{ }{ } *10=

...,101010,1010,10,λ=)(ML

0q 1q 2q0

11,0

Language accepted

Page 172: Flat

172

Remarks:

•The symbol never appears on the input tape

0q2M

0q1M

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

•Extreme automata:

Page 173: Flat

173

0q

2q

1qa

0q 1qa

}{=)( 1 aML

2M1M

}{=)( 2 aML

NFA DFA

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

ba,b

a,b

Page 174: Flat

174

Formal Definition of NFAs

FqQM ,,,, 0

:Q

::0q

:F

Set of states, i.e. 210 ,, qqq

: Input alphabet, i.e. ba,

Transition function

Initial state

Final states

Page 175: Flat

175

10 1, qq

0

11,0

Transition Function

0q 1q 2q

Page 176: Flat

176

0q

0

11,0

},{)0,( 201 qqq

1q 2q

Page 177: Flat

177

0q

0

11,0

1q 2q

},{),( 200 qqq

Page 178: Flat

178

0q

0

11,0

1q 2q

)1,( 2q

Page 179: Flat

179

Extended Transition Function

*

0q

5q4q

3q2q1qa

aa

b

10 ,* qaq

Page 180: Flat

180

540 ,,* qqaaq

0q

5q4q

3q2q1qa

aa

b

Page 181: Flat

181

0320 ,,,* qqqabq

0q

5q4q

3q2q1qa

aa

b

Page 182: Flat

182

Formally

wqq ij ,*

It holdsif and only if

there is a walk from towith label

iq jqw

Page 183: Flat

183

The Language of an NFA

0q

5q4q

3q2q1qa

aa

b

540 ,,* qqaaq

M

)(MLaa

50 ,qqF

Page 184: Flat

184

0q

5q4q

3q2q1qa

aa

b

0320 ,,,* qqqabq MLab

50 ,qqF

Page 185: Flat

185

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

540 ,,* qqabaaq )(MLaaba

Page 186: Flat

186

0q

5q4q

3q2q1qa

aa

b

50 ,qqF

10 ,* qabaq MLaba

Page 187: Flat

187

0q

5q4q

3q2q1qa

aa

b

aaababaaML *

Page 188: Flat

188

Formally

• The language accepted by NFA is:

• where

• and there is some

M

,...,, 321 wwwML

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

Fqk (final state)

Page 189: Flat

189

0q kq

w

w

w

),(* 0 wq MLw

Fqk

iq

jq

Page 190: Flat

190

Equivalence of NFAs and DFAs

Page 191: Flat

191

Equivalence of Machines

• For DFAs or NFAs:

• Machine is equivalent to machine

• if

1M 2M

21 MLML

Page 192: Flat

192

• 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 193: Flat

193

• 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 194: Flat

194

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

Page 195: Flat

195

Equivalence of NFAs and DFAs

Question: NFAs = DFAs ?

Same power?Accept the same languages?

YES!

Page 196: Flat

196

We will prove:

Languages acceptedby NFAs

Languages acceptedby DFAs

NFAs and DFAs have the same computation power

Page 197: Flat

197

Languages acceptedby NFAs

Languages acceptedby DFAs

Step 1

Proof: Every DFA is trivially an NFA

A language accepted by a DFAis also accepted by an NFA

Page 198: Flat

198

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 199: Flat

199

NFA to DFA

a

b

a

0q 1q 2q

NFA

DFA

0q

M

M

Page 200: Flat

200

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

M

M

Page 201: Flat

201

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

M

M

Page 202: Flat

202

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

a

M

M

Page 203: Flat

203

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

M

M

Page 204: Flat

204

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

M

M

Page 205: Flat

205

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

M

M

)(MLML

Page 206: Flat

206

NFA to DFA: Remarks

• We are given an NFA

• We want to convert it to an equivalent DFA

M

M

)(MLML

Page 207: Flat

207

• If the NFA has states

• the DFA has states in the power set

,...,, 210 qqq

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

Page 208: Flat

208

Procedure NFA to DFA

• 1. Initial state of NFA:

• Initial state of DFA:

0q

0q

Page 209: Flat

209

a

b

a

0q 1q 2q

NFA

DFA

0q

M

M

Page 210: Flat

210

Procedure NFA to DFA

• 2. For every DFA’s state

• Compute in the NFA

• Add transition to DFA

},...,,{ mji qqq

...

,,*

,,*

aq

aq

j

i

},...,,{ mji qqq

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

Page 211: Flat

211

a

b

a

0q 1q 2q

NFA

0q 21,qqa

DFA

},{),(* 210 qqaq

210 ,, qqaq

M

M

},{),(* 210 qqaq

Page 212: Flat

212

Procedure NFA to DFA

• Repeat Step 2 for all letters in alphabet,

• until

• no more transitions can be added.

Page 213: Flat

213

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

M

M

Page 214: Flat

214

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 215: Flat

215

a

b

a

0q 1q 2q

NFA

DFA

0q 21,qqa

b

ab

ba,

Fq 1

Fqq 21,

M

M

Page 216: Flat

216

Theorem

• Take NFA M

Apply procedure to obtain DFA M

Then and are equivalent :M M

MLML

Page 217: Flat

217

FinallyWe have proven

Languages acceptedby NFAs

Languages acceptedby DFAs

Page 218: Flat

218

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular Languages

Page 219: Flat

219

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular LanguagesRegular Languages

Page 220: Flat

220

Languages acceptedby NFAs

Languages acceptedby DFAs

We have proven

Regular LanguagesRegular Languages

Thus, NFAs accept the regular languages

Page 221: Flat

221

Single Final State for NFAs and DFAs

Page 222: Flat

222

Observation

• Any Finite Automaton (NFA or DFA)

• can be converted to an equivalent NFA

• with a single final state

Page 223: Flat

223

a

b

b

aNFA

Equivalent NFA

a

b

b

a

Example

Page 224: Flat

224

NFAIn General

Equivalent NFA

Singlefinal state

Page 225: Flat

225

Extreme Case

NFA without final state

Add a final stateWithout transitions

Page 226: Flat

226

Some Properties of Regular Languages

Page 227: Flat

227

1L2L

21LLConcatenation:

*1LStar:

21 LL Union:

Are regularLanguages

For regular languages and we will prove that:

properties

Page 228: Flat

228

We Say:Regular languages are closed under

21LLConcatenation:

*1LStar:

21 LL Union:

Page 229: Flat

229

Properties

1L 2L

21LLConcatenation:

*1LStar:

21 LL Union:

Are regularLanguages

For regular languages and we will prove that:

Page 230: Flat

230

1LRegular language

11 LML

1M

Single final state

NFA 2M

2L

Single final state

22 LML

Regular language

NFA

Page 231: Flat

231

Example

}{1 baL na

b 1M

baL 2ab

2M

Page 232: Flat

232

Union

• NFA for 1M

2M

21 LL

Page 233: Flat

233

• a

b

ab

}{1 baL n

}{2 baL

}{}{21 babaLL n NFA for

Page 234: Flat

234

Concatenation

• NFA for

21LL

1M 2M

Page 235: Flat

235

Example

• NFA for

a

b ab

}{1 baL n}{2 baL

}{}}{{21 bbaababaLL nn

Page 236: Flat

236

Star Operation• NFA for *1L

1M

*1L

Page 237: Flat

237

Example

• NFA for

*}{*1 baL n

a

b

}{1 baL n

N>= 0

Page 238: Flat

238

Procedure: NFA to DFA

1 Create a graph with vertex {q0}.Identify this vertex as initial vertex of DFA.

2 Repeat the following steps until no more edges are missing.Take any vertex {qi,qj,….qk} of G that has no outgoing edge for some symbol a of the alphabet.Compute (qi, a), (qj, a)…. (qk, a)Then form the union of all these yielding the set {ql, qm, …qn}.Create a vertex for G labeled {ql, qm,…qn} if it does not already exist.Add to G an edge from {qi, qj,…qk} to {ql,qm…qn} and label it with a.

3 Every state of G whose label contains any qf of F is identified as a final vertex of DFA.

4 If NFA accepts then vertex {q0} in G is also made a final vertex.

**

*

*

Page 239: Flat

239

q0 q2q10,1 0,1

10

Page 240: Flat

240

q0

{q0,q1}

q1

q0,q1,q2q1,q2

q2

0

01

1

0

0,1

0,1

1

1

0,1

Equivalent DFA

Start

0