CS6503 Theory of Computation Notes
CS6503 Theory of Computation Notes
OBJECTIVES:
The student should be made to:
Understand various Computing models like Finite State Machine, Pushdown Automata,
and Turing Machine.
Be aware of Decidability and Un-decidability of various problems.
Learn types of grammars.
UNIT II GRAMMARS 9
Grammar Introduction– Types of Grammar - Context Free Grammars and Languages–
Derivations and Languages – Ambiguity- Relationship between derivation and derivation
trees – Simplification of CFG – Elimination of Useless symbols - Unit productions - Null
productions – Greiback Normal form – Chomsky normal form – Problems related to CNF
and GNF.
TOTAL: 45 PERIODS
TEXT BOOKS:
1. Hopcroft J.E., Motwani R. and Ullman J.D, “Introduction to Automata Theory, Languages and
Computations”, Second Edition, Pearson Education, 2008. (UNIT 1,2,3)
2. John C Martin, “Introduction to Languages and the Theory of Computation”, Third Edition, Tata
McGraw Hill Publishing Company, New Delhi, 2007. (UNIT 4,5)
REFERENCES:
1. Mishra K L P and Chandrasekaran N, “Theory of Computer Science - Automata, Languages and
Computation”, Third Edition, Prentice Hall of India, 2004.
2. Harry R Lewis and Christos H Papadimitriou, “Elements of the Theory of Computation”, Second
Edition, Prentice Hall of India, Pearson Education, New Delhi, 2003.
3. Peter Linz, “An Introduction to Formal Language and Automata”, Third Edition, Narosa
Publishers, New Delhi, 2002.
4. Kamala Krithivasan and Rama. R, “Introduction to Formal Languages, Automata Theory and
Computation”, Pearson Education 2009
TABLE OF CONTENTS
8 Minimization of DFA
UNIT II GRAMMARS
5 Simplification of CFG
1 Pushdown Automata
2 Definitions
3 Moves
4 Instantaneous descriptions
2 Models
7 Partial Solvability
8 P and NP completeness
References 107
Theory of Computation 1
THEORY OF COMPUTATION
UNIT I - AUTOMATA
The theory of computation is the branch that deals with whether and how efficiently
problems can be solved on a model of computation, using an algorithm. The field is divided
into three major branches: automata theory, computability theory and computational
complexity theory.
Formal Proofs are the proofs in which we try to prove the statement ‘B’ is true
because statement ‘A’ is true. In other words, the Statement “If A then B” means that B is
deduced from A. In this statement A is called hypothesis and B is called conclusion
statement.
The formal proofs can be done by deductive proof and inductive proof.
Proof:
To prove R=S, we have to prove AUB=BUA
(i)x is in AUB then it is in BUA
Sl. No. Statement Justification
1 x is in AUB Given
2 x is in Aor x is in B By definition of union & (1)
3 x is in B or x is in A By definition of union & (2)
4 x is in BUA By definition of union & (3)
Proofs by contradiction
In proof by contradiction, to prove the statement of the form “if A true then B true”,
We start with statement A is not true by assumption and try to get the conclusion statement B.
When it impossible to reach B then we contradict our self and accept that A is true.
Example: Prove PUQ = QUP
Proof:
Initially assume, PUQ = QUP is not true
i.e. PUQ ≠ QUP
Now consider, x is in PUQ
x is in P or x is in Q (By Definition of Union)
x is in Q or x is in P (By Definition of Union)
x is in QUP (By Definition of Union)
This contradicts our assumption PUQ ≠ QUP
Hence the assumption which we made initially is
false Therefore PUQ = QUP is proved.
Example 1
Prove that every integer n ≥ 0, the number 42n + 1 + 3n + 2 is multiple of 13 by induction.
Let n = k, P(k) = 42(k) + 1 + 3(k) + 2= 42k + 1 + 3k + 2 = 13.t, true for some integer t
Theory of Computation 3
= 42(k + 1) + 1 + 3(k + 1) + 2
= 42k + 2 + 1 + 3k + 1 + 2
= 42k + 1 + 2 + 3k + 2 + 1
= 42.42k + 1 + 3.3k + 2
= 13[16. t + 3k+2 ]
= Multiple of 13
Example 2
Example 3
Show that 2n> n3 for n ≥ 10 by mathematical induction.
Proof:
Let n= 10, 210> 103, 1024 > 1000, The condition is true.
Theory of Computation 4
Let n= 11, 211> 113, 2048 > 1331, The condition is true.
Let n = 12, 212> 123, 4096 > 1728, The condition is true.
= 2k.2 1
> k3.2 1
= 213 = 8192
Example 4
Show that n! >= 2n - 1 by mathematical induction.
Proof:
Let n = k, k! >= 2k – 1
Let n = k + 1 (k + 1)!= (k + 1) k!
>=(k + 1) 2k – 1
(k + 1)!>=(k + 1) 2k – 1
Example 4
𝑛(𝑛+1)(2𝑛+1)
Prove by mathematical induction Ʃn2 = for all n ≥ 1.
6
Proof:
2 2 2 𝑛(𝑛+1)(2𝑛+1)
1 + 2 + ... + n =
6
1(1+1)(2.1+1) 1𝑥2𝑥3
Let n = 1, LHS = 12= 1, RHS = = = 1, LHS = RHS
6 6
2(2+1)(2.2+1) 2𝑥3𝑥5
Let n = 2, LHS = 12 + 22= 1 + 4 = 5, RHS = = = 5, LHS = RHS
6 6
k(k+1)(2k+1)
Let n = k, 12 + 22 + ... + k2= , assumed to be true
6
k(k+1)(2k+1)
= + (k + 1) (k +1)
6
k(k+1)(2k+1)
6(k+1)(k+1)
=
+6 6
k(k+1)(2k+1)+6(k+1)(k+1)
=
6
(k+1)[k(2k+1)+6(k+1)]
= 6
(k+1)( k+2)(2k+3)
= 6
(k+1)(k+1+1)(2[k+1]+1)
RHS 6
= (k+1)(k+2)(2k+2+1)
6
= (k+1)( k+2)(2k+3)
6
Alphabet:
An alphabet is a finite non empty set of symbols. The symbol Σ is used to denote the
alphabet.
1) Σ = {0, 1}
2) Σ = {a, b, c, …, z}
3) Σ = Set of ASII character
String:
The total number of symbols in the string is called length of the string
Example:
1) |0001|=4
2) |100|=3
Empty string is the string with zero occurrence of symbol .This empty string is denote
by ε
Power of an alphabet
If Σ is an alphabet, then the set of all string of certain length forms an alphabet .
Example :
∑ = {0, 1}
∑0 ={ ε }
∑1 = {0, 1}
∑+ = ∑1 𝑈 ∑2 𝑈 ∑3 …
∑+ = ∑i ⋃∞
i
∑∗ = ∑0 𝑈 ∑1 𝑈 ∑2 𝑈 …
∑∗ = ∑i ⋃∞
i
Concatination of strings
Let X and Y be the two strings over Σ = {a, b, c}. Then XY denotes the concatenation
of X and Y.
X = aabb
Y = cccc
XY = aabbcccc
YX = ccccaabb
A set of strings of all which are chosen from ∑∗ is called a language, where ∑ is a
particular alphabet set.
A finite automata has a several parts. It has set of states and rules for moving from
one state to another state depending on the input symbols.
It has the input alphabet, start state, and a set of accept state.
δ The transition function [Move from one state to another ] δ:Qx ΣQ
Theory of Computation 8
a b c a a b c a Input tape
Tape head /
reader
Finit
Types of finite automata (FA)
e
Deterministic finite automata (DFA)
Non deterministic finite automat (NFA)
Transition diagram
Transition table
Finite automata are called Deterministic automata if there is only one path for its
specified input from current state to next state.
Example 1 Design Finite Automata (FA) which accepts only input 111 over the input set Σ =
{1}
Solution:
Start q0 1 q1 1 q2 1
q3
Example 2 Design FA which accepts only those strings which start with 0 and end with 1
over the input set Σ = {0, 1}
Solution:
0 1
Start q0 0
q1 1
q3
0
Theory of Computation 9
Example 3 Design FA & State Table which accepts odd number of 1’s and any number of
0’s.
0 Input
States 0 1
q2
1 q0 q1 q2
1
Start q0 1 q1 q1 q2
0 q1 q2 q2 q1
0
State Transition Diagram State Transition Table
FA A = (Q, ∑, δ, q0, F)
= ({q0, q1, q2}, {0, 1}, {δ(q0, 0)= q1, δ(q0, 1)= q2, δ(q1, 0)= q1, δ(q1, 1)= q2 , δ(q2, 0)=
q2, δ(q2, 1)= q1 }, q0, {q2})
Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = {1}.
Start 1 1 q2 1
Example5 Design FA & State Table which accepts the binary number which is divisible by 3.
Input
States 0 1
1 q0 q1 q2
0
q1 q1 q2
Start q0 0 1 q2 q3
q1
q2 q3 q1
1 0 q2
1 q3 q3
00
Example 6 Design FA to accept L, where L= {Strings in which ‘a’ always appears tripled}
over the input set Σ = {a, b}.
Input
b b States a b
a a a s0 s1 s0
Start s0 s1 s2 s3
a s1 s2
s2 s3
s s1 s3
3
1 q2 q2 q1
State Transition Diagram
State Transition Table
b b
a
Start q0 q0
q0
Theory of Computation 11
Finite automata is also called as non deterministic automata when many paths are
specified in code from the current state to next state
A ={Q , ∑ , δ , qo , F}
Example : 1 construct NFA where L={0101* + 0100 n ≥ 0} over the string ∑={0,1}
0 1 00
Start q1 q2 q3 q4
0
q5
0
q6
State\ip 0 1
q1 q2 ɸ
q2 ɸ q3
q3 {q4 , q5 } ɸ
q4 ɸ q4
q5 q6 ɸ
q6 ɸ ɸ
M=({ q1 q2 q3 } , {0,1} , δ , q1 , { q3 } )
Where δ is given by
sol :
1
0
1
1
Start q1 0 q2 q3
0 0
0
0
Theory of Computation 12
state 0 1
q1 {q2 , q3} q1
q2 {q1 , q2} ɸ
q3 q2 {q1 , q2}
The ε transition in NFA is given in order to move from one state to another without
having any symbol from input.
Theory of Computation 13
Definition:
Q x ( ∑ u { ε } ) 2Q
L(M) ={ w/w € ∑∗ }
It is set of all state which are reachable from state p or epsilon transition such that
a b c
ε ε
Start q0 q1 q
2
ε closure(q1)={ q1 , q2}
ε closure(q2)={q2 }
1) Find all the ε transition for each state from Q that will be called as ε closure { qi }
Where { qi } is the element of Q
2) δ’ transition can be obtained from δ transition. i.e., an ε closure of δ.
3) Step 2 is repeated for each input symbol and for each state of given NFA.
4) Using the resultant state the transition table for equivalent NFA without ε can be
built .
Example 1: Convert the given NFA with ε transition to NFA without ε transition.
b
a ε
Start q0 q1 q
2
Theory of Computation 14
Step 1: ε closure
Step 2:
Step 3:
= ε closure(q1)
= { q1 , q2 }
= ε closure ɸ
={ɸ}
= ε closure (ɸ U ɸ)
= ε closure (ɸ)
={ɸ}
Theory of Computation 15
= ε closure (ɸ U q2)
= ε closure ( q2 )
= { q2 }
= ε closure ɸ
={ɸ}
= ε closure(δ( q2 , b))
= ε closure (q2 )
= { q2 }
Transition table :
state a b
q0 {q1 ,q2} ɸ
q1 ɸ q2
q2 ɸ q2
Step 4:
b
a
Start q2
a q2 b q2
Theory of Computation 16
Example 2 : Construct NFA with ε which access a language consisting of a string of any
number of ‘a’ followed by any number of ‘b’ and followed by any number ‘ c ‘. Convert
the NFA with ε to NFA without ε.
sol :
a b c
ε ε
Start q0 q1 q
2
Step 1: ε closure
step
2:
δ(q0 , a) = q0 δ(q0 , b) = ɸ δ (q0, c) = ɸ δ (q0, ε) = q1
Step 3:
= ε closure ( q0 Uɸ U ɸ)
= ε closure ( q0 )
= { q0 , q1 , q2 }
= { q1 , q2 }
= ε closure (ɸ Uɸ Uq2)
= { q2 }
= ε closure (ɸ 𝑈 ɸ )
= ε closure (ɸ)
= {ɸ}
= ε closure (q1)
= {q1 , q2}
= ε closure (ɸ𝑈q2)
= {q2}
= ε closure(δ(q2, a))
= ε closure (ɸ)
= {ɸ}
= ε closure(δ(q2, b))
= ε closure (ɸ)
= {ɸ}
= ε closure(δ(q2, c))
= ε closure (q2)
= {q2}
Step 4:
Transition table
state a b c
q1 ɸ {q1 ,q2} q2
q2 ɸ ɸ q2
Transition diagram:
a b c
a, b b
Start q0 q1 q
2
a, b
Let M={Q , ∑ , δ , qo , F} is the NFA which accepts the language L(M) then there
should be equivalent DFA denoted by M’={ Q’ , ∑’ , δ’ , qo’ , F’} such that L(M)=L(M’).
Theory of Computation 19
Conversion Steps:
STEP 1: The start state of NFA M will be the start state of DFA M’. Hence add qo of NFA to
Q’ then, find the transition for this start state.
STEP 2: For each state {q1, q2, q3……qi} in Q’. The transition for each input symbol ∑ can
be obtained as follows,
(ii) Add the [q1, q2, q3, ... , qk] in DFA if it is not already in Q.
(iii) Then, find the transition for every input symbol from ∑ for states [q 1, q2,
q3, ... , qk], if we get some state [q1,q2…..qn] which is not Q’ of DFA then add
this to Q’.
(iv) If there is no new state generating then stop the process after finding
all the transition.
(v) For the state [q1, q2, q3, ... , qk] € Q’ of DFA, if any 1 state qi is a final
state of NFA then [q1,q2…..qn] becomes a final state. Thus the set of all final
states € F’ of DFA.
δ (q0,1) = { q1}
δ (q1,0) = φ
Sol:
St/Ip 0 1
q0 {q0, q1} {q1}
q1 φ {q0, q1}
Theory of Computation 20
Transition Diagram:
= { q0, q1} U φ
= { q0, q1}
= { q0, q1}
Transition Table:
St/Ip 0 1
qo {q0, q1} {q1}
q1 φ {q0, q1}
{q0, q1} {q0, q1} {q0, q1}
St/Ip 0 1
→p {p, q} p
q r r
r s φ
s s s
Sol.
Transition Diagram:
Transition Table:
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
= {p, q} U {r}
= {p, q, r}
= {p} U {r}
= {p, r}
Theory of Computation 22
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
= {p, q, r, s}
= {p} U {r} U { φ }
= {p, r}
= {p, q} U {s}
= {p, q, s}
= {p} U { φ }
= {p}
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
Theory of Computation 23
{p, r} {p, q, s} p
= {p, q, r, s}
= {p, r, s}
= {p, q, r, s}
= {p, q, r, s}
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
{p, r} {p, q, s} p
= {p, q, s},
= {p, s}
St/Ip 0 1
→[P] [p,q] [ p]
[q] [r] [ r]
[r] [s] φ
s [s] [s]
= {p,q} U {s}
= [p,q,s]
= {p} U {s}
= [p,s]
Theory of Computation 25
→[P] [p,q] [ p]
[q] [r] [ r]
[r] [s] -
Step 1 : Consider M={Q, ∑, δ, q0, F} is a NFA with ε , we have to convert this NFA with ε to
equivalent DFA,
MD =( QD,∑ D, δD, qD, FD). Obtain ε closure (q0 ) = { p1p2……pn } becomes its start
state of DFA.
Step3 : State obtained [ P1P2……Pn ] ϵ QD , states containing final state Pi is a final state
DFA.
Theory of Computation 26
b a
ε q1 ε
q0 q2
b
ε closure(q0 )={ q0 q1 q2}
ε closure(q1)={ q1 q2}
ε closure(q2)={q2 }
= ε closure(δ({q0 q1 q2 } ,a) )
= ε closure(ɸ U q1 U q1 )
= ε closure q1
= { q1 q2}
= ε closure(δ({q0 q1 q2 } ,b) )
= ε closure(q0 U ɸ U q0 )
= ε closure q0
= { q0 q1 q2}
= ε closure(δ({ q1 q2 } ,a) )
= ε closure( q1 U ɸ )
= ε closure q1
= { q1 q2}
= ε closure(δ({ q1 q2 } ,b) )
=ε closure(ɸ U q0 )
=ε closure q0 = { q0 q1 q2}
= ε closure(δ({ q2 } ,a) )
= ε closure q1
= { q1 q2}
= ε closure(δ({ q2 } ,b) )
=ε closure q0
= {q0 q1 q2}
Theory of Computation 28
Transition of NFA
input a b
state
q0 { q1 q2} {q0 q1 q2}
Transition diagram
b b a,b
Start q0 q1
a,b
a,b
a,b
b a,b
11
q2
a,b
δ ‘([q1 q2 ],a)= δ(q1 ,a) U δ(q2,a)
= { q1 , q2}U{ q1 , q2 }
=[ q1 , q2 ]
= { q0 , q1 , q2}U{ q0 , q1 , q2 }
=[q0 , q1 , q2 ]
={ q1 , q2}U{ q1 , q2 }U{ q1 , q2 }
=[ q1 , q2 ]
=[ q0 ,q1 , q2 ]
input a b
state
q0 [ q1 q2 ] [ q0 q1 q2 ]
q1 [ q1 q2 ] [ q0 q1 q2 ]
q2 [ q1 q2 ] [ q0 q1 q2 ]
q1 q2 [ q1 q2 ] [ q0 q1 q2 ]
[ q0 q1 q2 ] [ q1 q2 ] [ q0 q1 q2 ]
q1 qq20
q0
a a b
a b b
[q1,q2] b [q1,q2,q3]
a b
Theory of Computation 30
MINIMIZE METHOD
δ (A,0)=B δ (A,1)=F
δ (B,0)=G δ (B,1)=C
δ (C,0)=A δ (C,1)=C
δ (D,0)=C δ (D,1)=G
δ (E,0)=H δ (E,1)=F
δ (F,0)=C δ (F,1)=G
δ (G,0)=G δ (G,1)=E
δ (H,0)=G δ (H,1)=C
TABLE 1
C is final state, It is distinguishable from other states.
C X X
D X
E X
F X
G X
H X
A B C D E F G
Theory of Computation 31
TABLE 2
B X
C X X
D X X
E X
F X X
G X X
H X X
TABLE :3
B X
C X X
D X X X
E X X
F X X X
G X X
H X X
A B C D E F G
Theory of Computation 32
TABLE :4
B X
C X X
D X X X
E X X X
F X X X X
G X X X
X
H X X
A B C D E F G
TABLE :5
B X
C X X
D X X X
E X X X
F X X X X
G X X X X
H X X X X
A B C D E F G
Theory of Computation 33
TABLE :6
B X
C X X
D X X X
E X X X
F X X X
G X X X X X
H X X X X X X
A B C D E F G
TABLE :7
B X
C X X
D X X X
E X X X
F X X X X
G X X X X X X
H X X X X X X
A B C D E F G
Minimized DFA
State/Input 0 1
->A B D
B G C
C* A C
D C G
E G A
Theory of Computation 34
𝜹(A,0)=B δ(A,1)=F
δ(B,0)=G δ(B,1)=C
δ(C,0)=A δ(C,1)=C
δ(D,0)=C δ(D,1)=G
δ(E,0)=H δ(E,1)=F
δ(F,0)= C δ(F,1)=G
δ(G,0)=G δ(G,1)=E
δ(H,0)=G δ(H,1)=c
Table 1
St\input 0 1
A B F
B G C
C A C
D C G
E H/B F
F C G
G G E
H G C
B=H
Eliminate H
Replace H by B
Table 2
St/input 0 1
A B F
B G C
C A C
D C G
E B F
F C G
G G E/A
A=E
Eliminate E
Replace E by A
Theory of Computation 35
Table 3
St\input 0 1
A B F/D
B G C
C A C
D C G
F C G
G G A
D=F
Eliminate F
Replace F with D
Table 4
St\input 0 1
A B D
B G C
C A C
D C G
G G A
A B
0
1 1 0 1 1
0
1
c
D G
0
Theory of Computation 36
THEOREM: Let L be a set accepted by Nondeterministic finite automata (NFA), then there
exist a Deterministic finite automata (DFA) that accepts L.
Proof:
Let M = (Q, Σ, δ, qo, F) be an NFA for language L, then Define DFA Mʹ such that
Mʹ = (Qʹ, Σʹ, δʹ, qoʹ, Fʹ)
(i) The states of Mʹ are all the subsets of M then the Qʹ=2Q
(ii) The input symbols are common for both NFA and DFA. i.e., Σʹ = Σ
(iii) If q0 is the initial state in the NFA, then q0ʹ = [q0] = initial state in DFA
(iv) Fʹ be the set of all final states which contain final states of M. i.e., Fʹ ⊆ 2Q 𝖴 F
(v) The element in Qʹ will be denoted by [q1, q2, q3, … , qi] is a single state in Qʹ and the
elements in Q denoted by{q1, q2, q3, …, qi} are multiple states in Q. Define δʹ such that
δʹ([q1, q2, q3, …, qi], a) = [p1, p2, p3, …, pj] iff δʹ({q1, q2, q3, …, qi}, a) = {p1, p2, p3, …, pj}
This mean that in NFA, at the current states { q1, q2, q3, …, qi }, if we give input a
then it goes to the next states {p1, p2, p3, … , pj}.
While constructing DFA, the current state is assumed to be [q1, q2, q3, …, qi] with
input a, the next state is assumed to be [p1, p2, p3, … , pj].
On applying δ function on each of states q1, q2, q3, …, qi, the new states may be any
of the states from p1, p2, p3, … , pj.
The theorem can be proved by mathematical induction on length of the input string x.
δʹ(q0ʹ, x) = [q1, q2, q3, …, qi] if and only if δ(q0, x) = {q1, q2, q3, …, qi}
Basis: If the length of input string is 0, i.e., |x|=0, that means x is ε then q0ʹ = [q0]
Induction: If we assume that the hypothesis is true for the input string of length 𝑚 (or less
than 𝑚), then if xa is the string of length 𝑚 + 1.
Now the function δʹ can be written as δʹ(q0ʹ, xa) = δʹ(δʹ(q0, x), a)
By the induction hypothesis,
δʹ(q0ʹ, x) = [p1, p2, p3, … , pj] if and only if δ(q0, x) = {p1, p2, p3, … , pj}
By definition of δʹ
δʹ([p1, p2, … , pj], a) = [r1, r2, ..., rk] if and only if δ({p1, p2, … , pj}, a) = {r1, r2, ..., rk}
Thus, δʹ(q0ʹ, xa) = [r1, r2, ..., rk] if and only if δ(q0, xa) = {r1, r2, ..., rk} is shown by induction.
Therefore L(M)=L(Mʹ).
i.e., If a language is accepted by NFA then the same language is also accepted by DFA.
Hence the theorem∎
THEOREM: If L is accepted by NFA with ε transition, then their exist L which is accepted
by NFA without ε transition. (Show that the language L accepted by NFA with ε move must
be accepted by NFA without ε move.)
Proof:
Let M = (Q, Σ, δ, q0, F) be an NFA with ε transition.
Construct Mʹ = (Q, Σ, δʹ, q0, Fʹ)
where Fʹ={ F 𝖴{q0} if ε closure contains state off
{F otherwise
Mʹ is a NFA without ε moves. The δʹ function can be denoted by the δʹʹ with same input.
For example, δʹ(q, a) = δʹʹ(q, a) for some q in Q and a from Σ.
We will apply the method of induction with input string x.
Basis:
The x will not be ε because δʹ(q0, ε)={q0} and δʹʹ(q0, ε) = ε-closure(q0)
Assume that the length of string x to be 1, i.e., |x|=1, then x is a symbol, say ʹaʹ.
δʹ(q0, a) = δʹʹ(q0, a)
Induction
Assume that the length of string x to be more than 1. i.e., |x| >1.
Theory of Computation 37
Let w = xa
δʹ(q0, wa) = δʹ(δʹ(q0, w), a)
By Induction hypothesis,
δʹ(q0, w) = δʹʹ(q0, w) = P
Now we will show that δʹ(p, a) = δ(q0,wa)
But δʹ(p, a) = 𝖴q in P δʹ(q, a) = 𝖴q in P δʹʹ(q, a)
AS P = δʹʹ(q0, w)
We have 𝖴q in P δʹʹ(q, a)= δʹʹ(q0,wa)
Thus by define of δʹʹ, δʹ(q0, wa) = δʹʹ(q0,wa)
L(M)=Lʹ(M)
i.e., If a language is accepted by NFA with ε transition then the same language is also
accepted by NFA without ε transition.
Hence the theorem∎
REGULAR EXPRESSION:
DEFENITION:
The language accepted by finite automata are easily described by simple
expression called regular expression.
REGULAR SET:
Regular sets are the sets which are accepted by finite automata.
EXACT DEFENITION:
Let ∑ be an alphabet which is used to denote the input set. The regular
expression over ∑ can be defined as follows
1) Фis the regular expression which denotes the empty set.
2) ξ is the regular expression and denote the set {ξ} (null string).
3) For each a in ∑ ,a is a regular expression and denote the set{a}.
4) If ‘R’ and ‘S’ are regular expression denoting the languages L1 and L2
respectively then
r+s is equivalent to L1υL2 ie.union
rs is equivalent to L1L2 ie.concatenation
r* equivalent to L1* ie.klean closure
EXAMPLE 1: write the regular expression for the language accepting all combination of a’s
over the set ∑={a}.
Solution:
Regular set={ ξ,a,aa,aaa,…….}
Regular expression(RE)=a*
EXAMPLE 2: design the RE for the language accepting all combination all combination of
a’s except the null q string over ∑={a}
Solution:
Regular set={ a,aa,aaa,………}
Regular expression(RE)=a+
EXAMPLE 3: design the RE for the language containing any no of a’s and b’s.
Solution:
Regular set={ ξ,a,b,aa,ab,bb,ba,aaa...............}
Theory of Computation 38
Regular expression(RE)=(a+b)*
EXAMPLE 4: construct RE for the language accepting all the strings which are ending with
00 ∑={0,1}.
Solution:
Regular set={ 00,000,100,0000,0100,1000,1100…........}
Regular expression(RE)=(0+1)*00
EXAMPLE 5: write the RE for the language accepting the strings which are starting with 1
and ending with 0 ∑={0,1}
Solution:
Regular set={ 10,100,110,1000,1010,1100,1110…..........}
Regular expression(RE)=1(0+1)*0
EXAMPLE 6: write RE to denote the language which accepts all the string which begin or
end with with either 00 or 11.
Solution:
L1=string begin with 00 or 11
L1=(00+11)(0+1)*
L2=string end with 00 or 11
L2 =(0+1)*(00+11)
RE=(00+11)(0+1)*+(0+1)*(00+11)
EXAMPLE 7: construct a RE for the language L which accepts all strings with atlest two ‘b’
over ∑={a.b}.
Solution:
RE=(a+b)*b(a+b)*b(a+b)*
EXAMPLE 8:Construct RE for the language which accepts all the string with atleast two b
over ∑={a,b,c}
Solution:
` RE=(a+b+c)*b(a+b+c)*b(a+b+c)*
EXAMPLE 9:construct a RE for the language which consist of exactly 2b’s over the set
∑={a,b}
Solution:
RE=a*ba*ba*
r, =b
r, =rΎ r4
rΎ =b
r4 =a*
step1:
r, =b
Step2:
R3=01
Step3:
R2=1
Step4: 01+2*
Theory of Computation 40
Step5:(01+2*)1
Step2:
Step3:
Theory of Computation 41
Step4:
Step5:
Step6:
Step7:
Theory of Computation 42
Step2:
Step3:
Step2:
Theory of Computation 43
Step3:
Step4:
Step2: there areq2,q3,……..qn no of states, the final state may be qj where j≤n.
Step3:let αji represents the transition from qj to qi.
Step4:calculate qi Є qi=αji.qij.
If qi is the start state then qi=αji.qj+ξ.
Step5:similarly compute the final state which ultimately gives the regular expression R.
R=Q+P then R=QP*
EXAMPLE1: construct the RE for the given DFA
Solution:
q1=ξ+q1a 1
q2=q1b+q2d 2
consider q1=ξ+q1a
q1=ξa*
q1= a*
consider q2=q1b+q2b
sub q1= a* =>q2= a*b+q2b
q2= a*b+ b*
q2= a*b+ RE= a*b+
EXAMPLE2: construct RE for the DFA given below
Solution:
q1=ξ+q30+q10 1
q2= q11+q21+ q31 2
q3= q20 3
sub q3 in q2
q2= q11+q21+ q31
q2= q11+q2(1+01)
q2= q11(1+01)* 4
sub 3 in 4
q1=ξ+ q200+q10 5
sub 4 in 5
Theory of Computation 45
Solution:
Refer example 1
Since q2 is the final state its enough to find q2 only and q3 is not the final state
USING DIRECT METHOD:
Construct RE for the given DFA
Step1:
K=0
r11 ξ
r12 0
r21 Ф
r22 ξ
Step2:
rikj=(rik-1k) (rkk-1k)* (rkk-1j)+ rik-1j
K=1
1
(r1 1) i=1,j=1 (r111)= (r101) (r101)*(r1o1)+ r101
=(ξ)(ξ)*(ξ)+ξ
=ξ+ξ
=ξ
(r112) i=1,j=2 (r1 2)= (r101) (r101)*(r1o2)+ r102
1
=ξ+0+0
=0
(r211) i=2,j=1 (r2 1)= (r201) (r101)*(r1o1)+ r201
1
=Ф.ξ.ξ+Ф
=Ф
=ξ
Step3:
Compute and find state from state q1 to final state q2
K=2
(r1 2)= (r102) (r202)*(r2o2)+ r102
2
=0(ξ)*ξ+0
=0+0
r12=0
Theory of Computation 47
Part (b) shows the construction for ϕ. Clearly there are no paths from start state to accepting
state, so ϕ is the language of this automaton. i.e., Regular expression = ϕ.
Finally, part (c) gives the automaton for a regular expression a. The language of this
automaton evidently consists of the one length string a, which is also L(a). i.e., Regular
expression = a.
a
It is easy to check that these automata all satisfy conditions (1), (2), and (3) of the inductive
hypothesis.
INDUCTION: We assume that the statement of the theorem is true for the immediate sub-
expressions of a given regular expression; that is, the languages of these sub-expressions are
also the languages of ε-NFA's with a single accepting state. The four cases are:
1. The expression is R + S for some smaller expressions R and S. Then the automaton of
Figure serves. That is, starting at the new start state, we can go to the start state of
either the automaton for R or the automaton for S. We then reach the accepting state of
one of these automata, following a path labeled by some string in L(R) or L(S),
respectively. Once we reach the accepting state of the automaton for R or S, we can
follow one of the ε-arcs to the accepting state of the new automaton.
R ε
ε
ε ε
2. The expression is RS for some smaller expressions R and S. The automaton for the
concatenation is shown in Figure. Note that the start state of the first automaton
becomes the start state of the whole, and the accepting state of the second automaton
becomes the accepting state of the whole. The idea is that the only paths from start to
accepting state go first through the automaton for R, where it must follow a path
labeled by a string in L(R), and then through the automaton for S, where it follows a
path labeled by a string in L(S).
ε
R S
Thus, the paths in the automaton of Figure are all and only those labeled by
strings in L(R)L(S).
3. The expression is R* for some smaller expression R. Then we use the automaton
of Figure. That automaton allows us to go either:
ε ε
R
(a) Directly from the start state to the accepting state along a path labeled ε. That
path lets us accept ε, which is in L(R)* no matter what expression R is.
(b) To the start state of the automaton for R, through that automaton one or more
times, and then to the accepting state. This set of paths allows us to accept
strings in L(R), L(R)L(R), L(R)L(R)L(R), and so on, thus covering all strings in
L(R) except perhaps ε, which was covered by the direct arc to the accepting state
mentioned in the figure.
4. The expression is (R) for some smaller expression R. The automaton for R also serves
as the automaton for (R), since the parentheses do not change the language defined by
the expression.
It is a simple observation that the constructed automata satisfy the 3 conditions given in the
inductive hypothesis - one accepting state, with no arcs into the initial state or out of the
accepting state. ∎
Theory of Computation 49
For the string w of length m, this is more than the number of states n. By
pigeonhole principle, at least one state must repeat. Thus we can find two different integers
i and j with 0 ≤ i < j ≤ 𝑛 such that 𝑝i = 𝑝j. Now we break w = 𝑥𝑦𝑧 as follows:
1. 𝑥 = 𝑎1𝑎2 … 𝑎i
2. 𝑦 = 𝑎i+1𝑎i+2 … 𝑎j
3. 𝑧 = 𝑎j+1𝑎j+2 … 𝑎𝑚
In the DFA 𝐴 as shown in figure, we can move from the start state p0 to pi with the
input string 𝑥, 𝑦 takes us from 𝑝i back to 𝑝i (since 𝑝i = 𝑝j), and 𝑧 takes us from 𝑝i to 𝑝𝐹.
𝑦 = 𝑎i+1 … 𝑎j
𝑧 = 𝑎j+1 … 𝑎𝑚
Start 𝑥 = 𝑎1 … 𝑎i
p0 pi pF
ADVANTAGES: Pumping lemma is used to check the given language is not regular or not.
Theory of Computation 50
that L1 𝖴 L̅2 is regular. In other words L1 - L2 is regular. Thus regular languages are closed
under difference.
Theorem 7: If L1 and L2 are two languages then L1· L2 is regular. In other words regular
languages are closed under concatenation.
Proof: If L1 and L2 are regular then they can be expressed as L 1 =L(R1) and L2 =L(R2), Then
L1.L2 =L(R1· R2) thus we get a regular language. Hence it is proved that regular languages are
closed under concatenation.