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
2
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
3
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
4
5. Chomsky Hierarchy: Regular grammars,
unrestricted grammar, context sensitive
language, relationship among languages
5
32. • Deterministic Finite Accepter (DFA)
M Q, , , q0 , F
Q : Finite set of states
: input alphabet
: transition function
:Q X Q
q0 : initial state is a member of Q
F : set of final states
32
33. Input Alphabet
a, b
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
33
34. Set of States Q
Q q0 , q1, q2 , q3 , q4 , q5
a,b
q5
a a,b
b a b
q0 a q1 b q2 b q3 a q4
34
43. * q0 , ab q2
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
43
44. * q0 , abba q4
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
44
45. * q0 , abbbaa q5
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
45
46. Observation: There is a walk from q0 to q 5
with label abbbaa
* q0 , abbbaa q5
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
46
47. Recursive Definition
* q, q
• * q, wa ( * (q, w), a )
a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
47
48. * q0 , ab
* (q0 , a ), b
* q0 , ,a ,b
q0 , a , b
q1 , b
q2 a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
48
49. Languages Accepted by DFAs
• Take DFA M
• Definition:
– The language L M contains
– all input strings accepted by M
LM
– = { strings that drive M to a final state}
49
50. Example
LM abba M
• a,b
q5
b a a,b
a b
q0 a q1 b q2 b q3 a q4
accept
50
51. Another Example
LM , ab, abba M
• a,b
q5
b a a a,b
b
q0 a q1 b q2 b q3 a q4
accept accept accept
51
52. Formally
• For a DFA Language accepted by M :
LM w * : * q0 , w F
M Q, , , q0 , F
alphabet transition initial final
function state states
52
70. Second Choice
a a
q1 a q2
a
q0
a
No transition:
q3
the automaton hangs
70
71. Second Choice
a a
Input cannot be consumed
q1 a q2
a
q0
a
q3 “reject”
71
72. An NFA accepts a string:
when there is a computation of the NFA
that accepts the string
•All the input is consumed and the automaton
is in a final state
72
73. 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
73
74. Example
aa is accepted by the NFA:
“accept”
q1 a q2 q1 a q2
a a
q0 q0
a a
q3 q3 “reject”
because this computation
accepts aa 74
120. Remarks:
•The symbol never appears on the
input tape
•Extreme automata:
M1 M2
q0 q0
L(M1 ) = {} L(M 2 ) = {λ}
120
121. •NFAs are interesting because we can
express languages easier than DFAs
a,b
NFA M1 DFA M2
q2
q0 a q1 b
a,b
q0 a q1
L( M1 ) = {a} L( M 2 ) = {a} 121
122. Formal Definition of NFAs
M Q, ,
, q0 , F
Q : Set of states, i.e. q0 , q1, q2
: Input alphabet, i.e. a, b
: Transition function
q0 : Initial state
F : Final states 122
141. • Since L M1 L M2 10 *
• machines M1 and M 2are equivalent
0
NFA M1 q0 q1 0, 1 q2
1
0,1
0
DFA M2 q0 q1 1 q2
1
0 141
142. Equivalence of NFAs and DFAs
Question: NFAs = DFAs ?
Same power?
Accept the same languages?
142
143. Equivalence of NFAs and DFAs
Question: NFAs = DFAs ? YES!
Same power?
Accept the same languages?
143
144. We will prove:
Languages Languages
accepted accepted
by NFAs by DFAs
NFAs and DFAs have the same
computation power
144
145. Step 1
Languages Languages
accepted accepted
by NFAs by DFAs
Proof: Every DFA is trivially an NFA
A language accepted by a DFA
is also accepted by an NFA 145
146. Step 2
Languages Languages
accepted accepted
by NFAs by DFAs
Proof: Any NFA can be converted to an
equivalent DFA
A language accepted by an NFA
is also accepted by a DFA 146
158. Procedure NFA to DFA
• 2. For every DFA’s state {qi , q j ,..., qm}
• Compute in the NFA
* qi , a ,
* q j,a , {qi , q j ,..., qm}
•
...
{qi , q j ,..., qm}, a {qi , q j ,..., qm}
•
158
Add transition to DFA
159. NFA M a
q0 a q1 q2
• b
* (q0 , a ) {q1, q2 }
DFA M
q0 a
q1, q2
q0 , a q1, q2 159
160. Procedure NFA to DFA
• Repeat Step 2 for all letters in alphabet,
• until
• no more transitions can be added.
160
161. NFA M a
q0 a q1 q2
• b
b a
DFA M
q0 a
q1, q2
b
a, b
161
162. Procedure NFA to DFA
• 3. For any DFA state {qi , q j ,..., qm}
• If some q j is a final state in the NFA
• Then, {qi , q j ,..., qm }
•
162
is a final state in the DFA
163. NFA M a
q0 a q1 q2 q1 F
• b
a
DFA M b
q0 a
q1, q2
b q1, q2 F
a, b
163
164. Theorem
Take NFA M
•
Apply procedure to obtain DFA M
Then M and M are equivalent :
LM LM
164
165. Finally
We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
165
167. We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
Regular Languages Regular Languages
167
168. We have proven
Languages Languages
accepted accepted
by NFAs by DFAs
Regular Languages Regular Languages
Thus, NFAs accept the regular languages
168
185. Example
n
L1* {a b} *
• NFA for
n
L1 {a N>=}
b0
a
b
185
186. 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
186
final vertex.