Professional Documents
Culture Documents
Cs8501 - Theory of Computation - by DR W T Chembian
Cs8501 - Theory of Computation - by DR W T Chembian
Cs8501 - Theory of Computation - by DR W T Chembian
UNIT V UNDECIDABILITY
Non Recursive Enumerable (RE) Lan ua e – Undecidable Problem with RE –
Undecidable Problems about TM – Post‘s Correspondence Problem, The Class
P and NP.
TOTAL :45PERIODS
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.
Department of Computer Science and
Engineering
Regulation: 2017
TABLE OF CONTENTS
Sl.no Topic Page No
a. Aim & Objective of the subject 1
b. Detailed Lesson Plan 2
Unit I- Introduction To Compilers
c. Part A 4
d. Part B 8
1. Language Processor 8
2. Software Tools used in Compilation 9
3. Analysis Part of Compilation 10
4. Phases Of Compiler 11
5. Cousins Of Compiler 16
6. The Grouping Of Phases 18
7. Compiler Construction Tools 18
Unit II- Lexical Analysis
e. Part A 20
f. Part B 23
8. Need and Role of Lexical Analyzer 23
9. Input Buffering 25
10. Expressing Tokens by Regular Expressions 26
11. Language for Specifying Lexical Analyzer 31
12. Regular Expression to DFA 33
U it III- Syntax Analysis
g. Part A 35
h. Part B 39
13. Need and Role of the Parser 39
14. Various Terminologies in Parsing 41
15. Context Free Grammars 42
16. Writing a Grammar 45
17. Recursive Descent Parser 48
18. Predictive Parser 50
19. Construction of Predictive Parsing Table 53
20. Shift Reduce Parser 55
21. LR Parser 58
22. Construction of SLR Parsing Table 61
23. Construction of LALR Parsing Table 65
24. YACC-Design of a Syntax Analyzer 68
Unit IV- Syntax Directed Translation & Runtime Environment
i. Part A 71
j. Part B 74
25. Source Language Issues 74
26. Storage Organization 76
27. Storage Allocation 77
28. Type Systems 81
29. Specification of a Simple Type Checker 86
30. Syntax Directed Definition 88
31. Construction of Syntax Tree 92
32. Parameter Parsing 94
33. Design of a Predictive Translator 96
Unit V- Code Optimization and Code Generation
k. Part A 100
l. Part B 103
34. Principal Sources of Optimization 103
35. DAG 108
36. Optimization of Basic Blocks 113
37. Global Data Flow Analysis 114
38. Issues in the Design of A Code Generator 122
39. A simple Code Generator Al orithm 124
40. Peephole Optimization 127
m. Industrial / Practical Connectivity of the subject 130
41. University Question papers
AIM AND OBJECTIVE OF THE SUBJECT
1
DETAILED LESSON PLAN
TEXT BOOKS:
1. Hopcroft J.E., Motwani R. and Ullman J.D, “Introduction to Automata Theory, Languages
and Computations”, Second Edition, Pearson Education, 2008. (UNIT 1,2,3)
2. John C Martin, “Introduction to Languages and the Theory of Computation”, Third Edition,
Tata McGraw Hill Publishing Company, New Delhi, 2007. (UNIT 4,5)
REFERENCES:
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
Introduction- Basic Mathematical Notation TI
1 and techniques 1 1
Minimization of DFA T1
8 1 8
2
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
Grammar Introduction T1
11 1 11
Types of Grammar T1
12 1 12
3
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
29 Computable languages and functions 1 33 T1
4
UNIT I- FINITE AUTOMATA
Introduction- Basic Mathematical Notation and techniques- Finite State systems – Basic
Definitions – Finite Automaton – DFA & NDFA – Finite Automaton with €- moves –
Regular Languages- Regular Expression – Equivalence of NFA and DFA – Equivalence
of NDFA‟s with and without €-moves – Equivalence of finite Automaton and regular
expressions –Minimization of DFA- - Pumping Lemma for Regular sets – Problems
based on Pumping Lemma.
PART-A
1. Define the following:
a. Symbol
A symbol is an abstract entity. Letters and digits are symbols.
b. String:
A string is a finite sequence of symbols.
Eg: abc, dog are strings
c. Language:
A language is a set of strings of symbols from one alphabet.
Ф, { ϵ} are languages.
Alphabet:
An alphabet is a finite set of symbols.
2. What is relation?
A binary relation is a set of pairs. The first component of each pair is
chosen from a set called the domain and the second component of each pair is
chosen from a set called a range.
What are the properties of relation?
a. Reflexive:
If aRa for all a in S
b. Irreflexive:
aRa is false for all a in S
c. Transitive:
aRb and bRc imply aRc
d. Symmetric: aRb
implies bRa
e. Asymmetric:
aRb implies that bRa is false
5
DR W T CHEMBIAN
3. What is an equivalence
relation? A relation R that is
i. Reflexive
ii. Symmetric
iii. Transitive
is said to be an equivalence relation.
4. What are the methods of formal proof?
i. Deductive proof
ii. Reduction to definition
iii. Other theorem forms
iv. Theorems that appear not to be if-then statements
5. What are the applications of theory of computatio ?
i. Compiler design
ii. Robotics
iii. Artificial intelligence
iv. Knowledge engineering
6. What is finite state system?
Finite state system:
Finite
control
M=(Q,Σ,δ,q0 ,F)
6
Where
q0- in a q is a
(NFA) NFA :
M = (Q,Σ,δ,q0,F)
Qx Σ-> 2Q
ε-closure(q) is the set of all vertices p such that there is a path from q to p.
1. concatenation :
L* = U L i
Lo = {E}
L i= L i-1 L1
ie. One or more number of occurrences of a string in L
Regular Expression:
Pumping lemma:
Let L be a regular set , then there is a constant n and z is any word in L and |Z|>- n
, we can write z = uvw in such a way
that |uv|<- n
8
PART-B
1.A INTRODUCTION
1. Write short notes on Strings , Alpbhapets and Languages.
Introduction
Strings, Alphabets and Languages
Symbol :
A symbol is abstract entity.
Letters and digits are examples of symbols.
String :
A string or word is finite sequence of symbol.
Example
a, b and c are symbols and abcd is a string.
The length of a string w is the number of symbols composing the string.
It is denoted as w
Example :
abcd has length 4
The empty string E, the string consist ng of zero symbols E =0.
A prefix of a string is any number of leading symbols of the string.
Example :
String abc has
prefixes, E, a, ab, abc.
A suffix is any number of t ailing symbols of that string.
Example :
String abc has suffix s
E, c, bc, abc
A prefixor suffix of a string other than the string itself is called a proper prefix or
suffix.
The concatenation of two strings is the string formed by writing the first followed by
the second without space.
For eg.
Concatenation of dog and house is doghouse
The empty string is the identity for concatenation operator
w w w
Alphabet :
An alphabet is a finite set of symbols.
Language :
9
A language is a set of string of symbols from some one alphabet.
The empty set φ and the set consisting of the empty string are languages.
The set of all string over a fixed alphabet , this language is denoted by *
Example
1. a
* , a, aa, aaa,...
2. 0,1
* , 0,1, 01,10, 00,11, 000 , 000 ,...
Set Notation :
Set is a collection of objects without repetition.
Finite sets may be specified by two forms
i. listing their members between brachets.
ii. Set former
x|p x
x in A|p x
If every member of A is a member of B, then we write A B and say A is
contained in B.
If A B but A B , that is every member of A is in B and there is same member of B
that is not in A, then we write A B .
A and B are equal if they have same members That is A = B iff A B nad BA .
Operations on Sets :
1. A B , the union of A nd B is
x|x is in A of x is in B
2. A B , the intersection of A and B is
x|x is in A and x is in B
3. A – B, the difference of A and B is
x|x is in A and x is not in B
4. A x B, the Cartesian product of A and B, is the set of ordered pairs (a, b) such that
a is in A and b is in B.
5. 2A , is the power set of A is the set of all, subsets of A
Example :
Let A = {1, 2}
B = {2, 3}
1. A B = {1, 2, 3}
10
2. A B = {2}
3. A – B = {1}
4. A x B = {(1, 2), (1, 3), (2, 2), (2, 3)}
5. 2 = 1,2,1, 2
A
If A and B have n and mmembers respectively, then
A x B has nm members
2A has 2n members.
Relations :
A binary relation is a set of pairs.
The first component of each pair is chosen from a set called
the domain and the second
component of each pair is chosen from a set called a range.
If R is a relation and (a, b) is a pair in R then we write a R b.
Properties of Relations :
We say a relation R on set S is
1. Reflexive
if aRa for all a in S
2. Irreflexive
if aRa is false for all a in S
3. Transitive
if aRb and bRc imply aRc
4. Symmetric
if aRb implies bRa
5. Asymmetic
if aRb implies that bRa is false.
Any asymmetric relation must be irreflexive.
Equivalence relation :
A relation R that is
i. Reflexive
ii. Symmetric
iii. Transitive
is said be an equivalence relation.
Closure of relations :
The transitive closure of R, denoted Rt is defined by
1) If (a, b) is in R, then (a, b) is in R +
2) if (a, b) is in Rt and (b, c) is in R then (a, c) is in R +
3) Nothing is in R+, unless it follows from (1) and (2)
11
The reflexive and transitive
closure of R denoted R+ is defined
as R+ U a, a|a is in s
Example :
Let R = {(1, 2), (2, 2), (2, 3)} be a relation on the set {1, 2, 3}
R+ = {(1, 2), (2, 2) (2, 3), (1, 3)}
R* = {(1, 2), (2, 2), (2, 3), (1, 3), (1, 1) (3, 3)}
Graphs :
A graphconsist of a finite set of verticles V and a set of paris of vertices E called
edges.
Graph is denoted as G = (V, E)
A path in a graph is a sequence of verticle V1, V2, V3, …., Vk k 1, such that there
is an edge (Vi, Vi+1) for each I |i k
Directed Graphs:
of a finite set of vertices V and a set of ordered
A directed graph or digraph consists
pairs of vertices E called arcs.
The arc from V W is denoted as V W
If V W is an arc, we say
V Pr edecessorof W
W Successorof V
Trees:
A tree is a digraph with the following properties
1. Three is one vertex, called the root that has no predecessor and from which
there is a path to every vertex.
2. Each vertex oth r than the root has exactly one predecessor.
3. The successor of each vertex is ordered from the left.
If there is a path from vertex V 1 to Vertex
V 2 then V 2 is said to be descendant of
V1 and V1 is said to be an ancestor of V2.
Explain the four ways of Theorem Proving.
Explain the methods of Formal Proof
12
In format proof
We try to prove that statement B is true because statement A is true.
The statement A is called hypothesis and B is called conclusion statement.
The four ways of Theorem Proving
(or)
Methods of formal proof.
(1) Deductive Proof
(2) Reduction Proof
(3) Other theorem forms
(4) Theorems that appear not to be if then statement.
Deductive Proof :
A deductive proof consists of a sequence of statements whose truth leads us from
some initial statement called the hypothesis or the given statement (s) to a
conclusion statement.
that is proved when we go from a hypothesis H to a conclusion C is the
The theorem
statement.
“If H then C”
We say that C is deducted from H
The hypothesis may be true or false hypically depending on values of its parameters.
Theorem 1
If x 4 then 2 x x 2
Proof :
The hypothesis H is x 4
The hypothesis has a parameter x and thus is neither true of false.
eg. H is true for x = 6 and false x = 2
The conclusion C is 2 x x 2
This statement also uses parameter x and is true for certain values of x and not others.
The intuitive argument that tells the conclusion 2 x x 2 will be true whenever x 4
The left side 2x doubles each time x increase by 1
x 12
The right side x2 grows by the ration
x
Hence if x 4 then 2 x x 2 , for all integers x ie 2 x x 2 is deducedfrom x 4
Theorem 2 :
13
If x is the sum of squares of four positive integers, then 2 x x 2
Statement Justification
1 x = a2 + b2 + c2 + d2 Given
2 a 1, b 1, c 1, d 1 Given
Reduction to definitions
sure how to start a proof conv rt all terms in the hypothesis to their
If you are not
definitions.
Theorem :
Let S be a finite subset of some inf n te set Let T be the complement of S with
respect to Then T is infinite.
Proof :
Original Statement New Statement
SUT = U and
T is the complement of S
S T
We use a common proof technique called “Proof by contradiction”
In this proof, the contradiction of the conclusion is “T is finite”
Let us assume T is finite,
|T| = m for some integer m
|S| = n
Since SUT = U and S T the elements of U are exactly the elements of S and T
Thus there must be n + m elements of U |U| = n + m
14
The statement that U is finite contradicts the given statement that U is infinite
Thus our assumption is contradiction
So T is infinite
Other Theorem Forms :
Ways of saying “if – Then”
The other ways in which if H then C might appear.
1. H implies C
2. H only if C
3. C if H
4. whenever H holds, C follows.
If – And – only – If statements :
The statement of the form
A if and only if B is actually two if – then stateme ts.
(i) if A then B and
(ii) if B then A
Theorems that appear not to be if – then statem nts :
Sometimes we find a theorem that appear ot to have a hypothesis.
An example is the well-known fact from the trigonometry.
Theorem
Sin 2 Cos 2 1
Additional Forms of Proof :
1. Proofs about sets.
2. Proofs by contradiction.
3. Proofs by counter example.
Proving Equivalences about s ts :
If E and F are two sets, then the statement E=F means the two sets represented are the
same.
Every element in the set epresented by E is in the set represented by F
And every element in the set represented by F is in the set represented by E.
Example :
The commutative law of union says that we can take the union of two sets R and S in
either order.
i.e., RUS = SUR
The commutative law of union says E = F
The proof of any statement that asserts the equality of two sets E = F, if follows the form
of any if – and – only – if – proof
15
1. Proof that if x is in E then x is in F
2. Proof that if x is in F then x is in E
Theorem :
R (S T) (R S) (R T)
Proof :
The two set of expressions involved are
E R (S T)
R (R S) (R T)
Steps in the part R (S T) ddd
1 x is in R U(S T) Given
1 x is in (R S) (R T) Given
16
The Contrapositive :
The contrapositive of the statement “if H then C” is “if not C then not H”
A statement and its contrapositive are either both true or both false.
To see “if H then C” and if not C then not H are logically equivalent.
There are four cases to consider
1. H and C both true
2. H true and C false
3. C true and H false
4. H and C both false
Proof by contradiction :
Another way to prove a statement of the form.
“if H then C is to prove the statement.
H and not C implies false hood.
Start by assuming both the hypothesis H and the negation of the conclusion C
Completethe proof by showing that som thing known to be false follows logically from
H and C
This form of proof is called proof by contradiction.
Counter example :
Statements that have no parameters, or that apply to only a finite number of values of
its parameter are called observations.
It is easier to prove that a statement is not a theorem than to prove it is a theorem.
Example
All primes are odd.
More formally, we might say
if integer x is a prime, then x is
odd Example
There is no pass of integers a and b such
that a mod b = b mod a
2.A.BASIC DEFINITIONS DFA AND NFA
of DFA and NFA and the language accepted by DFA
Describe the basic definitions
and NFA with an example.
Finite state systems :
17
Automaton is a mathematical model of a system with discute inputs and
The finite
outputs.
The system can be in a any one of a finite number of internal configuration or states.
that is
The state of the system summarixes the information concerning past inputs
needed to determine the behavior of the system on subsequent inputs.
The primaryexample of finite automaton is a switching circuit such as control unit of
a computer.
number of gates each of which can be in
A switching circuit is composed of a finite
one of two conditions usually 0 and 1
n
The state of a switching network with n gates is thus any one of the 2
assignments of 0 or 1 to the various gates.
Text editors and the lexical analyzers found in most compiters are designed as
finite state systems.
01 0 1 0 0 0
Finite Co trol
Basic Definitions :
Deterministic finite automata :
A finite automator (FA) consists of a finite set of states and a set of transitions from state to
state that occur on an inpul symbol chosen from an alphabet
For each input symbol there is exactly one transition out of each state.
One state denoted qo is the initial state in which the transition starts.
Some states are design ted s final states or accepting states.
The Deterministic finite automata can be represented as a transition diagram or transition
table.
The directed graph is used to represent the transition diagram.
The vertices of the graph correspond to the states of FA
If there is a transition
from state q to state p on input a there is an are labeled a
from state q to state p
a string x if the sequence of symbols of x leads start state to
The FA accepts
final state.
Example :
18
The initial state, qo is indicated by the arrow labeled start.
The final state indicated by the double circle.
The FA accepts all string of 0‟s and 1‟s in which both the number 0‟s and the number of
1‟s are even.
for eg.
The string accepted by the above FA, 11, 1100, 00, 0000, 1111, 110110
Formal Definition of DFA :
We formally denote a finite automaton by a 5 tube. M =
Q, , , qo , F
Q is a finite set of states
is a finite input alphabet
q
o in Q is the initial state
F F Q
is the set of final states
Qx
is the transition function m pping from
to (q, a)
ie is a state for each state q and input symbol
a
FA is denoted as a finite control
0 1 0 1 0 0 0
Finite Control
Finite control which is in same state from Q reads a sequence of symbols from
written on a tape.
(q, a)
In one move, the FA in state q, scanning a symbol a enters state and moves
its head one symbol to the right.
We define a function from
19
Q x *toQ
(q, w)
is the unique state p such that there is a path in the transition diagram from
q to p labeled w
Formally we define
(q, t) q
(1)
(2) for all string w and input symbols a
This FA is denoted as M
= (Q, , , qo , F) where
q ,q ,q ,q
Q= 0 1 2 3
0,1
q0 = q0
F= q0
is given as a transition table
s01
20
q0 q2 q1
q1 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2
To find the string accepted by DFA, suppose w = 110101 is input to M we have to
(q ,110101 )
find 0
The input sequence a1, a2, a3 …. an is accepted by NFA, if the transition leads
from the initial state of final state.
Formal Definition of NFA :
Formally we denote a NFA by a 5 – tuple
, , q , F)
M = (Q, 0
where
Q set of states
is a finite input alphabet
q
o in Q is the initial state
F F Q
is the set of final states
Q x to
is the transition function mapping from
Q x 2Q
The function can be extended to a function mapping from
Q x * to 2Q and
(ii)
Example :
Consider the NFA
22
Let the input w = 01001
Solution :
Q q0 , q1, q2 , q3 , q4
0,1
q0 = q0
F = {q2, q4}
:
0 1
q0 {q0, q0,} {q0, q1,}
q1 {q2}
q2 {q2} {q2}
q3 {q4}
q4 {q4} {q4}
(q0,01001) q
(q0 , 0) {q, q3 )
(q0 , 01)((q0, 0),1)
= ({q0 , q3 },1)
= (q0 ,1) (q3 ,1)
= {q0,q1)
= {q0, q1}
(q0 , 010 )((q0, 01), 0)
= ({q0 , q1 }, 0)
23
W T CHEMBIAN
= (q0 , 0) (q1 , 0)
= {q0,q3)
= {q0, q3}
= ({q0 , q3 }, 0)
= (q0 ,1) (q3 , 0)
= {q0,q3) {q4}
= {q0, q3, q4}
= ({q0 , q3 , q 4 },1)
= (q0 ,1) (q3 ,1) (q4 ,1)
= {q0,q1) {q4}
= {q0, q1, q4}
(q , 01001 )
contains a state in F so the input str ng 01001 is accepted by the NFA.
0
F1 is the set of all states in Q1containing a final state of M.
1
An element of Q will be denoted by [q1, q2, ……….q1) are in Q.
2is a single state of the DFA corresponding to the set of states of the NFA
q01 = [q0]
1 ( [q1], a) = [p1]
iff (q1, a) {p1}
1 ([q1, q2, … qi], a) = [p1, p2, …. pj]
iff 1 ([q1, q2, … qi], a) = [p1, p2, …. pj]
It is easy to show by induction on the length of the input string x that
1 (q01, x) = [q1, q2, …qj]
iff
1 (q 0 , x) = [q1, q2, …qj]
Basis :
The result is trivial for 1 x 1 = 0, since q01 = [q0] and x must be
1 ([q0 ],[q 0 ]
iff
( q0 ) q0
Induction :
Suppose that the hypothesis is true for inputs of length m or less
Let xa be a string of length m + 1 with a in then
iff
1 (q01, xa) [r1 , r2 ,...rk ]
iff
(q0 , xa) [r1 , r 2 ,... r k ]
which establishes the inductive hypothesis
1
1 (q 01 , x) is in F exactly when
(q0 , x) contains a state in F
L (M) = L (M)
26
DR W T CHEMBIAN
DR W T CHEMBIAN
q0 {q0} {q1}
q1 {q1} {q2}
[q2] {q2}
- closue (q)
-closue (q) is the set of all vertices p such that there is a path from q to p labeled
Example :
- closure (q0) = {q0, q1, q2}
ie) the path consisting of q0 alone is a from q0 to q0 with all arcs labeled .
Path q0 – q1, shows that q1 is in closure. (q0)
Path q0 – q1 – q2 shows that q2is in -closure.
can be defined as follows :
1. (q,) closure(q)
2. for w in * and a in
(q, wa) = - closure
(p) Where p = p |
For some p in ((q, w)
3. (R, a) (q, a)
q in R
4. (R, W) (q, w)
q in R
We can define L (M) as
The language accepted by M ( Q, , , q0 , F) to be
{w| q (q, ) contains a state in F}
Example :
Consider the NFA
27
DR W T CHEMBIAN
DR W T CHEMBIAN
Prove that “A language accepted by some NFA with - moves iff L is accepted
by without - moves NFA
Theorem :
If L is accepted by an NFA with -transitions then L is accepted by an NFA
without - transition.
Proof :
Let M = (Q, , , q0 , F) be an NFA with - transitions.
Now we have to define NFA without - move M‟
28
DR W T CHEMBIAN
DR W T CHEMBIAN
M1 = (Q1, 1 , 1 , q0 , F1 )
Where F1 = FU{q0} if - closure (q0) contains a state of F
=F Otherwise
It is easy show by induction on the length of the input string .We have to prove
1 (q0 , x) (q0 , x)
This statement may not be true for x
1 (q0,) {q 0 }
while (q0 ,) closure (q0 )
Therefore we begin our induction at 1
Basis :
| x | = 1 Then
x is a symbol a
1 (q0 , a) (q0 , a) by the definition of 1
Induction :
| x | >1 Let x = wa
1(q0, wa) 1((q0, w),a)
= 1 (p, a)
= 1 (q, a)
q in p
= (q, a)
q in p
= (p, a)
Consider the NFA with - moves
W T CHEMBIAN
DR W T CHEMBIAN
Solution :
Given NFA with - moves
M = ({q0, q1, q2}, {0, 1, 2, }, , q0, {q2})
Now we have to define NFA without - move
M1 = (Q1, , 1, q0, F1)
Q = {q0, q1, q3}
{0,1, 2}
F1 = {q0, q2} - closure (q0) = {q0, q1, q2} contains a state of F.
1
0 1 2
q2 {q2}
closure(q1 ) {q1, q2 }
closure(q2 ) {q2 }
(q0,) = closure(q0 )
= {q0, q1, q2}
1 (q0, 0) = closure ((q0 , 0))
= closure (((q0 ,), 0)
= closure (({q0 , q1 , q 2 }, 0)
= closure ((q0 , 0) (q1 , 0) (q2 , 0))
= closure (({q0 } )
= {q0, q1, q2}
DR W T CHEMBIAN
DR W T CHEMBIAN
DR W T CHEMBIAN
DR W T CHEMBIAN
= closure (({q2 ), 2)
= closure (q2 )
=
Example 2 :
Construct a NFA without - moves from NFA w th - moves
Solution :
closure (q0) = {q0, q1}
closure (q1) = {q1}
Let Given NFA with moves
M = (Q, , , q0 , F)
We have to find M‟, NFA without move
M = (Q, , 1 , q0 , F1 )
closure(q0) containsa statein F
F1 = {q0, q1}
F1 = F {q0 }
1 (q 0 ,) closure (q 0 )
= {q0, q1}
(q 0 , 0) = closure (1 (1 (q 0 ,), 0)
1
DR W T CHEMBIAN
DR W T CHEMBIAN
q1 {q1}
33
DR W T CHEMBIAN
DR W T CHEMBIAN
Proof :
We show by induction on the number of operator in the regular expression r that
there exists an NFA with - transitions having one final state and no transitions
out of this final state such that
L (M) = L (r)
Basis :
For regular expressions having zero operators.
The expression r must be , , or a forsomea in
Induction :
One or more operators in the regular expressions.
Assure that the theorem is true for regular expression with fewer that I operators.
i 1
Let r have I operators.
Case 1 :
r = r1 + r2
Both r1 and r2 must have fewer than i operator
Thus there are 2 NFA‟s
M1 = (Q1 , 1 , 1 , q1,{f 1} with
= L (M1) = L (r1)
Assume Q1 and Q2 are disjoint
Let q0 be a new initial state
f0 be a new initial state
Now we can construct NFA with
M = Q1, Q2 {q0, f 0},, 2, , q0,{f 0})
where is defined by
(i) (q0 ,) {q1, q 2 }
(ii) (q, a) 1 (q, a) for q in Q1 {f 1}and a in 1 {}
(iii) (q, a) 2 (q, a) for q in Q2 {f 2}and a in 2 {}
(iv) 1 (f 1,) 2 (f 2,) {f 0}
34
DR W T CHEMBIAN
DR W T CHEMBIAN
Hence
L (M) = L (M1) U L (M2)
Any path in the transition diagram of M from q0 to f0 must begin by going to
either q1 or q2on . If the path goes to q1 it may follow any path in M1 to f1 and then go
to f0 on
Hence L (M) = L (M1) U L (M2)
Case 2 :
r = r1 r 2
Let M1 and M2 be 2 NFA‟s
M1 = Q1 , 1 , 1 , q1,{f 1}) with
L (M1) = L (r1)
and
M2 = Q2 , 2 , 2 , q2 ,{f 2}) with
L (M2) = L (r2)
Assume Q1 and Q2 are disjoi t
No we can construct NFA with
L (M) = L (r)
M = (Q, Q2 , , 2 , ,{q1},{f 2})
where
is defined as
(i) (q, a) 1 (q1, a) for q in Q1 {f 1}and a in 1 {}
(ii) (q, a) (q1, a) for q in Q2 {f 1}and a in 2 {}
(iii) (f 1,) {q2 }
Every path in M from q1 to f2 is a path labeled by some string x form q1 to f1
followed by the edge from f1 to q2 labeled followed by a path labeled by some
string y form q2 to f2.
M
M1 M2
35
DR W T CHEMBIAN
DR W T CHEMBIAN
Thus
L (M) = L (M1) L (M2)
ie. L (M) = {xy | x is in L (M1) and y is in L (M2 )}
Case (iii)
r = r1 *
Let M1 = (Q1 , 1 , 1 , q1,{f 1}) with
L (M1) = L (r1)
Now we can construct NFA
Let M1 = (Q1 {q0 , f 0}, 1 , 1 , q0 ,{f 0}) with
L (M) = L (r)
where
q0 be an new initial state
f0 be an new final state
and is given by
(i) (q0 ,) (f 1,) {q1, f0 }
(ii) (q, a) 1 (q, a) for q in Q1 {f 1}and a in 1 {}
Any path from q0 to f0 consists either of a path from q0 to q1 on followed by some
number of paths from q1 to f1and back to q1 on 1 each labeled by a string in
L (M1) followed by a path from q1 to f1 on a string in L (M1) then to f0 on
Hence :
L (M) = L (M1)
Theorem 2
If L is accepted by DFA, then L is denoted by the regular expression.
Proof :
Let L be the set accepted by accepted by the DFA
36
DR W T CHEMBIAN
DR W T CHEMBIAN
M = ({q1,........, qn }, , , q1, F)
Let
Rijk denote the set of all string x such that (qi , x) q j and (qi , y) = ql for any that is
a prefix of x, then l k
k i.e.) = is the set of all strings that take the FA from state qi to qj without
Rij going
=
R ij R (R ) *R R
ik kk kj ij
The inputs of Rijk are, either
k 1
in
1) Rij
(or)
k 1 k 1
a string Rkj
We must show that for each i, j and k, there exists a regular expression
k k
DR W T CHEMBIAN
DR W T CHEMBIAN
Rn
L (M) = ij
q j in F
Thus L (M) is denoted by the regular expn.
rn rn ..........rn whereF{q , q ,.....q }
ij1 ij2 ijp ji j2 jp
[Nov/DEC 2015]
r4 = r5*
r5 = 1
The NFA for r5 = 1
38
DR W T CHEMBIAN
DR W T CHEMBIAN
39
DR W T CHEMBIAN
DR W T CHEMBIAN
Let k = 0
o
{a |(qi , a) q j
if i j
R ij
{a | (qi , a) q j } {} if i j
r 0
1
11
r0 0
12
r 0
21
r220 0 1
Rijk , Rikk1 (Rkkk1 )*Rkkj1 Rijk1
DR W T CHEMBIAN
DR W T CHEMBIAN
Let K = 2
r11(2) r 121 (r 221 ) *r 211 r111
= 1*0 (0 1) *1*
= 1*
= 1*
r12(2) r 121 (r 221 ) *r 221 r121
= 1*0 (0 1) *(0 1) 1*
= 1*0 (0 1) *1*0
= 1*0(0 1) *
r21(2) r 221 (r 221 ) *r 211 r211
= (0 1) (0 1) *
= (0 1) *
=
r22(2) r 221 (r 221 ) *r 221 r221
= (0 1) (0 1) *(0 1) (0 1)
= (0 1) * (0 1)
= (0 1) *
L (M) = r12(2)
= 1* 0 (0 + 1)*
L (M) = 1* 0 (0 + 1)*
5.MINIMIZATION OF DFA
Write and Explain the algorithm for minimization of DFA. Using the above
algorithm minimize the DFA. [MAY/JUNE 2016]
Discuss on the relation between DFA and Minimal DFA.[NOV/DEC 2015]
Discuss on equivalence and minimization of Automata. S[Nov/Dec 2015]
Minimization of DFA :
There is unique minimum state DFA for every regular set.
Theorem :
The minimum state automata accepting a language L is unique upto an isomorphism
ie) renaming of the states.
41
DR W T CHEMBIAN
DR W T CHEMBIAN
Proof :
Any DFA M = (Q, , , q0 , F) accepting L defines an equivalence relation that is a
refinement of RL
1
Thus the number of states of M is greater than or equal to the number of states of M
1
If equality holds then each of the states of M can be identified with one of the states
of M
Let q be a state of M there must be some x in * such that
Example :
Minimize the following DFA
Solution :
b x
c x x
d x x x
e x x x
f x x x x
g x x x x x x
h x x x x x x
a b c d e f g
Intially an x placed in each entry corresponding to one final state and one final state.
The entries
(c, a), (c, b), (c, d), (c, e), (c, f), (c, g), (c, h)
Now the unmarked pairs are
(a, b) (b, d) (d, e) (l, f) (f, g) (g,
h) (a, d) (b, e) (d, f) (e, g) (f, h)
(a, e) (b, f) (d, g) (e,
b) (a, f) (b, g) (d, b)
43
DR W T CHEMBIAN
DR W T CHEMBIAN
(a, h)
(a, b)
(a, 0) b
(b, g) is unmarked
(b, 0) g
(a,1) f
(f, c) is marked, so mark (a, b)
(b,1) c
(a, b)
(a, 0) b
(b, c) is marked so mark (a, d)
(d, 0) c
(a, l)
(a, 0) b
(b, g) is unmarked
(l, 0) h
(a,1) f
(f, f) is unmarked
(l,1)
f
(a, f)
(a, 0) (b, c) is marked so mark (a, f)
b
(f , 0)
c
(b, g) is unmarked
(a, g)
(a, 0) b (f, e) is unmarked
(g, 0) g
(a,1) f
(g,1) e
(b, g) is unmarked
(a, h)
(a, 0) b (f, c) is marked. So mark (a, h)
(h, 0) g
(a,1) f
(h,1) c
44
DR W T CHEMBIAN
DR W T CHEMBIAN
(b, d)
(b, 0) g
(g, c) is marked. so mark (b, d)
(d, 0) c
(b, e)
(b, 0) g
(g, h) is unmarked
(e, 0) h
(b,1) c
(c, f) is marked. So mark (b, e)
(e,1) f
(b, f)
(b, 0) g
(g, c) is marked. So mark (b, f)
(f , 0) c
(b, g)
(b, 0) g
(g, g) is unmarked
(g, 0) g
(b,1) c
(e, e) is marked. So place an x n (b, g)
(g,
1) e
(b, h)
(b, (g, g) is unmarked
0) g
(h, (c, c) is unmarked.
0) g
(b,
1) c
(h,1) c
(c, h) is unmarked. So place x in (d, e)
(d, e)
(d, 0) c
(e, 0) h
(c, c) is unmarked
(d, f)
(g, g) is unmarked.
(d, 0) c
(f , 0) c
(d,1) g
(f ,1) g
45
DR W T CHEMBIAN
DR W T CHEMBIAN
(d, g)
(d, 0) c
(c, g) is marked. So place an x in (d, g)
(g, 0) g
(d, h)
(d, 0) c
(c, g) is marked. So place an x in (d, g)
(g, 0) g
(d, h)
(d, 0) c
(c, g) is marked. So place an x in (d, h)
(h, 0) g
(e, f)
(e, 0) h
(h, c) is marked. so place x in (e, f)
(f , 0) c
(e, h)
(e,
0) h (h, g) is unmarked.
(h,
0) g (f, c) is marked. So place an x in (e, h)
(e,
1) f
(h,
1) c
(h, g) is unmarked
(e, g)
(f, e) is marked. So place x in (e, g)
(e, 0) h
(g, 0) g
(e,1) f
(g,1) e
(c, g) is marked. So place an x in (f, g)
(f, g)
(f , 0) c
(g, 0) g
(f, h)
46
DR W T CHEMBIAN
DR W T CHEMBIAN
(f , 0) c
(c, g) is marked. So place an x in (f, h)
(h, 0) g
(g, h)
(g, 0) g
(g, g) is unmarked
(h, 0) g
(g,1) e
(e, c) is marked. So place x in (g, h)
(h,1) c
Now the unmarked place are,
(a, e) (b, h) (d, f) (a, g)
(a, e)
(a, 0) b
(b, h) is unmarked
(e, 0) h
(a,1) f
(f, f) is unmarked.
(e,1) f
(a, g)
(a, 0) b
(b, g) is marked. So pace an x n (a, g)
(g,
0) g
(b, h)
(b, (g, g) is unmarked
0) g
(h, (c, c) is unmarked.
0) g
(b,
1) c
(h,1) c
(c, c) is unmarked
(d, f)
(d, 0) c
(g, g) is unmarked.
(f , 0) c
(d,1) g
(f ,1) g
On completion of the table, we conclude that the equivalent states are
a e b h d f
Algorithm :
begin
47
DR W T CHEMBIAN
DR W T CHEMBIAN
for p in F and q in Q-F do mark (p, q) for each pair of disfinct states (p, q)in F x
F or (Q – F) x (Q – F) do
if for some input symbol a
((p, a),(q, a) is marked then begin mark (p, q)
recursively mark all unkarked pairs on the lists of other paurs that are marked at this step.
end.
else
for all input symbols a do
put (p, q) on the list for ((p, a),(q, a) unless
((p, a) (q, a)
end.
Method II
For the above same problem, the DFA can be min m zed using DFA minimization
algorithm.
Solution :
Transition table :
0 1
a b f
b g c
c a c
d c g
e h f
f c g
f c g
g g c
h g c
Step 1
The pair of status (b, h) are same state transition. So b and h are equivalent state.
48
DR W T CHEMBIAN
DR W T CHEMBIAN
b h
0 1
a b f
[b,h] g c
*c a c
d c g
e h f
f c g
g c g
Step 2
The pair of status (d, f) are same state transit on.
d f
0 1 0 1
a b f a [b, h] c
[b,h] g c c a c
[d, c g
*c a c
f]
[d,f] c g
e [b, h] [d, f]
e h f
g g e
f h f
Step e
g g e The pair of states (a, e) are same state transition diagram.
a e
0 1
49
DR W T CHEMBIAN
DR W T CHEMBIAN
h]
[b, h] g c
c [a, e] c
[d, f] c g
g g [a, e]
Thus the minimized FA is
0 i2
is not regular.
|i is an int eger i 1 [Nov / Dec 2015]
Prove that the Languages are not regular. [Nov/Dec 2015]
Pumping lemma for regular sets :
Pumping lemma is a powerful for proving certain languages non-regular.
It is also useful for developing algorithms to answer whether the language accepted by
FA is finite or infinite.
by a DFA M = Q, , , q0, F) with some
If languages is regular it is accepted
particular number of states n.
50
DR W T CHEMBIAN
DR W T CHEMBIAN
Consider an input of n or more symbols a, a 2, … am, m n and for i = 1, 2 … m let
(q0 , a, a 2 .... a i ) qi
the n + 1 states q0, q1, …..qn to be distinct, since there
It is not possible for each of
are only n different states.
Thus there are two integers j and k.
O jk n, such that qj = qk
The path labeled a, a2…. a m in the transition diagram of M.
aj + 1 …. ak is of length atleast 1, and si ce k n , its length is
Since j<k, the string
no more than m.
is a, a2 … am is in L (M) then a, a2… aj then a, a2 … ajak+1 … am
If qm is in F, that
is also in L (M)
Since there is a path from q0 to q m that goes through q j but not around the loop.
(q0 , a,.... a ja k 1 .... a m ) ((q0 , a1 ... a j ), a n 1 .... a m
= (q j , a k 1 ... a m )
= (qk , a k 1 ... a m )
= qm
Similary we can go around the loop, as many times.
Thus a, .. aj (aj+1 … a) i ak+1 … am is in L (M)
Applications of pumbing lemma :
The pumping lemma is useful in proving that certain languages are not regular.
1. Select the language L you wish to prove non-regular and assume that L is
regular.
2. The adversary picks n, the constant mentioned in the pumping lemma.
3. Select a string z in . The choice may depend implicitly on the value of n.
4. The adversary breaks z into u, v and w subject to the constraints that |uv| n
and |v| 1.
5. Achieve a contradiction to the pumping lemma by showing for any u, v and w
determined by the adversary, that there exists an i for which uvw is not in L. I
may then be concluded that L is not regular you selection of i may depend on
n, u, v and w.
6. The formal statement of the pumping lemma,
(L) (n) (z)[z in L and| z | n imphess
and (i ) uviw is in L))]
Lemma :
51
DR W T CHEMBIAN
DR W T CHEMBIAN
Let L be a regular set. Then there is constant n, such if z is any word in L and |z| n,
we may write z = uvw in such a way that
| uv | n
| v | 1and
for all i 0 uvi w is in L
Proof :
Z is a, a2 …. a m
u = a1 , a 2 … a j
v = aj+1 …. ak
w = ak+1 … am
The pumping lemma states that if a regular set contains a long string, z, then it
i
contains infinite set of string of the form uv w.
52
DR W T CHEMBIAN
DR W T CHEMBIAN
put k = 0
uvkw = ai-j bi ai bi
put k = 2
uvkw = ai+j bi ai bi
Since for k = 0, 2, the strings that does not belong to the language L. So the language is
not regular.
2. Show that L 0i2 |i is an int eger i 1 is not regular.
Solution :
1. Assume L = 0i |i is an int eger i1is regular.
2
for k = 0
= On j2 On
2 2
for k = 0, 2 the strings vukw does not belong to the language L. so the language is not
regular.
53
DR W T CHEMBIAN
DR W T CHEMBIAN
PART-C
1.INDUCTIVE PROOFS
1. Prove the following by principle of Induction 02 + 12 + 22 + …. + n2 = n (n
1) (2n 1)
6
[MAY/JUNE 2016]
Use Mathematical induction to solve the problem of Fibonacci series. Also
state the inductive proofs. [MAY/JUNE 2016]
Inductive Proofs :
Theorems can be proved by mathematical induction
Let P(n) be a statement about a non negative integer
The Principal of mathematical induction is that P(n) follows from
(a) P (o)
(b) P (n-1) imples P(n) for n 1
Condition (a) is called the basis and co d tion (h) is called the inductive step.
Example 1 :
Prove by mathematical induction.
n (n 1) (2 1)
02 + 12 + 22 + …. + n2 =
6
Solution
n (n 1) (2n 1)
Let P (n) = 12 + 22 + 32 + ….. n2 =
6
Basic Step
for n = 0
n
L.H.S. i2 = 0
i0
54
DR W T CHEMBIAN
DR W T CHEMBIAN
n 2 n 1 2 2
i = i +n
i0 i0
n (n 1) (2n 1)
= n
2 6
= (n 2 n) (2n 1) 6n 2
6
= 2n3 2n 2 n 2 n 6n 2
6
= 2n 3 3n 2 n
6
= n (2n 2 3n 1)
6
= n (n 1) (2n 1)
6
L.H.S = R.H.S.
Thus by induction it is true for all n
Example 2 :
Prove by mathematical induction.
0 + 1 + 2 + …. + n = n (n 1)
2
Solution
( 1)
Let P (n) = 1 + 2+ 3 + n =
2
Basis Step
for n = 0
n
L.H.S. i=0
i0
n
R.H.S. i = n (n 1)
i0 2
=0
Inductive step
for n = n – 1
n n
i = (n 1)n implies i = n (n 1)
i0 2 i0 2
Since
55
DR W T CHEMBIAN
DR W T CHEMBIAN
n n
i = i+ n
i 0 i0
(n 1)n
= n
2
= (n 1)n 2n
2
= n 2 n 2n
2
=n2 1
2
= n(n 1)
2
L.H.S. = R.H.S.
Thus by induction it is true for all n.
Example 3 :
Prove if x 4 then 2 x x 2 by mathematical inducations
Solution
Basic step :
If x = 4 then 24 42
1616
x = 5 then 25 52
32 25
Inductive step
putx = x + 1
2 x 1 ( x 1)2
2 x.2 ( x 1)2
2 x.2 2 x 2 ( x1)2
2 x 2 x 2 2 x 1 x
2
2 x 1
by x
1
x2 x
1 1
Since x 4, x 4 , where RHS = 2.25
2 x 2 ( x 1) for x 4
56
DR W T CHEMBIAN
DR W T CHEMBIAN
Convert the following NFA to DFA [Nov/Dec 2015]
Example 1:
1. Let M = q0 , q10,1 , , q0 ,q1 be an
NFA where (q0, 0)q0, q1)
[q0, q1] ? ?
To find 1 ([q0 , q1 ], 0
q0 , q1 , 0 = (q0 , 0) (q1 , 0)
= {q0 , q1 }
= {q0, q1}
1([q0 , q1 ], 0) = [q 0 , q1 ]
57
DR W T CHEMBIAN
DR W T CHEMBIAN
M1 = (Q1, 1 , 1 , q 01 , F1 )
Q1 = { [q0], [q1], [q0, q1], }
{0,1}
1
q0 = [q0]
F1 = { [q1], [q0, q1] }
1
0 1
Transition Diagram
58
DR W T CHEMBIAN
DR W T CHEMBIAN
Examples 2 :
Consider the following NFA
a b
q0 {q0, {q2}
q1 }
q1 {q1} {q0}
59
DR W T CHEMBIAN
DR W T CHEMBIAN
[q0, q1] ? ?
[q0, q2] ? ?
[q1, q2] ? ?
[q0, q1, q2 ? ?
]
To find 1 ([q0 , q1 ], a
q0 , q1 , a = (q0 , a) (q1 , a)
= {q0 , q1 } {q1 }
= {q0, q1}
1 ([q 0 , q1 ], a) = [q 0 , q1 ]
To find 1 ([q0 , q1 ], b
q0 , q1, b = (q0 , b) (q1 , b)
= {q 2 } {q0 }
= {q0, q2}
1 ([q 0 , q1 ], b) = [q 0 , q 2 ]
To find 1 ([q0 , q 2 ], a
q0 , q 2 , a = (q0 , a) (q2 , a)
= {q0 , q1 } {q0 }
= {q0, q1}
1 ([q 0 , q 2 ], a) = [q 0 , q1 ]
To find 1 ([q0 , q 2 ], b
q0 , q 2 , b = (q0 , b) (q 2 , b)
= {q2 } {q1, q2 }
= {q0, q1}
= [q1 , q 2 ]
1 ([q0 , q 2 ], b) = [q1 , q 2 ]
60
DR W T CHEMBIAN
DR W T CHEMBIAN
To find 1 ([q1 , q 2 ], a
q1, q2 , a = (q1, a) (q2 , a)
= {q1 } {q0 }
= {q0, q1}
1 ([q1 , q 2 ], a) = [q 0 , q 1 ]
To find 1 ([q1 , q2 ], b
q1, q2 , b = (q1, b) (q2 , b)
= {q0 } {q1 , q 2 }
= {q0, q1, q2}
([q1 , q 2 ], b) = [q0 , q1 , q 2 ]
1
To find 1 ([q0 , q1 , q 2 ], a
q0 , q1 , q 2 , a = (q0 , a) (q1 , a) (q 2 , a)
= {q0 , q1 } {q1 } {q0 }
= {q0, q1,}
([q 0 , q1 , q 2 ], a) = [q0 , q1 , ]
1
To find 1 ([q0 , q1 , q 2 ], b )
q0 , q1 , q 2 , b= (q0 , b) (q1 , b) (q 2 , b)
= {q 2 } {q0 } {q1 , q 2 }
= {q0, q1, q2}
([q 0 , q1 , q 2 ], b) = [q0 , q1 , q 2 ]
1
a b
q1 [q1] [q0]
61
DR W T CHEMBIAN
DR W T CHEMBIAN
62
DR W T CHEMBIAN
DR W T CHEMBIAN
UNIT II - GRAMMARS
Grammar Introduction– Types of Grammar - Context Free Grammars and Languages–
Derivations and Languages – Ambiguity- Relationship between derivation and derivation
trees – Simplification of CFG – Elimination of Useless symbols - Unit productions - Null
productions – Greiback Normal form – Chomsky normal form – Problems related to CNF
and GNF.
PART-A
Grammar G is defines as
G= (V,T,P,S) Where
V = Set of variables or not terminals
T = Set of Terminals
P= set of productions of the form A -> α.
Where A -> is a variable
α-> string of terminals and non terminals
S = a special variable, called start symbol.
2. What is derivation?
If A-> β is a production and α and are any strings than the derivation is
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
E=> E+E
=>id+E
=> id+E*E
=> id+id*E
=> id+id*id
Example :
E=> E*E
=>E*id
=> E+E*id
4. what is CFL?
A string is in L(G) if
64
DR W T CHEMBIAN
DR W T CHEMBIAN
The vertices ofa derivation tree and labeled with terminal or variable symbols of the
grammer or
If an interior vertex is labeled A, and the sons of A are labeled x 1, x2, ….xk from
the left then A x1 x2 … xk must be a production.
The derivation tree.
If we lead the leaves from left to light, we get the string (id + id) * id.
More formally Let G (V, T, P, S) be a CFG
A tree is a derivation tree for G if
}
(1) Every vertex has a label, which is a symbol of VUTU {
(2) The label of the root is S
(4) If vertex has label A a d sons vertex A are labeled from left as x1,
A x , x ...x
x2 … xk then 1 2 k must be a production in p.
(5) If a vertex has a label , then it leaf and is the only son of its
father.
A context free grammar is said to be ambiguous if any word has more than one
parse tree or more than one left most derivation or more than one right most derivation is
said to be an ambiguous grammar.
DR W T CHEMBIAN
DR W T CHEMBIAN
S-> a A->a
9.What is nullable production? Write the method to eliminate the nullable
production?
A->BC A->a
Where A,B,C are variables , a is a terminal
14.What is Greibach normal form(GNF)?
GNF:
In GNF, every production is of the form
A-> aα
Where a-> is a terminal
66
DR W T CHEMBIAN
DR W T CHEMBIAN
PART-B
Grammar Introduction :
Grammar is denoted as G. which is defined as.
G = (V, T, P, S)
where,
V = set of variables or Non-Terminals.
T = set of Terminals (V and T are disjoint V T
P = finite set of productions each production is of the form A
where A is a variable.
is a string of symbols f om (VUT)*
S = is a special variable c lled the start symbol.
Example :
G = ({E}, {+, *, (,), id} p, E
where p consists of E E E
E E*E
E (E)
E id
Notations used in the Grammar.
1. The capital letters denote variables, S is the start symbol, unless otherwise stated.
2. The lower case letters a, b, c, d, e digits and boldface string are terminals.
3. The capital letters x, y and z denote symbols that may be either terminals or
variables.
4. The lower – case letter u, v, w, x, y and z denote strings of terminals.
67
DR W T CHEMBIAN
DR W T CHEMBIAN
5. The lower – case Greek letters ,, denote string of Non-terminals and
Terminals.
6. If A ,|2 | ...k
So the example can be written as,
E E E | E * E | (E) | id
Types of Grammars :
1) Type 0 Grammar
2) Type 1 Grammar
3) Type 2 Grammar
4) Type 3 Grammar
Type 0 Grammar :
It is understricted Grammar or phase structure grammar.
A grammar without any restriction.
The productions are of the form.
Type 1 Grammar :
It is contest sensitive grammar or context d p ndent grammar.
A production of the form.
is called type 1 production f
It is accepted by linear bounded arutomata
Type 2 Grammar :
It is context free grammar.
A production of the form A
where AV, and (VUT ) *
Left hand side has no l ft context or right context.
It is accepted by push down automata.
Type 3 Grammar :
It is regular grammar.
A production of the form A a or A ab, where A, B, v and a
It is accepted by finite automata.
Derivation and langauages :
If A B is a production of P and and are any strings in (VUT)* then
A
G
The derivation may be
2. left most derivation
3. right most derivation
68
DR W T CHEMBIAN
DR W T CHEMBIAN
lm
id E
lm
id E * E
lm
id id * E
lm
id id *id
Context free languages (CFL)
The language generated by G, L (G) is
*
L(G) {w | w is in T *andS w}
G
That is,
a string is in L (G) if
69
DR W T CHEMBIAN
DR W T CHEMBIAN
For the word id+id*id, there exists two right most derivation.
LMD 1 LMD 2
EEE EE *E
lm lm
id E EE*E
lm lm
id E * E id E * E
lm lm
id id * E id id * E
lm lm
id id *id id id *id
lm lm
E + E E * E
E * E +
id E E id
id
id id id
For the word id + id * id has two parse trees
So the grammar is ambiguous.
[Nov/Dec 2015]
Theorem :
Let G = (V, T, P, S) be a context free Grammar
*
Then S iff there is a derivation tree in Grammar G with yield
Proof :
We shall prove that for any A in V.
71
DR W T CHEMBIAN
DR W T CHEMBIAN
*
A if and only if there is an A-tree with as the yield.
This can be proved by methamatical induction on the number of interior vertices in
the tree.
Basis :
If there is only one interior vertex, then the tree is
E
x1 x2 xn
x
x1 2 xn
Case 2 :
(xi is a variable)
If x is a variable, then the derivation of i from x i must take fewer than k steps.
Thus by the inductive hypothesis, for each xi that is a variable, there is xi tree with
i
Let this tree b Ti
72
DR W T CHEMBIAN
DR W T CHEMBIAN
3.SIMPLIFICATION OF CFG
Discuss the methods for the simplification of CFG
Simplification of CFG:
There are several ways to restrict the format
of productions without reducing the
generative power of context – free grammar.
If L is a non empty context free language,
then it can be generated by a context free
grammar G with the following properties.
Each variable and each terminal of G appears in the derivat on of some word in L.
AB
There are no productions of the form , where A and B are variable.
If - is not in L, there need be no productions of the form A E
If E is not in L, every production be of one of the forms A BC and A O
Also we can make every productions of the fo m A a , where is a string.
There are two special forms of CFG
1. Chomsky Normal form.
2. Greibach Normal form.
Elemination of Useless symbols :
The useless symbols can be elimi ated from a grammar.
Let G = (V, T, P, S) be a Grammar
* *
A symbol x is useful if there is a derivation S x w , for some , and w,
where w is in T*
Otherwise x is useless
There are two aspects of usefulness
1. Some terminal string must be derivation from x
2. x must occur in some string derivation from s
Lemma 1 :
Given a CFG, G = (V, T, P, S) with L (G) = we can find an equivalent CFG G1.
G1 = (V1, T, P1, S) such that for each A in V1, there is some w in T* for which
*
Aw
Lemma 2:
Given a CFG G = (V, T, P, S), we can find an equivalent Grammar G1 = (V 1, T1,
P1, S) such that for each x in V1 U T1there exist and in (V1 U T1)* for which
*
S x
73
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
Consider the Grammar, and find the useless symbol.
S AB | a
A a
Solution :
We find that no terminal string is derivable from B. we therefore eliminate B and
the production S ab
Sa
A a
G = {s}, {a}, {s a}, s) is an equivalent Grammar with no useless symbol.
Elemination of E-Productions :
The productions of the form A E is called E-production
If E-is in L(G). we cannot eliminate all E-productio s from G.
If E-is not in L(G), we can eliminate the E-product ons from G.
The method is to determine for each variable A, whether
*
A E, if so it is called as A-nullable
We may replace each production B x1, x2 ,...xi ... xn by all productions striking out
some subsets of those x1‟s that are nullable. but we do not include B E, even if
all xi,s are nullable.
Example :
Consider the grammar
S as | bA |
Eliminate the E-productions.
Solution :
we find that E-is in (G), so we eliminate S and A-is nullable
so the resultant Grammar
S as | b |
Elimination of Unit productions :
The productions of the form A B is called is unit productions
There need be no productions of the form A B
Unit Productions can be eliminated form the grammar
Examble :
Consider the grammar
74
DR W T CHEMBIAN
DR W T CHEMBIAN
SA
A B
BC
Ca
Eliminate the unit productions
Solution :
By eliminating the unit productions, the resultant grammar is
SA
S bA | ab
A bAA | as | a
B aBB | bs | b [Nov/Dec 2015]
75
DR W T CHEMBIAN
DR W T CHEMBIAN
Let V” be the now set of non-terminals and P” be the ew set of productions
G3 = (V”, T, P”, S) is in CNF
Examble :
S bA | ab
A bAA | as | a
B aBB | bs | b
Find an equivalent grammar in CNF
Solution :
(1) S bA is replaced by
S Cb A
Cb b
(2) S aB is replaced by
S Ca B
Ca a
(3) A bAA is replaced by
A Cb AA
Cb b
A cb AA is replaced by
A Cb D1
D1 AA
(4) A aS is replaced by
A Ca S
Ca a
76
DR W T CHEMBIAN
DR W T CHEMBIAN
PART-C
77
DR W T CHEMBIAN
DR W T CHEMBIAN
Let A 1 B2 be a production in p and B B1 |B2 | ... |Br be the set of all B-
productions
Let G1 = (V, T, P, S) be obtained from G by deleting the production A 1 B2
from p and adding the productions
A 1B1 2 |1B2 2 |1B3 2 | ... |1B r 2
Then L (G) = L (G1)
Lemma 2:
Let G = (V, T, P, S) be a CFG
Let A A1| A2 | .... | Ar be the set of A-Productions for which A is the left most
symbol of RHS
Let A B1 B2 | ... |Bs be the remaining A-Productions.
Let G1 = (VU {B}, T, P, S) be the GFG formed by adding the variable B to V and
replacing all the A-productions by the productions
A B
1) i i i s
A Bi B
B
2) i i i r
B i B
Theorem :
Every context free language without ε- can be generated by a grammar for which
every production is the form A a , where A is a variable a is and is a string of
variables.
Proof :
Let G = (V, T, P, S) be a CFG in CNF generating the CFL L.
Assume V = {A1, A2, … Am}
The first step in the construction is to modify the productions so th
at if
Ai A j is a production, then j>i
Starting ith A1 and proceeding to Am we do this as follows
We now modify the Ak productions
If Ak A j is a production with j<k, we generate new set of production by
substituting for Aj, the RHS of each Aj production according to Lemma1.
By repeating the process k-1 times atmost we obtain productions of the form Ak A l
k according to Lemma 2 introducting a new variable Bk
78
DR W T CHEMBIAN
DR W T CHEMBIAN
By repeating the above process for each variable, we have only the productions of the
form.
1) Ai A j j i
2) Ai a a in T
3) Bi in (VU {B1, B2,...Bi1) *
for Am must be a terminal since Am is the highest
RHS of any production
numbered variable
on the RHS of any production for Am-1 must be Am-1 or a
The left most symbol
terminal symbol.
At the last step examine the productions for the new var ables B1, B2, … Bm
No Bi-productions can start with another B j therefore all Bi-productions have RHS beginning
with terminals or Ai‟s
Example :
Convert into GNF from the Grammar
G = ({A1, A2, A3}, {a, b}, P,
A1) where P consist of
A1A2 A3
A2 A3A1| b
A3A1A2 | a
Solution :
Step 1 :
Since RHS of the productions for A1 and A2 start with terminal or higher
numbered variables we begin with the productions.
A3A1A2
A3A2 A3| A2
A3A3A1A3A2 | bA3A2 (A2 A3A1| b)
The new resultant set of productions
A1A2 A3
A2 A3A1| | b
A3A3A1A3A2 | bA3A2 | a
We now apply lemma 2 to the productions
A3A3A1A3A2 | bA3A2 | a
symbol B3 is introduced and the production A3A3A1A3A2 is replaced by
79
DR W T CHEMBIAN
DR W T CHEMBIAN
A3 bA3A2 | a
A3 bA3A2|B3 | aB3
B3 A1A3A2
B2 A1A3A2 B3
The resultant set of production
A1A2 A3
A2 A3A1| b
A3 bA3A2 B 3
B3 A1A3A2 B3
Now all the productions with A3 on the RHS that start w th terminals.
These are used to replace A3 in the productions A2 A3A1 and then the
productions with A2 on the left are used to replace A2 in the production A1A2 A3
The new set of productions
A3 bA3 A2B3|aB3 |bA3 A2 |a
A2 bA3A2B3A1 |aB3A1 |bA3 A2A1 |aA1 |b
A1 bA3A2B3 A1 A3 |aB3 A1 A3 |bA3 A2 A1 |aA1 A3 |aA1 A3 |bA3 B3
bA3A2 B3 A1 A3 A3A2 |aB3 A1 A3 A3 A2 |bA3 A2 A1 A3 A3 A2 |
aA1 A3 A3 A2 |aA1 A3 A3A2 |bA3 A3 A2
B3 bA3A2B3 A1 A3 A3 A2B3 |aB3A1 A3 A3 A2 B3 |bA3 A2 A1 A3 A3 A2B3 |
aA1 A3 A3 A2B3 |aA1 A3 A3 A2B3 |bA3 A3 A2B3
80
DR W T CHEMBIAN
DR W T CHEMBIAN
PART A
1. What is Push Down Automata?
The PDA will have an input tape a finite control and a stack.
The stack holds a string of symbols from some alphabet
The device will be non-deterministic having some finite number of choices of moves in
each situations.
Formal Definition :
A push Down Automata M is a system M
= (Q, , , , q0 , Zo , F)
Where
Q is a finite set of states
is an alphabet called the input alphabet
is an alphabet called the stack alphabet
q
0 in Q is the initial state
Z
0 is is a particular stack symbol called the start symbol
FFQ
, is the set of fin l states
({})
is a transition function mapping from Q x x finite subset of
Qx *
81
DR W T CHEMBIAN
DR W T CHEMBIAN
where
l i m
q and p1 are states
a is in
Z
is a stack symbol
1 is in *
i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any
i enter state p1, replace symbol z by string i and advance the input head one symbol.
The second type of move called an is similar to the first, except that
the input
symbol is not used and the input head is not advanced after the move
(q,, z) {(p1, , ), (p2 , 2 ),...( pm , i )}
ie) The PDA in state q, independent of the input symbol being scanned and with z, the
top symbol on stack, can enter state pi, for any I and replace z by i . The input head is
not advanced.
3.What is instantaneous description of PDA(ID)?
ID of PDA:
The ID records the state , input a d stack contents
ID is defined as a triple
(q,w,U)
Where q-> is a state in the finite control
W -> is a string of input
U-> is a string of stack symbols.
4.Define the language accepted by PDA
The language is accepted by PDA in two ways.
1. Language accepted by empty stack.
2. Language accepted by final state.
Language accepted by empty stack:
To define the language accepted to be the set of all inputs for which some sequence of
move causes the PDA to empty its stack.
N(M = {w|q0, ,z0) (P,E,E) for some P in Q}
Language accepted by final state:
To define the language accepted to be the set of all inputs for which some choices moves
causes for PDA to enter a final state.
L(M) = {w|(q0,w,z0) (P,E,U) for some P in F and U in }
5.Define Deterministic Push down Automata?
The PDA M = (q,e,δ,q0,z0,F) is deterministic if
82
DR W T CHEMBIAN
DR W T CHEMBIAN
I)for each q in Q and Z in , whenever δ(q,E,Z) is non empty then δ(q,a,Z) is empty for all
a in Σ.
ii) for no q in Q Z in and a in ΣU{e} does δ(q,a,z) contain more than one element.
6.State the pumping lemma for CFL.
Let L be any CFL . then there is a constant n, depending on L, such that
|z| >= n , then we may write
Z = uvwxy such that
i) |vx| >=1
ii) |vwx|<= n
iii) For all i>=0 u v iw x i y is in L
7.What are the closure properties of (FL’s)?
CFL‟s are closed under
1. Union
2. Concatenation
3. Kleen Closure
4. Substitution
5. Homomorphism
6. Inverse homorphism
8.What is context free language derived from the following grammar?
S->a S b
S-> ab
Solution
S=> aSb=> aabb
S=>aSb=>aaSbb=> aaa Sbbb
………………=> a n-1 S b n-1
=>an bn
L = { an bn |n>=1}
9.Construct CFG to derive the grammar L ={ an bn |n>=1}
Solution :
S-<ab
S->a S b
83
DR W T CHEMBIAN
DR W T CHEMBIAN
PART-B
The device will be non-deterministic having some finite number of choices of
moves in each situations.
Formal Definition :
A push Down Automata M is a system
M = (Q, , , , q0 , Zo , F)
Where
Q x *
84
DR W T CHEMBIAN
DR W T CHEMBIAN
An input symbol is used. Depending on the input symbol, the top symbol
on the stack
and the state of a finite control, a number of choice are
possible.
Each choice consists of next state for thefinite control and a string of
symbols to replace the top tack symbol.
After selecting a choice, the input head is advanced one symbol.
where
a is in
Z is a stack symbol
1 is in *
i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any
i enter state p1, replace symbol z by string i and advance the input head one symbol.
The second type of move called an is similar to the first, except that
the input
symbol is not used and the input head is not advanced after the move
85
DR W T CHEMBIAN
DR W T CHEMBIAN
ie) The PDA in state q, independent of the input symbol being scanned and with z, the
top symbol on stack, can enter state pi, for any I and replace z by i . The input head is
not advanced.
(q,w, i )
w is a string of input
if (q, a, z) (p,)
for which some
To define the language accepted to be the set of all inputs
sequence of moves causes the PDA to empty its stack.
M (Q, , , , q , z , f )
For PDA , we define N(M), the language
0
0
accepted by empty stack to be
N(M) {W1(q0 , w, z0 ) , (P, ,), for some in Q}
86
DR W T CHEMBIAN
DR W T CHEMBIAN
for which some
To define the language accepted to be the set of all inputs
choices of moves causes the PDA to enter a final state.
We define L(M), the language accepted by PDA M by final state to be
*
PDA, it can be accepted by
If a set of can be accepted by empty stack by some
final state by some other PDA and vice versa.
87
DR W T CHEMBIAN
DR W T CHEMBIAN
where is defined as
1) (q1 ,O, R) {(q1 , BR)}
2) (q1 ,O, B) {(q1 , BB)}
3) (q1 ,O,G) {(q1 , BG)}
4) (q1 , C, R) {(q2 , R)}
5) (q1 , C, B) {(q2 , B)}
6) (q1 ,C, G) {(q2 , G)}
7) (q1 ,1, R) {(q1 ,GR)}
8) (q1 ,1, B) {(q1 ,GB)}
9) (q1 ,1,G) {(q1 ,GG)}
10) (q2 ,O, B) {(q2 ,)}
11) (q2 ,, R) {(q2 ,)}
12) (q2 ,1, G) {(q2 ,)}
Let x = O1C1O
88
DR W T CHEMBIAN
DR W T CHEMBIAN
Prove that “if a Language is accepted by empty stack, by some
PDA, it can
be accepted by final stat by some other PDA and V ce versa”
by some PDA, it can be accepted by final
If a Language is accepted by empty stack,
stat by some other PDA and Vice versa
Theorem 1 :
If L is L(M2) for some PDA M2, then L is N(M1) for some PDA M1.
Proof :
We prove M1 to simul te M2 with the option for
M1 should erase its stack whenever M2 enters a final state.
We use state qe of M1 to erase the stack
We use a bottom of stack marker X0 for M1 does not accidently accept if M 2 empties
its stack without entering a final state
Let M2 = (Q, , , , q0 , z0 , F) be a PDA such that L = L (M2)
Let M1 = (QU {qe,q0,‟}, ,U{x0},1,q01, x0 ,)
1) 1(q01,, x0 ) {(q0 , z0 , x0 )}
2) 1(q, a, z) (q, a, z )
for all q in Q, a in or{}and z in
89
DR W T CHEMBIAN
DR W T CHEMBIAN
(q0,x,z0) (q,,)
That is
Theorem 2:
If L is N(M) for some PDA M1, then L is L(M1) for some PDA M2
Proof :
We prove M2 to simulate M1
M2 enters a final state when and only when M1 empties its stack
Let M1 = (Q, , , , q0 , z0 , ) be a PDA such that L = N(M1)
1
Let M2 = (QU{q0 , qf}, , U {x0 }, 1, q01, x0 ,{qf })
DR W T CHEMBIAN
DR W T CHEMBIAN
Prove that “If L is a context free Language, then there exists a PDA M,
such that L = N(M)”
and “If L is n(m) for some PDA M, then L is a context
free language”.
Theorem 3:
If L is a context free Language, then there exists a PDA M, such that L = N(M)
Proof:
91
DR W T CHEMBIAN
DR W T CHEMBIAN
Where
(q, a, A) (q, )
Whenever A a is in p
The PDA M simulates left most derivations of G is in GNF each sentential form
derivation consist of a string of terminals x followed by a string of
in a left most
variables
M stores the suffix on the left sentential form on its stack after processing the
prefix x.
Theorem 4:
Proof :
Where
V is the set of objects of the form [q,A,p], for each q and p in q and A in plus the
new symbol S.
T=
for each q,q1,q2,… qm+1 in Q each a in U{} and A,B1,B2,…, Bm in such that
(q,a, A) (q1, B1, B2...Bm )
92
DR W T CHEMBIAN
DR W T CHEMBIAN
Lemma
Let L be any CFL. Then there is a constant n, depending only on >, such that if z is
in L and
1) | Vx | 1
2) | Vwx | n
3) for all I uvisxiy is in L
Proof :
Let G be a CFG in CNF generating L {}
If Z is in L(G) and Z is long, then any parse tree for z must contain a long path
We prove this by mathem tical induction on i, that path of length for z.
If the word generat d by a CNF grammar has no path of length greater than I, then the
word length is no greater than 2 i-1
Basis :
i = l is trivial
Induction step:
Let I > 1
If there are no paths of length greater than i - 1 in trees T1 and T2, then the
trees generate words of 2i-1 of fewer symbols
93
DR W T CHEMBIAN
DR W T CHEMBIAN
Thus the entire tree generates a word no longer than 2i-1
S
A B
T1 T2
Let G have k variables and let n = 2k
n, then since | z | > k-1 , any parse tree for z must have a path
If z is in L(G) and | z |
of length at least k +1.
But such apath has k + 2 vertices, and all except last vertex are labeled by
variables.
Thus there must be some variables that appears twice on the path.
Some variables must appear twice near the bottom of the path.
Then there must be two variables V1 and V2 on the path satisfying the following
conditions.
1. The vertices V1 and V2both have the same label say A
2. Vertex V1 is closer to the root than vertex V2
3. The portion of the path from V1 to the leaf is of length atmost k + 1
Now the subtree T1 and T2 is the subtree enerated by vertex V2 and Let Z2 is the
yield of subtree T2
Then we can write
Z1 = Z3 Z2 Z4
Z3 and Z4 cannot both be . Since the production used in
the derivation of z1
must be of the form A BC, for some variable B and C
The Subtree T2 must be completely within either the subtree generated by B or
the subtree generated by C.
Example :
G = ({A,B,C}, {a,b}, P,A)
P : {A BC, B BA, A a, B b, {C BA}
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
consider Z = anbnc n
write Z = uvwxy so as to satisfy the conditions of pumping lemma
u = am
vwx = an-m bm , w = aj aj
y = bn-m cn
Verify
uviwxiy = am aj bj bn-m cn
= am+j bn-m jcn # L
For i = 2
95
DR W T CHEMBIAN
DR W T CHEMBIAN
[May/June 2016]
Solution
Transition Diagram
R, ) Let x=0110
96
DR W T CHEMBIAN
DR W T CHEMBIAN
SOSI| A
A IAO| S | E
Solution
G=(V,T,P,S)
Where V = {S,A}
T = {0,1}
To construct a PDA M = Q, , , , q0 , z0 , )
Where
Q = {P1,q2}
T {0,1}
{v}U{z0 }
= {S,A,O,1,Z0}
97
DR W T CHEMBIAN
DR W T CHEMBIAN
n n
4) Design a PDA accepting L = {a b | n 1} by final state
Solution:
Transition Diagram:
Transition function
1) (q0 , o, z0 ) (q0 , Oz 0 )
2) (q0 , o, o) (q0 , oo)
3) (q0 ,1, o) (q1,)
4) (q1,1, o) (q1,)
5) (q1,, z0 ) (q2 ,)
M = ( Q, , , , q0 , z0 , F)
98
DR W T CHEMBIAN
DR W T CHEMBIAN
Q = {q0,q1,q2}
{0,1)
{0;1, z0}
F = {q2}
M = ({q0,q1},{0,1},{x,z0}, , q0,q0,
) where is given by
(q0 , o, z0 ) (q0 , xz 0 )
(q0 , o, x) (q0 , xx )
99
DR W T CHEMBIAN
DR W T CHEMBIAN
T = {0,1}
S[q0 , z0 , q1 ]
1) (q0 , o, z0 ) (q0 , x, z0 )
The production is
[q0 , x, q1 ]1
4) (q1,1, x) {(q1,)}
The production is
100
DR W T CHEMBIAN
DR W T CHEMBIAN
[q1, x, q1 ]1
5) (q1,, x) {(q1,)}
The production is
[q1, x, q1 ]
The production is
[q0 , x, q1 ]1
There are no production for the variable [q1, x, q0 ] and[q1, z0 , q0 ]
As all the productions for [q0 , x, q0 ] and [q0 , z0 , q0 ] have [q1, x, q0 ] or [q1, z0 , q0
]
on the right, no string of terminals can be derived from [q0 , x, q0 ] or [q0 , z0 , q0 ]
these variables on either the right or left, we
Deleting all production involving one of
end up with the following productions.
S[q0 , z0 , q1 ]
[q0 , x, q1 ]1
[q1, z0 , q1 ]
[q1, x, q1 ]
[q1, x, q1 ]1
101
DR W T CHEMBIAN
DR W T CHEMBIAN
T = {0,1}
P = set of productions
S[q0 , z0 , q0 ]
S[q0 , z0 , q1 ]
102
DR W T CHEMBIAN
DR W T CHEMBIAN
[q0 , z0 , q0 ]
5) (q1,1, x) {(q1,)}
[q1, x, q1 ]1
6) (q1,0, z0 ) {(q0 , z0 )}
There are no production for the variable [q1, x, q0 ]
As all the productions for [q0 , x, q0 ] have
[q1, x, q0 ] on the right, no string of
terminals can be derived from [q0 , x, q0 ]
Deleting all production involving one of these variables on either the right or left, we
end up with the following productions.
[q1, z0 , q0 ]
[q1, x, q1 ]1
PART - A
1.What is Turing machine?
*An input tape is divided into cells. The tape is infinite to the right.
a1 a2 ….. a1 … an B B ….
Finite
Control
Formally, a Turing Machine is donoted M
= ( Q, E, , , qo , B, F )
Where
DR W T CHEMBIAN
DR W T CHEMBIAN
The language accepted by M, denoted L (M) is the set of words in xthat cause Mto
enter a final state.
Formally the language accepted by TM.
M = ( Q, E, , , qo, B, F ) is
L (M) = {w | w in x and q o w 1 P 2 for some P in F and 1 and 2
The TM halts, (e) has no next move, whenever the input is accepted.
The TM will never halt for the words which are not accepted.
105
DR W T CHEMBIAN
DR W T CHEMBIAN
If f(i1,i2,….ik) is defined for all i1, i2..in then we say f is a total recursive
function.
A multi tape turing machine consists of a finite control with k tape heads and k tapes.
On a single move depending on the state and the scanned by each tape head, the turine
machine.
1. Changes state
2. Print a new symbol scanned by each tape head
3. Move each of its tape head independently one cell to the left or right.
A->wB
A->w
Then the grammar is right linear.
*If all productions of a CFG are of the form
106
DR W T CHEMBIAN
DR W T CHEMBIAN
A->BW
A->W
Then the grammar is left linear.
G=(V,T,P,S)
α -> β
*These grammar derives recursive and recursing num rable languages these languages
are accepted by Turing Machines.
*These grammar derives context sensitive language context sensitive language are
accepted by Linear Bound d Automata.
107
DR W T CHEMBIAN
DR W T CHEMBIAN
For a given Turing Machine M and a given string w, instead of asking whether
Turing Machine accepts w, its asks whether TM halts on input w. This problem is
referred as halting problem.
14.What is Reduction?
Given an instance I of P1 to find an instance F(I) od P2 so that for every I the answer for
the turn instances T and F(T) are the same.
Turing machine is used for solving computational , recursive and non recursive
enumerable problems.
PART-B
1. Discuss the basic definitions of Turing Machine.
The basic model of a TM has Finite
1. a finite control Control
2. an infinite tape
3. a tape head
tape is divided into cells. The tape has a left most cell but it is infinite to the
An input
right.
Each cell of the tape may hold exactly one of a finite numbers of tape symbols.
which is string of symbols chosen from a
Initially the n left most cells for n ≥ o hold the input
subset of tape symbols called the nput symbols.
The remaining infinity of cells each hold the blank, which is a special tape symbol that is
not an input symbol.
In one move of the Turing Machine, depending upon the symbol scanned by the tape
head and the state of the finite control
1. Changes state
2. Prints a symbol on the t pe cell scanned replacing what was written there
3. Moves its tape h ad l ft or right one cell
Formal Definition:
Formally, a Turing Machine is donoted M
= ( Q, E, , , qo , B, F )
Where
DR W T CHEMBIAN
DR W T CHEMBIAN
1 q 2
Where
1 , 2 is the string in *
The language accepted by M, denoted L (M) is the set of words in xthat cause Mto
enter a final state.
Formally the language accepted by TM.
M = ( Q, E, , , qo, B, F ) is
L (M) = {w | w in x and q o w 1 P 2 for some P in F and 1 and 2
The TM halts, (e) has no next move, whenever the input is accepted.
The TM will never halt for the words which are not accepted.
110
DR W T CHEMBIAN
DR W T CHEMBIAN
Solution
Suppose w = 00010
0 0 0 1 0
q0
0 0 0 0 B
q1 q 1
0 0 0 B B
q3
0 1 B
q0 (qo, O, R) (q1, O, R)
q1 (q1, O, R) (q2, B, L)
q2 (q3, B, R) - (q3, B, R)
q3 - - -
M = ( Q, , , , q0 , B,{q3}
Q = {q0,q1,q2,q3}
111
DR W T CHEMBIAN
DR W T CHEMBIAN
{0,1)
{0,1, B}
F = {q3}
000q010 0000q1000000q1B
0000q2BB0000Bq3
M = (Q,
Where Q is
112
DR W T CHEMBIAN
DR W T CHEMBIAN
The first component of the state controls the action, while the second
component „remembers‟ a symbol.
1) =([q1,0],0,R),
2) =([q1,1],1,R)
Initially q0 is the control component of the state and M moves right. The
first component of statebecomes q1 and the first symbol seen is stored in
the second component.
1) =([q1,0],1,R),
2) =([q1,1],0,R)
a O stored and sees a 1, or vice versa, th n M continues to move to the
If M has
right.
1) =([q1,B],0,L),
2) =([q1,B],0,L)
M enters the final state [q1,B] if it reaches a blank symbol without having first
encountered a second copy of the left most symbol.
If M reaches a blank in state (q1, 0) or (q1, 1) it accepts.
For state (9,10) and symbol 0 or for state (q1 , 1) and symbol 1, is not defined.
Thus if M encounters the tape symbol stored in its state. M halts without accepting.
2. Multiple tracks:
The tape of the Turing machine is divided into K tracks for any finite K.
The symbols on the tape are considered k tuples one component for each track
C 1 0 1 1 1 1 $ B ...
B B B B 1 0 1 B B
113
DR W T CHEMBIAN
DR W T CHEMBIAN
B 1 0 0 1 0 1 B B
Finite control
Example:
greatest than 2, written on the first track and
The tape of a TM takes a binary input
determined whether it is a prime.
Solution:
The input is surrounded by C and $ on the first tracks.
Thus the allowable input symbols are
[ C, B, B] is identified with C [O,
B, B] is identified withO [1, B,
B] is identified with 1
[$, B, B] is identified with $
[B, B, B] is identified with B
To test it its input is prime, the Turing Machine
Write the number two in binary on the second
track. Copies the first tracks on the third
The second track is subtracted as many times as possible from the third track, and
leaving the remainders.
If the remainder is z ro, the number on the first track is not a prime.
Checking off symbols is useful for visualizing
how a Turing Machine recognizes
languages defined by repeated strings such as
{ w w | in *}
{w c y | and y in *, w y}
{w wR | w in *}
It is also useful when lengths of substrings must be compared, such as in the languages
{ai bi | ≥ 1}
{ aibjck 1 i j, or j k}
114
DR W T CHEMBIAN
DR W T CHEMBIAN
We introduce an extra track on the tape that holds a blank or
The appears when the symbol below it has been considered by the Turing machine in one
of its comparisons.
Example:
Solution:
d = a, b or B}
The second component of the state is used sto e an nput symbol
{ [B, d] | d = a, b or c
The input symbol [B, d] is identified with d
= [x d] | x = B or and d = 0
is defined as
115
DR W T CHEMBIAN
DR W T CHEMBIAN
Shifting Over:
A Turing machine can make space on its tape by shifting all non – blank symbols a
finite number of cells to the right.
head moves to the right, repeatedly store the symbols read in the finite
The tape
control
The symbols are replaced by the symbols read from cells to the left.
The TM can return to the vacated cells and print symbols of its choosing.
Example :
Solution :
Let the tape of M does not contain blanks b tw n non – blanks.
Let Q contains the states of the form [q,Aa,A2] for q = q1 of q2 A1,A2 in
Let x be a special symbol not used buy M except in shifting process
M starts the shifting process in state [q1,B,B]
are defined as
1) ([ q1, B, B], A1([q1, B, A1], x, R) for A1 in {B, x}
2) ([ q1, B, A1], A2 ([q1, A1, A2 ], x, R) for A1 and A2 in {B, x}
3) ([ q1, B, A1 ], A3 ([q1, A1, A3 ], A1, R) for A1, A2 , A3 in {B, x}
4) ([ q1, A1, A2 ], B ([q1, A2 , B], A1, R) for A1, and A2 in {B, x}
5) ([ q1, A1, B], B ([q2 , B, B], A1, L)
6) ([ q1, A1, A2 ], B ([q1, A2 , B], A1, R) for A1, and A2 in {B, x}
Subroutines :
The Turing machine can simulate any type of subroutine, include recursive procedure
and any of the parameter passing mechanisms.
We describe only the use of parameter less, non-recursive sub routines.
The general idea is
To write part of a TM program to serve as a subroutine.
It will have a designated initial state and return state which
has no move and
which will be used to effect a return to the calling routine.
116
DR W T CHEMBIAN
DR W T CHEMBIAN
To design a Tm that calls the subroutine a new set for states for the
subroutines is mad, and a move from the return state is specified.
subroutine and the
The call is effected by entering the initial state for the
return is effected by the move from the return state.
Example :
Solution :
M starts with Om | On on its tape and ends with O mn surrounded by blanks.
The general idea is to place a 1 after O m | O n
and then copy the block of n O‟s onto the right
end m time each time erasing one of the O‟s.
The is defined as for copy sub routine as
0 1 2 B
q1 (q2, 2, R) (q4, 1, L)
q2 (q2, O, R) (q2, 1, R) (q3, O, L)
q4 (q5, 1, R) (q4, 1, L)
To complete the progr m formultiplication we add states to convert initial ID q 0
Om | On to B O m-1,q,On 1.
i.e
0 1 2 B
117
DR W T CHEMBIAN
DR W T CHEMBIAN
q5 (q7, O, L)
q7 (q8, 1, L)
q8 (q9, O, L) (q10, B,
R)
q9 (q9, O, L) (q10, B,
R)
q10 (q11, B, R)
q0 00100 Bq60100B0q6100B01q100
Discuss about the Multihead and Multi Tape Turing Machine. [NOV/DEC
2013]
A multitape turning machine consists of a finite control with K tape heads and k taps.
Each tape is infinite in both directions.
On a single move depending on the stateof the finite control and the symbol scanned by
each of the tape heads, the machine can
1) Change state
2) Print a new symbol scanned by each tape heads
3) Move each of tape heads independent one cell to the left or right or keep it
state.
Initially the input appears on the blank.
118
DR W T CHEMBIAN
DR W T CHEMBIAN
… …
… …
… …
Finite Control
Theorem :
Proof :
Let L be accepted by M, a TM with k tapes
We can construct M2 a single tape TM with 2k tracks
One track records the contents of the corresponding tape of M.
The other tape is Blank, except for a Marker that holds the symbol scanned by the
corresponding head of M.
… …
… …
119
DR W T CHEMBIAN
DR W T CHEMBIAN
… …
The finite control of M2 stores the state of M1
along with a count of number of
head markers to the right of M2‟s tape head.
Head 1 x
Tape 1 A1 A2 … .. Am
Head 2 x
Tape 2 B1 B2 … … Bm
Head 3 x
Tape 3 C1 C2 … … Cm
DR W T CHEMBIAN
DR W T CHEMBIAN
Describe the chomskian hierarchy of Languages. [May/June 2016]
The Chomskian hierarcy of languages :
The four classes of languages
1. Regular sets
2. Context free languages
3. Context sensitive languages
4. Recursive and recursively enumerable languages
The four classes of languages are grammatically charecterised.
These four classes of languages are called as chomshy hierarchy.
1. Regular Grammar :
It all productions of a CFG are of the form
A wB where A, B are var ables
A w where w are string of ter min als
then we say the grammar is light li eave.
If all productions are of the form
A Bw
A B
then we say the gramm r is left lineave.
A right or left linear grammar is called as regular grammar.
Regular grammar derives regular languages.
Regular languages are accepted by finite Automata.
2. Unrestricted Grammar :
with 4 tube notation.
A grammar is used
G = (V, T, P, S)
The productions are of the form
121
DR W T CHEMBIAN
DR W T CHEMBIAN
These grammar also known as type 0 grammar or phase structure grammar.
These are accepted by turning machines.
Suppose we place the restriction on the production of a phase structure
grammer that be atleast as long as .
The resulting grammar is context sensitive grammar.
These grammars are called as type 1 grammers
These grammar derives context sensitive language
Context sensitive languages are accepted by linear bounded Automata.
A linear bounded automata is a non-determinist c turning machine satisfying the
following two conditions.
1. Its input alphabet includes two special symbols and $, the left and right end
marker respectively.
2. The LBA has no moves left from or right from $, nor may it print another
symbol over or $.
The LBA is denoted as
M = (Q, ,, ,q0,,$,F)
Where Q, , , , q0 , and F are as for a Non-deterministic
TM , $, are symbols in the left and right end markers.
The language accepted by M is
L(M) {w | w is in ({,$) *and q 0 w$ qfor some q in F
122
DR W T CHEMBIAN
DR W T CHEMBIAN
5.A.HALTING PROBLEM
Explain Halting Problem. Is it solvable or unsolvable problem? Discuss.
[May/June 2016]
The Halting Problem :
If the problem of whether a TM M accept the string w is unsolvable.
It cannot be solved for recursively enumerable languages.
not if it loops forever. Accepts :
This approach will procedure an answer only if T halts
Given a TM, M and a string w, Does, TM, M accepts w?
An instance of the problem accepts consists of a pair <M, w> with the universal
turning machine.
Lu = {<m‟, w‟> | w L (M) }
The haltingproblem is related to the membership problem for recursively enumerable
languages.
Halting Problem :
For a given turning machine M and a giv n string w, instead of asuling whether
turning machine accepts w. it asks whether turning machine halts on input w. This
problem is referred as halting problem.
Halts : Given a turning machine M, and a string w does M halts on input w?
We can consider the corresponding language L(M)
{ M , W1 | M halts
1
on input w }
Reducing One Decision Problem to another :
If P1 and P2 are decision problems. P1 is reducible P2 ie) written as
P1P2
If there is an algorithmic procedure that allows us
“Given an arbitrary instance I of P1 to find an instance F (I) of P2. So that for every I the
answer for the two instances I and F (I) are the same.
Reducing One language to another :
and
If L1 and L2 are languages over alphabet respectively, we say that L1
1 2
123
DR W T CHEMBIAN
DR W T CHEMBIAN
Forboth problems, an instance is a pair consisting of turning machine, M and a string
w.
Given a pari <m, w> an instance
of Accepts we must construct another pair <m1,
w1> an instance of Halts.
This meansthat M1 and w1 must be constructed so that M1 halts on input w1 iff M
accepts w.
i.e) If M accepts w, m1 must halt on w1 and if M either rejects w or runs forever on w, m,
must not halt on w.
Let us choose w = w1
To construct M1, the moves of M are simulated by changi g the move of the form
124
DR W T CHEMBIAN
DR W T CHEMBIAN
Solution:
n n
Machine M contains O 1 followed by an infinity of
Initially the Turing
Blanks. For eg.
xy
0 0 1 1 B …
q0 q1 q1 q2
125
DR W T CHEMBIAN
DR W T CHEMBIAN
M repeatedly replaces the leftmost O by and moves right to the leftmost L replacing
it by Y. moves left to right to the left most X then moves one cell right to the leftmost
O and repeats the cycle.
0 1 X Y B
q0 (q1, X, R) (q3, Y, R -
q1 (q1, O, R) (q2, Y, L) (q1, Y, R) -
q3 q3, Y, R) (q4, B R)
q4 - - - - -
q0 0011 x q1 011 x o q1 11
xxyyq3 xxyybq4
The Turing Machine accepts L = { On 1n | n 1}
0 1 X Y B
q0 (q1, X, R) (q3, Y, R -
126
DR W T CHEMBIAN
DR W T CHEMBIAN
q3 q3, Y, R) (q4, B R)
q4 - - - - -
q7
q8
M = ( Q, , , , q 0 , B, F)
Q = {q0,q1,q2,q3,q4,q5,q6,q7,q8}
{0,1)
{0,1, x, y, B}
Let consider w = 0011
q0 0011 x q1110x 1 q110
x11q10 x110q1Bx11q20
x1q31x xq3l1xq3x11x
xq011x xyq41xxy1q4x
subtraction Solution:
DR W T CHEMBIAN
DR W T CHEMBIAN
O for M<n
The TM started with O m, On on its tape and halts on O m –n on its tape.
its leading O by blank then searches light for a 1 followed by a O and
M repeatedly replaces
changes the O to 1.
M moves left until it encounters a blank and then repeats the cycle. The repetition ends
Next
if
1. Searching right for a O, M encounters a blank. Then the n O‟s in O m | On have
all been changed to 1‟s and n + 1 of the m O‟s have been changed to B. M
replaces the n + 1 1‟s by a O and n B‟s leaving m-n O‟s on its tape.
2. Beginning the cycle M cannot find a O to change to a blank, because the first
m O‟s already have been changed. Then n m, so m – n = O. m replaces all
remaining 1‟s and O‟s by B.
0 1 B
q0 (qo, B, R) (q5, B, R)
q1 (q1, O, R) (q2, 1, R)
q6 -- -- --
M is defined as
M = {Q, , , , qo, B, F}
= {O, 1}
= {0, 1,
B} F = {q6}
128
DR W T CHEMBIAN
DR W T CHEMBIAN
BOq6BB..
PART-A
Decidable problem:
*A problem whose language is recursive is said to be decidable.
*A problem is decidable if there is an algorithm that takes as input an instance of
the problem and determines whether the answer to that instance is yes or no.
DR W T CHEMBIAN
DR W T CHEMBIAN
Undecidable problem:
Does the turing machine M accept i put w? here both M and w are the parameters of
the problem. In formalizing a problem as a language. The input w is restricted to be
over {0,1} and M to have tape alphabet {0,1,B}. This Turing Machine is referred as
Universal Turing Machine.
We can construct a language Ld from the table by using the diagonal entries of the table
to determine membershin in L1.
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
List A List B
i wi xi
1 1 111
2 10111 10
3 10 0
Solution :
This PCP has a solution
M=4
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
101111110 = 101111110
The Solution
i1 = 2
i2 = 1
i3 = 1
i4 = 3
8.What is MPCP?
131
DR W T CHEMBIAN
DR W T CHEMBIAN
The modified version of PCP is the following given lists A and B of K strings each
from Σ* say
A = w1, w2,….wk
B = x1,x2,….xk
W1,wi1,…wir = x1 xi1xi2….xir
For any k>= 0 and m>= 0 if N k – N ang g1,g2,…gk : Nm -> N are elements of PR ,
then f(g1,g2,…gk) obtained from f and g1, g2,…. Gk by composition is an element
of PR.
For any n>=0 any function g:N n+1 -> N in PR and any function.
a) constant functions
DR W T CHEMBIAN
DR W T CHEMBIAN
PART-B
1. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES
State and prove the closure Properties of recursive and recursively
enumerable languages. [Nov/Dec 2012]
Closure properties of recursive and recursively enum rable languages :
Theorem 1 :
Proof :
Let L be a recursive language and M a tuning machine that halts on all inputs
accepts L.
Construct M‟ from
M so that if M enters final state on input w then m‟ halts
with accepting.
If M halts ithout accepting, M‟ enters final state.
Since one of these two events occurs M‟ an algorithm.
Clearly L (M) is the
complement of L and thus the complement of L is a
recursive language.
133
DR W T CHEMBIAN
DR W T CHEMBIAN
Theorem 2 :
The union of two recursive language is recursive.
The union of two recursively enumerable language is recursively enumerable.
Proof :
134
DR W T CHEMBIAN
DR W T CHEMBIAN
For recursively enumerable languages the above construction does not work.
Since M1 may not halt.
Instead M can simultaneously simulate M1 and M2 on separate tapes.
If either accepts, then M accepts.
135
DR W T CHEMBIAN
DR W T CHEMBIAN
Theorem 2 :
Proof :
Let M1 and M2 accept L and respectively.
Construct M to simulate simultaneously M and M2
M accepts w if M1 accepts w and rejects if M2 accepts w
Since w is in either L or we know that exactly one of M1 or M2 will accept.
Thus M will always say either „yes‟ or „no‟ but will never say both.
Since M is an algorithm that accepts L, it follows that L is recursive.
136
DR W T CHEMBIAN
DR W T CHEMBIAN
Encode the following TM, M <M, 1011> in binary
2, q3}, {0, 1}, {0, 1, B}, , q1, B1, {q2})
M = ({q1, q
Where is
(q1,1) (q3 , 0, R)
(q3, 0) (q1,1, R)
(q3,1) (q2 , 0, R)
137
DR W T CHEMBIAN
DR W T CHEMBIAN
Solution :
1) (q1,1) (q3 , 0, R)
(q1, x2 ) (q3, x1, D2 )
Code1 = 0 10 10 10 102
1 2 3 1
2) (q3, 0) (q1,1, R)
(q3 , x1) (q1, x2 , D2 )
Code2 = 03101101102102
3) (q3,1) (q2 , 0, R)
(q3, x2 ) (q2 , x1, D2 )
Code3 = 03102102101102
4) (q3, B) (q3,1, L)
(q3, x3) (q3, x2, D1)
Code4 = 03103103102101
|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011
111010010001010011000101010010011000100100101001100010001000100101
111011
138
DR W T CHEMBIAN
DR W T CHEMBIAN
In the table, if the entry is
1 – means wi is not in L(Mj)
2 – means wi is in L (Mj)
We can construct a language
Ld from the table by using the diagonal entires of the table to
determine membership in Ld
To guarantee that no TM accepts L d. we insist that w1 is in L diff the the (i, i) entry is
o, that is if Mi does not accept w1.
Supposethat some TM Mj, accepted Ld then the following contradictions may
occur.
1) If wj is in Ld then (j, j) entry o, implying that wj is not in L(mj) and
contradiciting Ld = L(Mj)
2) If wj is not in Ld, then the (j, j) entry is 1, implying that wj is in L(Mj) which
contradicts Ld = L(Mj)
As wj is either in or not in Ld, we conclude that our assumption Ld = L(Mj) is false.
Thus no TM in the list accepts Ld. And no turning machine accepts Ld.
Lemma :
Ld is not recusively enumerable.
4. THE UNIVERSAL LANGUAGE
139
DR W T CHEMBIAN
DR W T CHEMBIAN
The behavior of M1 is as follows
1) Check the format of tape 1, to see that it has a prefix of the form 111Code, 11
code2 || … || coder ||| and that there no two codes that begin with o i | oj | for the
same i and j for the same i and j Also check that if o i | oj | ok | ol | om is a code
then i j 3,l l 3 and
2) Initialise tape 2 contain w the portion of the input beyond the second block of
three 1‟s. Initialise tape 3 to hold a single O. representing q1. All three tape
heads are positioned on the left most symbols.
3) If tape e holds OO. the code for the final state, halt and accept.
4) Let xj be the symbol currently scanned by tape head2 a d let Oi be the current
content of tape 3.
Scan tape 1 from the left end to the second 111 looking for a substring beginning 110 i |
Oj11. If no such string is found, halt and reject. M has o next move and has not accepted.
Thus we have an algorithm for Ld. since no such algorithm exists, we know our
assumption, that algorithm A for Lu exists is false.
Hence Lu is recursively enumerable, but not r cursive.
DR W T CHEMBIAN
DR W T CHEMBIAN
K0 a 0
For each and each , the constant function
Ca k Nk N for every X E Nk
In the case K = 0 we may identify the function Cak with the number a
2. The successor function :
NN
is defined by the formula s (x) = x + 1
3. Project Functions
K 1 1 i k
For much and each I with
the projection function
P k : Nk N
1 is defined by the formula
Pi (x1, x 2 ,..., xi ,... x k ) xi
k
Composition :
1 i k,
Suppose f is a partial function from Nk to N and for each I with giis a
m
partial function from N to N. The partial function obtained from f and g 1, g2, …,
gk by composition is the partial function h from Nm to N defined by the formula
h(x) = (f (g1 (x), g2 (x), …. gk (x)) (XENm)
The Primate recursion operation :
n0
Suppose and g and h are functions of n and n + 2 variables. respectively The
function obtained from g and h by the operation of primitive recursion is the
function.
f : Nn1 N
defined by the formula
f (x, 0) = g (x)
f (x, k+1) = h (x, k, f (x1k))
DR W T CHEMBIAN
DR W T CHEMBIAN
h (x, k, Add (x, k) should be S (Add (x, k))
This means h (x1, x2, x3) should be s (x3) or S (P33 (x1, x2, x3))
Therefore Add can be obtained as
f0 = p11 (an initial function)
f1 = S (an initial function)
f2 = p33 (an initial function)
f3 = S(P33) (Obtained from f1 and f2 by compostion)
f4 = Add (obtained from f0 and f3 by primitive recursion)
Mult
To Obtain
Mult (x, 0) = 0
Mult (x, k+1) = x * (k + 1)
= Add (x * k, x)
= Add (x, Mult (x, k))
5.A.TRACTABLE AND INTRACTABLE PROBLEM
Explain about tractable and intractable problem with suitable
examples.(NOV/DEC2016,Apr/May 2017)
Tractable problem
Tracatable problem is a problem which can recognize with in reasonable time
and space constraints and can be solved in polynomial time. Those problems for
which no polynomial time algorithm are known requires exponential runtime.
Intractable Problem:
Intractable problems a e techniques for showing problems not to be solvable in
polynomial time.
PSpace= Space(cnk )
c0,k 0
c0,k 0
143
DR W T CHEMBIAN
DR W T CHEMBIAN
NPSpace= NSpace(cnk )
c0,k 0
The sets P and SPace include any language that can be recognized by aTuring
machine with time complexity or space complexity bounded by some
polynomial
Generally allowing non-determinstism will allow improvements in the time
complexity that is required to solve many problems.
There are many languages or decision problems in NP for which no determinstic
polynomial time algorithm are known.
There are no languages in NP that are known not to be in P.The problem P is the
subset of NP and the following holds
P NP PSpace NPSpace
Primitivity Problem:
This is one of the common decision problem stated as,
"Given 'n' as psitive integer, Is 'n' is aprime numbers?"
For the above problem, the solution is polynomial when unary notation is used
and the solution is exponential when binary digits that is needed to encode 'n' is
"log n".
For this problem,actually test all divisors upto √n and if it is tested in constant time, then
the required time is proportional to √n, which is not bounded by any polynomial time of 'log n'.
144
DR W T CHEMBIAN
DR W T CHEMBIAN
No
Reductions:
"L1 is reducible to L2" if there is a computable function 'f' so that
checking whether xL1 is equivalent to check whether f(x) L2.
L1 is no harder than L2 can be tested in two ways by computing function
'f' and testing membership in L2
The statement "no harder than" can be distinguised by possible
and impossible.
If testing the membership of astring in L2 is possible, then testing a
string after computing 'f' is also possible
The reducing function'f' should be computable in areasonable amount of
time hich is in polynomial time.
Properties of Polynomial Time Reduction
If L1 and L2 are languagesover alphabet ∑1 and ∑2, then the language L1 is
polynomial time reducible to L2, which is denoted as L1≤pL2 if and only if f(x) L2
and f can be computed in polynomial time such there is a turing machine with
polynomial time complexity that computes 'f'.
145
DR W T CHEMBIAN
DR W T CHEMBIAN
Solution :
5) (q1,1) (q3 , 0, R)
(q1, x2 ) (q3, x1, D2 )
1 2 3 1 2
Code1 = 0 10 10 10 10
6) (q3, 0) (q1,1, R)
(q3 , x1) (q1, x2 , D2 )
3 1 1 2 2
Code2 = 0 10 10 10 10
7) (q3,1) (q2 , 0, R)
(q3, x2 ) (q2 , x1, D2 )
Code3 = 03102102101102
8) (q3, B) (q3,1, L)
(q3, x3) (q3, x2, D1)
Code4 = 03103103102101
|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011
111010010001010011000101010010011000100100101001100010001000100101
111011
146
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
List A List B
i wi xi
1 1 111
2 10111 10
3 10 0
Solution :
has a solution
This PCP
M=4
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
101111110 = 101111110
The Solution
147
DR W T CHEMBIAN
DR W T CHEMBIAN
i1 = 2
i2 = 1
i3 = 1
i4 = 3
The Modified version of PCP (MPCP) is the following
Given list A and B, of K strings each from * say
A = w1, w2 …, wk
B = x1 , x2 …, xk
This problem has a solution if there exists sequence of integers i 1,
i2,…, ir, such that
w1wi1 wi2 …wir = xi1 xi2 …xir
The difference between the MPCP a d PCP is that in the MPCP a solution required to
start with the firs string on each list.
Lemma
Proof :
Let
A = w1, w2 …, k and
B = x1, x2 …, xk
be an instance of the MPCP
to an instance of PCP that has a solution, iff our
We convert this instance of MPCP
MPCP instance has a solution.
If PCP were decidable then MPCP would be decidable.
Let is the alphabet containing all the symbols in List A and B
Let and not be in
Let yi be obtained from wi by inserting the symbol after each character of wi
148
DR W T CHEMBIAN
DR W T CHEMBIAN
Let Zi be obtained from xi by inserting the symbol ahead of each character of
xi
Great new words
y0= y1 Z0 = Z1
yk+1 = $ Zk+1 = $
Example :
List A List B
wi xi
1 1 111
2 10111 10
3 10 0
Solution :
The lists C and D are constructed from the lists A and B
Let
C = y0 , y1, …. yk+1
D = Z0, Z1, …. Zk+1
List C List D
yi zi
0 1 1 1 1 1
1 1 111
2 10111 1 0
149
DR W T CHEMBIAN
DR W T CHEMBIAN
3 1 0 0
4 $ $
Lists C and D represents an instance of PCP
This instance of PCP has a solution iff the instance of MPCP represented by lists A and
list B has a solution.
Undecidability of PCP
Theorem :
PCP is undecidable
Proof :
It is sufficient to show that if MPCP
were d cidable, then PCP would be decidable
whether a TM accepts a given word.
We reduce Lu to MPCP, which again can be reduced to PCP.
For each M and w1 we construct an instance of MPCP that if it has a solution has one
starts with
#q0w# 1q11 #...#k qk
k where
Strings between sucresive #‟s are successive ID‟s in a computation of M with input
w.
qx is the final state.
the pairs of strings forming lists A and B of the instance of MPCP are given
Formally
below.
The first pair is
List A List B
# #q0w#
The remaining pairs are grouped as
Group 1 :
List A List B
x x
150
DR W T CHEMBIAN
DR W T CHEMBIAN
# # for each x in
Group II :
List A List B
9x yp if (q, x) (p, y, R)
Group III :
List A List B
XqY q
Xq q
qY q
Group IV :
List A List B
if x is a prefix of y.
x and y are the concatenation of corresponding strings of lists A and B respectively.
If xy = y then
151
DR W T CHEMBIAN
DR W T CHEMBIAN
Example :
0 1 B
q3 - - -
w = 01
Solution :
The first pair is
List A List B
# #q, 01#
The remaining pairs are
Group I :
List A List B
0 D
1 1
# #
Group II
152
DR W T CHEMBIAN
DR W T CHEMBIAN
List A List B
0q1, 1 q200
from (q1,1) (q2 , 0, L)
1q1, 1 q2 10
0q1, # q2 01 #
from (q1, B) (q2 ,1, L)
1q1 # q211#
0q2 0 q3 00
from (q12 , 0) (q3 , 0, L)
1q2, 0 q0 10
Group III
List A List B
0q30 q3
0q31 q3
1q30 q3
1q31 q3
List A List B
0q3 q3
1q3 q3
q3 0 q3
q3 1 q3
Group IV :
153
DR W T CHEMBIAN
DR W T CHEMBIAN
List A List B
q3 # # #
M accepts input w = 01 by the sequence of Id‟s
q, 01, 1 q2 1, 1 0 q1, 1 q2 01, q3 1 0 1, q3 01, q3 1, q3
154
DR W T CHEMBIAN
DR W T CHEMBIAN
Fifth Semester
CS6503-THEORY OF COMPUTATION
(Regulations 2013)
7.What are the required field of an instantaneous description of a Turing machine? (pg.no:105)
m
11 (a) (i) Given ∑=(a,b),construct a DFA which recognize the language L={b abn;m,n>0}.
(6)(pg.no:20)
DR W T CHEMBIAN
DR W T CHEMBIAN
δ a b
q0 {q0,q1} {q1}
q1 φ {q0,q1}
Or
(b) Discuss the basic approach to convert from NFA to regular expression illudtrate with
an example.(pg.no: 40)
(16)
12 (a) (i) Construct a Context Free Grammar for the language L={an: n is odd} (pg.no:67)(6)
(ii) Define derivation tree. Explain its uses with an example.(pg.no:70) (10)
Or
(b) Obtain a grammar in chomsky Normal Form(CNF) equival nt to the grammar G with the production
P given.(pg.no:75)
(ii)State and explain the pumping lemma for CFG (pg.no:93) (10)
Or
(b) with an example, explain the procedu e to obtain a PDA from the given CFG. (16)
14 (a) Discuss the various techniqu s for Turing Machine construction.(pg.no:112) (16)
Or
Or
(b) (i) What are tractable problems? compare it with intractable problems. (pg.no:143) (10)
DR W T CHEMBIAN
DR W T CHEMBIAN
Fifth Semester
CS6503-THEORY OF COMPUTATION
(Regulations 2013)
5. Construct a right most derivation of (a+b)*c for using the grammar, and also state that whether a
given grammar is ambiguous or not. (pg.no:71)
6. Differentiate PDA acceptance by empty stack method with acceptance by the final
state method.(pg.no:86)
11 (a) Construct NFA with epsilon for the RE=(a/b)*ab and convert into DFA and further find the
minimized DFA.(pg.no:38,29,43)
157
DR W T CHEMBIAN
DR W T CHEMBIAN
Or
n
(b) Prove for every n >=1 by mathematical induction i3 {n(n 1) / 2}2 (pg.no:54) (16)
1
12 (a) Given the CFG G, Find CFG G' in CNF generating the language L(G)-{^}(pg.no:75)
S->AACD
A->aAb|^
C->aC|a
D->aDa|bDb|^ Or
form(GNF).(pg.no:77) S->Xa|BB
B->b|Sb
X->b X-
>a
13. (a) (i) Construct a DPDA for even length pali drome. (pg.no:88) (6)
N(P)=L(G)(pg.no:91)(10) Or
(b)Convert the following CFG to PDA nd verify for (a+b) and a++.(16)
I->a|b|Ia||Ib|I0|I1,E->I|E+E|E*E|(E)
Or
(b) Write about Multitape and Multi head turing machineswith suitable
example.(pg.no:118) (16)
15 (a) Explain recursive and recursively enumerable language with suitable example. (16)(pg.no:133)
Or
(b) Explain about tractable and intractable problem with suitable examples.(pg.no:143) (16)
158
DR W T CHEMBIAN