CS8501 - THEORY OF COMPUTATION - by LearnEngineering - in
CS8501 - THEORY OF COMPUTATION - by LearnEngineering - in
in
n
CFG – Parse Trees – Ambiguity in Grammars and Languages – Definition of
g.i
the Pushdown Automata – Languages of a Pushdown Automata – Equivalence
of Pushdown Automata and CFG, Deterministic Pushdown Automata.
rin
UNIT IV PROPERTIES OF CONTEXT FREE LANGUAGES
Normal Forms for CFG – Pumping Lemma for CFL – Closure Properties of
ee
CFL – Turing Machines – Programming Techniques for TM.
gin
UNIT V UNDECIDABILITY
Non Recursive Enumerable (RE) Language – Undecidable Problem with RE –
Undecidable Problems about TM – Post‘s Correspondence Problem, The Class
En
P and NP.
TOTAL :45PERIODS
arn
TEXT BOOK:
1. J.E.Hopcroft, R.Motwani and J.D Ullman, ―Introduction to Automata
Le
REFERENCES:
1. H.R.Lewis and C.H.Papadimitriou, ―Elements of the theory of
ww
Engineering
n
g.i
SUBJECT CODE: CS8 5 0 1
rin
Regulation: 2017
ee
gin
En
arn
Le
w.
ww
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
n
3. Analysis Part of Compilation 10
g.i
4. Phases Of Compiler 11
5. Cousins Of Compiler 16
6. The Grouping Of Phases 18
rin
7. Compiler Construction Tools 18
Unit II- Lexical Analysis
e.
f.
Part A
Part B ee 20
23
gin
8. Need and Role of Lexical Analyzer 23
9. Input Buffering 25
10. Expressing Tokens by Regular Expressions 26
En
g. Part A 35
h. Part B 39
Le
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.
n
Parameter Parsing 94
33. Design of a Predictive Translator 96
g.i
Unit V- Code Optimization and Code Generation
k. Part A 100
rin
l. Part B 103
34. Principal Sources of Optimization 103
35.
36.
DAG
ee
Optimization of Basic Blocks
108
113
gin
37. Global Data Flow Analysis 114
38. Issues in the Design of A Code Generator 122
39. A simple Code Generator Algorithm 124
En
n
g.i
rin
ee
gin
En
arn
Le
w.
ww
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:
n
1. Mishra K L P and Chandrasekaran N, “Theory of Computer Science - Automata, Languages
g.i
and Computation”, Third Edition, Prentice Hall of India, 2004.
rin
Second Edition, Prentice Hall of India, Pearson Education, New Delhi, 2003.
Hours
Sl.
No
Unit
ee
Topic / Portions to be Covered Required
/ Planned
Cumulative
Hrs
Books
Referred
gin
Introduction- Basic Mathematical Notation TI
1 and techniques 1 1
T1
2 Finite Automaton 1 2
3 1 3 T1
T1
6 moves 1 6
ww
Minimization of DFA T1
8 1 8
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
n
g.i
Ambiguity- Relationship between derivation T1
15 and derivation trees 1 15
II
rin
Simplification of CFG T1
16 1 16
Elimination of Useless symbols - Unit
17
ee
productions- Null productions 1 17
T1
gin
Greiback Normal form T1
18 1 18
19 1 19
22 1 22
23 1 23
III Equivalence of Pushdown automata and T1
ww
24 CFL 4 27
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
Computable languages and functions T1
29 1 33
n
33 Partial Solvability 1 38 T1,T2
g.i
34 Problems about Turing machine 1 39 T1,T2
rin
Chomskian hierarchy of languages. T1,T2
35 1 40
Unsolvable Problems and Computable
36 Functions
ee 1 41 T1,T2
gin
37 Primitive recursive functions 1 42 T1,T2
languages
41 1 47
n
PART-A
g.i
1. Define the following:
a. Symbol
rin
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:
ee
gin
A language is a set of strings of symbols from one alphabet.
Ф, { ϵ} are languages.
En
Alphabet:
An alphabet is a finite set of symbols.
2. What is relation?
arn
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
n
ii. Reduction to definition
g.i
iii. Other theorem forms
iv. Theorems that appear not to be if-then statements
rin
5. What are the applications of theory of computation?
i. Compiler design
ii.
iii.
Robotics
ee
Artificial intelligence
gin
iv. Knowledge engineering
6. What is finite state system?
En
and outputs. The system with discrete inputs and outputs. The system can be in
any one of the finite number of internal states and input symbols.
Le
Input Tape
0 + 1 . . .
tape head
w.
Finite
ww
control
DFA:
M=(Q,Σ,δ,q0 ,F)
Where
q0- in a q is a
NFA :
n
NFA is defined as 5 tuples
g.i
M = (Q,Σ,δ,q0,F)
rin
Q-> Set of states
L(M)
ε-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
n
ie. One or more number of occurrences of a string in L
g.i
13. What is regular expression?
rin
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
Le
|uv|<- n
w.
15. Construct a DFA that accepts input string of0,s and 1’s that end with 11.
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 :
n
A string or word is finite sequence of symbol.
g.i
Example
a, b and c are symbols and abcd is a string.
rin
The length of a string w is the number of symbols composing the string.
It is denoted as w
Example :
abcd has length 4 ee
gin
The empty string E, the string consisting of zero symbols E =0.
A prefix of a string is any number of leading symbols of the string.
En
Example :
String abc has prefixes,
E, a, ab, abc.
arn
suffix.
The concatenation of two strings is the string formed by writing the first followed
ww
n
Set Notation :
g.i
Set is a collection of objects without repetition.
Finite sets may be specified by two forms
rin
i. listing their members between brachets.
ii. Set former
x | p x
x in A | p x ee
If every member of A is a member of B, then we write A B and say A is
gin
contained in B.
If A B but A B , that is every member of A is in B and there is same member of
En
Operations on Sets :
1. A B , the union of A and B is
x| x is in A of x is in B
Le
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
n
The first component of each pair is chosen from a set called the domain and the
g.i
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.
rin
Properties of Relations :
We say a relation R on set S is
1. Reflexive
if aRa for all a in S ee
gin
2. Irreflexive
if aRa is false for all a in S
3. Transitive
En
A relation R that is
i. Reflexive
ww
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
n
Graph is denoted as G = (V, E)
g.i
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
rin
Directed Graphs:
A directed graph or digraph consists of a finite set of vertices V and a set of
ee
ordered pairs of vertices E called arcs.
The arc from V W is denoted as V W
gin
If V W is an arc, we say
V Pr edecessorof W
W Successorof V
En
Trees:
A tree is a digraph with the following properties
arn
1. Three is one vertex, called the root that has no predecessor and from which
there is a path to every vertex.
Le
2. Each vertex other 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 V1 to Vertex V2 then V2 is said to be descendant of
w.
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
n
(4) Theorems that appear not to be if then statement.
g.i
Deductive Proof :
A deductive proof consists of a sequence of statements whose truth leads us from
rin
some initial statement called the hypothesis or the given statement (s) to a
conclusion statement.
The theorem that is proved when we go from a hypothesis H to a conclusion C is
the statement.
“If H then C”
ee
gin
We say that C is deducted from H
The hypothesis may be true or false hypically depending on values of its
En
parameters.
Theorem 1
If x 4 then 2 x x 2
arn
Proof :
The hypothesis H is x 4
Le
The conclusion C is 2 x x 2
This statement also uses parameter x and is true for certain values of x and not
ww
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 1
2
13
Statement Justification
1 x = a 2 + b2 + c 2 + d2 Given
x4
n
4 (1) and (3) properties of arithmetic
g.i
5 2x x2 (5) and Theorem (1)
rin
Reduction to definitions
If you are not sure how to start a proof convert all terms in the hypothesis to their
definitions.
Theorem :
ee
gin
Let S be a finite subset of some infinite set Let T be the complement of S with
respect to Then T is infinite.
En
Proof :
Original Statement New Statement
arn
SUT = U and
w.
T is the complement of S
S T
ww
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
n
4. whenever H holds, C follows.
g.i
If – And – only – If statements :
The statement of the form
rin
A if and only if B is actually two if – then statements.
(i) if A then B and
(ii) if B then A
ee
Theorems that appear not to be if – then statements :
Sometimes we find a theorem that appear not to have a hypothesis.
gin
An example is the well-known fact from the trigonometry.
Theorem
En
Sin 2 Cos 2 1
Additional Forms of Proof :
arn
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.
ww
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
n
g.i
Statement Justification
1 x is in R U(S T) Given
rin
2 x is in R or x is in S T (1) and definition of union
3 ee
x is in R or x in in both S and T (2) and definition of intersection
gin
4 x is in RUS (3) and definition of union
Statement Justification
1 x is in (R S) (R T) Given
w.
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
n
4. H and C both false
g.i
Proof by contradiction :
Another way to prove a statement of the form.
rin
“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
ee
Complete the proof by showing that something known to be false follows logically
from H and C
gin
This form of proof is called proof by contradiction.
Counter example :
En
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.
arn
Example
All primes are odd.
Le
Example
There is no pass of integers a and b such that
a mod b = b mod a
ww
Describe the basic definitions of DFA and NFA and the language accepted by
DFA and NFA with an example.
17
The finite Automaton is a mathematical model of a system with discute inputs and
outputs.
The system can be in a any one of a finite number of internal configuration or
states.
The state of the system summarixes the information concerning past inputs that is
needed to determine the behavior of the system on subsequent inputs.
The primary example of finite automaton is a switching circuit such as control unit
of a computer.
A switching circuit is composed of a finite number of gates each of which can be
n
in one of two conditions usually 0 and 1
g.i
The state of a switching network with n gates is thus any one of the 2n assignments
of 0 or 1 to the various gates.
rin
Text editors and the lexical analyzers found in most compiters are designed as
finite state systems.
0 1 0 1 0 0 0
ee
gin
Finite Control
Basic Definitions :
Deterministic finite automata :
En
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.
arn
One state denoted qo is the initial state in which the transition starts.
Some states are designated as final states or accepting states.
Le
18
n
The final state indicated by the double circle.
g.i
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.
rin
for eg.
The string accepted by the above FA, 11, 1100, 00, 0000, 1111, 110110
Formal Definition of DFA :
ee
We formally denote a finite automaton by a 5 tube.
gin
M = Q, , , q o , F
Q is a finite set of states
is a finite input alphabet
En
qo
in Q is the initial state
F F Q is the set of final states
arn
0 1 0 1 0 0 0
ww
Finite Control
Finite control which is in same state from Q reads a sequence of symbols from
written on a tape.
In one move, the FA in state q, scanning a symbol a enters state (q, a ) and moves
its head one symbol to the right.
Q x * to Q
(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
(1)
(q , t ) q
(2) for all string w and input symbols a
(q, wa ) ( (q, w ), a )
n
A string x is said to be accepted by FA
g.i
M = (Q, , , q o , F) if
(q o , x ) p, for some P in F
rin
The language accepted by FA, denoted as L(M)
L (M) = x | (q o , x ) is in F
ee
The language is a regular set if it is the set accepted by the same FA
gin
Example :
Consider the transition diagram
En
arn
Le
w.
This FA is denoted as
M = (Q, , , q o , F) where
ww
Q = q 0 , q1 , q 2 , q 3
0,1
q0 = q0
F = q 0
is given as a transition table
s 0 1
20
q0 q2 q1
q1 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2
n
g.i
(q 0 ,110) ( (q,1),1)
(q1 ,1)
q0
rin
(q0 ,110) ( (q 0 ,11), 0)
(q0 , 0)
q2
ee
gin
(q0 ,1101) ( (q 0 ,110),1)
(q2 ,1)
En
q3
(q0 ,11010) ( (q 0 ,1101), 0)
arn
(q3 , 0)
q1
Le
(q 0 ,110101) ( (q 0 ,11010),1)
(q1 ,1)
w.
q 0 F
Thus 110101 is accepted by the FA Thus 110101 is in L(M)
ww
L(M) = is the set of string with an even number of o‟s and an even number of 1‟s
n
g.i
rin
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 :
ee
Formally we denote a NFA by a 5 – tuple
gin
M = (Q, , , q 0 , F)
where
Q set of states
En
Q x 2Q
The function can be extended to a function mapping from
w.
Q x * to 2 Q and
ww
22
n
g.i
Let the input w = 01001
Solution :
rin
Q q 0 , q1 , q 2 , q 3 , q 4
0,1
q0 = q0
F = {q2, q4}
ee
gin
:
0 1
En
q2 {q2} {q2}
q3 {q4}
q4 {q4} {q4}
Le
(q0,01001) q
w.
(q 0 , 0) {q, q 3 )
(q 0 , 01) ( (q 0 , 0), 1)
ww
= ({q 0 , q 3 }, 1)
= (q 0 ,1) (q 3 ,1)
= {q0,q1)
= {q0, q1}
(q 0 , 010 ) ( (q 0 , 01), 0)
= ( {q 0 , q1 }, 0)
23
= (q 0 , 0) (q1 , 0)
= {q0,q3)
= {q0, q3}
(q 0 , 0100 ) ( (q 0 , 010 ), 1)
= ( {q 0 , q 3 }, 0)
= (q 0 ,1) (q 3 , 0)
= {q0,q3) {q4}
n
= {q0, q3, q4}
g.i
(q 0 , 01001 ) ( (q 0 , 0100 ), 1)
= ( {q 0 , q 3 , q 4 }, 1)
rin
= (q 0 ,1) (q 3 ,1) (q 4 ,1)
= {q0,q1) {q4}
= {q0, q1, q4} ee
gin
(q 0 , 01001 )
contains a state in F so the input string 01001 is accepted by the NFA.
En
[Nov/Dec 2015]
Le
Let L be a set accepted by NFA, then there exists a DFA that accepts L.
Proof :
Let M = Q, , , q 0 , F be an NFA which accepts L.
Define a DFA.
M1 Q1 , 1 , 1 , q 0 , F1
1
The states of M1 are all the subsets of the set of states of M
i.e) Q1 = 2Q
24
n
1 (q 0 , x) = [q1, q2, …qj]
1
g.i
iff
1 (q 0 , x ) = [q1, q2, …qj]
rin
Basis :
The result is trivial for 1 x 1 = 0, since q01 = [q0] and x must be
iff
1 ( [q 0 ], [q 0 ]
ee
gin
( q 0 ) q 0
Induction :
En
iff
(q 0 , x) [p1 , p 2 , ... p j ]
w.
1 [p1 , p 2 , .....p j ], a)
r1 , r2 , ... rk
iff
1 (q 0 , xa ) ( (q 0 , x), a )
1 [p1 , p 2 , .....p j ], a)
r1 , r2 , ... rk
Thus
25
iff
1 (q 0 , xa) [r1 , r2 , ...r k ]
1
iff
(q 0 , xa ) [r1 , r2 , ... r k ]
which establishes the inductive hypothesis
1 (q 01 , x ) is in F1 exactly when (q 0 , x) contains a state in F
L (M) = L (M)
n
g.i
3.A.FINITE AUTOMATA WITH -MOVES
rin
Discuss on Finite Automata with epsilon Transitions. [Nov /Dec 2015]
We say an NFA accepts a string w if there is some labeled w from the initial state
to a final state of course edges labeled may be included in the path although the
Le
Formal definition :
A NFA with moves to be a 5 – tuple,
ww
M = (Q, , , q 0 , F)
is the transition function maps
Q x ( to 2 Q
(q, a ) will consist of all states P such that there is a transition labeled a from q to
p where a is either or a symbol in
0 1 2
26
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 :
n
- closure (q0) = {q0, q1, q2}
g.i
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)
rin
Path q0 – q1 – q2 shows that q2is in -closure.
can be defined as follows :
1. (q,) closure(q) ee
gin
2. for w in * and a in
(q, wa) = - closure (p)
Where p = p |
En
For some p in ( (q, w )
arn
3. (R, a ) (q, a )
q in R
Le
4. (R , W) (q, w )
q in R
w.
{w| q (q,w) contains a state in F}
Example :
Consider the NFA
27
Find (q0, q1)
(q0, 01) = closure ( ( (q 0 , 0), 1)
n
(q0, 0) = closure ( ( (q 0 ,), 0)
g.i
(q0, 01) = closure (q 0 )
= {q0, q1, q2}
rin
(q0, 01) = closure ( ( (q 0 ,), 0)
ee
= closure ( ({q 0 , q1 , q 2 ), 0)
= closure ( (q 0 , 0) (q, 0) (q 2, 0))
gin
= closure ({q 0 } )
= {q0, q1, q2}
En
(q0, 01) = closure ( ( (q 0 , 0), 1)
= closure ( ({q 0 , q1 , q 2 ), 1)
arn
= closure{q1 }
= {q1, q2}
w.
M1 = (Q1, 1 , 1 , q 0 , 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 (q 0 , x ) (q 0 , x )
This statement may not be true for x
1 (q 0,) {q 0 }
while (q 0 ,) closure (q 0 )
n
Therefore we begin our induction at 1
g.i
Basis :
|x|=1
rin
Then x is a symbol a
1 (q 0 , a ) (q 0 , a ) by the definition of 1
Induction :
| x | >1 Let x = wa ee
gin
1(q0, wa) 1( (q0, w), a )
= ( p, a )
1
En
= (q , a )
1
q in p
= (q, a )
arn
q in p
= (p, a )
Le
= ( (q 0 , w ), a (q 0 , wa )
w.
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
n
0 1 2
g.i
q0 {q0, q1, q2} {q0, q1} {q2}
rin
q1 {q1, q2} {q2}
q2
ee
{q2}
closure(q1 ) {q1 , q 2 }
gin
closure(q 2 ) {q 2 }
(q0,) = closure(q 0 )
En
= closure ( ( (q 0 ,), 0)
= closure ( ({q 0 , q1 , q 2 }, 0)
Le
= closure ( ( (q 0 ,), 2)
= closure ( ({q 0 , q1 , q 2 }, 2)
= closure ( (q 0 , 2) (q1 , 2) (q 2 , 2))
= closure ( {q 2 }
= {q2}
1 ( q 1 , 0 ) = closure ( (q1 , 0))
= closure ( ( (q1 ,), 0)
= closure ( ({ q1 , q 2 }, 0)
n
= closure ( (q1 , 0) (q 2 , 0))
g.i
= closure( )
=
rin
1 ( q 1 , 0 ) = closure ( (q1 , 0))
= closure ( ( (q1 ,), 1)
ee
= closure ( ({ q1 , q 2 }, 1)
= closure ( (q1 ,1) (q 2 ,1) ))
gin
= closure ({q1 } )
= {q1, q2}
En
= closure ( ({ q1 , q 2 }, 2)
= closure ( (q1 , 2) (q 2 , 2) )
Le
= closure ( {q 2 } )
= {q2}
w.
1 ( q 2 , 0 ) = closure ( (q 2 ,), 0)
= closure ( ({q 2 ), 0)
ww
= closure()
=
1 (q 2 ,1) = closure ( (q 2 ,), 1)
= closure ( ({q 2 ), 1)
= closure()
=
1 ( q 2 , 2 ) = closure ( (q 2 ,), 2)
31
= closure ( ({q 2 ), 2)
= closure (q 2 )
=
n
g.i
Example 2 :
rin
Construct a NFA without - moves from NFA with - moves
ee
gin
Solution :
En
1 (q 0 , ) closure (q 0 )
= {q0, q1}
1 (q 0 , 0) = closure (1 (1 (q 0 ,), 0)
= closure (1 ({q 0 , q1 , ), 0)
= closure ( ({q 0 , 0) (q 0 , 0)
= closure ({q 0 ), )
= {q0, q1}
32
n
=
g.i
1 (q1 ,1) = closure (1 (1 (q1 ,), 1)
= closure (1 ({q 2 ), 1)
rin
= closure (q1 )
= {q1}
0 1 ee
gin
q0 {q0, q1} {q1}
En
q1 {q1}
arn
Le
33
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 for somea in
n
Induction :
g.i
One or more operators in the regular expressions.
Assure that the theorem is true for regular expression with fewer that I operators.
rin
i 1
Let r have I operators.
Case 1 :
r = r1 + r2 ee
Both r1 and r2 must have fewer than i operator
gin
Thus there are 2 NFA‟s
M1 = (Q1 , 1 , 1 , q1 ,{f 1} with
En
= L (M1) = L (r1)
Assume Q1 and Q2 are disjoint
arn
34
Hence
L (M) = L (M1) U L (M2)
n
Any path in the transition diagram of M from q0 to f0 must begin by going to either
g.i
q1 or q2on . If the path goes to q1 it may follow any path in M1 to f1 and then go to f0
on
rin
Hence L (M) = L (M1) U L (M2)
Case 2 :
r = r1 r 2
Let M1 and M2 be 2 NFA‟s ee
M1 = Q1 , 1 , 1 , q1 ,{f 1}) with
gin
L (M1) = L (r1)
and
En
is defined as
(i) (q, a ) 1 (q1 , a ) for q in Q1 {f 1}and a in 1 {}
ww
35
Thus
L (M) = L (M1) L (M2)
ie. L (M) = { xy | x is in L (M1 ) and y is in L (M 2 )}
Case (iii)
r = r1 *
Let M1 = (Q1 , 1 , 1 , q1 ,{f 1}) with
L (M1) = L (r1)
n
Now we can construct NFA
g.i
Let M1 = (Q1 {q 0 , f 0}, 1 , 1 , q 0 ,{f 0}) with
L (M) = L (r)
rin
where
q0 be an new initial state
f0 be an new final state
and is given by ee
gin
(i) (q 0 ,) (f 1,) {q1 , f 0 }
(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
En
Hence :
L (M) = L (M1)
Le
w.
ww
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
M = ({q1 , ........, q n }, , , q1 , F)
Let
denote the set of all string x such that (q i , x ) q j and (q i , y) = ql for any that is a
k
R ij
prefix of x, then l k
k
i.e.) R ij
= is the set of all strings that take the FA from state qi to qj without going
though any state numberd higher than k.
we can define
k
R ij
= is the set of all strings that take the FA from state qi to qj
n
without going through any state numbered higher than k.
g.i
We can define
k
R recursively. ij
k k 1 k 1 k 1 k 1
R = R (R ) * R R
rin
ij ik kk kj ij
The inputs of
k
R are, either
1) in R
k 1
ij
ij
ee
gin
(or)
k 1 k 1
2) Composed of a string R ik
followed by zero of more strings in R kk
followed by
En
k 1
a string R kj
We must show that for each i, j and k, there exists a regular expression
arn
k k
r ij
denoting the language R ij
Basis :
k=0
is a finite set of strings, each of which is either or a single symbol.
0
w.
R ij
Induction :
ww
R ijn
L (M) =
q j in F
Thus L (M) is denoted by the regular expn.
rijn1 rijn2 ........... rijp
n
whereF {q ji , q j2 , .....q jp}
n
[Nov/DEC 2015]
g.i
Construct an NFA for the regular express on 01* + 1 (or) (0 (1*)) + 1
rin
Solution :
Given regular expression
r = 01* + 1
It is of the form r = r1 + r2 whereee
gin
r1 = 01*
r2 = 1
The NFA for r2 = 1
En
arn
r1 = r3 r4
where r3 = 0
w.
r4 = 1*
The NFA for r3 = 0
ww
r4 = r 5 *
r5 = 1
The NFA for r5 = 1
38
n
g.i
The NFA for r1 – r3r4 = 01*
rin
ee
gin
En
39
n
r120 0
g.i
r210
r220 0 1
rin
R ijk , R ikk 1 (R kkk1 ) * R kkj1 R ijk 1
rijk rikk 1 (rkkk 1 ) * rkjk 1 rijk 1
For K = 1 ee
gin
(1)
R 11 r110 (r110 ) * r110 r110
= (1) (1) * (1) (1)
En
= 1* + (1)
= 1*
arn
= 1* + 0
= 1*0
w.
= 1*
=
r22(1) r210 (r110 ) * r120 r220
= (1) * (0) 0 1
= 1* 0 0 1
= 0 1
= 0 1
40
Let K = 2
r11( 2 ) r121 (r22
1 1
) * r21 r111
= 1* 0 ( 0 1) * 1*
= 1*
= 1*
r12( 2 ) r121 (r22
1 1
) * r22 r121
= 1* 0 ( 0 1) * ( 0 1) 1*
= 1* 0 (0 1) * 1* 0
n
= 1* 0 (0 1) *
g.i
r21( 2 ) r22
1 1
(r22 1
) * r21 r21
1
rin
= (0 1) *
=
r22( 2) r22
1 1
(r22 1
) * r22 r22
1
ee
= ( 0 1) ( 0 1) * ( 0 1) ( 0 1)
gin
= (0 1) * ( 0 1)
= (0 1) *
En
L (M) = r12( 2)
= 1* 0 (0 + 1)*
arn
L (M) = 1* 0 (0 + 1)*
Le
5.MINIMIZATION OF DFA
w.
Write and Explain the algorithm for minimization of DFA. Using the above
algorithm minimize the DFA. [MAY/JUNE 2016]
ww
Discuss on the relation between DFA and Minimal DFA. [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
Proof :
Any DFA M = (Q, , , q 0 , F) accepting L defines an equivalence relation that is a
refinement of RL
Thus the number of states of M is greater than or equal to the number of states of
M1
If equality holds then each of the states of M can be identified with one of the
states of M1
Let q be a state of M there must be some x in * such that
(q 0 , x ) q , otherwise q would be removed from Q
n
Identify q with the state 1 (q 01 , x ) of M1
g.i
The identification will be consistent.
If (q 0 , x ) (q 0 , y) q, then x and y are in the same equivalence class of RL.
rin
Thus 1 (q 01 , x) 1 (q 01 , y)
A Minimization Algorithm :
ee
There is a simple method for finding the minimum state DFA M1, equivalent a
given DFA M = ( Q, , , q0, F)
gin
Let be the equivalence relation on the states of M.
If P q, we say p is equivalent to q.
En
Procedure :
An X is placed in the table each time a of states that cannot be equivalent.
Initially an X is placed in each entry corresponding to one find state and one non –
ww
final state.
Next for each pair of states P and q that are not distinguishable, we consider.
r = (p, a )
s = (q, a ) for each input symbol a
If states r and s have been shown to be distinguishable by some string x, then p and
q are distinguishable by string ax.
Thus if the string (r,s) in the table has an x, an x is placed at the entry (p, q)
42
Example :
Minimize the following DFA
n
g.i
rin
Solution :
b x
ee
gin
c x x
d x x x
En
e x x x
arn
f x x x x
g x x x x x x
Le
h x x x x x x
w.
a b c d e f g
Intially an x placed in each entry corresponding to one final state and one final
ww
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
(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
n
(b, c) is marked so mark (a, d)
( d , 0) c
g.i
rin
(a, l)
( a , 0) b
(l, 0) h ee
(b, g) is unmarked
gin
(a ,1) f
(f, f) is unmarked
(l,1) f
En
(a, f)
( a , 0) b
(b, c) is marked so mark (a, f)
arn
( f , 0) c
(a, g)
Le
( a , 0) b
(b, g) is unmarked
( g , 0) g
w.
(a ,1) f
(f, e) is unmarked
(g,1) e
ww
(a, h)
( a , 0) b
(b, g) is unmarked
( h , 0) g
(a ,1) f
(f, c) is marked. So mark (a, h)
(h ,1) c
44
(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
n
(b, f)
g.i
( b, 0) g
(g, c) is marked. So mark (b, f)
( f , 0) c
rin
(b, g)
( b, 0) g
( g , 0) g
(g, g) is unmarked
ee
gin
(b,1) c
(e, e) is marked. So place an x in (b, g)
(g,1) e
En
(b, h)
( b, 0) g
arn
(g, g) is unmarked
( h , 0) g
(b,1) c
(c, c) is unmarked.
(h ,1) c
Le
(d, e)
w.
( d , 0) c
(c, h) is unmarked. So place x in (d, e)
( e, 0 ) h
ww
(d, f)
(d, 0) c
(c, c) is unmarked
(f , 0) c
(d,1) g
(g, g) is unmarked.
(f ,1) g
45
(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
n
(d, h)
g.i
( d , 0) c
(c, g) is marked. So place an x in (d, h)
( h , 0) g
rin
(e, f)
( e, 0 ) h
( f , 0) c ee
(h, c) is marked. so place x in (e, f)
gin
(e, h)
( e, 0 ) h
En
(h, g) is unmarked.
( h , 0) g
(e,1) f
(f, c) is marked. So place an x in (e, h)
arn
(h ,1) c
(e, g)
Le
( e, 0 ) h
(h, g) is unmarked
( g , 0) g
w.
(e,1) f
(f, e) is marked. So place x in (e, g)
(g,1) e
ww
(f, g)
( f , 0) c
(c, g) is marked. So place an x in (f, g)
( g , 0) g
(f, h)
46
( 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)
n
(a, e)
g.i
( a , 0) b
(b, h) is unmarked
( e, 0 ) h
rin
(a ,1) f
(f, f) is unmarked.
(e,1) f
(a, g) ee
gin
( a , 0) b
(b, g) is marked. So pace an x in (a, g)
( g , 0) g
En
(b, h)
( b, 0) g
arn
(g, g) is unmarked
( h , 0) g
(b,1) c
(c, c) is unmarked.
(h ,1) c
Le
(d, f)
w.
(d, 0) c
(c, c) is unmarked
(f , 0) c
ww
(d,1) g
(g, g) is unmarked.
(f ,1) g
On completion of the table, we conclude that the equivalent states are
a e b h d f
Algorithm :
begin
47
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
n
( (p, a ) (q, a )
g.i
end.
Method II
rin
For the above same problem, the DFA can be minimized using DFA minimization
algorithm.
Solution :
Transition table : ee
gin
0 1
a b f
En
b g c
arn
c a c
d c g
Le
e h f
w.
f c g
ww
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
bh
0 1
a b f
[b,h] g c
*c a c
d c g
n
g.i
e h f
f c g
rin
g c g
Step 2 ee
gin
The pair of status (d, f) are same state transition.
d f
En
0 1 0 1
a b f a [b, h] c
arn
[b,h] g c c a c
Le
*c a c [d, c g
f]
[d,f] c g
w.
e [b, h] [d, f]
e h f
ww
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
h]
[b, h] g c
c [a, e] c
[d, f] c g
g g [a, e]
n
Thus the minimized FA is
g.i
rin
ee
gin
En
arn
Le
0 i2
| i is an int eger i 1 is not regular. [Nov / Dec 2015]
ww
Since j<k, the string aj + 1 …. ak is of length atleast 1, and since k n , its length is
n
no more than m.
g.i
If qm is in F, that is a, a2 … am is in L (M) then a, a2… aj then a, a2 … ajak+1 … am
is also in L (M)
rin
Since there is a path from q0 to qm that goes through qj but not around the loop.
(q 0 , a , .... a j a k 1 .... a m ) ( (q 0 , a 1 ... a j ), a n 1 .... a m
ee
= (q j , a k 1 ... a m )
= (q k , a k 1 ... a m )
gin
= qm
Similary we can go around the loop, as many times.
En
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.
Le
4. The adversary breaks z into u, v and w subject to the constraints that |uv| n
and |v| 1.
ww
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 …. am
u = a 1 , a2 … aj
v = aj+1 …. ak
n
w = ak+1 … am
g.i
The pumping lemma states that if a regular set contains a long string, z, then it
contains infinite set of string of the form uviw.
rin
Problems based on pumping lemma :
1. Show that the language L = a n b n | n 1 is not regular
Solution : ee
(a) Assume that L = a n b n | n 1 is a regular languages.
gin
(b) Let n be the integer, ie) no of states in the pumping lemma.
(c) Take one string z from L
En
z = uvw
z = ai bi
Le
w = ai-m bi
= a i bi
ww
52
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 0i | i is an int eger i 1 is not regular.
2
Solution :
1. Assume L = 0i | i is an int eger i 1 is regular.
2
n
2. Let n be the integer, ie. no. of states in the pumping lemma.
g.i
3. Take one string Z
2
Let Z = O n
rin
4. Break z into z = uvw.
uv = O m 2
V = Oj
W = On2 – m2
2
ee
gin
uvw = Om On m2
2 2
2
= On
En
uvkw = uvvk-1w.
= Om O j ( k 1) On m2
2 2 2
Le
= Om O j ( k 1) On m2
2 2 2
for k = 0
w.
uvkw = Om O j On m2
2 2 2
= On j2 On
2 2
ww
for k = 0, 2 the strings vukw does not belong to the language L. so the language is not
regular.
53
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]
n
g.i
Inductive Proofs :
Theorems can be proved by mathematical induction
rin
Let P(n) be a statement about a non negative integer n
The Principal of mathematical induction is that P(n) follows from
(a) P (o)
ee
(b) P (n-1) imples P(n) for n 1
gin
Condition (a) is called the basis and condition (h) is called the inductive step.
Example 1 :
Prove by mathematical induction.
En
Solution
n (n 1) (2n 1)
Let P (n) = 12 + 22 + 32 + ….. n2 =
6
Le
Basic Step
for n = 0
w.
n
L.H.S. i2 = 0
i0
ww
54
n 2
n 1 2
i = i + n2
i0 i0
n (n 1) (2n 1) 2
= n
6
(n 2 n ) (2n 1) 6n 2
=
6
2n 3 2n 2 n 2 n 6n 2
=
6
2n 3 3n 2 n
n
=
6
g.i
n (2n 2 3n 1)
=
6
rin
n (n 1) (2n 1)
=
6
L.H.S = R.H.S.
ee
Thus by induction it is true for all n
gin
Example 2 :
Prove by mathematical induction.
n ( n 1)
0 + 1 + 2 + …. + n =
En
2
Solution
arn
n ( n 1)
Let P (n) = 1 + 2+ 3 + n =
2
Basis Step
Le
for n = 0
n
L.H.S. i=0
w.
i0
n n (n 1)
R.H.S. i =
ww
i0 2
=0
Inductive step
for n = n – 1
n (n 1)n n n ( n 1)
i= implies i =
i0 2 i0 2
Since
55
n n
i = i+n
i0 i0
(n 1)n
= n
2
(n 1)n 2n
=
2
n 2 n 2n
=
2
n2 1
n
=
2
g.i
n (n 1)
=
2
rin
L.H.S. = R.H.S.
Thus by induction it is true for all n.
Example 3 :
ee
Prove if x 4 then 2 x x 2 by mathematical inducations
gin
Solution
Basic step :
If x = 4 then 2 4 4 2
En
1616
x = 5 then 25 52
arn
32 25
Inductive step
Le
putx = x + 1
2 x 1 ( x 1) 2
2 x .2 ( x 1) 2
w.
2 x .2 2 x 2 ( x1) 2
ww
2 x 2 x 2 2 x 1
x 2 2 x 1
by x
1
x2
x
1 1
Since x 4, , where RHS = 2.25
x 4
2 x 2 ( x 1) for x 4
56
Example 1:
1. Let M = q 0 , q1 0,1, , q 0 , q1 be an
NFA where (q 0 , 0) q 0 , q1 )
(q 0 ,1) q1
n
(q 0 , 0)
g.i
(q 0 ,1) q 0 , q1 )
rin
Solution :
We can construct a DFA
M1 = (Q1, {0, 1}, 1 , [q0], F)
Q1 = all subsets of {q0, q1) ee
Q1 = [q 0 ], [q1 ], [q 0 ,q1 ],
gin
F1 = Set of states of Q1 containing state in F
F1 = { [q1], [q0, q1]}
En
Transition Table : 1
0 1
arn
[q0, q1] ? ?
ww
To find 1 ( [q 0 , q1 ], 0
q 0 , q1 , 0 = (q 0 , 0) (q1 , 0)
= {q 0 , q1 }
= {q0, q1}
1( [q 0 , q1 ], 0) = [q 0 , q1 ]
57
To find 1 ( [q 0 , q1 ], 1
q 0 , q1 ,1 = (q 0 ,1) (q1 ,1)
= {q1 } {q 0 , q1 }
= {q0, q1}
( [q 0 , q1 ], 1) = [q 0 , q 1 ]
1
M1 = (Q1, 1 , 1 , q 01 , F1 )
n
Q1 = { [q0], [q1], [q0, q1], }
g.i
{0,1}
q01 = [q0]
rin
F1 = { [q1], [q0, q1] }
1
0
ee
1
gin
[q0] [q0, [q1]
q1,]
En
Le
Transition Diagram
w.
ww
58
n
g.i
rin
Examples 2 :
Consider the following NFA
a b
ee
gin
q0 {q0, {q2}
q1}
En
q1 {q1} {q0}
M1 = (Q1, 1 , 1 , q 01 , F1 )
Q1 = { [q0], [q1], [q2], [q0, q1], [q0, q2], [q1, q2], [q0, q1, q2], }
w.
{a, b}
ww
q01 = [q0]
F1 = { [q2], [q0, q1], [q1, q2], [q0, q1, q2] }
1
a b
59
[q0, q1] ? ?
[q0, q2] ? ?
[q1, q2] ? ?
n
[q0, q1, q2 ? ?
g.i
]
rin
To find 1 ( [q 0 , q1 ], a
q 0 , q1 , a = (q 0 , a ) (q1 , a )
ee
= {q 0 , q1 } { q1 }
= {q0, q1}
gin
( [q 0 , q 1 ], a ) = [q 0 , q 1 ]
1
To find 1 ( [q 0 , q1 ], b
En
q 0 , q1 , b = (q 0 , b) (q1 , b)
= {q 2 } { q 0 }
arn
= {q0, q2}
( [q 0 , q1 ], b) = [q 0 , q 2 ]
1
To find 1 ( [q 0 , q 2 ], a
Le
q 0 , q 2 , a = (q 0 , a ) (q 2 , a )
w.
= {q 0 , q1 } { q 0 }
= {q0, q1}
ww
1 ( [q 0 , q 2 ], a ) = [q 0 , q 1 ]
To find 1 ( [q 0 , q 2 ], b
q 0 , q 2 , b = (q 0 , b) (q 2 , b)
= {q 2 } { q1 , q 2 }
= {q0, q1}
= [q 1 , q 2 ]
1 ( [q 0 , q 2 ], b) = [q1 , q 2 ]
60
To find 1 ( [q1 , q 2 ], a
q1 , q 2 , a = (q1 , a ) (q 2 , a )
= {q1 } { q 0 }
= {q0, q1}
( [q1 , q 2 ], a ) = [q 0 , q1 ]
1
To find 1 ( [q1 , q 2 ], b
q1 , q 2 , b = (q1 , b) (q 2 , b)
= {q 0 } { q1 , q 2 }
n
= {q0, q1, q2}
g.i
( [q1 , q 2 ], b) = [q 0 , q1 , q 2 ]
1
To find 1 ( [q 0 , q1 , q 2 ], a
rin
q 0 , q1 , q 2 , a = (q 0 , a ) (q1 , a ) (q 2 , a )
= {q 0 , q1 } { q1 } {q 0 }
ee
= {q0, q1,}
gin
( [q 0 , q1 , q 2 ], a ) = [q 0 , q1 , ]
1
To find 1 ( [q 0 , q1 , q 2 ], b )
En
q 0 , q1 , q 2 , b = (q 0 , b) (q1 , b) (q 2 , b)
= { q 2 } {q 0 } {q1 , q 2 }
arn
a b
w.
q1 [q1] [q0]
61
n
g.i
rin
ee
gin
En
arn
Le
w.
ww
62
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.
n
PART-A
g.i
1. Define free grammar.
rin
Grammar G is defines as
G= (V,T,P,S) Where
ee
V = Set of variables or not terminals
gin
T = Set of Terminals
P= set of productions of the form A -> α.
En
2. What is derivation?
Le
If A-> β is a production and α and are any strings than the derivation is
w.
Example :
E=> E+E
=>id+E
=> id+E*E
n
=> id+id*E
g.i
=> id+id*id
rin
Right most derivation:
ee
If at each step of derivation, a production is applied to the right most non
terminal then the derivation is said to be right most derivation.
gin
Example :
E=> E*E
En
=>E*id
arn
=> E+E*id
4. what is CFL?
Le
A string is in L(G) if
ww
64
The vertices of a 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 x1, x2, ….xk from
the left then A x1 x2 … xk must be a production.
If we lead the leaves from left to light, we get the string (id + id) * id.
n
g.i
A tree is a derivation tree for G if
rin
(2) The label of the root is S
ee
(3) If a vertex is interior and has label then A must be in V
gin
(4) If vertex has label A and sons vertex A are labeled from left as
x1, x2 … xk then A x1, x 2 ...x k must be a production in p.
En
(5) If a vertex has a label , then it leaf and is the only son of its
father.
arn
A context free grammar is said to be ambiguous if any word has more than one
Le
parse tree or more than one left most derivation or more than one right most derivation is
said to be an ambiguous grammar.
w.
S-> a A->a
9.What is nullable production? Write the method to eliminate the nullable
production?
n
S-> as |bA|E A->E
g.i
Solution :
We find that ε is in L(G), so we cannot eliminate S-> t and A is nullable. So the
rin
resultant grammar
S-> as|b|E
11.What is unit production? ee
gin
The productions of the form A-> B is called as unit productions.
En
Solution
By eliminating the unit productions the resultant grammar is
Le
S-> a
13.What is Chomsky normal form?
w.
A->BC A->a
ww
GNF:
In GNF, every production is of the form
A-> aα
Where a-> is a terminal
66
PART-B
n
ii.Ambiquity in Context Free Grammars with example.[Nov/Dec 2015]
g.i
When is a grammar said to be ambiguous?Explain with the help of an
rin
example. [May/June 2016]
Grammar Introduction :
ee
Grammar is denoted as G. which is defined as.
G = (V, T, P, S)
gin
where,
V = set of variables or Non-Terminals.
T = set of Terminals (V and T are disjoint V T
En
Example :
G = ({E}, {+, *, (,), id} p, E_
where p consists of E E E
w.
E E*E
E (E)
ww
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
n
4) Type 3 Grammar
g.i
Type 0 Grammar :
It is understricted Grammar or phase structure grammar.
rin
A grammar without any restriction.
The productions are of the form.
Type 1 Grammar :
ee
It is contest sensitive grammar or context dependent grammar.
gin
A production of the form.
is called type 1 production if
It is accepted by linear bounded arutomata
En
Type 2 Grammar :
It is context free grammar.
arn
It is regular grammar.
A production of the form A a or A ab, where A, B, v and a
ww
n
id E * E
g.i
lm
id id * E
lm
rin
id id * id
lm
Right most derivation :
ee
If at each step in a derivation is applied to the light most variable is said to be right
gin
most derivation.
Example
E E E | E * E | (E) | id
En
lm
id E
Le
lm
id E * E
w.
lm
id id * E
lm
ww
id id * id
Context free languages (CFL)
The language generated by G, L (G) is
*
L(G) {w | w is in T * and S w}
G
That is,
a string is in L (G) if
69
n
the left then A x1 x2 … xk must be a production.
g.i
The derivation tree.
If we lead the leaves from left to light, we get the string (id + id) * id.
rin
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 { }
ee
(2) The label of the root is S
gin
(3) If a vertex is interior and has label then A must be in V
(4) If vertex has label A and sons vertex A are labeled from left as x1, x2 … xk
then A x1, x 2 ...x k must be a production in p.
En
(5) If a vertex has a label , then it leaf and is the only son of its father.
Ambiguity :
arn
A context free grammar G such that some word has two parse trees is said to be
ambiguous.
An equivalent definition of ambiguity is that some word has more than one left
Le
Solution :
Deriving a string id + id * id
70
For the word id+id*id, there exists two right most derivation.
LMD 1 LMD 2
EEE E E*E
lm lm
id E E E*E
lm lm
id E * E id E * E
lm lm
n
id id * E id id * E
g.i
lm lm
id id * id id id * id
rin
lm lm
Parse tree 1
E ee parse tree 2
E
gin
E + E E * E
id E * E E + E id
En
id id
id id
arn
Let G=(V,T,P,S) be a CFG, Then prove that the terminal string W is in the
Language of variable A then there is a Parse Tree with root A and yield α.
ww
[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
x1 x2 xn
i.e) x1, x2 …. xn must be and A be a production of p, by the definition of a
n
derivation tree.
g.i
Induction :
Assume that the result ais tree for k-1 interior vertices.
rin
Suppose that is the yield of an A-tree with k interior vertices for k>1
The son‟s of the node A could not all be leaves.
ee
Let the labels of the sons be x1, x2 … xn in order from the left.
Then A x1, x2 …. xn is a production in P.
gin
If the ith son is not a leaf it is the root of the subtree, and xi must be a variable.
The portion of delivered from xi must lie to the left of the symbols delivered
from xj.
En
2) x1 i if x i is a var iable
Case 1 :
Le
(xi is a terminal)
If i x i then x 1 is a terminal such that the derivation tree is.
w.
x1 x2 xn
ww
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
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.
n
Each variable and each terminal of G appears in the derivation of some word in L.
g.i
There are no productions of the form A B , where A and B are variable.
If - is not in L, there need be no productions of the form A E
rin
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 form A a , where is a string.
ee
There are two special forms of CFG
1. Chomsky Normal form.
gin
2. Greibach Normal form.
Elemination of Useless symbols :
The useless symbols can be eliminated from a grammar.
En
where w is in T*
Otherwise x is useless
Le
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
*
A w
Lemma 2:
Given a CFG G = (V, T, P, S), we can find an equivalent Grammar G1 = (V1, T1,
P1, S) such that for each x in V1 U T1there exist and in (V1 U T1)* for which
*
S x
73
Example :
Consider the Grammar, and find the useless symbol.
S AB | a
Aa
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.
n
g.i
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-productions from G.
rin
If E-is not in L(G), we can eliminate the E-productions from G.
The method is to determine for each variable A, whether
*
A ee
E, if so it is called as A-nullable
gin
We may replace each production B x1, x 2 , ... x i ... x n 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.
En
Example :
Consider the grammar
arn
S as | bA |
A
Eliminate the E-productions.
Le
Solution :
we find that E-is in L(G), so we eliminate S and A-is nullable
w.
74
SA
AB
BC
Ca
Eliminate the unit productions
Solution :
By eliminating the unit productions, the resultant grammar is
SA
n
g.i
4.CHOMSKY NORMAL FORM
Construct a equivalent Grammar G in CNF for the Grammar. Also discuss
rin
the procedure to convert the Grammar into CNF. [Nov/Dec 2015]
S bA | ab ee
gin
A bAA | as | a
B aBB | bs | b [Nov/Dec 2015]
En
AB
Aa
where A, B, C are variable, a is a term.
Le
Theorem :
Any context free language without E is generated by a Grammar in which the
w.
Proof :
Let G be a CFG, generating a language not containing E.
We can find an equivalent grammar G1 = (V, T, P, S) such that p contains no unit
productions or E-productions.
Thus if a productions has a single symbol on the right, that symbol is a terminal
then the production is an acceptable form.
If production is of the form A x1, x2 …. xm where m 2
75
n
A B1 D1 , D1 B2 D 2 , .. D 2 B3 D3 , ....
g.i
D m 3 Bm 2 D m 2 , D m 2 Bm 1 Bm
Let V” be the now set of non-terminals and P” be the new set of productions
rin
G3 = (V”, T, P”, S) is in CNF
Examble :
S bA | ab
A bAA | as | a
ee
gin
B aBB | bs | b
Find an equivalent grammar in CNF
En
Solution :
(1) S bA is replaced by
S Cb A
arn
Cb b
(2) S aB is replaced by
Le
S Ca B
Ca a
w.
Cb b
A c b AA is replaced by
A Cb D1
D1 AA
(4) A aS is replaced by
A Ca S
Ca a
76
n
Cb b
g.i
(9) B b is in proper form
rin
Resultant grammar :
1. S Cb A |Ca B
A Cb D1 |Ca S | a
B C b S |Ca D 2 | b ee
gin
D1 AA
D2 BB
Ca a
En
Cb b
arn
PART-C
Le
Construct the CNF and GNF for the Grammar.Also Discuss the procedure to
ww
77
Let A 1 B 2 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 B 2 from p and adding the productions
A 1 B1 2 |1 B2 2 |1 B3 2 | ... |1 Br 2
Then L (G) = L (G1)
Lemma 2:
Let G = (V, T, P, S) be a CFG
Let A A1 | A 2 | .... | A r be the set of A-Productions for which A is the left most
n
symbol of RHS
g.i
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
rin
replacing all the A-productions by the productions
A Bi
1) i i s
A Bi B
B i
ee
gin
2) i i r
B i B
En
Theorem :
Every context free language without ε- can be generated by a grammar for which
arn
78
By repeating the above process for each variable, we have only the productions of
the form.
1) A i A j j i
2) Ai a a in T
3) Bi in (VU {B1 , B2 , ...Bi 1 ) *
RHS of any production for Am must be a terminal since Am is the highest
numbered variable
The left most symbol on the RHS of any production for A m-1 must be Am-1 or a
terminal symbol.
n
At the last step examine the productions for the new variables B1, B2, … Bm
g.i
No Bi-productions can start with another Bj therefore all Bi-productions have RHS
beginning with terminals or Ai‟s
rin
Example :
Convert into GNF from the Grammar
G = ({A1, A2, A3}, {a, b}, P, A1)
where P consist of ee
gin
A1A 2 A 3
A 2 A 3 A1| b
A 3 A1A 2 | a
En
Solution :
Step 1 :
arn
Since RHS of the productions for A1 and A2 start with terminal or higher
numbered variables we begin with the productions.
A 3 A1A 2
Le
A 3 A 2 A 3| A 2
A 3 A 3 A1A 3 A 2 | bA3 A 2 (A 2 A 3 A1| b)
w.
A 2 A 3 A1| | b
A 3 A 3 A1A 3 A 2 | bA3 A 2 | a
We now apply lemma 2 to the productions
A 3 A 3 A1A 3 A 2 | bA3 A 2 | a
symbol B3 is introduced and the production A3 A3 A1A3A 2 is replaced by
79
A 3 bA 3 A 2 | a
A 3 bA 3 A 2| B3 | aB3
B3 A1A 3 A 2
B2 A1A 3 A 2 B3
The resultant set of production
A1A 2 A 3
A 2 A 3 A1| b
A 3 bA3 A 2 B3
B3 A1A 3 A 2 B3
n
Now all the productions with A3 on the RHS that start with terminals.
g.i
These are used to replace A3 in the productions A 2 A 3 A1 and then the
productions with A2 on the left are used to replace A2 in the production A1A 2 A 3
rin
The new set of productions
A 3 bA3A2B3|aB3|bA3A2|a
ee
A 2 bA3A2B3A1|aB3A1|bA3A2A1|aA1|b
gin
A1 bA3A2B3A1A3|aB3A1A3|bA3A2A1|aA1A3|aA1A3|bA3
B3 bA3A2B3A1A3A3A2|aB3A1A3A3A2|bA3A2A1A3A3A2|
En
aA1A3A3A2|aA1A3A3A2|bA3A3A2
B3 bA3A2B3A1A3A3A2B3|aB3A1A3A3A2B3|bA3A2A1A3A3A2B3|
aA1A3A3A2B3|aA1A3A3A2B3|bA3A3A2B3
arn
Le
w.
ww
80
PART A
1.
What is Push Down Automata?
The PDA will have an input tape a finite control and a stack.
n
The stack holds a string of symbols from some alphabet
g.i
The device will be non-deterministic having some finite number of choices of
moves in each situations.
rin
Formal Definition :
A push Down Automata M is a system
M = (Q, , , , q 0 , Zo , F)
Where ee
gin
Q is a finite set of states
is an alphabet called the input alphabet
is an alphabet called the stack alphabet
En
q0
in Q is the initial state
Z0
arn
Q x *
w.
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 the finite control and a string of
symbols to replace the top tack symbol.
After selecting a choice, the input head is advanced one symbol.
(q, a, z) {( p1 , , ), (p 2 , 2 ),...( p m , m )}
81
where
q and p1 l i m 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
n
symbol is not used and the input head is not advanced after the move
g.i
(q,, z) {( p1, , ), (p2 , 2 ),...( pm , i )}
ie) The PDA in state q, independent of the input symbol being scanned and with z, the
rin
top symbol on stack, can enter state pi, for any I and replace z by i . The input head is
not advanced.
ee
3.What is instantaneous description of PDA(ID)?
ID of PDA:
gin
The ID records the state , input and stack contents
ID is defined as a triple
(q,w,U)
En
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
n
iii) For all i>=0 u v iw x i y is in L
g.i
7.What are the closure properties of (FL’s)?
CFL‟s are closed under
rin
1. Union
2. Concatenation
3. Kleen Closure
4. Substitution
5. Homomorphism
ee
gin
6. Inverse homorphism
8.What is context free language derived from the following grammar?
En
S->a S b
S-> ab
Solution
arn
L = { an bn |n>=1}
9.Construct CFG to derive the grammar L ={ an bn |n>=1}
Solution :
ww
S-<ab
S->a S b
83
PART-B
The PDA will have an input tape a finite control and a stack.
n
The stack holds a string of symbols from some alphabet
g.i
The device will be non-deterministic having some finite number of choices of
moves in each situations.
rin
Formal Definition :
ee
A push Down Automata M is a system
gin
M = (Q, , , , q 0 , Zo , F)
En
Where
Q x *
84
n
g.i
symbols to replace the top tack symbol.
After selecting a choice, the input head is advanced one symbol.
rin
(q, a, z) {( p1 , , ), (p 2 , 2 ),...( p m , m )}
where
ee
gin
q and p1 l i m are states
a is in
En
Z is a stack symbol
arn
1 is in *
Le
i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any
w.
i enter state p1, replace symbol z by string i and advance the input head one symbol.
ww
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
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.
n
(q,w, i )
g.i
Where q is a state in the finite control
rin
w is a string of input
ee
is a string of stack symbols.
gin
If M (Q, , , , q 0 , z 0 , f ) is a PDA we say
En
(q,aw,z ) (p, w, , )
arn
if (q, a, z) (p, )
To define the language accepted to be the set of all inputs for which some
ww
86
To define the language accepted to be the set of all inputs for which some
choices of moves causes the PDA to enter a final state.
n
g.i
Deterministic push down Automata :
The PDA is deterministic, if atmost one move is possible from any ID.
rin
The PDA M = (Q, , , , q 0 , z 0 , F) is deterministic if
ee
1) For each q in Q and z in , whenever (q,, z) is non empty then (q, a, z)
is empty for all a in .
gin
2) For no q in Q,Z in and a in U{}does (q, a, z) contain more than one
element.
En
The deterministic and non- deterministic models of PDA, are not equivalent with
arn
Solution
w.
Transition Diagram:
87
n
g.i
rin
where is defined as
3) (q1 , O, G) {( q1 , BG )}
En
Let x = O1C1O
88
(q 2 ,,)
n
2.EQUIVALENCE OF PUSHDOWN AUTOMATA AND CFL
g.i
Prove that “if a Language is accepted by empty stack, by some PDA, it can be
rin
accepted by final stat by some other PDA and Vice versa”
Theorem 1 :
En
If L is L(M2) for some PDA M2, then L is N(M1) for some PDA M1.
arn
Proof :
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
n
Let x be in L(M2), then
g.i
(q0, x,z0) (q,, ) for some q in F
Now consider M1 with input x By rule (1)
rin
(q01, x,x0) (q 0 , x , z 0 , x 0 )
(q0,x,z0) (q,, ) ee
gin
By rule (3) and (4)
(q, , , x 0 ) (q e ,,)
En
That is
arn
L(M2) = N(M1)
Theorem 2:
w.
If L is N(M) for some PDA M1, then L is L(M1) for some PDA M2
ww
Proof :
We prove M2 to simulate M1
M2 enters a final state when and only when M1 empties its stack
Let M1 = (Q, , , , q 0 , z 0 , ) be a PDA such that L = N(M1)
Let M2 = (QU{q01, qf}, , U {x0}, 1 , q 01 , x 0 ,{q f })
n
input x
g.i
Let x be in N(M1)
(q 0 , x, z 0 ) (q,,)
rin
Now, consider M2 with input x
(q 0 , x, x 0 ) (q 0 , x, z 0 )
1
ee
(q 0 , x, x 0 ) (q,, x 0 )
(q,, x 0 ) (q f ,,)
gin
Thus
LM 2 NM1
En
arn
Prove that “If L is a context free Language, then there exists a PDA M, such
Le
that L = N(M)” and “If L is n(m) for some PDA M, then L is a context free
language”.
w.
Theorem 3:
ww
If L is a context free Language, then there exists a PDA M, such that L = N(M)
Proof:
Let M is defined as
M ({q}, T, V, , q, s, )
91
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 in
a left most derivation consist of a string of terminals x followed by a string of
variables
M stores the suffix on the left sentential form on its stack after processing the
n
prefix x.
g.i
Theorem 4:
rin
If L is n(m) for some PDA M, then L is a context free language.
Proof :
ee
Let M = ( Q, , , , q 0 , z 0 , ) be the PDA such that L = N(M)
gin
Let G = (V,T,P,S) be a CFG
Where
En
V is the set of objects of the form [q,A,p], for each q and p in q and A in plus the
arn
new symbol S.
T=
Le
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
The pumping lemma for CFL‟s states that there are two short substrings close
together that can be repeated both the same number of times.
Lemma
n
g.i
Let L be any CFL. Then there is a constant n, depending only on >, such that if z is
in L and
rin
| z | n then we may write
1) | Vx | 1
ee
gin
2) | Vwx | n
3) for all I uvisxiy is in L
En
Proof :
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 mathematical induction on i, that path of length for z.
Le
If the word generated by a CNF grammar has no path of length greater than I, then
the word length is no greater than 2i-1
w.
Basis :
ww
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
A B
T1 T2
n
But such a path has k + 2 vertices, and all except last vertex are labeled by
g.i
variables.
Thus there must be some variables that appears twice on the path.
rin
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.
ee
1. The vertices V1 and V2both have the same label say A
2. Vertex V1 is closer to the root than vertex V2
gin
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 generated by vertex V2 and Let Z2 is the
En
yield of subtree T2
Then we can write
arn
Z1 = Z 3 Z2 Z4
Z3 and Z4 cannot both be . Since the production used in the derivation of z1 must
Le
subtree generated by C.
Example :
ww
The pumping lemma can be used to prove a variety of languages not to be context
free.
The pumping lemma can also be used to show that certain languages similar to L1
are not context free.
94
Example :
Solution :
consider Z = anbnc n
n
write Z = uvwxy so as to satisfy the conditions of pumping lemma
g.i
u = am
rin
vwx = an-m bm , w = aj a j
Verify
y = bn-m cn
ee
gin
uvwxy = am an-m bm bn-m cn
En
= n
a bn cn
For I = o
uviwxiy = am aj bj bn-m cn
Le
For i = 2
ww
= a2n-m-j,bm+n-jjcn # L
PART-C
95
[May/June 2016]
Solution
Transition Diagram
n
g.i
rin
PDA M is defined as, ee
gin
1) (q1 , O, R) {( q1 , BR)}
2) (q1 ,1, R) {( q1 , GR )}
En
Let x=0110
96
S OSI| A
n
g.i
A IAO| S | E
rin
Solution
Where V = {S,A}
En
T = {0,1}
To construct a PDA M = Q, , , , q 0 , z 0 , )
arn
Where
Le
Q = {P1,q2}
T {0,1}
w.
{v}U{z 0 }
ww
= {S,A,O,1,Z0}
1) (q1 ,, z 0 ) q 2 , S)
97
2) (q 2 ,, s) (q 2 , OSI )
3) (q 2 ,, s) (q 2 , A)
4) (q 2 ,, A) (q 2 , S)
5) (q 2 ,, A) (q 2 , IAO)
6) (q 2 ,, A) (q 2 ,)
7) (q 2 , o, O) (q 2 ,)
n
8) (q 2 ,1,1) (q 2 ,)
g.i
9) (q 2 , o,1) (q 2 ,)
10) (q 2 ,1,0) (q 2 ,)
rin
4) Design a PDA accepting L = {anbn | n 1} by final state
Solution:
ee
gin
Transition Diagram:
En
arn
Le
Transition function
w.
1) (q 0 , o, z 0 ) (q 0 , Oz 0 )
2) (q 0 , o, o) (q 0 , oo)
ww
M = ( Q, , , , q 0 , z 0 , F)
98
Q = {q0,q1,q2}
{0,1)
{0;1, z 0}
F = {q2}
n
g.i
Final state is reached so the string w = 0011 is accepted.
rin
2. CONVERSION OF PDA TO CFL
Convert the given PDA to CFG.
ee [Nov/Dec 2015]
gin
Given PDA
M = ({q0,q1},{0,1},{x,z0}, , q0,q0, )
En
where is given by
(q 0 , o, z 0 ) (q 0 , xz 0 )
arn
(q 0 , o, x ) (q 0 , xx )
Le
Solution :
99
T = {0,1}
S [q 0 , z 0 , q 0 ] (from rule 1)
S [q 0 , z 0 , q1 ]
1) (q 0 , o, z 0 ) (q 0 , x, z 0 )
n
g.i
The Productions are
[q 0 , z 0 , q 0 ] o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]
rin
[q 0 , z 0 , q 0 ] o [q 0 , x, q1 ][q1 , z 0 , q 0 ]
ee
[q 0 , z 0 , q1 ] o [q 0 , x, q 0 ][q 0 , z 0 , q1 ]
gin
[q 0 , z 0 , q1 ] o [q 0 , x, q1 ][q1 , z 0 , q1 ]
2) There is a move (q 0 , o, x ) {( q 0 , xx )}
En
[q 0 , x, q 0 ] o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]
[q 0 , x, q 0 ] o [q 0 , x, q1 ][q1 , x, q 0 ]
Le
[q 0 , x, q1 ] o [q 0 , x, q 0 ][q 0 , x, q1 ]
w.
[q 0 , x, q1 ] o [q 0 , x, q1 ][q1 , x, q1 ]
ww
3) (q 0 ,1, x ) {( q1 ,)}
The production is
[q 0 , x, q1 ] 1
The production is
100
[q1 , x, q1 ] 1
The production is
[q1 , x, q1 ]
6) (q 0 ,1, x ) {( q1 ,)}
The production is
n
g.i
[q 0 , x, q1 ] 1
rin
As all the productions for [q 0 , x, q 0 ] and [q 0 , z 0 , q 0 ] have [q1 , x, q 0 ] or [q1 , z 0 , q 0 ] on the
right, no string of terminals can be derived from [q 0 , x, q 0 ] or [q 0 , z 0 , q 0 ]
ee
Deleting all production involving one of these variables on either the right or left, we
gin
end up with the following productions.
S [q 0 , z 0 , q1 ]
En
[q 0 , z 0 , q1 ] o [q 0 , x, q1 ][q1 , z 0 , q1 ]
arn
[q 0 , x, q1 ] o [q 0 , x, q1 ][q1 , x, q1 ]
[q 0 , x, q1 ] 1
Le
[q1 , z0 , q1 ]
w.
[q1 , x, q1 ]
[q1 , x, q1 ] 1
ww
(q 0 ,1, z 0 ) {( q 0 , xz 0 )}
(q 0 ,1, x ) {( q 0 , xx )}
101
(q 0 ,0, x ) {( q1 , x )}
n
T = {0,1}
g.i
P = set of productions
S [q 0 , z 0 , q 0 ]
rin
S [q 0 , z 0 , q1 ]
1) (q 0 ,1, z 0 ) {( q 0 , xz 0 )} ee
gin
[q 0 , z 0 , q 0 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]
[q 0 , z 0 , q 0 ] 1 [q 0 , x, q1 ][q1 , z 0 , q 0 ]
En
[q 0 , z 0 , q1 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q1 ]
arn
[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]
Le
2) (q 0 ,1, x ) {( q 0 , xx )}
[q 0 , x, q 0 ] 1 [q 0 , x, q 0 ][q 0 , x, q 0 ]
w.
[q 0 , x, q 0 ] 1 [q 0 , x, q1 ][q1 , x, q 0 ]
ww
[q 0 , x, q1 ] 1 [q 0 , x, q 0 ][q 0 , x, q1 ]
[q 0 , x, q1 ] 1 [q 0 , x, q1 ][q1 , x, q1 ]
3) (q 0 ,0, x ) (q1 , x )
[q 0 , x, q 0 ] 0 [q1 , x, q 0 ]
102
[q 0 , x , q1 ] 0 [q1 , x , q1 ]
4) (q 0 ,, z 0 ) {( q 0 ,)}
[q 0 , z 0 , q 0 ]
[q1 , x, q1 ] 1
6) (q1 ,0, z 0 ) {( q 0 , z 0 )}
n
g.i
[q1 , z 0 , q 0 ] 0 [q 0 , z 0 , q 0 ]
rin
[q1 , z 0 , q1 ] 0 [q 0 , z 0 , q1 ]
[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]
arn
[q 0 , z o , q 0 ] 1 [q 0 , x, q1 ][q1 , z o , q 0 ]
[q 0 , x, q1 ] 1 [q 0 , x, q1 ][q1 , x, q1 ]
Le
[q 0 , x , q1 ] 0 [q1 , x, q1 ]
w.
[q1 , z 0 , q 0 ]
ww
[q1 , x, q1 ] 1
[q1 , z o , q 0 ] 0 [q 0 , z o , q 0 ]
[q1 , z o , q1 ] 0 [q 0 , z o , q1 ]
103
PART - A
1.What is Turing machine?
n
The basic modes of a TM has
g.i
a) A finite control
b) An infinite tape
rin
c) A tape head
*An input tape is divided into cells. The tape is infinite to the right.
ee
*each cell of the tape holds exactly one symbol.
gin
*The tape head moves in both direction.
a1 a2 ….. a1 … an B B ….
En
arn
Finite
Control
Le
w.
M = ( Q, E, , , qo, B, F )
Where
n
Where q-> is the current state of M
g.i
α 1 , α 2-> is the string in
rin
4. Define moves of a Turing machine.
The language accepted by M, denoted L (M) is the set of words in x that cause M
to enter a final state.
ww
105
If f(i1,i2,….ik) is defined for all i1, i2..in then we say f is a total recursive
function.
n
Techniques for TM construction:
g.i
1. Storage in the finite control
2. Multiple tracks
rin
3. Checking off symbols
4. Shifting over
5. Subrartines
ee
gin
8.What is multi head and multi tape turing machines?
A multi tape turing machine consists of a finite control with k tape heads and k tapes.
En
On a single move depending on the state and the scanned by each tape head, the turine
arn
machine.
1. Changes state
Le
A->wB
A->w
Then the grammar is right linear.
*If all productions of a CFG are of the form
106
A->BW
A->W
Then the grammar is left linear.
G=(V,T,P,S)
n
The productions are of the form
g.i
α -> β
rin
α, β-> are string of grammar symbols with α=ϵ
*These grammar derives recursive and recursing enumerable languages these languages
are accepted by Turing Machines. ee
gin
11. What is context sensitive language?
*These grammar derives context sensitive language context sensitive language are
Le
107
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
n
the turn instances T and F(T) are the same.
g.i
15.What are the features of Turing Machine?
rin
It has external memory
It has unlimited memory capacity
ee
Tape head can be read the input at both sides
It produces certain output based on its input.
gin
16.What are the applications of Turing Machines?
Turing machine is used for solving computational , recursive and non recursive
arn
enumerable problems.
108
PART-B
1. Discuss the basic definitions of Turing Machine.
n
Finite
g.i
1. a finite control Control
2. an infinite tape
3. a tape head
rin
An input tape is divided into cells. The tape has a left most cell but it is infinite to the
right.
ee
Each cell of the tape may hold exactly one of a finite numbers of tape symbols.
Initially the n left most cells for n ≥ o hold the input which is string of symbols chosen
gin
from a subset of tape symbols called the input symbols.
The remaining infinity of cells each hold the blank, which is a special tape symbol
that is not an input symbol.
En
In one move of the Turing Machine, depending upon the symbol scanned by the tape
head and the state of the finite control
arn
1. Changes state
2. Prints a symbol on the tape cell scanned replacing what was written there
3. Moves its tape head left or right one cell
Le
Formal Definition:
w.
Where
1 q 2
n
g.i
Where
rin
1 , 2 is the string in *
The language accepted by M, denoted L (M) is the set of words in x that cause M
ww
Solution
Suppose w = 00010
0 0 0 1 0
n
g.i
q0
0 0 0 0 B
rin
q1 q1
ee
gin
0 0 0 B B
En
q3
arn
Le
0 1 B
q0 (qo, O, R) (q1, O, R)
w.
q1 (q1, O, R) (q2, B, L)
ww
q2 (q3, B, R) - (q3, B, R)
q3 - - -
M = ( Q, , , , q 0 , B, {q 3 }
Q = {q0,q1,q2,q3}
111
{0,1)
{0,1, B}
F = {q3}
n
g.i
0000q2BB0000Bq3
rin
2.PROGRAMMING TECHNIQUES FOR TURING MACHINE
ee
Explain the programming techniques for Turing Machine Construction.
[Nov/Dec 2015]
gin
To describe the complicated TM constructions, some techniques are used,
The techniques are
En
3. Checking of symbols
4. Shifting over
5. Subroutines
Le
a. Exercising control
b. Storing a symbol
Example:
Consider a TM „M‟ that looks at the first symbol. Records it in its finite control
and checks that the symbol does not appear elsewhere on its input.
Solution
M = (Q,
Where Q is
112
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)
n
g.i
Initially q0 is the control component of the state and M moves right. The
first component of state becomes q1 and the first symbol seen is stored in
rin
the second component.
1) =([q1,0],1,R),
2) =([q1,1],0,R)
ee
If M has a O stored and sees a 1, or vice versa, then M continues to move to
gin
the right.
1) =([q1,B],0,L),
En
2) =([q1,B],0,L)
arn
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.
Le
Thus if M encounters the tape symbol stored in its state. M halts without
ww
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
B 1 0 0 1 0 1 B B
Finite control
Example:
The tape of a TM takes a binary input greatest than 2, written on the first track and
determined whether it is a prime.
n
Solution:
g.i
The input is surrounded by C and $ on the first tracks.
Thus the allowable input symbols are
rin
[ C, B, B] is identified with C
[O, B, B] is identified with O
ee
[1, B, B] is identified with 1
[$, B, B] is identified with $
gin
[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.
En
If the remainder is zero, the number on the first track is not a prime.
Le
Checking off symbols is useful for visualizing how a Turing Machine recognizes
languages defined by repeated strings such as
ww
{ w w | w in *}
{w c y | w 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
Example:
Solution:
n
g.i
Let Q = {[q, d] | q = q1, q2 …. qq
d = a, b or B}
rin
The second component of the state is used store an input symbol
{ [B, d] | d = a, b or c
ee
The input symbol [B, d] is identified with d
gin
= [x d] | x = B or and d = 0
is defined as
arn
115
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.
The tape head moves to the right, repeatedly store the symbols read in the finite
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 :
n
Construct a Turing machine M = {Q, , , , qo, B, F} which shift non blank
g.i
symbols two cells to the right.
rin
Solution :
Let the tape of M does not contain blanks between non – blanks.
ee
Let Q contains the states of the form [q,Aa,A2] for q = q1 of q2A1,A2 in
Let x be a special symbol not used buy M except in shifting process
gin
M starts the shifting process in state [q1,B,B]
are defined as
En
Subroutines :
The Turing machine can simulate any type of subroutine, include recursive
ww
116
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.
The call is effected by entering the initial state for the subroutine and the
return is effected by the move from the return state.
Example :
Solution :
n
M starts with Om | On on its tape and ends with Omn surrounded by blanks.
g.i
The general idea is to place a 1 after Om | On and then copy the block of n O‟s onto the
right end m time each time erasing one of the O‟s.
rin
The is defined as for copy sub routine as
0 1 2 B
q1 (q2, 2, R) (q4, 1, L) ee
gin
q2 (q2, O, R) (q2, 1, R) (q3, O, L)
q4 (q5, 1, R) (q4, 1, L)
arn
Om | On to B Om-1,q,On 1.
w.
i.e
0 1 2 B
117
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)
n
g.i
q11 (q11, B, R) (q12, B, R)
rin
Simulating for w = 00100
q0 00100
ee
Bq60100 B0q6100 B01q100
gin
B012q20 B012q2 B B012q300 ….
En
A multitape turning machine consists of a finite control with K tape heads and k
taps.
ww
… …
… …
… …
n
g.i
rin
Finite Control
Theorem :
ee
It a language L is accepted by a multitape turning machine. It is accepted by a
single tape turning machine.
gin
Proof :
The other tape is Blank, except for a Marker that holds the symbol scanned by the
corresponding head of M.
Le
Finite Control
ww
… …
… …
119
… …
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
n
Head 2 x
g.i
Tape 2 B1 B2 … … Bm
rin
Head 3 x
Tape 3 C1 C2 … … Cm
ee
gin
Each move of M1 is simulated by a sweep from left to right and then from right to
arn
M2 sweeps right visiting each of the cells with head markers and recording the
symbol scanned by each head of M1
w.
When M2 crosses a head marker it must update the count of head markers to its
right
ww
When no more head markers are to the right M2 has seen the symbols scanned
by each of M1‟s heads.
Now M2 makes a left until it reaches the left most pass it updates the tape symbol
of M1
Finally M2 changes the state of M1 recorded in M2‟s control to complete the
simulation of one move of M1
If new state of M1 is accepting then M2 accepts move of M1
It takes 2k2 moves of M2 to simulate k moves of M1
120
n
2. Context free languages
g.i
3. Context sensitive languages
4. Recursive and recursively enumerable languages
The four classes of languages are grammatically charecterised.
rin
These four classes of languages are called as chomshy hierarchy.
1. Regular Grammar :
ee
It all productions of a CFG are of the form
gin
A wB where A, B are var iables
Aw where w are string of ter min als
En
AB
then we say the grammar is left lineave.
Le
2. Unrestricted Grammar :
ww
121
n
Context sensitive languages are accepted by linear bounded Automata.
g.i
Linear Bounded Automata (LBA)
rin
A linear bounded automata is a non-deterministic turning machine satisfying the
following two conditions.
ee
1. Its input alphabet includes two special symbols and $, the left and right end
marker respectively.
gin
2. The LBA has no moves left from or right from $, nor may it print another
symbol over or $.
The LBA is denoted as
En
M = (Q, , , , q0, , $, F)
Where Q, , , , q 0 , and F are as for a Non-deterministic TM
arn
G = (V, T, P, S)
Where productions are of the form
A
Where A is not-terminal
is a string of terminals
These grammars are type 2 grammars.
These grammars derives context free language (CFLS)
The context free languages are accepted push down automata.
122
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.
This approach will procedure an answer only if T halts not if it loops forever.
n
Accepts : 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
g.i
turning machine.
Lu = {<m‟, w‟> | w L (M) }
rin
The halting problem is related to the membership problem for recursively
enumerable languages.
Halting Problem :
ee
For a given turning machine M and a given string w, instead of asuling whether
gin
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?
En
answer for the two instances I and F (I) are the same.
Reducing One language to another :
ww
n
To construct M1, the moves of M are simulated by changing the move of the form
g.i
(p, a ) (h r , b, D) to
(p, a ) (p, a, s)
rin
i.e) If M ever arrives in state p with a on the current tape, M1 is stuch in this state
and the symbol for ever.
M1 will begin by inserting a new symbol # in the left most cell, moving
everything else over one cell. ee
Then q0 is moved with the tape head to next cell ie.) second cell
gin
M1 has the same moves as M, as well the additional move
(q, # ) (q, # , s) for all possible.
En
States q.
If M ever moves its tape head off, M, will enter an infinite loop, with its tape head
arn
[Nov/Dec 2013]
COMPUTABLE LANGUAGES AND FUNCTIONS
ww
n
i1 i2 ik
the tape separated by 1‟s as O | O | O
g.i
If the TM halts with a tape consisting of Om, then we say that f(i1,i2,... ik,) = m,
where f is the function of k arguments. computed by this Turing machine.
rin
If Turing machine M computes function of k arguments then f need not have a
value for all different k tuples.
ee
If f (i1,i2,... ik,) is defined for all i1,i2,... ik, then we say f is a total recursive
function.
gin
A function f (i1,i2,... ik,) computed by a TM is called partial recursive function.
PART-C
1. DESIGN OF TURING MACHINES
En
Solution:
For eg.
x y
0 0 1 1 B …
q 0 q1 q1 q 2
125
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 -
n
g.i
q2 (q2, O, L) - (q0, X, R) (q2, Y, L) -
q3 q3, Y, R) (q4, B R)
rin
q4 - - - - -
ee
gin
M = ( { q0, q1, q2, q3, q4 }, { 0 , 1}, {0, 1 , X, Y, B}, , q0, B, {q4}
q0 0011 x q1 011 x o q1 11
xq2 0y1
xxyyq3 xxyybq4
w.
Solution
0 1 X Y B
q0 (q1, X, R) (q3, Y, R -
126
q3 q3, Y, R) (q4, B R)
q4 - - - - -
n
q7
g.i
q8
rin
M = ( Q, , , , q 0 , B, F)
ee
Q = {q0,q1,q2,q3,q4,q5,q6,q7,q8}
gin
{0,1)
En
{0,1, x, y, B}
q0 0011 x q1 110 x 1 q1 10
Le
Solution:
O for M<n
The TM started with Om, On on its tape and halts on Om –n on its tape.
M repeatedly replaces its leading O by blank then searches light for a 1 followed by
a O and changes the O to 1.
Next M moves left until it encounters a blank and then repeats the cycle. The repetition
ends 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.
n
2. Beginning the cycle M cannot find a O to change to a blank, because the first
g.i
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.
rin
0 1 B
q0 (qo, B, R) (q5, B, R)
ee
gin
q1 (q1, O, R) (q2, 1, R)
q6 -- -- --
w.
M is defined as
ww
M = {Q, , , , qo, B, F}
= {O, 1}
= {0, 1, B}
F = {q6}
128
BOq6BB..
n
g.i
UNIT-V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTION
rin
Unsolvable Problems and Computable Functions – Primitive recursive functions –
Recursive and recursively enumerable languages – Universal Turing machine.
ee
MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable
problems- Tractable and possibly intractable problems - P and NP completeness -
gin
Polynomial time reductions.
PART-A
En
The subset of recursive enumerable set is called as recursive set. All the languages in the
recursive set are accepted by TM.
ww
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.
Undecidable problem:
n
The union of two recursive language is recursive.
g.i
The union of two recursively enumerable language is recursively enumerable.
If a language L and its complement of are recursively enumerable the L and then L
rin
is recursive.
Does the turing machine M accept input 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
arn
We can construct a language Ld from the table by using the diagonal entries of the table
to determine membershin in L1.
Example :
n
g.i
List A List B
i wi xi
rin
1 1 111
2 10111 10 ee
gin
3 10 0
Solution :
En
M=4
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
Le
101111110 = 101111110
The Solution
w.
i1 = 2
ww
i2 = 1
i3 = 1
i4 = 3
8.What is MPCP?
131
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
n
W1,wi1,…wir = x1 xi1xi2….xir
g.i
9. What is primitive recursive function?
rin
The primitive recursive function is defined as follows
ee
For any k>= 0 and m>= 0 if N k – N ang g1,g2,…gk : Nm -> N are elements of PR ,
gin
then f(g1,g2,…gk) obtained from f and g1, g2,…. Gk by composition is an element
of PR.
En
For any n>=0 any function g:N n+1 -> N in PR and any function.
a) constant functions
ww
n
g.i
PART-B
1. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES
rin
State and prove the closure Properties of recursive and recursively
enumerable languages. [Nov/Dec 2012]
ee
Closure properties of recursive and recursively enumerable languages :
gin
Theorem 1 :
En
Proof :
arn
Let L be a recursive language and M a tuning machine that halts on all inputs
Le
accepts L.
Construct M‟ from M so that if M enters final state on input w then m‟ halts with
w.
accepting.
If M halts without accepting, M‟ enters final state.
ww
133
n
g.i
rin
Theorem 2 :
ee
The union of two recursive language is recursive.
gin
The union of two recursively enumerable language is recursively enumerable.
En
Proof :
Clearly M accepts L1 U L2
134
n
g.i
rin
ee
For recursively enumerable languages the above construction does not work.
gin
Since M1 may not halt.
Instead M can simultaneously simulate M1 and M2 on separate tapes.
En
135
Theorem 2 :
Proof :
n
Since w is in either L or we know that exactly one of M1 or M2 will accept.
g.i
Thus M will always say either „yes‟ or „no‟ but will never say both.
rin
Since M is an algorithm that accepts L, it follows that L is recursive.
ee
gin
En
arn
Le
w.
ww
Define Universal Turing machine and discuss about the Universal codes.
n
symbol.
g.i
We assume that
Q = {q1, q2, … qn}
rin
F = {q2}
There is no need for more than one final state in any TM, since once it accepts it
may as well halt.
ee
The symbols 0, 1, B are used with the synonyms x1, x2, x3 respectively.
gin
Directions L and R used with the synonyms D1 and D2.
The move (q i , x j) q k , x l , D m ) is encods by the binary string.
Oi | O j | O k | O l | O m
En
Example :
137
Solution :
1) (q1,1) (q 3 , 0, R )
(q1, x 2 ) (q 3 , x1, D2 )
Code1 = 01102103101102
2) (q3 , 0) (q1,1, R )
(q 3 , x1) (q1, x 2 , D 2 )
n
Code2 = 03101101102102
g.i
3) (q3 ,1) (q 2 , 0, R )
(q3 , x 2 ) (q 2 , x1, D2 )
rin
Code3 = 03102102101102
4) (q3 , B) (q3 ,1, L)
ee
(q 3 , x 3) (q 3 , x 2 , D1 )
Code4 = 03103103102101
gin
Thus the string denoted by <M, 1011> is
En
|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011
111010010001010011000101010010011000100100101001100010001000100101
arn
111011
Le
Lemma :
Ld is not recursively enumerable.
Suppose we have a list of (0+1)* in canonical order where
w i is the ith word
M j
is the TM whose code is the integer j written in binary
We can construct an infinite table that tells for all I and j whether wi is in L (Mj)
138
n
1) If wj is in Ld then (j, j) entry o, implying that wj is not in L(mj) and
g.i
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
rin
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.
ee
gin
4. THE UNIVERSAL LANGUAGE
En
whether. <M1, w> is Lu, where M1 is the TM with the tape alphabet {0, 1, B}
equivalent.
w.
Theorem 1 :
Lu is recursively enumerable.
ww
Proof :
We shall exhibit a three tape TM M1 accepting Lu
The first tape of M1 is the input tape and the input head on that tape is used to
look up moves of the TM M when given code <M, w> as input.
The second tape of M1 will simulate of M.
The alphabet of M is {0, 1, B}, so each, of M‟s tape can be held in one tape cell of
M1‟s second tape.
The third type holds the state of M with qi represented by Oi
139
n
4) Let xj be the symbol currently scanned by tape head2 and let Oi be the current
g.i
content of tape 3.
Scan tape 1 from the left end to the second 111 looking for a substring beginning 110i |
rin
Oj11. If no such string is found, halt and reject. M has no next move and has not
accepted.
If such a code is found, let it be oi | oj | ok | ol | om Then put Ok on tape 3 print x2 on the
ee
tape cell scanned by tape head 2 and move that head in Direction Dm.
gin
5) Go to step (3)
M1 accepts < M, W > if, M accepts w. It is also true that if m run
forever on w, M1 will run forever on <m, w>.
En
Theorem 2
Lu is not recursive
Proof :
Le
140
n
g.i
rin
Thus we have an algorithm for Ld. since no such algorithm exists, we know our
ee
assumption, that algorithm A for Lu exists is false.
Hence Lu is recursively enumerable, but not recursive.
gin
En
of PR, then
f (g1, g2, … gk) obtained from f and g1 of g2, … gk, by composition is an element PR
ww
n 1
3. For any n 0 any function g : N N in PR, and any function
h : N n 2 N in PR
n 1
the function f : N N obtained from g and h by plimitive recursion is in PR.
4. No other functions are in the set PR.
Initial Function :
The initial function are the following
1. Constant functions :
141
In the case K = 0 we may identify the function Cak with the number a
2. The successor function :
N N is defined by the formula s (x) = x + 1
3. Project Functions
For much K 1 and each I with 1 i k
the projection function
n
P1 : N k N is defined by the formula
k
g.i
P i ( x1, x 2 , ..., x i , ... x k ) x i
k
Composition :
rin
Suppose f is a partial function from Nk to N and for each I with 1 i k, giis a
partial function from Nm to N. The partial function obtained from f and g1, g2, …,
ee
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)
gin
The Primate recursion operation :
Suppose n 0 and g and h are functions of n and n + 2 variables. respectively The
En
f (x, 0) = g (x)
f (x, k+1) = h (x, k, f (x1k))
Le
Mult (x, y) = x * y
are primitive recursive.
If Add is obtained from g and h by primitive recursion. g and h must be functions
of one of three variables.
The equations are
Add (x, 0) = g (x)
Add (x, k+1) = h (x, k, Add (x, k))
Add (x, 0) is x and so g to be the initial functions P11
142
n
Mult (x, 0) = 0
g.i
Mult (x, k+1) = x * (k + 1)
= Add (x * k, x)
rin
= Add (x, Mult (x, k))
5.A.TRACTABLE AND INTRACTABLE PROBLEM
Explain about tractable and intractable problem with suitable
ee
examples.(NOV/DEC2016,Apr/May 2017)
gin
Tractable problem
Tracatable problem is a problem which can recognize with in reasonable time
En
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:
arn
c 0, k 0
PSpace= Space(cn
c 0 , k 0
k
)
143
NPSpace= NSpace(cn
c 0, k 0
k
)
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.
n
There are many languages or decision problems in NP for which no determinstic
g.i
polynomial time algorithm are known.
There are no languages in NP that are known not to be in P.The problem P is the
rin
subset of NP and the following holds
P NP PSpace NPSpace
ee
NP Problem as CNFG satisfiablity problem.
gin
CNF Satisfiablity Problem
C1 C2 C3 ...... Cn
Where Ci=subexpressions
Each Ci is the disjunction of the literal expression for example,
Le
Primitivity Problem:
This is one of the common decision problem stated as,
ww
144
n
is 2m which is fed to the hypothetical polynomial time algorithm for P2. If the decision
algorithm run in O(nK) time , then 0n an input of length 2m, it may take O(2km) which is
g.i
exponential in M.
rin
P1 Instance P2 Instance Decide Yes
Construct
ee
gin
No
En
Reductions:
"L1 is reducible to L2" if there is a computable function 'f' so that checking
whether x L1 is equivalent to check whether f(x) L2.
arn
impossible.
If testing the membership of astring in L2 is possible, then testing a string
w.
145
n
(q1,1) (q 3 , 0, R )
g.i
(q 3 , 0) (q1,1, R )
(q 3 ,1) (q 2 , 0, R )
rin
(q3 , B) (q3 ,1, L)
Solution :
5) (q1,1) (q 3 , 0, R )
ee
gin
(q1, x 2 ) (q 3 , x1, D2 )
Code1 = 01102103101102
En
6) (q3 , 0) (q1,1, R )
(q 3 , x1) (q1, x 2 , D 2 )
arn
Code2 = 03101101102102
7) (q3 ,1) (q 2 , 0, R )
(q3 , x 2 ) (q 2 , x1, D2 )
Le
Code3 = 03102102101102
8) (q3 , B) (q3 ,1, L)
w.
(q 3 , x 3) (q 3 , x 2 , D1 )
ww
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
n
g.i
of strings over some alphabet
rin
i1, i2,…, im, with M 1 such that
wi1, wi2, …, wim = xi1 xi2 … xim
ee
The sequence i1, … im is a solution to this PCP
gin
Example :
List A List B
arn
i wi xi
1 1 111
Le
2 10111 10
w.
3 10 0
ww
Solution :
i1 = 2
i2 = 1
i3 = 1
i4 = 3
n
The Modified version of PCP (MPCP) is the following.
g.i
Given list A and B, of K strings each from * say
A = w1, w2 …, wk
rin
B = x1, x2 …, xk
This problem has a solution if there exists sequence of integers
i1, i2,…, ir, such that
w1wi1 wi2 …wir = xi1 xi2 …xir ee
gin
The difference between the MPCP and PCP is that in the MPCP a solution
required to start with the firs string on each list.
En
Lemma
Proof :
Let
w.
A = w1, w2 …, wk and
B = x1, x2 …, xk
ww
Example :
n
List A List B
g.i
wi xi
rin
1 1 111
3
10111
10
ee
10
0
gin
En
Solution :
Let
C = y0, y1, …. yk+1
D = Z0, Z1, …. Zk+1
Le
w.
List C List D
ww
yi zi
0 1 1 11 1
1 1 1 1 1
2 1 0 1 1 1 10
149
3 10 0
4 $ $
n
Undecidability of PCP
g.i
Theorem :
PCP is undecidable
rin
Proof :
ee
It is sufficient to show that if MPCP were decidable, then PCP would be decidable
whether a TM accepts a given word.
gin
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
En
where
Strings between sucresive #‟s are successive ID‟s in a computation of M with
input w.
Le
given below.
The first pair is
ww
List A List B
# #q0w#
The remaining pairs are grouped as
Group 1 :
List A List B
x x
150
# # for each x in
Group II :
List A List B
9x yp if (q, x) (p, y, R )
n
if (q, B) (p, y, L)
g.i
q# pzy#
rin
Group III :
ee
gin
For each q in F, and x and Y in
List A List B
En
XqY q
arn
Xq q
qY q
Le
Group IV :
w.
List A List B
ww
if x is a prefix of y.
If xy = y then
151
Example :
and is given as
n
0 1 B
g.i
q1 (q2, 1, k) (q2, 0, L) (q2, 1, L)
rin
q2 (q3, 0, L) (q1, 0, R) (q2, 0, R)
q3 -
ee- -
gin
Construct an instance of MPCP with lists A and B
En
w = 01
Solution :
arn
# #q, 01#
The remaining pairs are
w.
Group I :
ww
List A List B
0 D
1 1
# #
Group II
152
List A List B
0q1, 1 q200
from (q1 ,1) (q 2 , 0, L)
1q1, 1 q2 10
0q1, # q2 01 #
from (q1 , B) (q 2 ,1, L)
1q1 # q211#
n
0q2 0 q3 00
g.i
from (q12 , 0) (q 3 , 0, L)
1q2, 0 q0 10
rin
q2 1 0q1 from (q 2 ,1) (q1 , 0, L)
q2 # 0q2#
ee from (q 2 , B) (q 2 , 0, R )
gin
Group III
List A List B
En
0q30 q3
0q31 q3
arn
1q30 q3
Le
1q31 q3
w.
List A List B
ww
0q3 q3
1q3 q3
q30 q3
q31 q3
Group IV :
153
List A List B
q3 # # #
n
g.i
rin
ee
gin
En
arn
Le
w.
ww
154
Fifth Semester
CS6503-THEORY OF COMPUTATION
(Regulations 2013)
n
Time: Three hours Maximum:100 marks
g.i
Answer ALL questions.
rin
1. Define Deterministic Finite Automata (DFA).(pg.no:7)
ee
2. What are the closure properties of regular languages?(pg.no:7)
gin
3. What is meant by Context Free Grammar(CFG)?(pg.no:58)
7.What are the required field of an instantaneous description of a Turing machine? (pg.no:105)
11 (a) (i) Given ∑=(a,b),construct a DFA which recognize the language L={bmabn;m,n>0}.
(6)(pg.no:20)
δ 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)
n
12 (a) (i) Construct a Context Free Grammar for the language L={an: n is odd}.(pg.no:67)(6)
g.i
(ii) Define derivation tree. Explain its uses with an example.(pg.no:70) (10)
rin
Or
ee
(b) Obtain a grammar in chomsky Normal Form(CNF) equivalent to the grammar G with the production
P given.(pg.no:75)
gin
S->aAbB ,A->aA/a, B->bB/b.
(ii)State and explain the pumping lemma for CFG (pg.no:93) (10)
Or
arn
(b) with an example, explain the procedure to obtain a PDA from the given CFG. (16)
Le
14 (a) Discuss the various techniques for Turing Machine construction.(pg.no:112) (16)
Or
w.
Or
(b) (i) What are tractable problems? compare it with intractable problems. (pg.no:143) (10)
Fifth Semester
CS6503-THEORY OF COMPUTATION
(Regulations 2013)
n
Time: Three hours Maximum:100 marks
g.i
Answer ALL questions.
rin
1. Generate NFA-ϵ to represent a*b|c. (pg.no:58)
ee
2. Show whether a language L={0n12n|n>0} is regular or not using pumping lemma.(pg.no:53)
gin
3. Give language of regular expression of a?(b/c)*.(pg.no:69)
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)
arn
6. Differentiate PDA acceptance by empty stack method with acceptance by the final state
method.(pg.no:86)
Le
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
Or
n
(b) Prove for every n >=1 by mathematical induction i3 {n(n 1) / 2}2
1
(pg.no:54) (16)
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
n
g.i
D->aDa|bDb|^ Or
rin
S->Xa|BB
B->b|Sb
X->b
ee
gin
X->a
En
13. (a) (i) Construct a DPDA for even length palindrome. (pg.no:88) (6)
(ii)Prove- if PDA P is constructed from CFG G be the above construction, then N(P)=L(G)(pg.no:91)(10)
arn
Or
(b)Convert the following CFG to PDA and verify for (a+b) and a++.(16)
Le
I->a|b|Ia||Ib|I0|I1,E->I|E+E|E*E|(E)
w.
Or
ww
(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