KEMBAR78
Cs6503 theory of computation book notes | PDF
THEORY
OF
COMPUTATION
G. Appasami, M.Sc., M.C.A., M.Phil., M.Tech., (Ph.D.)
Assistant Professor
Department of Computer Science and Engineering
Dr. Paul’s Engineering Collage
Pauls Nagar, Villupuram
Tamilnadu, India
SARUMATHI PUBLICATIONS
Villupuram, Tamilnadu, India
First Edition: July 2016
Published By
SARUMATHI PUBLICATIONS
© All rights reserved. No part of this publication can be reproduced or stored in any form or
by means of photocopy, recording or otherwise without the prior written permission of the
author.
Price Rs. 101/-
Copies can be had from
SARUMATHI PUBLICATIONS
Villupuram, Tamilnadu, India.
Sarumathi.publications@gmail.com
Printed at
Meenam Offset
Pondicherry – 605001, India
Acknowledgement
I am very much grateful to the management of paul’s educational trust, Respected
principal Dr. Y. R. M. Rao, M.E., Ph.D., cherished Dean Dr. E. Mariappane, M.E.,
Ph.D., and helpful Head of the department Mr. M. G. Lavakumar M.E., (Ph.D.).
I thank my colleagues and friends for their cooperation and their support in my
career venture.
I thank my parents and family members for their valuable support in completion of
the book successfully.
I express my special thanks to SARUMATHI PUBLICATIONS for their continued
cooperation in shaping the work.
Suggestions and comments to improve the text are very much solicitated.
Mr. G. Appasami
CS6503 THEORY OF COMPUTATION L T P C 3 0 0 3
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 I FINITE AUTOMATA 9
Introduction- Basic Mathematical Notation and techniques- Finite State systems – Basic
Definitions – Finite Automaton – DFA & NDFA – Finite Automaton with €- moves – Regular
Languages- Regular Expression – Equivalence of NFA and DFA – Equivalence of NDFA‟s
with and without €-moves – Equivalence of finite Automaton and regular expressions –
Minimization of DFA- - Pumping Lemma for Regular sets – Problems based on Pumping
Lemma.
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.
UNIT III PUSHDOWN AUTOMATA 9
Pushdown Automata- Definitions – Moves – Instantaneous descriptions – Deterministic
pushdown automata – Equivalence of Pushdown automata and CFL - pumping lemma for
CFL – problems based on pumping Lemma.
UNIT IV TURING MACHINES 9
Definitions of Turing machines – Models – Computable languages and functions –
Techniques for Turing machine construction – Multi head and Multi tape Turing Machines -
The Halting problem – Partial Solvability – Problems about Turing machine- Chomskian
hierarchy of languages.
UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9
Unsolvable Problems and Computable Functions – Primitive recursive functions –
Recursive and recursively enumerable languages – Universal Turing machine.
MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable problems-
Tractable and possibly intractable problems - P and NP completeness - Polynomial time
reductions.
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
S. No. Contents Page no.
UNIT I FINITE AUTOMATA
1 Introduction - Basic Mathematical Notation and techniques
2 Finite State systems - Basic Definitions Finite Automaton
3 DFA & NDFA
4 Finite Automaton with ε- moves
5 Regular Languages - Regular Expression
6
Equivalence of NFA and DFA
Equivalence of NDFA’s with and without ε - moves
7 Equivalence of finite Automaton and regular expressions
8 Minimization of DFA
9 Pumping Lemma for Regular sets
10 Problems based on Pumping Lemma
UNIT II GRAMMARS
1 Grammar Introduction - Types of Grammar
2 Context Free Grammars and Languages
3 Derivations and Languages Ambiguity
4 Relationship between derivation and derivation trees
5 Simplification of CFG
6
Elimination of Useless symbols
Unit productions - Null productions
7 Greiback Normal form
8 Chomsky normal form
9 Problems related to CNF and GNF
UNIT III PUSHDOWN AUTOMATA
1 Pushdown Automata
2 Definitions
3 Moves
4 Instantaneous descriptions
5 Deterministic pushdown automata
6 Equivalence of PDA and CFL
7 Pumping lemma for CFL
8 Problems based on pumping Lemma
UNIT V TURING MACHINES
1 Definitions of Turing machines
2 Models
3 Computable languages and functions
4 Techniques for Turing machine Construction
5 Multi head and Multi tape Turing Machines
6 The Halting problem
7 Partial Solvability
8 Problems about Turing machine
9 Chomskian hierarchy of languages
UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE
FUNCTIONS
1 Unsolvable Problems and Computable Functions
2 Primitive recursive functions
3 Recursive and recursively enumerable languages
4 Universal Turing machine.
5 Measuring and classifying complexity
6 Tractable and Intractable problems
7 Tractable and possibly intractable problems
8 P and NP completeness
9 Polynomial time reductions
2 Marks Questions and Answers 74
Question Bank 100
Model Question paper 105
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.
1.1 Introduction to formal proof
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.
1.1.1 Deductive Proof
It consists of a sequence of statements given with logical reasoning in order to prove
the first (or initial) statement. The first statement is called hypothesis.
1.1.2 Inductive Proof
It is a recursive kind of proof which consists of sequence of parameterized statements
that cure statement itself with lower values of its parameters.
1.1.3 Additional forms of Proofs
I. Proofs about sets
II. Proofs by contradiction
III. Proofs by counter example
Proofs about sets
Set is a collection of elements or items. Let us consider two sets A and B. Define the
expression R as union of A and B (i.e. AUB) and S as union of B and A (i.e. BUA), where U
is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B.
Prove that R=S(i.e, x is in R if and only if it is in S)
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)
(i) x is in BUA then it is in AUB
Sl. No. Statement Justification
1 x is in BUA Given
Theory of Computation 2
2 x is in B or x is in A By definition of union & (1)
3 x is in Aor x is in B By definition of union & (2)
4 x is in AUB By definition of union & (3)
So AUB=BUA, Thus R=S is true, Hence proved.
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.
Proofs by counter example
In order to prove certain statements, we need to check all the possible conditions in
which that statement remains true. There are some situations in which the statement cannot
be true.
Example 1: There is no pair of integers a and b such that amod b = b mod a
Proof: There are two possibilities. They are either a>b or a<b.
If a=2 and b=3 then 2 mod 3 ≠ 3 mod 2
If a=3 and b=2 then 3 mod 2 ≠ 2 mod 3
If a=b=2 then 2 mod 2 = 2 mod 2, so the given statement is true only if a=b, so we have to
change the statement slightly, Thus, amod b = b mod a true only when a=b,
We proved by counter example, this type of proof is called proof by counter example. Such
proof are true only at specific conditions.
Example 2: All primes are odd numbers.
2, 3, 5 ,7 1, 13, 17, 23, . . are prime numbers and all are odd numbers except 2.
The integer 2 is prime but not odd, so the statement is not a theorem.
Example 1
Prove that every integer n ≥ 0, the number 42n + 1
+ 3n + 2
is multiple of 13 by induction.
Proof: Let n= 0, P(0) = 42(0) + 1
+ 3(0) + 2
= 41
+ 32
= 4 + 9 = 13 = 13.t where t=1
Let n = 1, P(1) = 42(1) + 1
+ 3(1) + 2
= 43
+ 33
= 64 + 27 = 91 = 13.t where t= 7
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
Let n = k + 1, P(k + 1) = 42(k + 1) + 1
+ 3(k + 1) + 2
= 42(k + 1) + 1
+ 3(k + 1) + 2
= 42k + 2 + 1
+ 3k + 1 + 2
= 42k + 1 + 2
+ 3k + 2 + 1
= 42k + 1.
42
+ 3k + 2.
31
= 42
.42k + 1
+ 3.3k + 2
= 42
.42k + 1
+ 42
3k+2
- 42
3k+2
+ 3.3k + 2
{ Add & Sub 42
3k+2
}
= 42
(42k + 1
+ 3k+2
) + 3k+2
(-42
+ 3)
= 42
(13.t)- 3k+2
(-42
+ 3) { 42k + 1
+ 3k + 2
= 13.t}
= 16 (13.t)- 3k+2
(-13)
= 13[16. t + 3k+2
]
= Multiple of 13
฀ P(k + 1) is multiple of 13, Hence proved.
Example 2
Prove 1 + 2 + 3 + … + n = n (n+1)/2 using induction method.
Proof:
Let n = 1, then LHS = 1 and RHS = 1 (1 + 1) / 2 = 1
LHS = RHS
Let n = 2, then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) / 2 = 3
LHS = RHS
Let n = k, 1 + 2 + 3 + … + k = k (k+1)/2
Consider n = k +1, then LHS = 1 + 2 + 3 + … + k + (k+1) = (k+1) (k+2) / 2
RHS = k (k+1)/2 + (k + 1)
= k2
+ k + 2 (k + 1)
2 2
= (k2
+ 3k + 2) / 2
= (k+1) (k+2) / 2
LHS = RHS
Hence Proved.
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.
Let n = k, 2k
> k3
, Assume the condition is true for k.
Let n = k +1, 2k+1
= 2k
.2 1
= 2k
.2 1
> k3
.2 1
฀ 2k+1
> k3
.2 1
Let k =12 in above inequality, LHS = 212+1
= 213
= 8192
RHS = 123
.2 = 3456
฀ LHS  RHS, Hence Proved.
Example 4
Show that n! >= 2n - 1
by mathematical induction.
Proof:
Let n = 1, LHS = 1! = 1 RHS = 21 - 1
= 20
= 1
LHS >= RHS
Let n = 2, LHS = 2! = 2.1 = 2 RHS = 22 - 1
= 21
= 2
LHS >= RHS
Let n = 3, LHS = 3! = 3. 2.1 = 6 RHS = 23 - 1
= 24
= 4
LHS >= RHS
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
Let k=2, LHS = (2+1)! = 3! =6
RHS = (2+1)2 2- 1
=3.2 = 6
฀ LHS  RHS, Hence Proved.
Theory of Computation 5
Example 4
Prove by mathematical induction Ʃn2
=
+ +
for all n ≥ 1.
Proof:
12
+ 22
+ ... + n2
=
+ +
Let n = 1, LHS = 12
= 1, RHS =
+ . +
=
𝑥 𝑥
= 1, ฀ LHS = RHS
Let n = 2, LHS = 12
+ 22
= 1 + 4 = 5, RHS =
+ . +
=
𝑥 𝑥
= 5, ฀LHS = RHS
Let n = k, 12
+ 22
+ ... + k2
=
+ +
, assumed to be true
Let n = k+1, LHS = 12
+ 22
+ ... + k2
+ (k + 1)2
=
+ +
+ (k + 1)2
=
+ +
+ (k + 1) (k +1)
=
+ +
+
+ +
=
+ + + + +
=
+ [ + + + ]
=
+ ( 2+ + + )
=
+ ( 2+ + )
=
+ + +
RHS =
+ + + [ + ]+
=
+ + + +
=
+ + +
฀ LHS = RHS, Hence Proved
Theory of Computation 6
Alphabets, Strings and language
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:
A string is a finite sequence of symbols chosen from some alphabet.
1) Σ ={0,1}  11001 [ Empty string is denoted by ]
2) Σ = {a, b, c}  aabbcbbbaa
The total number of symbols in the string is called length of the string
Example:
1) |0001|=4
2) |100|=3
Empty string ( ):
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 .
Σk
to be the set of string of length k for each symbol in Σ.
Example :
∑ = {0, 1}
∑ ={ }
∑ = {0, 1}
∑ = {00, 01, 10, 11}
∑ = {000, 001, 010, 011, 100, 101, 110, 111}
Theory of Computation 7
∑+
= ∑ 𝑈 ∑ 𝑈 ∑ …
∑+
= ∑ ⋃∞
=
∑∗
= ∑ 𝑈 ∑ 𝑈 ∑ 𝑈 …
∑∗
= ∑ ⋃∞
=
Set of all strings over an alphabet is denoted by ∑∗
Set of all strings over an alphabet except null string is denoted by ∑+
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
Language [Language is a collection of all strings]
A set of strings of all which are chosen from ∑∗
is called a language, where ∑ is a
particular alphabet set.
Finite state system (or) finite automata :
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.
Definition of finite automata:
A finite automata is a collection of 5-tuples A = (Q , ∑, , q0
, F)
Where A  Name of the finite automata
Q  Finite set of states [non-empty]
∑  The set of input symbols [input set]
 The transition function [Move from one state to another ] :Qx ΣQ
Theory of Computation 8
q0
q1
q2 q3
1 1Start 1
q0
q1 q3
0 1Start
0 1
0
q0
 Initial or start state q0∈Q
F  Set of all final states
Types of finite automata (FA)
 Deterministic finite automata (DFA)
 Non deterministic finite automat (NFA)
Transition diagram
Transition diagram for a DFA A = (Q, ∑, , q0, F) is a graph define as follows
o For each state q in Q there is a node.
o For each state q in Q and each input symbol a in ∑ then the transition
diagram has an arc from node q to node p.
Transition table
A transition table is a conventional table represent of a function like in finite
automata. That takes two argument and return a value. The rows of the table correspond to
the state and column corresponds to the input symbols.
Deterministic finite automata:
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:
Example 2 Design FA which accepts only those strings which start with 0 and end with 1
over the input set Σ = {0, 1}
Solution:
a b c a a b c a Input tape
Finite
control
Tape head /
reader
Theory of Computation 9
Input
0
q0
q1
q1
q1
q2
q2
1
q2
q2
q1
States
q2
1 1Start
1
1
Input
0
q0
q1
q1
q1
q2
q3
1
q2
q2
q1
States
q3
q2 q3
q0
q2
0
0
Start
1
1
q1
q3
0
0
1
10
q0
q1
q2
0
1
Start
0
0
1 1
Example 3 Design FA & State Table which accepts odd number of 1’s and any number of
0’s.
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})
Check: 0110 & 1110
q0
0110  0q1
110  01q2
10  011q1
0  0110q1
 Reached non final state  not accepted
q0
1110  1q2
110  11q1
10  111q2
0  1110q2
Reached final state  string accepted
Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = {1}.
Check: 111 & 1111
q0
111  1q1
11  11q2
1  111q3
 Reached final state  String accepted
q0
1111  1q1
111  11q2
11  111q3
1  1111q1
 Reached non final state  not accepted
Example5 Design FA & State Table which accepts the binary number which is divisible by 3.
State Transition Diagram State Transition Table
Theory of Computation 10
Input
a
s0
s1
s1
s2
s3
s1
b
s0

s3
States
s2
s3 
b
s0
s2
s3
a as1
a
b
a
Input
0
q0
q1
q1
q1
q2
q2
1
q2
q2
q1
States
q0
q2
q1
0
Start
0
1
0 1
1
q0
q0
q0
b
a
b
b
Start
Start
Check: 9 & 8 (i.e. 1001 &1000 )
q0
1001  1q2
001  10q3
01  100q2
1 1001q1
 Reached final state  String accepted
q0
1000  1q2
000  10q3
00 100q2
0 1000q3
 non final state  not accepted
Example 6 Design FA to accept L, where L= {Strings in which ‘a’ always appears tripled}
over the input set Σ = {a, b}.
Example 7 Design FA which checks the given binary number is even.
State Transition Diagram
State Transition Table
Check: 6 & 7 (i.e. 0110 & 0111)
q0
0110  0q1
110  01q2
10  011q2
0  0110q1
 Reached final state  string accepted
q0
0111  0q1
111  01q2
11  011q2
1  0111q2
 Reached non final state  not accepted
Non deterministic automata:
Theory of Computation 11
q1
q3 q4
0 01
Start q2
1
q6
0
0
0
q5
1
q2
1
Start
1
0
0
0
0
q1
0
0
1
q3
Finite automata is also called as non deterministic automata when many paths are
specified in code from the current state to next state
NFA can be defined as the collection of five tuple
A ={Q , ∑ , , qo , F}
Example : 1 construct NFA where L={0101* + 0100 n ≥ 0} over the string ∑={0,1}
Example 2 : construct the transmission diagram for NFA where
M=({ q1 q2 q3 } , {0,1} , , q1 , { q3 } )
Where is given by
’(q1 , 0) = { q2 , q3} ’(q1 , 1)= { q1 }
’(q2 , 0) = { q1 , q2} ’(q2 , 1)={ ɸ }
’(q3 , 0) = { q2 } ’(q3 , 1)= { q1 , q2 }
sol :
Stateip 0 1
q1
q2
ɸ
q2
ɸ q3
q3
{q4
, q5
} ɸ
q4
ɸ q4
q5
q6
ɸ
q6
ɸ ɸ
Theory of Computation 12
NFA with Epsilon transition:
The transition in NFA is given in order to move from one state to another without
having any symbol from input.
state 0 1
q1 {q2 , q3} q1
q2 {q1 , q2} ɸ
q3 q2 {q1 , q2}
Theory of Computation 13
q0
q
q2
Start q1
q
b ca
q0
q2
Start q1
b
a
Definition:
The language L is accepted by NFA with denoted by M ={Q , ∑ , , qo , F} can be
defined as follow .
Q x ( ∑ u { } )  2Q
L(M) ={ w/w € ∑∗
}
Epsilon closure (p) :
It is set of all state which are reachable from state p or epsilon transition such that
1) closure (p) ={p}, Where p € Q
2) If there exist -closure (p) ={q} and ( q , ) = r , then closure (p) ={q, r}.
Example 1: Find the closure for the following NFA with
closure(q0 )={ q0 , q1 , q2}
closure(q1)={ q1 , q2}
closure(q2)={q2 }
Conversion from NFA with to NFA without :
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 .
’(q, a) = closure( ( ^
(q, ), a))
Example 1: Convert the given NFA with transition to NFA without transition.
Theory of Computation 14
Step 1: closure
closure (q0 )={ q0 }
closure (q1 )={ q1 , q2 }
closure (q2 )={ q2 }
Step 2:
’(q0 , a) = q1 ’(q0 , b) = ɸ ’ (q0, ) = ɸ
’(q1 , a) = ɸ ’(q1 , b) = ɸ ’ (q1, ) = q2
’(q2 , a) = ɸ ’(q2 , b) = q2 ’ (q2, ) = ɸ
Step 3:
’(q0, a) = closure( ( ^
(q0 , ), a))
= closure( ( closure (q0 ), a))
= closure( (q0, a))
= closure(q1)
= { q1 , q2 }
’(q0 , b) = closure( ( ^
(q0 , ), b))
= closure( ( closure (q0 ), b))
= closure( (q0 , b))
= closure ɸ
= { ɸ }
’(q1, a) = closure( ( ^
(q1 , ), a))
= closure( ( closure (q1 )a))
= closure( ({q1 , q2 }, a))
= closure( (q1 , a) U (q2 , a))
= closure (ɸ U ɸ)
= closure (ɸ)
= { ɸ }
Theory of Computation 15
q2
Start
b
b
a q2
q2
a
’(q1, b) = closure( ( ^
(q1 , ),b))
= closure( ( closure (q1 )b))
= closure( ({q1 , q2} , b))
= closure( (q1 , b) U (q2 , b))
= closure (ɸ U q2)
= closure ( q2 )
= { q2 }
’(q2, a) = closure( ( ^
(q2 , ), a))
= closure( ( closure (q2 ), a))
= closure( ( q2, a))
= closure ɸ
= { ɸ }
’(q2, b) = closure( ( ^
(q2 , ), b))
= closure( ( closure (q2 ), b))
= closure( ( q2 , b))
= closure (q2 )
= { q2 }
Transition table :
Step 4:
Transition diagram : NFA without
state a b
q0 {q1 ,q2} ɸ
q1 ɸ q2
q2 ɸ q2
Theory of Computation 16
q0
q2
Start q1
b ca
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 :
Step 1: closure
closure (q0 )={ q0 , q1 , q2 }
closure (q1 )={ q1 , q2 }
closure (q2 )={ q2 }
step 2:
(q0 , a) = q0 (q0 , b) = ɸ (q0, c) = ɸ (q0, ) = q1
(q1 , a) = ɸ (q1 , b) = q1 (q1, c) = ɸ (q1, ) = q2
(q2 , a) = ɸ (q2 , b) = ɸ (q2, c) = q2 (q2, ) = ɸ
Step 3:
’(q0, a) = closure( ( ^
(q0 , ), a))
= closure( ( closure (q0 ), a))
= closure( (q0, a) 𝑈 (q1, a) 𝑈 (q2, a))
= closure ( q0 Uɸ U ɸ)
= closure ( q0 )
= { q0 , q1 , q2 }
’(q0, b) = closure( ( ^
(q0 , ), b))
= closure( ( closure (q0 )b))
= closure( (q0, b) 𝑈 (q1, b) 𝑈 (q2, b))
= closure (ɸ 𝑈q1 𝑈ɸ)
= { q1 , q2 }
’(q0, c) = closure( ( ^
(q0, ), c))
Theory of Computation 17
= closure( ( closure (q0 ), c))
= closure( (q0, c) 𝑈 (q1, c) 𝑈 (q2, c))
= closure (ɸ Uɸ Uq2)
= { q2 }
’(q1, a) = closure( ( ^
(q1, ), a))
= closure( ( closure (q1 ), a))
= closure( (q1, a) 𝑈 (q2, a))
= closure (ɸ 𝑈 ɸ )
= closure (ɸ)
= {ɸ}
’(q1, b) = closure( ( ^
(q1 , ),b))
= closure( ( closure (q1 )b))
= closure( (q1, b) 𝑈 (q2, b))
= closure (q1)
= {q1 , q2}
’(q1, c) = closure( ( ^
(q1 , ), c))
= closure( ( closure (q1 ), c))
= closure( (q1, c) 𝑈 (q2, c))
= closure (ɸ𝑈q2)
= {q2}
’(q2, a) = closure( ( ^
(q2 , ), a))
= closure( ( closure (q2 ), a))
= closure( (q2, a))
= closure (ɸ)
= {ɸ}
’(q2, b) = closure( ( ^
(q2 , ), b))
= closure( ( closure (q2 ), b))
Theory of Computation 18
q0
q2
Start q1
a, b
a
a, b
b c
b
= closure( (q2, b))
= closure (ɸ)
= {ɸ}
’(q2,c) = closure( ( ^
(q2 , ), c))
= closure( ( closure (q2 ), c))
= closure( (q2, c))
= closure (q2)
= {q2}
Step 4:
Transition table
state a b c
q0 {q0, q1, q2} {q1 ,q2} q2
q1 ɸ {q1 ,q2} q2
q2 ɸ ɸ q2
Transition diagram:
Conversion N.F.A to D.F.A
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,
(i) ’( [q1,q2,q3……qi], a) = (q1,a ) U (q2, a)…… U (qi, a)
= [q1, q2, q3, ... , qk]
(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 [q1, 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.
Example 1: Construct the equivalent DFA for the given NFA.
M = ({q0, q1}, {0,1}, , qo, {q1}) where is given by
(q0,0) = {q0, q1}
(q0,1) = { q1}
(q1,0) = φ
(q1,0) = {q0, q1}
Sol:
Transition Table (NFA)
St/Ip 0 1
q0 {q0, q1} {q1}
q1 φ {q0, q1}
Theory of Computation 20
Transition Diagram:
’( {q0, q1}, 0) = (q0, 0) U (q1, 0)
= { q0, q1} U φ
= { q0, q1}
’( {q0, q1}, 1) = (q0,1) U (q1, 1)
= { 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}
Transition Diagram: (DFA)
Theory of Computation 21
ssq
q
Example 2. Construct an DFA equivalent to the given NFA.
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}, 0) = ( p,0) U ( q,0)
= {p, q} U {r}
= {p, q, r}
’({p, q}, 1) = ( p,1) U ( q,1)
= {p} U {r}
= {p, r}
Theory of Computation 22
q
q
New State table:
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
{p, q} {p, q, r} {p, r}
’({p, q, r}, 0) = ( p,0) U ( q,0) U ( r,0)
= {p, q} U {r} U {s}
= {p, q, r, s}
’({p, q, r}, 1) = ( p,1) U ( q,1) U ( r,1)
= {p} U {r} U { φ }
= {p, r}
’({p, r}, 0) = ( p,0) U ( r,0)
= {p, q} U {s}
= {p, q, s}
’({p, r}, 1) = ( p,1) U ( r,1)
= {p} U { φ }
= {p}
New transition table:
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
Theory of Computation 23
q
{p, q} {p, q, r} {p, r}
{p, q, r} {p, q, r, s} {p, r}
{p, r} {p, q, s} p
’({p, q, r, s}, 0) = ( p,0) U ( q,0) U ( r,0) U ( s,0)
= {p,q} U {r} U {s} U {s}
= {p, q, r, s}
’({p, q, r, s}, 1) = ( p,1) U ( q,1) U ( r,1) U ( s,1)
= {p} U {r} U { φ } U {s}
= {p, r, s}
’( [p,q,s],0) = ( p,0) U ( q,0) U ( s,0)
= {p,q} U {r} U {s}
= {p, q, r, s}
’( [p,q,s],1) = ( p,1) U ( q,1) U ( s,1)
= {p,q} U {r} U {s}
= {p, q, r, s}
New transition table:
St/Ip 0 1
→P {p, q} p
q r r
r s φ
s s s
{p, q} {p, q, r} {p, r}
{p, q, r} {p, q, r, s} {p, r}
{p, r} {p, q, s} p
{p,q,r,s} {p, q, r, s} {p, r, s}
Theory of Computation 24
q2
{p,q,s} {p, q, r, s} {p, r, s}
’({p, r, s}, 0) = ( p,0) U ( r,0) U ( s,0)
= {p,q} U {s} U {s}
= {p, q, s},
’({p, r, s}, 1) = ( p,1) U ( r,1) U ( s,1)
= {p} U {s} U {s}
= {p, s}
New transition table:
St/Ip 0 1
→[P] [p,q] [ p]
[q] [r] [ r]
[r] [s] φ
s [s] [s]
[p,q] [p,q,r] [p,r]
[p,q,r] [p,q,r,s] [p,r]
[p,r] [p,q,s] [p]
p,q,r,s [p,q,r,s] [p,r,s]
p,q,s [p,q,r,s] [p,r,s]
p,r,s [p,q,s] [p,s]
’( [p,s],0) = ( p,0) U ( s,0)
= {p,q} U {s}
= [p,q,s]
’( [p,s],1) = ( p,1) U ( s,1)
= {p} U {s}
= [p,s]
Theory of Computation 25
New transition table:
Transition Diagram: (DFA)
METHOD FOR CONVERSION NFA WITH TO DFA
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.
Step2 : Obtain transition on { p1p2……pn } for each input.
D ({ p1p2……pn }, a) = closure( (P1 ,a) U (P2 (a) U ……U(Pn ,a))
=⋃ closure Pi , a= where a ϵ ∑
Step3 : State obtained [ P1P2……Pn ] ϵ QD , states containing final state Pi is a final state
DFA.
St/Ip 0 1
→[P] [p,q] [ p]
[q] [r] [ r]
[r] [s] -
[s] [s] [s]
[p,q] [p,q,r] [p,r]
[p,q,r] [p,q,r,s] [p,r]
[p,r] [p,q,s] [p]
[p,q,r,s] [p,q,r,s] [p,r,s]
[p,q,s] [p,q,r,s] [p,r,s]
[p,r,s] [p,q,s] [p,s]
[p,s] [p,q,s] [p,s]
Theory of Computation 26
EXAMPLE 1: Convert the following NFA with to equivalent DFA.
b a
a
b
closure(q0 )={ q0 q1 q2}
closure(q1)={ q1 q2}
closure(q2)={q2 }
(q0 , a) = ɸ (q0 , b) = q0 (q1, ) = q1
(q1 , a) = q1 (q1 , b) = ɸ (q2, ) = q2
(q2 , a) = q1 (q2 , b) = q0 (q2, ) = ɸ
’(q0 , a) = closure( ( ^
(q0, ),a))
’(q0 , a) = closure( ( closure q0 ),a))
= closure( ({q0 q1 q2 } ,a) )
= closure( (q0 ,a)U (q1 ,a)U (q2 ,a) )
= closure(ɸ U q1 U q1 )
= closure q1
= { q1 q2}
’(q0 , b) = closure( ( ^
(q0, ),b))
’(q0 , b) = closure( ( closure q0 ),b))
= closure( ({q0 q1 q2 } ,b) )
= closure( (q0 ,b)U (q1 ,b)U (q2 ,b) )
q0
q1
q2
Theory of Computation 27
= closure(q0 U ɸ U q0 )
= closure q0
= { q0 q1 q2}
’(q1 , a) = closure( ( ^
(q1, ),a))
’(q1 , a) = closure( ( closure q1 ),a))
= closure( ({ q1 q2 } ,a) )
= closure( (q1 ,a)U (q2 ,a) )
= closure( q1 U ɸ )
= closure q1
= { q1 q2}
’(q1 , b) = closure( ( ^
(q1, ),b))
’(q1, b) = closure( ( closure q1 ),b))
= closure( ({ q1 q2 } ,b) )
= closure( (q1 ,b)U (q2 ,b) )
= closure(ɸ U q0 )
= closure q0 = { q0 q1 q2}
’(q2 , a) = closure( ( ^
(q2, ),a))
’(q2, a) = closure( ( closure q2 ),a))
= closure( ({ q2 } ,a) )
= closure q1
= { q1 q2}
’(q2 , b) = closure( ( ^
(q2, ),b))
’(q2, b) = closure( ( closure q2 ),b))
= closure( ({ q2 } ,b) )
= closure q0
= {q0 q1 q2}
Theory of Computation 28
q0
q2
11
Start
a,b
a,b
q1
a,b
a,b
a,b
a,bbb
b
Transition of NFA
input
state
a b
q0 { q1 q2} {q0 q1 q2}
q1 { q1 q2} {q0 q1 q2}
q2 { q1 q2} {q0 q1 q2}
Transition diagram
‘([q1 q2 ],a)= (q1 ,a) U (q2,a)
= { q1 , q2}U{ q1 , q2 }
=[ q1 , q2 ]
‘([q1 q2 ],b)= (q1 ,b) U (q2,b)
= { q0 , q1 , q2}U{ q0 , q1 , q2 }
=[q0 , q1 , q2 ]
‘([q0 q1 q2 ],a)= (q0 ,a) U (q1 ,a) U (q2,a)
={ q1 , q2}U{ q1 , q2 }U{ q1 , q2 }
=[ q1 , q2 ]
‘([q0 q1 q2 ],b)= (q0 ,b) U (q1 ,b) U (q2,b)
={ q0 ,q1 , q2}U{ q0 ,q1 , q2 }U{ q0 ,q1 , q2 }
=[ q0 ,q1 , q2 ]
Transition table for DFA
Theory of Computation 29
[q1,q2,q3]
input
state
a b
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 ]
a a b
a b b
b
a
a b
[q1,q2]
q0
q0 q1
q2
Theory of Computation 30
MINIMIZE METHOD
TABLE FILLING 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.
B
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
H X 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
MINIMIZE METHOD [alter 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
Stinput 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
A B
GD
c
Table 3
Stinput 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
Stinput 0 1
A B D
B G C
C A C
D C G
G G A
: This is the minimized DFA
0
0
1 1 0 1 1
0
1
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 + .
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*
EXAMPLE10:construct a RE for the language L,∑={a.b} in which total no of a’s are
divisible by 3
Solution:
RE=(b*ab*ab*ab*)*
METHOD FOR CONSTRUCTION OF NFA FROM RE:
EXAMPLE1:Construct NFA for the RE b+ba*
Sol:
r=b+ba*
r=r +r
Theory of Computation 39
r =b
r =r r
r =b
r =a*
step1:
r =b
EXAMPLE2: Construct an NFA for the given RE (01+2*)1
Sol:
R=(01+2*)1
R=r r
r =01+2*
r =1
r =r +r
r =01
r =2*
step1:
r4=2*
Step2:
R3=01
Step3:
R2=1
Step4: 01+2*
Theory of Computation 40
Step5:(01+2*)1
DIRECT OR SUBSET METHOD:
EXAMPLE 1: design FA for the RE 10+(0+11)0*1
Step1:
Step2:
Step3:
Theory of Computation 41
Step4:
Step5:
Step6:
Step7:
Theory of Computation 42
EXAMPLE 2:design the DFA for the FE 0+01*
Step1:
Step2:
Step3:
EXAMPLE3:design DFA for the given RE
Step1:
Step2:
Theory of Computation 43
Step3:
Step4:
IDENTITY RULES FOR RE:
1.ξ.R=R.ξ=R
2.ξ *=ξ
3.(Ф)*=ξ
4.Ф.R=R.Ф=Ф
5.Ф+R=R
6.R+R=R
7.RR* =R*R=R+
8.(R*)*=R*
9.ξ+RR*=R+
10.(P+Q)R=PQ+PR
11.(P+Q)*=P*Q*=(P*+*Q)*
12.R*(ξ+R)=(ξ+R)R*=R*
13.(R+ξ)*=R*
14.ξ+R*=R*
15.(PQ)*P=P(QP)*
16.R*R+R=R*R
AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION:
Step1: let q1 be the initial state.
Theory of Computation 44
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
q1=ξ+ q11(1+01)*
00+ q10
q1=ξ+ q1(0+1(1+01)*
00)
q1=ξ+(0+1(1+01)*
00)*
q1=(0+1(1+01)*
00)*
(ξ.R=R.ξ=R)
EXAMPLE3: construct the RE for the given DFA
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:
rik
j=(rik-1
k) (rkk-1
k)*
(rkk-1
j)+ rik-1
j
K=1
(r11
1) i=1,j=1 (r11
1)= (r10
1) (r10
1)*
(r1o
1)+ r10
1
=(ξ)(ξ)*
(ξ)+ξ
=ξ+ξ
= ξ
(r11
2) i=1,j=2 (r11
2)= (r10
1) (r10
1)*
(r1o
2)+ r10
2
=ξ+0+0
=0
(r21
1) i=2,j=1 (r21
1)= (r20
1) (r10
1)*
(r1o
1)+ r20
1
=Ф.ξ.ξ+Ф
=Ф
(r21
2) i=2,j=2 (r21
2)= (r20
1) (r10
1)*
(r1o
2)+ r20
2
=Ф(ξ)*
.0+(1+ξ)
=Ф+ξ
Theory of Computation 46
=ξ
Step3:
Compute and find state from state q1 to final state q2
K=2
(r12
2)= (r10
2) (r20
2)*(r2o
2)+ r10
2
=0(ξ)*ξ+0
=0+0
r12=0
Theory of Computation 47
Theorem: Every language defined by a regular expression is also defined by a finite
automaton.
Proof: Suppose L = L(R) for a regular expression R. We show that L = L(E) for some -NFA
E with:
1. Exactly one accepting state.
2. No arcs into the initial state.
3. No arcs out of the accepting state.
BASIS: There are three parts to the basis as shown in the following three figures.
Part (a) to handle the expression . The language of the automaton is easily seen to be { },
since the only path from the start state to an accepting state is labeled . i.e., Regular
expression = .
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.
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.
Thus, the language of the automaton in Figure is L(R) U L(S).
R
S
a
Theory of Computation 48
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).
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:
(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. ∎
R
R S
Theory of Computation 49
PUMPING LEMMA: To prove languages are not regular.
Statement: Let L be a regular language, then there is a constant such that for every string
in L and | | . We can break into three sub-strings and represented as = such
that
1. ≠ 𝜖. i.e., | | .
2. | | .
3. For all , the string is also in L.
Proof:
If L is a regular Language, then it is accepted by a DFA 𝐴 = 𝑄, 𝛴, 𝛿, , 𝐹 with n
states. i.e., L = L(A). Consider the input string w of length or more, say = 𝑎 𝑎 . . . 𝑎
where and each 𝑎 is an input symbol. The mapping function can be defined as
𝛿 , 𝑎 𝑎 . . . 𝑎 = .
For the string 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 and with
< such that = . Now we break = as follows:
1. = 𝑎 𝑎 … 𝑎
2. = 𝑎 + 𝑎 + … 𝑎
3. = 𝑎 + 𝑎 + … 𝑎
In the DFA 𝐴 as shown in figure, we can move from the start state p0 to pi with the
input string , takes us from back to (since = ), and takes us from to .
Note that may be empty if = , Also may be empty if = = . However
cannot be empty as < .
𝛿 , 𝑎 𝑎 . . . 𝑎 𝑎 + … 𝑎 𝑎 + … 𝑎 = 𝛿 𝛿 , 𝑎 , … , 𝑎 , 𝑎 + … 𝑎 𝑎 + … 𝑎
= 𝛿 , 𝑎 + … 𝑎 𝑎 + … 𝑎
= 𝛿 𝛿 , 𝑎 + … 𝑎 , 𝑎 + … 𝑎
= 𝛿 , 𝑎 + … 𝑎
=
If the automaton 𝐴 receives the input w. that is .
Case 1: If = 0, then = 0
= . The automaton 𝐴 goes from the start state 0 to on
input . Since is also , A goes from to the accepting state on input . Thus
𝐴 accepts .
Case 2: If > 0, then the automaton 𝐴 goes from 0 to on input . Circles from to k
times on input , and then goes from to the accepting state on input . Thus
𝐴 accepts .
Thus, for 0, is accepted by a automaton 𝐴. That is, is in 𝐿.
i.e. We have proved that given string of any length can be accepted by Finite Automata by
pumping a substring. i.e., substring repeated as many times as we like and resulting string
may be accepted by Finite Automata. ∎
ADVANTAGES: Pumping lemma is used to check the given language is not regular or not.
p0 pi pF
Start = 𝑎 … 𝑎
= 𝑎 + … 𝑎
= 𝑎 + … 𝑎
Theory of Computation 50
EXAMPLE1:show that the set L={bi2
} is not regular.
Solution:
To prove L=bi2
is not regular
i=2 L=2 => L=b4
=bbbb
i=3 L=3 => L=b9
=bbbbbbbbb
according to pumping lemma
Lui
w Є L where i≥1
L=uvi
w
L=b(bb)i
b if i=2 => bbbbbb not belongs to L
If i=3 => bbbbbbbb not belongs to L
EXAMPLE2: show that the language L={0n
1n+1
/n>0} is not regular
Solution:
To prove L={0n
1n+1
/n>0} is not regular
Let n=1 L=01
12
= 011
Let n=2 L=02
13
=00111
Let n=3 L=03
14
=0001111
Length of the string =n+n+1
=2n
+1
Then according to pumping lemma
L=011
U=0 v=1 w=1
uvi
w=01i
1
=0111(if i=2)not belongs to L
e length of the string after pumping is not in 2n
+1 form
EXAMPLE3: check the given language L={02n
/n/n≥1} is not regular or not
Solution:
Let n=1 L= 02(1)
=00
Let n=2 L =02(2)
=0000
Let n=3 L=02(3)
=000000
Note:
L=string consisting of even no of 0’s
L=even length of string with 0
Then according to pumping lemma
L= 0000
uvi
w= o(00)i
0
=0000(if n=1)
0(00)i
0 Є L
Theory of Computation 51
Closure properties of regular languages (RL)
If certain languages are regular and a new language L is formed from them by certain
operations (such as union or concatenation) then L is also regular. These properties are called
closure properties of regular languages. Such languages represent the class of regular
languages which is closed under the certain operations. The closure properties express the
idea that when one or many languages are regular then certain related languages are also
regular. The closure properties of regular languages are as given below.
1. The union of two regular languages is regular.
2. The intersection of two regular languages is regular.
3. The complement of a regular language is regular.
4. The difference of two regular languages is regular.
5. The reversal of a regular language is regular.
6. The Kleene closure operation on a regular language is regular.
7. The concatenation of regular language is regular.
8. A homomorphism of regular languages is regular.
9. The inverse homomorphism of regular language is regular.
Theorem 1: If L1 and L2 are two languages then L1 ∪ L2 is regular.
Proof: If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L
(R2). Then L1 ∪ L2 = L (R1 + R2) thus we get L1 ∪ L2 as regular language. (Any language
given by some regular expression is regular).
Theorem 2: The complement of regular language is regular.
Proof: Consider L1 be regular language which is accepted by a DFA M = (Q, Σ, , q0, F). The
complement of regular language L̅1 is which is accepted by M ' = (Q, Σ, , q0, Q-F). That
means M is a DFA with final states ∈ F and M ' is a DFA in which all the non-final states of
M become final. In other words, we can say that strings that are accepted by M are rejected
by M' similarly, the strings rejected by M are accepted by M'.
Thus L̅1 is accepted by M' is regular.
Theorem 3: If L1 and L2 are two languages then L1 ∩ L2 is regular.
Proof: Consider that languages L1 is regular. That means there exists some DFA M1 that
accepts L1. We can write M1 = (Q1, Σ, 1, q1, F1 ) Similarly being L2 regular there is another
DFA M2 = = (Q2, Σ, 2, q2, F2 ).
Let L be the language obtained from L1 ∩ L2. We can the simulate M=(Q, Σ, , q, F ).
Where Q = Q1 ∩ Q2
= 1 ∩ 2 a mapping function derived from both the DFAs.
q ∈ Q which is initial state of machine M.
F = F1 ∩ F2, the set of final states, which is common for M1 and M2 both. It is clear
that there exists some DFA which accepts L1 ∩ L2 i.e. L. Hence L is a regular language. This
proves that if L1 and L2 are two regular languages then L1 ∩ L2 is regular. In other words the
regular language is closed under intersection.
Theorem 4: If L1 and L2 are two regular languages then L1 - L2 is regular.
Proof : The L1 - L2 can also be denoted as L1 ∪ L̅2
Consider L1 be regular language which is accepted by DFA M = (Q, Σ, , q0, F). The
complement of regular language L1 is L̅2 which is accepted by M ' = (Q, Σ, , q0, Q-F). That
means M is a DFA with final states set F and M' is a DFA in which all the non final states of
M become final states and all the final states of M become non-final states Thus L1 and L̅2
are two regular languages. That also means: these languages are accepted by regular
expressions. If L1 =L(R1) and L̅2=L(R'2). Then L1 ∪ L̅2 = L(R1+R'2). This ultimately shows
Theory of Computation 52
that L1 ∪ L̅2 is regular. In other words L1 - L2 is regular. Thus regular languages are closed
under difference.
Theorem 5: The reversal of a regular languages is regular
Proof: Reversal of a string means obtaining a string which is written from backward that is
W
R
is denoted as reversal of string w. That means L(wR
) = (L(w))R
. This proof can be done
with basis of induction.
Basis: If w = ɛ or ϕ then w R
is also ɛ or ϕ
i.e. (ɛ )R
= ɛ and (ϕ )R
= ϕ Hence L(w R
) is also regular.
Induction :
Case 1: If w = w1 + w2 then w = (w1)R
+( w2)R
As the regular language is closed under union, w is also regular.
Case 2 : If w = w1 w2 then w = (w1)R
( w2)R
As the regular language is closed under concatenation, w is also regular
Thus, the reversal of a regular languages is regular.
Theorem 6: The closure operation on regular language is regular
Proof : If language L1 is regular then it can be expressed as L1 =L(R1
*
). Thus for a closure
operation a language can be expressed as a language of regular expressions. Hence L1 is said
to be a regular language.
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 L1 =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.
Theorem 8: A homomorphism of regular language is regular.
Proof : The term homomorphism means substitution of string by some other symbols. For
instance the string "aabb" can be written as 0011 under homomorphism. Clearly here, a is
replaced by 0 and b is replaced by 1. Let Σ is the set of input alphabets and Γ be the set of
substitution symbols then Σ *→Γ* is homomorphism. The definition of homomorphism can
be extended as
Let, w = a1 a2 … an
h(w) = h(a1)h(a2)...h(an)
If L is a Language that belongs to the set Σ, then homomorphic image of L can be defined as
h(L) = { h(w): w∈L }
To prove that if L is regular, h(L) is also regular consider following example
Let Σ = {a,b} and w = abab
Put h(a) = 00 and h(b) = 11
Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011
The homomorphism to language is applied by applying homomorphism on each string
of language.
∴ If L = ab*
b = ab+
= {ab, abb, abbb, abbbb, ...}
Now h(L) = {0011, 001111, 00111111, 0011111111, ...}
∴ h(L) = 00 (11)+
As it can be represented by a regular expression, it is a regular language. Hence it is
proved that if L is regular then h(L) is also regular. In other words, family of regular
languages is closed under homomorphism.
Theory of Computation 53
Theorem 9: The inverse homomorphism of regular language is regular.
Proof: Let h: Σ*→Γ* is homomorphism.
The Σ is the input set and Γ be the substitution symbols used by homomorphic function.
Let, L be the regular language where L ∈ Σ then h(L) be homomorphic language.
The inverse homomorphic language can be represented as h-1
(L) such that h-1
: Γ* → Σ*
Let, h-1
(L) = {w | w ∈ L}
If L is regular then h(L) is also regular because regular language is closed under
homomorphism. That if there exist a FA M = (Q, Σ, , q, F) which accepts L then h(L) must
also be accepted by FA M. For complement of L i.e. language L' the inverse homomorphic
language is h-1
(L). Let M' = (Q, Σ, , q, Q-F) be the FA in which all the final states of M
become non-final states and all the non-final states of M become the final states. Clearly the
language L' can be accepted by M' Hence h-1
(L) must also be accepted by FA M'.
Let L= (010)* is a R.L., h(0) = a and h(1) = bb be a homomorphic function then h(L) =
(abba)*
h-1
(h(L))= (010)* = L as the inverse homomorphism h-1
(a)=0 and h-1
(bb)=1.
Decision properties of regular languages (RL)
1. Membership property: A string is in a language, i.e., w ∈ L
2. Emptiness property: Accepting state separated from start state, i.e., ɸ
3. Equivalence property: Two languages are equal, i.e., L1 = L2

Cs6503 theory of computation book notes

  • 1.
    THEORY OF COMPUTATION G. Appasami, M.Sc.,M.C.A., M.Phil., M.Tech., (Ph.D.) Assistant Professor Department of Computer Science and Engineering Dr. Paul’s Engineering Collage Pauls Nagar, Villupuram Tamilnadu, India SARUMATHI PUBLICATIONS Villupuram, Tamilnadu, India
  • 2.
    First Edition: July2016 Published By SARUMATHI PUBLICATIONS © All rights reserved. No part of this publication can be reproduced or stored in any form or by means of photocopy, recording or otherwise without the prior written permission of the author. Price Rs. 101/- Copies can be had from SARUMATHI PUBLICATIONS Villupuram, Tamilnadu, India. Sarumathi.publications@gmail.com Printed at Meenam Offset Pondicherry – 605001, India
  • 3.
    Acknowledgement I am verymuch grateful to the management of paul’s educational trust, Respected principal Dr. Y. R. M. Rao, M.E., Ph.D., cherished Dean Dr. E. Mariappane, M.E., Ph.D., and helpful Head of the department Mr. M. G. Lavakumar M.E., (Ph.D.). I thank my colleagues and friends for their cooperation and their support in my career venture. I thank my parents and family members for their valuable support in completion of the book successfully. I express my special thanks to SARUMATHI PUBLICATIONS for their continued cooperation in shaping the work. Suggestions and comments to improve the text are very much solicitated. Mr. G. Appasami
  • 5.
    CS6503 THEORY OFCOMPUTATION L T P C 3 0 0 3 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 I FINITE AUTOMATA 9 Introduction- Basic Mathematical Notation and techniques- Finite State systems – Basic Definitions – Finite Automaton – DFA & NDFA – Finite Automaton with €- moves – Regular Languages- Regular Expression – Equivalence of NFA and DFA – Equivalence of NDFA‟s with and without €-moves – Equivalence of finite Automaton and regular expressions – Minimization of DFA- - Pumping Lemma for Regular sets – Problems based on Pumping Lemma. 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. UNIT III PUSHDOWN AUTOMATA 9 Pushdown Automata- Definitions – Moves – Instantaneous descriptions – Deterministic pushdown automata – Equivalence of Pushdown automata and CFL - pumping lemma for CFL – problems based on pumping Lemma. UNIT IV TURING MACHINES 9 Definitions of Turing machines – Models – Computable languages and functions – Techniques for Turing machine construction – Multi head and Multi tape Turing Machines - The Halting problem – Partial Solvability – Problems about Turing machine- Chomskian hierarchy of languages. UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9 Unsolvable Problems and Computable Functions – Primitive recursive functions – Recursive and recursively enumerable languages – Universal Turing machine. MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions. 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
  • 6.
    TABLE OF CONTENTS S.No. Contents Page no. UNIT I FINITE AUTOMATA 1 Introduction - Basic Mathematical Notation and techniques 2 Finite State systems - Basic Definitions Finite Automaton 3 DFA & NDFA 4 Finite Automaton with ε- moves 5 Regular Languages - Regular Expression 6 Equivalence of NFA and DFA Equivalence of NDFA’s with and without ε - moves 7 Equivalence of finite Automaton and regular expressions 8 Minimization of DFA 9 Pumping Lemma for Regular sets 10 Problems based on Pumping Lemma UNIT II GRAMMARS 1 Grammar Introduction - Types of Grammar 2 Context Free Grammars and Languages 3 Derivations and Languages Ambiguity 4 Relationship between derivation and derivation trees 5 Simplification of CFG 6 Elimination of Useless symbols Unit productions - Null productions 7 Greiback Normal form
  • 7.
    8 Chomsky normalform 9 Problems related to CNF and GNF UNIT III PUSHDOWN AUTOMATA 1 Pushdown Automata 2 Definitions 3 Moves 4 Instantaneous descriptions 5 Deterministic pushdown automata 6 Equivalence of PDA and CFL 7 Pumping lemma for CFL 8 Problems based on pumping Lemma UNIT V TURING MACHINES 1 Definitions of Turing machines 2 Models 3 Computable languages and functions 4 Techniques for Turing machine Construction 5 Multi head and Multi tape Turing Machines 6 The Halting problem 7 Partial Solvability 8 Problems about Turing machine 9 Chomskian hierarchy of languages UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 1 Unsolvable Problems and Computable Functions
  • 8.
    2 Primitive recursivefunctions 3 Recursive and recursively enumerable languages 4 Universal Turing machine. 5 Measuring and classifying complexity 6 Tractable and Intractable problems 7 Tractable and possibly intractable problems 8 P and NP completeness 9 Polynomial time reductions 2 Marks Questions and Answers 74 Question Bank 100 Model Question paper 105 References 107
  • 9.
    Theory of Computation1 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. 1.1 Introduction to formal proof 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. 1.1.1 Deductive Proof It consists of a sequence of statements given with logical reasoning in order to prove the first (or initial) statement. The first statement is called hypothesis. 1.1.2 Inductive Proof It is a recursive kind of proof which consists of sequence of parameterized statements that cure statement itself with lower values of its parameters. 1.1.3 Additional forms of Proofs I. Proofs about sets II. Proofs by contradiction III. Proofs by counter example Proofs about sets Set is a collection of elements or items. Let us consider two sets A and B. Define the expression R as union of A and B (i.e. AUB) and S as union of B and A (i.e. BUA), where U is the Union operation U on two sets A and B such that if x ϵ AUB iff x is in A or x is in B. Prove that R=S(i.e, x is in R if and only if it is in S) 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) (i) x is in BUA then it is in AUB Sl. No. Statement Justification 1 x is in BUA Given
  • 10.
    Theory of Computation2 2 x is in B or x is in A By definition of union & (1) 3 x is in Aor x is in B By definition of union & (2) 4 x is in AUB By definition of union & (3) So AUB=BUA, Thus R=S is true, Hence proved. 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. Proofs by counter example In order to prove certain statements, we need to check all the possible conditions in which that statement remains true. There are some situations in which the statement cannot be true. Example 1: There is no pair of integers a and b such that amod b = b mod a Proof: There are two possibilities. They are either a>b or a<b. If a=2 and b=3 then 2 mod 3 ≠ 3 mod 2 If a=3 and b=2 then 3 mod 2 ≠ 2 mod 3 If a=b=2 then 2 mod 2 = 2 mod 2, so the given statement is true only if a=b, so we have to change the statement slightly, Thus, amod b = b mod a true only when a=b, We proved by counter example, this type of proof is called proof by counter example. Such proof are true only at specific conditions. Example 2: All primes are odd numbers. 2, 3, 5 ,7 1, 13, 17, 23, . . are prime numbers and all are odd numbers except 2. The integer 2 is prime but not odd, so the statement is not a theorem. Example 1 Prove that every integer n ≥ 0, the number 42n + 1 + 3n + 2 is multiple of 13 by induction. Proof: Let n= 0, P(0) = 42(0) + 1 + 3(0) + 2 = 41 + 32 = 4 + 9 = 13 = 13.t where t=1 Let n = 1, P(1) = 42(1) + 1 + 3(1) + 2 = 43 + 33 = 64 + 27 = 91 = 13.t where t= 7 Let n = k, P(k) = 42(k) + 1 + 3(k) + 2 = 42k + 1 + 3k + 2 = 13.t, true for some integer t
  • 11.
    Theory of Computation3 Let n = k + 1, P(k + 1) = 42(k + 1) + 1 + 3(k + 1) + 2 = 42(k + 1) + 1 + 3(k + 1) + 2 = 42k + 2 + 1 + 3k + 1 + 2 = 42k + 1 + 2 + 3k + 2 + 1 = 42k + 1. 42 + 3k + 2. 31 = 42 .42k + 1 + 3.3k + 2 = 42 .42k + 1 + 42 3k+2 - 42 3k+2 + 3.3k + 2 { Add & Sub 42 3k+2 } = 42 (42k + 1 + 3k+2 ) + 3k+2 (-42 + 3) = 42 (13.t)- 3k+2 (-42 + 3) { 42k + 1 + 3k + 2 = 13.t} = 16 (13.t)- 3k+2 (-13) = 13[16. t + 3k+2 ] = Multiple of 13 ฀ P(k + 1) is multiple of 13, Hence proved. Example 2 Prove 1 + 2 + 3 + … + n = n (n+1)/2 using induction method. Proof: Let n = 1, then LHS = 1 and RHS = 1 (1 + 1) / 2 = 1 LHS = RHS Let n = 2, then LHS = 1 + 2 = 3 and RHS = 2(2 + 1) / 2 = 3 LHS = RHS Let n = k, 1 + 2 + 3 + … + k = k (k+1)/2 Consider n = k +1, then LHS = 1 + 2 + 3 + … + k + (k+1) = (k+1) (k+2) / 2 RHS = k (k+1)/2 + (k + 1) = k2 + k + 2 (k + 1) 2 2 = (k2 + 3k + 2) / 2 = (k+1) (k+2) / 2 LHS = RHS Hence Proved. Example 3 Show that 2n > n3 for n ≥ 10 by mathematical induction. Proof: Let n= 10, 210 > 103 , 1024 > 1000, ฀ The condition is true.
  • 12.
    Theory of Computation4 Let n= 11, 211 > 113 , 2048 > 1331, ฀ The condition is true. Let n = 12, 212 > 123 , 4096 > 1728, ฀ The condition is true. Let n = k, 2k > k3 , Assume the condition is true for k. Let n = k +1, 2k+1 = 2k .2 1 = 2k .2 1 > k3 .2 1 ฀ 2k+1 > k3 .2 1 Let k =12 in above inequality, LHS = 212+1 = 213 = 8192 RHS = 123 .2 = 3456 ฀ LHS  RHS, Hence Proved. Example 4 Show that n! >= 2n - 1 by mathematical induction. Proof: Let n = 1, LHS = 1! = 1 RHS = 21 - 1 = 20 = 1 LHS >= RHS Let n = 2, LHS = 2! = 2.1 = 2 RHS = 22 - 1 = 21 = 2 LHS >= RHS Let n = 3, LHS = 3! = 3. 2.1 = 6 RHS = 23 - 1 = 24 = 4 LHS >= RHS 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 Let k=2, LHS = (2+1)! = 3! =6 RHS = (2+1)2 2- 1 =3.2 = 6 ฀ LHS  RHS, Hence Proved.
  • 13.
    Theory of Computation5 Example 4 Prove by mathematical induction Ʃn2 = + + for all n ≥ 1. Proof: 12 + 22 + ... + n2 = + + Let n = 1, LHS = 12 = 1, RHS = + . + = 𝑥 𝑥 = 1, ฀ LHS = RHS Let n = 2, LHS = 12 + 22 = 1 + 4 = 5, RHS = + . + = 𝑥 𝑥 = 5, ฀LHS = RHS Let n = k, 12 + 22 + ... + k2 = + + , assumed to be true Let n = k+1, LHS = 12 + 22 + ... + k2 + (k + 1)2 = + + + (k + 1)2 = + + + (k + 1) (k +1) = + + + + + = + + + + + = + [ + + + ] = + ( 2+ + + ) = + ( 2+ + ) = + + + RHS = + + + [ + ]+ = + + + + = + + + ฀ LHS = RHS, Hence Proved
  • 14.
    Theory of Computation6 Alphabets, Strings and language 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: A string is a finite sequence of symbols chosen from some alphabet. 1) Σ ={0,1}  11001 [ Empty string is denoted by ] 2) Σ = {a, b, c}  aabbcbbbaa The total number of symbols in the string is called length of the string Example: 1) |0001|=4 2) |100|=3 Empty string ( ): 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 . Σk to be the set of string of length k for each symbol in Σ. Example : ∑ = {0, 1} ∑ ={ } ∑ = {0, 1} ∑ = {00, 01, 10, 11} ∑ = {000, 001, 010, 011, 100, 101, 110, 111}
  • 15.
    Theory of Computation7 ∑+ = ∑ 𝑈 ∑ 𝑈 ∑ … ∑+ = ∑ ⋃∞ = ∑∗ = ∑ 𝑈 ∑ 𝑈 ∑ 𝑈 … ∑∗ = ∑ ⋃∞ = Set of all strings over an alphabet is denoted by ∑∗ Set of all strings over an alphabet except null string is denoted by ∑+ 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 Language [Language is a collection of all strings] A set of strings of all which are chosen from ∑∗ is called a language, where ∑ is a particular alphabet set. Finite state system (or) finite automata : 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. Definition of finite automata: A finite automata is a collection of 5-tuples A = (Q , ∑, , q0 , F) Where A  Name of the finite automata Q  Finite set of states [non-empty] ∑  The set of input symbols [input set]  The transition function [Move from one state to another ] :Qx ΣQ
  • 16.
    Theory of Computation8 q0 q1 q2 q3 1 1Start 1 q0 q1 q3 0 1Start 0 1 0 q0  Initial or start state q0∈Q F  Set of all final states Types of finite automata (FA)  Deterministic finite automata (DFA)  Non deterministic finite automat (NFA) Transition diagram Transition diagram for a DFA A = (Q, ∑, , q0, F) is a graph define as follows o For each state q in Q there is a node. o For each state q in Q and each input symbol a in ∑ then the transition diagram has an arc from node q to node p. Transition table A transition table is a conventional table represent of a function like in finite automata. That takes two argument and return a value. The rows of the table correspond to the state and column corresponds to the input symbols. Deterministic finite automata: 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: Example 2 Design FA which accepts only those strings which start with 0 and end with 1 over the input set Σ = {0, 1} Solution: a b c a a b c a Input tape Finite control Tape head / reader
  • 17.
    Theory of Computation9 Input 0 q0 q1 q1 q1 q2 q2 1 q2 q2 q1 States q2 1 1Start 1 1 Input 0 q0 q1 q1 q1 q2 q3 1 q2 q2 q1 States q3 q2 q3 q0 q2 0 0 Start 1 1 q1 q3 0 0 1 10 q0 q1 q2 0 1 Start 0 0 1 1 Example 3 Design FA & State Table which accepts odd number of 1’s and any number of 0’s. 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}) Check: 0110 & 1110 q0 0110  0q1 110  01q2 10  011q1 0  0110q1  Reached non final state  not accepted q0 1110  1q2 110  11q1 10  111q2 0  1110q2 Reached final state  string accepted Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = {1}. Check: 111 & 1111 q0 111  1q1 11  11q2 1  111q3  Reached final state  String accepted q0 1111  1q1 111  11q2 11  111q3 1  1111q1  Reached non final state  not accepted Example5 Design FA & State Table which accepts the binary number which is divisible by 3. State Transition Diagram State Transition Table
  • 18.
    Theory of Computation10 Input a s0 s1 s1 s2 s3 s1 b s0  s3 States s2 s3  b s0 s2 s3 a as1 a b a Input 0 q0 q1 q1 q1 q2 q2 1 q2 q2 q1 States q0 q2 q1 0 Start 0 1 0 1 1 q0 q0 q0 b a b b Start Start Check: 9 & 8 (i.e. 1001 &1000 ) q0 1001  1q2 001  10q3 01  100q2 1 1001q1  Reached final state  String accepted q0 1000  1q2 000  10q3 00 100q2 0 1000q3  non final state  not accepted Example 6 Design FA to accept L, where L= {Strings in which ‘a’ always appears tripled} over the input set Σ = {a, b}. Example 7 Design FA which checks the given binary number is even. State Transition Diagram State Transition Table Check: 6 & 7 (i.e. 0110 & 0111) q0 0110  0q1 110  01q2 10  011q2 0  0110q1  Reached final state  string accepted q0 0111  0q1 111  01q2 11  011q2 1  0111q2  Reached non final state  not accepted Non deterministic automata:
  • 19.
    Theory of Computation11 q1 q3 q4 0 01 Start q2 1 q6 0 0 0 q5 1 q2 1 Start 1 0 0 0 0 q1 0 0 1 q3 Finite automata is also called as non deterministic automata when many paths are specified in code from the current state to next state NFA can be defined as the collection of five tuple A ={Q , ∑ , , qo , F} Example : 1 construct NFA where L={0101* + 0100 n ≥ 0} over the string ∑={0,1} Example 2 : construct the transmission diagram for NFA where M=({ q1 q2 q3 } , {0,1} , , q1 , { q3 } ) Where is given by ’(q1 , 0) = { q2 , q3} ’(q1 , 1)= { q1 } ’(q2 , 0) = { q1 , q2} ’(q2 , 1)={ ɸ } ’(q3 , 0) = { q2 } ’(q3 , 1)= { q1 , q2 } sol : Stateip 0 1 q1 q2 ɸ q2 ɸ q3 q3 {q4 , q5 } ɸ q4 ɸ q4 q5 q6 ɸ q6 ɸ ɸ
  • 20.
    Theory of Computation12 NFA with Epsilon transition: The transition in NFA is given in order to move from one state to another without having any symbol from input. state 0 1 q1 {q2 , q3} q1 q2 {q1 , q2} ɸ q3 q2 {q1 , q2}
  • 21.
    Theory of Computation13 q0 q q2 Start q1 q b ca q0 q2 Start q1 b a Definition: The language L is accepted by NFA with denoted by M ={Q , ∑ , , qo , F} can be defined as follow . Q x ( ∑ u { } )  2Q L(M) ={ w/w € ∑∗ } Epsilon closure (p) : It is set of all state which are reachable from state p or epsilon transition such that 1) closure (p) ={p}, Where p € Q 2) If there exist -closure (p) ={q} and ( q , ) = r , then closure (p) ={q, r}. Example 1: Find the closure for the following NFA with closure(q0 )={ q0 , q1 , q2} closure(q1)={ q1 , q2} closure(q2)={q2 } Conversion from NFA with to NFA without : 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 . ’(q, a) = closure( ( ^ (q, ), a)) Example 1: Convert the given NFA with transition to NFA without transition.
  • 22.
    Theory of Computation14 Step 1: closure closure (q0 )={ q0 } closure (q1 )={ q1 , q2 } closure (q2 )={ q2 } Step 2: ’(q0 , a) = q1 ’(q0 , b) = ɸ ’ (q0, ) = ɸ ’(q1 , a) = ɸ ’(q1 , b) = ɸ ’ (q1, ) = q2 ’(q2 , a) = ɸ ’(q2 , b) = q2 ’ (q2, ) = ɸ Step 3: ’(q0, a) = closure( ( ^ (q0 , ), a)) = closure( ( closure (q0 ), a)) = closure( (q0, a)) = closure(q1) = { q1 , q2 } ’(q0 , b) = closure( ( ^ (q0 , ), b)) = closure( ( closure (q0 ), b)) = closure( (q0 , b)) = closure ɸ = { ɸ } ’(q1, a) = closure( ( ^ (q1 , ), a)) = closure( ( closure (q1 )a)) = closure( ({q1 , q2 }, a)) = closure( (q1 , a) U (q2 , a)) = closure (ɸ U ɸ) = closure (ɸ) = { ɸ }
  • 23.
    Theory of Computation15 q2 Start b b a q2 q2 a ’(q1, b) = closure( ( ^ (q1 , ),b)) = closure( ( closure (q1 )b)) = closure( ({q1 , q2} , b)) = closure( (q1 , b) U (q2 , b)) = closure (ɸ U q2) = closure ( q2 ) = { q2 } ’(q2, a) = closure( ( ^ (q2 , ), a)) = closure( ( closure (q2 ), a)) = closure( ( q2, a)) = closure ɸ = { ɸ } ’(q2, b) = closure( ( ^ (q2 , ), b)) = closure( ( closure (q2 ), b)) = closure( ( q2 , b)) = closure (q2 ) = { q2 } Transition table : Step 4: Transition diagram : NFA without state a b q0 {q1 ,q2} ɸ q1 ɸ q2 q2 ɸ q2
  • 24.
    Theory of Computation16 q0 q2 Start q1 b ca 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 : Step 1: closure closure (q0 )={ q0 , q1 , q2 } closure (q1 )={ q1 , q2 } closure (q2 )={ q2 } step 2: (q0 , a) = q0 (q0 , b) = ɸ (q0, c) = ɸ (q0, ) = q1 (q1 , a) = ɸ (q1 , b) = q1 (q1, c) = ɸ (q1, ) = q2 (q2 , a) = ɸ (q2 , b) = ɸ (q2, c) = q2 (q2, ) = ɸ Step 3: ’(q0, a) = closure( ( ^ (q0 , ), a)) = closure( ( closure (q0 ), a)) = closure( (q0, a) 𝑈 (q1, a) 𝑈 (q2, a)) = closure ( q0 Uɸ U ɸ) = closure ( q0 ) = { q0 , q1 , q2 } ’(q0, b) = closure( ( ^ (q0 , ), b)) = closure( ( closure (q0 )b)) = closure( (q0, b) 𝑈 (q1, b) 𝑈 (q2, b)) = closure (ɸ 𝑈q1 𝑈ɸ) = { q1 , q2 } ’(q0, c) = closure( ( ^ (q0, ), c))
  • 25.
    Theory of Computation17 = closure( ( closure (q0 ), c)) = closure( (q0, c) 𝑈 (q1, c) 𝑈 (q2, c)) = closure (ɸ Uɸ Uq2) = { q2 } ’(q1, a) = closure( ( ^ (q1, ), a)) = closure( ( closure (q1 ), a)) = closure( (q1, a) 𝑈 (q2, a)) = closure (ɸ 𝑈 ɸ ) = closure (ɸ) = {ɸ} ’(q1, b) = closure( ( ^ (q1 , ),b)) = closure( ( closure (q1 )b)) = closure( (q1, b) 𝑈 (q2, b)) = closure (q1) = {q1 , q2} ’(q1, c) = closure( ( ^ (q1 , ), c)) = closure( ( closure (q1 ), c)) = closure( (q1, c) 𝑈 (q2, c)) = closure (ɸ𝑈q2) = {q2} ’(q2, a) = closure( ( ^ (q2 , ), a)) = closure( ( closure (q2 ), a)) = closure( (q2, a)) = closure (ɸ) = {ɸ} ’(q2, b) = closure( ( ^ (q2 , ), b)) = closure( ( closure (q2 ), b))
  • 26.
    Theory of Computation18 q0 q2 Start q1 a, b a a, b b c b = closure( (q2, b)) = closure (ɸ) = {ɸ} ’(q2,c) = closure( ( ^ (q2 , ), c)) = closure( ( closure (q2 ), c)) = closure( (q2, c)) = closure (q2) = {q2} Step 4: Transition table state a b c q0 {q0, q1, q2} {q1 ,q2} q2 q1 ɸ {q1 ,q2} q2 q2 ɸ ɸ q2 Transition diagram: Conversion N.F.A to D.F.A 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’).
  • 27.
    Theory of Computation19 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, (i) ’( [q1,q2,q3……qi], a) = (q1,a ) U (q2, a)…… U (qi, a) = [q1, q2, q3, ... , qk] (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 [q1, 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. Example 1: Construct the equivalent DFA for the given NFA. M = ({q0, q1}, {0,1}, , qo, {q1}) where is given by (q0,0) = {q0, q1} (q0,1) = { q1} (q1,0) = φ (q1,0) = {q0, q1} Sol: Transition Table (NFA) St/Ip 0 1 q0 {q0, q1} {q1} q1 φ {q0, q1}
  • 28.
    Theory of Computation20 Transition Diagram: ’( {q0, q1}, 0) = (q0, 0) U (q1, 0) = { q0, q1} U φ = { q0, q1} ’( {q0, q1}, 1) = (q0,1) U (q1, 1) = { 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} Transition Diagram: (DFA)
  • 29.
    Theory of Computation21 ssq q Example 2. Construct an DFA equivalent to the given NFA. 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}, 0) = ( p,0) U ( q,0) = {p, q} U {r} = {p, q, r} ’({p, q}, 1) = ( p,1) U ( q,1) = {p} U {r} = {p, r}
  • 30.
    Theory of Computation22 q q New State table: St/Ip 0 1 →P {p, q} p q r r r s φ s s s {p, q} {p, q, r} {p, r} ’({p, q, r}, 0) = ( p,0) U ( q,0) U ( r,0) = {p, q} U {r} U {s} = {p, q, r, s} ’({p, q, r}, 1) = ( p,1) U ( q,1) U ( r,1) = {p} U {r} U { φ } = {p, r} ’({p, r}, 0) = ( p,0) U ( r,0) = {p, q} U {s} = {p, q, s} ’({p, r}, 1) = ( p,1) U ( r,1) = {p} U { φ } = {p} New transition table: St/Ip 0 1 →P {p, q} p q r r r s φ s s s
  • 31.
    Theory of Computation23 q {p, q} {p, q, r} {p, r} {p, q, r} {p, q, r, s} {p, r} {p, r} {p, q, s} p ’({p, q, r, s}, 0) = ( p,0) U ( q,0) U ( r,0) U ( s,0) = {p,q} U {r} U {s} U {s} = {p, q, r, s} ’({p, q, r, s}, 1) = ( p,1) U ( q,1) U ( r,1) U ( s,1) = {p} U {r} U { φ } U {s} = {p, r, s} ’( [p,q,s],0) = ( p,0) U ( q,0) U ( s,0) = {p,q} U {r} U {s} = {p, q, r, s} ’( [p,q,s],1) = ( p,1) U ( q,1) U ( s,1) = {p,q} U {r} U {s} = {p, q, r, s} New transition table: St/Ip 0 1 →P {p, q} p q r r r s φ s s s {p, q} {p, q, r} {p, r} {p, q, r} {p, q, r, s} {p, r} {p, r} {p, q, s} p {p,q,r,s} {p, q, r, s} {p, r, s}
  • 32.
    Theory of Computation24 q2 {p,q,s} {p, q, r, s} {p, r, s} ’({p, r, s}, 0) = ( p,0) U ( r,0) U ( s,0) = {p,q} U {s} U {s} = {p, q, s}, ’({p, r, s}, 1) = ( p,1) U ( r,1) U ( s,1) = {p} U {s} U {s} = {p, s} New transition table: St/Ip 0 1 →[P] [p,q] [ p] [q] [r] [ r] [r] [s] φ s [s] [s] [p,q] [p,q,r] [p,r] [p,q,r] [p,q,r,s] [p,r] [p,r] [p,q,s] [p] p,q,r,s [p,q,r,s] [p,r,s] p,q,s [p,q,r,s] [p,r,s] p,r,s [p,q,s] [p,s] ’( [p,s],0) = ( p,0) U ( s,0) = {p,q} U {s} = [p,q,s] ’( [p,s],1) = ( p,1) U ( s,1) = {p} U {s} = [p,s]
  • 33.
    Theory of Computation25 New transition table: Transition Diagram: (DFA) METHOD FOR CONVERSION NFA WITH TO DFA 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. Step2 : Obtain transition on { p1p2……pn } for each input. D ({ p1p2……pn }, a) = closure( (P1 ,a) U (P2 (a) U ……U(Pn ,a)) =⋃ closure Pi , a= where a ϵ ∑ Step3 : State obtained [ P1P2……Pn ] ϵ QD , states containing final state Pi is a final state DFA. St/Ip 0 1 →[P] [p,q] [ p] [q] [r] [ r] [r] [s] - [s] [s] [s] [p,q] [p,q,r] [p,r] [p,q,r] [p,q,r,s] [p,r] [p,r] [p,q,s] [p] [p,q,r,s] [p,q,r,s] [p,r,s] [p,q,s] [p,q,r,s] [p,r,s] [p,r,s] [p,q,s] [p,s] [p,s] [p,q,s] [p,s]
  • 34.
    Theory of Computation26 EXAMPLE 1: Convert the following NFA with to equivalent DFA. b a a b closure(q0 )={ q0 q1 q2} closure(q1)={ q1 q2} closure(q2)={q2 } (q0 , a) = ɸ (q0 , b) = q0 (q1, ) = q1 (q1 , a) = q1 (q1 , b) = ɸ (q2, ) = q2 (q2 , a) = q1 (q2 , b) = q0 (q2, ) = ɸ ’(q0 , a) = closure( ( ^ (q0, ),a)) ’(q0 , a) = closure( ( closure q0 ),a)) = closure( ({q0 q1 q2 } ,a) ) = closure( (q0 ,a)U (q1 ,a)U (q2 ,a) ) = closure(ɸ U q1 U q1 ) = closure q1 = { q1 q2} ’(q0 , b) = closure( ( ^ (q0, ),b)) ’(q0 , b) = closure( ( closure q0 ),b)) = closure( ({q0 q1 q2 } ,b) ) = closure( (q0 ,b)U (q1 ,b)U (q2 ,b) ) q0 q1 q2
  • 35.
    Theory of Computation27 = closure(q0 U ɸ U q0 ) = closure q0 = { q0 q1 q2} ’(q1 , a) = closure( ( ^ (q1, ),a)) ’(q1 , a) = closure( ( closure q1 ),a)) = closure( ({ q1 q2 } ,a) ) = closure( (q1 ,a)U (q2 ,a) ) = closure( q1 U ɸ ) = closure q1 = { q1 q2} ’(q1 , b) = closure( ( ^ (q1, ),b)) ’(q1, b) = closure( ( closure q1 ),b)) = closure( ({ q1 q2 } ,b) ) = closure( (q1 ,b)U (q2 ,b) ) = closure(ɸ U q0 ) = closure q0 = { q0 q1 q2} ’(q2 , a) = closure( ( ^ (q2, ),a)) ’(q2, a) = closure( ( closure q2 ),a)) = closure( ({ q2 } ,a) ) = closure q1 = { q1 q2} ’(q2 , b) = closure( ( ^ (q2, ),b)) ’(q2, b) = closure( ( closure q2 ),b)) = closure( ({ q2 } ,b) ) = closure q0 = {q0 q1 q2}
  • 36.
    Theory of Computation28 q0 q2 11 Start a,b a,b q1 a,b a,b a,b a,bbb b Transition of NFA input state a b q0 { q1 q2} {q0 q1 q2} q1 { q1 q2} {q0 q1 q2} q2 { q1 q2} {q0 q1 q2} Transition diagram ‘([q1 q2 ],a)= (q1 ,a) U (q2,a) = { q1 , q2}U{ q1 , q2 } =[ q1 , q2 ] ‘([q1 q2 ],b)= (q1 ,b) U (q2,b) = { q0 , q1 , q2}U{ q0 , q1 , q2 } =[q0 , q1 , q2 ] ‘([q0 q1 q2 ],a)= (q0 ,a) U (q1 ,a) U (q2,a) ={ q1 , q2}U{ q1 , q2 }U{ q1 , q2 } =[ q1 , q2 ] ‘([q0 q1 q2 ],b)= (q0 ,b) U (q1 ,b) U (q2,b) ={ q0 ,q1 , q2}U{ q0 ,q1 , q2 }U{ q0 ,q1 , q2 } =[ q0 ,q1 , q2 ] Transition table for DFA
  • 37.
    Theory of Computation29 [q1,q2,q3] input state a b 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 ] a a b a b b b a a b [q1,q2] q0 q0 q1 q2
  • 38.
    Theory of Computation30 MINIMIZE METHOD TABLE FILLING 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. B C X X D X E X F X G X H X A B C D E F G
  • 39.
    Theory of Computation31 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
  • 40.
    Theory of Computation32 TABLE :4 B X C X X D X X X E X X X F X X X X G X X X H X 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
  • 41.
    Theory of Computation33 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
  • 42.
    Theory of Computation34 MINIMIZE METHOD [alter 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 Stinput 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
  • 43.
    Theory of Computation35 A B GD c Table 3 Stinput 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 Stinput 0 1 A B D B G C C A C D C G G G A : This is the minimized DFA 0 0 1 1 0 1 1 0 1 0
  • 44.
    Theory of Computation36 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 + . 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.
  • 45.
    Theory of Computation37 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…………}
  • 46.
    Theory of Computation38 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* EXAMPLE10:construct a RE for the language L,∑={a.b} in which total no of a’s are divisible by 3 Solution: RE=(b*ab*ab*ab*)* METHOD FOR CONSTRUCTION OF NFA FROM RE: EXAMPLE1:Construct NFA for the RE b+ba* Sol: r=b+ba* r=r +r
  • 47.
    Theory of Computation39 r =b r =r r r =b r =a* step1: r =b EXAMPLE2: Construct an NFA for the given RE (01+2*)1 Sol: R=(01+2*)1 R=r r r =01+2* r =1 r =r +r r =01 r =2* step1: r4=2* Step2: R3=01 Step3: R2=1 Step4: 01+2*
  • 48.
    Theory of Computation40 Step5:(01+2*)1 DIRECT OR SUBSET METHOD: EXAMPLE 1: design FA for the RE 10+(0+11)0*1 Step1: Step2: Step3:
  • 49.
    Theory of Computation41 Step4: Step5: Step6: Step7:
  • 50.
    Theory of Computation42 EXAMPLE 2:design the DFA for the FE 0+01* Step1: Step2: Step3: EXAMPLE3:design DFA for the given RE Step1: Step2:
  • 51.
    Theory of Computation43 Step3: Step4: IDENTITY RULES FOR RE: 1.ξ.R=R.ξ=R 2.ξ *=ξ 3.(Ф)*=ξ 4.Ф.R=R.Ф=Ф 5.Ф+R=R 6.R+R=R 7.RR* =R*R=R+ 8.(R*)*=R* 9.ξ+RR*=R+ 10.(P+Q)R=PQ+PR 11.(P+Q)*=P*Q*=(P*+*Q)* 12.R*(ξ+R)=(ξ+R)R*=R* 13.(R+ξ)*=R* 14.ξ+R*=R* 15.(PQ)*P=P(QP)* 16.R*R+R=R*R AVDEN METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION: Step1: let q1 be the initial state.
  • 52.
    Theory of Computation44 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
  • 53.
    Theory of Computation45 q1=ξ+ q11(1+01)* 00+ q10 q1=ξ+ q1(0+1(1+01)* 00) q1=ξ+(0+1(1+01)* 00)* q1=(0+1(1+01)* 00)* (ξ.R=R.ξ=R) EXAMPLE3: construct the RE for the given DFA 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: rik j=(rik-1 k) (rkk-1 k)* (rkk-1 j)+ rik-1 j K=1 (r11 1) i=1,j=1 (r11 1)= (r10 1) (r10 1)* (r1o 1)+ r10 1 =(ξ)(ξ)* (ξ)+ξ =ξ+ξ = ξ (r11 2) i=1,j=2 (r11 2)= (r10 1) (r10 1)* (r1o 2)+ r10 2 =ξ+0+0 =0 (r21 1) i=2,j=1 (r21 1)= (r20 1) (r10 1)* (r1o 1)+ r20 1 =Ф.ξ.ξ+Ф =Ф (r21 2) i=2,j=2 (r21 2)= (r20 1) (r10 1)* (r1o 2)+ r20 2 =Ф(ξ)* .0+(1+ξ) =Ф+ξ
  • 54.
    Theory of Computation46 =ξ Step3: Compute and find state from state q1 to final state q2 K=2 (r12 2)= (r10 2) (r20 2)*(r2o 2)+ r10 2 =0(ξ)*ξ+0 =0+0 r12=0
  • 55.
    Theory of Computation47 Theorem: Every language defined by a regular expression is also defined by a finite automaton. Proof: Suppose L = L(R) for a regular expression R. We show that L = L(E) for some -NFA E with: 1. Exactly one accepting state. 2. No arcs into the initial state. 3. No arcs out of the accepting state. BASIS: There are three parts to the basis as shown in the following three figures. Part (a) to handle the expression . The language of the automaton is easily seen to be { }, since the only path from the start state to an accepting state is labeled . i.e., Regular expression = . 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. 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. Thus, the language of the automaton in Figure is L(R) U L(S). R S a
  • 56.
    Theory of Computation48 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). 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: (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. ∎ R R S
  • 57.
    Theory of Computation49 PUMPING LEMMA: To prove languages are not regular. Statement: Let L be a regular language, then there is a constant such that for every string in L and | | . We can break into three sub-strings and represented as = such that 1. ≠ 𝜖. i.e., | | . 2. | | . 3. For all , the string is also in L. Proof: If L is a regular Language, then it is accepted by a DFA 𝐴 = 𝑄, 𝛴, 𝛿, , 𝐹 with n states. i.e., L = L(A). Consider the input string w of length or more, say = 𝑎 𝑎 . . . 𝑎 where and each 𝑎 is an input symbol. The mapping function can be defined as 𝛿 , 𝑎 𝑎 . . . 𝑎 = . For the string 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 and with < such that = . Now we break = as follows: 1. = 𝑎 𝑎 … 𝑎 2. = 𝑎 + 𝑎 + … 𝑎 3. = 𝑎 + 𝑎 + … 𝑎 In the DFA 𝐴 as shown in figure, we can move from the start state p0 to pi with the input string , takes us from back to (since = ), and takes us from to . Note that may be empty if = , Also may be empty if = = . However cannot be empty as < . 𝛿 , 𝑎 𝑎 . . . 𝑎 𝑎 + … 𝑎 𝑎 + … 𝑎 = 𝛿 𝛿 , 𝑎 , … , 𝑎 , 𝑎 + … 𝑎 𝑎 + … 𝑎 = 𝛿 , 𝑎 + … 𝑎 𝑎 + … 𝑎 = 𝛿 𝛿 , 𝑎 + … 𝑎 , 𝑎 + … 𝑎 = 𝛿 , 𝑎 + … 𝑎 = If the automaton 𝐴 receives the input w. that is . Case 1: If = 0, then = 0 = . The automaton 𝐴 goes from the start state 0 to on input . Since is also , A goes from to the accepting state on input . Thus 𝐴 accepts . Case 2: If > 0, then the automaton 𝐴 goes from 0 to on input . Circles from to k times on input , and then goes from to the accepting state on input . Thus 𝐴 accepts . Thus, for 0, is accepted by a automaton 𝐴. That is, is in 𝐿. i.e. We have proved that given string of any length can be accepted by Finite Automata by pumping a substring. i.e., substring repeated as many times as we like and resulting string may be accepted by Finite Automata. ∎ ADVANTAGES: Pumping lemma is used to check the given language is not regular or not. p0 pi pF Start = 𝑎 … 𝑎 = 𝑎 + … 𝑎 = 𝑎 + … 𝑎
  • 58.
    Theory of Computation50 EXAMPLE1:show that the set L={bi2 } is not regular. Solution: To prove L=bi2 is not regular i=2 L=2 => L=b4 =bbbb i=3 L=3 => L=b9 =bbbbbbbbb according to pumping lemma Lui w Є L where i≥1 L=uvi w L=b(bb)i b if i=2 => bbbbbb not belongs to L If i=3 => bbbbbbbb not belongs to L EXAMPLE2: show that the language L={0n 1n+1 /n>0} is not regular Solution: To prove L={0n 1n+1 /n>0} is not regular Let n=1 L=01 12 = 011 Let n=2 L=02 13 =00111 Let n=3 L=03 14 =0001111 Length of the string =n+n+1 =2n +1 Then according to pumping lemma L=011 U=0 v=1 w=1 uvi w=01i 1 =0111(if i=2)not belongs to L e length of the string after pumping is not in 2n +1 form EXAMPLE3: check the given language L={02n /n/n≥1} is not regular or not Solution: Let n=1 L= 02(1) =00 Let n=2 L =02(2) =0000 Let n=3 L=02(3) =000000 Note: L=string consisting of even no of 0’s L=even length of string with 0 Then according to pumping lemma L= 0000 uvi w= o(00)i 0 =0000(if n=1) 0(00)i 0 Є L
  • 59.
    Theory of Computation51 Closure properties of regular languages (RL) If certain languages are regular and a new language L is formed from them by certain operations (such as union or concatenation) then L is also regular. These properties are called closure properties of regular languages. Such languages represent the class of regular languages which is closed under the certain operations. The closure properties express the idea that when one or many languages are regular then certain related languages are also regular. The closure properties of regular languages are as given below. 1. The union of two regular languages is regular. 2. The intersection of two regular languages is regular. 3. The complement of a regular language is regular. 4. The difference of two regular languages is regular. 5. The reversal of a regular language is regular. 6. The Kleene closure operation on a regular language is regular. 7. The concatenation of regular language is regular. 8. A homomorphism of regular languages is regular. 9. The inverse homomorphism of regular language is regular. Theorem 1: If L1 and L2 are two languages then L1 ∪ L2 is regular. Proof: If L1 and L2 are regular then they have regular expression L1 = L (R1) and L2 = L (R2). Then L1 ∪ L2 = L (R1 + R2) thus we get L1 ∪ L2 as regular language. (Any language given by some regular expression is regular). Theorem 2: The complement of regular language is regular. Proof: Consider L1 be regular language which is accepted by a DFA M = (Q, Σ, , q0, F). The complement of regular language L̅1 is which is accepted by M ' = (Q, Σ, , q0, Q-F). That means M is a DFA with final states ∈ F and M ' is a DFA in which all the non-final states of M become final. In other words, we can say that strings that are accepted by M are rejected by M' similarly, the strings rejected by M are accepted by M'. Thus L̅1 is accepted by M' is regular. Theorem 3: If L1 and L2 are two languages then L1 ∩ L2 is regular. Proof: Consider that languages L1 is regular. That means there exists some DFA M1 that accepts L1. We can write M1 = (Q1, Σ, 1, q1, F1 ) Similarly being L2 regular there is another DFA M2 = = (Q2, Σ, 2, q2, F2 ). Let L be the language obtained from L1 ∩ L2. We can the simulate M=(Q, Σ, , q, F ). Where Q = Q1 ∩ Q2 = 1 ∩ 2 a mapping function derived from both the DFAs. q ∈ Q which is initial state of machine M. F = F1 ∩ F2, the set of final states, which is common for M1 and M2 both. It is clear that there exists some DFA which accepts L1 ∩ L2 i.e. L. Hence L is a regular language. This proves that if L1 and L2 are two regular languages then L1 ∩ L2 is regular. In other words the regular language is closed under intersection. Theorem 4: If L1 and L2 are two regular languages then L1 - L2 is regular. Proof : The L1 - L2 can also be denoted as L1 ∪ L̅2 Consider L1 be regular language which is accepted by DFA M = (Q, Σ, , q0, F). The complement of regular language L1 is L̅2 which is accepted by M ' = (Q, Σ, , q0, Q-F). That means M is a DFA with final states set F and M' is a DFA in which all the non final states of M become final states and all the final states of M become non-final states Thus L1 and L̅2 are two regular languages. That also means: these languages are accepted by regular expressions. If L1 =L(R1) and L̅2=L(R'2). Then L1 ∪ L̅2 = L(R1+R'2). This ultimately shows
  • 60.
    Theory of Computation52 that L1 ∪ L̅2 is regular. In other words L1 - L2 is regular. Thus regular languages are closed under difference. Theorem 5: The reversal of a regular languages is regular Proof: Reversal of a string means obtaining a string which is written from backward that is W R is denoted as reversal of string w. That means L(wR ) = (L(w))R . This proof can be done with basis of induction. Basis: If w = ɛ or ϕ then w R is also ɛ or ϕ i.e. (ɛ )R = ɛ and (ϕ )R = ϕ Hence L(w R ) is also regular. Induction : Case 1: If w = w1 + w2 then w = (w1)R +( w2)R As the regular language is closed under union, w is also regular. Case 2 : If w = w1 w2 then w = (w1)R ( w2)R As the regular language is closed under concatenation, w is also regular Thus, the reversal of a regular languages is regular. Theorem 6: The closure operation on regular language is regular Proof : If language L1 is regular then it can be expressed as L1 =L(R1 * ). Thus for a closure operation a language can be expressed as a language of regular expressions. Hence L1 is said to be a regular language. 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 L1 =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. Theorem 8: A homomorphism of regular language is regular. Proof : The term homomorphism means substitution of string by some other symbols. For instance the string "aabb" can be written as 0011 under homomorphism. Clearly here, a is replaced by 0 and b is replaced by 1. Let Σ is the set of input alphabets and Γ be the set of substitution symbols then Σ *→Γ* is homomorphism. The definition of homomorphism can be extended as Let, w = a1 a2 … an h(w) = h(a1)h(a2)...h(an) If L is a Language that belongs to the set Σ, then homomorphic image of L can be defined as h(L) = { h(w): w∈L } To prove that if L is regular, h(L) is also regular consider following example Let Σ = {a,b} and w = abab Put h(a) = 00 and h(b) = 11 Then we can write h(w) = h(a) h(b) h(a) h(b) =00110011 The homomorphism to language is applied by applying homomorphism on each string of language. ∴ If L = ab* b = ab+ = {ab, abb, abbb, abbbb, ...} Now h(L) = {0011, 001111, 00111111, 0011111111, ...} ∴ h(L) = 00 (11)+ As it can be represented by a regular expression, it is a regular language. Hence it is proved that if L is regular then h(L) is also regular. In other words, family of regular languages is closed under homomorphism.
  • 61.
    Theory of Computation53 Theorem 9: The inverse homomorphism of regular language is regular. Proof: Let h: Σ*→Γ* is homomorphism. The Σ is the input set and Γ be the substitution symbols used by homomorphic function. Let, L be the regular language where L ∈ Σ then h(L) be homomorphic language. The inverse homomorphic language can be represented as h-1 (L) such that h-1 : Γ* → Σ* Let, h-1 (L) = {w | w ∈ L} If L is regular then h(L) is also regular because regular language is closed under homomorphism. That if there exist a FA M = (Q, Σ, , q, F) which accepts L then h(L) must also be accepted by FA M. For complement of L i.e. language L' the inverse homomorphic language is h-1 (L). Let M' = (Q, Σ, , q, Q-F) be the FA in which all the final states of M become non-final states and all the non-final states of M become the final states. Clearly the language L' can be accepted by M' Hence h-1 (L) must also be accepted by FA M'. Let L= (010)* is a R.L., h(0) = a and h(1) = bb be a homomorphic function then h(L) = (abba)* h-1 (h(L))= (010)* = L as the inverse homomorphism h-1 (a)=0 and h-1 (bb)=1. Decision properties of regular languages (RL) 1. Membership property: A string is in a language, i.e., w ∈ L 2. Emptiness property: Accepting state separated from start state, i.e., ɸ 3. Equivalence property: Two languages are equal, i.e., L1 = L2