0% found this document useful (0 votes)
66 views

CS6503 Theory of Computation Notes

Toc notes

Uploaded by

TJS CSE HOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

CS6503 Theory of Computation Notes

Toc notes

Uploaded by

TJS CSE HOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 57

CS6503 THEORY OF COMPUTATION LTPC 3003

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

Equivalence of NFA and DFA


6
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

Elimination of Useless symbols


6
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 + 423k+2 - 423k+2 + 3.3k + 2 { Add & Sub 423k+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
𝑛(𝑛+1)(2𝑛+1)
Prove by mathematical induction Ʃn2 = for all n ≥ 1.
6

Proof:

2 2 2 𝑛(𝑛+1)(2𝑛+1)
1 + 2 + ... + n =
6
1(1+1)(2.1+1) 1𝑥2𝑥3
Let n = 1, LHS = 12= 1, RHS = = = 1, ฀ LHS = RHS
6 6
2(2+1)(2.2+1) 2𝑥3𝑥5
Let n = 2, LHS = 12 + 22= 1 + 4 = 5, RHS = = = 5, ฀LHS = RHS
6 6

k(k+1)(2k+1)
Let n = k, 12 + 22 + ... + k2= , assumed to be true
6

Let n = k+1, LHS = 12 + 22 + ... + k2+ (k + 1)2


= k(k+1)(2k+1) 2
+ (k + 1)
6

k(k+1)(2k+1)
= + (k + 1) (k +1)
6
k(k+1)(2k+1)
6(k+1)(k+1)
=
+6 6

k(k+1)(2k+1)+6(k+1)(k+1)
=
6

(k+1)[k(2k+1)+6(k+1)]
= 6

(k+1)( 2k2+ k+6k+6)


= 6

(k+1)( 2k2+ 7k+6)


=
6

(k+1)( k+2)(2k+3)
= 6

(k+1)(k+1+1)(2[k+1]+1)
RHS 6

= (k+1)(k+2)(2k+2+1)
6

= (k+1)( k+2)(2k+3)
6

□ 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 = {0, 1}

∑2 = {00, 01, 10, 11}

∑3 = {000, 001, 010, 011, 100, 101, 110, 111}


Theory of Computation 7

∑+ = ∑1 𝑈 ∑2 𝑈 ∑3 …

∑+ = ∑i ⋃∞
i

∑∗ = ∑0 𝑈 ∑1 𝑈 ∑2 𝑈 …

∑∗ = ∑i ⋃∞
i

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  Initial or start state q0∈Q

F  Set of all final states

a b c a a b c a Input tape
Tape head /
reader

Finit
Types of finite automata (FA)
e
 Deterministic finite automata (DFA)
 Non deterministic finite automat (NFA)

Transition diagram

Transition 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:
Start q0 1 q1 1 q2 1
q3

Example 2 Design FA which accepts only those strings which start with 0 and end with 1
over the input set Σ = {0, 1}

Solution:
0 1
Start q0 0
q1 1
q3
0
Theory of Computation 9

Example 3 Design FA & State Table which accepts odd number of 1’s and any number of
0’s.
0 Input
States 0 1
q2
1 q0 q1 q2
1
Start q0 1 q1 q1 q2

0 q1 q2 q2 q1
0
State Transition Diagram State Transition Table

FA A = (Q, ∑, δ, q0, F)

= ({q0, q1, q2}, {0, 1}, {δ(q0, 0)= q1, δ(q0, 1)= q2, δ(q1, 0)= q1, δ(q1, 1)= q2 , δ(q2, 0)=
q2, δ(q2, 1)= q1 }, q0, {q2})

Check: 0110 & 1110


q 0110  0q 110  01q 10  011q 0  0110q  Reached non final state  not accepted
0 1 2 1 1
q 1110  1q 110  11q 10  111q 0  1110q Reached final state  string accepted
0 2 1 2 2

Example 4 Design FA which accepts the unary number which is divisible by 3 over Σ = {1}.
Start 1 1 q2 1

Check: 111 & 1111


q 111  1q 11  11q 1  111q  Reached final state  String accepted
0 1 2 3
q 1111  1q 111  11q 11  111q 1  1111q  Reached non final state  not accepted
0 1 2 3 1

Example5 Design FA & State Table which accepts the binary number which is divisible by 3.
Input
States 0 1
1 q0 q1 q2
0
q1 q1 q2
Start q0 0 1 q2 q3
q1
q2 q3 q1
1 0 q2
1 q3 q3
00

State Transition Diagram State Transition Table


Theory of Computation 10

Check: 9 & 8 (i.e. 1001 &1000 )


q 1001  1q 001  10q 01  100q 1 1001q  Reached final state  String accepted
0 2 3 2 1
q 1000  1q 000  10q 00 100q 0 1000q  non final state  not accepted
0 2 3 2 3

Example 6 Design FA to accept L, where L= {Strings in which ‘a’ always appears tripled}
over the input set Σ = {a, b}.
Input
b b States a b
a a a s0 s1 s0
Start s0 s1 s2 s3
a s1 s2 
s2 s3 
s s1 s3
3

Example 7 Design FA which checks the given binary number is even.


0
q1 Input
0 States 0 1
0 1 q0 q1 q2
Start
q0
1 q2 q1 q1 q2

1 q2 q2 q1
State Transition Diagram
State Transition Table

Check: 6 & 7 (i.e. 0110 & 0111)


q 0110  0q 110  01q 10  011q 0  0110q  Reached final state  string accepted
0 1 2 2 1
q 0111  0q 111  01q 11  011q 1  0111q  Reached non final state  not accepted
0 1 2 2 2

Non deterministic automata:

b b
a
Start q0 q0

q0
Theory of Computation 11

Finite automata is also called as non deterministic automata when many paths are
specified in code from the current state to next state

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}

0 1 00
Start q1 q2 q3 q4
0

q5
0
q6

State\ip 0 1
q1 q2 ɸ
q2 ɸ q3
q3 {q4 , q5 } ɸ
q4 ɸ q4
q5 q6 ɸ
q6 ɸ ɸ

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 :

1
0
1
1
Start q1 0 q2 q3
0 0
0
0
Theory of Computation 12

state 0 1
q1 {q2 , q3} q1
q2 {q1 , q2} ɸ
q3 q2 {q1 , q2}

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.
Theory of Computation 13

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 ε

a b c

ε ε
Start q0 q1 q
2

ε closure(q0 )={ q0 , q1 , q2}

ε closure(q1)={ q1 , q2}

ε closure(q2)={q2 }

Conversion from NFA with s to NFA without s :

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.
b

a ε
Start q0 q1 q
2
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

δ’(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 :
state a b
q0 {q1 ,q2} ɸ
q1 ɸ q2
q2 ɸ q2
Step 4:

Transition diagram : NFA without ε

b
a
Start q2
a q2 b q2
Theory of Computation 16

Example 2 : Construct NFA with ε which access a language consisting of a string of any
number of ‘a’ followed by any number of ‘b’ and followed by any number ‘ c ‘. Convert
the NFA with ε to NFA without ε.

sol :
a b c

ε ε
Start q0 q1 q
2

Step 1: ε closure

ε 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

= ε 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:

a b c

a, b b
Start q0 q1 q
2
a, b

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 [q 1, q2,
q3, ... , qk], if we get some state [q1,q2…..qn] which is not Q’ of DFA then add
this to Q’.

(iv) If there is no new state generating then stop the process after finding
all the transition.

(v) For the state [q1, q2, q3, ... , qk] € Q’ of DFA, if any 1 state qi is a final
state of NFA then [q1,q2…..qn] becomes a final state. Thus the set of all final
states € F’ of DFA.

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

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

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

{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

{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,qq,s [p,q,r,s] [p,r,s]


2

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)


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]

METHOD FOR CONVERSION NFA WITH s 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))


𝑛
i=1
= ε closure δ(Pi , where a ϵ ∑
a)

Step3 : State obtained [ P1P2……Pn ] ϵ QD , states containing final state Pi is a final state
DFA.
Theory of Computation 26

EXAMPLE 1: Convert the following NFA with ε to equivalent DFA.

b a

ε q1 ε
q0 q2

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) )


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

Transition of NFA

input a b
state
q0 { q1 q2} {q0 q1 q2}

q1 { q1 q2} {q0 q1 q2}

q2 { q1 q2} {q0 q1 q2}

Transition diagram

b b a,b
Start q0 q1
a,b
a,b
a,b
b a,b
11
q2

a,b
δ ‘([q1 q2 ],a)= δ(q1 ,a) U δ(q2,a)

= { q1 , q2}U{ q1 , q2 }

=[ q1 , q2 ]

δ ‘([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

input a b
state
q0 [ q1 q2 ] [ q0 q1 q2 ]

q1 [ q1 q2 ] [ q0 q1 q2 ]

q2 [ q1 q2 ] [ q0 q1 q2 ]

q1 q2 [ q1 q2 ] [ q0 q1 q2 ]

[ q0 q1 q2 ] [ q1 q2 ] [ q0 q1 q2 ]

q1 qq20
q0

a a b

a b b
[q1,q2] b [q1,q2,q3]

a b
Theory of Computation 30

MINIMIZE METHOD

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.

C X X

D X

E X

F X

G X

H X
A B C D E F G
Theory of Computation 31

TABLE 2

B X

C X X

D X X

E X

F X X

G X X

H X X

TABLE :3

B X

C X X

D X X X

E X X

F X X X

G X X

H X X
A B C D E F G
Theory of Computation 32

TABLE :4

B X

C X X

D X X X

E X X X

F X X X X

G X X X
X
H X X
A B C D E F G

TABLE :5

B X

C X X

D X X X

E X X X

F X X X X

G X X X X

H X X X X
A B C D E F G
Theory of Computation 33

TABLE :6

B X

C X X

D X X X

E X X X

F X X X

G X X X X X

H X X X X X X
A B C D E F G

TABLE :7

B X

C X X

D X X X

E X X X

F X X X X

G X X X X X X

H X X X X X X
A B C D E F G

Minimized DFA
State/Input 0 1
->A B D
B G C
C* A C
D C G
E G A
Theory of Computation 34

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
St\input 0 1
A B F
B G C
C A C
D C G
E H/B F
F C G
G G E
H G C

 B=H
Eliminate H
Replace H by B
Table 2
St/input 0 1
A B F
B G C
C A C
D C G
E B F
F C G
G G E/A
 A=E
Eliminate E
Replace E by A
Theory of Computation 35

Table 3
St\input 0 1
A B F/D
B G C
C A C
D C G
F C G
G G A
 D=F
Eliminate F
Replace F with D

Table 4
St\input 0 1
A B D
B G C
C A C
D C G
G G A

: This is the minimized DFA

A B
0

1 1 0 1 1
0
1
c
D G
0
Theory of Computation 36

THEOREM: Let L be a set accepted by Nondeterministic finite automata (NFA), then there
exist a Deterministic finite automata (DFA) that accepts L.
Proof:
Let M = (Q, Σ, δ, qo, F) be an NFA for language L, then Define DFA Mʹ such that
Mʹ = (Qʹ, Σʹ, δʹ, qoʹ, Fʹ)
(i) The states of Mʹ are all the subsets of M then the Qʹ=2Q
(ii) The input symbols are common for both NFA and DFA. i.e., Σʹ = Σ
(iii) If q0 is the initial state in the NFA, then q0ʹ = [q0] = initial state in DFA
(iv) Fʹ be the set of all final states which contain final states of M. i.e., Fʹ ⊆ 2Q 𝖴 F
(v) The element in Qʹ will be denoted by [q1, q2, q3, … , qi] is a single state in Qʹ and the
elements in Q denoted by{q1, q2, q3, …, qi} are multiple states in Q. Define δʹ such that
δʹ([q1, q2, q3, …, qi], a) = [p1, p2, p3, …, pj] iff δʹ({q1, q2, q3, …, qi}, a) = {p1, p2, p3, …, pj}
This mean that in NFA, at the current states { q1, q2, q3, …, qi }, if we give input a
then it goes to the next states {p1, p2, p3, … , pj}.
While constructing DFA, the current state is assumed to be [q1, q2, q3, …, qi] with
input a, the next state is assumed to be [p1, p2, p3, … , pj].
On applying δ function on each of states q1, q2, q3, …, qi, the new states may be any
of the states from p1, p2, p3, … , pj.
The theorem can be proved by mathematical induction on length of the input string x.
δʹ(q0ʹ, x) = [q1, q2, q3, …, qi] if and only if δ(q0, x) = {q1, q2, q3, …, qi}
Basis: If the length of input string is 0, i.e., |x|=0, that means x is ε then q0ʹ = [q0]
Induction: If we assume that the hypothesis is true for the input string of length 𝑚 (or less
than 𝑚), then if xa is the string of length 𝑚 + 1.
Now the function δʹ can be written as δʹ(q0ʹ, xa) = δʹ(δʹ(q0, x), a)
By the induction hypothesis,
δʹ(q0ʹ, x) = [p1, p2, p3, … , pj] if and only if δ(q0, x) = {p1, p2, p3, … , pj}
By definition of δʹ
δʹ([p1, p2, … , pj], a) = [r1, r2, ..., rk] if and only if δ({p1, p2, … , pj}, a) = {r1, r2, ..., rk}
Thus, δʹ(q0ʹ, xa) = [r1, r2, ..., rk] if and only if δ(q0, xa) = {r1, r2, ..., rk} is shown by induction.
Therefore L(M)=L(Mʹ).
i.e., If a language is accepted by NFA then the same language is also accepted by DFA.
Hence the theorem∎

THEOREM: If L is accepted by NFA with ε transition, then their exist L which is accepted
by NFA without ε transition. (Show that the language L accepted by NFA with ε move must
be accepted by NFA without ε move.)
Proof:
Let M = (Q, Σ, δ, q0, F) be an NFA with ε transition.
Construct Mʹ = (Q, Σ, δʹ, q0, Fʹ)
where Fʹ={ F 𝖴{q0} if ε closure contains state off
{F otherwise
Mʹ is a NFA without ε moves. The δʹ function can be denoted by the δʹʹ with same input.
For example, δʹ(q, a) = δʹʹ(q, a) for some q in Q and a from Σ.
We will apply the method of induction with input string x.
Basis:
The x will not be ε because δʹ(q0, ε)={q0} and δʹʹ(q0, ε) = ε-closure(q0)
Assume that the length of string x to be 1, i.e., |x|=1, then x is a symbol, say ʹaʹ.
δʹ(q0, a) = δʹʹ(q0, a)
Induction
Assume that the length of string x to be more than 1. i.e., |x| >1.
Theory of Computation 37

Let w = xa
δʹ(q0, wa) = δʹ(δʹ(q0, w), a)
By Induction hypothesis,
δʹ(q0, w) = δʹʹ(q0, w) = P
Now we will show that δʹ(p, a) = δ(q0,wa)
But δʹ(p, a) = 𝖴q in P δʹ(q, a) = 𝖴q in P δʹʹ(q, a)
AS P = δʹʹ(q0, w)
We have 𝖴q in P δʹʹ(q, a)= δʹʹ(q0,wa)
Thus by define of δʹʹ, δʹ(q0, wa) = δʹʹ(q0,wa)
L(M)=Lʹ(M)
i.e., If a language is accepted by NFA with ε transition then the same language is also
accepted by NFA without ε transition.
Hence the theorem∎

REGULAR EXPRESSION:
DEFENITION:
The language accepted by finite automata are easily described by simple
expression called regular expression.
REGULAR SET:
Regular sets are the sets which are accepted by finite automata.
EXACT DEFENITION:
Let ∑ be an alphabet which is used to denote the input set. The regular
expression over ∑ can be defined as follows
1) Фis the regular expression which denotes the empty set.
2) ξ is the regular expression and denote the set {ξ} (null string).
3) For each a in ∑ ,a is a regular expression and denote the set{a}.
4) If ‘R’ and ‘S’ are regular expression denoting the languages L1 and L2
respectively then
r+s is equivalent to L1υL2 ie.union
rs is equivalent to L1L2 ie.concatenation
r* equivalent to L1* ie.klean closure

EXAMPLE 1: write the regular expression for the language accepting all combination of a’s
over the set ∑={a}.
Solution:
Regular set={ ξ,a,aa,aaa,…….}
Regular expression(RE)=a*

EXAMPLE 2: design the RE for the language accepting all combination all combination of
a’s except the null q string over ∑={a}
Solution:
Regular set={ a,aa,aaa,………}
Regular expression(RE)=a+

EXAMPLE 3: design the RE for the language containing any no of a’s and b’s.
Solution:
Regular set={ ξ,a,b,aa,ab,bb,ba,aaa...............}
Theory of Computation 38

Regular expression(RE)=(a+b)*

EXAMPLE 4: construct RE for the language accepting all the strings which are ending with
00 ∑={0,1}.
Solution:
Regular set={ 00,000,100,0000,0100,1000,1100…........}
Regular expression(RE)=(0+1)*00

EXAMPLE 5: write the RE for the language accepting the strings which are starting with 1
and ending with 0 ∑={0,1}
Solution:
Regular set={ 10,100,110,1000,1010,1100,1110…..........}
Regular expression(RE)=1(0+1)*0

EXAMPLE 6: write RE to denote the language which accepts all the string which begin or
end with with either 00 or 11.
Solution:
L1=string begin with 00 or 11
L1=(00+11)(0+1)*
L2=string end with 00 or 11
L2 =(0+1)*(00+11)
RE=(00+11)(0+1)*+(0+1)*(00+11)

EXAMPLE 7: construct a RE for the language L which accepts all strings with atlest two ‘b’
over ∑={a.b}.
Solution:
RE=(a+b)*b(a+b)*b(a+b)*

EXAMPLE 8:Construct RE for the language which accepts all the string with atleast two b
over ∑={a,b,c}
Solution:
` RE=(a+b+c)*b(a+b+c)*b(a+b+c)*

EXAMPLE 9:construct a RE for the language which consist of exactly 2b’s over the set
∑={a,b}
Solution:
RE=a*ba*ba*

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Ύ r4
rΎ =b
r4 =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Ύ +r4
rΎ =01
r4 =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:
rikj=(rik-1k) (rkk-1k)* (rkk-1j)+ rik-1j
K=1
1
(r1 1) i=1,j=1 (r111)= (r101) (r101)*(r1o1)+ r101
=(ξ)(ξ)*(ξ)+ξ
=ξ+ξ

(r112) i=1,j=2 (r1 2)= (r101) (r101)*(r1o2)+ r102
1

=ξ+0+0
=0
(r211) i=2,j=1 (r2 1)= (r201) (r101)*(r1o1)+ r201
1

=Ф.ξ.ξ+Ф

(r212) i=2,j=2 (r212)= (r201) (r101)*(r1o2)+ r202


=Ф(ξ)*.0+(1+ξ)
=Ф+ξ
Theory of Computation 46

Step3:
Compute and find state from state q1 to final state q2
K=2
(r1 2)= (r102) (r202)*(r2o2)+ r102
2

=0(ξ)*ξ+0
=0+0
r12=0
Theory of Computation 47

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.
a

It is easy to check that these automata all satisfy conditions (1), (2), and (3) of the inductive
hypothesis.

INDUCTION: We assume that the statement of the theorem is true for the immediate sub-
expressions of a given regular expression; that is, the languages of these sub-expressions are
also the languages of ε-NFA's with a single accepting state. The four cases are:

1. The expression is R + S for some smaller expressions R and S. Then the automaton of
Figure serves. That is, starting at the new start state, we can go to the start state of
either the automaton for R or the automaton for S. We then reach the accepting state of
one of these automata, following a path labeled by some string in L(R) or L(S),
respectively. Once we reach the accepting state of the automaton for R or S, we can
follow one of the ε-arcs to the accepting state of the new automaton.

R ε
ε

ε ε

Thus, the language of the automaton in Figure is L(R) U L(S).


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).

ε
R S

Thus, the paths in the automaton of Figure are all and only those labeled by
strings in L(R)L(S).
3. The expression is R* for some smaller expression R. Then we use the automaton
of Figure. That automaton allows us to go either:

ε ε
R

(a) Directly from the start state to the accepting state along a path labeled ε. That
path lets us accept ε, which is in L(R)* no matter what expression R is.
(b) To the start state of the automaton for R, through that automaton one or more
times, and then to the accepting state. This set of paths allows us to accept
strings in L(R), L(R)L(R), L(R)L(R)L(R), and so on, thus covering all strings in
L(R) except perhaps ε, which was covered by the direct arc to the accepting state
mentioned in the figure.
4. The expression is (R) for some smaller expression R. The automaton for R also serves
as the automaton for (R), since the parentheses do not change the language defined by
the expression.
It is a simple observation that the constructed automata satisfy the 3 conditions given in the
inductive hypothesis - one accepting state, with no arcs into the initial state or out of the
accepting state. ∎
Theory of Computation 49

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 w
in L and |w| ≥ 𝑛. We can break w into three sub-strings and represented as w = 𝑥𝑦𝑧 such
that
1. 𝑦 ≠ 𝜖. i.e., |𝑦| ≥ 1.
2. |𝑥𝑦| ≤ 𝑛.
3. For all 𝑘 ≥ 0, the string 𝑥𝑦k𝑧 is also in L.
Proof:
If L is a regular Language, then it is accepted by a DFA 𝐴 = (𝑄, 𝛴, 𝛿, 𝑞0, 𝐹) with n
states. i.e., L = L(A). Consider the input string w of length 𝑛 or more, say w = 𝑎1𝑎2. . . 𝑎𝑚
where 𝑚 ≥ 𝑛 and each 𝑎i is an input symbol. The mapping function δ can be defined as
𝛿(𝑝0, 𝑎1𝑎2. . . 𝑎i) = 𝑝i.

For the string w of length m, this is more than the number of states n. By
pigeonhole principle, at least one state must repeat. Thus we can find two different integers
i and j with 0 ≤ i < j ≤ 𝑛 such that 𝑝i = 𝑝j. Now we break w = 𝑥𝑦𝑧 as follows:
1. 𝑥 = 𝑎1𝑎2 … 𝑎i
2. 𝑦 = 𝑎i+1𝑎i+2 … 𝑎j
3. 𝑧 = 𝑎j+1𝑎j+2 … 𝑎𝑚
In the DFA 𝐴 as shown in figure, we can move from the start state p0 to pi with the
input string 𝑥, 𝑦 takes us from 𝑝i back to 𝑝i (since 𝑝i = 𝑝j), and 𝑧 takes us from 𝑝i to 𝑝𝐹.
𝑦 = 𝑎i+1 … 𝑎j

𝑧 = 𝑎j+1 … 𝑎𝑚
Start 𝑥 = 𝑎1 … 𝑎i
p0 pi pF

Note that 𝑥 may be empty if i = 0, Also 𝑧 may be empty if j = 𝑛 = 𝑚. However 𝑦


cannot be empty as i < j.
𝛿(𝑝0, 𝑎1𝑎2. . . 𝑎i𝑎i+1 … 𝑎j𝑎j+1 … 𝑎𝑚) = 𝛿(𝛿(𝑝0, 𝑎1, … , 𝑎i), 𝑎i+1 … 𝑎j𝑎j+1 … 𝑎𝑚)
= 𝛿(𝑝i, 𝑎i+1 … 𝑎j𝑎j+1 … 𝑎𝑚)
= 𝛿(𝛿(𝑝i, 𝑎i+1 … 𝑎j), 𝑎j+1 … 𝑎𝑚)
= 𝛿(𝑝j, 𝑎j+1 … 𝑎𝑚)
= 𝑞𝐹
If the automaton 𝐴 receives the input w. that is 𝑥𝑦k𝑧.
Case 1: If 𝑘 = 0, then w = 𝑥𝑦0𝑧 = 𝑥𝑧. The automaton 𝐴 goes from the start state 𝑝0 to 𝑝i on
input 𝑥. Since 𝑝i is also 𝑝j, A goes from 𝑝i to the accepting state 𝑝𝐸 on input 𝑧. Thus
𝐴 accepts 𝑥𝑧.
Case 2: If 𝑘 > 0, then the automaton 𝐴 goes from 𝑝0 to 𝑝i on input 𝑥. Circles from 𝑝i to 𝑝i k
times on input 𝑦k, and then goes from 𝑝i to the accepting state 𝑝𝐹 on input 𝑧. Thus
𝐴 accepts 𝑥𝑦k𝑧.
Thus, for 𝑘 ≥ 0, 𝑥𝑦k𝑧 is accepted by a automaton 𝐴. That is, 𝑥𝑦k𝑧 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.
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
Luiw Є L where i≥1
L=uviw
L=b(bb)ib if i=2 => bbbbbb not belongs to L
If i=3 => bbbbbbbb not belongs to L

EXAMPLE2: show that the language L={0n1n+1 /n>0} is not regular


Solution:
To prove L={0n1n+1 /n>0} is not regular
Let n=1 L=0112= 011
Let n=2 L=0213=00111
Let n=3 L=0314=0001111
Length of the string =n+n+1
=2n+1
Then according to pumping lemma
L=011
U=0 v=1 w=1
uviw=01i1
=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
uviw= o(00)i0
=0000(if n=1)
0(00)i0 Є 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 (R 1) 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, Σ, δ, q 0, 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 M 1 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 M 1 and M2 both. It is clear
that there exists some DFA which accepts L 1 ∩ 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, Σ, δ, q 0, 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
R R R
W is denoted as reversal of string w. That means L(w ) = (L(w)) . 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 L 1 =L(R1*). Thus for a closure
operation a language can be expressed as a language of regular expressions. Hence L 1 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 L 1 =L(R1) and L2 =L(R2), Then
L1.L2 =L(R1· R2) thus we get a regular language. Hence it is proved that regular languages are
closed under concatenation.

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

You might also like