Download as pdf or txt
Download as pdf or txt
You are on page 1of 129

lOMoARcPSD|5597675

Toc notes

Computer Science (Anna University)

StuDocu is not sponsored or endorsed by any college or university


Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)
lOMoARcPSD|5597675

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS8501 - THEORY OF COMPUTATION

(FOR III YEAR V SEM STUDENTS)

UNIT I to V

PREPARED BY

S.RADHA

AP/CSE

ACADEMIC CO-ORDINATOR HOD DEAN – ACADEMICS PRINCIPAL

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SENGUNTHAR ENGINEERING COLLEGE, TIRUCHENGODE

LECTURE PLAN

Subject Name : THEORY OF COMPUTATION

Subject Code : CS8501

Name of Faculty/Designation : S.RADHA/AP

Course : V SEMESTER B.E CSE

Academic year : 2019-2020[ODD]

RECOMMENDED TEXT BOOKS/REFERENCE BOOKS

S.NO TITLE OF THE BOOK AUTHOR REFERENCE

1 Theory and Computation A.A.Puntambekar T1

Introduction to Automata John E. Hopcroft,


2 Theory, Languages and Rajeev Motwani, R1
Computation Jeffrey D. Ullman
Introduction to Languages
3 John C Martin R2
and the Theory of
Computation

NO. OF TEACHING
TOPIC REFERENCE
HOURS AIDS

UNIT I - FINITE AUTOMATA


T1- Ch1.1 to 1.3,
Introduction to Formal proof 1 BB
R1-Ch1,R2-Ch1
T1- Ch1.1 to 1.3,
Additional Forms of Proof 1 BB
R1-Ch1,R2-Ch1
Inductive Proof T1- Ch1.4,R2-Ch1 1 BB
T1- Ch1.1 to 1.3,
Introduction to Finite Automata 1 BB
R1-Ch1,R2-Ch1
Basic Mathematical Notations and
T1- Ch1.4,R2-Ch1 1 BB
Techniques
Finite State Systems T1-Ch1.6, R2-Ch1 1 BB
T1-Ch1.6 to 1.10,
Finite Automaton, DFA& NDFA 2 BB
R1-Ch2

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Finite Automaton with €- moves T1-Ch1.11, R1-Ch2 2 BB


UNIT II - REGULAR EXPRESSIONS AND LANGUAGES
Regular Languages- Regular
T1-Ch2.1, R1-Ch3 1 BB
Expression
Equivalence of NFA and DFA -
Equivalence of NDFA’s with and T1-Ch2.2, R1-Ch3 2 BB
without €-moves
Equivalence of finite Automaton and
T1-Ch2.7, R1-Ch3.2 2 BB
regular expressions
Minimization of DFA T1-Ch2.6,R2-Ch4.4 2 BB
Pumping Lemma for Regular sets T1-Ch2.11,R2-Ch5 1 BB
Problems based on Pumping Lemma. T1-Ch2.12,R2-Ch5 1 BB

UNIT –III CONTEXT FREE GRAMMAR AND LANGUAGES


Grammar Introduction T1- Ch3.1, R1-Ch5 1 BB
Types of Grammar - Context Free T1- Ch3.1and 3.2,
2 BB
Grammars and Languages R1-Ch5
Ambiguity- Relationship between T1-Ch3.5 , 3.6,R1-
1 BB
derivation and derivation trees Ch5.4
Definition of Pushdown automata-
T1- Ch4.1,4.3,R1-Ch6 2 BB
Languages of a Pushdown Automata
T1- Ch4.2,R1-Ch6.1.4,
Moves - Instantaneous descriptions 2 BB
R2-Ch8
T1- Ch4.5,
Deterministic pushdown automata 1 BB
R1-Ch6.4
Equivalence of Pushdown automata
T1- Ch4.6,R1-Ch6.3 2 BB
and CFL
UNIT IV - PROPERTIES OF CONTEXT FREE LANGUAGES
Simplification of CFG T1- Ch3.7.1,R1-Ch7 1 BB

Greibach Normal form T1-Ch3.8.2,R2-Ch8 1 BB

T1-Ch3.8.1,R1-
Chomsky normal form 1 BB
Ch7.1.5
pumping lemma for CFL T1- Ch4.7,R1-Ch7.2 2 BB

problems based on pumping Lemma T1- Ch4.7,R1-Ch7.2 1 BB

Definitions of Turing machines T1- Ch5.1,R2-Ch10 1 BB


Techniques for Turing machine T1- Ch5.3,
1 BB
construction R1-Ch8.3
Revision 1 BB
UNIT –V UNDECIDABILITY
Unsolvable Problems and
T1- Ch6.1 2 BB
Computable Functions
Recursive and recursively T1- Ch6.3,R1-
1 PPT
enumerable languages 9.2.2,Web resource

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Undecidable problems with Turing T1- Ch6.4,R1-9.2.3 1 BB


Machine
T1- Ch6.6,R1-
Tractable and Intractable problems 2 BB
Ch10.1,Web resource
Tractable and possibly intractable T1- Ch6.6,R1-
1 PPT
problems Ch10.1,Web resource
T1- Ch6.7,R1-
P and NP completeness 2 BB
Ch10.2,Web resource
T1- Ch6.8,R1-
Post Correspondence Problem Ch10.1.5,Web 2 BB
resource
Revision 1 BB
Total 49
Revision 2
Total 51

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

CS8501 THEORY OF COMPUTATION LTPC


3003
OBJECTIVES:
 To understand the language hierarchy
 To construct automata for any given pattern and find its equivalent regular
expressions
 To design a context free grammar for any given language
 To understand Turing machines and their capability
 To understand undecidable problems and NP class problems

UNIT I AUTOMATA FUNDAMENTALS 9


Introduction to formal proof – Additional forms of Proof – Inductive Proofs –Finite Automata –
Deterministic Finite Automata – Non-deterministic Finite Automata – Finite Automata with
Epsilon Transitions
UNIT II REGULAR EXPRESSIONS AND LANGUAGES 9
Regular Expressions – FA and Regular Expressions – Proving Languages not to be regular –
Closure Properties of Regular Languages – Equivalence and Minimization of Automata.
UNIT III CONTEXT FREE GRAMMAR AND LANGUAGES 9
CFG – Parse Trees – Ambiguity in Grammars and Languages – Definition of the Pushdown
Automata – Languages of a Pushdown Automata – Equivalence of Pushdown Automata and
CFG, Deterministic Pushdown Automata.
UNIT IV PROPERTIES OF CONTEXT FREE LANGUAGES 9
Normal Forms for CFG – Pumping Lemma for CFL – Closure Properties of CFL – Turing
Machines – Programming Techniques for TM.
UNIT V UNDECIDABILITY 9
Non Recursive Enumerable (RE) Language – Undecidable Problem with RE – Undecidable
Problems about TM – Post‘s Correspondence Problem, The Class P and NP.
TOTAL :45 PERIODS
OUTCOMES:
Upon completion of the course, the students will be able to:
 Construct automata, regular expression for any pattern.
 Write Context free grammar for any construct.
 Design Turing machines for any language.
 Propose computation solutions using Turing machines.
 Derive whether a problem is decidable or not.

TEXT BOOK:
1. J.E.Hopcroft, R.Motwani and J.D Ullman, ―Introduction to Automata Theory, Languages
and Computations‖, Second Edition, Pearson Education, 2003.

REFERENCES:
1. H.R.Lewis and C.H.Papadimitriou, ―Elements of the theory of Computation‖, Second
Edition, PHI, 2003.
2. J.Martin, ―Introduction to Languages and the Theory of Computation‖, Third Edition, TMH,
2003.
3. Micheal Sipser, ―Introduction of the Theory and Computation‖, Thomson Brokecole, 1997.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

UNIT-I
FINITE AUTOMATA

1.1 INTRODUCTION TO COMPUTATION


 Computation is a general term for any type of information processing.
 It is a process following a well defined model that is understood and can be
expressed in an algorithm, protocol network topology etc.,
 It is also a major subject matter of computer science, it investigates what can
or cannot be done in a computational manner.
1.1.1 Classes of Computation
Computation can be classified as follows:
 Digital Vs Analog
 Sequential Vs Parallel Vs Concurrent
 Batch Vs interactive
 Computation as Physical Phenomenon:
A computation can be seen as a purely physical phenomenon occurring inside a closed
“physical system” called a computer. Examples of such physical system includes
 Digital Computers
 Quantum Computers
 DNA Computers
 Molecular Computers
 Analog Computers
1.1.2 Mathematical model of Computation
In the theory of Computation, a diversity of mathematical models of computers has
been developed. Typical mathematical models of computers are the following:
1. State models including
a. Turing Machine
b. Pushdown automata
c. Finite Automaton
2. Functional models including

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

a. Lambda calculus
3. Logical models including
a. Logic programming
4. Concurrent models including
a. Actor model
1.1.3 Definition of Automata
An open-ended computer science discipline that concerns an abstract device
called an automaton, which performs a specific and recognition function. A formal
system that represents a machine that acts according to given specification.
1.1.4 Alphabets, Strings, and Languages
1.1.4.1 Alphabets
An alphabet is a finite, non-empty set of symbols. It is denoted by ∑.
Example:
i. ∑ = {a, b}, an alphabet of 2 symbols a and b.
ii. ∑ = {0, 1, 2}, an alphabet of 3 symbols 0,1 and 2.
1.1.4.2 Strings
A string or word over an alphabet ∑ is a finite sequence of symbols
from ∑.
Example:
i If ∑ = {a, b}, then abab, aabba, aaabba are all strings over the alphabet
∑ = {a, b}.
ii If ∑ = {a}, then a, aa, aaa are all strings over the alphabet ∑ = {a}.
1.1.4.3 Languages
For any alphabet ∑, any aubset L of ∑* is a language, a set of strings from an alphabet
is called as a ‘Language’.
Example:
i. English: It is a Language over ∑ = {a, b, c, …, z}.
ii. Binary String: {0,1,01,10,0101,…} is a language over ∑ = {0, 1}.
iii. If ∑ = {a, b} is an alphabet then ∑* = { є, a, b, aa, ab, … } is a language.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.2 INTRODUCTION TO FORMAL PROOF DEFINITION


A proof of a statement is essentially just a convincing or justifying argument that the
statement is true. A proof not only convinces but explains why the statement is true and
also how it relates to other statements and how it fits into the overall theory.
There are two types of proofs:
1. Deductive proof
2. Inductive proof
1.2.1 Deductive Proof
A deductive proof consists of a sequence of statements whose truth leads us from
some initial statement called hypothesis or given statements to a conclusion statement.
The theorem that is proved when we go from a hypothesis H to a conclusion C is the
statement “if H then C”, we say that “C is deduced from H”.
Theorem 1:
If x≥4 then 2x ≥x2.
Proof:
Here Hypothesis H is x≥4
Conclusion C is 2x ≥x2
x≥4:
 Hypothesis has a parameter x and it is neither true nor false.
 The truth depends on the value of the parameter i.e) h is true for x=6 and false
for x=2.
2x ≥x2:
The conclusion C is 2x ≥x2. This statement also uses parameter x and is true
for certain values of x and not for others. Example:
 C is false for x=3 since 23=8 which is not as large as 3*2=9 (8 ≥ 9).
 C is true for x=4 since 24=4*2=16.
 For x=5. The statement is also true since 25=32 is at least as large as 5*2=25
(32 ≥ 25).
 Let us conclude the conclusion as 2x ≥x2 will be true whenever x≥4.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.2.2 Modus ponens


 The hypothesis of some theorem is a previous statement, then the
conclusion of that theorem is true, and can be written down as a statement of
our proof. This logical rule is called modus ponens.
 If we know that H is true, and we know “if H then C” is true, we may conclude
that C is true.
Proof:
The intuitive argument that tells the conclusion 2x ≥x2 is true for the hypothesis x ≥
4. If the hypothesis is true for x, that is, x is the sum of the squares of four integers,
then x must be at least 4.
Statement Justification
1. x=a2+b2+c2+d2 Given
2. a≥1,b≥1,c≥1,d≥1 Given
3. a2≥1,b2≥1,c2≥1,d2≥1 Follows statement 2
4. x ≥ 4 Follows statement 1 and 3
5. 2x ≥x2 Follows statement 4
Step 1:
Let a, b, c and d is the names of the four integers. One of the given statements of the
theorem says x is the sum of the squares of four integers.
Step 2:
This statement represents four distinct statements, one of the four integers involved.
Each values being squared must be at least 1.
Step 3:
We observe that if a number is at least 1 then its square also at least 1.
Step 4:
It uses the statements 1 and 3 using well known properties of arithmetic; we conclude
that x is at least 1+1+1+1 or 4.
Step 5:
In the final step, we use the statement 4. Theorem 1 is the justification for writing down
its conclusion since its hypothesis is a previous statement.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

For Example
Prove that root 2 is not a rational
The proof requires these facts about integers (which are the whole numbers, 0, 1, -1, 2, -
2, 3, -3, etc.).
1. For integers a, if a2 is even, then a is even. The definition of even is that c is
even if and only if there is some integer k such that c=2*k.
2. For integers a, if a 2 is odd, then a is odd. The definition of odd is that c is not
even; necessarily, this means that there is some integer k such that c=2*k+1.
3. If a number x is the ratio of two integers, then it is the ratio of two relatively
prime integers. That is, if x is a ratio of two integers, then there are some
integers a and b such that b is not 0, x=a/b, and the greatest common divisor
of a and b is 1 (1 and -1 both divide a and b, but no other integers do that).
Suppose that x is the square root of 2 and that x is also the ratio of two integers. Let a
and be b relatively prime integers such that b is not 0 and x=a/b. Then
2=x2=(a2)/(b2).
So, 2 * (b2)= a2.
Therefore, a2 is even (because it is twice another integer). By (1) above, a is even.
Thus a=2*k for some integer k, and hence 2 * (b2)= (2k)2
Therefore, 2 * (b2)= 4*(k2).
Divide by two, to discover that b2= 2*(k2).
Therefore b2 is even (because it is twice another integer). By (1) above, b is even.
Therefore, b=2*j for some integer k.
Therefore, a and b are not relatively prime, because each has 2 as a divisor and 2 is
bigger than 1 (their supposed greatest common divisor). This is a contradiction.
The contradiction means that something in our "Suppose that x is the square root of 2
and x is also the ratio of two integers" is false. So, if one part of this "and" sentence is
true, the other part must be false. In particular, if x is indeed the square root of 2, then x
is NOT the ratio of two integers. In mathematical terminology, x is irrational. "Ir" as a
prefix means "not". So x is NOT rational where rational means being the ratio of two
integers (with the denominator integer non-zero)

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.3 ADDITIONAL FORMS OF PROOF


 Proofs about sets
 Proofs by contradiction
 Proofs by counter example
 Proofs by Contrapositive

1.3.1 Proof by Contrapositive:


The contrapositive of a conditional statements is formed by negating both the
hypothesis and the conclusion and then interchanging the resulting negations.
Ex: p→q
Contrapositive is ‫ך‬q → ‫ך‬p
In other words, it does both the jobs inverse and converse.
Theorem:
Conditional: For any real numbers a, b, if ab=0 then either a=0 or b=0.
Contrapositive: For any real numbers a, b, if a is not 0 and b is not 0, then ab is not
0.
1.3.2 Proof by Contradiction
“H and not C implies falsehood”
 That is start by assuming both the hypothesis H and the negation of the
conclusion C
 Complete the proof by showing that something known to be false follows
logically from H to not C. This form of proof is called as proof by
contradiction.
Theorem:
To prove for any sets A, B, and C if A∩B = ϕ and C subset B and A∩C ≠ ϕ.
Therefore there exists x with x Є A∩C, then x Є A and x Є C.
 Since C subset B and x Є C, it follows that x Є B.
 Therefore x Є A∩B which contradicts the assumption that A∩B =ϕ
 Since the assumption that the conditional statement is
false leads to a contradiction, the statement is proved.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.3.3 Proof by Counter Example


In order to prove certain statement, we need to see all possible conditions in which
that statement remains rue. There are some situations n which the statement
cannot be true.
Theorem:
There is no such pair of integers such that a mod b = b mod a.
Proof:
Consider a=2 and b=3, then clearly 2 mod 3 ≠ 3 mod 2.
 Thus the given pairs is true for any pairs of integers but if a=b then
naturally a mod b = b mod a.
 Thus we need to change the statement slightly, we can say a mod b = b
mod a when a = b.
1.3.4 Proof about Sets
If E and F are two expressions representing sets, the statement E=F means that
the two sets represented are the same.
Example 1:
The commutative law of union says that we can take the union of two sets R and S
in either order.
 That is R∪S=S∪R
 In this case E is the expression R∪S and F is the expression S∪R.
 The commutative law of union says that E = F. Example 2: “if and only
if statement”
 An element x is in E if and only if x is in F.
 The form of any if and only if proof are as follows:
 Proof that “ if x is in E, then x is in F”
 Proof that if x is in F, then x is in E”
Theorem:
(Let us prove the distributive law of union over intersection) R∪(S∩T)=(R∪S) ∩
(R∪T)

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Proof:
The two set expressions involved are
E= R∪(S∩T) and F=(R∪S) ∩ (R∪T)
In the ‘if’ part we assume element x is in E and show it is in F. Steps in ‘if part’ are
as follows:
Step Statement Justification
No.
1 x is in R∪(S∩T) Given
2 x is in R or x is in S∩T (1) and definition of union
3 x is in R or x is in S and T (2) and definition of intersection
4 x is in R∪S (3) and definition of union
5 x is in R∪T (3) and definition of union
6 x is in (R∪S) ∩ (R∪T) (4), (5) and definition of intersection
Steps in ‘only if part’ are as follows:
Step Statement Justification
No.
1 x is in (R∪S) ∩ (R∪T) Given
2 x is in R∪S (1) and definition of intersection.
3 x is in R∪T (1) and definition of intersection.
4 x is in R or x is in S and T (2), (3) and reasoning about
unions.
5 x is in R or x is in S∩T (4) and definition of intersection.
6 x is in R∪(S∩T) (5) and definition of union.

Since we have now proved both parts of the if-and-only-if statement, the
distributive law of union over intersection is proved.
1.4 INDUCTIVE PROOFS:
 There is a special form of proof called inductive ie) essential when
dealing with recursively defined objects.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Many of the most familiar inductive proofs deals with integers, but in
automata theory we also need inductive proofs about such recursively
defined concepts as trees and expression of various sorts such as
regular expressions.
1.4.1 Mathematical Induction
Mathematical induction is a way of establishing the correctness of formulas
involving an integer variable. It also applies to inequalities, algorithms and other
assertions involving an integer variable. Even more broadly it applies to algorithms
and assertions involving string variables. Let's see how it works first in the case of
a formula.
You have a formula that involves an integer variable n and you want to prove it
is true for all positive integers n. To do this you do the following two things.
(1) First you show it is true for n = 1
(2) Then you show that the truth of the formula for a particular value of n
implies the truth of the formula for n + 1
These two things imply that the formula is true for all positive integers n. The
idea is that starting with the truth for n = 1, you can apply (2) repeatedly to reach
any positive integer n.
Steps:
Step 1:
The basis where we show s(i) for a particular integer c. Usually i=0 or i=1.
Step 2:
The inductive step where we assume n ≥ i, where i is the basis
For Example
Prove, by Mathematical Induction, that
n 2n  17n  1
n  12  n  22  n  32  ...  2n 2 
6
is true for all natural numbers n.
Discussion
Some readers may find it difficult to write the L.H.S. in P(k + 1). Some cannot
factorize the L.H.S. and are forced to expand everything.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

For P(1),
1 3  8
4
L.H.S. = 22 = 4, R.H.S. = 6 .  P(1) is true.
Assume that P(k) is true for some natural number k, that is
k 2k  17k  1
k  12  k  22  k  32  ...  2k 2 
6
…. (1)
For P(k + 1) ,
k  22  k  32  ...  2k 2  2k  12  2k  22 There is a missing term in front
and two more terms at
the back.)
 k  2  k  3  ...  2k   2k  1  4k  1
2 2 2 2 2

 k  1  k  2  k  3  ...  2k   2k  1  3k  1


2 2 2 2 2 2

k 2k  17k  1
  2k  1  3k  1
2 2

6 , by (1)


2k  1 k 7k  1  62k  1  3k  12
6 (Combine the first two terms)


2k  1 7k 2  13k  6  3k  12
6


2k  1 7k  6k  1  3k  12
6


k  1 2k  17k  6  18k  1
6


k  1 14k 2  37k  24
6


k  1 2k  37k  8  k  12k  1  17k  1  1
6 6
 P(k + 1) is true.
By the Principle of Mathematical Induction, P(n) is true for all natural numbers, n.

10

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.5 FINITE AUTOMATA

An automaton is supposed to run on some given sequence of inputs in discrete


time steps. At each time step, an automaton gets one input that is picked up from a
set of symbols or letters, which is called an alphabet. At any time, the symbols so far
fed to the automaton as input form a finite sequence of symbols, which is called a
word.

An automaton contains a finite set of states. At each instance in time of some


run, the automaton is in one of its states. At each time step when the automaton
reads a symbol, it jumps or transits to a next state that is decided by a function that
takes current state and the symbol currently read as parameters. This function is
called transition function.
The automaton reads the symbols of the input word one after another and
transits from state to state according to the transition function, until the word is read
completely. Once the input word has been read, the automaton is said to have been
stopped and the state at which automaton has stopped is called final state.
Depending on the final state, it's said that the automaton either accepts or rejects an
input word. There is a subset of states of the automaton, which is defined as the set
of accepting states. If the final state is an accepting state, then the automaton
accepts the word. Otherwise, the word is rejected. The set of all the words accepted
by an automaton is called the language recognized by the automaton.
1.5.1 Formal definition
An automaton is represented formally by a 5-tuple (Q,Σ,δ,q0,F), where:
 Q is a finite set of states.
 Σ is a finite set of symbols, called the alphabet of the automaton.
 δ is the transition function, that is, δ: Q × Σ → Q.
 q0 is the start state, that is, the state of the automaton before any input
has been processed, where q0 Q.
 F is a set of states of Q (i.e. F  Q) called accept states.

11

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.5.1.1 Input word


An automaton reads a finite string of symbols a1,a2,...., an , where ai  Σ, which is
called an input word. The set of all words is denoted by Σ*.
Run
A sequence of states q0,q1,q2,...., qn, where qi  Q such that q0 is the start state
and qi = δ(qi-1,ai) for 0 < i ≤ n, is a run of the automaton on an input word w =
a1,a2,...., an  Σ*. In other words, at first the automaton is at the start state q 0, and
then the automaton reads symbols of the input word in sequence. When the
automaton reads symbol ai it jumps to state qi = δ(qi-1,ai). qn is said to be the final
state of the run.
Accepting word
A word w  Σ* is accepted by the automaton if qn  F.
Recognized language
An automaton can recognize a formal language. The language L  Σ* recognized
by an automaton is the set of all the words that are accepted by the automaton.
Recognizable languages
The recognizable languages are the set of languages that are recognized by some
automaton. For the above definition of automata the recognizable languages are
regular languages. For different definitions of automata, the recognizable
languages are different.
1.5.2 Model for Finite Automaton
Every automaton consists of some essential features as in real computers. It
has a mechanism for reading input. The input is assumed to be a sequence of
symbols over a given alphabet and is placed on an input tape(or written on an input
file). The simpler automata can only read the input one symbol at a time from left to
right but not change. Powerful versions can both read
 The automaton can produce output of some form. If the output in
response to an input string is binary (say, accept or reject), then it is
called an accepter. If it produces an output sequence in response to an
input sequence, then it is called a transducer(or automaton with output).

12

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 The automaton may have a temporary storage, consisting of an


unlimited number of cells, each capable of holding a symbol from an
alphabet (which may be different from the input alphabet). The
automaton can both read and change the contents of the storage cells in
the temporary storage. The accusing capability of this storage varies
depending on the type of the storage.
 The most important feature of the automaton is its control unit, which can
be in any one of a finite number of interval states at any point. It can
change state in some defined manner determined by a transition
function.

Figure 1.1: generic automation


Operation of the automation is defined as follows.
At any point of time the automaton is in some integral state and is reading a
particular symbol from the input tape by using the mechanism for reading input. In
the next time step the automaton then moves to some other integral (or remain in
the same state) as defined by the transition function. The transition function is
based on the current state, input symbol read, and the content of the temporary
storage. At the same time the content of the storage may be changed and the input
read may be modified.
The automation may also produce some output during this transition. The
internal state, input and the content of storage at any point defines the
configuration of the automaton at that point. The transition from one configuration

13

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

to the next ( as defined by the transition function) is called a move. Finite state
machine or Finite Automation is the simplest type of abstract machine we consider.
Any system that is at any point of time in one of a finite number of interval state
and moves among these states in a defined manner in response to some input,
can be modeled by a finite automaton.
1.5.3 Example of finite automaton
An Example Automaton: the 11011 Sequence Detector
We begin our formal discussion of finite automata with an example discussed in
the previous chapter. This example is the 11011 sequence detector, which we
now discuss using the terms and state diagrams of finite automata theory.
Here is the state diagram of the 11011 sequence detector drawn as a finite
automaton.

Figure1.2 : Finite Automaton for Detecting 11011 Sequence with no Overlap

The reader will note that the figure is quite different from that previously drawn
for the sequence detector. We comment on a few of the more important features of
this FA.
1. The states are labeled as q1, q2, q3, q4, q5, and q6. Theoreticians who work with
finite automata prefer to label the states with the lower-case “q”, beginning at 1
and running to the number of states.
2. The output of this automaton is not associated with the transitions, but with the
states. In this, the automaton more resembles the counters we discussed
earlier, than it does the sequence detector. We shall later note that some finite

14

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

automata models do have output associated with the transitions, but they are
not so common.
3. There are six states associated with the automaton, not the five as developed
earlier. This is a result of the output being associated with the states.
4. The state q6 has a double circle around it. This marks it as an accept state,
also called a final state. Finite automata may have any number of accept
states, including zero (for no accept states).
5. The FA has a start state, q1, that is indicated by having an arrow pointing at it
from nowhere. The FA starts here.
6. The FA takes a string, one character at a time, as input and outputs either
“accept” or “reject”. If the FA ends in an accept state at the end of
processing the string, the FA accepts the string; otherwise it rejects it. The term
“detector” seems not to be used when discussing finite automata.
7. There is no concept of a real clock, such as we used in our counters and
sequence detectors. These FA are mathematical models.
8. This finite automata is said to accept any string terminating in 11011, rather
than detecting the sequence 11011. We now call this an “11011 acceptor”.
1.5.4 Variant Definitions of Automata
Automata are defined to study useful machines under mathematical formalism.
So, the definition of an automaton is open to variations according to the "real world
machine", which we want to model using the automaton. People have studied
many variations of automata. The most standard variant, which is described above,
is called a deterministic finite automaton. The following are some popular variations
in the definition of different components of automata.
Input
 Finite input: An automaton that accepts only finite sequence of symbols. The
above introductory definition only encompasses finite words.
States
 Finite states: An automaton that contains only a finite number of states. The
above introductory definition describes automata with finite numbers of states.

15

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Stack memory: An automaton may also contain some extra memory in the form
of a stack in which symbols can be pushed and popped. This kind of automaton
is called a pushdown automaton
Transition function
 Deterministic: For a given current state and an input symbol, if an automaton
can only jump to one and only one state then it is a deterministic automaton.
 Nondeterministic: An automaton that, after reading an input symbol, may jump
into any of a number of states, as licensed by its transition relation. Notice that
the term transition function is replaced by transition relation: The automaton
non-deterministically decides to jump into one of the allowed choices. Such
automata are called nondeterministic automata.
Acceptance condition – for finite automaton
 Acceptance of finite words
- Automaton goes through the whole examined word and ends in some final
state.
1.6 NON DETERMINISTIC FINITE AUTOMATA

 An NFA has a finite set of states, a finite set of input symbols, one start state
and set of accepting states.
 The difference between the DFA and the NFA is in the type of δ
i) For the NFA, δ is a function that takes a state and an input symbol as
arguments, but returns a set of zero, one or more states.
δ (q,a) = {p,q}
Ex: δ (q0,a) = {q1,q2}
ii) For the DFA, δ is a function returns only one
state. δ (q,a) = {ps}
Ex: δ (q0,a) = {q1}

Example
Let a non-deterministic finite automaton be →

 Q = {a, b, c}
 ∑ = {0, 1}
 q0 = {a}

16

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 F = {c}
The transition function δ as shown below −
Present State Next State for Input 0 Next State for Input 1

a a, b b

b c a, c

c b, c c

Its graphical representation would be as follows −

1.6.1 DFA vs NDFA


The following table lists the differences between DFA and NDFA.

DFA NDFA

The transition from a state is to a The transition from a state can


single particular next state for each be to multiple next states for
input symbol. Hence it is each input symbol. Hence it is
called deterministic. called non-deterministic.

Empty string transitions are not seen NDFA permits empty string
in DFA. transitions.

Backtracking is allowed in DFA In NDFA, backtracking is not


always possible.

Requires more space. Requires less space.

A string is accepted by a DFA, if it A string is accepted by a NDFA,


transits to a final state. if at least one of all possible
transitions ends in a final state.

17

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.6.2 Theorem

Let X = (Qx, ∑, δx, q0, Fx) be an NDFA which accepts the language L(X). We have
to design an equivalent DFA Y = (Qy, ∑, δy, q0, Fy) such that L(Y) = L(X). The
following procedure converts the NDFA to its equivalent DFA −
Algorithm
Input − An NDFA
Output − An equivalent DFA
Step 1 − Create state table from the given NDFA.
Step 2 − Create a blank state table under possible input alphabets for the
equivalent DFA.
Step 3 − Mark the start state of the DFA by q0 (Same as the NDFA).
Step 4 − Find out the combination of States {Q0, Q1,... , Qn} for each possible input
alphabet.
Step 5 − Each time we generate a new DFA state under the input alphabet
columns, we have to apply step 4 again, otherwise go to step 6.
Step 6 − The states which contain any of the final states of the NDFA are the final
states of the equivalent DFA.
Example
Let us consider the NDFA shown in the figure below.

18

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

q δ(q,0) δ(q,1)

a {a,b,c,d,e} {d,e}

b {c} {e}

c ∅ {b}

d {e} ∅

e ∅ ∅

Using the above algorithm, we find its equivalent DFA. The state table of the DFA is
shown in below.
q δ(q,0) δ(q,1)

[a] [a,b,c,d,e] [d,e]

[a,b,c,d,e] [a,b,c,d,e] [b,d,e]

[d,e] [e] ∅

[b,d,e] [c,e] [e]

[e] ∅ ∅

[c, e] ∅ [b]

[b] [c] [e]

[c] ∅ [b]

The state diagram of the DFA is as follows −

19

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

1.7 FINITE AUTOMATA WITH EPSILON-TRANSITION


1.7.1 Introduction
The ε-transitions in NFA are given in order to move from one state to another
without having any symbol from input set ∑.
Example:
0 1 2
Start 0,ε 1,ε
q0 q1 q2

 In this NFA with ε, q0 is a start state with input 0; one can either be in state
q0 or in state q1.
 If we get at the start a symbol 1, then with ε-move we can change state from
q0 to q1 and then input we can be in state q1.
For example, the string w=002 is accepted by the NFA along the path q0, q0, q0,
q1, q2, q2 with labelled 0, 0, ε, ε, 2.
1.7.2 Definition (or) Formal notation for an ε-NFA
The language accepted by NFA with ε denoted by M = (Q, ∑, δ, q0, F) can be
defined as follows:
Let
M= (Q, ∑, δ, q0, F) be a NFA with ε where, Q is a finite set of states
∑ is input symbols
δ is a transition function for transition from Q X { ∑ ∪ ε } to 2Q q0 is a start state.
F is a set of final states such that F ⊆ Q. The string w is accepted by NFA can be
represented as
L(M) = {w | w ⊆ ∑* and δ transition for w from q0 reaches to F} Example:
Construct NFA with ε which accepts a language consisting the strings of any
number of a’s followed by any number of b’s followed by any number of c’s.
Solution:

20

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

a b c

Start ε ε
q0 q1 q2

Transition Table:
State input
a b c ε
q0 q0 φ φ q1
q1 φ q1 φ q2
*q2 φ φ q2 φ

1.7.3 Epsilon Closures(ε-closure)


 Informally, we ε-closure a state q by following all transitions out of q that are
labelled ε.
 When we get to other states by following ε we follow the ε-transitions out of
those states and so on.
 Finding every state that can be reached from q along any path whose arcs
are labelled ε.
Example:0 1 2
Start
Transition diagram ε ε
q0 q1 q2
Input
State
0 1 2 ε
q0 q0 φ φ q1
q1 φ q1 φ q2
*q2 φ φ q2 φ

 The ε-CLOSURE(q0) = { q0, q1, q2}. i.e) the path consisting of q0 along is a
path from q0 to q2 with all arcs labelled ε.
 The path from q0 to q1 labelled ε shows that q0 is in ε-CLOSURE(q0) and
path q0 , q1, q2 shows q2 is in ε-CLOSURE(q0).

21

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

ε-closure definition:
1. Let p be set of states.
2. Then ε-closure(p) = ∪𝑞∈𝑝 ε-closure(q)
3. δ' transition function is defined as
a. δ'(q,ε) = ε-CLOSURE(q)
b. for w in ∑*, and a in ∑
δ'(q,wa) = ε-CLOSURE(p), where p= {p | for some r in δ'(q,w), p in δ(r,a)}
c. δ(R,a) = ∪𝑞 𝑖𝑛 𝑅 δ(q,a)
d. δ’(R,w) = ∪𝑞 𝑖𝑛 𝑅 δ’(R,w)
4. he language accepted by NFA with ε-moves is defined as: L(M) = {w |
δ'(q0,w) contains a state in F}.
For Example

ε ε
2 3 6
ε

1
b
ε

4 5 7
a ε

ε-closure(1) = {1,2,4,3,6}={1,2,3,4,6}
ε-closure(2) = {2,3,6}
ε-closure(5) = {5,7}
Example:
1. Consider the NFA given below and find δ(q0,01).
0 1 2

Start ε ε
q0 q1 q2

Solution:
δ (q0, ε) = ε-closure(q0) = {q0,q1,q2} 1
Thus

22

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Then
δ (q0,0) = ε-closure(δ (δ (q0, ε),0))
= ε-closure(δ ({q0,q1,q2},0))
= ε-closure(δ (q0,0)∪ δ (q1,0) )∪ δ (q2,0)
= ε-closure({q0}∪{φ}∪{φ})
= ε-closure({q0})
= {q0, q1, q2} from the equation 1
δ (q0,01) = ε-closure(δ (δ (q0, 0),1))
= ε-closure(δ ({q0,q1,q2},1))
= ε-closure(δ (q0,1)∪ δ (q1,1) )∪ δ (q2,1)
= ε-closure({φ}∪{q1}∪{φ})
= ε-closure({q1})
= {q1, q2}
Since δ (q0,01) = {q1, q2} which contains final state {q2}, it is an accepting string.

1.8 CONVERSION AND EQUIVALENCE

NFA with ԑ NFA without ԑ DFA

1.8.1 Conversion from NFA with ε to without ε


1. Find out all the ε transitions from each state from Q. That will be called
as ε- closure({qi}).
2. Then δ' transitions can be obtained. The δ' transitions means ε-closure
on δ moves.
3. Step 2 is repeated for each input symbol and for each state of given
NFA.
4. Using the resultant states the transition table for equivalent NFA without
ε can be built.
1.8.2 Rules for conversion
δ '(q,a) = ε-closure(δ (δ '(q, ε),a)) where δ '(q, ε) = ε-closure(q)

23

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example 1:
Convert the following NFA with ε to without ε.
0 1 2

Start ε ε
q0 q1 q2

1. Finding out ε-transitions


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

2. δ ' transitions for each state on each input symbol

δ '(q0,0) = ε-closure(δ (δ '(q0, ε),0)

= ε-closure(δ (ε-closure(q0),0)

= ε-closure(δ ({q0, q1, q2}),0)

= ε-closure(δ (q0,0)∪ δ (q1,0) ∪ δ (q2,0))


= ε-closure(q0 ∪ φ ∪ φ)
= ε-closure(q0)
= {q0, q1, q2}
δ'(q0,1) = ε-closure(δ(δ'(q0, ε),1)
= ε-closure(δ(ε-closure(q0),1)
= ε-closure(δ({q0, q1, q2}),1)
= ε-closure(δ(q0,1)∪δ(q1,1) ∪δ(q2,1))
= ε-closure(φ ∪ q1 ∪ φ)
= ε-closure(q1)
= {q1, q2}
δ'(q0,2) = ε-closure(δ(δ'(q0, ε),2)
= ε-closure(δ(ε-closure(q0),2)

24

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

= ε-closure(δ({q0, q1, q2}),2)


= ε-closure(δ(q0,2)∪δ(q1,2) ∪δ(q2,2))
= ε-closure(φ ∪ φ ∪ q2)
= ε-closure(q2)
= {q2}
δ'(q1,0) = ε-closure(δ(δ'(q1, ε),0)
= ε-closure(δ(ε-closure(q1),0)
= ε-closure(δ({q1, q2}),0)
= ε-closure(δ(q1,0) ∪δ( q2,0))
= ε-closure(φ ∪ φ)
= ε-closure(φ)

δ'(q1,1) = ε-closure(δ(δ'(q1, ε),1)
= ε-closure(δ(ε-closure(q1),1)
= ε-closure(δ({q1, q2}),1)
= ε-closure(δ(q1,1) ∪δ( q2,1))
= ε-closure(q1 ∪ φ)
= ε-closure(q1)
= {q1,q2}
δ'(q1,2) = ε-closure(δ(δ'(q1, ε),2)
= ε-closure(δ(ε-closure(q1),2)
= ε-closure(δ({q1, q2}),2)
= ε-closure(δ(q1,2) ∪δ( q2,2))
= ε-closure(φ ∪q2)
= ε-closure(q2)
= {q2}
δ'(q2,0) = ε-closure(δ(δ'(q2, ε),0)
= ε-closure(δ(ε-closure(q2),0)
= ε-closure(δ(q2,0))
= ε-closure(φ)

25

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

δ'(q2,1) = ε-closure(δ(δ'(q2, ε),1)


= ε-closure(δ(ε-closure(q2),1)
= ε-closure(δ(q2,1))
= ε-closure(φ)

δ'(q2,2) = ε-closure(δ(δ'(q2, ε),2)
= ε-closure(δ(ε-closure(q2),2)
= ε-closure(δ(q2,2))
= ε-closure(q2)
= {q2}

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


δ'(q0,2)= φ δ'(q1,0)= {q1, q2}
δ'(q1,1)= {q1, q2} δ'(q1,2)= φ δ'(q2,0)=
{q2}
δ'(q2,1)= {q2} δ'(q2,2)= {q2}
Transition Table:
Input
State
0 1 2
Q0* {q0, q1,q2} {q1, q2} {q2}
Q1* φ {q1, q2} {q2}
Q2* φ φ {q2}

The equivalent NFA is


0 1
0,1
Q0 q1

0,1,2 1,2

Q2

26

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

QUESTION BANK

Part- A

1. Give two strings that are accepted and two strings that are rejected by the following
finite automata M=({q0,q1,q2},{0,1},q0,q1,) [May/June 2016]
2. List any four ways of theorem proving. (Nov’2007)
3. What are deductive proofs?[Nov/Dec 2014]
4. Define proof by contra positive.
5. Define Induction principle. (Apr’2008)
6. Define Alphabets.
7. Define string.
8. What is the need for finite automata?
9. What are finite automata? Give two examples. (May’2009.Apr’2008,May 2007)
10. Define DFA.[May/Jun 2013,Nov/Dec 2016]
11. Explain how DFA process strings.
12. Define transition diagram.[May/Jun 2015]
13. Define transition table.
14. Define the language of NFA. (Nov’2008)
15. Define є- transitions.[May/Jun 2013]
16. Define NFA.[Nov/Dec 2013,Apr/May 18]
17. Define є -NFA.
18. Define є- closure.

27

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Part-B & C
1. Construct DFA equivalent to the NFA given below: (10) [May2006,
Nov/Dec 2013,Nov 2016]

2. Construct an NFA for the following regular expression: (a+b)*


a+b[Apr/May 2010]
3. Construct an NFA without e - transitions for the following NFA. [NOV/DEC
2009]
4. Prove that root 2 is not a rational (8)[Nov/Dec 2011]
5. Find the regular expression corresponding to the following automata.
[Nov/Dec 2009]
6. For a given regular expression r, prove that there exists an NFA with
transitions that accepts L(r).
7. 7.Prove for every n>=1 by mathematical induction d∑ i3 ={n(n+1)/2}2 [May
2017]
8. Describe the Closure properties of Regular Languages.[Apr/May 2018]

28

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

UNIT-II

REGULAR EXPRESSIONS AND LANGUAGES


2.1 Definition

A method of representing language as expression is known as “regular expression”.


That is, the language accepted by finite state automata is easily described by simple
expressions.

2.1.1 The Operators of Regular Expressions

 Let ∑ be a finite set of symbols.


 Let L1,L2 be set of strings in ∑*
1. Union:

 The union of two languages L and M denoted L∪M is the set of


strings that are in either L or M or both.
 For example if L={001,10,111} and M = {ε,001} then L∪M = {ε,
10,001,111}
2. Concatenation:

 The concatenation of languages L and M is the set of strings that


can be formed by taking any string in L and concatenating it with
any string in M.
Example1:If L={001,10,111} and M={ε,001},then
L.M= {001,10,111,001001,10001,1110001}
Example 2:If L1={10,01} and L2 ={11,00},then
L1.L2 = {1011,1000,0111,0100}.
3. Closure:

 Kleenex Closure or Closure of L:Li


∞ =⋃
L* Li

𝑖=0

29

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Example: If L1={0,11} then L*= L0∪L1∪L2∪...


L0={ε} L1={0,11}

L2={00,011,110,1111}

L3={000,0110,1100,11110,1100,11011,11110,111111}
 Positive Closure of L
One or More Occurrences

2.1.2 Formal Definition


Let ∑ be an alphabet. The regular expressions over ∑ and the sets that they denote
are defined recursively as follows:
i. ϕ is a regular expression and denotes the empty set.
ii. ε is a regular expression and denotes the set {ε}.
iii. For each a ϵ ∑, ‘a’ is a regular expression and denotes the set {a}.
iv. If r and s are regular expressions denoting the language R and S respectively
then (r+s), (rs), (r)* are regular expressions that denotes the sets R∪S, RS and
R respectively.

Example 1:
Write a regular expression for the language accepting all combination of a’s over
the set ∑ = {a}.

Solution:

 All combinations of a’s means a may be single, double, triple and so on.
 There may be the case that ‘a’ is appearing for zero times, which means a null
string. So L={ε,a,aa,aaa,aaaa,...}.
R=a*
Example 2:
Design the regular expression for the language accepting all combinations of a’s
except the null string over ∑={a}.
Solution:
R=a+

30

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example 3:
Design the regular expression for the language containing all the strings containing
any number of a’s and b’s.
Solution:
R = (a+b)*
Example 4:
Construct the regular expression for the language accepting all the strings which
are ending with 00 over the set ∑={0,1}.
Solution:
R = (0+1)*00

Example 5:
Write the regular expression for the language accepting the string which are starting
with 1 and ending with 0 over the set ∑={0,1}.
Solution:

R = 1(0+1)*0

Example 6:

Describe in simple English the language represented by the following regular


expression r= (a+ab)*

Solution:

L(r) = {a,ab,aab,abab, ................. }

2.1.3 Identities for Regular Expressions

I1 : ϕ+R=R

I2 : ϕR =Rϕ = R

I3 : λR = Rλ =R

I4 : λ* = λ

I5 : R+R=R

31

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

I6 : R*R* = R*

I7 : RR* = R*R

I8 : (R*)* = R*

I9 : λ + RR* = R* = λ + R*R I10 : (PQ)*P = P(QP)*


I11 : (P+Q)* = (P*Q*)* = (P*+Q*)*

I12 : (P+Q)R = PR + QR and R(P+Q) = RP +RQ

2.2 FINITE AUTOMATA AND REGULAR EXPRESSIONS

Can be converted Regular


Expressions
Can be converted to

Deterministic
Finite
NFA with ε-moves
Automata

NFA without
ε- moves
Can be converted Can be converted

2.2.1 Equivalence of NFA and Regular Expressions


Theorem:
Let r be a regular expression, then there exists a NFA with ε transition that
accepts L(r).
Proof:
1. Basis : (Zero Operator)
 r has zero operators means, r can be either ε or ϕ or ‘a’ for some ‘a’ in
input set ∑.

32

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 If r= ε, then
Equivalence of NFA and Regular Expressions:
Theorem:

Let r be a regular expression, then there exists a NFA with ε transition that
accepts L(r).
Proof:
1. Basis : (Zero Operator)
 r has zero operators means, r can be either ε or ϕ or ‘a’ for some ‘a’ in
input set ∑.
 If r= ε, then

q0

 If r= ϕ, then

q0 q1

 If r = a, then

a
q0 q1

2. Induction
This theorem can be true for n number of operators. The regular expression contains
equal to or more than one operator. In any type of regular expression there are only three
cases possible.
 Union
 Concatenation
 Closure
 Star
 Positive

33

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Case 1: Union Case


 Let r = r1+r2 where r1, r2 be the regular expressions.
 There exists two NFA’s
M1= (Q1,∑1,δ1,q0,{F1})

M1= (Q2,∑2,δ2,q0,{F2})

 L(M1) = L(r1) means the language states by regular expression r1 is same


which is represented by M1. Similarly L(M2) =L(r2)
 Q1 represents the set of all the states in Machine M1.
 Q2 represents the set of all the states in Machine M2.
 We assure that Q1 and Q2 are totally different, that is Q1 and Q2 are disjoint.
 Let q0 be new initial state and f0 be the new final state, then we will have M =
((Q1∪ Q2∪{ q0, f0}),(∑1∪∑2), δ, q0,{ f0})

The δ is denoted by

 δ(q0,ε) = {Q1,Q2}

 δ(q0,a) = δ1(q,a) for q in Q1 – {f1} and a in ∑1 ∪ {ε}.

 δ(q,a) = δ2(q,a) for q in Q2 – {f2} and a in ∑2 ∪ {ε}.

 iv. δ(f,ε) = δ1(f2,ε) = {f0}.

q1 M1 f1
ε
ε
Start f0
q0

ε
ε
q2 M2 f2

34

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Case 2: Concatenation case

 Let r = r1r2 where r1 and r2 are two regular expressions.


 The M1 and M2 denotes the two machines such that L(M1) = L(r1) and
L(M2) = L(r2).
 The construction of machine M will be M = (Q1∪Q2,∑1∪∑2,δ1,{q1},{f2}).
 The mapping function δ will be given as
o δ(q,a) = δ1(q,a) for q in Q1-{f1} and Q in ∑1∪{ε}
o δ(f1,ε) = {q2}
o δ(q,a) = δ2(q,a) for q in Q2 and a in ∑1∪{ε}

Start ε
q1 M1 f1 q2 M2 f2

 The initial state q1 by some input a, the next state will be f1.
 And on receiving ε, the transitions will be from f1 to q2 and the final state will
be f2.
 The transition from q2 to f2 will be on receiving some input b.
 Thus L(M) = ab
i.e) a is in L(M1), b is in L(M2).
Hence we prove L(M) = L(M1) . L(M2).
Case 3: Closure Case
 Let r= r1*, where r1 be a regular expression.
 The machine M1 is such that L(M1) = L(r1).
 Then construct M = (Q1∪{q0,f0},∑1,δ,q0,f0).
 The mapping function δ is given by
i. δ(q0,ε) = δ(f1,ε) = {q1,f0}
ii. δ(q,a) = δ1(q,a) for q in Q1-{f1} and a is in ∑∪{ε}.

35

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 The machine M will be

Start ε ε
q0 q1 M1 f1 f0

 The machine M1 shows that from q0 to q1, there is a transition on receiving ε.


 Similarly from q0 to f0 on ε, there is a path.
 The path exists from f1 to q1 a back path.
 Similarly a transition from f1 to f0 final state on receiving ε.
 Thus one can derive ε,a,aa,aaa,... for the input a.
Thus L(M) = L(M1)* is proved
2.2.2 Construction of NFA from Regular expression
Example 1:
Construct a NFA for the regular expression 01.
Example 2:

Construct a NFA for the regular expression a*

ε
Start
q0 q1 q2 q3
ε a ε

ε
Example 3:

Construct a NFA for the regular expression a+.

Start 0 1
q0 q1 q2
Star
q0 q1 q2 q3
t ε a ε

36

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example 4:

Construct a NFA for the regular expression ba+.

ε
Star
q0 ε b
q3 q4 q5
ε a ε
Example 5:

Construct a NFA for the regular expression ba*.

Star b ε ε
q q q q q
a

ε
Example 6:

Construct a NFA for the regular expression b+ba*.

b ε
q1
ε
ε
Star ε ε q9
t q0 q5 q7 q8
a

ε ε ε
q3

Example 7:

Construct a NFA for the regular expression (0+1)*.

0
q2 q3 ε
ε
Start ε ε
q0 q1 q6 q
ε ε
1
q4 q5

ε 37

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

2.3 CONVERSION OF Ε-NFA INTO DFA

Steps:

Step 1:

Find the ε-closure of the state q0 from the constructed ε-NFA that is, from state
q0, ε-transition to other states is identified as well as ε-transitions from other states
are identified and combined as one set (new state).

Step 2:

Perform the following steps until there are no more new state has been
constructed.

i. Find the transition of the given regular expression symbols over ∑ from
the new state, that is move(new state, symbol)
ii. Find the ε-closure of move(new state, symbol)

Example:
Construct the DFA for the regular expression (a/b)*ab.

Solution:

a
ε
ε 3 4
Star ε ε a b
t 1 2 7 8 9

ε
5 6
ε b

38

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

ε -closure (1) -------- = {1, 2, 3, 5, 8}  A

Move (A,a) = {4,9}

Move (A,b) = {6}

ε -closure ({4, 9}) -- = {4, 7, 8, 2, 3, 5, 9} = {2, 3, 4, 5, 7, 8, 9} B

Move (B,a) = {4,9}

Move (B,b)

ε -closure ({6}) = {6,10}

= --- {6,7,8,2,3,5} = {2,3,5,6,7,8}  C

Move (C,a) = {4,9}

Move(C,b) = {6}

ε -closure ({6, 10}) - = {6,7,8,2,3,5,10} = {2,3,5,6,7,8,10}  D

Move (D,a) = {4,9}

Move (D,b) = (6)


Transition Table:
State Input
a b
->A B C
B B D
C B C
*D B C

39

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Equivalent DFA is

Start a b
A B C

a
a

b
b
D

2.4 CONVERSION OF FINITE AUTOMATA TO REGULAR EXPRESSIONS:


Theorem:

The regular expression can also be represented by its equivalent Deterministic


Finite Automata.
Formula:

The formula for getting the language r k is given by the regular expression:
ij
rijk = (rikk-1)( rkkk-1)*( rkjk-1)+( rijk-1)

2.4.1 Problems based on Finite Automata to Regular Expression Conversion:


Example 1:
Construct the regular expression for the automata given below:

Start 0
q0 q1

Solution:

rijk = (rikk-1)( rkkk-1)*( rkjk-1)+( rijk-1)

40

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

k=0

r (0) = ε
11

r (0) = 0
12

r (0) = ϕ
21

r (0) = ε
22

k=1

r11(1)=r11(0) r11(0)* r11(0)+ r11(0)

r12(1)=r11(0) r11(0)* r12(0)+ r12(0)

=0

R21(1)=r21(0) r11(0)* r12(0)+ r22(0)

R22(1)=r21(0) r11(0)* r12(0)+ r22(0)

 Now let us compute for final state which denotes the regular expression.

 R12(2) will be computed, because there are total 2 states and final state is q2,
whose start state is q1.

r21 (2) =(r12 (1)) (r22(1))*(r22 (1)) + (r12(1))

= 0. (ε)*. ε + 0

= 0+0

r21 (2) = 0 which is a final regular expression.

41

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example 2:

Solution:
We will find Rij(0) where K = 0
R11(0)=e because from state q1 to q1 can be achieved only by e transition.
R12(0)=0because from q1 we can reach q2 by ‘0’ input.

R13(0)=1 because from q1 we can reach q3 by ‘1’ input d(q1, 1) = q3


R21(0)=0 because d(q2, 0)=q1
R22(0)=e because from q2 we can reach q2 only on e transition R23(0)=1 because d(q2,
1)=q3
R31(0)=fbecause from q3 to reach q1 no such path exists
R32(0)=0+1 because from q3 to reach q2 we can give either ‘0’ or ‘1’ as input symbol.
R33(0)=eto remain in q3 it needs e transition.
Tabulation is as follows for K=0:

R
(0)
11 e
R
(0)
12 0
R
(0)
13 1
R
(0)
21 0
R
(0)
22 e
R 0
(0)
32 +1

42

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

R
(0)
33 e

We need to apply the following simplification.

• (e+R)* = R*

• R + RS* = RS*

• fR = Rf = f

• f + R = R + f = R (Identity)

n=3 (number of states is 3 {q1, q2, q3})

Rij(K)=Rij(K-1)+RiK(K-1)(RKK(K-1))*RKj(K-1)

Therefore for K=1

R11(1) = R11(0)+R11(0)(R11(0))* R11(0)

= e + e(e)*e

=e

R12(1) = R12(0)+R11(0)(R11(0))* R12(0)

= 0+e(e)*0

= 0+0 = 0

R13(1) = R13(0)+R11(0)(R11(0))* R13(0)

43

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

= 1+e(e)*1

= 1+1 = 1

R21(1) = R21(0)+R21(0)(R11(0))* R13(0)

= 0+0(e)*e
= 0+0 = 0

R22(1) = R22(0)+R21(0)(R11(0))* R12(0)

= e + 0(e)*0
R23(1) = R23(0)+R21(0)(R11(0))* R13(0)

= 1+0(e)*1

= 1+ 01

R31(1) = R31(0)+R31(0)(R11(0))* R11(0)

= f + f(e)*e

=f + f

=f

R32(1) = R32(0)+R31(0)(R11(0))* R12(0)

= 0+1 + f(e)*) =0 + 1 + f
= 0+1

R33(1) = R33(0)+R31(0)(R11(0))* R13(0)

44

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

= e + f(e)*1

=e

Therefore

R11(2) = R11(1)+R12(1)(R22(1))* R21(1) = e + 0(e + 00)*0


= e + 0(00)*0=(00)*
R12(2) = R12(1)+R12(1)(R22(1))* R22(1) = 0 + 0(e + 00)*(e+00) = 0+0(00)*=0(00*) (R+RS*=RS*)
R13(2) = R13(1)+R12(1)(R22(1))* R23(1) = 1 + 0(e + 00)*(1+01) Here (e+00)*=(00)*
and (1+01) = (e + 0)1
= 0* Hence 0(00)*(e+0)1=0(0*)1
R13(2)=1+00*1=0*1

R21(2) = R21(1)+R21(1)(R12(1))* R21(1)

= 0+(e+00)(e+00)*0

= 0+00(00)*0

= 0(00)*

R22(2) = R22(1)+R22(1)(R22(1))* R22(1)

= (e+00)+(e+00)(e+00)*(e+00)

= (00)*

R23(2) = R23(1)+R22(1)(R22(1))* R23(1)

= (1+01)+(e+00)(e+00)*(1+01)

45

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

= (e+0)1+(00)*(1+01)

= (e+0)1 + (00)*(e+0)1

= (e+0)1 + 0*1 (because (00)*(e+0)1=0*1)

= 0*1

R31(2) = R31(1)+R32(1)(R22(1))* R21(1)

= f+(0+1)(e+00)*0

= f + (0+1)(00)*0

=(0+1)(00)*0 (because (e+00)* = (00)*)

R32(2) = R32(1)+R32(1)(R22(1))* R22(1)

= (0+1) + (0+1)(e+00)*(e+00)

= (0+1) + (0+1)(00)*

= (0 + 1)(00)* (because R + RS* = RS*)

R33(2) = R33(1)+R32(1)(R22(1))* R23(1)

= e+(0+1)(e+00)*(1+01)
= e+(0+1)(00)*(e+0)1 (because (e+00)*=(00)* and (1+01)=((e+0)1))

=e+(0+1)0*1 (because (00)*(e+0)=0*) = e+(0+1)0*1

L(M)=R12(3) +R13(3) (where n=3 states)

46

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

R12(3) =R12(2) +R13(2) (R33(2) )*R32(2)


= 0(00) * +0 *1(ε + (0 +1)0 *1) *(0 +1)(00) *
= 0(00) * + 0 *1((0 +1)0 *1) *(0 +1)(00) *(because (ε+R)*=R*)
R13(3) =R13(2) +R13(2) (R33(2) )*R33(2)
= 0 *1+0 *1(ε + 0 +1)0 *1*(ε+(0 +1)0 *1) Similarly = 0 *1[ε +(ε + (0 +1)0 *1) *(ε + (0 +1)0
*1)] = 0 *1(ε +(0 +1)0 *1) *
(becauseε R*=R*)
=0*1((0+1)0*1)* (because ε+R)*=R*)
Hence regular expression is
R12(3) = R13(2) = 0 *1((0 +1)0*1)*(0 + 1)(00) *+0(00)*
+ 0 *1((0 +1)0*1)*
= 0 *1((0 +1)0*1) *(0 + 1)(00) *+0(00)*(because R + RS*= RS*)
The regular expression for the finite automata is
L(M)=0*1((0+1)0*1)(0+1)(00)*+0(00)*

2.5 ARDEN'S METHOD FOR CONVERTING DFA TO REGULAR EXPRESSION


R =Q + RP i.e) R = QP* Q+ RP = Q + (QP*)P
= Q (ɛ + P*P)
= QP*
=R
Algorithm
1. Let q1 be the initial state.
2. There are q2,q3,q4,...qn number of states. The final state may be some qj where
j≤n.
3. Let αji represents transition from qj to qi.
4. Calculate qi such that qi = αjiqi
If qi is a start state qi = αjiqj + ɛ.

5. Similarly compute the final state which ultimately gives the regular expression.
Example 1:
Construct regular expression from the given DFA.

47

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

0 1
Start 1
q1 q2

1
0
0
q3

Solution:
q1 = q10 + q30 + ɛ ------------------ ①

q2 = q21 + q11 + q31 ----------------------- ②

q3 = q20 ------------------------------ ③

substitute ③ to ②

q2 = q21 +q11 + q201

q2 = q2(1+01) + q11
∴ Q + RP = QP*
R P Q

q2 = q11 (1+01)* --------------------------- ④

substitute ④ to ①
q1 = q10 + q200 + ɛ

= q10 + q11 (1+01)*00 + ɛ


q1 = q1 [ 0 + 1 (1 + 01)*00] + ɛ ∴ Q + RP = QP* R P
Q
= ɛ (0 + 1 ( 1 + 01)* 00)* ∴ ɛ . R = R q1 =
[0 + 1 (1 + 01 )* 00]*

48

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Final regular expression is


q1 = [ 0 + 1 ( 1 + 01 )* 00 ]*

Example 2:
b
a
Start b a
q1 q2 q3

Solution:
q1 = q1a + ɛ ---------------------------------------- > ①
q2 = q1b + q2b ------------------------------------- > ②

we can rewrite ① as

q1 = ɛ + q1a ∴ Q + RP = QP*
Q=ɛ
R = q1
P=a
q1 = ɛ a*
= a*

∴ ɛ.R = R

Substitute value of q1 in ②, we get

q2 = q1b + q2b
q2 = a*b + q2b

q2 = a*b + q2b R = Q + RP →QP*

49

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

a*bb* a*b+

∴ b.b* = b+

Final regular expression is a*b+

2.6 PROVING LANGUAGES NOT TO BE REGULAR

2.6.1 Pumping Lemma for Regular Languages


For any regular language L, there exists an integer n, such that for all x ∈ L with |x| ≥ n, there
exists u, v, w ∈ Σ∗, such that x = uvw, and
(1) |uv| ≤ n
(2) |v| ≥ 1
(3) for all i ≥ 0: uviw ∈ L
In simple terms, this means that if a string v is ‘pumped’, i.e., if v is inserted any
number of times, the resultant string still remains in L.
Pumping Lemma is used as a proof for irregularity of a language. Thus, if a language is
regular, it always satisfies pumping lemma. If there exists at least one string made from
pumping which is not in L, then L is surely not regular.
The opposite of this may not always be true. That is, if Pumping Lemma holds, it does not
mean that the language is regular.

For example, let us prove L01 = {0n1n | n ≥ 0} is irregular.


Let us assume that L is regular, then by Pumping Lemma the above given rules follow.
Now, let x ∈ L and |x| ≥ n. So, by Pumping Lemma, there exists u, v, w such that (1) – (3)
hold.

We show that for all u, v, w, (1) – (3) does not hold.


If (1) and (2) hold then x = 0n1n = uvw with |uv| ≤ n and |v| ≥ 1.
So, u = 0a, v = 0b, w = 0c1n where : a + b ≤ n, b ≥ 1, c ≥ 0, a + b + c = n

50

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

But, then (3) fails for i = 0


uv0w = uw = 0a0c1n = 0a + c1n ∉ L, since a + c ≠ n.

Example: anbn is not Regular


N is the number from the pumping lemma (add one, if odd).
Choose w to be be aN/2bN/2. (Since this is what it takes to be “long enough”.)
1 2
aaaaaaaaaabbbbbbbbbb
x y z
We show that there is no x, y, z with the required properties:
|xy|  N,
y  ,
 q  0, xyqz is in L.
Three cases to consider:
 y falls in region 1:
 y falls across regions 1 and 2:
 y falls in region 2:
Example: anbn is not Regular
Second try (choose w to make your proof easier):
Choose w to be be aNbN. (Since we get to choose any w in L.)
1 2
aaaaaaaaaabbbbbbbbbb
x y z

We show that there is no x, y, z with the required properties:


|xy|  N,
y  ,
 q  0, xyqz is in L.
Since |xy|  N, y must be in region 1. So y = ag for some g  1.

51

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Pumping (any q but 1) will violate the equality constraint.


2.6.2 A Complete Proof using the Pumping Lemma
Proof that L = {anbn} is not regular:
Suppose L is regular. Since L is regular, we can apply the pumping lemma to L. Let N be
the number from the pumping lemma for L.
Choose w = aNbN.
Note that w  L and |w|  N.
From the pumping lemma, there exists some x, y, z where xyz = w and |xy|  N, y  , and
 q  0, xyqz L.
Because |xy|  N, y = a|y| (y is all a’s). We choose q = 2 and xyqz = aN+|y|bN. Because |y| >
0, then xy2z  L (the string has more a’s than b’s).
Thus for all possible x, y, z: xyz = w, q, xyqz  L.
Contradiction.  L is not regular.
You get to choose w. Make it a single string that depends only on N. Choose w so that it
makes your proof easier.
You may end up with various cases with different q values that reach a contradiction. You
have to show that all possible cases lead to a contradiction.
Proof of the Pumping Lemma
Since L is regular it is accepted by some DFSA, M.
Let N be the number of states in M.
Let w be a string in L of length N or more.
N
aaaaaaaaaabbbbbbbbbb
x y
Then, in the first N steps of the computation of M on w, M must visit N+1 states. But there
are only N different states. Thus it must have looped at least once. We'll call the portion
of w that corresponds to the loop y. But if it can loop once, it can loop an infinite number
of times. Thus:
 M can recognize xyqz for all values of q  0.
 y   (since there was a loop of length at least one)
 |xy|  N (since we found y within the first N steps of the computation)

52

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Another Pumping Example


L = {w=aJbK : K > J} (more b's than a's)
Choose w = aNbN+1
N
aaaaaaaaaabbbbbbbbbbb
x y z

We are guaranteed to pump only a's, since |xy|  N.


So there exists a number of copies of y that will cause there to be more a's than b's, thus
violating the claim that the pumped string is in L.

2.7 CLOSURE PROPERTIES OF REGULAR LANGUAGES


2.7.1 Properties of Regular Sets
Property 1. The union of two regular set is regular.
Proof
Let us take two regular expressions
RE1 = a(aa)* and RE2 = (aa)*
So, L1 = {a, aaa, aaaaa,.....} (Strings of odd length excluding Null)
and L2 ={ ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∪ L2 = { ε, a, aa, aaa, aaaa, aaaaa, aaaaaa,.......}
(Strings of all possible lengths including Null)
RE (L1 ∪ L2) = a* (which is a regular expression itself)
Hence, proved.

Property 2. The intersection of two regular set is regular.


Proof
Let us take two regular expressions
RE1 = a(a*) and RE2 = (aa)*
So, L1 = { a,aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 ∩ L2 = { aa, aaaa, aaaaaa,.......} (Strings of even length excluding Null)
RE (L1 ∩ L2) = aa(aa)* which is a regular expression itself.
Hence, proved.
53

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Property 3. The complement of a regular set is regular.


Proof
Let us take a regular expression
RE = (aa)*
So, L = {ε, aa, aaaa, aaaaaa, .......} (Strings of even length including Null)
Complement of L is all the strings that is not in L.
So, L’ = {a, aaa, aaaaa, .....} (Strings of odd length excluding Null)
RE (L’) = a(aa)* which is a regular expression itself.
Hence, proved.

Property 4. The difference of two regular set is regular.


Proof
Let us take two regular expressions −
RE1 = a (a*) and RE2 = (aa)*
So, L1 = {a, aa, aaa, aaaa, ....} (Strings of all possible lengths excluding Null)
L2 = { ε, aa, aaaa, aaaaaa,.......} (Strings of even length including Null)
L1 – L2 = {a, aaa, aaaaa, aaaaaaa, ....}
(Strings of all odd lengths excluding Null)
RE (L1 – L2) = a (aa)* which is a regular expression.
Hence, proved.

Property 5. The reversal of a regular set is regular.


Proof
We have to prove LR is also regular if L is a regular set.
Let, L = {01, 10, 11, 10}
RE (L) = 01 + 10 + 11 + 10
LR = {10, 01, 11, 01}
RE (LR) = 01 + 10 + 11 + 10 which is regular
Hence, proved.

54

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Property 6. The closure of a regular set is regular.


Proof
If L = {a, aaa, aaaaa, .......} (Strings of odd length excluding Null)
i.e., RE (L) = a (aa)*
L* = {a, aa, aaa, aaaa , aaaaa,……………} (Strings of all lengths excluding Null)
RE (L*) = a (a)*
Hence, proved.

Property 7. The concatenation of two regular sets is regular.


Proof
Let RE1 = (0+1)*0 and RE2 = 01(0+1)*
Here, L1 = {0, 00, 10, 000, 010, ......} (Set of strings ending in 0)
and L2 = {01, 010,011,.....} (Set of strings beginning with 01)
Then, L1 L2 = {001,0010,0011,0001,00010,00011,1001,10010,.............}
Set of strings containing 001 as a substring which can be represented by an RE − (0 +
1)*001(0 + 1)*
Hence proved.

2.8 DFA MINIMIZATION USING EQUIVALENCE THEOREM


If X and Y are two states in a DFA, we can combine these two states into {X, Y} if they
are not distinguishable. Two states are distinguishable, if there is at least one string S,
such that one of δ (X, S) and δ (Y, S) is accepting and another is not accepting. Hence, a
DFA is minimal if and only if all the states are distinguishable.
Algorithm
Step 1 − All the states Q are divided in two partitions − final states and non-final states
and are denoted by P0. All the states in a partition are 0th equivalent. Take a counter k and
initialize it with 0.
Step 2 − Increment k by 1. For each partition in P k, divide the states in Pk into two
partitions if they are k-distinguishable. Two states within this partition X and Y are k-
distinguishable if there is an input S such that δ(X, S) and δ(Y, S) are (k-1)-
distinguishable.
Step 3 − If Pk ≠ Pk-1, repeat Step 2, otherwise go to Step 4.
Step 4 − Combine kth equivalent sets and make them the new states of the reduced DFA.

55

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example
Let us consider the following DFA −

q δ(q,0) δ(q,1)

a b c

b a d

c e f

d e f

*e e f

f f f
Let us apply the above algorithm to the above DFA −
 P0 = {(c,d,e), (a,b,f)}
 P1 = {(c,d,e), (a,b),(f)}
 P2 = {(c,d,e), (a,b),(f)}
Hence, P1 = P2.
There are three states in the reduced DFA. The reduced DFA is as follows −

56

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Q δ(q,0) δ(q,1)

(a, b) (a, b) (c,d,e)

*(c,d,e) (c,d,e) (f)

(f) (f) (f)

QUESTION BANK
Part- A
1. State whether regular languages are closed under intersection and
complementation.[May/June 16,Nov/Dec 17]
2. State the pumping lemma for regular languages.[May/June 2016]
3. What are the two ways representing automata.
4. What are the applications of finite automata?
5. What are the closure properties of regular languages?
6. Show whether a language L={0n12n |n>0} is regular or not using pumping lemma.[May
2017]
7. Draw the transition diagram for an identifier
8. . Construct an NFA for the following regular expression: (a+b)* a+b
9. Explain a finite automaton for the regular expression 0*1*.
10. Illustrate a regular expression for the set of all the strings
11. Compose the difference between the + closure and * closure
12. Illustrate a regular expression for the set of all strings of 0’s
13. Find out the language generated by the regular expression(0+1)*.
14. Tabulate the regular expression for the following
L1=set of strings 0 and 1 ending in 00

57

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

L2=set of all strings 0 and 1 beginning with 0 and ending with 1


15. Illustrate a regular expression for the set of all the strings have odd number of 1’s
16. Illustrate a regular expression for the set of all strings of 0’s and 1’s not containing 101 as
substring.
17. Find out the language generated by the regular expression(0+1)*.
18. Is it true the language accepted by any NFA is different from the regular language? Justify
your answer.

PART – B & C

1. Demonstrate how the set L= {abn/n>=1} is not a regular.


2. Express that the regular languages are closed under.
(a)union (b)intersection(c)Kleene Closure(d)Complement (e)Difference
3. Examine whether the language L=(0n1n| n>=1) is regular or not? Justify your answer.
4. Describe a Regular Expression. Write a Regular Expression for the set of strings that
consists of alternating 0’s and 1’s.
5. Construct Finite Automata equivalent to the regular expression (ab+a)*
6. Describe the closure properties of regular languages.
7. Describe NFA with epsilon for the RE=(a/b)*ab and convert it into DFA and further find
the minimized DFA.
8. Construct NDFA for given RE using Thomson rule.
i) a.(a+b)* ab
ii) (a.b)*
iii) (a+b)
9. Explain the DFA Minimization algorithm with an example.
10. Set the algorithm for minimization of a DFA. Develop a minimized DFA for the RE
(a+b)(a+b)* and trace for the string baaaab.

58

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

UNIT III

CONTEXT FREE GRAMMAR AND LANGUAGES

3.1 CFG

3.1.1 Introduction to Grammar


A context-free grammar (CFG) is a set of recursive rewriting rules (or productions)
used to generate patterns of strings. A CFG consists of the following components: a set
of terminal symbols, which are the characters of the alphabet that appear in the strings
generated by the grammar. Grammar is a set of rules used to define the language.
3.1.2 Types of grammar
 Type 0 – Recursive Grammar
 Type 1 – Context Sensitive Grammar
 Type 2 – Context free Grammar
 Type 3 – Regular Grammar

Type 0

Type 1

Type 2

Type 3

Type 0 Grammar:
 A phrase structure grammar with no restriction on the production is called as
type 0 grammar.
 A language that is generated by type 0grammars is called as the “type 0”
languages.
 The production in the type 0 grammar is of the form α→β in which there is no
restriction for the length of α and β.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Here α and β can contain either any number of terminals and non terminals.
For example,
 Aac → bBDE
 aBD → abcDE
Type 1 Grammar:
This grammar contains the restriction that the production of the α and β, the
length of the β is larger than or equal to the length of the α.
That is, α→β [|α| ≤ |β|]
 A language generated by the type 1 grammar is called as type 1 language and
it is “context sensitive grammar”.
 The production in the type 1 grammar is of the form α→β where
 α is the non terminal
 β is terminal followed by any number of non terminals.
Example:
S → aAB B → b
A → aBcb AB → bB
Type 2 Grammar:
A Context-Free Grammar (CFG) is one whose production rules are of the form:

where is any single non-terminal, and is any combination of terminals and non-
terminals. A NFA/DFA cannot recognize strings from this type of language since we must
be able to "remember" information somehow. Instead we use a Push-Down Automaton
which is like a DFA except that we are also allowed to use a stack.
Type 3 Grammar:
A regular language is one which can be represented by a regular grammar, described
using a regular expression, or accepted using an NFA or a DFA.
3.1.3 Formal Definition
A context-free grammar (CFG) consisting of a finite set of grammar rules is a
quadruple (N, T, P, S) where
 N is a set of non-terminal symbols.
 T is a set of terminals where N ∩ T = NULL.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 P is a set of rules, P: N → (N ∪ T)*, i.e., the left-hand sides of the production


rule P does have any right context or left context.
 S is the start symbol.
Example
 The grammar ({A}, {a, b, c}, P, A), P : A → aA, A → abc.
 The grammar ({S, a, b}, {a, b}, P, S), P: S → aSa, S → bSb, S → ε
 The grammar ({S, F}, {0, 1}, P, S), P: S → 00S | 11F, F → 00F | ε
3.2 PARSE TREE
A derivation tree or parse tree is an ordered rooted tree that graphically represents the
semantic information a string derived from a context-free grammar.
Representation Technique
 Root vertex − Must be labeled by the start symbol.
 Vertex − Labeled by a non-terminal symbol.
 Leaves − Labeled by a terminal symbol or ε.
If S → x1x2 …… xn is a production rule in a CFG, then the parse tree / derivation tree will
be as follows −

There are two different approaches to draw a derivation tree −


Top-down Approach
 Starts with the starting symbol S
 Goes down to tree leaves using productions
Bottom-up Approach
 Starts from tree leaves
 Proceeds upward to the root which is the starting symbol S

3.2.1 Derivation or Yield of a Tree

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

The derivation or the yield of a parse tree is the final string obtained by concatenating the
labels of the leaves of the tree from left to right, ignoring the Nulls. However, if all the
leaves are Null, derivation is Null.
Example
Let a CFG {N,T,P,S} be
N = {S}, T = {a, b}, Starting symbol = S, P = S → SS | aSb | ε
One derivation from the above CFG is “abaabb”
S → SS → aSbS → abS → abaSb → abaaSbb → abaabb

Sentential Form and Partial Derivation Tree


A partial derivation tree is a sub-tree of a derivation tree/parse tree such that either all of
its children are in the sub-tree or none of them are in the sub-tree.
Example
If in any CFG the productions are −
S → AB, A → aaA | ε, B → Bb| ε
the partial derivation tree can be the following −

If a partial derivation tree contains the root S, it is called a sentential form. The above
sub-tree is also in sentential form.

3.2.2 Leftmost and Rightmost Derivation of a String

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Leftmost derivation − A leftmost derivation is obtained by applying production to the


leftmost nonterminal in each step.
 Rightmost derivation − A rightmost derivation is obtained by applying production to the
rightmost non terminal in each step.
Example 1
Let any set of production rules in a CFG be
X → X+X | X*X |X| a
over an alphabet {a}.
The leftmost derivation for the string "a+a*a" may be −
X → X+X → a+X → a + X*X → a+a*X → a+a*a
The stepwise derivation of the above string is shown as below −

The rightmost derivation for the above string "a+a*a" may be −


X → X*X → X*a → X+X*a → X+a*a → a+a*a

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

The stepwise derivation of the above string is shown as below −

Example 2
Construct the parse tree for the string 00101 for the following CFG using both leftmost
and rightmost derivation. The CFG is
S → A1B
A → 0A | ε
B → 0B | 1B | ε

Solution:
Leftmost derivation Rightmost derivation

3.2.2 Left and Right Recursive Grammars


In a context-free grammar G, if there is a production in the form
XXa

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

where X is a non-terminal and ‘a’ is a string of terminals, it is called a left recursive


production. The grammar having a left recursive production is called a left recursive
grammar.
And if in a context-free grammar G, if there is a production is in the form
XaX
where X is a non-terminal and ‘a’ is a string of terminals, it is called a right recursive
production. The grammar having a right recursive production is called a right recursive
grammar.
3.3 AMBIGUITY IN GRAMMARS AND LANGUAGES
If a context free grammar G has more than one derivation tree for some string w ∈ L(G),
it is called an ambiguous grammar. There exist multiple right-most or left-most derivations
for some string generated from that grammar.
For example
1. Check whether the given grammar is ambiguous or not-
S → SS
S→a
S→b
Solution Let us consider a string w generated by the given grammar-
w = abba
Now, let us draw parse trees for this string w.

Since two different parse trees exist for string w, therefore the given grammar is
ambiguous.
2. Check whether the given grammar is ambiguous or not-
7

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S→A/B
A → aAb / ab
B → abB / ∈
Solution Let us consider a string w generated by the given grammar-
w = ab
Now, let us draw parse trees for this string w.

Since two different parse trees exist for string w, therefore the given grammar is
ambiguous.
3. Check whether the given grammar is ambiguous or not-
S → AB / C
A → aAb / ab
B → cBd / cd
C → aCd / aDd
D → bDc / bc
Solution Let us consider a string w generated by the given grammar- w = aabbccdd
Now, let us draw parse trees for this string w.

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Since two different parse trees exist for string w, therefore the given grammar is
ambiguous.
3.4 PUSHDOWN AUTOMATA
Pushdown automata differ from finite state machines in two ways:
1. They can use the top of the stack to decide which transition to take.
2. They can manipulate the stack as part of performing a transition.
A pushdown automaton is a way to implement a context-free grammar in a similar way we
design DFA for a regular grammar. A DFA can remember a finite amount of information,
but a PDA can remember an infinite amount of information.
Basically a pushdown automaton is −
"Finite state machine" + "a stack"
A pushdown automaton has three components −
 an input tape,
 a control unit, and
 a stack with infinite size.
The stack head scans the top symbol of the stack.

A stack does two operations −


 Push − a new symbol is added at the top.
 Pop − the top symbol is read and removed.
A PDA may or may not read an input symbol, but it has to read the top of the stack in
every transition.

Pushdown automata choose a transition by indexing a table by input signal, current


state, and the symbol at the top of the stack. This means that those three parameters
completely determine the transition path that is chosen. Finite state machines just look at

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

the input signal and the current state: they have no stack to work with. Pushdown
automata add the stack as a parameter for choice. Pushdown automata can also
manipulate the stack, as part of performing a transition.
Finite state machines choose a new state, the result of following the transition. The
manipulation can be to push a particular symbol to the top of the stack, or to pop off the
top of the stack. The automaton can alternatively ignore the stack, and leave it as it is.
The choice of manipulation (or no manipulation) is determined by the transition table. Put
together: Given an input signal, current state, and stack symbol, the automaton can follow
a transition to another state, and optionally manipulate (push or pop) the stack.
If we allow a finite automaton access to two stacks instead of just one, we obtain a more
powerful device, equivalent in power to a Turing machine. A linear bounded automaton is
a device which is more powerful than a pushdown automaton but less so than a Turing
machine.
Pushdown automata are equivalent to context-free grammars: for every context-free
grammar, there exists a pushdown automaton such that the language generated by the
grammar is identical with the language generated by the automaton, which is easy to
prove. The reverse is true, though harder to prove: for every pushdown automaton there
exists a context-free grammar such that the language generated by the automaton is
identical with the language generated by the grammar.
3.4.1 Formal Definition
A PDA can be formally described as a 7-tuple (Q, ∑, S, δ, q0, I, F) −
 Q is the finite number of states
 ∑ is input alphabet
 S is stack symbols
 δ is the transition function: Q × (∑ ∪ {ε}) × S × Q × S*
 q0 is the initial state (q0 ∈ Q)
 I is the initial stack top symbol (I ∈ S)
 F is a set of accepting states (F ∈ Q)
The following diagram shows a transition in a PDA from a state q1 to state q2, labeled as
a,b → c

10

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

This means at state q1, if we encounter an input string ‘a’ and top symbol of the stack
is ‘b’, then we pop ‘b’, push ‘c’ on top of the stack and move to state q2.
3.4.2 Terminologies Related to PDA
3.4.2.1 Instantaneous Description
The instantaneous description (ID) of a PDA is represented by a triplet (q, w, s) where
 q is the state
 w is unconsumed input
 s is the stack contents
Turnstile Notation
The "turnstile" notation is used for connecting pairs of ID's that represent one or many
moves of a PDA. The process of transition is denoted by the turnstile symbol "⊢".
Consider a PDA (Q, ∑, S, δ, q0, I, F). A transition can be mathematically represented by
the following turnstile notation −
(p, aw, Tβ) ⊢ (q, w, αb)
This implies that while taking a transition from state p to state q, the input symbol ‘a’ is
consumed, and the top of the stack ‘T’ is replaced by a new string ‘α’.
Note − If we want zero or more moves of a PDA, we have to use the symbol (⊢*) for it.
3.4.3 Problems on transition diagram of PDA
1. Suppose the PDA P = ({p, q},s {0,1}, {z0, x},δ, q,z0,{p}) has the following transition
functions:
a.  (q,0,z0) = {(q, x)}
b.  (q,0,x) = {(q, xx)}
c. (q,1,x) = {(q, x)}
d.  (q, , x) = {(p,)}
e.  (p, , x) = {(p,)}
f.  (p, 1, x) = {(p,xx)}
g.  (p, 1,z0) = {(p,)}

11

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Starting from the initial ID (q, w, z0), show all the reachable instantaneous description
where the input string ‘w’ is as follows:
(i). 01
(ii). 0011
(iii). 010
Solution:
(i) String w=01 ID = (q, w,z0)
(q, 01,z0)├ (q, 1, xz0)
├ (q, , x)
├ (p, )
Now final state p is reached. So the string w=01 is accepted.
(ii) W=0011
ID = (q, w,z0)
(q, 0011,z0)├ (q, 011, xz0)
├ (q, 11,xxz0)
├ (q, 1,xxz0)
├ (q, ,xxz0)
├ (p, ,xz0)
├ (p, )
So the string 0011 is accepted.
(iii) W=010
(q, 010,z0)├ (q, 10,xz0)
├ (q, 0,xz0)
├ (q, ,xxz0)
├ (p, xz0)
├ (p, )
So the string 010 is accepted.

12

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

2. Consider the following PDA and find whether the string 000111 and 00011 is accepted.

0,z0 / 0z0
0,0 /00
1, 0 /ε
Start 1, 0 /ε ε, z0 /ε
p q r

ε, z0 /ε

Solution:
Transition function:
 (p, 0, z0) = (p, 0z0)
 (p, 0, 0) = (p, 00)
 (p, 1, 0) = (q, )
 (p, ,z0) = (r, )
 (q, 1, 0) = (q, )
 (q, , z0) = (r, )

String w = 000111
(p, 000111, z0) ├(p, 00111, 0z0)
├(p, 0111, 00z0)
├(p,111, 000z0)
├(q, 11, 00z0)
├(q, 1, 0z0)
├(q, , z0)
├ (r,)
So the string 000111 is accepted.
String w = 00011
(p, 000111, z0)├(p, 00011, 0z0)
├(p, 0011, 00z0)
├(p,11, 000z0)
├(q, 1, 00z0)

13

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

There is no transition function δ


(q, , 0), so the string is not accepted.
3.5 LANGUAGES OF PDA
Here are two different ways to define PDA acceptability.
3.5.1 Final State Acceptability
In final state acceptability, a PDA accepts a string when, after reading the entire
string, the PDA is in a final state. From the starting state, we can make moves that end
up in a final state with any stack values. The stack values are irrelevant as long as we
end up in a final state.
For a PDA (Q, ∑, S, δ, q0, I, F), the language accepted by the set of final states F is −
L(PDA) = {w | (q0, w, I) ⊢* (q, ε, x), q ∈ F}
for any input stack string x.
3.5.2 Empty Stack Acceptability
Here a PDA accepts a string when, after reading the entire string, the PDA has
emptied its stack.
For a PDA (Q, ∑, S, δ, q0, I, F), the language accepted by the empty stack is −
L(PDA) = {w | (q0, w, I) ⊢* (q, ε, ε), q ∈ Q}

Example
Construct a PDA that accepts L = {0n 1n | n ≥ 0}
Solution

This language accepts L = {ε, 01, 0011, 000111, ............................. }


Here, in this example, the number of ‘a’ and ‘b’ have to be same.
 Initially we put a special symbol ‘$’ into the empty stack.
 Then at state q2, if we encounter input 0 and top is Null, we push 0 into stack. This
may iterate. And if we encounter input 1 and top is 0, we pop this 0.

14

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Then at state q3, if we encounter input 1 and top is 0, we pop this 0. This may also
iterate. And if we encounter input 1 and top is 0, we pop the top element.
 If the special symbol ‘$’ is encountered at top of the stack, it is popped out and it finally
goes to the accepting state q4.
Example
Construct a PDA that accepts L = { wwR | w = (a+b)* }
Solution

Initially we put a special symbol ‘$’ into the empty stack. At state q2, the w is being read.
In state q3, each 0 or 1 is popped when it matches the input. If any other input is given,
the PDA will go to a dead state. When we reach that special symbol ‘$’, we go to the
accepting state q4.
3.6 EQUIVALENCE OF PDA AND CFG
If a grammar G is context-free, we can build an equivalent nondeterministic PDA which
accepts the language that is produced by the context-free grammar G. A parser can be
built for the grammar G.
Also, if P is a pushdown automaton, an equivalent context-free grammar G can be
constructed where
L(G) = L(P)
3.6.1 Algorithm to find PDA corresponding to a given CFG
Input − A CFG, G = (V, T, P, S)
Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F)
Step 1 − Convert the productions of the CFG into GNF.
Step 2 − The PDA will have only one state {q}.
Step 3 − The start symbol of CFG will be the start symbol in the PDA.

15

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Step 4 − All non-terminals of the CFG will be the stack symbols of the PDA and all
the terminals of the CFG will be the input symbols of the PDA.
Step 5 − For each production in the form A → aX where a is terminal and A, X are
combination of terminal and non-terminals, make a transition δ (q, a, A).
Problem 1
Construct a PDA from the following CFG.
G = ({S, X}, {a, b}, P, S)
where the productions are −
S → XS | ε , A → aXb | Ab | ab
Solution
Let the equivalent PDA,
P = ({q}, {a, b}, {a, b, X, S}, δ, q, S)
where δ −
δ(q, ε , S) = {(q, XS), (q, ε )}
δ(q, ε , X) = {(q, aXb), (q, Xb), (q, ab)}
δ(q, a, a) = {(q, ε )}
δ(q, 1, 1) = {(q, ε )}
Problem 2
Given G = (V,Σ,R,S), what the PDA will do is effect a leftmost derivation of a string w ∈
L(G). The PDA is
M = ( {0,1}, Σ, V, Δ, 0, {1} )
Namely, there are only two states The PDA moves immediately to the final state
is 1 with the start symbol on the stack and then stays in this state.
These are the transitions in Δ:
1: ( (0,ε,ε), (1,S) )
2: ( (1,ε,A), (1,α) ) for A → α
3: ( (1,σ,σ), (1,ε) ) for σ ∈ Σ
This constructed PDA is inherently non-deterministic; if there is a choice of rules to
apply to a non-terminal, then there is a non-deterministic choice of processing steps.
Graphically the presentation is this:

16

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

To say that G and M are equivalent means that L(M) = L(G), or, considering an arbitrary
string w ∈ Σ*:
S ⇒* w ⇔ (0,w,ε) ⊢* (1,ε,ε)
Expression Grammar
The most informative examples are those in which there exist the possibility of not using
a leftmost derivation such as our expression grammar:
E→E+T|T
T→T*F|F
F→(E)|a
We can readily match up a leftmost derivation of a + a * a with the corresponding
machine configuration processing as follows:
(0, a + a * a, ε)
⊢ (1, a + a * a, E)
⊢ (1, a + a * a, E + T) E⇒E+T
⊢ (1, a + a * a, T + T) ⇒T+T
⊢ (1, a + a * a, F + T) ⇒F+T
⊢ (1, a + a * a, a + T) ⇒a+T
⊢ (1, + a * a, + T)
⊢ (1, a * a, T)
⊢ (1, a * a, T * F) ⇒a+T*F
⊢ (1, a * a, F * F) ⇒a+F*F
⊢ (1, a * a, a * F) ⇒a+a*F
⊢ (1, * a, * F)
⊢ (1, a, F)
⊢ (1, a, a) ⇒a+a*a
⊢ (1, ε, ε)
3.6.2 Algorithm to find CFG corresponding to a given PDA
Input − A CFG, G = (V, T, P, S)
17

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Output − Equivalent PDA, P = (Q, ∑, S, δ, q0, I, F) such that the non- terminals of the
grammar G will be {Xwx | w,x ∈ Q} and the start state will be Aq0,F.
Step 1 − For every w, x, y, z ∈ Q, m ∈ S and a, b ∈ ∑, if δ (w, a, ε) contains (y, m) and
(z, b, m) contains (x, ε), add the production rule Xwx → a Xyzb in grammar G.
Step 2 − For every w, x, y, z ∈ Q, add the production rule Xwx → XwyXyx in grammar G.
Step 3 − For w ∈ Q, add the production rule Xww → ε in grammar G.
Problem 1
The grammar for anbn
Use the grammar: S ⟶ ε | aSb
Here is the PDA:

A simple run is:


(0, aabb, ε)
⊢ (1, aabb, S)
⊢ (1, aabb, aSb)
⊢ (1, abb, Sb)
⊢ (1, abb, aSbb)
⊢ (1, bb, Sbb)
⊢ (1, bb, bb)
⊢ (1, b, b)
⊢ (1, ε, ε)
3.7 DETERMINISTIC PUSH DOWN AUTOMATA
ADPDA is a PDA in which no state p has two different outgoing transitions
((p,x,α),(q,β)) and ((p,x′,α′),(q′,β′))
which are compatible in the sense that both could be applied. A DCFL is basically a
language which accepted by a DPDA, but we need to qualify this further.
We want to argue that the language L = { w ∈ {a,b}* : #a(w) = #b(w)} is deterministic
context free in the sense there is DPDA which accepts it.In the above PDA, the only
non-determinism is the issue of guessing the end of input; however this form of non-
determinism is considered artificial. When one considers whether a language Lsupports

18

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

a DPDA or not, a dedicated end-of-input symbol is always added to strings in the


language.
Formally, a language L over Σ is deterministic context free, or L is a DCFL , if
L$ is accepted by a DPDA M
where $ is a dedicated symbol not belonging to Σ. The significance is that we can make
intelligent usage of the knowledge of the end of input to decide what to do about the
stack. In our case, we would simply replace the transition into the final state by:

With this change, our PDA is now a DPDA:

a*b* example
Two common variations on a's followed by b's. When they're equal, no stack bottom is
necessary. When they're unequal, you have to be prepared to recognize that the
stacked a's have been completely matched or not.

a. { anbn : n ≥ 0 }

b. { ambn : 0 ≤ m < n }
Let's look at a few sample runs of (b). The idea is that you cannot enter the final state
with an "a" still on the stack. Once you get to the final state, you can consume
remaining b's and end marker.

19

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

We can start from state 1 with the stack bottom pushed on:
success: abb
state input stack

1 abb$ c

1 bb$ ac

2 b$ ac

2 $ c

3 ε ε
(fail: ab)

state input stack

1 ab$ c

1 b$ ac

2 $ ac

Observe that a string like ab also fails due to the inability to consume the very last a.

20

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

QUESTION BANK

PART- A

1. Define the acceptance of a PDA by empty stack. Is it true that the language accepted
2. by a PDA by empty stack or by that of final state is different languages? [May 2017]
3. What is additional feature PDA has when compared with NFA? Is PDA Superior
4. over NFA in the sense of language acceptance ? Justify your answer.[ Nov/Dec
2013]
5. What are the different ways in which a PDA accepts the language? Define
them.[Apr/May 2018]
6. Is a true that non deterministic PDA is more powerful than that of deterministic PDA?
Justify your answer. [Nov 2016,Apr/May 2018]
7. Explain acceptance of PDA with empty stack.
8. Define instantaneous description of a PDA.
9. Give the formal definition of a PDA.[ May 2011,Nov 2017]
10. Define the languages generated by a PDA using final state of the PDA and empty
stack of that PDA. May’2004, Nov’2006
11. Define CFG.[Nov 2016]
12. Find L(G)where G=({S},{0,1},{S->0S1,S->є},S).
13. Define derivation tree for a CFG (or) Define parse tree.
14. Construct the CFG for generating the language L={anbn /n>=1}. [Nov’2004,Nov/Dec
2013]
15. Find the language generated by the CFG G=({S},{0,1},{S->0/1/ є ,S->0S0/1S1},S).
16. Write the CFG to generate the set {ambncp | m + n=p and p>=1}.
17. Give an example for a context free grammar.

21

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

PART-B & C

1. Explain in detail about Push down Automata and CFG. (16) [May/Jun 2013, Nov
2017]
2. Consider the GNF CFG G = ({S, T, C, D}, {a, b, c, d}, S, P) where P is:
ScCDDtc/∈ C TD c
TDCcST a DC d
3. Present a pushdown automaton that accepts the language generated by this
grammar.
4. Construct a PDA for the set of palindrome over the alphabet {a, b}.[Apr/May
2017,Apr/May 18]

5. Construct the PDA that accepts the language . [May/Jun 2013, Nov/Dec
17]
6. Construct a PDA that accepts L= { wwR | w = (a+b)* }[May/June 16]
7. Consider the grammar: [Apr/May 2010]
SICtS
S I C t S e S
S a
C  b where I, t, and, e stand for if, then, and else, and C and S for
“conditional” and “statement” respectively.
(1) Construct a leftmost derivation for the sentence w = i b t i b t a e a.
(2) Show the corresponding parse tree for the above sentence.
(3) Is the above grammar ambiguous? If sp, prove it.
(4) Remove ambiguity if any and prove that both the grammar produces the
same language.
8. Find a Context-Free Grammar for the following language: L = {anbmck : k = n + m }
[Nov/Dec 2013,Apr/May 2018]
9. When a grammar is said to be ambiguous? Explain with the help of an
example.[May/June 2016, Nov 2016]

22

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

UNIT IV

PROPERTIES OF CONTEXT FREE LANGUAGES

4.1 NORMAL FORMS FOR CFG

 The context free grammar is a type 2 grammar which contains the production of
form α → β where | α | ≤ | β |.
 CFG has single non terminal on the left side of the productions and any number of
terminals and non terminals on the right side.
Example:
CFG are as follows:
A→b
S → ABC
S → aAB
The normal forms of CFG are as follows:
1. Chomsky Normal Form (CNF)
2. Greibach Normal Form (GNF)
4.1.1 Simplification of CFG
To make CFG in a Chomsky Normal Form, the following simplifications are to be made.
1. Eliminate useless symbols.
2. Eliminate ε productions.
3. Eliminate unit productions.
4.1.1.1 Eliminating useless symbols
1. Useless symbols of the grammar are those non terminals or terminals that do not
appear in any derivation of a terminal string from the starting symbol.
2. Useful symbols is a variable or non terminal in the grammar G = (V, T, P, S) if there
is a derivation of the form s=> α
Where,
S → start symbol w → string
X → may be in V or T.
 There are two strings to identify for eliminating the useless symbols and they are

23

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Generating Symbols
 Reachable Symbols
Generating Symbols
The symbol X in the grammar is generating if X => w for some terminal string ‘w’.
Every terminal is always generating since it derives itself in zero step.
Example:
X => w
S c
Xd
Reachable symbols
The symbol X is reachable if there is a derivation of the form S => αXβ for some α and
β in V or T of the grammar G.
S → XY | C X → a
Y → d D → 0D
 If we want to eliminate the useless symbols, then we have to remove all the symbols
that are not generating and that are not reachable.
Example
Remove the useless symbols in the given CFG.
S → AB | CA
A→a
B → BC | AB
C → aB | b
Solution:
First find all the productions which are giving terminal symbols.
A → a and C → b
Now consider the start symbol.
S →AB | CA S → AB
S → CA
Let us take A and B, S → aB
S → aBC →aBBC → aABBC → aaBBBC → aaBCBBC →….and so on.
So we eliminate B.
After eliminating B we get S → CA A→a C→b

24

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

4.1.1.2 Elimination of ε-production from CFG


A variable A is nullable if A . Find them by a recursive algorithm:
Basis: If A  is a production, then A is nullable.
Induction: If A is the head of a production whose body consists of only nullable
symbols, then A is nullable.
 Once we have the nullable symbols, we can add additional productions and then
throw away the productions of the form A  for any A.
 If A  X1 X2 …Xk is a production, add all productions that can be formed by
eliminating some or all of those Xi's that are nullable.
o But, don't eliminate all k if they are all nullable.
Example:
If S → 0S | 1S | ε
Then we can remove ε-production. But we have to take care of the meaning of the CFG. That
is, meaning of CFG should not get changed if we place S → ε in other rules, we get S → 0.
When S → 0, S → 0S and S → ε.
As well as,
S → 1,
S → 1S and S → ε.
Hence we can rewrite the rule as S → 0S | 1S | 1 | 0. Thus ε-production is removed.
Example:
Remove the ε production from the following CFG by preserving the meaning of it.
S → XYX
X → 0X | ε Y → 1Y | ε
Solution:
 Removing ε production, we get deleting X → ε and Y → ε.
 To preserve the meaning of CFG, we are actually placing ε at right hand side
whenever X and Y have appeared.
Let us take X → ε.
S → XY
If first X at right hand side is ε, then S → XY. Next take the X at the left hand side and apply ε
to it, we get,

25

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S → YX
Take Y → ε
S → XX
Take X → ε and Y → ε
S→X
S → Y, when both X are replaced by ε.
After eliminating ε production at S productions, we write
S → XY | YX | XX | X | Y Now consider,
X → 0X | ε X → 0
Y → 1Y | ε Y → 1
We write X and Y production rule as X → 0X | 0
Y → 1Y | 1
Finally,
S XY | YX | XX | X | Y
X 0X | 0
Y 1Y | 1
4.1.1.3 Eliminating Unit productions
1. The productions of the form A  B, where A,B V called unit production.
2. Eliminate useless symbols and  - productions.
3. Discover those pairs of variables (A,B) such that A B.
 Because there are no  - productions, this derivation can only use unit
productions.
 Thus, we can find the pairs by computing reachablity in a graph where
nodes = variables, and arcs = unit productions.
4. Replace each combination where A B α and α is other than a single
variable by A  α.
 i.e., “short circuit" sequences of unit productions, which must eventually
be followed by some other kind of production.
Remove all unit productions.
 Consider the grammar G is S  A, A  B, B C, C  d.
Here A,B,C are the unit variables of length one. Then the resultant grammar is S  d. This is
called the chain rule.
26

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example
Eliminate unit productions from the following grammar.
S  A | bb
A  B |b
BS|a
Solution:
In the given grammar, the unit productions are S  A, A  B and B  S.
S  A gives S  b.
S  A  B gives S  B gives S  a.
A  B gives A  a
A  B S gives A  S gives A bb.
B  S gives B  bb.
B  S  A gives B A gives B  b.
The new productions are
S  bb | b | a
A  b | a | bb
B  a | bb | b
It has no unit productions. In order to get the reduced CFG, we have to eliminate the useless
symbols.
From the above grammar we can eliminate the A and B productions.
Then the resultant grammar is S  bb | b | a.
4.1.2 Normal Forms
 The grammar can be simplified by reducing the ε production, removing useless
symbols, unit production. There is also a need to have grammar in some specific
form.
 In CFG at the right hand of the production there are any numbers of terminal or non
terminal symbols in any combination.
 To normalize such a grammar, that means, we want the grammar in some specific
format.
 There are two important normal forms such as,
 Chomsky’s Normal Form (CNF)
 Greibach Normal Form (GNF)

27

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

4.1.2.1 Chomsky’s Normal Form


The Chomsky’s Normal Form is in the form of
Non Terminal  Non Terminal Non Terminal
Non Terminal Terminal
Example:
1. A → BC, where A,B,C are non terminals
2. A → a, where A is a non terminal and ‘a’ is a terminal.
4.1.2.1.1 Steps for converting grammar into CNF
Step 1:
Simplify the grammar by eliminating ε-production, unit production, and useless
symbols.
Step 2:
Now add all the productions of the form A → BC and A → a, such that the production
body contains two non terminals and the single terminal on the right side of the
production.
Step 3:
If the production has the form A → X1X2X3….Xk, where k ≥ 2, then CNF is
A → X1Y1
Y1→ X2Y2
Yk-2 → Xk-2Yk-2
Yk-1 → Xk-1Yk.
Example
Convert the following CFG into CNF.
S → aaaaS S → aaaa
Solution:
Chomsky’s Normal Form is, NT → NT.NT
NT → T
The given CFG is
S → aaaaS  rule 1
S → aaaa  rule 2
If we add a rule
A → a, which is in CNF, so the rule 1 and rule 2 as

28

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S → AAAAS
S → AAAA
Let us take,
S → A, and AAAS can be replaced by P1.
If we define
P1 → AAAS, then the rule becomes S → AP1
Here P1 is not a CNF, so convert P1 as follows,
P1 → A, and AAS can be replaced by P2 as
P2 → AP2 is in CNF form.
Here again P2 is not in CNF form, so P2 can be replaced by P3 as
P2 → A, and AS can be replaced by P3.
P2 → AP3
P3 → AS which is in CNF. So the grammar is rewritten as
S → AP1
P1 → AP2
P2 → AP3
P3 → AS,
for the rule 1.
Consider the rule 2,
S → AAAA S → AA AA
P4 P5
P4 → AA
P5 → AA
Both P4 and P5 are same. So it can be written as
S → P4.P5
S → P4 P4,
since P4 = P5.
Finally the CNF can be written as,
S → AP1
P1 → AP2
P2 → AP3
P3 → AS

29

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S → P4P4
P4 → AA
A→a
4.1.2.2 Greibach Normal form
The rule for GNF is
Non terminal → one terminal. Any number of non terminals
NT  T. NT
Example:
S → aA  in GNF
S→a
S → AA  not in GNF
S → Aa
We can use two important lemmas based on which it is easy to convert the given CFG to
GNF.
Lemma 1:
G = (V, T, P, S) be a given CFG and if there is a production A → Ba and
B → β1 | β2 | … |βn Then we can convert the A rule as
A → β1a | β2a | β3a | …|βna
For example,
S → Aa
A → aA | bA | aAS | b
Then we can convert S rule in GNF as,
S  aAa | bAa | aASa | ba
A aA | bA | aAS | b
Lemma 2:
Let G = (V, T, P, S) be a given CFG and if there is a production A → Aa1 | Aa2 | Aa3 | …|
Aan | β1 | β2 | …| βn
Such that βi do not start with A, then equivalent grammar in CNF can be A → β1 | β2 |…| βn
A → β1Z | β2Z | …| βnZ Z → a1 | a2 | …| an
Z → a1Z | a2Z | …| anZ
For example,
Consider A → A1| 0B | 2

30

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Here
A → 0B | 2
A → 0BZ | 2Z
Z → 1 Z → 1Z
Problems:
1. Convert the following grammar to GNF. S  abSb
S  aa
Solution:
NT → t. NT
Let us take first production
i) S → abSb
Create another NT namely B, so B → a
Substitute in s rule,
S → aBSB is in GNF Similarly,
ii) S → aa
Create new NT namely A A → a
So,
Finally
S → aA
S  aBSB
2. Convert the given CFG to GNF
S → ABA
A → aA | ε
B → bB | ε
Solution:
 Eliminate ε-production from the given production S → ABA | AB | AA | BA | A | B
A → aA | a B → bB | b
 Remove the unit production
S → ABA | AB | AA | A
S → aABA | aAB | aAA | aA | aBA | aB | aA | a
S → aABA | aAB | aAA | aBA | aA | aB | a
S → BA | B

31

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S → bBA | bB | bA | b
Finally,
S → aABA | aAB | aAA | aBA | aA | aB | a
S → bBA | bB | bA | b
A → aA | a
B → bB | b
3. Convert the following CFG into CNF
S → ASA | aB,
A → B | S,
B→b|∈
Solution
(1) Since S appears in R.H.S, we add a new state S0 and S0 → S is added to the
production set and it becomes −
S0 → S,
S → ASA | aB,
A → B | S,
B→b|ε
(2) Now we will remove the null productions −
B → ε and A → ε
After removing B → ε, the production set becomes −
S0 → S,
S → ASA | aB | a,
A → B | S | ε,
B→b
After removing A → ε, the production set becomes −
S0 → S,
S → ASA | aB | a | AS | SA | S,
A → B | S,
B→b
(3) Now we will remove the unit productions.
After removing S → S, the production set becomes −
S0 → S,

32

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S → ASA | aB | a | AS | SA,
A → B | S,
B→b
After removing S0 → S, the production set becomes −
S0 → ASA | aB | a | AS | SA,
S → ASA | aB | a | AS | SA
A → B | S,
B→b
After removing A → B, the production set becomes −
S0 → ASA | aB | a | AS | SA,
S → ASA | aB | a | AS | SA
A→S|b
B→b
After removing A → S, the production set becomes −
S0 → ASA | aB | a | AS | SA,
S → ASA | aB | a | AS | SA
A → b |ASA | aB | a | AS | SA,
B→b
(4) Now we will find out more than two variables in the R.H.S
Here, S0 → ASA, S → ASA, A → ASA violates two Non-terminals in R.H.S.
Hence we will apply step 4 and step 5 to get the following final production set which is in
CNF
S0 → AX | aB | a | AS | SA
S → AX | aB | a | AS | SA
A → b |AX | aB | a | AS | SA
B→b
X → SA
(5) We have to change the productions
S0 → aB,
S → aB,
A → aB
And the final production set becomes −

33

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

S0 → AX | YB | a | AS | SA
S → AX | YB | a | AS | SA
A → b |AX | YB | a | AS | SA
B→b
X → SA
Y→a

4.2 PUMPING LEMMA FOR CFL


The theorem below is the pumping lemma for context-free languages:
Theorem
Let L be an infinite context-free language. Then there exists some positive integer
m such that any w  L with |w|  m can be decomposed as w = uvxyz with |vxy|  m
and |vy| 1 such that uvixyiz  L for all i = 0, 1, …
Proof:
Let’s first notice some of the differences between this pumping lemma and the one for
regular languages. First, observe that we do not necessarily find the parts to pump at the
beginning of the string. Because of this we will usually have several cases to consider
depending on the location of the substring vxy. Also notice that we have two substrings, v
and y, both of which pump. The length of vy must be at least 1, and it is possible that one
of v or y is empty. Using a grammar in CNF and a corresponding derivation tree, the proof
sketch below shows why we have two substrings that pump.
Proof sketch: Let L be a context-free language and consider L – {}. Assume L is
generated by the CFG, G = (V, T, S, P) which is in Chomsky Normal Form. Thus, G has no
useless symbols, unit productions or -productions. If w  L(G) then, using the Chomsky
grammar, its derivation tree is a binary tree.
Suppose the derivation tree for w has height k + 1. That is, the longest path from the
root to a leaf has length k + 1. Notice that all leaves in the tree are obtained by using a
production of the form A  a. This raises the question of how long w could be. In the
worst case, the derivation tree is a complete binary tree down to the level immediately
above the leaf level. That is, the number of nodes at each level satisfy this geometric
progression: 20, 21, 22, …, 2k. This means that the kth level of the tree contains 2k nodes

34

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

and thus the leaf level must also have 2k nodes because the productions used to get the
leaves are of the form A  a. Thus, |w| ≤ 2k also.
Now, suppose the grammar has k variables i.e. |V| = k. Let w be a string such that S
* w and |w|  2k. This means that every parse tree for w has height at least k + 1.
Suppose we follow a path from the root labeled S to a leaf on level k + 1. There are k + 2
nodes along the path a path always has one more node than edges), and k+1 of those are
labeled by variables. Thus, two nodes along the path must be labeled by the same
variable. This means we have a situation that looks like this:

Here’s what this means: starting from a leaf and working upward toward the root we
can identify two vertices Ai and Aj on the path which are labeled by the same variable i.e. Ai
= Aj. Looking at the corresponding sentential forms in a derivation what we really have is
this: S * uAiz. Going from Ai to Aj we have Ai * vAiy. Thus, the derivation of w could
proceed like this: S * uAiz * uvAiyz * uvvAiyyz …uviAiyiz *uvixyiz What this
indicates is that we can repeat the subtree rooted at the first A i as often as we'd like until
eventually we have Ai * x which stops the derivation.
Thus, if our original string w is “long enough”, it can be broken up into substrings u, v, x,
y, and z, two of which (v and y) can be repeated as often as we’d like. That is, w = uvxyz
and for every i ≥ 0, uvixyiz  L. When using a proof by contradiction to show that a
language is not context-free, we assume that the opposite is true i.e. assume L is context-
free. Then, by Theorem 8.1 there is some integer m so that if a string with length greater
than m is chosen then that string should “pump”. In the notation of the theorem it must be

35

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

true that |vxy| ≤ m and |vy| ≥ 1 (in other words, at least one of v, y is nonempty). In order
to obtain our contradiction, we need to consider all possible “locations” of vxy and, in each
case, find a value of i such that when we pump i times the string we end up with is not in L.
As with the pumping lemma for regular languages we use the notation wi = uvixyiz and thus
w0 = uxz.
Here are some examples of how the pumping lemma for context-free languages is used.
When you find a value of i that gives you a contradiction you must explicitly state what that
contradiction is. You may not eliminate cases by saying that one case substantially the
same as another. Each case should be explicitly considered. There is usually more than
one way to define the cases to be used so the most important thing is to make sure every
possible place that vxy could appear is considered.
Example:
Using pumping lemma prove that the language (anbncn |n=1) is not context free.
The given language L={anbncn}
Let z be any string that belongs to L
Let z = aPbPcP€L
According to pumping lemma, if z is in L and |z|>n, z can be written as
z=uvwxy
z=aPbPcP as
u, vwx and y respectively, we get
u=aP
vwx=bP where |vwx|=n
vx=bP-m where |vx|=1
P
y=c
Substituting these values in uv1wx1y
=uvi-1vwx xi-1y (uviwxiy is expressed in this form)
=uvwx(vx)i-1y
=aPbP(bP-m)i-1cP
=aPbPbP for all values of i

Let i=0.
uvi-1vwx xi-1 y = aPbPbP(0)-m(0)-P+micP

36

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

=aPbPbm-PcP
=aPbmcP€L
Hence L is not a context free grammar.
Context-free languages are closed under several common operations.
4.3 CLOSURE PROPERTIES OF CFL
1.Union
Suppose we have grammars for two languages, with start symbols S and T. Rename
variables as needed to ensure that the two grammars don't share any variables. Then
construct a grammar for the union of the languages, with start symbol Z, by taking all the
rules from both grammars and adding a new rule Z -> S | T.
2.Concatenation
Suppose we have grammars for two languages, with start symbols S and T. Rename
variables as needed to ensure that the two grammars don't share any variables. Then
construct a grammar for the union of the languages, with start symbol Z, by taking all the
rules from both grammars and adding a new rule Z -> ST.
3.Star
Suppose that we have a grammar for the language L, with start symbol S. The grammar
for L*, with start symbol T, contains all the rules from the original grammar plus the rule T ->
TS | e.
4.String reversal
Reverse the character string on the right hand side of every rule in the grammar.
5.Homomorphism
Suppose that we have a grammar G for language L and a homomorphism h. To
construct a grammar for h(L), modify the right hand side of every rule in G to replace each
terminal symbol t with its image h(t) under the homomorphism.
6.Intersection with a regular language
The intersection of a context-free language and a regular language is always context-
free. To show this, assume we have a PDA M accepting the context-free language and a
DFA N accepting the regular language. Use the product construction to create a PDA which
simulates both machines in parallel. This works because only M needs to manipulate the
stack; N never touches the stack.

37

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Non-closure facts
Context-free languages are not closed under set intersection or set complement.
1.Intersection
Consider the languages L1 and L2 defined by L1 = {anbncj: n,j = 0} and L2 = {ajbncn: n,j =
0}. They are both context-free. However, their intersection is the language L = {anbncn: n =
0}. We used the pumping lemma to show that L is not context-free.
2.Set complement
There are two approaches to showing this. First, you can use deMorgan's laws to show that
closure under set complement plus closure under union would imply closure under
intersection.
4.4 TURING MACHINES
A Turing Machine is an accepting device which accepts the languages (recursively
enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turing.
4.4.1 Definition
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape
divided into cells on which input is given. It consists of a head which reads the input tape. A
state register stores the state of the Turing machine. After reading an input symbol, it is
replaced with another symbol, its internal state is changed, and it moves from one cell to
the right or left. If the TM reaches the final state, the input string is accepted, otherwise
rejected.
A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −
 Q is a finite set of states
 X is the tape alphabet
 ∑ is the input alphabet
 δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.
 q0 is the initial state
 B is the blank symbol
 F is the set of final states
Example of Turing machine
Turing machine M = (Q, X, ∑, δ, q0, B, F) with
 Q = {q0, q1, q2, qf}
 X = {a, b}

38

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 ∑ = {1}
 q0 = {q0}
 B = blank symbol
 F = {qf }
δ is given by −

Tape alphabet PresentState Present State Present State


symbol ‘q0’ ‘q1’ ‘q2’

a 1Rq1 1Lq0 1Lqf

b 1Lq2 1Rq1 1Rqf

Here the transition 1Rq1 implies that the write symbol is 1, the tape moves right, and the
next state is q1. Similarly, the transition 1Lq2 implies that the write symbol is 1, the tape
moves left, and the next state is q2.
4.4.2 Time and Space Complexity of a Turing Machine
For a Turing machine, the time complexity refers to the measure of the number of times the
tape moves when the machine is initialized for some input symbols and the space
complexity is the number of cells of the tape written.
Time complexity all reasonable functions −
T(n) = O(n log n)
TM's space complexity −
S(n) = O(n)
4.4.3 Acceptance of Languages

A TM accepts a language if it enters into a final state for any input string
w. A language is recursively enumerable (generated by Type-0 grammar) if it
is accepted by a Turing machine.

A TM decides a language if it accepts it and enters into a rejecting state for


any input not in the language. A language is recursive if it is decided by a
Turing machine.

There may be some cases where a TM does not stop. Such TM accepts the
language, but it does not decide it.

39

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

4.4.4 Designing a Turing Machine

The basic guidelines of designing a Turing machine have been explained below with the
help of a couple of examples.

Example 1
Design a TM to recognize all strings consisting of an odd number of α’s.

Solution

The Turing machine M can be constructed by the following moves −

 Let q1 be the initial state.

 If M is in q1; on scanning α, it enters the state q2 and writes B(blank).

 If M is in q2; on scanning α, it enters the state q1 and writes B(blank).

 From the above moves, we can see that M enters the state q1 if it scans an even
number of α’s, and it enters the state q2 if it scans an odd number of α’s. Hence q2 is
the only accepting state.

Hence,

M = {{q1, q2}, {1}, {1, B}, δ, q1, B, {q2}}

where δ is given by −

Tape alphabet symbol Present State ‘q1’ Present State ‘q2’

α BRq2 BRq1

Example 2
Design a Turing Machine that reads a string representing a binary number and erases all
leading 0’s in the string. However, if the string comprises of only 0’s, it keeps one 0.

Solution

Let us assume that the input string is terminated by a blank symbol, B, at each end of the
string.

The Turing Machine, M, can be constructed by the following moves −

 Let q0 be the initial state.

40

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 If M is in q0, on reading 0, it moves right, enters the state q1 and erases 0. On reading
1, it enters the state q2 and moves right.

 If M is in q1, on reading 0, it moves right and erases 0, i.e., it replaces 0’s by B’s. On
reaching the leftmost 1, it enters q2 and moves right. If it reaches B, i.e., the string
comprises of only 0’s, it moves left and enters the state q3.

 If M is in q2, on reading either 0 or 1, it moves right. On reaching B, it moves left and


enters the state q4. This validates that the string comprises only of 0’s and 1’s.

 If M is in q3, it replaces B by 0, moves left and reaches the final state qf.

 If M is in q4, on reading either 0 or 1, it moves left. On reaching the beginning of the


string, i.e., when it reads B, it reaches the final state qf.

Hence,

M = {{q0, q1, q2, q3, q4, qf}, {0,1, B}, {1, B}, δ, q0, B, {qf}}

where δ is given by −

Tape Present Present Present Present Present


alphabet State ‘q0’ State ‘q1’ State ‘q2’ State ‘q3’ State ‘q4’
symbol

0 BRq1 BRq1 ORq2 - OLq4

1 1Rq2 1Rq2 1Rq2 - 1Lq4

B BRq1 BLq3 BLq4 OLqf BRqf

Example 2
Design a Turing Machine which reverses the given string {abb}

41

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Example 4
3. Construct a Turing Machine ™ to move an input string over the alphabet A = {a} to the
right one cell. Assume that the tape head starts somewhere on a blank cell to the left of the
input string. All other cells are blank, labeled by ^. The machine must move the entire string
to the right one cell, leaving all remaining cells blank.
Solution:
The format of the string in the tape is:
λ λ a a a λ λ λ …

R/W head
The required transition rules are:
d(q0, l) = (q1, l, R)
d(q1, a) = (q2, l, R)
d(q2, a) = (q2, a, R)
d(q2, l) = (q3, a, R)
where q3 € F
Example 5
Design a Turning Machine to recognize each of the following languages.
(i) {0 n1n | n ≥1}
(ii) {wwR | w € ( 0 +1)*}
(i) {0n1n|n≥1}
Solution:
Initially the tape of M contains 0n1n followed by infinity of blanks. Starting at leftmost 0, we
check it off by replacing it with some other symbol, say x. we then let the read-write head
travel right to find the leftmost ‘1’, which in turn is checked off by replacing it with another
symbol, say y. After that, we go to left again to the leftmost 0, replace it with an x, then
move to the leftmost ‘1’, and replace it with y, and so on.
Travelling back and forth the same way we match each 0 with a corresponding 1. If after
some time no 0’s and 1’s remain, then the string must be in L.
Working on this, the solution is
Q={qc,q1,q2,q3,q4}
F={q4}

42

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

∑={0,1}
G={0, 1, x, y, B}

The transitions can be broken into several parts. The set


d(q0,0)=(q1,x,R) d(q1,0)=(q1,0,R) d(q1,y)=(q1,y,R) d(q1,1)=(q1,y,L)
replaces the leftmost 0 with an x, then causes the read-write head to travel right to first 1,
replacing it with a y. When the y is written, the machine enters a state q2, indicating that an
0 has been successfully paired with a 1.The next set of transitions reverses the direction
until an x is encountered, repositions the read-write head over the left most 0, and returns
control to initial state.
d(q2,y)=(q2,y,L) d(q2,0)=(q2,0,L) d(q2,x)=(q0,x,R)
We are now back in the initial state q0, ready to deal with the next 0 and 1.After one pass
through this part of the computation, the machine will have carried partial computation.
i.e. q000….011…..1 xq00…..0y1…..1,
So that single 0 has been matched with a single 1. After 2 passes, we will have completed
the partial computation.
q000….011…..1 xxq00…..0yy1…..1 and so on, indicating that the matching is carried out
properly.
When the input is a string 0n1n, the rewriting continues this way, stopping only when
there are no more 0’s to be erased, when looking for the leftmost 0, the read-write head
travels with the machine in state q2. When an x is encountered, the direction is reversed, to
get the 0. But now, instead if finding an 0, it will find a 1. To terminate, a final check is made
to see if all 0’s and 1’s is replaced. This is done by
d( q0 , y) = ( q3 , y, R)
d( q3 , y) = ( q3 , B, R)
d( q3 , B) = ( q4 , B, R)
If the input string is not in the language, the computation will halt in non-final state.
If the input string is in the language, it will result in final state.
Computation of 0011.
q0 0011 xq1 011 x0 q111 xq2 0 y1
q2 x0 y1 xq0 0 y1 xxq1 y1 xxyq1 xxq2 yy xq2 xyy
xxq0 yy  xxyq3 y xxyyq3 B xxyyBq4 B.

43

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

(ii) {wwR w € (0+1)*}


Solution:
L = {wwR , w € (0+1)*}
Consider a TM M = (Q, ∑, G, d, q0, B, F) which recognizes the language of the type wwR
i.e. palindrome type of language.
Q = q0 ……q7, ∑={0,1}, G=B, q0 – initial state, q7 – final state. d is defined as follows:
The tape head moves back and forth comparing the symbol at one end of the remaining
non black string to the symbol at the other end.
4.4.5 Multi Tape Turing Machine

Multi-tape Turing Machines have multiple tapes where each tape is accessed with a
separate head. Each head can move independently of the other heads. Initially the input
is on tape 1 and others are blank. At first, the first tape is occupied by the input and the
other tapes are kept blank. Next, the machine reads consecutive symbols under its
heads and the TM prints a symbol on each tape and moves its heads.

A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q0, F)


where −

 Q is a finite set of states

 X is the tape alphabet

 B is the blank symbol

 δ is a relation on states and symbols where

δ: Q × Xk → Q × (X × {Left_shift, Right_shift, No_shift })k

44

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

where there is k number of tapes

 q0 is the initial state

 F is the set of final states

Note − Every Multi-tape Turing machine has an equivalent single-tape Turing machine.
4.5 Programming Techniques for Turing Machine Construction
Designing Turing machines by writing out a complete set of states and a next – move
function is a noticeably unrewarding task. In order to describe complicated Turing machine
constructions we need some “higher – level” conceptual tools.
 Assume input integers m and n are put on the input tape separated by a 1 as 0 m10n
(two unary numbers using 0’s separated by a special symbol 1).
 The TM is M = ({q0, q1, …, q6}, {0, 1}, {0, 1, B}, , q0, B).
 No final state is needed.
 M conducts the following computation steps:
1. find its leftmost 0 and replaces it by a blank;
2. move right, and look for a 1;
3. after finding a 1, move right continuously
4. after finding a 0, replace it by a 1;
5. move left until finding a blank, & then move one cell to the right to get a
0;
6. repeat the above process.
 The transition table of M is as shown in Table 8.2.
The transition table for the TM
symbol
state 0 1 B
q0 (q1, B, R) (q5, B, R) -
q1 (q1, 0, R) (q2, 1, R) -
q2 (q3, 1, L) (q2, 1, R) (q4, B, L)
q3 (q3, 0, L) (q3, 1, L) (q0, B, R)
q4 (q4, 0, L) (q4, B, L) (q6, 0, R)
q5 (q5, B, R) (q5, B, R) (q6, B, R)
q6 - - -

45

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

 Moves to compute 2  1 = 1:
_

q00010 1 Bq1010 3 B0q110 4 B01q20 5 B0q311 9 Bq3011 8 q3B011 10


Bq0011 1 BBq111 4 BB1q21 6 BB11q2B 7 BB1q41 12 BBq41B 12 Bq4BBB
13 B0q6BB halt! (with one 0 left, correct)

 Moves to compute 1  2 = 0:
_

q00100  Bq1100  B1q200  Bq3110  q3B110  Bq0110  BBq510  BBBq50 


BBBBq5B  BBBBBq6 halt! (with no 0 left, correct)
4.5.1 Storage in the Finite Control
The finite control can be used to hold a finite amount of information. To do so, the state
is written as a pair of elements, one exercising control and the other storing SYMBOL. It
should be emphasized that this arrangement is for conceptual purposes only. No
modifications in the definition of the Turing machine have been made. In general, we can
allow the finite control to have k components, all but one of which store information.
We can use the finite control of the TM to hold a finite amount of data.

In the figure we see that the finite control not only consist of a state q but also of three
data elements A, B and C. The technique requires no extension to the TM model. We
merely think of the state as the tuple [q,A,B,C]. Regarding states this way allows to
describe transitions in a more systematic way and often to simplify the strategy of the
program.
To recognize the language (01*)(10*)

46

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

4.5.2 Checking off Symbols


Checking off symbols is a useful trick for visualizing how a TM recognizes languages
defined by repeated strings, such as {ww | w in ∑* }, {wcy | w and y in ∑* , w ≠ y} or {wwR |
w in ∑* }. Finite Control It also useful when lengths of substrings must be compared, such
as in the languages
{ai b i | i ≥ 1} or {a i b i c k | i ≠ j or j ≠ k}
Shifting over
A Turing machine can make a space on its tape by shifting all non blank symbols a finite
number of cells to the right. To do so, the tape head makes an excursion to the right,
repeatedly storing the symbols read in its finite control and replacing them with symbols
read from dells to the left. The Tm can then return to the vacated dells and print symbols of
its choosing. If space is available, it can push blocks of symbols left in a similar manner.
4.5.3 Multiple Tracks
We can imagine that the tape of the Turing machine is divided into k tracks, for any
finite k. This arrangement is shown in Fig. with k=3. The symbols on the tape are
considered k- tuples, one component for each track.
¢ 1 0 1 1 1 1 $ B B
B B B B 1 0 1 B B B…
B 1 0 0 1 0 1 B B B
Another useful trick is to divide the tape of the TM in several tracks. Each track can hold
one symbol and the alphabet of the TM consists of tuples, with one component for each
47

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

track. This technique does not extend the model of the TM. It is simply a way to view tape
symbols and to imagine that they have a useful structure. A common use of multiple track
is to use one track to mark cells and the second track as the data.
4.5.4 Subroutines
As with programs, a “modular” or “top-down” design is facilitated if we use subroutines
to define elementary processes. A Turing machine can simulate any type of subroutine
found in programming languages, including recursive procedures and any of the known
parameter-passing mechanisms. The general idea is to write part of a TM program to serve
as a subroutine; it will have a designed initial state and a designated return state which has
no move and which will be used to affect a return to the calling routine. To design a TM that
“calls” the subroutine, a new set of states for the subroutine is made, and a move from the
return is affected by the move from the return state.

48

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

QUESTION BANK

PART-A (2 Marks)
1. What do you mean by null production and unit production.[May/June 16]
2. State whether regular languages are closed under intersection and
complementation.[May/June 16,Nov/Dec 17]
3. How to simplify the context free grammar?
4. What is Useless symbol? How to remove that?
5. Eliminate the useless symbol for the following productions
6. What are є-Productions? How to eliminate the є-Productions?
7. Eliminate the null production for the following grammar.
8. What are unit productions? How to eliminate the unit production?
9. Eliminate the unit production from the grammar below:
10. Define Chomsky normal form. [Nov/Dec 2016,Apr/May 2018]
11. Define greibach normal form. [May/Jun 2013]
12. State Pumping lemma for Context free language. [Dec 08]
13. Can you say the language generated by a CFG in CNF is finite or infinite? If so
14. how? If not, why?
15. What is a Turing machine?[May/June 2016,Nov/Dec 2017,Apr/May 2018]
16. What are the special features of TM? [Nov 2016]
17. Define Turing machine. [Nov 2016]
18. Define Instantaneous description of TM.
19. What are the applications of TM?
20. Define a move in TM.
21. What is the language accepted by TM?
22. What are the techniques for Turing machine construction? [Nov/Dec 2013]
23. What is a multi-tape Turing machine?

49

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

PART – B & C
1. Convert the following grammar into CNF. [Nov/Dec 2013]
S aX | Yb
XS|
Y bY | b
2. Convert the following grammar G into Greibach Normal Form (GNF).[May
2017,Nov/Dec 2017]
S  XA|BB
B b|SB
Xb
Aa
3. Convert the following grammar into an equivalent one with no unit productions and no
useless symbols. Convert to Chomsky Normal Form (CNF).[Apr/May 2010]
S→A CB
A→C D
B→1B 1
C→0C 0
D→2D 2
4. What is the purpose of normalization? Construct the CNF and GNF for the following
grammar and explain steps
5. Design a Turing Machine which reverses the given string {abb} [Nov/Dec 2012,May
2017]
6. Construct a Turing Machine ™ to move an input string over the alphabet A = {a} to the
right one cell. Assume that the tape head starts somewhere on a blank cell to the left
of the input string. All other cells are blank, labeled by ^. The machine must move the
entire string to the right one cell, leaving all remaining cells blank.[Apr/May 2010]
7. Design a Turning Machine to recognize each of the following languages.
(i) {0 n1n | n ≥1}
(ii) {wwR | w € ( 0 +1)*}[Apr/May 2009,Apr/May 2018]
8. Design Turing Machine for the function f(n)=n2 [Nov/Dec 2009]
9. Explain the variations of Turing Machine.[May/June 2016,May 2017]

50

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

10. Construct a Turing machine to accept palindromes in an alphabet set ∑= {0,1}. Trace
the string ‘0101’ and “1001” [May/June 2016]
11. Explain in detail about Programming Techniques for Turing Machine.[Nov/Dec 2017,
Apr/May 2018]

51

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

UNIT –V

UNDECIDABILITY

5.1 NON RECURSIVE ENUMERABLE (RE) LANGUAGE


For an undecidable language, there is no Turing Machine which accepts the
language and makes a decision for every input string w (TM can make decision for
some input string though). A decision problem P is called “undecidable” if the
language L of all yes instances to P is not decidable. Undecidable languages are not
recursive languages, but sometimes, they may be recursively enumerable languages.

Example
 The halting problem of Turing machine

 The mortality problem


 The mortal matrix problem
 The Post correspondence problem, etc.

5.1.1 Recursive Enumerable (RE) or Type -0 Language


RE languages or type-0 languages are generated by type-0 grammars. An RE language
can be accepted or recognized by Turing machine which means it will enter into final
state for the strings of language and may or may not enter into rejecting state for the
strings which are not part of the language. It means TM can loop forever for the strings
which are not a part of the language. RE languages are also called as Turing
recognizable languages.

52

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

5.1.2 Recursive Language (REC)


A recursive language (subset of RE) can be decided by Turing machine which means it
will enter into final state for the strings of language and rejecting state for the strings
which are not part of the language. e.g.; L= {a nbncn|n>=1} is recursive because we can
construct a turing machine which will move to final state if the string is of the form
anbncn else move to non-final state. So the TM will always halt in this case. REC
languages are also called as Turing decidable languages. The relationship between and
REC languages can be shown in Figure.
5.1.2.1 Closure Properties of Recursive Languages
 Union: If L1 and If L2 are two recursive languages, their union L1∪L2 will also be
recursive because if TM halts for L1 and halts for L2, it will also halt for L1∪L2.
 Concatenation: If L1 and If L2 are two recursive languages, their concatenation
L1.L2 will also be recursive. For Example:
 L1= {anbncn|n>=0}
 L2= {dmemfm|m>=0}
 L3= L1.L2
 = {anbncndm emfm|m>=0 and n>=0} is also recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2 says m no. of d’s
followed by m no. of e’s followed by m no. of f’s. Their concatenation first matches no. of
a’s, b’s and c’s and then matches no. of d’s, e’s and f’s. So it can be decided by TM.
 Kleene Closure: If L1is recursive, its kleene closure L1* will also be
recursive. For Example:
L1= {anbncn|n>=0}
L1*= { anbncn||n>=0}* is also recursive.
 Intersection and complement: If L1 and If L2 are two recursive languages, their
intersection L1 ∩ L2 will also be recursive. For Example:
 L1= {anbncndm|n>=0 and m>=0}
 L2= {anbncndn|n>=0 and m>=0}
 L3=L1 ∩ L2
 = { anbncndn |n>=0} will be recursive.

53

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then any no. of
d’s. L2 says any no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n
no. of d’s. Their intersection says n no. of a’s followed by n no. of b’s followed by n no.
of c’s followed by n no. of d’s. So it can be decided by turing machine, hence recursive.
Similarly, complement of recursive language L1 which is ∑*-L1, will also be recursive.
5.2 UNDECIDABLE PROBLEM WITH RE
5.2.1 Halting Problem
Input − A Turing machine and an input string w.
Problem − Does the Turing machine finish computing of the string w in a finite number
of steps? The answer must be either yes or no.
Proof − At first, we will assume that such a Turing machine exists to solve this problem
and then we will show it is contradicting itself. We will call this Turing machine as
a Halting machine that produces a ‘yes’ or ‘no’ in a finite amount of time. If the halting
machine finishes in a finite amount of time, the output comes as ‘yes’, otherwise as
‘no’. The following is the block diagram of a Halting machine −

Now we will design an inverted halting machine (HM)’ as −


 If H returns YES, then loop forever.
 If H returns NO, then halt.
The following is the block diagram of an ‘Inverted halting machine’ −

54

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Further, a machine (HM)2 which input itself is constructed as follows −


 If (HM)2 halts on input, loop forever.
 Else, halt.
Here, we have got a contradiction. Hence, the halting problem is undecidable.
5.3 RICE Theorem
Rice theorem states that any non-trivial semantic property of a language which is
recognized by a Turing machine is undecidable. A property, P, is the language of all
Turing machines that satisfy that property.
5.3.1 Formal Definition
If P is a non-trivial property, and the language holding the property, L p , is recognized by
Turing machine M, then Lp = {<M> | L(M) ∈ P} is undecidable.
5.3.2 Description and Properties
 Property of languages, P, is simply a set of languages. If any language belongs
to P (L ∈ P), it is said that L satisfies the property P.
 A property is called to be trivial if either it is not satisfied by any recursively
enumerable languages, or if it is satisfied by all recursively enumerable
languages.
 A non-trivial property is satisfied by some recursively enumerable languages and
are not satisfied by others. Formally speaking, in a non-trivial property, where L ∈
P, both the following properties hold:
o Property 1 − There exists Turing Machines, M1 and M2 that recognize the
same language, i.e. either ( <M1>, <M2> ∈ L ) or ( <M1>,<M2> ∉ L )

55

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

o Property 2 − There exists Turing Machines M1 and M2, where M1


recognizes the language while M2 does not, i.e. <M1> ∈ L and <M2> ∉ L
5.3.3 Proof
Suppose, a property P is non-trivial and φ ∈ P.
Since, P is non-trivial, at least one language satisfies P, i.e., L(M0) ∈ P , ∋ Turing
Machine M0.
Let, w be an input in a particular instant and N is a Turing Machine which follows −
On input x
 Run M on w
 If M does not accept (or doesn't halt), then do not accept x (or do not halt)
 If M accepts w then run M0 on x. If M0 accepts x, then accept x.
A function that maps an instance ATM = {<M,w>| M accepts input w} to a N such that
 If M accepts w and N accepts the same language as M0, Then L(M) = L(M0) ∈ p
 If M does not accept w and N accepts φ, Then L(N) = φ ∉ p
Since ATM is undecidable and it can be reduced to Lp, Lp is also undecidable.
5.4 POST CORRESPONDENCE PROBLEM
The Post Correspondence Problem (PCP), introduced by Emil Post in 1946, is an
undecidable decision problem. The PCP problem over an alphabet ∑ is stated as
follows − Given the following two lists, M and N of non-empty strings over ∑ −
M = (x1, x2, x3,………, xn)
N = (y1, y2, y3,………, yn)
We can say that there is a Post Correspondence Solution, if for some i 1,i2,………… ik,
where 1 ≤ ij ≤ n, the condition xi1 …….xik = yi1 …….yik satisfies.
Example 1
Find whether the lists M = (abb, aa, aaa) and N = (bba, aaa, aa) have a Post
Correspondence Solution?

x1 x2 x3

M Abb aa aaa

N Bba aaa aa

56

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Here,
x2x1x3 = ‘aaabbaaa’
and y2y1y3 = ‘aaabbaaa’
We can see that
x2x1x3 = y2y1y3
Hence, the solution is i = 2, j = 1, and k = 3.
Example 2
Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post
Correspondence Solution?
Solution

x1 x2 x3

M ab bab bbaaa

N a ba bab

In this case, there is no solution because −


| x2x1x3 | ≠ | y2y1y3 | (Lengths are not same)
Hence, it can be said that this Post Correspondence Problem is undecidable.
5.4.1 Proof sketch of undecidability
The most common proof for the undecidability of PCP describes an instance of
PCP that can simulate the computation of a Turing machine on a particular input. A
match will only occur if the input would be accepted by the Turing machine. Because
deciding if a Turing machine will accept an input is a basic undecidable problem, PCP
cannot be decidable either.
This means it will list a string describing the initial state, followed by a string describing
the next state, and so on until it ends with a string describing an accepting state. The
state strings are separated by some separator symbol (usually written #). According to
the definition of a Turing machine, the full state of the machine consists of three parts:
 The current contents of the tape.
 The current state of the finite state machine which operates the tape head.
 The current position of the tape head on the tape.

57

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Although the tape has infinitely many cells, only some finite prefix of these will be
non-blank. We write these down as part of our state. To describe the state of the finite
control, we create new symbols, labelled q1 through qk, for each of the finite state
machine’sk states. We insert the correct symbol into the string describing the tape’s
contents at the position of the tape head, thereby indicating both the tape head’s
position and the current state of the finite control. For the alphabet {0,1}, a typical state
might look something like:
101101110q700110.
A simple computation history would then look something like this:
q0101#1q401#11q21#1q810.
We start out with this block, where x is the input string and q0 is the start state:

q0x#
The top starts out “lagging” the bottom by one state, and keeps this lag until the
very end stage. Next, for each symbol a in the tape alphabet, as well as #, we have a
“copy” block, which copies it unmodified from one state to the next:
A
A
We also have a block for each position transition the machine can make,
showing how the tape head moves, how the finite state changes, and what happens to
the surrounding symbols. For example, here the tape head is over a 0 in state 4, and
then writes a 1 and moves right, changing to state 7:

q40 1q7
Finally, when the top reaches an accepting state, the bottom needs a chance to
finally catch up to complete the match. To allow this, we extend the computation so that
once an accepting state is reached, each subsequent machine step will cause a symbol
near the tape head to vanish, one at a time, until none remain. If qf is an accepting
state, we can represent this with the following transition blocks, where a is a tape
alphabet symbol:

58

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

qfa
aqf
q
f
q
f
There are a number of details to work out, such as dealing with boundaries between
states, making sure that our initial tile goes first in the match, and so on, but this shows
the general idea of how a static tile puzzle can simulate a Turing machine computation.
5.5 NP PROBLEMS
In computational complexity theory, NP is one of the most fundamental
complexity classes. The abbreviation NP refers to “nondeterministic polynomial time.”
Intuitively, NP is the set of all decision problems for which the instances where the
answer is “yes” have efficiently verifiable proofs of the fact that the answer is indeed
“yes”. More precisely, these proofs have to be verifiable in polynomial time by a
deterministic Turing machine. In an equivalent formal definition, NP is the set of
decision problems where the “yes”-instances can be accepted in polynomial time by a
non-deterministic Turing machine. The equivalence of the two definitions follows from
the fact that an algorithm on such a non-deterministic machine consists of two phases,
the first of which consists of a guess about the solution, which is generated in a non-
deterministic way, while the second consists of a deterministic algorithm that verifies or
rejects the guess as a valid solution to the problem. The complexity class P is contained
in NP, but NP contains many important problems, the hardest of which are called NP-
complete problems, whose solutions are sufficient to deal with any other NP problem in
polynomial time. The most important open question in complexity theory, the P NP
problem, asks whether polynomial time algorithms actually exist for NP-complete, and
by corollary, all NP problems. It is widely believed that this is not the case.
5.5.1 Formal definition
The complexity class NP can be defined in terms of NTIME as follows:

59

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

Alternatively, NP can be defined using deterministic Turing machines as verifiers. A


language L is in NP if and only if there exist polynomials p and q, and a deterministic
Turing machine M, such that
 For all x and y, the machine M runs in time p(|x|) on input (x,y)
 For all x in L, there exists a string y of length q(|x|) such that M(x,y) € 1
 For all x not in L and all strings y of length q(|x|), M(x,y) € 0
5.6 P PROBLEMS
5.6.1 Class p-problem solvable in polynomial time:

5.6.2 Non deterministic polynomial time


A nondeterministic TM that never makes more than p(n) moves in any sequence of
choices for some
• NP is the set of languags that are accepted by polynomial time NTM’s
• Many problems are in NP but appear not to be in p.
• One of the great mathematical questions of our age: is there anything in NP
that is not in
5.6.2.1 NP-complete problems
If We cannot resolve the “p=np question, we can at least demonstrate that certain
problems in NP are
• These are called NP-complete.
• Intellectual leverage: Each NP-complete problem’s apparent difficulty reinforces
the belief that they are all hard.
5.6.2.2 Methods for proving NP-Complete problems
• Polynomial time reduction (PTR): Take time that is some polynomial in the input
size to convert instances of one problem to instances of another.
• If P1 PTR to P2 and P2 is in P1 the so is P1.

60

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

• Start by showing every problem in NP has a PTR to Satisfiability of Boolean


formula. Then, more problems can be proven NP complete by showing that
SAT

5.7 UNIVERSAL TURING MACHINE

A Turing Machine is the mathematical tool equivalent to a digital computer. It was


suggested by the mathematician Turing in the 30s, and has been since then the most
widely used model of computation in computability and complexity theory.

The model consists of an input output relation that the machine computes. The
input is given in binary form on the machine's tape, and the output consists of the
contents of the tape when the machine halts. What determines how the contents of the
tape change is a finite state machine (or FSM, also called a finite automaton) inside the
Turing Machine. The FSM is determined by the number of states it has, and the
transitions between them.

At every step, the current state and the character read on the tape determine the
next state the FSM will be in, the character that the machine will output on the tape
(possibly the one read, leaving the contents unchanged), and which direction the head
moves in, left or right.

The problem with Turing Machines is that a different one must be constructed for
every new computation to be performed, for every input output relation.

This is why we introduce the notion of a universal turing machine (UTM), which along
with the input on the tape, takes in the description of a machine M. The UTM can go on
then to simulate M on the rest of the contents of the input tape. A universal turing
machine can thus simulate any other machine.

61

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

5.7.1 Construction of Universal Turing Machine

It is easiest to describe the Universal Turing Machine U as a multitape TM with


tapes and operation (moves) described below:
(i) Tape 1 – keeps the transitions d of M encoded in binary, that is tape symbol X i of M
is represented by 0i, and tape symbols will be separated by single 1’s along with the
string w.
(ii) Tape 2 – keeps a binary string w (input of M) where M’s 0’s are encoded as 10, 1’s
as 100.
(iii) Tape 3 – holds the state of M, with state q, represented by I 0’s.
Other tapes are scratch tapes. The operation of U can be summarized as follows:
(i) Examine the Tape 1 to make sure that the code for M is a legitimate code for some
TM. If not, U halts without accepting. Since invalid codes are assumed to represent the
TM with no moves, and such a TM accepts no inputs, this action is correct.
(ii) Initialize Tape 2 for the input string w where the blanks of M (encoded as 1000)
could be replaced by U’s own blank symbol.
(iii) Place 0, as the start state of M, on Tape 3, and move the head of U’s second tape
to the first simulated cell.
(iv) To simulate a move of M, U searches on its first tape for a transition
0 10 10 10l10m, such that 0i is the state on tape 3, and 0j is the tape symbol of M that
i j k

begins at the position on tape 2 scanned by U. This transition 0 i10j10k10l10m is the one
M would next make.
we should:
(a) Change the contents of tape 3 to 0k (next state). To do so, U first erases all the 0’s

62

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

on tape 3 to blanks, and the copies 0k from tape 1 to tape 3.


(b) Replace 0j on tape 2 by 0l; that is, change the tape symbol of M. If more or less
space is needed (i.e., i1j), use the scratch tape and shift contents appropriately to
manage the spacing.
(c) Move the head on tape 2 to the position of the next 1 to the left or right,
respectively, depending on whether m=1 (move left) or m=2 (move right). Thus, U
simulates the move of M to the left or to the right.
(v) If M enters its accepting state, then U accepts.
In this manner, U simulates M on w.
5.7.2 Theorem
U accepts the coded pair <M,w> if and only if M accepts w, i.e., Lu=L(U) is RE.
Tape 1: encoded simulated TM M
Tape 2: encoded its input w
Tape 3: encoded its state q
Tape 4: and others: scratch tapes
M(encoded moves of M)

Finite control of U
Organization of the Universal Turing Machine U as a Multitape TM.

63

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

5.7.3 Undecidability of Universal Language

64

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)


lOMoARcPSD|5597675

QUESTION BANK
PART A
1. What is post correspondence problem?
2. What is Polynomial Time?
3. Discuss to write the Class P.[May/June 2016]
4. Discuss the Class NP.
5. What is the Time Complexity of the Class NP of NDTM?
6. Discuss to write the definition of Class NP- Completeness.[May 2017]
7. What is P Versus NP Problem?
8. Write the definition of Class NP- Completeness.
9. What is NP-Hard and NP-Complete?
10. Write the properties of NP-Hard and NP-Complete.[Nov 2016]
11. What is NP- Complete? Write its properties.
12. What is Undecidable theory?
13. Differentiate between recursive and recursively enumerable
languages.[May/June 2016, Nov/Dec 2017]
14. What do you mean by Universal Turing Machine?[Apr/May 2018]

PART – B & C

1. Explain the Post Correspondence Problem in detail. [Nov/Dec 2014,Nov/Dec 2013,


Nov/Dec 2012, Apr/May 2010,May/June 2016]
2. Write a note on NP Problems.[Nov/Dec 2012]
3. Prove that the universal language is recursively enumerable but no recursive.[May
2017,May/Jun 2014,Apr/May 2009,Nov/Dec 2017]
4. Prove that the Halting Problem is undecidable. [Nov/Dec 2012,Nov/Dec 2017,
Apr/May 2018]
5. Prove that there exists a recursively enumerable language whose compliment if
NOT recursively enumerable.
6. What is Universal Turing Machine? Bring out its significance. Also construct a
Turing machine to add two numbers and encode it.[May/June 2016,Nov/Dec 2016,
Nov/Dec 2017]

65

Downloaded by J.Ruby Elizabeth (ruby_253@yahoo.co.in)

You might also like