Flat

lavishka_anuj 3,044 views 238 slides Mar 27, 2012
Slide 1
Slide 1 of 240
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135
Slide 136
136
Slide 137
137
Slide 138
138
Slide 139
139
Slide 140
140
Slide 141
141
Slide 142
142
Slide 143
143
Slide 144
144
Slide 145
145
Slide 146
146
Slide 147
147
Slide 148
148
Slide 149
149
Slide 150
150
Slide 151
151
Slide 152
152
Slide 153
153
Slide 154
154
Slide 155
155
Slide 156
156
Slide 157
157
Slide 158
158
Slide 159
159
Slide 160
160
Slide 161
161
Slide 162
162
Slide 163
163
Slide 164
164
Slide 165
165
Slide 166
166
Slide 167
167
Slide 168
168
Slide 169
169
Slide 170
170
Slide 171
171
Slide 172
172
Slide 173
173
Slide 174
174
Slide 175
175
Slide 176
176
Slide 177
177
Slide 178
178
Slide 179
179
Slide 180
180
Slide 181
181
Slide 182
182
Slide 183
183
Slide 184
184
Slide 185
185
Slide 186
186
Slide 187
187
Slide 188
188
Slide 189
189
Slide 190
190
Slide 191
191
Slide 192
192
Slide 193
193
Slide 194
194
Slide 195
195
Slide 196
196
Slide 197
197
Slide 198
198
Slide 199
199
Slide 200
200
Slide 201
201
Slide 202
202
Slide 203
203
Slide 204
204
Slide 205
205
Slide 206
206
Slide 207
207
Slide 208
208
Slide 209
209
Slide 210
210
Slide 211
211
Slide 212
212
Slide 213
213
Slide 214
214
Slide 215
215
Slide 216
216
Slide 217
217
Slide 218
218
Slide 219
219
Slide 220
220
Slide 221
221
Slide 222
222
Slide 223
223
Slide 224
224
Slide 225
225
Slide 226
226
Slide 227
227
Slide 228
228
Slide 229
229
Slide 230
230
Slide 231
231
Slide 232
232
Slide 233
233
Slide 234
234
Slide 235
235
Slide 236
236
Slide 237
237
Slide 238
238
Slide 239
239
Slide 240
240

About This Presentation

No description available for this slideshow.


Slide Content

1
Theory of Automata
&
Formal Languages

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

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

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

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

6
CPU
input memory
output memory
Program memory
temporary memory

7
CPU
input memory
output memory
Program memory
temporary memory3
)(xxf
computexx
computexx
2 2x 42*2z 82*)(zxf

8
Automaton
CPU
input memory
output memory
Program memory
temporary memory
Automaton

9
input memory
output memory
temporary memory
Finite
Automaton

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

11
input memory
output memory
Stack
Pushdown
Automaton
Pushdown Automaton
Programming Languages (medium computing power)
Push, Pop

12
input memory
output memory
Random Access Memory
Turing
Machine
Turing Machine
Algorithms (highest computing power)

13
Finite
Automata
Pushdown
Automata
Turing
Machine
Power of Automata

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 }
2
S
= { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }
Observation:| 2
S
| = 2
|S|
( 8 = 2
3
)

15
Cartesian Product
A = { 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

16
RELATIONS
R = {(x
1, y
1), (x
2, y
2), (x
3, y
3), …}
x
iR y
i
e. g. ifR = „>‟: 2 > 1, 3 > 2, 3 > 1
In relations x
ican be repeated

17
Equivalence Relations
•Reflexive:x R x
•Symmetric:x R y y R x
•Transitive:x R Y andy R z x R z
Example:R = „=„
•x = x
•x = y y = x
•x = y andy = z x = z

18
Equivalence Classes
For equivalence relationR
equivalence class ofx = {y : x R y}
Example:
R = { (1, 1), (2, 2), (1, 2), (2, 1),
(3, 3), (4, 4), (3, 4), (4, 3) }
Equivalence class of1 = {1, 2}
Equivalence class of3 = {3, 4}

19
Example of Equivalence relation
Let 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”

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}

21
PROOF TECHNIQUES
•Proof by induction
•Proof by contradiction

22
Induction
We have statementsP
1, P
2, P
3, …
If we know
•for some k that P
1, P
2, …, P
kare true
•for any n >= k that
P
1, P
2, …, P
nimply P
n+1
Then
Every P
iis true

23
Trees
root
leaf
parent
child
Trees have no cycles

24
Proof by Induction
•Inductive basis
Find P
1, P
2, …, P
kwhich are true
•Inductive hypothesis
Let‟s assume P
1, P
2, …, P
nare true,
for any n >= k
•Inductive step
Show that P
n+1is true

25
root
leaf
Level 0
Level 1
Level 2
Level 3
Height 3

26
Binary Trees

27
Example
Theorem:A binary tree of height n
has at most 2
n
leaves.
Proof:
let l(i)be the number of leaves at level i
l(0) = 0
l(3) = 8

28
Induction Step
hypothesis:l(n) <= 2
n
Level
n
n+1

29
We want to show:l(i) <= 2
i
•Inductive basis
l(0) = 1 (the root node)
•Inductive hypothesis
Let‟s assume l(i) <= 2
i
for all i = 0, 1, …, n
•Induction step
we need to show that l(n + 1) <= 2
n+1

30
hypothesis:l(n) <= 2
n
Level
n
n+1
l(n+1) <= 2 * l(n) <= 2 * 2
n
= 2
n+1
Induction Step

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

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 impossible2 2

33
= n/m 2 m
2
= n
2
Therefore, n
2
is even
n is even
n = 2 k
2 m
2
= 4k
2
m
2
= 2k
2
m is even
m = 2 p
Thus, m and n have common factor 2
Contradiction!2

34
Basic Terms
Alphabet:A finite non empty set of elements.
={a,b,c,d,…z}

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

36
Alphabets and Strings
•We will use small alphabets:
•Strings abbaw
bbbaaav
abu ba, baaabbbaaba
baba
abba
ab
a

37
String Operationsm
n
bbbv
aaaw


21
21 bbbaaa
abba mn
bbbaaawv 
2121
Concatenationabbabbbaaa

38 12
aaaw
n
R
 n
aaaw 
21 ababaaabbb
Reversebbbaaababa

39
String Length
•Length:
•Examples:n
aaaw 
21 nw 1
2
4
a
aa
abba

40
Recursive Definition of Length
For any letter:
For any string :
Example:1a 1wwa wa 4
1111
111
11
1
a
ab
abbabba

41
Length of Concatenation
•Example: vuuv 853
8
5,
3,
vuuv
aababaabuv
vabaabv
uaabu

42
Proof of Concatenation Length
•Claim:
•Proof: By induction on the length
–Induction basis:
– From definition of length:vuuv v 1v vuuuv 1

43
–Inductive hypothesis:
• for
–Inductive step: we will prove

– forvuuv nv ,,2,1 1nv vuuv

44
Inductive Step
•Write , where
•From definition of length:
•From inductive hypothesis:
•Thus: wav 1,anw 1
1
wwa
uwuwauv wuuw vuwauwuuv 1

45
Empty String
•A string with no letters:
•Observations: abbaabbaabba
www
0

46
Substring
•Substring of string:
–a subsequence of consecutive characters
• String Substringbbab
b
abba
ab abbab
abbab
abbab
abbab

47
Prefix and Suffix
•Prefixes Suffixesabbab abbab
abba
abb
ab
a b
ab
bab
bbab
abbab uvw
prefix
suffix

48
Another Operation
•Example:
•Definition:
–

n
n
wwww abbaabbaabba
2 0
w 0
abba

49
The * Operation
•: the set of all possible strings from
• alphabet
•* ,,,,,,,,,*
,
aabaaabbbaabaaba
ba

50
The +Operation
: the set of all possible strings from
alphabet except ,,,,,,,,,*
,
aabaaabbbaabaaba
ba * ,,,,,,,, aabaaabbbaabaaba

51
Language
•A language is any subset of
•Example:
•Languages:* ,,,,,,,,*
,
aaabbbaabaaba
ba },,,,,{
,,
aaaaaaabaababaabba
aabaaa

52
Another Example
•An infinite language}0:{ nbaL
nn aaaaabbbbb
aabb
ab L Labb

53
Operations on Languages
•The usual set operations
•Complement: aaaaaabbbaaaaaba
ababbbaaaaaba
aaaabbabaabbbaaaaaba
,,,,
}{,,,
},,,{,,,

 LL* ,,,,,,, aaabbabaabbaa

54
Reverse
•Definition:
•Examples:}:{ LwwL
RR ababbaabababaaabab
R
,,,, }0:{
}0:{
nabL
nbaL
nnR
nn

55
Concatenation
•Definition:
•Example: 2121 ,: LyLxxyLL baaabababaaabbaaaab
aabbaaba
,,,,,
,,,

56
Another Operation
•Definition:
•Special case: 

n
n
LLLL bbbbbababbaaabbabaaabaaa
babababa
,,,,,,,
,,,,
3 0
0
,,aaabbaa
L

57
More Examples
•}0:{ nbaL
nn }0,:{
2
mnbabaL
mmnn 2
Laabbaaabbb

58
Star-Closure (Kleene *)
•Definition:
•Example:
• 
210
* LLLL ,,,,
,,,,
,,
,
*,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba

59
Positive Closure
•Definition:*
21
L
LLL  ,,,,
,,,,
,,
,
abbbbabbaaabbaaa
bbbbbbaabbaa
bba
bba

60
Finite Automaton
Input
String

Output
String
Finite
Automaton

61
Finite Accepter

Input
“Accept”
or
“Reject”
String
Finite
Automaton
Output

62
Transition Graph

initial
state
final
state
“accept”
state
transition
Abba -Finite Accepter0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba,

63
Initial Configuration
•1
q 2
q 3
q 4
q a b b a 5
q a a b b ba,
Input Stringa b b a ba, 0
q

64
Reading the Input
•0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b b a ba,

650
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b b a ba,

660
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b b a ba,

670
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b b a ba,

680
q 1
q 2
q 3
q 4
q a b b a
Output: “accept”5
q a a b b ba, a b b a ba,
Input finished

69
Rejection
•1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b a ba, 0
q

70
•0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b a ba,

71
•0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b a ba,

72
•0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b a ba,

730
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba,
Output:
“reject”a b a ba,
Input finished

74
Another Examplea b ba, ba, 0
q 1
q 2
q a b a

75a b ba, ba, 0
q 1
q 2
q a b a

76a b ba, ba, 0
q 1
q 2
q a b a

77a b ba, ba, 0
q 1
q 2
q a b a

78a b ba, ba, 0
q 1
q 2
q a b a
Output: “accept”
Input finished

79
Rejectiona b ba, ba, 0
q 1
q 2
q a b b

80a b ba, ba, 0
q 1
q 2
q a b b

81a b ba, ba, 0
q 1
q 2
q a b b

82a b ba, ba, 0
q 1
q 2
q a b b

83a b ba, ba, 0
q 1
q 2
q a b b
Output: “reject”
Input finished

84
•Deterministic Finite Accepter (DFA)FqQM ,,,,
0 Q 0
q F
: Finite set of states
: input alphabet
: transition function
: initial state is a member of Q
: set of final states
:Q X Q

85
Input Alphabet 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, ba,

86
Set of States Q 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, 543210
,,,,, qqqqqqQ ba,

87
Initial State 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q

88
Set of Final StatesF 0
q 1
q 2
q 3
q a b b a 5
q a a b b ba, 4qF ba, 4
q

89
Transition Function 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, QQ: ba,

9010
,qaq 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q 1
q

9150
,qbq 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q

920
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 32
,qbq

93
Transition Function
• 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, a b 0
q 1
q 2
q 3
q 4
q 5
q 1
q 5
q 5
q 2
q 2
q 3
q 4
q 5
q ba, 5
q 5
q 5
q 5
q

94
Extended Transition Function * QQ*:* 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba,

9520
,* qabq 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q 1
q 2
q

9640
,* qabbaq 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba,

9750
,* qabbbaaq 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q

9850
,* qabbbaaq 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 0
q
Observation:There is a walk from to
with label0
q abbbaa 1
q

99
Recursive Definition
•)),,(*(,*
,*
awqwaq
qq 0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba,

1000
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, 2
1
0
0
0
0
,
,,
,,,*
),,(*
,*
q
bq
baq
baq
baq
abq

101
Languages Accepted by DFAs
•Take DFA
•Definition:
–The language contains
–all input strings accepted by
– = { strings that drive to a final state} M ML M M ML

102
Example
•0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, abbaML M
accept

103
Another Example0
q 1
q 2
q 3
q 4
q a b b a 5
q a a b b ba, ba, abbaabML ,, M
acceptacceptaccept

104
Formally
•For a DFA Language accepted by :FqQM ,,,,
0 M FwqwML ,*:*
0
alphabet
transition
function
initial
state
final
states

105
Observation
•Language accepted by :
•Language rejected by :FwqwML ,*:*
0 M FwqwML ,*:*
0 M

106
More Examples
•a b ba, ba, 0
q 1
q 2
q }0:{nbaML
n
accept trap state
or dead state

107
•ML
= { all strings with prefix }ab a b ba, 0
q 1
q 2
q
acceptba, 3
q a b

108
•ML
= { all strings without
substring }001 0 00 001 1 0 1 1 0 0 1,0

109
Regular Languages
•A language is regular if there is
•a DFA such that
•All regular languages form a language
family
–L M MLL

110
Example
•The language
•is regular:
•*,: bawawaL a b ba, a b b a 0
q 2
q 3
q 4
q

111
Non Deterministic
Automata

112
Non Deterministic Finite
AccepterFqQM ,,,,
0 :2
Q
Q

1131q 2q 3
q a a a 0
q }{a
Alphabet =
Nondeterministic Finite Accepter (NFA)

1141q 2q 3
q a a a 0
q
Two choices}{a
Alphabet =
Nondeterministic Finite Accepter (NFA)

115
No transition1q 2q 3
q a a a 0
q
Two choices
No transition}{a
Alphabet =
Nondeterministic Finite Accepter (NFA)

116a a 0
q 1q 2q 3
q a a
First Choicea

117a a 0
q 1q 2q 3
q a a a
First Choice

118a a 0
q 1q 2q 3
q a a
First Choicea

119a a 0
q 1q 2q 3
q a a a
“accept”
First Choice
All input is consumed

120a a 0
q 1q 2q 3
q a a
Second Choicea

121a a 0
q 1q 2q a a
Second Choicea 3
q

122a a 0
q 1q 2q a a a 3
q
Second Choice
No transition:
the automaton hangs

123a a 0
q 1q 2q a a a 3
q
Second Choice
“reject”
Input cannot be consumed

124
An NFA accepts a string:
when there is a computationof the NFA
that accepts the string
•All the input is consumed and the automaton
is in a final state

125
An 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
•The input cannot be consumed

126
Exampleaa
is accepted by the NFA:0
q 1q 2q 3
q a a a
“accept”0
q 1q 2q a a a 3
q
“reject”
because this computation
accepts aa

127a 0
q 1q 2q 3
q a a
Rejection examplea

128a 0
q 1q 2q 3
q a a a
First Choice

129a 0
q 1q 2q 3
q a a a
First Choice
“reject”

130
Second Choicea 0
q 1q 2q 3
q a a a

131
Second Choicea 0
q 1q 2q a a a 3
q

132
Second Choicea 0
q 1q 2q a a a 3
q
“reject”

133
Examplea
is rejected by the NFA:0
q 1q 2q a a a 3
q
“reject”0
q 1q 2q a a a 3
q
“reject”
All possible computations lead to rejection

134
Rejection examplea a 0
q 1q 2q 3
q a a a a

135a a 0
q 1q 2q 3
q a a a
First Choicea

136a a 0
q 1q 2q 3
q a a
First Choicea a
No transition:
the automaton hangs

137a a 0
q 1q 2q 3
q a a a
“reject”
First Choicea
Input cannot be consumed

138a a 0
q 1q 2q 3
q a a
Second Choicea a

139a a 0
q 1q 2q a a
Second Choicea 3
q a

140a a 0
q 1q 2q a a a 3
q
Second Choice
No transition:
the automaton hangsa

141a a 0
q 1q 2q a a a 3
q
Second Choice
“reject”a
Input cannot be consumed

142aaa
is rejected by the NFA:0
q 1q 2q 3
q a a a
“reject”0
q 1q 2q a a a 3
q
“reject”
All possible computations lead to rejection

1431q 2q 3
q a a a 0
q
Language accepted:}{aaL

144
Lambda →Transitions1q 3
q a 0
q 2q a

145a a 1q 3
q a 0
q 2q a

146a a 1q 3
q a 0
q 2q a

147a a 1q 3
q a 0
q 2q a
(read head doesn‟t move)

148a a 1q 3
q a 0
q 2q a

149a a 1q 3
q a 0
q 2q a
“accept”
String is acceptedaa
all input is consumed

150a a 1q 3
q a 0
q 2q a
Rejection Examplea

151a a 1q 3
q a 0
q 2q a a

152a a 1q 3
q a 0
q 2q a
(read head doesn‟t move)a

153a a 1q 3
q a 0
q 2q a a
No transition:
the automaton hangs

154a a 1q 3
q a 0
q 2q a
“reject”
String is rejectedaaa a
Input cannot be consumed

155
Language accepted:}{aaL 1q 3
q a 0
q 2q a

156
Another NFA Example0
q 1q 2q a b 3
q

157a b 0
q 1q 2q a b 3
q

1580
q 2q a b 3
q a b 1q

159a b 0
q 1q a b 3
q 2q

160a b 0
q 1q a b 3
q 2q
“accept”

1610
q a b a b
Another Stringa b 1q 2q 3
q

1620
q a b a b a b 1q 2q 3
q

1630
q a b a b a b 1q 2q 3
q

1640
q a b a b a b 1q 2q 3
q

1650
q a b a b a b 1q 2q 3
q

1660
q a b a b a b 1q 2q 3
q

1670
q a b a b a b 1q 2q 3
q

168a b a b 0
q a b 1q 2q 3
q
“accept”

169ab
ababababababL ...,,,
Language accepted0
q 1q 2q a b 3
q

170
Another NFA Example0
q 1q 2q 0 1 1,0

171{ }
{}*10=
...,101010,1010,10,λ=)(ML 0
q 1q 2q 0 1 1,0
Language accepted

172
Remarks:
•The symbol never appears on the
input tape 0
q 2M 0
q 1M {}=)M(L
1 }λ{=)M(L
2
•Extreme automata:

1730q 2q 1q a 0q 1q a }{=)(
1aML 2M 1M }{=)(
2aML
NFA DFA
•NFAs are interesting because we can
express languages easier than DFAs
b
a,b
a,b

174
Formal Definition of NFAsFqQM ,,,,
0 :Q : :
0
q :F
Set of states, i.e.210
,,qqq :
Input alphabet, i.e.ba,
Transition function
Initial state
Final states

17510
1,qq 0 1 1,0
Transition Function 0
q 1q 2q

1760
q 0 1 1,0 },{)0,(
201
qqq 1q 2q

1770
q 0 1 1,0 1q 2q },{),(
200
qqq

1780
q 0 1 1,0 1q 2q )1,(
2q

179
Extended Transition Function
•* 0q 5q 4q 3q 2q 1q a a a b 10
,* qaq

180540
,,* qqaaq 0q 5q 4q 3q 2q 1q a a a b

1810320
,,,* qqqabq 0q 5q 4q 3q 2q 1q a a a b

182
Formallywqq
ij
,*
It holds
if and only if
there is a walk from to
with label i
q j
q w

183
The Language of an NFA
•0q 5q 4q 3q 2q 1q a a a b 540 ,,* qqaaq M )(MLaa 50
,qqF

1840q 5q 4q 3q 2q 1q a a a b 0320 ,,,* qqqabq MLab 50
,qqF

185
•0q 5q 4q 3q 2q 1q a a a b 50
,qqF 540 ,,* qqabaaq )(MLaaba

1860q 5q 4q 3q 2q 1q a a a b 50
,qqF 10
,* qabaq MLaba

1870q 5q 4q 3q 2q 1q a a a b aaababaaML *

188
Formally
•The language accepted by NFA is:
•where
•and there is some M ,...,,
321
wwwML ,...},{),(*
0 jim
qqwq Fq
k (final state)

189
•0q kq w w w ),(*
0
wq MLw Fq
k iq jq

190
Equivalence of NFAs and DFAs

191
Equivalence of Machines
•For DFAs or NFAs:
•Machine is equivalent to machine
•if
•1M 2M 21 MLML

192
•0q 1q 2q 0 1 1,0 0q 1q 2q 0 1 1 0 1,0
NFA
DFA*}10{
1ML *}10{
2ML 1M 2M

193
•Since
•machines and are equivalent *10
21 MLML 1M 2M 0q 1q 2q 0 1 1,0 0q 1q 2q 0 1 1 0 1,0
DFA
NFA1M 2M

194
Equivalence of NFAs and DFAs
Question: NFAs =DFAs ?
Same power?
Accept the same languages?

195
Equivalence of NFAs and DFAs
Question: NFAs =DFAs ?
Same power?
Accept the same languages?
YES!

196
We will prove:
Languages
accepted
by NFAs
Languages
accepted
by DFAs
NFAs and DFAs have the same
computation power

197
Languages
accepted
by NFAs
Languages
accepted
by DFAs
Step 1
Proof:Every DFA is trivially an NFA
A language accepted by a DFA
is also accepted by an NFA

198
Languages
accepted
by NFAs
Languages
accepted
by DFAs
Step 2
Proof:Any NFA can be converted to an
equivalent DFA
A language accepted by an NFA
is also accepted by a DFA

199
NFA to DFA
•a b a 0q 1q 2q
NFA
DFA0q M M

200
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a M M

201
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b M M

202
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a M M

203
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a b M M

204
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a b ba, M M

205
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a b ba, M M )(MLML

206
NFA to DFA: Remarks
•We are given an NFA
•We want to convert it to an equivalent DFAM M )(MLML

207
•If the NFA has states
•the DFA has states in the power set
•,...,,
210
qqq ,....,,,,,,,
7432110
qqqqqqq

208
Procedure NFA to DFA

•1.Initial state of NFA:

•Initial state of DFA: 0
q 0
q

209
•a b a 0q 1q 2q
NFA
DFA0q M M

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

211
•a b a 0q 1q 2q
NFA0q 21,qq a
DFA},{),(*
210 qqaq 210 ,, qqaq M M },{),(*
210 qqaq

212
Procedure NFA to DFA
•Repeat Step 2for all letters in alphabet,
• until
•no more transitions can be added.

213
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a b ba, M M

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 j
q },...,,{
mji
qqq

215
•a b a 0q 1q 2q
NFA
DFA0q 21,qq a b a b ba, Fq
1 Fqq
21, M M

216
Theorem

Take NFAM
Apply procedure to obtain DFA M
Then and are equivalent :M M MLML

217
Finally
We have proven
Languages
accepted
by NFAs
Languages
accepted
by DFAs

218
Languages
accepted
by NFAs
Languages
accepted
by DFAs
We have proven
Regular Languages

219
Languages
accepted
by NFAs
Languages
accepted
by DFAs
We have proven
Regular LanguagesRegular Languages

220
Languages
accepted
by NFAs
Languages
accepted
by DFAs
We have proven
Regular LanguagesRegular Languages
Thus, NFAs accept the regular languages

221
Single Final State
for NFAs and DFAs

222
Observation
•Any Finite Automaton (NFA or DFA)
•can be converted to an equivalent NFA
•with a single final state

223a b b a
NFA
Equivalent NFA a b b a
Example

224
NFA
In General
Equivalent NFA
Single
final state

225
Extreme Case
NFA without final state
Add a final state
Without transitions

226
Some Properties of
Regular Languages

2271L 2L 21LL
Concatenation:*
1L
Star:21LL
Union:
Are regular
Languages
For regular languages and
we will prove that:
properties

228
We Say:
Regular languages are closed under21LL
Concatenation:*
1L
Star:21LL
Union:

229
Properties1L 2L 21LL
Concatenation:*
1L
Star:21LL
Union:
Are regular
Languages
For regular languages and
we will prove that:

2301L
Regular language11LML 1M
Single final state
NFA2M 2L
Single final state22LML
Regular language
NFA

231
Example}{
1
baL
n a b 1M baL
2 a b 2M

232
Union
•NFA for 1M 2M 21LL

233
•a b a b }{
1
baL
n }{
2baL }{}{
21
babaLL
n
NFA for

234
Concatenation
•NFA for 21LL 1M 2M

235
Example

•NFA fora b a b }{
1
baL
n }{
2baL }{}}{{
21
bbaababaLL
nn

236
Star Operation
•NFA for *
1L 1M *
1L

237
Example
•NFA for*}{*
1
baL
n a b }{
1
baL
n
N>= 0

238
Procedure: NFA to DFA
1Create a graph with vertex {q0}.Identify this vertex as
initial vertex of DFA.
2Repeat 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.
3Every state of G whose label contains any qf of F is
identified as a final vertex of DFA.
4If NFA accepts then vertex {q0} in G is also made a
final vertex.* * * *

239
q0
q2
q1
0,1 0,1
1
0

240
q0
{q0,
q1}
q
1
q0,q1,q2
q1,q2
q2
0
0
1
1
0
0,1
0,1
1
1
0,1
Equivalent
DFA
Start
0
Tags