Cs8501 - Theory of Computation - by DR W T Chembian

You might also like

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

CS8501 THEORY OF COMPUTATION

UNIT I AUTOMATA FUNDAMENTALS


Introduction to formal proof – Additional forms of Proof – Inductive Proofs –
Finite Automata – Deterministic Finite Automata – Non-deterministic Finite
Automata – Finite Automata with Epsilon Transitions

UNIT II REGULAR EXPRESSIONS AND LANGUAGES


Regular Expressions – FA and Regular Expressions – Proving Languages not to
be regular – Closure Properties of Regular Languages – Equivalence and
Minimization of Automata.

UNIT III CONTEXT FREE GRAMMAR AND LANGUAGES


CFG – Parse Trees – Ambiguity in Grammars and Languages – Definition of
the Pushdown Automata – Languages of a Pushdown Automata – Equivalence
of Pushdown Automata and CFG, Deterministic Pushdown Automata.

UNIT IV PROPERTIES OF CONTEXT FREE LANGUAGES


Normal Forms for CFG – Pumping Lemma for CFL – Closure Properties of
CFL – Turing Machines – Programming T chniques for TM.

UNIT V UNDECIDABILITY
Non Recursive Enumerable (RE) Lan ua e – Undecidable Problem with RE –
Undecidable Problems about TM – Post‘s Correspondence Problem, The Class
P and NP.
TOTAL :45PERIODS

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

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

Engineering

SUBJECT CODE: CS8 5 0 1

SUBJECT NAME: Theory Of Computation

Regulation: 2017
TABLE OF CONTENTS
Sl.no Topic Page No
a. Aim & Objective of the subject 1
b. Detailed Lesson Plan 2
Unit I- Introduction To Compilers
c. Part A 4
d. Part B 8
1. Language Processor 8
2. Software Tools used in Compilation 9
3. Analysis Part of Compilation 10
4. Phases Of Compiler 11
5. Cousins Of Compiler 16
6. The Grouping Of Phases 18
7. Compiler Construction Tools 18
Unit II- Lexical Analysis
e. Part A 20
f. Part B 23
8. Need and Role of Lexical Analyzer 23
9. Input Buffering 25
10. Expressing Tokens by Regular Expressions 26
11. Language for Specifying Lexical Analyzer 31
12. Regular Expression to DFA 33
U it III- Syntax Analysis
g. Part A 35
h. Part B 39
13. Need and Role of the Parser 39
14. Various Terminologies in Parsing 41
15. Context Free Grammars 42
16. Writing a Grammar 45
17. Recursive Descent Parser 48
18. Predictive Parser 50
19. Construction of Predictive Parsing Table 53
20. Shift Reduce Parser 55
21. LR Parser 58
22. Construction of SLR Parsing Table 61
23. Construction of LALR Parsing Table 65
24. YACC-Design of a Syntax Analyzer 68
Unit IV- Syntax Directed Translation & Runtime Environment
i. Part A 71
j. Part B 74
25. Source Language Issues 74
26. Storage Organization 76
27. Storage Allocation 77
28. Type Systems 81
29. Specification of a Simple Type Checker 86
30. Syntax Directed Definition 88
31. Construction of Syntax Tree 92
32. Parameter Parsing 94
33. Design of a Predictive Translator 96
Unit V- Code Optimization and Code Generation
k. Part A 100
l. Part B 103
34. Principal Sources of Optimization 103
35. DAG 108
36. Optimization of Basic Blocks 113
37. Global Data Flow Analysis 114
38. Issues in the Design of A Code Generator 122
39. A simple Code Generator Al orithm 124
40. Peephole Optimization 127
m. Industrial / Practical Connectivity of the subject 130
41. University Question papers
AIM AND OBJECTIVE OF THE SUBJECT

The student should be made to:

1. Understand various Computing models like Finite State Machine, Pushdown


Automata, and Turing Machine.
2. Be aware of Decidability and Un-decidability of various problems.
3. Learn types of grammars.

1
DETAILED LESSON PLAN
TEXT BOOKS:

1. Hopcroft J.E., Motwani R. and Ullman J.D, “Introduction to Automata Theory, Languages
and Computations”, Second Edition, Pearson Education, 2008. (UNIT 1,2,3)

2. John C Martin, “Introduction to Languages and the Theory of Computation”, Third Edition,
Tata McGraw Hill Publishing Company, New Delhi, 2007. (UNIT 4,5)

REFERENCES:

1. Mishra K L P and Chandrasekaran N, “Theory of Computer Scie ce - Automata, Languages


and Computation”, Third Edition, Prentice Hall of India, 2004.

2. Harry R Lewis and Christos H Papadimitriou, “Elements of the Theory of Computation”,


Second Edition, Prentice Hall of India, Pearson Education, New Delhi, 2003.

Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
Introduction- Basic Mathematical Notation TI
1 and techniques 1 1

Finite State systems – Basic Definitions – T1


2 Finite Automaton 1 2

3 DFA & NDFA – Finite Automaton with €- moves 1 3 T1

4 Regular Langu ges- Regular Expression 1 4 T1

5 Equivalence of NFA and DFA 1 5 T1

I Equivalence of NDFAs with and without €- T1


6 moves 1 6

Equivalence of finite Automaton and T1


7 regular expressions 1 7

Minimization of DFA T1
8 1 8

9 Pumping Lemma for Regular sets 1 9 T1

10 Problems based on Pumping Lemma. 1 10 T1

2
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
Grammar Introduction T1
11 1 11

Types of Grammar T1
12 1 12

13 Context Free Grammars and Languages 1 13 T1

Derivations and Languages T1


14 1 14
Ambiguity- Relationship between derivation T1
15 and derivation trees 1 15
II
Simplification of CFG T1
16 1 16
Elimination of Useless symbols - Unit T1
17 productions- Null productions 1 17

Greiback Normal form T1


18 1 18

19 Chomsky normal form 1 19 T1

Problems related to CNF and GNF. T1


20 1 20

Pushdown Automata- Definitions T1


21 1 21

22 Moves – Instantan ous descriptions 1 22 T1

Deterministic pushdown automata T1


23 1 23
III Equivalence of Pushdown automata and T1
24 CFL 4 27

Pumping lemma for CFL T1


25 2 29

Problems based on pumping Lemma. T1


26 1 30

27 Definitions of Turing machines 1 31 T1


IV
28 Models 1 32 T1

3
Hours
Sl. Cumulative Books
Unit Topic / Portions to be Covered Required
No Hrs Referred
/ Planned
29 Computable languages and functions 1 33 T1

30 Techniques for Turing machine construction 2 35 T1

Multi head and Multi tape Turing Machines T1


31 1 36

32 The Halting problem 1 37 T1,T2

33 Partial Solvability 1 38 T1,T2

34 Problems about Turing machine 1 39 T1,T2

35 Chomskian hierarchy of languages. 1 40 T1,T2

Unsolvable Problems and Computable


T1,T2
36 Functions 1 41

37 Primitive recursive functions 1 42 T1,T2

Recursive and recursively enumerable


T1,T2
38 languages 2 44

39 Universal Turing machine 1 45 T1,T2

40 V Measuring And Classifyi g Complexity 1 46 T1,T2

Tractable and Intractable problems T1,T2


41 1 47

Tractable and possibly intractable problems T1,T2


42 1 48

43 P and NP completeness 1 49 T1,T2

Polynomial time reductions T1,T2


44 1 50

4
UNIT I- FINITE AUTOMATA
Introduction- Basic Mathematical Notation and techniques- Finite State systems – Basic
Definitions – Finite Automaton – DFA & NDFA – Finite Automaton with €- moves –
Regular Languages- Regular Expression – Equivalence of NFA and DFA – Equivalence
of NDFA‟s with and without €-moves – Equivalence of finite Automaton and regular
expressions –Minimization of DFA- - Pumping Lemma for Regular sets – Problems
based on Pumping Lemma.

PART-A
1. Define the following:
a. Symbol
A symbol is an abstract entity. Letters and digits are symbols.
b. String:
A string is a finite sequence of symbols.
Eg: abc, dog are strings
c. Language:
A language is a set of strings of symbols from one alphabet.
Ф, { ϵ} are languages.
Alphabet:
An alphabet is a finite set of symbols.
2. What is relation?
A binary relation is a set of pairs. The first component of each pair is
chosen from a set called the domain and the second component of each pair is
chosen from a set called a range.
What are the properties of relation?
a. Reflexive:
If aRa for all a in S
b. Irreflexive:
aRa is false for all a in S
c. Transitive:
aRb and bRc imply aRc
d. Symmetric: aRb
implies bRa
e. Asymmetric:
aRb implies that bRa is false

5
DR W T CHEMBIAN

3. What is an equivalence
relation? A relation R that is

i. Reflexive
ii. Symmetric
iii. Transitive
is said to be an equivalence relation.
4. What are the methods of formal proof?
i. Deductive proof
ii. Reduction to definition
iii. Other theorem forms
iv. Theorems that appear not to be if-then statements
5. What are the applications of theory of computatio ?
i. Compiler design
ii. Robotics
iii. Artificial intelligence
iv. Knowledge engineering
6. What is finite state system?
Finite state system:

The finite Automaton is a mathematical model of a system with discrete inputs


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.
Input Tape
0 + 1 . . .
tape head

Finite
control

7. what is Deterministic Finite


Automata(DFA)? DFA:

DFA is defined by a 5 tuple.

M=(Q,Σ,δ,q0 ,F)

6
Where

Q- is a finite set of states

Σ- is a finite input alphabet

q0- in a q is a

9. Define Non deterministic finite automata

(NFA) NFA :

NFA is defined as 5 tuples

M = (Q,Σ,δ,q0,F)

Q-> Set of states

Σ -> set of input symbols

δ > is a transition function mapping from

Qx Σ-> 2Q

qo -> an initial state

F -> set of final stater F<Q

10. Define the language accepted by finite


automata? The language accept d by FA:

The language accepted by FA is called as regular language. It is denoted as


L(M)

L(M) = {X \ δ(q0,x) = p, for p in F}

11. Define ε-closure (q)

ε-closure(q) is the set of all vertices p such that there is a path from q to p.

12. What are the closure properties of regular languages?

1. concatenation :

The concatenation of L1 and L2 is


7
L1L2={ xy|x is in L1 and y is in L2}

2.The kleen closure:

L* = U L i

ie. Zero or more occurrences of a string in L

Lo = {E}
L i= L i-1 L1
ie. One or more number of occurrences of a string in L

13. What is regular expression?

Regular Expression:

1) Ф is a regular expression denoting the language { }


2) E is a regular expression denoting the language {E}
3) For each a in Σ , a is a regular expression de oting the language{a}
4) If r and s are regular expression then r+s , rs and r* are regular expression
denoting the language.

14. State the pumping lemma for regular languages.

Pumping lemma:

Let L be a regular set , then there is a constant n and z is any word in L and |Z|>- n
, we can write z = uvw in such a way

that |uv|<- n

|V|>- and for all i>0 uv i w is in L


15. Construct a DFA that accepts input string of0,s and 1’s that end with 11.

8
PART-B
1.A INTRODUCTION
1. Write short notes on Strings , Alpbhapets and Languages.
Introduction
Strings, Alphabets and Languages
Symbol :
  
A symbol is abstract entity.
 
 Letters and digits are examples of symbols.

String :
  
A string or word is finite sequence of symbol.
 
 Example
a, b and c are symbols and abcd is a string. 
  
The length of a string w is the number of symbols composing the string.
 
 It is denoted as w

  
Example :
 abcd has length 4 
The empty string E, the string consist ng of zero symbols E =0.
A prefix of a string is any number of leading symbols of the string.
Example :
String abc has
prefixes, E, a, ab, abc.
A suffix is any number of t ailing symbols of that string.
Example :
String abc has suffix s
E, c, bc, abc

 A prefixor suffix of a string other than the string itself is called a proper prefix or
suffix.

 The concatenation of two strings is the string formed by writing the first followed by
the second without space.
  
For eg.
 
 Concatenation of dog and house is doghouse
  
The empty string is the identity for concatenation operator

  w w w
Alphabet :
  
An alphabet is a finite set of symbols.

Language :
 9



  
A language is a set of string of symbols from some one alphabet.
 
 The empty set φ and the set consisting of the empty string   are languages.
  
The set of all string over a fixed alphabet  , this language is denoted by *
  
Example
1.  a
* , a, aa, aaa,...
2.  0,1
* , 0,1, 01,10, 00,11, 000 , 000 ,...
Set Notation :
  
Set is a collection of objects without repetition.
  
Finite sets may be specified by two forms
i. listing their members between brachets.
ii. Set former
x|p x 
x in A|p x
 
If every member of A is a member of B, then we write A B and say A is
contained in B.

If A B but A  B , that is every member of A is in B and there is same member of B
that is not in A, then we write A B .
A and B are equal if they have same members That is A = B iff A B nad BA .
Operations on Sets :
1. A B , the union of A nd B is
x|x is in A of x is in B
2. A B , the intersection of A and B is
x|x is in A and x is in B
3. A – B, the difference of A and B is
x|x is in A and x is not in B
4. A x B, the Cartesian product of A and B, is the set of ordered pairs (a, b) such that
a is in A and b is in B.
5. 2A , is the power set of A is the set of all, subsets of A
Example :
Let A = {1, 2}
B = {2, 3}
1. A B = {1, 2, 3}

10
2. A B = {2}
3. A – B = {1}
4. A x B = {(1, 2), (1, 3), (2, 2), (2, 3)}
5. 2 =   1,2,1, 2
A


 If A and B have n and mmembers respectively, then
A x B has nm members

2A has 2n members.
Relations :
  
A binary relation is a set of pairs.

 The first component of each pair is chosen from a set called
the domain and the second
component of each pair is chosen from a set called a range.
 
If R is a relation and (a, b) is a pair in R then we write a R b.
Properties of Relations :
  
We say a relation R on set S is
1. Reflexive
if aRa for all a in S
2. Irreflexive
if aRa is false for all a in S
3. Transitive
if aRb and bRc imply aRc
4. Symmetric
if aRb implies bRa
5. Asymmetic
if aRb implies that bRa is false.
  
Any asymmetric relation must be irreflexive.

Equivalence relation :
  
A relation R that is
i. Reflexive
ii. Symmetric
iii. Transitive
is said be an equivalence relation.
Closure of relations :
  
The transitive closure of R, denoted Rt is defined by
1) If (a, b) is in R, then (a, b) is in R +
2) if (a, b) is in Rt and (b, c) is in R then (a, c) is in R +
3) Nothing is in R+, unless it follows from (1) and (2)
11

The reflexive and transitive
 closure of R denoted R+ is defined
as R+ U a, a|a is in s
Example :
Let R = {(1, 2), (2, 2), (2, 3)} be a relation on the set {1, 2, 3}
R+ = {(1, 2), (2, 2) (2, 3), (1, 3)}
R* = {(1, 2), (2, 2), (2, 3), (1, 3), (1, 1) (3, 3)}
Graphs :

A graphconsist of a finite set of verticles V and a set of paris of vertices E called
edges.
  
Graph is denoted as G = (V, E)
 
A path in a graph is a sequence of verticle V1, V2, V3, …., Vk k 1, such that there
is an edge (Vi, Vi+1) for each I |i k
Directed Graphs:

 of a finite set of vertices V and a set of ordered
A directed graph or digraph consists
pairs of vertices E called arcs.
 
 The arc from V W is denoted as V  W
 
If V W is an arc, we say
V  Pr edecessorof W
W  Successorof V
Trees:
A tree is a digraph with the following properties
1. Three is one vertex, called the root that has no predecessor and from which
there is a path to every vertex.
2. Each vertex oth r than the root has exactly one predecessor.
3. The successor of each vertex is ordered from the left.

If there is a path from vertex V 1 to Vertex
V 2 then V 2 is said to be descendant of
V1 and V1 is said to be an ancestor of V2.

1.B INTRODUCTION TO FORMAL PROOF

  
Explain the four ways of Theorem Proving.
 
Explain the methods of Formal Proof

Introduction to formal Proof :


 
Formal proof is a step by step to solve the problem.

12
  
In format proof

We try to prove that statement B is true because statement A is true.
  
The statement A is called hypothesis and B is called conclusion statement.
The four ways of Theorem Proving
 
(or)
 
Methods of formal proof.
 
(1) Deductive Proof
 
(2) Reduction Proof
 
(3) Other theorem forms
 
(4) Theorems that appear not to be if then statement.
 
Deductive Proof :

A deductive proof consists of a sequence of statements whose truth leads us from

some initial statement called the hypothesis or the given statement (s) to a
conclusion statement.

  that is proved when we go from a hypothesis H to a conclusion C is the
The theorem
statement.
 
“If H then C”
 
We say that C is deducted from H
 The hypothesis may be true or false hypically depending on values of its parameters.
 Theorem 1
 If x  4 then 2 x  x 2
Proof :
 
 The hypothesis H is x 4
 
 The hypothesis has a parameter x and thus is neither true of false.
 
 eg. H is true for x = 6 and false x = 2

  
The conclusion C is 2 x  x 2

  
This statement also uses parameter x and is true for certain values of x and not others.
  
The intuitive argument that tells the conclusion 2 x  x 2 will be true whenever x 4
 
The left side 2x doubles each time x increase by 1

  x 12
The right side x2 grows by the ration 

 x 
  
Hence if x  4 then 2 x  x 2 , for all integers x ie 2 x  x 2 is deducedfrom x  4

 Theorem 2 :

 13



If x is the sum of squares of four positive integers, then 2 x  x 2
Statement Justification

1 x = a2 + b2 + c2 + d2 Given
2 a 1, b 1, c 1, d 1 Given

3 a 2 1, b2 1, c2 1, d 2 1 (2) and properties of arithmetic

4 x 4 (1) and (3) properties of arithmetic

5 2xx2 (5) and Theorem (1)

Reduction to definitions

sure how to start a proof conv rt all terms in the hypothesis to their
If you are not
definitions.
Theorem :
Let S be a finite subset of some inf n te set Let T be the complement of S with
respect to Then T is infinite.
Proof :
Original Statement New Statement

S is finite There is an integer n such |s| = n

U is infinite for no integer P is |U| = p

SUT = U and
T is the complement of S
S T 

  
We use a common proof technique called “Proof by contradiction”
  
In this proof, the contradiction of the conclusion is “T is finite”
 
Let us assume T is finite,
|T| = m for some integer m
|S| = n
 
Since SUT = U and S T the elements of U are exactly the elements of S and T

Thus there must be n + m elements of U |U| = n + m
14
  
The statement that U is finite contradicts the given statement that U is infinite
 
 Thus our assumption is contradiction
 
So T is infinite
Other Theorem Forms :
  
Ways of saying “if – Then”
 
 The other ways in which if H then C might appear.
1. H implies C
2. H only if C
3. C if H
4. whenever H holds, C follows.
If – And – only – If statements :
  
The statement of the form
 
A if and only if B is actually two if – then stateme ts.
(i) if A then B and
(ii) if B then A
Theorems that appear not to be if – then statem nts :

Sometimes we find a theorem that appear ot to have a hypothesis.
  
An example is the well-known fact from the trigonometry.
Theorem
Sin 2  Cos 2 1
Additional Forms of Proof :
1. Proofs about sets.
2. Proofs by contradiction.
3. Proofs by counter example.
Proving Equivalences about s ts :

If E and F are two sets, then the statement E=F means the two sets represented are the
same.

Every element in the set epresented by E is in the set represented by F

And every element in the set represented by F is in the set represented by E.
Example :

The commutative law of union says that we can take the union of two sets R and S in
either order.
i.e., RUS = SUR

The commutative law of union says E = F

The proof of any statement that asserts the equality of two sets E = F, if follows the form
of any if – and – only – if – proof

15
1. Proof that if x is in E then x is in F
2. Proof that if x is in F then x is in E
Theorem :
R (S T) (R S) (R T)
Proof :
The two set of expressions involved are
E R (S T)
R (R S) (R T)
Steps in the part R (S T) ddd

Statement Just fication

1 x is in R U(S T) Given

2 x is in R or x is in S T (1) and definition of union

3 x is in R or x in in both S and T (2) and definition of intersection

4 x is in RUS (3) and definition of union

5 x is in RUT (4) and definition of union

6 x is in (R S) (R T) (4), (5) and definition of intersection

Steps in the „only-if‟ part.


Stat m nt Justification

1 x is in (R S) (R T) Given

2 x is in RUS (1) and definition of intersection

3 x is in RUT (1) and definition of intersection

4 x is in R or x is in both S and T (2) and (3) reasoning about union

5 x is in R or x is in S T (4) and definition intersection

6 x is in RU S T (5) and definition of union.

16
The Contrapositive :
  
The contrapositive of the statement “if H then C” is “if not C then not H”
 
 A statement and its contrapositive are either both true or both false.
  
To see “if H then C” and if not C then not H are logically equivalent.

 There are four cases to consider
1. H and C both true
2. H true and C false
3. C true and H false
4. H and C both false
Proof by contradiction :
  
Another way to prove a statement of the form.

“if H then C is to prove the statement.
  
H and not C implies false hood.
  
Start by assuming both the hypothesis H and the negation of the conclusion C

Completethe proof by showing that som thing known to be false follows logically from
H and C
 
This form of proof is called proof by contradiction.
Counter example :
Statements that have no parameters, or that apply to only a finite number of values of
its parameter are called observations.
It is easier to prove that a statement is not a theorem than to prove it is a theorem.
Example
All primes are odd.
More formally, we might say
if integer x is a prime, then x is
odd Example
There is no pass of integers a and b such
that a mod b = b mod a
 2.A.BASIC DEFINITIONS DFA AND NFA


 of DFA and NFA and the language accepted by DFA
Describe the basic definitions
and NFA with an example.

 Finite state systems :


 17




 Automaton is a mathematical model of a system with discute inputs and
The finite
outputs.
 
 The system can be in a any one of a finite number of internal configuration or states.

  that is
The state of the system summarixes the information concerning past inputs
needed to determine the behavior of the system on subsequent inputs.

The primaryexample of finite automaton is a switching circuit such as control unit of
 a computer.

  number of gates each of which can be in
A switching circuit is composed of a finite
one of two conditions usually 0 and 1
 n
The state of a switching network with n gates  is thus any one of the 2
assignments of 0 or 1 to the various gates.
 
Text editors and the lexical analyzers found in most compiters are designed as
finite state systems.
01 0 1 0 0 0

Finite Co trol
Basic Definitions :
Deterministic finite automata :
A finite automator (FA) consists of a finite set of states and a set of transitions from state to

state that occur on an inpul symbol chosen from an alphabet
For each input symbol there is exactly one transition out of each state.
One state denoted qo is the initial state in which the transition starts.
 
 Some states are design ted s final states or accepting states.


The Deterministic finite automata can be represented as a transition diagram or transition
table.
  
The directed graph is used to represent the transition diagram.
  
The vertices of the graph correspond to the states of FA

If there is a transition 
from state q to state p on input a there is an are labeled a
 from state q to state p

 a string x if the sequence of symbols of x leads start state to
The FA accepts
 final state.

Example :




18




  
The initial state, qo is indicated by the arrow labeled start.
 
 The final state indicated by the double circle.

The FA accepts all string of 0‟s and 1‟s in which both the number 0‟s and the number of
1‟s are even.
 
for eg.
The string accepted by the above FA, 11, 1100, 00, 0000, 1111, 110110
Formal Definition of DFA :

We formally denote a finite automaton by a 5 tube. M =

Q, , , qo , F

Q is a finite set of states

is a finite input alphabet
q 
o in Q is the initial state
 F F Q
is the set of final states
 Qx
is the transition function m pping from
to (q, a)
ie is a state for each state q and input symbol
a
  
 FA is denoted as a finite control

 0 1 0 1 0 0 0

Finite Control
 
 Finite control which is in same state from Q reads a sequence of symbols from
  
written on a tape.
 (q, a) 
In one move, the FA in state q, scanning a symbol a enters state and moves
 its head one symbol to the right.

 
We define a function from
 19



Q x *toQ

 (q, w)
 is the unique state p such that there is a path in the transition diagram from
q to p labeled w

Formally we define

(q, t)  q
(1) 
(2) for all string w and input symbols a
 

(q, wa ) ((q, w), a)



A string x is said to be accepted by FA
 (Q, , , q , F) 
M= o if
 (qo , x)  p, for some P in F


The language accepted by FA, denoted as L(M) L
 x |(qo , x) is in F
(M) = 

 Thelanguage is a regular set if it is the set acc pted by the same FA
Example :
Consider the transition diagram


This FA is denoted as M

= (Q, , , qo , F) where
q ,q ,q ,q
Q=  0 1 2 3 
  0,1
q0 = q0

F= q0

  
is given as a transition table

s01

20
q0 q2 q1
q1 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2


To find the string accepted by DFA, suppose w = 110101 is input to M we have to
(q ,110101 )
find 0

 (q0 ,1) 9,


  (q0 ,110) ((q,1),1)


 (q1 ,1)
 q0

 

  (q0 ,110)  ( (q 0 ,11),0) 


   (q0 , 0)
 q2

 
(q0 ,1101)  (  (q0 ,110),1)
 (q2 ,1)
q3

 

(q0 ,11010)  ( (q0 ,1101),0)


 (q3 , 0)
 q1
 

(q0 ,110101) ((q0 ,11010),1)


(q1 ,1)
q0 F

Thus 110101 is accepted by the FA Thus 110101 is in L(M)

L(M) = is the set of string with an even number of o‟s and an even number of 1‟s

Non – Deterministic finite Automata :



A finite automata model to allow zero, one or more transitions froma state on
the same input sympol. This new model is called a non deterministic
finite Automata (NFA)
21
  
Any set accepted by NFA can also be accepted by DFA.
 
Example


The input sequence a1, a2, a3 ….  an is accepted by NFA, if the transition leads
from the initial state of final state.
Formal Definition of NFA :

Formally we denote a NFA by a 5 – tuple
, , q , F)
M = (Q, 0

where

Q set of states

is a finite input alphabet
q 
o in Q is the initial state
F F Q
is the set of final states
 Q x  to
is the transition function mapping from

Q x 2Q

    
The function can be extended to a function mapping from

Q x * to 2Q and

(i) (q,) {q}


  
(q, a )  (q, w), a 

(ii)  
Example :
Consider the NFA

22
Let the input w = 01001
Solution :
Q  q0 , q1, q2 , q3 , q4 
  0,1
q0 = q0
F = {q2, q4}
:
0 1
q0 {q0, q0,} {q0, q1,}
q1  {q2}
q2 {q2} {q2}
q3 {q4} 
q4 {q4} {q4}

 (q0,01001) q

 (q0 , 0) {q, q3 )

 (q0 , 01)((q0, 0),1)
= ({q0 , q3 },1)
= (q0 ,1) (q3 ,1)

= {q0,q1)
= {q0, q1}
  (q0 , 010 )((q0, 01), 0)

= ({q0 , q1 }, 0)

23
W T CHEMBIAN

= (q0 , 0) (q1 , 0)

= {q0,q3)
= {q0, q3}

  (q0 , 0100 )((q0, 010 ),1)

= ({q0 , q3 }, 0)
= (q0 ,1) (q3 , 0)

= {q0,q3) {q4}
= {q0, q3, q4}

  (q0 , 01001 )((q0, 0100 ),1)

= ({q0 , q3 , q 4 },1)
= (q0 ,1) (q3 ,1) (q4 ,1)

= {q0,q1) {q4}
= {q0, q1, q4}
(q , 01001 ) 
contains a state in F so the input str ng 01001 is accepted by the NFA.

0

2. B.EQUIVALENCE DFA AND NFA


Discuss on the relation between DFA and NFA
Prove that “A language accepted by some DFA iff L is accepted by NFA
[Nov/Dec 2015]

The Equivalence of DFA’s and NFA’s


  
Since every DFA is an NFA it is clear that the class of languages accepted by

NFA‟s includes the regular sets.

for every NFA e can construct an equivalent DFA.
 Theorem :
 Let L be a set accepted by NFA, then there exists a DFA that accepts L.
Proof :
 Let M = Q, , , q0 , F be an NFA which accepts L.
Define a DFA.
 
M1 Q1, 1, 1 , q01, F1 

The states of M1 are all the subsets of the set of states of
1 Q
 M i.e) Q = 2
24




DR W T CHEMBIAN
DR W T CHEMBIAN

 
F1 is the set of all states in Q1containing a final state of M.
 1 
An element of Q will be denoted by [q1, q2, ……….q1) are in Q.
  
2is a single state of the DFA corresponding to the set of states of the NFA
  
q01 = [q0]
 
1 ( [q1], a) = [p1]
iff (q1, a) {p1}
1 ([q1, q2, … qi], a) = [p1, p2, …. pj]
iff 1 ([q1, q2, … qi], a) = [p1, p2, …. pj]
 
It is easy to show by induction on the length of the input string x that
1 (q01, x) = [q1, q2, …qj]
iff
1 (q 0 , x) = [q1, q2, …qj]
Basis :
The result is trivial for 1 x 1 = 0, since q01 = [q0] and x must be 
1 ([q0 ],[q 0 ]
iff
 ( q0 ) q0

Induction :
Suppose that the hypothesis is true for inputs of length m or less
 Let xa be a string of length m + 1 with a in  then

 1 (q01, xa) 1 (1 (q01, x),a)


 By the inductive hypothesis
 1 (q01 , x) [p1 , p2 ,...p j ]
 iff
 (q 0 , x) [p1 , p2 , p j ]

 1 (q0 , xa) 1 (1 (q01, x),a)


 1 [p1, p2 ,.....p j ],a)
 r1 , r2 ,... rk 
 iff
 1 (q0 , xa) ((q0 , x), a)
 1 [p1, p2 ,.....p j ],a)
 r1 , r2 ,... rk 
 Thus
 25



DR W T CHEMBIAN
DR W T CHEMBIAN

iff
1 (q01, xa) [r1 , r2 ,...rk ]
iff
 (q0 , xa) [r1 , r 2 ,... r k ]
which establishes the inductive hypothesis
 1
1 (q 01 , x) is in F exactly when
 (q0 , x) contains a state in F
L (M) = L (M)

3.A.FINITE AUTOMATA WITH -MOVES


 
Discuss on Finite Automata with epsilon Trans t o s. [Nov /Dec 2015]

Finite Automata with Moves :


  
The NFA may be extended to include transitions on the empty input 
 
For eg.









We say an NFA accepts a st ing 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
's do not appear explicitly in w.

 by the NFA by the path q0 – q0 – q0 – q1 – q2 – q2
For eg. the word 002 is accepted
with arcs labeled 0, 0, ,, 2
Formal definition :

A NFA ith  moves to be a 5 – tuple,
M = (Q, , , q0 , F)
  is the transition function maps 
Q x (   to 2Q

(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

DR W T CHEMBIAN
DR W T CHEMBIAN

q0 {q0}   {q1}

q1  {q1}  {q2}

[q2]   {q2} 

  - closue (q) 
  -closue (q) is the set of all vertices p such that there is a path from q to p labeled 
Example : 
 - closure (q0) = {q0, q1, q2}
  
ie) the path consisting of q0 alone is a from q0 to q0 with all arcs labeled  .
 
 Path q0 – q1, shows that q1 is in  closure. (q0)
 
Path q0 – q1 – q2 shows that q2is in  -closure.

 
 can be defined as follows :

1. (q,) closure(q)
2. for w in * and a in 

(q, wa) = - closure
(p) Where p =  p | 




For some p in ((q, w)
3. (R, a) (q, a)

 q in R
 
4. (R, W) (q, w)

q in R
 
 We can define L (M) as
The language accepted by M ( Q, , , q0 , F) to be


{w| q  (q, ) contains a state in F}


Example : 
Consider the NFA








27




DR W T CHEMBIAN
DR W T CHEMBIAN

Find  (q0, q1)


 

 (q0, 01) = closure (((q0 , 0),1)


 

 (q0, 0) = closure (((q0 ,), 0)



 (q0, 01) =  closure (q0 )
= {q0, q1, q2}
 

 (q0, 01) = closure (((q0 ,), 0)


= closure (({q0 , q1 , q 2 ), 0)
= closure ((q0 , 0) (q, 0) (q2, 0))
= closure ({q0 } )
= {q0, q1, q2}
 

 (q0, 01) = closure (((q0 , 0),1)


= closure (({q0 , q1 , q2 ),1)
= closure ((q0 ,1) (q1,1) (q2,1))
= closure ( {q1} )
= closure{q1}
= {q1, q2}

3.B.EQUIVALENCE OF NFA’s WITH AND WITHOUT -MOVES


Prove that “A language accepted by some NFA with - moves iff L is accepted
by without - moves NFA
Theorem :
If L is accepted by an NFA with -transitions then L is accepted by an NFA
without - transition.
Proof :
Let M = (Q, , , q0 , F) be an NFA with - transitions.
Now we have to define NFA without - move M‟
28

DR W T CHEMBIAN
DR W T CHEMBIAN

M1 = (Q1, 1 , 1 , q0 , F1 )
Where F1 = FU{q0} if - closure (q0) contains a state of F
=F Otherwise
 
It is easy show by induction on the length of the input string .We have to prove

1 (q0 , x) (q0 , x)
 
This statement may not be true for x 
1 (q0,) {q 0 }
while (q0 ,) closure (q0 )
  
Therefore we begin our induction at 1
 
Basis :
| x | = 1 Then
 
x is a symbol a

1 (q0 , a) (q0 , a) by the definition of 1
Induction :
| x | >1 Let x = wa
1(q0, wa) 1((q0, w),a)
= 1 (p, a)
= 1 (q, a)
q in p
= (q, a)

q in p
= (p, a)
 

= ((q0 , w), a (q0 , wa )

3.C. CONVERSION OF NFA WITH -MOVES TO NFA WITHOUT -MOVES


 
CONVERT THE NFA WITH -MOVES TO NFA WITHOUT -MOVES


Consider the NFA with - moves

Find an equivalent NFA without - moves


29

W T CHEMBIAN
DR W T CHEMBIAN

Solution :
Given NFA with - moves
M = ({q0, q1, q2}, {0, 1, 2, },  , q0, {q2})
Now we have to define NFA without - move
M1 = (Q1, , 1, q0, F1)
Q = {q0, q1, q3}
 {0,1, 2}
F1 = {q0, q2} - closure (q0) = {q0, q1, q2} contains a state of F.
1

0 1 2

q0 {q0, q1, q2} {q0, q1} {q2}

q1  {q1, q2} {q2}

q2   {q2}
closure(q1 ) {q1, q2 }
closure(q2 ) {q2 }
(q0,) =  closure(q0 )
= {q0, q1, q2}
1 (q0, 0) = closure ((q0 , 0))
= closure (((q0 ,), 0)
= closure (({q0 , q1 , q 2 }, 0)
= closure ((q0 , 0) (q1 , 0) (q2 , 0))
= closure (({q0 } )
= {q0, q1, q2}

1 (q 0 ,1) = closure ((q0 ,1))


= closure (((q0 ,),1)
= closure (({q0 , q1 , q 2 },1)
= closure ((q0 ,1) (q1,1) (q2 ,1))
= closure ( ({q1} )
= {q1, q2}
1 (q 0 , 2) = closure ((q0 , 2))
30

DR W T CHEMBIAN
DR W T CHEMBIAN

= closure (((q0 ,), 2)


= closure (({q0 , q1 , q 2 }, 2)
= closure ((q0 , 2) (q1, 2) (q 2 , 2))
= closure ( {q2 }
= {q2}
 (q1 , 0)
1
= closure ((q1 , 0))
= closure (((q1 ,), 0)
= closure (({ q1, q2 }, 0)
= closure((q1, 0) (q2 , 0))
= closure()
=
1 (q1 , 0) = closure ((q1 , 0))
= closure(((q1 ,),1)
= closure (({ q1, q2 },1)
= closure((q1,1) (q2 ,1) ))
= closure ({q1} )
= {q1, q2}
 (q1 , 2)
1
= closure ((q1 , 2))
= closure (((q1 ,), 2)
= closure (({q1, q2 }, 2)
= closure((q1, 2) (q2 , 2) )
= closure( {q2 })
= {q2}
1 (q 2 , 0) = closure((q2 ,), 0)
= closure (({q2 ), 0)
= closure()
=
1 (q 2 ,1) = closure ((q2 ,),1)
= closure(({q2 ),1)
= closure()
=
1 (q 2 , 2) = closure((q2 ,), 2)
31

DR W T CHEMBIAN
DR W T CHEMBIAN

= closure (({q2 ), 2)
= closure (q2 )
=

Example 2 :
Construct a NFA without - moves from NFA w th - moves

Solution :
 closure (q0) = {q0, q1}
 closure (q1) = {q1}
Let Given NFA with moves
M = (Q, , , q0 , F)
We have to find M‟, NFA without  move
M = (Q, , 1 , q0 , F1 )
closure(q0) containsa statein F
F1 = {q0, q1}
F1 = F {q0 }
 1 (q 0 ,) closure (q 0 )
= {q0, q1}
 (q 0 , 0) =  closure (1 (1 (q 0 ,), 0)
1

=  closure (1 ({q 0 , q1 , ), 0)


= closure (({q0 , 0) (q0 , 0)
= closure ({q0 ), )
= {q0, q1}
32

DR W T CHEMBIAN
DR W T CHEMBIAN

1 (q 0 ,1) =  closure (1 (1 (q 0 ,),1)


=  closure (1 ({q0 , q1 , ),1)
= closure (({q0 ,1) (q1 ,1)
= closure ( {q1))
= {q1}
1 (q1 , 0) = closure (1 (1 (q1 ,), 0)
= closure (1 ({q1 ), 0)
= closure()
=
1 (q1,1) = closure (1 (1 (q1 ,),1)
= closure (1 ({q 2 ),1)
= closure(q1)
= {q1}
0 1

q0 {q0, q1} {q1}

q1  {q1}

4.A.EQUIVALENCE OF FINITE AUTOMATA AND REGULAR EXPRESSIONS


 
Explain about Finite Automata and Regular Expressions. [Nov/Dec 2015]

Equivalence of finite automata and regular expressions :



The languagesaccepted by finite automata are the languages denoted by regular
expressions.
  
For every regular expression there is an equivalent NFA with - transitions.
 
Theorem 1:
Let r be a regular expression. Then there exists an NFA with - transitions that

accepts L (r)

33

DR W T CHEMBIAN
DR W T CHEMBIAN

Proof :
We show by induction on the number of operator in the regular expression r that
there exists an NFA with - transitions having one final state and no transitions
out of this final state such that
L (M) = L (r)
Basis :
For regular expressions having zero operators.
 
The expression r must be , , or a forsomea in 

Induction :
One or more operators in the regular expressions.
  
Assure that the theorem is true for regular expression with fewer that I operators.
i 1
 
Let r have I operators.
Case 1 :
r = r1 + r2
  
Both r1 and r2 must have fewer than i operator
Thus there are 2 NFA‟s
M1 = (Q1 , 1 , 1 , q1,{f 1} with
= L (M1) = L (r1)
Assume Q1 and Q2 are disjoint
Let q0  be a new initial state
f0  be a new initial state
  
Now we can construct NFA with

M = Q1, Q2 {q0, f 0},, 2, , q0,{f 0})
where  is defined by
(i) (q0 ,) {q1, q 2 }
(ii) (q, a) 1 (q, a) for q in Q1 {f 1}and a in 1 {}
(iii) (q, a) 2 (q, a) for q in Q2 {f 2}and a in 2 {}
(iv) 1 (f 1,) 2 (f 2,) {f 0}

34

DR W T CHEMBIAN
DR W T CHEMBIAN

 
Hence
L (M) = L (M1) U L (M2)
Any path in the transition diagram of M from q0 to f0 must begin by going to
either q1 or q2on . If the path goes to q1 it may follow any path in M1 to f1 and then go
to f0 on
Hence L (M) = L (M1) U L (M2)
Case 2 :
r = r1 r 2
Let M1 and M2 be 2 NFA‟s
M1 = Q1 , 1 , 1 , q1,{f 1}) with
L (M1) = L (r1)
and
M2 = Q2 , 2 , 2 , q2 ,{f 2}) with
L (M2) = L (r2)
Assume Q1 and Q2 are disjoi t
No we can construct NFA with
L (M) = L (r)
M = (Q, Q2 , , 2 , ,{q1},{f 2})
where
  is defined as 
(i) (q, a) 1 (q1, a) for q in Q1 {f 1}and a in 1 {}
(ii) (q, a) (q1, a) for q in Q2 {f 1}and a in 2 {}
 (iii) (f 1,) {q2 }

Every path in M from q1 to f2 is a path labeled by some string x form q1 to f1
followed by the edge  from f1 to q2 labeled followed by a path labeled by some
 string y form q2 to f2.
 M
M1 M2

 35



DR W T CHEMBIAN
DR W T CHEMBIAN

  
Thus

L (M) = L (M1) L (M2)
ie. L (M) = {xy | x is in L (M1) and y is in L (M2 )}
Case (iii)
r = r1 *
Let M1 = (Q1 , 1 , 1 , q1,{f 1}) with
L (M1) = L (r1)
Now we can construct NFA
Let M1 = (Q1 {q0 , f 0}, 1 , 1 , q0 ,{f 0}) with
L (M) = L (r)
where
q0  be an new initial state
f0  be an new final state
and  is given by
(i) (q0 ,) (f 1,) {q1, f0 }
(ii) (q, a) 1 (q, a) for q in Q1 {f 1}and a in 1 {}
Any path from q0 to f0 consists either of a path from q0 to q1 on  followed by some
number of paths from q1 to f1and back to q1 on 1 each labeled by a string in
 L (M1) followed by a path from q1 to f1 on a string in L (M1) then to f0 on 
Hence :

 L (M) = L (M1)












 Theorem 2
 If L is accepted by DFA, then L is denoted by the regular expression.
 Proof :
Let L be the set accepted by accepted by the DFA

 36



DR W T CHEMBIAN
DR W T CHEMBIAN

M = ({q1,........, qn }, , , q1, F)
Let
Rijk  denote the set of all string x such that (qi , x)  q j and (qi , y) = ql for any that is
a prefix of x, then l  k
k i.e.) = is the set of all strings that take the FA from state qi to qj without
Rij going

though any state numberd higher than k.



 R
we can define ijk = is the set of all strings that take the 
FA from state qi to qj
without going through any state numbered higher than k.
 
We can definek
R ij recursively.
k k 1 k 1k 1 k 1

=
R ij R (R ) *R R
ik kk kj ij

 
The inputs of Rijk are, either
k 1
in
1) Rij
(or)
k 1 k 1

2) Composed of a string R ik followed by zero of more strings in R kk followed by


k 1

a string Rkj

We must show that for each i, j and k, there exists a regular expression
k k

rij denoting the language R ij


We can show by induction on k.
Basis :
k=0
R ij
0
is a finite set of strings, each of which is either  or a single symbol.
Induction :
 
 The recursive formula Rijk involves only the regular expression operators
a) union
b) concatenation
c) closure
 
By the induction hypothesis, for rijk , we may select the regular expression
rijk , rijk1 (rkkk1 )*rkkj1 rij k1
 
We can conclude
37

DR W T CHEMBIAN
DR W T CHEMBIAN

Rn
L (M) = ij

q j in F
Thus L (M) is denoted by the regular expn.
rn rn  ..........rn whereF{q , q ,.....q }
ij1 ij2 ijp ji j2 jp

4.B.CONVERSION OF REGULAR EXPRESSION TO FINITE AUTOMATA


 
Construct the Finite Automata equivalent to the Regular Expression…

[Nov/DEC 2015]

Construct an NFA for the regular express on 01* + 1 (or) (0 (1*)) + 1


Solution :
Given regular expression
r = 01* + 1
It is of the form r = r1 + r2 where
r1 = 01*
r2 = 1
The NFA for r2 = 1

Now r1 is of the form


r1 = r3 r4
where r3 = 0
r4 = 1*
The NFA for r3 = 0

r4 = r5*
r5 = 1
The NFA for r5 = 1

38

DR W T CHEMBIAN
DR W T CHEMBIAN

The NFA for r4 = r5* = 1*

The NFA for r1 – r3r4 = 01*

The NFA for r = r1 + r2

39

DR W T CHEMBIAN
DR W T CHEMBIAN

4.C.CONVERSION OF FINITE AUTOMATA TO REGULAR EXPRESSION

Convent the following DFA to a regular expression


Solution :
Find R k for i, j, k
ij

Let k = 0
o
{a |(qi , a) q j

if i  j  
R ij  
{a | (qi , a) q j } {} if i  j 
 
r 0
1
11

r0 0
12

r 0 
21

r220  0 1
Rijk , Rikk1 (Rkkk1 )*Rkkj1 Rijk1

rijk rikk1 (rkkk1 )*rkkj1 rijk1


For K = 1
R11(1)  r 110 (r 110 ) *r 110  r 110
= (1) (1) *(1) (1)
= 1* + (1)
= 1*

r12(1)  r 110 (r 110 ) *r 120  r120


= (1) (1) *0 0
= 1* + 0
= 1*0
r21(1)  r 210 (r110 ) *r110  r 210
= (1) *(1) 
= 1*
=
r22(1)  r 210 (r 110 ) *r 120  r220
= (1) *(0) 0 1
= 1*0 0 1
= 0 1
=  0 1
40

DR W T CHEMBIAN
DR W T CHEMBIAN

Let K = 2
r11(2)  r 121 (r 221 ) *r 211  r111
= 1*0 (0 1) *1*
= 1*
= 1*
r12(2)  r 121 (r 221 ) *r 221  r121
= 1*0 (0 1) *(0 1)  1*
= 1*0 (0 1) *1*0
= 1*0(0 1) *
r21(2)  r 221 (r 221 ) *r 211  r211
= (0 1) (0 1) *
= (0 1) * 
=
r22(2)  r 221 (r 221 ) *r 221  r221
= (0 1) (0 1) *(0 1) (0 1)
= (0 1) * (0 1)
= (0 1) *
L (M) = r12(2)
= 1* 0 (0 + 1)*
L (M) = 1* 0 (0 + 1)*

5.MINIMIZATION OF DFA
 
Write and Explain the algorithm for minimization of DFA. Using the above
algorithm minimize the DFA. [MAY/JUNE 2016]
 
Discuss on the relation between DFA and Minimal DFA.[NOV/DEC 2015]


Discuss on equivalence and minimization of Automata. S[Nov/Dec 2015]
Minimization of DFA :
  
There is unique minimum state DFA for every regular set.
 
Theorem :

The minimum state automata  accepting a language L is unique upto an isomorphism
ie) renaming of the states.
41

DR W T CHEMBIAN
DR W T CHEMBIAN

Proof :
Any DFA M = (Q, , , q0 , F) accepting L defines an equivalence relation that is a
refinement of RL
 1
 Thus the number of states of M is greater than or equal to the number of states of M

1
If equality holds then each of the states of M can be identified with one of the states
 of M
 
 Let q be a state of M there must be some x in * such that

  (q0 , x) q , otherwise q would be removed from Q


  
Identify q with the state 1 (q01 , x) of M1
 
 The identification will be consistent.
 
If (q0 , x) (q0 , y) q, then x and y are in the same equivalence class of R L.

Thus 1 (q01, x) 1 (q01, y)


A Minimization Algorithm :
 1
  the minimum state DFA M , equivalent a
There is a simple method for finding
given DFA M = ( Q, , , q0, F)
Let  be the equivalence relation on the states of M.
 If P q, we say p is equivalent to q.
 P q iff for each input string x
(p, x) is an accepting state.
(q, x) is an accepting state.
We say that p is distinguish ble from q if there exists on x such that
 (p, x) is an F and

 (q, x) is not in F and vice versa.

Procedure :
  
An X is placed in the table each time a of states that cannot be equivalent.

  an X is placed in each entry corresponding to one find state and one non – final
Initially
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




DR W T CHEMBIAN
DR W T CHEMBIAN

Example :
Minimize the following DFA

Solution :
b x

c x x

d x x x

e x x x

f x x x x

g x x x x x x

h x x x x x x

a b c d e f g

  
Intially an x placed in each entry corresponding to one final state and one final state.
 
The entries

(c, a), (c, b), (c, d), (c, e), (c, f), (c, g), (c, h)
  
Now the unmarked pairs are
(a, b) (b, d) (d, e) (l, f) (f, g) (g,
 
h) (a, d) (b, e) (d, f) (e, g) (f, h)
(a, e) (b, f) (d, g) (e,

b) (a, f) (b, g) (d, b)
43

DR W T CHEMBIAN
DR W T CHEMBIAN 




(a, h) 
(a, b) 
  (a, 0)  b 
(b, g) is unmarked
 (b, 0)  g 

 (a,1) f 
 (f, c) is marked, so mark (a, b)
 (b,1)  c 


(a, b) 
 (a, 0)  b 
 (b, c) is marked so mark (a, d)
 (d, 0)  c 






(a, l) 
 (a, 0)  b 
 (b, g) is unmarked
 (l, 0)  h 

 (a,1) f 
 (f, f) is unmarked
(l,1) 
f 


(a, f) 
(a, 0) (b, c) is marked so mark (a, f)

b 
(f , 0) 

 c
 
 (b, g) is unmarked
(a, g) 
 
  (a, 0)  b (f, e) is unmarked
 (g, 0)  g 
 
 (a,1) f 
 
  (g,1)  e
 
 (b, g) is unmarked
(a, h) 
 
  (a, 0)  b (f, c) is marked. So mark (a, h)
 (h, 0)  g 

  (a,1) f
  (h,1) c


44




DR W T CHEMBIAN
DR W T CHEMBIAN 




(b, d) 
 (b, 0)  g 
 (g, c) is marked. so mark (b, d)
 (d, 0)  c 


(b, e) 
 (b, 0)  g 
 (g, h) is unmarked
 (e, 0)  h 

 (b,1)  c 
 (c, f) is marked. So mark (b, e)
 (e,1)  f 

(b, f)
 (b, 0)  g 
 (g, c) is marked. So mark (b, f)
 (f , 0)  c 


(b, g) 
 (b, 0)  g 
 (g, g) is unmarked
 (g, 0)  g 

 (b,1)  c 
 (e, e) is marked. So place an x n (b, g)
(g, 
1)  e 


(b, h) 
(b, (g, g) is unmarked
0)  g 

(h, (c, c) is unmarked.
0)  g 

(b, 
1) c 
 (h,1) c 
 (c, h) is unmarked. So place x in (d, e)

 

 (d, e) 
 (d, 0)  c 

 (e, 0)  h 

 (c, c) is unmarked
 
(d, f) 
 (g, g) is unmarked.
  (d, 0) c

 (f , 0) c

  (d,1) g
  (f ,1) g


45




DR W T CHEMBIAN
DR W T CHEMBIAN 




(d, g) 
 (d, 0)  c 
 (c, g) is marked. So place an x in (d, g)
 (g, 0)  g 




(d, h) 
 (d, 0)  c 
 (c, g) is marked. So place an x in (d, g)
 (g, 0)  g 


(d, h) 
 (d, 0)  c 
 (c, g) is marked. So place an x in (d, h)
 (h, 0)  g 


(e, f) 
 (e, 0)  h 
 (h, c) is marked. so place x in (e, f)
 (f , 0)  c 


(e, h) 
(e, 
0)  h (h, g) is unmarked.

(h, 
0)  g (f, c) is marked. So place an x in (e, h)
(e, 

1) f 
(h, 
1) c 

 (h, g) is unmarked
 
(e, g) 
 (f, e) is marked. So place x in (e, g)
 (e, 0)  h 

 (g, 0)  g 
 
 (e,1)  f 

 (g,1)  e 

 (c, g) is marked. So place an x in (f, g)
 
 (f, g)
 (f , 0)  c

  (g, 0)  g

(f, h)



46




DR W T CHEMBIAN
DR W T CHEMBIAN

 (f , 0)  c
(c, g) is marked. So place an x in (f, h)
 (h, 0)  g
(g, h)
 (g, 0)  g
(g, g) is unmarked
 (h, 0)  g
(g,1) e
(e, c) is marked. So place x in (g, h)
 (h,1) c
Now the unmarked place are,
(a, e) (b, h) (d, f) (a, g)
(a, e) 
 (a, 0)  b 
 (b, h) is unmarked
 (e, 0)  h 

 (a,1) f 
 (f, f) is unmarked.
 (e,1)  f 


(a, g) 
 (a, 0)  b 
 (b, g) is marked. So pace an x n (a, g)
(g, 
0)  g 


(b, h) 
(b, (g, g) is unmarked
0)  g 

(h, (c, c) is unmarked.
0)  g 

(b, 
1) c 
 (h,1) c 

 (c, c) is unmarked
 
(d, f) 

 (d, 0) c
(g, g) is unmarked.
 
 (f , 0) c

  (d,1) g
  (f ,1) g
 On completion of the table, we conclude that the equivalent states are
a e b h d f


 Algorithm :
begin

47




DR W T CHEMBIAN
DR W T CHEMBIAN

for p in F and q in Q-F do mark (p, q) for each pair of disfinct states (p, q)in F x
F or (Q – F) x (Q – F) do
if for some input symbol a
((p, a),(q, a) is marked then begin mark (p, q)
recursively mark all unkarked pairs on the lists of other paurs that are marked at this step.
end.
else
for all input symbols a do
put (p, q) on the list for ((p, a),(q, a) unless
((p, a) (q, a)
end.
Method II
For the above same problem, the DFA can be min m zed using DFA minimization
algorithm.
Solution :
Transition table :
0 1

a b f

b g c

c a c

d c g

e h f

f c g

f c g

g g c

h g c

Step 1
The pair of status (b, h) are same state transition. So b and h are equivalent state.
48

DR W T CHEMBIAN
DR W T CHEMBIAN

b h

0 1

a b f

[b,h] g c

*c a c

d c g

e h f

f c g

g c g

Step 2
The pair of status (d, f) are same state transit on.
d f

0 1 0 1

a b f a [b, h] c

[b,h] g c c a c
 [d, c g
*c a c
f]
[d,f] c g
e [b, h] [d, f]
e h f
g g e
f h f
Step e
g g e The pair of states (a, e) are same state transition diagram.
a e

0 1

[a, e] [b, [d, f]

49

DR W T CHEMBIAN
DR W T CHEMBIAN

h]

[b, h] g c

c [a, e] c

[d, f] c g

g g [a, e]

 
Thus the minimized FA is

6.PUMPING LEMMA FOR REGULAR SETS



State the Pumping Lemma for Regular Languages. Show that L

0 i2
 is not regular.
|i is an int eger i 1 [Nov / Dec 2015]

Prove that the Languages are not regular. [Nov/Dec 2015]
Pumping lemma for regular sets :
  
Pumping lemma is a powerful for proving certain languages non-regular.

 
It is also useful for developing algorithms to answer whether the language accepted by
FA is finite or infinite.

 by a DFA M = Q, , , q0, F) with some
If languages is regular it is accepted
particular number of states n.
50

DR W T CHEMBIAN
DR W T CHEMBIAN

 
 Consider an input of n or more symbols a, a 2, … am, m  n and for i = 1, 2 … m let
 (q0 , a, a 2 .... a i ) qi

 the n + 1 states q0, q1, …..qn to be distinct, since there
It is not possible for each of
are only n different states.
 
Thus there are two integers j and k.
O  jk n, such that qj = qk
 
The path labeled a, a2…. a m in the transition diagram of M.


  aj + 1 …. ak is of length atleast 1, and si ce k n , its length is
Since j<k, the string
no more than m.

 is a, a2 … am is in L (M) then a, a2… aj then a, a2 … ajak+1 … am
If qm is in F, that
is also in L (M)
  
Since there is a path from q0 to q m that goes through q j but not around the loop.
  (q0 , a,.... a ja k 1 .... a m ) ((q0 , a1 ... a j ), a n 1 .... a m
= (q j , a k 1 ... a m )
= (qk , a k 1 ... a m )
= qm
Similary we can go around the loop, as many times.
Thus a, .. aj (aj+1 … a) i ak+1 … am is in L (M)
Applications of pumbing lemma :
The pumping lemma is useful in proving that certain languages are not regular.
1. Select the language L you wish to prove non-regular and assume that L is
regular.
 2. The adversary picks n, the constant mentioned in the pumping lemma.
 3. Select a string z in . The choice may depend implicitly on the value of n.
4. The adversary breaks z into u, v and w subject to the constraints that |uv| n
and |v| 1.
5. Achieve a contradiction to the pumping lemma by showing for any u, v and w
determined by the adversary, that there exists an i for which uvw is not in L. I
may then be concluded that L is not regular you selection of i may depend on
n, u, v and w.
 6. The formal statement of the pumping lemma,
 (L) (n) (z)[z in L and| z | n imphess
 and (i ) uviw is in L))]
 Lemma :
 51



DR W T CHEMBIAN
DR W T CHEMBIAN

Let L be a regular set. Then there is constant n, such if z is any word in L and |z| n,
we may write z = uvw in such a way that
| uv | n
| v | 1and
for all i  0 uvi w is in L
Proof :
Z is a, a2 …. a m
u = a1 , a 2 … a j
v = aj+1 …. ak
w = ak+1 … am

The pumping lemma states that if a regular set  contains a long string, z, then it
i
contains infinite set of string of the form uv w.

Problems based on pumping lemma :


1. Show that the language L =  a n bn | n 1 is not r gular
Solution :
(a) Assume that L =  a n bn | n 1 is a regular la guages.
(b) Let n be the integer, ie) no of states in the pumping lemma.
(c) Take one string z from L
Z = ai bi such that | z | n
(4) Break z into 3 strings.
z = uvw
z = ai bi
and mak the assumptions that
uv = am
v = aj
w = ai-m bi
= ai bi
our assumption is correct
i.e) | uv | n 
| v |1
since both the conditions are true the string uvkw is also in
L uvkw = uvvk-1w
= amaj(k-1) ai-mb i
= am+j(k-1) bi

52

DR W T CHEMBIAN
DR W T CHEMBIAN

put k = 0
uvkw = ai-j bi  ai bi
put k = 2
uvkw = ai+j bi  ai bi
Since for k = 0, 2, the strings that does not belong to the language L. So the language is
not regular.
2. Show that L  0i2 |i is an int eger i 1 is not regular.
Solution :
1. Assume L = 0i |i is an int eger i1is regular.
2

2. Let n be the integer, ie. no. of states in the pumping lemma


3. Take one string Z
Let Z = O n 2
4. Break z into z = uvw.
uv = Om 2
V = O j2
W = On2 – m2
uvw = Om2 On 2  m2

Our assumption | uv | n | v |1 is correct.


Since both candidates are true, the string uvkw is also in
L uvkw = uvvk-1w.
= Om2 Oj2 (k1) On2 m2
= Om Oj (k1) On
2 2 2 2
m

for k = 0

uvkw= O m2 O j2 On2 m2

= On  j2 On
2 2

for k = 0, 2 the strings vukw does not belong to the language L. so the language is not
regular.

53

DR W T CHEMBIAN
DR W T CHEMBIAN

PART-C

1.INDUCTIVE PROOFS
1. Prove the following by principle of Induction 02 + 12 + 22 + …. + n2 = n (n
1) (2n 1)
6
[MAY/JUNE 2016]
Use Mathematical induction to solve the problem of Fibonacci series. Also
state the inductive proofs. [MAY/JUNE 2016]

Inductive Proofs :
  
Theorems can be proved by mathematical induction
  
Let P(n) be a statement about a non negative integer
 
 The Principal of mathematical induction is that P(n) follows from
(a) P (o)
(b) P (n-1) imples P(n) for n 1
  
Condition (a) is called the basis and co d tion (h) is called the inductive step.
Example 1 :
Prove by mathematical induction.
n (n 1) (2 1)
02 + 12 + 22 + …. + n2 =  
6
Solution
n (n 1) (2n 1)
Let P (n) = 12 + 22 + 32 + ….. n2 =
6
Basic Step
for n = 0
n
L.H.S.  i2 = 0
i0

R.H.S. n (n 1) (2n 1) 0


6
Inductive step
for n = n – 1
n 1 2 n
 i = (n) (n 1) (2n11) implies  i = n (n 1) (2n 1)
2
i0 6 i0 6
Since

54

DR W T CHEMBIAN
DR W T CHEMBIAN

n 2 n 1 2 2
 i = i +n
i0 i0
n (n 1) (2n 1)
=   n
2 6

= (n 2  n) (2n 1)  6n 2
6

= 2n3  2n 2  n 2  n  6n 2
6

= 2n 3  3n 2  n
6

= n (2n 2  3n 1)
6
= n (n 1) (2n 1)
6
L.H.S = R.H.S.
 Thus by induction it is true for all n 
 Example 2 : 
Prove by mathematical induction.
0 + 1 + 2 + …. + n = n (n 1)
2
Solution
( 1)
Let P (n) = 1 + 2+ 3 + n =
2
Basis Step
for n = 0
n
L.H.S.  i=0
i0
n
R.H.S.  i = n (n 1)
i0 2
=0
Inductive step
for n = n – 1
n n
 i = (n 1)n implies  i = n (n 1)
i0 2 i0 2
Since

55

DR W T CHEMBIAN
DR W T CHEMBIAN

n n
 i = i+ n
i 0 i0
(n 1)n
= n
2
= (n 1)n  2n
2
= n 2  n  2n
2
=n2 1
2
= n(n 1)
2
L.H.S. = R.H.S.
Thus by induction it is true for all n.
Example 3 :
Prove if x 4 then 2 x  x 2 by mathematical inducations
Solution
Basic step :
If x = 4 then 24 42
1616
x = 5 then 25 52
32  25
Inductive step
putx = x + 1
 2 x 1 ( x 1)2
2 x.2 ( x 1)2

2 x.2  2 x 2 ( x1)2
2 x 2  x 2  2 x 1 x
2
 2 x 1
 by x
1
x2 x
1 1
Since x 4, x  4 , where RHS = 2.25
2 x 2 ( x 1) for x  4
56

DR W T CHEMBIAN
DR W T CHEMBIAN

2.PROBLEM ON NFA TO DFA


Convert the following NFA to DFA [Nov/Dec 2015]
Example 1:
1. Let M =  q0 , q10,1 , , q0 ,q1 be an
NFA where (q0, 0)q0, q1)

 (q0 ,1)  q1 



  (q0 , 0) 
 (q0 ,1)  q0 , q1 )
Solution :
We can construct a DFA
M1 = (Q1, {0, 1}, 1 , [q0], F)
1 0 1
Q = all subsets of {q , q )
Q1 =  [q0 ],[q1 ],[q0 ,q1 ], 
F1 = Set of states of Q1 containing state in F
F1 = { [q1], [q0, q1]}
Transition Table : 1
0 1

[q0] [q0, [q1]


q1,]
[q1]  [q0, q1]

[q0, q1] ? ?

  

To find 1 ([q0 , q1 ], 0
  q0 , q1 , 0 = (q0 , 0) (q1 , 0)

= {q0 , q1 } 
= {q0, q1}
1([q0 , q1 ], 0) = [q 0 , q1 ]
57

DR W T CHEMBIAN
DR W T CHEMBIAN

To find 1 ([q 0 , q1 ],1


  q0 , q1 ,1 = (q0 ,1) (q1 ,1)

= {q1 } {q0 , q1 }
= {q0, q1}
1 ([q0 , q1 ],1) = [q 0 , q1 ]

 M1 = (Q1, 1 , 1 , q 01 , F1 )
Q1 = { [q0], [q1], [q0, q1],  }
 {0,1}
1
q0 = [q0]
F1 = { [q1], [q0, q1] }
1
0 1

[q0] [q0, [q1]


q1,]

[q1]  [q0, q1]

[q0, q1] [q0, q1] [q0, q1]

  

Transition Diagram

58

DR W T CHEMBIAN
DR W T CHEMBIAN

Examples 2 :
Consider the following NFA
a b

q0 {q0, {q2}
q1 }

q1 {q1} {q0}

[q2] {q0} {q1, q2}

Construct an equivalent DFA


Solution :
We construct DFA M1
M1 = (Q1, 1 , 1 , q 01 , F1 )
Q1 = { [q0], [q1], [q2], [q0, q1], [q0 , q2], [q1, q2], [q0, q1, q2],  }
 {a, b}
q01 = [q0]
F1 = { [q2], [q0, q1], [q1, q2], [q0, q1, q2] }
1
a b

[q0] [q0, [q2]


q 1]

59

DR W T CHEMBIAN
DR W T CHEMBIAN

[q1] [q1] [q0]

[q2] [q0] [q1, q2]

[q0, q1] ? ?

[q0, q2] ? ?

[q1, q2] ? ?

[q0, q1, q2 ? ?
]

To find 1 ([q0 , q1 ], a
  q0 , q1 , a  = (q0 , a) (q1 , a)

= {q0 , q1 } {q1 }
= {q0, q1}
1 ([q 0 , q1 ], a) = [q 0 , q1 ]
To find 1 ([q0 , q1 ], b
q0 , q1, b = (q0 , b) (q1 , b)
= {q 2 } {q0 }
= {q0, q2}
1 ([q 0 , q1 ], b) = [q 0 , q 2 ]
To find 1 ([q0 , q 2 ], a
  q0 , q 2  , a  = (q0 , a) (q2 , a)

= {q0 , q1 } {q0 }
= {q0, q1}
1 ([q 0 , q 2 ], a) = [q 0 , q1 ]
To find 1 ([q0 , q 2 ], b
 q0 , q 2 , b = (q0 , b) (q 2 , b)

= {q2 } {q1, q2 }
= {q0, q1}
= [q1 , q 2 ]
1 ([q0 , q 2 ], b) = [q1 , q 2 ]
60

DR W T CHEMBIAN
DR W T CHEMBIAN

To find 1 ([q1 , q 2 ], a
  q1, q2  , a = (q1, a) (q2 , a)

= {q1 } {q0 }
= {q0, q1}
1 ([q1 , q 2 ], a) = [q 0 , q 1 ]
To find 1 ([q1 , q2 ], b
  q1, q2  , b = (q1, b) (q2 , b)

= {q0 } {q1 , q 2 }
= {q0, q1, q2}
 ([q1 , q 2 ], b) = [q0 , q1 , q 2 ]
1

To find 1 ([q0 , q1 , q 2 ], a
 q0 , q1 , q 2 , a = (q0 , a) (q1 , a) (q 2 , a)

= {q0 , q1 } {q1 } {q0 }
= {q0, q1,}
 ([q 0 , q1 , q 2 ], a) = [q0 , q1 , ]
1

To find 1 ([q0 , q1 , q 2 ], b )
q0 , q1 , q 2 , b= (q0 , b) (q1 , b) (q 2 , b)

= {q 2 } {q0 } {q1 , q 2 }
= {q0, q1, q2}
 ([q 0 , q1 , q 2 ], b) = [q0 , q1 , q 2 ]
1

a b

q0 [q0, q1] [q2]

q1 [q1] [q0]

[q2] [q0] [q1, q 2]

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

61

DR W T CHEMBIAN
DR W T CHEMBIAN

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

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

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

62

DR W T CHEMBIAN
DR W T CHEMBIAN

UNIT II - GRAMMARS
Grammar Introduction– Types of Grammar - Context Free Grammars and Languages–
Derivations and Languages – Ambiguity- Relationship between derivation and derivation
trees – Simplification of CFG – Elimination of Useless symbols - Unit productions - Null
productions – Greiback Normal form – Chomsky normal form – Problems related to CNF
and GNF.

PART-A

1. Define free grammar.

Grammar G is defines as

G= (V,T,P,S) Where
V = Set of variables or not terminals
T = Set of Terminals
P= set of productions of the form A -> α.
Where A -> is a variable
α-> string of terminals and non terminals
S = a special variable, called start symbol.

2. What is derivation?

If A-> β is a production and α and are any strings than the derivation is

The production A-> β is applied to the string α A to obtain α β

3. What are the types of derivation?

The derivation may be


 Left most derivation

 Right most derivation
Left most derivation :
If at each step of derivation ,a production is applied to the left most non
terminal then the derivation is said to be left most derivation.
63

DR W T CHEMBIAN
DR W T CHEMBIAN

Example :

E -> E+E | E*E|(E) |id

Deriving a string id+id using left most derivation

E=> E+E

=>id+E

=> id+E*E

=> id+id*E

=> id+id*id

Right most derivation:

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.

Example :

E=> E*E

=>E*id

=> E+E*id

4. what is CFL?

The language generated by G is L(G)

L(G) = { w| w is in T* and S => w}

A string is in L(G) if

i) The string consists of only terminals

ii) The string can be derived from S.

5.What is derivation tree?


 
Derivation can be displayed as a derivation tree.

64

DR W T CHEMBIAN
DR W T CHEMBIAN


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 x 1, x2, ….xk from
  
the left then A x1 x2 … xk must be a production.
 
The derivation tree.

 
If we lead the leaves from left to light, we get the string (id + id) * id.

 
More formally Let G (V, T, P, S) be a CFG

 
A tree is a derivation tree for G if

}
(1) Every vertex has a label, which is a symbol of VUTU {
(2) The label of the root is S

(3) If a vertex is interior and has label then A must be in V

(4) If vertex has label A a d sons vertex A are labeled from left as x1,
A x , x ...x
x2 … xk then 1 2 k must be a production in p.
(5) If a vertex has a label , then it leaf and is the only son of its
father.

6.What is an ambiguous gramma ?

A context free grammar is said to be ambiguous if any word has more than one
parse tree or more than one left most derivation or more than one right most derivation is
said to be an ambiguous grammar.

7.What is an useless symbol?

A symbol x is useful if there is a derivation


S= > αxβ=> , for some α, β and w where w is in T* ,Otherwise X is useless.
8.Eliminate the useless symbol, from the following grammar

S-> AB|a A-> a


Solution :
No terminal string is derivable from B. so eliminate B and the production S-> AB.
65

DR W T CHEMBIAN
DR W T CHEMBIAN

S-> a A->a
9.What is nullable production? Write the method to eliminate the nullable
production?

For each variable A, whether A=> E,if so it is called as A-nullable. We may


replace each production B-> x1,x2…xn by all productions striking out some subsets of
those Xi „s that are nullable. But we do not include B-> ε even if all Xi‟s are nullable.

10.Eliminate the E-production from the following grammar.

S-> as |bA|E A->E


Solution :
We find that ε is in L(G), so we cannot eliminate S-> t and A is nullable. So the
resultant grammar
S-> as|b|E
11.What is unit production?

The productions of the form A-> B s called as unit productions.

12.Eliminate the unit productions from the grammar

S-> A A->B B->C C->a


Solution
By eliminating the unit productions the resultant grammar is
S-> a
13.What is Chomsky normal form?

A->BC A->a
Where A,B,C are variables , a is a terminal
14.What is Greibach normal form(GNF)?

GNF:
In GNF, every production is of the form
A-> aα
Where a-> is a terminal

66

DR W T CHEMBIAN
DR W T CHEMBIAN

α->is a string of variables.

PART-B

1.GRAMMAR –TYPES OF GRAMMAR


 
 Discuss about Grammar and define the types of Grammar.
 
Discuss the following

i.CFG and Parse Trees

ii.Ambiquity in Context Free Grammars with example.[Nov/Dec 2015]


 
When is a grammar said to be ambiguous?Explain with the help of an
example. [May/June 2016]

Grammar Introduction :
 
Grammar is denoted as G. which is defined as.
G = (V, T, P, S)
where,
V = set of variables or Non-Terminals.
T = set of Terminals (V and T are disjoint V T 
P = finite set of productions each production is of the form A 
where A is a variable.
is a string of symbols f om (VUT)*
S = is a special variable c lled the start symbol.
Example :
G = ({E}, {+, *, (,), id} p, E
where p consists of E E  E
E E*E
E (E)
E id
Notations used in the Grammar.
1. The capital letters denote variables, S is the start symbol, unless otherwise stated.
2. The lower case letters a, b, c, d, e digits and boldface string are terminals.
3. The capital letters x, y and z denote symbols that may be either terminals or
variables.
4. The lower – case letter u, v, w, x, y and z denote strings of terminals.

67

DR W T CHEMBIAN
DR W T CHEMBIAN

5. The lower – case Greek letters ,,  denote string of Non-terminals and
Terminals.
6. If A ,|2 | ...k
So the example can be written as,
E  E  E | E * E | (E) | id
Types of Grammars :
1) Type 0 Grammar
2) Type 1 Grammar
3) Type 2 Grammar
4) Type 3 Grammar
Type 0 Grammar :
 
It is understricted Grammar or phase structure grammar.
A grammar without any restriction.

The productions are of the form.
Type 1 Grammar :
 
It is contest sensitive grammar or context d p ndent grammar.
A production of the form.
is called type 1 production f 

It is accepted by linear bounded arutomata
Type 2 Grammar :

It is context free grammar.

A production of the form A 
where AV, and (VUT ) *
  
Left hand side has no l ft context or right context.
 
It is accepted by push down automata.
Type 3 Grammar :
  
It is regular grammar.
 
 A production of the form A a or A  ab, where A, B, v and a 
 
It is accepted by finite automata.
Derivation and langauages :
 
If A  B is a production of P and and  are any strings in (VUT)* then
A
G
  
The derivation may be
2. left most derivation
3. right most derivation
68

DR W T CHEMBIAN
DR W T CHEMBIAN

Left most derivation :



  to the left most non-terminal then
If at each step of derivation, a production is applied
the derivation is said to be left-most derivation.
 
Example
E  E  E | E * E | (E) | id
Deriving a string id + id * using left most derivation.
EEE
lm
 id  E
 lm
 id  E * E
 lm
 id  id *
 E lm
 id id
*id lm
Right most derivation :

 If at each step in
a derivation is applied to the light most variable is said to be right
most derivation.
Example
E  E  E | E * E | (E) | id
Deriving a string id + id * using left most derivation.
lm

EEE

lm
 id  E
lm
  id  E * E
lm
 id  id * E

lm
  id  id *id
Context free languages (CFL)
 
The language generated by G, L (G) is
*
L(G) {w | w is in T *andS  w}
G
  
That is,

a string is in L (G) if

69

DR W T CHEMBIAN
DR W T CHEMBIAN

1) The string consists of only terminals


2) The string can be delivered
  
A string of terminals and variables  is called a sentential form if
  
We define grammar G1 and G2 to be equivalent if L(G1 ) = L(G2)

Derivation Trees (Parse tree)
  
Derivation can be displayed as a derivation tree.

 The vertices of
a derivation tree and labeled with terminal or variable symbols of the
grammer or 

are labeled x 1, x 2, ….xk from
If an interior vertex is labeled A, and the sons of A 
the left then A  x1 x2 … xk must be a production.
  
The derivation tree.
  
If we lead the leaves from left to light, we get the string (id + id) * id.
  
More formally Let G (V, T, P, S) be a CFG
 
 A tree is a derivation tree for G if
 (1) Every vertex has a label, which is a symbol of VUTU {}
 (2) The label of the root is S 
 (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.
(5) If a vertex has a label , then it leaf and is the only son of its father.
Ambiguity :
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 most
derivation or more than one right most derivation.
  
Example :
 
Show that the Grammar G
 
E  E  E | E * E | (E) | id is ambiguous.
Solution :
 
 Deriving a string id + id * id










 70



DR W T CHEMBIAN
DR W T CHEMBIAN

 
For the word id+id*id, there exists two right most derivation.
LMD 1 LMD 2
EEE EE *E
lm lm

 id  E EE*E
lm lm

 id  E * E  id  E * E
lm lm

 id  id * E  id  id * E
lm lm

 id  id *id  id  id *id
lm lm

Parse tree 1 parse tree 2


E E

E + E E * E

E * E +
id E E id
id
id id id
For the word id + id * id has two parse trees
 So the grammar is ambiguous.

 2.THE RELATIONSHIP BETWEEN DERIVATION AND DERIVATION TREES



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

 [Nov/Dec 2015]
 Theorem :
Let G = (V, T, P, S) be a context free Grammar
*
Then S   iff there is a derivation tree in Grammar G with yield 
Proof :
 
We shall prove that for any A in V.

 71



DR W T CHEMBIAN
DR W T CHEMBIAN

*
A   if and only if there is an A-tree with  as the yield.

This can be proved by methamatical induction on the number of interior vertices in
the tree.
Basis :
 
If there is only one interior vertex, then the tree is
E

x1 x2 xn

i.e) x1, x2 …. xn must be  and A be a production of p, by the definition of a


derivation tree.
Induction :
  
Assume that the result ais tree for k-1 interior vertices.
 
 Suppose that  is the yield of an A-tree with k inter or vertices for k>1
  
The son‟s of the node A could not all be leaves.
  
Let the labels of the sons be x1, x2 … xn in ord r from the left.
  
Then A x1, x2 …. x n is a production in P.
  
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.
Thus we can write as 1 2 ... n , where for each I between 1 and n.
1) 1  xi if xi is a ter min al
2) x1 i if xi is a variable
Case 1 :
(xi is a terminal)
 
If i  x i then x1 is a terminal such that the derivation tree is.
A

x
x1 2 xn
Case 2 :
(xi is a variable)
  
If x is a variable, then the derivation of i from x i must take fewer than k steps.
  
Thus by the inductive hypothesis, for each xi that is a variable, there is xi tree with
  i
 
Let this tree b Ti

72

DR W T CHEMBIAN
DR W T CHEMBIAN

3.SIMPLIFICATION OF CFG
 
Discuss the methods for the simplification of CFG

Simplification of CFG:

There are several ways to restrict the format 
of productions without reducing the
 generative power of context – free grammar.

If L is a non empty context free language,
then it can be generated by a context free
grammar G with the following properties.
 
 Each variable and each terminal of G appears in the derivat on of some word in L.
 AB 
There are no productions of the form , where A and B are variable.
 
If - is not in L, there need be no productions of the form A  E
 
 If E is not in L, every production be of one of the forms A  BC and A  O
  
Also we can make every productions of the fo m A a , where  is a string.
  
There are two special forms of CFG
1. Chomsky Normal form.
2. Greibach Normal form.
Elemination of Useless symbols :
The useless symbols can be elimi ated from a grammar.
Let G = (V, T, P, S) be a Grammar
* *

A symbol x is useful if there is a derivation S x w , for some , and w,
where w is in T*
  
Otherwise x is useless
 
 There are two aspects of usefulness
1. Some terminal string must be derivation from x
2. x must occur in some string derivation from s
Lemma 1 :
Given a CFG, G = (V, T, P, S) with L (G) =  we can find an equivalent CFG G1.
G1 = (V1, T, P1, S) such that for each A in V1, there is some w in T* for which
*
Aw
Lemma 2:
Given a CFG G = (V, T, P, S), we can find an equivalent Grammar G1 = (V 1, T1,
P1, S) such that for each x in V1 U T1there exist  and  in (V1 U T1)* for which
*
S x
73

DR W T CHEMBIAN
DR W T CHEMBIAN

Example :
Consider the Grammar, and find the useless symbol.
S AB | a
A a
Solution :
We find that no terminal string is derivable from B. we therefore eliminate B and
the production S  ab
Sa
A a
G = {s}, {a}, {s  a}, s) is an equivalent Grammar with no useless symbol.
Elemination of E-Productions :
  
The productions of the form A  E is called E-production
 
 If E-is in L(G). we cannot eliminate all E-productio s from G.
  
If E-is not in L(G), we can eliminate the E-product ons from G.
 
 The method is to determine for each variable A, whether

  * 
A  E, if so it is called as A-nullable
We may replace each production B x1, x2 ,...xi ... xn by all productions striking out
some subsets of those x1‟s that are nullable. but we do not include B  E, even if
all xi,s are nullable.
Example :
Consider the grammar
S  as | bA |
 
Eliminate the E-productions.
Solution :
we find that E-is in (G), so we eliminate S and A-is nullable
so the resultant Grammar
S  as | b |
Elimination of Unit productions :
  
The productions of the form A  B is called is unit productions
  
There need be no productions of the form A  B
  
Unit Productions can be eliminated form the grammar
 
Examble :
Consider the grammar 

74

DR W T CHEMBIAN
DR W T CHEMBIAN

SA
A B
BC
Ca
Eliminate the unit productions
Solution :
By eliminating the unit productions, the resultant grammar is
SA

4.CHOMSKY NORMAL FORM


 
Construct a equivalent Grammar G in CNF for the Grammar. Also discuss
the procedure to convert the Grammar into CNF. [Nov/Dec 2015]
 
Construct the following Grammar in CNF

S  bA | ab
A  bAA | as | a
B  aBB | bs | b [Nov/Dec 2015]

Chomsky normal form (CNF)


In Chomsky normal form, the productions are of the form
 A B
 A a
 where A, B, C are vari ble, a is a term.
 Theorem :

Any context free language without E is generated by a Grammar in which the
 productions are of the form A  BC or A  a . Here A, B and C are variable and a
 is a terminal.
Proof :
  
Let G be a CFG, generating a language not containing E.

  G1 = (V, T, P, S) such that p contains no unit
We can find an equivalent grammar
productions or E-productions.

 on the right, that symbol is a terminal then
Thus if a productions has a single symbol
the production is an acceptable form.
 
 If production is of the form A x1, x2 …. xm where m  2

 75



DR W T CHEMBIAN
DR W T CHEMBIAN

If xi is a terminal a, introduce a new variable ca and a production ca  a then


replace xi by ca

variables be V1 and the few set of productions be P 1 consider
Let the new set of
G2 (V1, T, P1, S)

We modify G2 by adding some additional symbols to V1 and replacing some
 productions of P 1
 
For each production
A B B ..... B of P1 where m  3 we create a new variables D , D, …. D and
1 2 m 1 2 m-2
replace A B1B2 ...... Bm by the set of productions.
A B1 D 1, D 1B2 D2 ,.. D2 B3 D3 ,....
D B D ,D B B
m 3 m 2 m 2 m 2 m 1 m


Let V” be the now set of non-terminals and P” be the ew set of productions
G3 = (V”, T, P”, S) is in CNF
Examble :
S  bA | ab
A  bAA | as | a
B  aBB | bs | b
Find an equivalent grammar in CNF
Solution :
(1) S  bA is replaced by
S Cb A
Cb  b
(2) S  aB is replaced by
S Ca B
Ca  a
(3) A  bAA is replaced by
A Cb AA
Cb  b
A cb AA is replaced by
A Cb D1
D1 AA
(4) A aS is replaced by
A Ca S
Ca  a

76

DR W T CHEMBIAN
DR W T CHEMBIAN

(5) A a is in proper form


(6) B aBB is replaced by
B Ca BB
Ca  a
(7) B Ca BB is replaced by
B Ca D2
D2  BB
(8) B  bS is replaced by
B Cb S
Cb  b
(9) B  b is in proper form
Resultant grammar :
1. S Cb A |Ca B
A Cb D1|Ca S |
a B Cb S |Ca D2
| b D1 AA
D2 
BB Ca 
a Cb  b

PART-C

1.GREIBACH NORMAL FORM


 
Construct the CNF and GNF for the Grammar.Also Discuss the procedure to
convert the Grammar into GNF. [May/June 2016]

Greibach normal form :



GNF uses productions whose light hand sides each start with a terminal symbol
followed by some variable
Lemma 1:
 
Let G = (V, T, P, S) be a FCG

77

DR W T CHEMBIAN
DR W T CHEMBIAN

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 1B1 2 |1B2 2 |1B3 2 | ... |1B r 2
Then L (G) = L (G1)
Lemma 2:
  
Let G = (V, T, P, S) be a CFG
Let A  A1| A2 | .... | Ar be the set of A-Productions for which A is the left most

symbol of RHS
  
Let A B1  B2 | ... |Bs be the remaining A-Productions.

Let G1 = (VU {B}, T, P, S) be the GFG formed by adding the variable B to V and
replacing all the A-productions by the productions
A B 
1) i i  i  s
A Bi B
B  
2) i i  i  r

B i B
Theorem :
Every context free language without ε- can be generated by a grammar for which
every production is the form A a , where A is a variable a is and  is a string of
variables.
Proof :
  
Let G = (V, T, P, S) be a CFG in CNF generating the CFL L.
  
Assume V = {A1, A2, … Am}
  
The first step in the construction is to modify the productions so th
 
at if
Ai A j is a production, then j>i

Starting ith A1 and proceeding to Am we do this as follows
  
We now modify the Ak productions

If Ak A j is a production with j<k, we generate new set of production by
 substituting for Aj, the RHS of each Aj production according to Lemma1.


By repeating the process k-1 times atmost we obtain productions of the form Ak A l 
k according to Lemma 2 introducting a new variable Bk

78
DR W T CHEMBIAN
DR W T CHEMBIAN



By repeating the above process for each variable, we have only the productions of the
form.
1) Ai A j j  i
2) Ai  a a in T
3) Bi in (VU {B1, B2,...Bi1) *

 for Am must be a terminal since Am is the highest
RHS of any production
numbered variable

 on the RHS of any production for Am-1 must be Am-1 or a
The left most symbol
terminal symbol.
  
At the last step examine the productions for the new var ables B1, B2, … Bm

No Bi-productions can start with another B j therefore all Bi-productions have RHS beginning
with terminals or Ai‟s
Example :
Convert into GNF from the Grammar
G = ({A1, A2, A3}, {a, b}, P,
A1) where P consist of
A1A2 A3
A2 A3A1| b
A3A1A2 | a
Solution :
Step 1 :
Since RHS of the productions for A1 and A2 start with terminal or higher
numbered variables we begin with the productions.
A3A1A2
A3A2 A3| A2
A3A3A1A3A2 | bA3A2 (A2 A3A1| b)
 
The new resultant set of productions
A1A2 A3
A2 A3A1| | b
A3A3A1A3A2 | bA3A2 | a
  
We now apply lemma 2 to the productions
 
A3A3A1A3A2 | bA3A2 | a

symbol B3 is introduced and the production A3A3A1A3A2 is replaced by

79

DR W T CHEMBIAN
DR W T CHEMBIAN

A3 bA3A2 | a
A3 bA3A2|B3 | aB3
B3 A1A3A2
B2 A1A3A2 B3
 
The resultant set of production
A1A2 A3
A2 A3A1| b
A3 bA3A2 B 3
B3 A1A3A2 B3
  
Now all the productions with A3 on the RHS that start w th terminals.

These are used to replace A3 in the productions A2 A3A1 and then the 
 productions with A2 on the left are used to replace A2 in the production A1A2 A3
 
The new set of productions
A3 bA3 A2B3|aB3 |bA3 A2 |a
A2  bA3A2B3A1 |aB3A1 |bA3 A2A1 |aA1 |b
A1 bA3A2B3 A1 A3 |aB3 A1 A3 |bA3 A2 A1 |aA1 A3 |aA1 A3 |bA3 B3
 bA3A2 B3 A1 A3 A3A2 |aB3 A1 A3 A3 A2 |bA3 A2 A1 A3 A3 A2 |
aA1 A3 A3 A2 |aA1 A3 A3A2 |bA3 A3 A2
B3  bA3A2B3 A1 A3 A3 A2B3 |aB3A1 A3 A3 A2 B3 |bA3 A2 A1 A3 A3 A2B3 |
aA1 A3 A3 A2B3 |aA1 A3 A3 A2B3 |bA3 A3 A2B3

80

DR W T CHEMBIAN
DR W T CHEMBIAN

UNIT-III PUSHDOWN AUTOMATA


Pushdown Automata- Definitions – Moves – Instantaneous descriptions – Deterministic
pushdown automata – Equivalence of Pushdown automata and CFL - pumping lemma for
CFL – problems based on pumping Lemma.

PART A
1. What is Push Down Automata?
  
The PDA will have an input tape a finite control and a stack.
 
 The stack holds a string of symbols from some alphabet

The device will be non-deterministic having some finite number of choices of moves in
each situations.
Formal Definition :

A push Down Automata M is a system M

= (Q, , , , q0 , Zo , F)
Where

Q is a finite set of states
 
is an alphabet called the input alphabet 
is an alphabet called the stack alphabet

q 
0 in Q is the initial state
Z
0 is  is a particular stack symbol called the start symbol
FFQ
, is the set of fin l states
 ({}) 
is a transition function mapping from Q x x finite subset of
Qx *

2. Define the moves of PDA.



The moves ill be of two types
  
In the first type of move,

An input symbol is used. Depending on the input symbol, the top symbol
  and the state of a finite control, a number of choice are
on the stack
possible.

  for the finite control and a string of symbols
Each choice consists of next state
to replace the top tack symbol.
 
After selecting a choice, the input head is advanced one symbol.
(q, a, z) {(p1, , ), (p2 ,  2 ),...( pm ,  m )}

81

DR W T CHEMBIAN
DR W T CHEMBIAN

where
l i m
q and p1 are states

a is in
Z
is a stack symbol
1 is in *
i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any

i enter state p1, replace symbol z by string i and advance the input head one symbol.

The second type of move called an  is similar to the first, except that
the input
symbol is not used and the input head is not advanced after the move
(q,, z) {(p1, , ), (p2 , 2 ),...( pm ,  i )}
ie) The PDA in state q, independent of the input symbol being scanned and with z, the

top symbol on stack, can enter state pi, for any I and replace z by i . The input head is
not advanced.
3.What is instantaneous description of PDA(ID)?
ID of PDA:
  The ID records the state , input a d stack contents
ID is defined as a triple
(q,w,U)
Where q-> is a state in the finite control
W -> is a string of input
U-> is a string of stack symbols.
4.Define the language accepted by PDA
The language is accepted by PDA in two ways.
1. Language accepted by empty stack.
2. Language accepted by final state.
Language accepted by empty stack:
To define the language accepted to be the set of all inputs for which some sequence of
move causes the PDA to empty its stack.
N(M = {w|q0, ,z0) (P,E,E) for some P in Q}
Language accepted by final state:
To define the language accepted to be the set of all inputs for which some choices moves
causes for PDA to enter a final state.
L(M) = {w|(q0,w,z0) (P,E,U) for some P in F and U in }
5.Define Deterministic Push down Automata?
The PDA M = (q,e,δ,q0,z0,F) is deterministic if
82

DR W T CHEMBIAN
DR W T CHEMBIAN

I)for each q in Q and Z in , whenever δ(q,E,Z) is non empty then δ(q,a,Z) is empty for all
a in Σ.
ii) for no q in Q Z in and a in ΣU{e} does δ(q,a,z) contain more than one element.
6.State the pumping lemma for CFL.
Let L be any CFL . then there is a constant n, depending on L, such that
|z| >= n , then we may write
Z = uvwxy such that
i) |vx| >=1
ii) |vwx|<= n
iii) For all i>=0 u v iw x i y is in L
7.What are the closure properties of (FL’s)?
CFL‟s are closed under
1. Union
2. Concatenation
3. Kleen Closure
4. Substitution
5. Homomorphism
6. Inverse homorphism
8.What is context free language derived from the following grammar?
S->a S b
S-> ab
Solution
S=> aSb=> aabb
S=>aSb=>aaSbb=> aaa Sbbb
………………=> a n-1 S b n-1
=>an bn
L = { an bn |n>=1}
9.Construct CFG to derive the grammar L ={ an bn |n>=1}
Solution :
S-<ab
S->a S b

83

DR W T CHEMBIAN
DR W T CHEMBIAN

PART-B

1.PUSH DOWN AUTOMATA BASIC DEFINITIONS


 
Discuss about the Basic Definitions of Push Down Automata.

Push Down Automata :


 
 The PDA will have an input tape a finite control and a stack.
 
 The stack holds a string of symbols from some alphabet



The device will be non-deterministic having some finite number of choices of
moves in each situations.

Formal Definition :


A push Down Automata M is a system 
M = (Q, , , , q0 , Zo , F)

Where

Q  is a finite set of states

 is an alphabet c lled the input alphabet

  is an alphabet called the stack alphabet

q 0  in Q is the initial state

Z0  is  is a particular stack symbol called the start symbol

FFQ , is the set of final states

 is a transition function mapping from Q x ({}) x   finite subset of

Q x *

84

DR W T CHEMBIAN
DR W T CHEMBIAN

Moves of the Push Down automata


 
 The moves will be of two types
 
 In the first type of move,


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, , ), (p2 ,  2 ),...( pm ,  m )}

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
symbol is not used and the input head is not advanced after the move

(q,, z) {(p1, , ), (p2 , 2 ),...( pm ,  i )}

85

DR W T CHEMBIAN
DR W T CHEMBIAN

ie) The PDA in state q, independent of the input symbol being scanned and with z, the
top symbol on stack, can enter state pi, for any I and replace z by  i . The input head is
not advanced.

Instantaneous descriptions : (ID)


 
 The ID records the state, input and stack contents
 
ID is defined as a triple

(q,w, i )

Where q  is a state in the finite control

w  is a string of input

  is a string of stack symbols. 




If M (Q, , , , q0 , z0 , f ) is a PDA we
say (q,aw,z  ) (p, w,, )

if (q, a, z) (p,)

Language accepted by PDA

1. Language accepted by empty stack


 for which some
To define the language accepted to be the set of all inputs
 sequence of moves causes the PDA to empty its stack.
 M (Q, , , , q , z , f )
For PDA , we define N(M), the language
0
0
accepted by empty stack to be
N(M) {W1(q0 , w, z0 ) , (P, ,), for some in Q}

2. Language accepted by final state:

86

DR W T CHEMBIAN
DR W T CHEMBIAN


  for which some
To define the language accepted to be the set of all inputs
choices of moves causes the PDA to enter a final state.
 
We define L(M), the language accepted by PDA M by final state to be
*

L(M) {W1(q0 , w, z0 ) , (P, , ), for some in P in f and in *}


 PDA, it can be accepted by
If a set of can be accepted by empty stack by some
final state by some other PDA and vice versa.

Deterministic push down Automata :


 
 The PDA is deterministic, if atmost one move is possible from any ID.
 
The PDA M = (Q, , , , q0 , z0 , F) is deterministic f

1) For each q in Q and z in , whenev r (q,, z) is non empty then  (q, a, z)


is empty for all a in .
2) For no q in Q,Z in anda in U{}does (q,a, z) contain more than one
element.
The deterministic and non- deterministic models of PDA, are not equivalent with
respect to the language accepted.
wwR is accepted by Non-deterministic PDA but not by any Deterministic PDA
Design a PDA acc pting L = {wcwR | win (0+1)*} by empty stack
 
 Solution

  M ({q1 , q2 },{0,1, c},{R, B, G}, , q1 , R, )


 
Transition Diagram:

87

DR W T CHEMBIAN
DR W T CHEMBIAN



 
 where  is defined as
 
 1)  (q1 ,O, R) {(q1 , BR)}
 
 2)  (q1 ,O, B) {(q1 , BB)}
3)  (q1 ,O,G) {(q1 , BG)}
4)  (q1 , C, R) {(q2 , R)}
5)  (q1 , C, B) {(q2 , B)}
 
 6)  (q1 ,C, G) {(q2 , G)}
 
 7)  (q1 ,1, R) {(q1 ,GR)}
 
 8)  (q1 ,1, B) {(q1 ,GB)}
 
 9)  (q1 ,1,G) {(q1 ,GG)}
 
 10)  (q2 ,O, B) {(q2 ,)}
 
 11) (q2 ,, R) {(q2 ,)}
 
 12) (q2 ,1, G) {(q2 ,)}
  
Let x = O1C1O
 88



DR W T CHEMBIAN
DR W T CHEMBIAN

 (q1 , O1C1O, R) (q1 ,1C1O, BR ) (q1 , c1o, GBR )



  (q2 ,1O, GBR ) (q2 , O, BR ) (q2 ,, R)

  (q2 ,,)
 
x = O1C1O is accepted by PDA

2.EQUIVALENCE OF PUSHDOWN AUTOMATA AND CFL


Prove that “if a Language is accepted by empty stack, by some
PDA, it can
be accepted by final stat by some other PDA and V ce versa”

Equivalence of acceptance by final state and empty stack


 by some PDA, it can be accepted by final
If a Language is accepted by empty stack,
stat by some other PDA and Vice versa

Theorem 1 :
If L is L(M2) for some PDA M2, then L is N(M1) for some PDA M1.

Proof :
We prove M1 to simul te M2 with the option for
  
M1 should erase its stack whenever M2 enters a final state.
  
We use state qe of M1 to erase the stack

 We use a bottom of stack marker X0 for  M1 does not accidently accept if M 2 empties
its stack without entering a final state
 
 Let M2 = (Q, , , , q0 , z0 , F) be a PDA such that L = L (M2)
 
 Let M1 = (QU {qe,q0,‟}, ,U{x0},1,q01, x0 ,)

 Where 1 is defined as follows

1) 1(q01,, x0 ) {(q0 , z0 , x0 )}
 2) 1(q, a, z) (q, a, z )
 for all q in Q, a in or{}and z in 

 89



DR W T CHEMBIAN
DR W T CHEMBIAN

3) For all q in F and Z in U{x0}


1 (q,, z0 ) (qe ,)
4) For all z in U{x0}
1 (qe ,, z) (qe ,)
  
Rule (1) causes M1 to enter the initial ID of M2
  
Rule (2) allows M1 to simulate M2

Rule (3) and (4) allow M1 to the choice of entering
state qe and erasing its stack thereby
 accepting the input or continuing to simulate M2
  
Let x be in L(M2), then

(q0, x,z0) (q,, ) for some q in F

Now consider M1 with input x By rule

(1) (q01, x,x0)  (q0 , x, z0 , x 0 )
By rule (2) every move of M2 is a legal move for M1 thus.

(q0,x,z0) (q,,)

By rule (3) and (4)

(q,, , x 0 )  (qe ,,)

That is

(q01, x,x0)  (q0 , x, z0 , x 0 ) (q,, , x 0 )  (qe ,,)


M1 accepts x by empty st ck
L(M2) = N(M1)

Theorem 2:

If L is N(M) for some PDA M1, then L is L(M1) for some PDA M2

Proof :
  
We prove M2 to simulate M1
  
M2 enters a final state when and only when M1 empties its stack
 
 Let M1 = (Q, , , , q0 , z0 , ) be a PDA such that L = N(M1)
 1 
Let M2 = (QU{q0 , qf}, , U {x0 }, 1, q01, x0 ,{qf })

Where ' is defined as follows


90

DR W T CHEMBIAN
DR W T CHEMBIAN

1) 1 (q01,, x0 ) {q0 , z0 , x0 )}


2) For all q in Q, a in U{},and Z in 
1 (q, a, z) (q, a, z)
3) For all q in Q
1 (q,, x 0 )  (qf ,)
  
Rule(1) causes M2 to enter the initial ID of M1
  
Rule(2) allows M2 to simulate M1
 
 Rule(3) causes M 2, when X0 appears to enter a final state, thereby accepting the input x
 
Let x be in N(M1)
(q0 , x, z0 ) (q,,)
 
Now, consider M 2 with input x
(q01, x, x0 ) (q0 , x, z0 )
(q0 , x, x 0 ) (q,, x 0 )
(q,, x 0 ) (qf ,,)
 
Thus
LM2  NM1 

3.EQUIVALENCE OF CFL AND PDA


Prove that “If L is a context free Language, then there exists a PDA M,
such that L = N(M)”
 and “If L is n(m) for some PDA M, then L is a context
free language”.

Theorem 3:

If L is a context free Language, then there exists a PDA M, such that L = N(M)

Proof:

Let G = (V,T,P,S) be a CFG in Greibach Norm from generating L


 
Let M is defined as
M ({q},T, V, , q, s, )

91

DR W T CHEMBIAN
DR W T CHEMBIAN

Where

(q, a, A) (q, )

Whenever A a is in p


The PDA M simulates left most derivations of G is in GNF each sentential form
 derivation consist of a string of terminals x followed by a string of
in a left most
variables 

M stores the suffix  on the left sentential form on its stack after processing the
prefix x.

Theorem 4:

If L is n(m) for some PDA M, then L is a context free language.

Proof :

Let M = ( Q, , , , q0 , z0 , ) be the PDA such that L = N(M)

Let G = (V,T,P,S) be a CFG

Where

V  is the set of objects of the form [q,A,p], for each q and p in q and A in plus the
new symbol S.

T=

P  is the set of productions.

1) S  [q0,z0,q] for each q in Q

2) [q,A,qm+1] a[q1, B1, q2 ] [q2 , B2 , q3 ],...[ qm , Bm , qm 1 ]

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

(If m = 0, then the productin is [q,A,q1]  a

92

DR W T CHEMBIAN
DR W T CHEMBIAN

4.PUMPING LEMMA FOR CFL


 
State the pumping lemma for CFL and Show that the language L={anbncn |
n>=1} is not a CFL. [Nov/Dec 2015]

Pumping Lemma for CFL:



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

Let L be any CFL. Then there is a constant n, depending only on >, such that if z is
in L and

| z |  n then we may write

z = uvwxy such that

1) | Vx |  1
2) | Vwx |  n
3) for all I  uvisxiy is in L
Proof :
Let G be a CFG in CNF generating L {}
If Z is in L(G) and Z is long, then any parse tree for z must contain a long path
We prove this by mathem tical induction on i, that path of length for z.


If the word generat d by a CNF grammar has no path of length greater than I, then the

word length is no greater than 2 i-1
Basis :

i = l is trivial

Since the tree must be of the form


Induction step:

 Let I > 1

If there are no paths of length greater than i - 1 in trees T1 and T2, then the

 trees generate words of 2i-1 of fewer symbols
93




DR W T CHEMBIAN
DR W T CHEMBIAN

 
 Thus the entire tree generates a word no longer than 2i-1

S

A B
T1 T2

 
Let G have k variables and let n = 2k

 n, then since | z | > k-1 , any parse tree for z must have a path
If z is in L(G) and | z | 
 of length at least k +1.

 But such apath has k + 2 vertices, and all except last vertex are labeled by
variables.
  
Thus there must be some variables that appears twice on the path.
 
 Some variables must appear twice near the bottom of the path.

 Then there must be two variables V1 and V2 on the path satisfying the following
conditions.
1. The vertices V1 and V2both have the same label say A
2. Vertex V1 is closer to the root than vertex V2
3. The portion of the path from V1 to the leaf is of length atmost k + 1

Now the subtree T1 and T2 is the subtree enerated by vertex V2 and Let Z2 is the
yield of subtree T2
Then we can write

Z1 = Z3 Z2 Z4

Z3 and Z4 cannot both be . Since the production used in
the derivation of z1
 must be of the form A  BC, for some variable B and C


The Subtree T2 must be completely within either the subtree generated by B or
the subtree generated by C.
  
Example :
 
G = ({A,B,C}, {a,b}, P,A)

P : {A  BC, B  BA, A  a, B  b, {C  BA}

Applications of pumping lemma:



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 L 1
are not context free.
94

DR W T CHEMBIAN
DR W T CHEMBIAN

Example :

show that L = {ai b ic i | 1  1} is not context free. Language.


Solution :

Let L = {ai b ic i | i  1} is a CFL


Let n  be the constant of Lemma 1.

consider Z = anbnc n
write Z = uvwxy so as to satisfy the conditions of pumping lemma

u = am

vwx = an-m bm , w = aj aj

y = bn-m cn
Verify

uvwxy = am an-m bm bn-m cn


= an bn cn
uviwxiy = am (an-m-j)-i aj bj (bm-j)I bn-m cn
For I = o

uviwxiy = am aj bj bn-m cn
= am+j bn-m jcn # L
For i = 2

uviwxiy = am a2n-2m-2j aj bj bn-m cn


= a2n-m-j,bm+n-jjcn # L
For i = 0 and i = 2 uviwxi y is not in L so given L = {ai b ic i | i  1} is a CFL
PART-C

1. Construct the PDA to accept the following L={wwR } by empty stack.

95

DR W T CHEMBIAN
DR W T CHEMBIAN

[May/June 2016]

Solution

Transition Diagram

PDA M is defined as,

1)  (q1 ,O, R) {(q1 , BR)}


2)  (q1 ,1, R) {(q1 ,GR)}
3)  (q1 ,O, B) {(q1 , BB)} ,(q2,)}
4)  (q1 ,O,G) {(q1 , BG)}
5)  (q1 ,1, B) {(q1 ,GB)}
6) (q1 ,1, G) {(q1 , GG )}(q2 ,)}
7)  (q2 ,O, B) {(q2 ,)}
8) (q2 ,1, G) {(q2 ,)}
9) (q1 ,, R) {(q2 ,)}
10) (q2 ,, R) {(q2 ,)}

M ({q1 , q2 ,},{0,1},{R, B, G}, ,91 ,

R, ) Let x=0110

(q1, 0110, R) (q1 ,110, BR )

 (q1 ,10, GBR ) (q1 , O, BR )

96

DR W T CHEMBIAN
DR W T CHEMBIAN

 (q1 , O, GGBR ) (q2 ,, R)



 (q1 , O, BGGBR ) (q2 ,,)

 (q1 ,, BBGGBR )

x = 0110 is accepted by PDA

4) Convert the Grammar

SOSI| A

A IAO| S | E

Design a PDA that accepts the same language by empty stack.

Solution

The Given grammar

G=(V,T,P,S)

Where V = {S,A}

T = {0,1}

To construct a PDA M = Q, , , , q0 , z0 , )

Where

Q = {P1,q2}

 T {0,1}

{v}U{z0 }

= {S,A,O,1,Z0}

where  is defined as,

1) (q1 ,, z0 ) q 2 ,S)

For each production

97

DR W T CHEMBIAN
DR W T CHEMBIAN

2) (q2 ,, s) (q2 , OSI )


3) (q2 ,, s) (q2 , A)
4) (q2 ,, A) (q2 ,S)
5) (q2 ,, A) (q2 , IAO)
6) (q2 ,, A) (q2 ,)

For each terminal

7) (q2 , o, O) (q2 ,)


8) (q2 ,1,1) (q2 ,)
9) (q2 , o,1) (q2 ,)
10) (q2 ,1,0) (q2 ,)

n n
4) Design a PDA accepting L = {a b | n 1} by final state

Solution:

Transition Diagram:

Transition function 

1) (q0 , o, z0 )  (q0 , Oz 0 )
2) (q0 , o, o)  (q0 , oo)
3) (q0 ,1, o)  (q1,)
4) (q1,1, o) (q1,)
5) (q1,, z0 )  (q2 ,)

The PDA is defined as

M = ( Q, , , , q0 , z0 , F)

98

DR W T CHEMBIAN
DR W T CHEMBIAN

Q = {q0,q1,q2}

 {0,1)

 {0;1, z0}

F = {q2}

Let us consider the string w = 0011

(q 0 ,0011; z0 )  (q 0 ,011; oz0 )  (q1 ,1;0z 0 )  (q1 ,; z0 )  (q 2 ,)

Final state is reached so the string w = 0011 is accepted.

2. CONVERSION OF PDA TO CFL



Convert the given PDA to CFG. [Nov/Dec 2015]
Given PDA

M = ({q0,q1},{0,1},{x,z0}, , q0,q0,

 ) where  is given by

(q0 , o, z0 ) (q0 , xz 0 )

(q0 , o, x) (q0 , xx )

 (q0 ,1, x) (q1,)



 (q1,1, x) (q1,)

(q1,, x) (q1,)

(q1,, z0 ) (q1,)

Construct a CFG G, generating N(M)

Solution :

V {s,[q0 , x, q0 ],[q0 , x, q1 ],[q1, x, q0 ],[q1, x, q1 ][q0 , z0 , q0 ][q0 , z0 , q1 ][q1, z0 , q0 ][q1, z0 , q1 ]}

99




DR W T CHEMBIAN
DR W T CHEMBIAN

T = {0,1}

The productions for s are

S[q0 , z0 , q0 ] (from rule 1)

S[q0 , z0 , q1 ]

The Productions for each transition functions of M.

1) (q0 , o, z0 ) (q0 , x, z0 )

The Productions are

[q0 , z0 , q0 ]o [q0 , x, q 0 ][q0 , z0 , q0 ]

[q0 , z0 , q0 ]o [q0 , x, q 1 ][q1, z0 , q 0 ]

[q0 , z0 , q1 ]o [q0 , x, q 0 ][q0 , z0 , q1 ]

[q0 , z0 , q1 ]o [q0 , x, q 1 ][q1, z0 , q 1 ]

2) There is a move  (q0 , o, x)  {(q0 , xx )}

The productions are

[q0 , x, q0 ]o [q0 , x, q0 ][q0 , z0 , q 0 ]

[q0 , x, q0 ]o [q0 , x, q1 ][q1, x, q0 ]

[q0 , x, q1 ]o [q0 , x, q0 ][q0 , x, q1 ]

[q0 , x, q1 ]o [q0 , x, q1 ][q1, x, q1 ]

3)  (q0 ,1, x)  {(q1,)}

The production is

[q0 , x, q1 ]1

4)  (q1,1, x)  {(q1,)}

The production is
100

DR W T CHEMBIAN
DR W T CHEMBIAN

[q1, x, q1 ]1

5)  (q1,, x)  {(q1,)}

The production is

[q1, x, q1 ]

6)  (q0 ,1, x)  {(q1,)}

The production is

[q0 , x, q1 ]1

  
There are no production for the variable [q1, x, q0 ] and[q1, z0 , q0 ]

As all the productions for [q0 , x, q0 ] and [q0 , z0 , q0 ] have [q1, x, q0 ] or [q1, z0 , q0
]
 on the right, no string of terminals can be derived from [q0 , x, q0 ] or [q0 , z0 , q0 ]

these variables on either the right or left, we
Deleting all production involving one of
end up with the following productions.

S[q0 , z0 , q1 ]

[q0 , z0 , q1 ]o [q0 , x, q 1 ][q1, z0 , q 1 ]

[q0 , x, q1 ]o [q0 , x, q1 ][q1, x, q1 ]

[q0 , x, q1 ]1

[q1, z0 , q1 ]

[q1, x, q1 ]

[q1, x, q1 ]1

1) Give a grammer for the language N(M) where


M  ({q0 , q1},{0,1},{z0 , x}, , q0 , z0 , ) and  is given by

 (q0 ,1, z0 ) {(q0 , xz 0 )}



 (q0 ,1, x) {(q0 , xx )}

101

DR W T CHEMBIAN
DR W T CHEMBIAN

 (q0 ,0, x) {(q1, x)}



 (q0 ,, z0 ) {(q0 ,)}

 (q1,1, x) {(q1,)}

 (q1,0, z0 ) {(q0 , z0 )}

V {S1,[q0 , z0 , q0 ],[q0 , z0 , q1 ],[q1, z0 , q0 ],[q1, z0 , q1 ][q0 , x, q0 ][q0 , x, q1 ][q1, x, q0 ][q1, x, q1 ]}

T = {0,1}

P = set of productions

S[q0 , z0 , q0 ]

S[q0 , z0 , q1 ]

1) (q0 ,1, z0 ) {(q0 , xz 0 )}

[q0 , z0 , q0 ]1 [q0 , x, q 0 ][q0 , z0 , q0 ]

[q0 , z0 , q0 ]1 [q0 , x, q 1 ][q1, z0 , q 0 ]

[q0 , z0 , q1 ]1 [q0 , x, q 0 ][q0 , z0 , q1 ]

[q0 , z0 , q1 ]1 [q0 , x, q 1 ][q1, z0 , q 1 ]

2)  (q0 ,1, x)  {(q0 , xx )}

[q0 , x, q0 ]1 [q0 , x, q0 ][q0 , x, q0 ]

[q0 , x, q0 ]1 [q0 , x, q1 ][q1, x, q0 ]

[q0 , x, q1 ]1 [q0 , x, q0 ][q0 , x, q1 ]

[q0 , x, q1 ]1 [q0 , x, q1 ][q1, x, q1 ]

3)  (q0 ,0, x)  (q1, x)

[q0 , x, q0 ]0 [q1, x, q0 ]

102

DR W T CHEMBIAN
DR W T CHEMBIAN

[q0 , x, q1 ]0 [q1, x, q1 ]

4)  (q0 ,, z0 )  {(q0 ,)}

[q0 , z0 , q0 ]

5)  (q1,1, x)  {(q1,)}

[q1, x, q1 ]1

6)  (q1,0, z0 )  {(q0 , z0 )}

[q1, z0 , q0 ]0 [q0 , z0 , q0 ]

[q1, z0 , q1 ]0 [q0 , z0 , q1 ]

  
There are no production for the variable [q1, x, q0 ]

As all the productions for [q0 , x, q0 ] have
[q1, x, q0 ] on the right, no string of
 terminals can be derived from [q0 , x, q0 ]
Deleting all production involving one of these variables on either the right or left, we
 end up with the following productions.

 [q0 , z0 , q1 ]1 [q0 , x, q 1 ][q1, z0 , q 1 ]

[q0 , zo , q0 ]1 [q0 , x, q1 ][q1, zo , q0 ]



[q0 , x, q1 ]1 [q0 , x, q1 ][q1, x, q1 ]

 [q0 , x, q1 ]0 [q1, x, q1 ]

 [q1, z0 , q0 ]

 [q1, x, q1 ]1

[q1, zo , q0 ]0 [q0 , zo , q0 ]



 [q1, zo , q1 ]0 [q0 , zo , q1 ]





 103



DR W T CHEMBIAN
DR W T CHEMBIAN

UNIT-IV – TURING MACHINES

Definitions of Turing machines – Models – Computable languages and functions –Techniques


for Turing machine construction – Multi head and Multi tape Turing Machines - The Halting
problem – Partial Solvability – Problems about Turing machine- Chomskian hierarchy of
languages.

PART - A
1.What is Turing machine?

The basic modes of a TM has


a) A finite control
b) An infinite tape
c) A tape head

*An input tape is divided into cells. The tape is infinite to the right.

*each cell of the tape holds exactly one symbol.

*The tape head moves in both direction.

a1 a2 ….. a1 … an B B ….

Finite
Control

2. What is the formal definition of turing machine?


Formally, a Turing Machine is donoted M
= ( Q, E, , , qo , B, F )

Where

Q  finite set of states


  finite set of tape symbols B
  a symbol of , is the blank
E  a subset of  not including is the set of input symbols.
104

DR W T CHEMBIAN
DR W T CHEMBIAN

 is the transition fuction mapping


Q  Q  {L, R}
qo a state in a Q is the initial state.
F  is the set of final states.
FQ

3.Define instantaneous description of turing machine?

ID of Turing machines is denoted by α 1 q α 2.

Where q-> is the current state of M

α 1 , α 2-> is the string in

4. Define moves of a Turing machine.



A move of M is defined as follows Let X 1 X 2 …. X 1-1 q X1 X 1+1 ….Xn be an

 ID suppose  (q1 Xi) = ( P, , L )

When we can write

X 1 X2 ……X 1-1 q X i….X n X 1 X 2 ….X 1-1  p X 1+1 …Xn

Suppose  (q1 Xi) = (P, Y, R) then

X 1 X2 ……X 1-1 q X i….X n X 1 X 2 ….X 1-1  p X 1+1 …Xn

5.Define the language acc pt d by Turing Machine?

The Language accepted by TM:


The language accepted by M, denoted L (M) is the set of words in xthat cause Mto
enter a final state.
 
Formally the language accepted by TM.
M = ( Q, E, , , qo, B, F ) is
L (M) = {w | w in  x and q o w 1 P 2 for some P in F and 1 and 2
  
The TM halts, (e) has no next move, whenever the input is accepted.
 
The TM will never halt for the words which are not accepted.

6.Define total recursive function and partial recursive function.

105

DR W T CHEMBIAN
DR W T CHEMBIAN

Total recursive function:

If f(i1,i2,….ik) is defined for all i1, i2..in then we say f is a total recursive
function.

Partial recursive function:

A function f(i1,….ik) computed by a TM is called a partial recursive function.

7.What are the techniques for Turing machine construction?

Techniques for TM construction:

1. Storage in the finite control


2. Multiple tracks
3. Checking off symbols
4. Shifting over
5. Subrartines

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.

Each types is infinite in both directions.

On a single move depending on the state and the scanned by each tape head, the turine
machine.

1. Changes state
2. Print a new symbol scanned by each tape head
3. Move each of its tape head independently one cell to the left or right.

9.What is regular grammar?

A right or left linear grammar is called as regular grammar. Regular grammar


derives regular languages. Regular languages are accepted by finite automata.

*If all productions of a CFG are of the form

A->wB
A->w
Then the grammar is right linear.
*If all productions of a CFG are of the form
106

DR W T CHEMBIAN
DR W T CHEMBIAN

A->BW
A->W
Then the grammar is left linear.

10.What is unrestricted grammar or phrase structure grammar or Type 0


grammar?

A grammar is used with 4-tuple notation,

G=(V,T,P,S)

The productions are of the form

α -> β

α, β-> are string of grammar symbols with α=ϵ

*These grammar derives recursive and recursing num rable languages these languages
are accepted by Turing Machines.

11. What is context sensitive language?

*If the restriction on the production

α->β of a phrase structure grammar that β be atleast as long as α.

*These grammars are type 1 grammar.

*These grammar derives context sensitive language context sensitive language are
accepted by Linear Bound d Automata.

12.Define Linear Bounded Automata.

A linear bounded Automata is a non-deterministic Turing Machine satisfying the


following two conditions.
1.Its input alphabet includes two special symbols and , the left and right end marker
respectively.
2.The LBA has no moves from left from or right from nor may it print another symbol
over .
13.What is Halting Problem?

107

DR W T CHEMBIAN
DR W T CHEMBIAN

For a given Turing Machine M and a given string w, instead of asking whether
Turing Machine accepts w, its asks whether TM halts on input w. This problem is
referred as halting problem.

14.What is Reduction?

If P1 and P2 are decision problems

We say P1 is reducible to P2 ie. Written as P1<=P2.

Given an instance I of P1 to find an instance F(I) od P2 so that for every I the answer for
the turn instances T and F(T) are the same.

15.What are the features of Turing Machine?

  It has external memory


  It has unlimited memory capacity
  Tape head can be read the input at both sides
 It produces certain output based on its input.

16.What are the applications of Turing Mach nes?

Turing machines is used as a model of general purpose computer.

Turing machine is used for solving computational , recursive and non recursive
enumerable problems.

 Turing machine can be used for representing sub-routines.























108




DR W T CHEMBIAN
DR W T CHEMBIAN

PART-B
1. Discuss the basic definitions of Turing Machine.

The Turing Machine


a1 a2 ….. a1 … an B B ….

  
The basic model of a TM has Finite
1. a finite control Control
2. an infinite tape
3. a tape head

  tape is divided into cells. The tape has a left most cell but it is infinite to the
An input
right.
  
Each cell of the tape may hold exactly one of a finite numbers of tape symbols.

  which is string of symbols chosen from a
Initially the n left most cells for n ≥ o hold the input
subset of tape symbols called the nput symbols.
The remaining infinity of cells each hold the blank, which is a special tape symbol that is
not an input symbol.
In one move of the Turing Machine, depending upon the symbol scanned by the tape
head and the state of the finite control
1. Changes state
2. Prints a symbol on the t pe cell scanned replacing what was written there
3. Moves its tape h ad l ft or right one cell

Formal Definition:

Formally, a Turing Machine is donoted M
= ( Q, E, , , qo , B, F )

Where

Q  finite set of states


  finite set of tape symbols B
  a symbol of , is the blank
E  a subset of  not including is the set of input symbols.
 is the transition fuction mapping
109

DR W T CHEMBIAN
DR W T CHEMBIAN

Q  Q  {L, R}


qo a state in a Q is the initial state.
F  is the set of final states.
FQ

Instantaneous Description : (ID)


 
ID of Turing Machine is denoted by

1 q 2

Where

q  is the current state of M

1 , 2  is the string in *

Moves of the Turing Machine

A move of M is defined as follows Let X 1 X 2 …. X 1-1 q X1 X 1+1 ….Xn be an


ID suppose  (q1 Xi) = ( P, , L )

 When we can write

 X 1 X2 ……X 1-1 q X i….X n X 1 X 2 ….X 1-1  p X 1+1 …Xn

 Suppose  (q1 Xi) = (P, Y, R) then

 X 1 X2 ……X 1-1 q X i….X n X 1 X 2 ….X 1-1  p X 1+1 …Xn

 The Language accepted by TM:


The language accepted by M, denoted L (M) is the set of words in xthat cause Mto
enter a final state.
 
Formally the language accepted by TM.
 M = ( Q, E, , , qo, B, F ) is
L (M) = {w | w in  x and q o w 1 P 2 for some P in F and 1 and 2
  
The TM halts, (e) has no next move, whenever the input is accepted.
 
 The TM will never halt for the words which are not accepted.

 2.Construct a Turing machine to perform addition

 110



DR W T CHEMBIAN
DR W T CHEMBIAN

Solution

Suppose the input is Om |On

Finally the TM halts on tape containing Om+n

Suppose w = 00010

0 0 0 1 0

q0

0 0 0 0 B

q1 q 1

0 0 0 B B

q3

0 1 B

q0 (qo, O, R) (q1, O, R)
q1 (q1, O, R) (q2, B, L)

q2 (q3, B, R) - (q3, B, R)

q3 - - -

M = ( Q, , , , q0 , B,{q3}

Q = {q0,q1,q2,q3}

111

DR W T CHEMBIAN
DR W T CHEMBIAN

 {0,1)

 {0,1, B}

F = {q3}

Simulating for w = 00010

q0 00010  0q1 0010  00q0 010 

000q010 0000q1000000q1B

0000q2BB0000Bq3

Hence Turing machine performs addition

2.PROGRAMMING TECHNIQUES FOR TURING MACHINE



Explain the programming techniques for Turing Machine Construction. 
[Nov/Dec 2015]
To describe the complicated TM construct ons, some techniques are used,
The techniques are
1. Storage in the finite control
2. Multiple tracks
3. Checking of symbols
4. Shifting over
5. Subroutines

1. Storage in the finite control


  The finite control can be used to hold a finite amount of information.
  The state is written as pair of elements
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

DR W T CHEMBIAN
DR W T CHEMBIAN

Ie., Q consists of the pairs


[q0, 0], [q0, 1], [q0, B]
[q0, 0], [q1, 1], [q1, B]
The set F= {[q1,B]}

 The first component of the state controls the action, while the second
component „remembers‟ a symbol.
1) =([q1,0],0,R),
2) =([q1,1],1,R)


Initially q0 is the control component of the state and M moves right. The
first component of statebecomes q1 and the first symbol seen is stored in
the second component.
1) =([q1,0],1,R),
2) =([q1,1],0,R)

 a O stored and sees a 1, or vice versa, th n M continues to move to the
If M has
right.

1) =([q1,B],0,L),
2) =([q1,B],0,L)

M enters the final state [q1,B] if it reaches a blank symbol without having first
encountered a second copy of the left most symbol.

  
If M reaches a blank in state (q1, 0) or (q1, 1) it accepts.
  
For state (9,10) and symbol 0 or for state (q1 , 1) and symbol 1,  is not defined.
 
Thus if M encounters the tape symbol stored in its state. M halts without accepting.

2. Multiple tracks:
  
The tape of the Turing machine is divided into K tracks for any finite K.
 
The symbols on the tape are considered k tuples one component for each track
C 1 0 1 1 1 1 $ B ...

B B B B 1 0 1 B B

113

DR W T CHEMBIAN
DR W T CHEMBIAN

B 1 0 0 1 0 1 B B

Finite control

Example:


 greatest than 2, written on the first track and
The tape of a TM takes a binary input
determined whether it is a prime.

Solution:
  
The input is surrounded by C and $ on the first tracks.

Thus the allowable input symbols are
[ C, B, B]  is identified with C [O,
B, B]  is identified withO [1, B,
 B]  is identified with 1
[$, B, B]  is identified with $

[B, B, B]  is identified with B
To test it its input is prime, the Turing Machine
 Write the number two in binary on the second
track.  Copies the first tracks on the third
 The second track is subtracted as many times as possible from the third track, and
leaving the remainders.

 If the remainder is z ro, the number on the first track is not a prime.

3. Checking off symbols.


Checking off symbols is useful for visualizing
how a Turing Machine recognizes
languages defined by repeated strings such as
{ w w | in *}
{w c y | and y in *, w y}
{w wR | w in *}
  
It is also useful when lengths of substrings must be compared, such as in the languages

{ai bi | ≥ 1}

{ aibjck 1 i  j, or j  k}
114

DR W T CHEMBIAN
DR W T CHEMBIAN

 
We introduce an extra track on the tape that holds a blank or
 
The appears when the symbol below it has been considered by the Turing machine in one
of its comparisons.

Example:

Consider a Turing Machine M (Q, , , q0, B, F)

which recognizes the langues L = {w c w | w in (a + b)

Solution:

Let Q = {[q, d] | q = q1, q2 …. qq

d = a, b or B}
  
The second component of the state is used sto e an nput symbol
  { [B, d] | d = a, b or c 
 
 The input symbol [B, d] is identified with d

 = [x d] | x = B or and d = 0 

q0 = [q1, B] and F = {[q9, B[}

 is defined as

1)  ( [q1, B], [B, d] = ( [q2, d], [ , d], R)


2)  ( [q2, d], [B, e]) = ( [q2, d], [B, e], R)
3)  ( [q2, d], [B, c]) = ( [q3, d], [B, c], R)
4)  ( [q, d], [ , e]) = ( [q , d], [ , e], R)
3 3

5)  ( [q3, d], [B, d]) = ( [q4, B], [ , d], L)


6)  ( [q, B], [ , d]) = ( [q , B], [ , d], L)
4 4

7)  ( [q4, B], [B, c]) = ( [q5, B], [B, c], L)


8)  ( [q4, B], [B, c]) = ( [q5, B], [B, c], L)
9)  ( [q6, B], [B, d]) = ( [q6, B], [B, d], L)
10)  ( [q, B], [ , d]) = ( [q , B], [ , d], R)
6 1
11)  ( [q, B], [ , d]) = ( [q , B], [ , d], R)
5 7

12)  ( [q7, B], [B, c]) = ( [q8, B], [B, c], R)


13)  ( [q8, B], [ , d]) = ( [q , 8B], [ , d], R)
14)  ( [q8, B], [B, B]) = ( [q4, B], [ , B], L)

115

DR W T CHEMBIAN
DR W T CHEMBIAN

Shifting Over:

A Turing machine can make space on its tape by shifting all non – blank symbols a
 finite number of cells to the right.

head moves to the right, repeatedly store the symbols read in the finite
The tape
control
  
The symbols are replaced by the symbols read from cells to the left.
 
The TM can return to the vacated cells and print symbols of its choosing.

Example :

Construct a Turing machine M = {Q, , , , qo, B, F} which shift non blank


symbols two cells to the right.

Solution :

Let the tape of M does not contain blanks b tw n non – blanks.
  
Let Q contains the states of the form [q,Aa,A2] for q = q1 of q2 A1,A2 in 
 
 Let x be a special symbol not used buy M except in shifting process
M starts the shifting process in state [q1,B,B]
 are defined as
1) ([ q1, B, B], A1([q1, B, A1], x, R) for A1 in {B, x}
2) ([ q1, B, A1], A2 ([q1, A1, A2 ], x, R) for A1 and A2 in {B, x}
3) ([ q1, B, A1 ], A3  ([q1, A1, A3 ], A1, R) for A1, A2 , A3 in {B, x}
4) ([ q1, A1, A2 ], B ([q1, A2 , B], A1, R) for A1, and A2 in {B, x}
5) ([ q1, A1, B], B  ([q2 , B, B], A1, L)
6) ([ q1, A1, A2 ], B ([q1, A2 , B], A1, R) for A1, and A2 in {B, x}

Subroutines :


The Turing machine can simulate any type of subroutine, include recursive procedure
and any of the parameter passing mechanisms.
  
We describe only the use of parameter less, non-recursive sub routines.
  
The general idea is
  
To write part of a TM program to serve as a subroutine.

It will have a designated initial state and return state which
has no move and
which will be used to effect a return to the calling routine.

116

DR W T CHEMBIAN
DR W T CHEMBIAN


 
To design a Tm that calls the subroutine a new set for states for the
subroutines is mad, and a move from the return state is specified.

subroutine and the
The call is effected by entering the initial state for the
return is effected by the move from the return state.

Example :

The design of a TM to implement the total recursive function

Solution :
 
M starts with Om | On on its tape and ends with O mn surrounded by blanks.

 The general idea is to place a 1 after O m | O n 
and then copy the block of n O‟s onto the right
end m time each time erasing one of the O‟s.
 
The  is defined as for copy sub routine as

0 1 2 B

q1 (q2, 2, R) (q4, 1, L)
q2 (q2, O, R) (q2, 1, R) (q3, O, L)

q3 (q3, O, L) (q3, 1, L) (q1, 2, R)

q4 (q5, 1, R) (q4, 1, L)


To complete the progr m formultiplication we add states to convert initial ID q 0
Om | On to B O m-1,q,On 1.
i.e

 (q0, O), = (q6, B,R)



 (q6, O), = (q6, O,R)

 (q6, 1), = (q1, 1,R)
 
The  is defined Multiplication as

0 1 2 B

117

DR W T CHEMBIAN
DR W T CHEMBIAN

q5 (q7, O, L)
q7 (q8, 1, L)

q8 (q9, O, L) (q10, B,
R)

q9 (q9, O, L) (q10, B,
R)

q10 (q11, B, R)

q11 (q11, B, R) (q12, B, R)

Simulating for w = 00100

q0 00100 Bq60100B0q6100B01q100

B012q20 B012q2 B  B012q300 ….

3..MULTIHEAD AND MULTITAPE TURING MACHINE

Discuss about the Multihead and Multi Tape Turing Machine. [NOV/DEC
2013]

Multihead and Multi tape turning machine :

  
A multitape turning machine consists of a finite control with K tape heads and k taps.
  
Each tape is infinite in both directions.

On a single move depending on the stateof the finite control and the symbol scanned by
 each of the tape heads, the machine can
1) Change state
2) Print a new symbol scanned by each tape heads
3) Move each of tape heads independent one cell to the left or right or keep it
state.
 
Initially the input appears on the blank.
118

DR W T CHEMBIAN
DR W T CHEMBIAN

… …

… …

… …

Finite Control
Theorem :

It a language L is accepted by a multitape turning machine. It is accepted by a


single tape turning machine.

Proof :
Let L be accepted by M, a TM with k tapes
We can construct M2 a single tape TM with 2k tracks
One track records the contents of the corresponding tape of M.
The other tape is Blank, except for a Marker that holds the symbol scanned by the
 corresponding head of M.

 A three tape turning machine




 Finite Control

 … …

 … …




 119



DR W T CHEMBIAN
DR W T CHEMBIAN

… …


The finite control of M2 stores the state of M1
along with a count of number of
head markers to the right of M2‟s tape head.

Head 1 x

Tape 1 A1 A2 … .. Am
Head 2 x

Tape 2 B1 B2 … … Bm
Head 3 x

Tape 3 C1 C2 … … Cm

Simulation of three tapes by one


Each move of M1 is simulated by a sweep from left to right and then from right to
left by the tape head of M2
Initally M2‟s head is at the left most cell containing a head marker.
  
To simulate a move of M1
 M2 sweeps right visiting each of the cells with head markers and recording the
symbol scanned by each head of M1 
 When M2 crosses a head marker it must update the count of head markers to its
 right
 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 M 1
  
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

DR W T CHEMBIAN
DR W T CHEMBIAN

4. CHOMSKIAN HIERARCHY OF LANGUAGES


Describe the chomskian hierarchy of Languages. [May/June 2016]
The Chomskian hierarcy of languages :
  
The four classes of languages
1. Regular sets
2. Context free languages
3. Context sensitive languages
4. Recursive and recursively enumerable languages
  
The four classes of languages are grammatically charecterised.
 
These four classes of languages are called as chomshy hierarchy.

1. Regular Grammar :
 
It all productions of a CFG are of the form
A  wB where A, B are var ables
A w where w are string of ter min als
then we say the grammar is light li eave.
If all productions are of the form
A  Bw
A B
then we say the gramm r is left lineave.
  
A right or left linear grammar is called as regular grammar.
 
 Regular grammar derives regular languages.
 
Regular languages are accepted by finite Automata.

2. Unrestricted Grammar :

 with 4 tube notation.
A grammar is used
G = (V, T, P, S)
 
The productions are of the form



where, ,are arbitray string of grammar symbols with 

121

DR W T CHEMBIAN
DR W T CHEMBIAN

  
These grammar also known as type 0 grammar or phase structure grammar.
 
These are accepted by turning machines.

3. Central sensitive languages :


 Suppose we place the restriction on the production  of a phase structure
grammer that  be atleast as long as  .
  
The resulting grammar is context sensitive grammar.
  
These grammars are called as type 1 grammers
  
These grammar derives context sensitive language
 
Context sensitive languages are accepted by linear bounded Automata.

Linear Bounded Automata (LBA)


 A linear bounded automata is a non-determinist c turning machine satisfying the
following two conditions.
1. Its input alphabet includes two special symbols  and $, the left and right end
marker respectively.
2. The LBA has no moves left from or right from $, nor may it print another
symbol over or $.
The LBA is denoted as
M = (Q, ,, ,q0,,$,F)
Where Q, , , , q0 , and F are as for a Non-deterministic
TM , $,  are symbols in  the left and right end markers.
 
The language accepted by M is
L(M) {w | w is in ({,$) *and q 0  w$ qfor some q in F

4. Context free Grammar :



  as 4 tuples
The CFG is defined
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

DR W T CHEMBIAN
DR W T CHEMBIAN

5.A.HALTING PROBLEM
 
Explain Halting Problem. Is it solvable or unsolvable problem? Discuss.
[May/June 2016]
The Halting Problem :
  
If the problem of whether a TM M accept the string w is unsolvable.
  
It cannot be solved for recursively enumerable languages.

  not if it loops forever. Accepts :
This approach will procedure an answer only if T halts
Given a TM, M and a string w, Does, TM, M accepts w?
 
An instance of the problem accepts consists of a pair <M, w> with the universal
turning machine.
Lu = {<m‟, w‟> | w  L (M) }

The haltingproblem is related to the membership problem for recursively enumerable
languages.
Halting Problem :
 
For a given turning machine M and a giv n string w, instead of asuling whether
turning machine accepts w. it asks whether turning machine halts on input w. This
problem is referred as halting problem.
Halts : Given a turning machine M, and a string w does M halts on input w?
We can consider the corresponding language L(M)
{ M , W1 | M halts
1
on input w }
Reducing One Decision Problem to another :
If P1 and P2 are decision problems. P1 is reducible P2 ie) written as
P1P2
If there is an algorithmic procedure that allows us
“Given an arbitrary instance I of P1 to find an instance F (I) of P2. So that for every I the
answer for the two instances I and F (I) are the same.
Reducing One language to another :
  and 
If L1 and L2 are languages over alphabet respectively, we say that L1
  1 2

reducible to L2 ie) written as


 
This type of reducibility is called as many one reduciability
Theorem :
The halting problem is undecidable.
Proof :
 
We show that Accept can be reduced to „Halts‟

123

DR W T CHEMBIAN
DR W T CHEMBIAN


Forboth problems, an instance is a pair consisting of turning machine, M and a string
w.

Given a pari <m, w> an instance
 of Accepts we must construct another pair <m1,
 w1> an instance of Halts.

This meansthat M1 and w1 must be constructed so that M1 halts on input w1 iff M
accepts w.
i.e) If M accepts w, m1 must halt on w1 and if M either rejects w or runs forever on w, m,
must not halt on w.
  
Let us choose w = w1
 
 To construct M1, the moves of M are simulated by changi g the move of the form

  (p, a) (hr , b, D) to


 (p, a) (p, a,s)


i.e) If M ever arrives
in state p with a on the curre t 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.

Then q0 is moved with the tape head to ext cell ie.) second cell
M1 has the same moves as M, as well the additional move
(q, #) (q, #,s)
for all possible.
States q.
 If M ever moves its tape head off, M, will enter an infinite loop, with its tape head
on the left most cell. Ie) It ever halts.
Thus the hulting problem is undecidable.

5.B COMPUTABLE LANGUAGES AND FUNCTIONS



Explain Turing Machine as a computer of Integer functions with an example. 
[Nov/Dec 2013]
COMPUTABLE LANGUAGES AND FUNCTIONS

A Languagethat is accepted by a Turing Machine is said to be recursively
 enumerable

The term enumerable derives fromthe fact that these languages whose strings can be
enumerated by a turing machine.
  
The class of recursively enumerable languages very broad and it includes the
CFL‟s The class of recursively enumerable languages includes some languages for

which we cannot determine membership. ie) It is not accepted by Turing machine.
 
If L(M) is such a language, then any TM, recognizing L(M) must fail to half on

124

DR W T CHEMBIAN
DR W T CHEMBIAN

some input not in L(M).


  
M halts on input w.

The subclass of the recursively enumerable called the 
recursive sts which ar those
language accepted by any TM that halts on all inputs.
THE TURING MACHINE AS A COMPUTER OF INTEGER FUNCTION

 
In addition to language acceptor, the TM may be viewed as a computer of function
from integers to integers.
 1 0 
The integer is represented by the string Oi

If a function has K arguments i1,i2,... ik, then these integers are initially placed on the
 O | Oi 2 | Oi k
tape separated by 1‟s as i1

If the TM halts with a tape consisting of O m, then we say that f(i 1
,i2,... ik,) = m, where f
 is the function of k arguments. computed by this Turing machine.


If Turing machine M computes function of k argume ts then f need not have a value
for all different k tuples.

 ik,) is defined for all i1,i2,... ik, th n we say f is a total recursive
If f (i1,i2,...
function.
  
A function f (i1,i2,... ik,) computed by a TM is called partial recursive function.
PART-C
 1. DESIGN OF TURING MACHINES
 Design a Turing Machine to accept the Palindromes in an alphabet set .Trace
the strings “0101” and “1001”. [MAY/JUNE 2016]
Design a Turing Machine to perform addition and proper subtraction.

1. Construct a Turing Machine for L = { On 1 n | n  1}

Solution:
 n n
  Machine M contains O 1 followed by an infinity of
Initially the Turing
Blanks. For eg.

xy
0 0 1 1 B …

q0 q1 q1 q2

125

DR W T CHEMBIAN
DR W T CHEMBIAN

M repeatedly replaces the leftmost O by and moves right to the leftmost L replacing
it by Y. moves left to right to the left most X then moves one cell right to the leftmost
O and repeats the cycle.

0 1 X Y B

q0 (q1, X, R) (q3, Y, R -
q1 (q1, O, R) (q2, Y, L) (q1, Y, R) -

q2 (q2, O, L) - (q0, X, R) (q2, Y, L) -

q3 q3, Y, R) (q4, B R)

q4 - - - - -

M = ( { q0, q1, q2, q3, q4 }, { 0 , 1}, {0, 1 , X, Y, B}, , q0, B,

{q4} To verify the string w = 0011

q0 0011 x q1 011 x o q1 11 

xq2 0y1  q2 x0yl  xq0 0y1 

xxq1 y1  xxyq1 l  xxq2 yy 

xq2 xyy  xxq0 yy  xxyq3 y 

xxyyq3 xxyybq4
 
 The Turing Machine accepts L = { On 1n | n  1}

2) Construct a Turing Machine for L = {wwR | w{0,1}


Solution

0 1 X Y B

q0 (q1, X, R) (q3, Y, R -

126

DR W T CHEMBIAN
DR W T CHEMBIAN

q1 (q1, O, R) (q2, Y, L) (q1, Y, R) -


q2 (q2, O, L) - (q0, X, R) (q2, Y, L) -

q3 q3, Y, R) (q4, B R)

q4 - - - - -

q5 (q6, Y, L) (q8, X, R) (q8, Y, R)

q6 (q6, O, L) (q6, 1, L) (q0, X, R) (q0, Y, R)

q7

q8

M = ( Q, , , , q 0 , B, F)

Q = {q0,q1,q2,q3,q4,q5,q6,q7,q8}

{0,1)

{0,1, x, y, B}

Let consider w = 0011

q0 0011 x q1110x 1 q110

x11q10 x110q1Bx11q20

x1q31x xq3l1xq3x11x

xq011x xyq41xxy1q4x

xyq51x xq6 yyx

2. Construct a Turing Machine to perform proper

subtraction Solution:

Proper subtraction M-n is defined as

M-n = M - n for Mn


127

DR W T CHEMBIAN
DR W T CHEMBIAN

O for M<n
 
The TM started with O m, On on its tape and halts on O m –n on its tape.

  its leading O by blank then searches light for a 1 followed by a O and
M repeatedly replaces
changes the O to 1.

  M moves left until it encounters a blank and then repeats the cycle. The repetition ends
Next
if
1. Searching right for a O, M encounters a blank. Then the n O‟s in O m | On have
all been changed to 1‟s and n + 1 of the m O‟s have been changed to B. M
replaces the n + 1 1‟s by a O and n B‟s leaving m-n O‟s on its tape.
2. Beginning the cycle M cannot find a O to change to a blank, because the first
m O‟s already have been changed. Then n  m, so m – n = O. m replaces all
remaining 1‟s and O‟s by B.

0 1 B

q0 (qo, B, R) (q5, B, R)
q1 (q1, O, R) (q2, 1, R)

q2 (q3, 1, L) (q2, 1, R) (q4, B, L)

q3 (q3, O, L) (q3, 1, L) (qo, B, R)

q4 (q4, O, L) (q4, B, L) (q6, O, R)

q5 (q5, B, R) (q5, B, R) (q6, B, R)

q6 -- -- --

M is defined as

M = {Q, , , , qo, B, F}

Q = {q0, q1, q2, q3, q4, q5, q6}

 = {O, 1}

 = {0, 1,
B} F = {q6}
128

DR W T CHEMBIAN
DR W T CHEMBIAN

A sample computation of M on input 0010 is

q0 0010 |-- Bq1 o10 |-- BOq110|-- BO1q2O

BOq311 |-- Bq3o11 |-- q3BO11 |-- Bq0 011

BBq111 |--BB1q21 |-- BB11q2

BB1q41B|-- BBq41BB |-- Bq4BBBB

BOq6BB..

UNIT-V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTION

Unsolvable Problems and Computable Functions – Pr mitive recursive functions –


Recursive and recursively enumerable languages – Universal Turing machine.
MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable
problems- Tractable and possibly intractable probl ms - P and NP completeness -
Polynomial time reductions.

PART-A

1. What is recursive enumerable and recursive


set? Recursive Enumerable set:
The languages accepted by Turing Machines are called as recursive enumerable
languages. Recursively numerable set includes regular languages and CFL‟s. some
languages in recursive enumerable set are not accepted by TM.
Recursive set:
The subset of recursive enumerable set is called as recursive set. All the languages in the
recursive set are accepted by TM.

2.What is decidable problem(or) decidability?

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.

3. What is undecidable problem(or) undecidability?


129

DR W T CHEMBIAN
DR W T CHEMBIAN

Undecidable problem:

*A problem whose language is recursively is said to be undecidable.

*A problem is undecidable if there is no algorithm that takes as input an instance


the problem and determines whether the answer to that instance is yes or no.

4. What are the closure properties of recursive & recursively enumerable


languages?

  The complement of recursive language is recursive.


  The union of two recursive language is recursive.
 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
is recursive.

5.What is universal turing machine?

Universal Turing machine:

If the problem is undecidable.

Does the turing machine M accept i put w? here both M and w are the parameters of
the problem. In formalizing a problem as a language. The input w is restricted to be
over {0,1} and M to have tape alphabet {0,1,B}. This Turing Machine is referred as
Universal Turing Machine.

6.What is diagonalization language?

In the table if the entry is

0-> means i is not in L(Mj)

1-> means i is in L(Ml)

We can construct a language Ld from the table by using the diagonal entries of the table
to determine membershin in L1.

7.What is Post correspondence Problem(PCP)?



An instanceof post correspondence problem CP(P) consist of two lists. A = w1,
 …, wk and

B = x1, …, xk
130

DR W T CHEMBIAN
DR W T CHEMBIAN

of strings over some alphabet 



This instance of PCP has a solution
 if there any sequence of integers i1,
 i2,…, im, with M 1 such that
 
wi1, wi2, …, wim = xi1 xi2 … xim
 
The sequence i1, … im is a solution to this PCP

Example :

Let {O,1} Let A and B be list of three strings.

List A List B

i wi xi

1 1 111

2 10111 10

3 10 0

Solution :
This PCP has a solution
M=4
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
101111110 = 101111110
The Solution

i1 = 2
i2 = 1

i3 = 1

i4 = 3

8.What is MPCP?

131

DR W T CHEMBIAN
DR W T CHEMBIAN

The modified version of PCP is the following given lists A and B of K strings each
from Σ* say

A = w1, w2,….wk

B = x1,x2,….xk

This problem has a solution if there exists sequence of integers

I1,i2,…ir such that

W1,wi1,…wir = x1 xi1xi2….xir

9. What is primitive recursive function?

The primitive recursive function is defined as follows

All initial functions are elements of PR

For any k>= 0 and m>= 0 if N k – N ang g1,g2,…gk : Nm -> N are elements of PR ,
then f(g1,g2,…gk) obtained from f and g1, g2,…. Gk by composition is an element
of PR.

For any n>=0 any function g:N n+1 -> N in PR and any function.

H: N n+2 -> N in PR.

No other functions are in the set PR.

No other functions are in the set PR.

10.What are the initial functions?

a) constant functions

b) The successor function

c) The projection function

11. What are P problems?

The problems that can be solved in a polynomial time by deterministic turing


machine. Eg) Krushals Algorithm b) Decidable Problem

12.What are NP problems?


132

DR W T CHEMBIAN
DR W T CHEMBIAN

The problems that can be solved in a non-deterministic polynomial time by non


deterministic turing machine.

Example: Undecidable problem

13. What is NP complete problems?

NP complete problems are NP problems.

The NP completeness problem in which ever language in NP reduces to P in


polynomial time.

PART-B
1. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES
 
State and prove the closure Properties of recursive and recursively
enumerable languages. [Nov/Dec 2012]
Closure properties of recursive and recursively enum rable languages :

Theorem 1 :

The complement of a recursive la guage is recursive.

Proof :

Let L be a recursive language and M a tuning machine that halts on all inputs
accepts L.

Construct M‟ from
 M so that if M enters final state on input w then m‟ halts
with accepting.

If M halts ithout accepting, M‟ enters final state.
 
 Since one of these two events occurs M‟ an algorithm.


Clearly L (M) is the
complement of L and thus the complement of L is a
recursive language.

133

DR W T CHEMBIAN
DR W T CHEMBIAN

Theorem 2 :
 
 The union of two recursive language is recursive.
The union of two recursively enumerable language is recursively enumerable.

Proof :

Let L1 and L2 be recursive language accepted by algorithms M1 and M2


Let L1 and L2 be recursive l nguage accepted by algorithms M1 and M 2
 
 We construct M1, which first simulates M1
 
 If M1 accepts then M accepts.
 
 If M1 rejects then M simulates M2 and accepts iff M2 accepts.
 
 Since both M1 and M2 are algorithms, M is generated to halt.
 
Clearly M accepts L1 U L2

134

DR W T CHEMBIAN
DR W T CHEMBIAN

 
 For recursively enumerable languages the above construction does not work.
Since M1 may not halt.
Instead M can simultaneously simulate M1 and M2 on separate tapes.
 If either accepts, then M accepts.


























 135



DR W T CHEMBIAN
DR W T CHEMBIAN

Theorem 2 :

If a language L and its complement L (and hence L ) is recursive.

Proof :
 
 Let M1 and M2 accept L and  respectively.
 
 Construct M to simulate simultaneously M and M2
 
 M accepts w if M1 accepts w and rejects if M2 accepts w
 
 Since w is in either L or  we know that exactly one of M1 or M2 will accept.
 
 Thus M will always say either „yes‟ or „no‟ but will never say both.
 
Since M is an algorithm that accepts L, it follows that L is recursive.

2.UNIVERSAL TURING MACHINE


 
Define Universal Turing machine and discuss about the Universal codes.

Universal turning Machine :


  
Diagnolization is used to show the problem is undecidable.
 
The problem is :

136

DR W T CHEMBIAN
DR W T CHEMBIAN

“Does the turning machine M accept 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}

Turning Machine codes :


  
We encode turning machines with restricted alphabets as strings over {0, 1}
  
Let
M = (Q,{0,1},{0,1, B}, , q1, B,{q2 }) be a turning and Blank as the additional tape
symbol. 
  
We assume that
Q = {q1, q2, …
 
qn} F = {q2}

 for more than one final state in any TM, since once it accepts it may
There is no need
as well halt.
  
The symbols 0, 1, B are used with the synonyms x1, x2, x3 respectively.
  
Directions L and R used with the syno yms D1 and D2.
The move (qi , x j) qk , xl , Dm ) is encods by the binary
string. Oi | Oj | Ok | Ol | Om
A binary code for turning machine M is
||| Code, || Code2 || … || Coder |||.
Where each codeiis of the form 0i10j10k10l10m
Each move of M is encoded by one of the code i‟s
  
The moves need not be in any particulars order
 
 The pair <M, w> is represented by the string of the form
|||Code1 ||Code2 || … Coder ||| followed by w 

Any such string ill be denoted <m, w>
Example :


Encode the following TM, M <M, 1011> in binary
2, q3}, {0, 1}, {0, 1, B},  , q1, B1, {q2})
M = ({q1, q
 Where  is
 (q1,1)  (q3 , 0, R)

 (q3, 0)  (q1,1, R)

 (q3,1)  (q2 , 0, R)

137

DR W T CHEMBIAN
DR W T CHEMBIAN

 (q3, B)  (q3,1, L)

Solution :

1) (q1,1)  (q3 , 0, R)
 (q1, x2 )  (q3, x1, D2 )
Code1 = 0 10 10 10 102
1 2 3 1

2)  (q3, 0)  (q1,1, R)
 (q3 , x1)  (q1, x2 , D2 )
Code2 = 03101101102102
3)  (q3,1)  (q2 , 0, R)
 (q3, x2 )  (q2 , x1, D2 )
Code3 = 03102102101102
4) (q3, B)  (q3,1, L)
 (q3, x3)  (q3, x2, D1)
Code4 = 03103103102101

Thus the string denoted by <M, 1011> is

|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011
111010010001010011000101010010011000100100101001100010001000100101
111011

3. NON RECURSIVELY ENUMERABLE LANGUAGE


 
Prove that Ld is not recursively enumerable

A non – recursively enumerable language :


Lemma :
Ld is not recursively enumerable.
 wi
Suppose we have a list of (0+1)* in canonical order where

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 (M j)

138

DR W T CHEMBIAN
DR W T CHEMBIAN

  
In the table, if the entry is
1 – means wi is not in L(Mj)
2 – means wi is in L (Mj)

We can construct a language 
Ld from the table by using the diagonal entires of the table to
 determine membership in Ld

To guarantee that no TM accepts L d. we insist that w1 is in L diff the the (i, i) entry is
 o, that is if Mi does not accept w1.

 Supposethat some TM Mj, accepted Ld then the following contradictions may
occur.
1) If wj is in Ld then (j, j) entry o, implying that wj is not in L(mj) and
contradiciting Ld = L(Mj)
2) If wj is not in Ld, then the (j, j) entry is 1, implying that wj is in L(Mj) which
contradicts Ld = L(Mj)
  
As wj is either in or not in Ld, we conclude that our assumption Ld = L(Mj) is false.
 
Thus no TM in the list accepts Ld. And no turning machine accepts Ld.
Lemma :
Ld is not recusively enumerable.
4. THE UNIVERSAL LANGUAGE

The Universal Language :


The universal language Lu is defined to be
{<M, w> | M accepts w}
We say Lu, universal, since the question of whether any particular string w in (0
+1)* is a accepted by ny particulars TM M is equivalent to the question of
whether. <M1, w> is Lu, where M1 is the TM with the tape alphabet {0, 1, B}
equivalent.
Theorem 1 :
Lu is recursively enumerable.
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
 1
M ‟s second tape.
 i
The third type holds the state of M with q i represented by O

139

DR W T CHEMBIAN
DR W T CHEMBIAN

  
The behavior of M1 is as follows
1) Check the format of tape 1, to see that it has a prefix of the form 111Code, 11
code2 || … || coder ||| and that there no two codes that begin with o i | oj | for the
same i and j for the same i and j Also check that if o i | oj | ok | ol | om is a code
then i  j  3,l  l  3 and
2) Initialise tape 2 contain w the portion of the input beyond the second block of
three 1‟s. Initialise tape 3 to hold a single O. representing q1. All three tape
heads are positioned on the left most symbols.
3) If tape e holds OO. the code for the final state, halt and accept.
4) Let xj be the symbol currently scanned by tape head2 a d let Oi be the current
content of tape 3.
Scan tape 1 from the left end to the second 111 looking for a substring beginning 110 i |
Oj11. If no such string is found, halt and reject. M has o next move and has not accepted.

If such a code is found, let it be oi | oj | ok | ol | om Th n put Ok on tape 3 print x2 on the


tape cell scanned by tape head 2 and move that h ad in Direction D m.
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>.
If m halts on w without accepting, M 1 does the same on < m1, w >.
 Thus lu is recursively enumerable.
 Theorem 2
 Lu is not recursive
Proof :
  
Suppose A is an algorithm, recognizing lu.
  
Then we can recognize Ld as follows.
  
Given string w in (o + 1)*, determine for I w = wi
 
Integer I in binary is the code for some TM Mi Feed < Mi, wi> to algorithm A

 accept iff Mi accepts wi














 140



DR W T CHEMBIAN
DR W T CHEMBIAN



Thus we have an algorithm for Ld. since no such algorithm exists, we know our
assumption, that algorithm A for Lu exists is false.
 
Hence Lu is recursively enumerable, but not r cursive.

5.PRIMITIVE RECURSIVE FUNCTION


Discuss about primitive recursive function.

Primitive Recursive Functions :


  
The primitive recursive function is defined as follows.
1. All initial functions are elements of PR
N N
2. For any K 0 and M 0 if Nk – N and g 1, g2, … gk; m are elements
of PR, then
f (g1, g2, … gk) obtained from f and g1 of g2, … gk, by composition is an element PR
n0 g : Nn1  N
3. For any any function in PR, and any function
h : Nn2  N in PR
f : Nn1  N
the function 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

DR W T CHEMBIAN
DR W T CHEMBIAN

K0 a 0
For each and each , the constant function
Ca k  Nk  N for every X E Nk
In the case K = 0 we may identify the function Cak with the number a
2. The successor function :
NN
is defined by the formula s (x) = x + 1
3. Project Functions
K 1 1 i  k
For much and each I with
the projection function
P k : Nk N
1 is defined by the formula
Pi (x1, x 2 ,..., xi ,... x k )  xi
k

Composition :
 1  i  k,
Suppose f is a partial function from Nk to N and for each I with giis a
m
partial function from N to N. The partial function obtained from f and g 1, g2, …,

gk by composition is the partial function h from Nm to N defined by the formula
h(x) = (f (g1 (x), g2 (x), …. gk (x)) (XENm)
The Primate recursion operation :
n0
Suppose and g and h are functions of n and n + 2 variables. respectively The
function obtained from g and h by the operation of primitive recursion is the
function.
f : Nn1  N
defined by the formula
f (x, 0) = g (x)
f (x, k+1) = h (x, k, f (x1k))

Addition and Multiplication :



  Add and Mult from N x N to N defined by the formulas
The functions
Add (x, y) = x + y
 
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 P 11
142

DR W T CHEMBIAN
DR W T CHEMBIAN

  
h (x, k, Add (x, k) should be S (Add (x, k))
 
This means h (x1, x2, x3) should be s (x3) or S (P33 (x1, x2, x3))
 
Therefore Add can be obtained as
f0 = p11 (an initial function)
f1 = S (an initial function)
f2 = p33 (an initial function)
f3 = S(P33) (Obtained from f1 and f2 by compostion)
f4 = Add (obtained from f0 and f3 by primitive recursion)

  Mult
To Obtain
Mult (x, 0) = 0
 
Mult (x, k+1) = x * (k + 1)
= Add (x * k, x)
= Add (x, Mult (x, k))
5.A.TRACTABLE AND INTRACTABLE PROBLEM

Explain about tractable and intractable problem with suitable
examples.(NOV/DEC2016,Apr/May 2017)

Tractable problem
Tracatable problem is a problem which can recognize with in reasonable time
and space constraints and can be solved in polynomial time. Those problems for
which no polynomial time algorithm are known requires exponential runtime.
Intractable Problem:
Intractable problems a e techniques for showing problems not to be solvable in
polynomial time.

Tractable and possibly Intractable problems:


Some of the complexity classes containing the languages recognizable in
polynomial time and polynomial space are as follows,
Class P= Time(cnk )
c0,k 0

PSpace= Space(cnk )
c0,k 0

Class NP= NTime(cnk )

c0,k 0

143

DR W T CHEMBIAN
DR W T CHEMBIAN

NPSpace= NSpace(cnk )

c0,k 0

 The sets P and SPace include any language that can be recognized by aTuring
machine with time complexity or space complexity bounded by some
 polynomial
 Generally allowing non-determinstism will allow improvements in the time
 complexity that is required to solve many problems.
 There are many languages or decision problems in NP for which no determinstic
 polynomial time algorithm are known.
  There are no languages in NP that are known not to be in P.The problem P is the
subset of NP and the following holds
P NP PSpace NPSpace

NP Problem as CNFG satisfiablity probl m.

CNF Satisfiablity Problem

The instance of CNF Satisfiablity problem is logical expression which contains


variables xi and the logical connectives as ,, (AND,OR,NOT respectively)
The expression of conjuctiv normal form is givem as follow:
C1  C2  C3 ...... Cn
Where Ci=subexpressions
Each Ci is the disjunction of the literal expression for example,
(x1  x2  x4)  ( x1  x3  x4 ) is the CNF expression with two conjucts.

Primitivity Problem:
This is one of the common decision problem stated as,
"Given 'n' as psitive integer, Is 'n' is aprime numbers?"
 For the above problem, the solution is polynomial when unary notation is used
and the solution is exponential when binary digits that is needed to encode 'n' is
"log n".
For this problem,actually test all divisors upto √n and if it is tested in constant time, then
the required time is proportional to √n, which is not bounded by any polynomial time of 'log n'.

144

DR W T CHEMBIAN
DR W T CHEMBIAN

5.B.POLYNOMIAL TIME REDUCTION



  with suitable examples.
Explain about Polynomial Time reduction
Definition-Polynomial Time reduction

A reduction from P1 to P2 is polynomial time if it takes time that is some
polynomial in the length of the P1 instance. The P2 instance will be of length that is
polynomial in the length of P1 instance. A problem P cannot be solved in polynomial
time can be proved by the reduction of a problemP1 which is known not to be in P1 to
P2.
Proof: To prove, if P2 is in P then P1 is also in P . When P1 instance length is M, output
is 2m which is fed to the hypothetical polynomial time algorithm for P2. If the decision
algorithm run in O(nK) time , then 0 n an input of length 2 m, it may take O(2km) which is
exponential in M.

P1 Instance P2 Instance Decide Yes


Construct

No
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.
L1 is no harder than L2 can be tested in two ways by computing function
'f' and testing membership in L2
 The statement "no harder than" can be distinguised by possible
 and impossible.
 If testing the membership of astring in L2 is possible, then testing a
 string after computing 'f' is also possible
  The reducing function'f' should be computable in areasonable amount of
time hich is in polynomial time.

Properties of Polynomial Time Reduction
If L1 and L2 are languagesover alphabet ∑1 and ∑2, then the language L1 is
polynomial time reducible to L2, which is denoted as L1≤pL2 if and only if f(x) L2
and f can be computed in polynomial time such there is a turing machine with
polynomial time complexity that computes 'f'.

145




DR W T CHEMBIAN
DR W T CHEMBIAN

Theorem:≤p is transitive, if L1≤p L2 and L2≤ pL3 then L1≤pL3


Theorem: If L2P and L1<pL2 ,then L1P
Polynomial Time Reduction with CNF-SAT
Problem CNF-SAT Reducible to complete sub graph
problem PART-C

1. Encode the following TM, M <M, 1011> in binary


M = ({q1, q2, q3}, {0, 1}, {0, 1, B},  , q1, B1, {q2}) No
Where  is
 (q1,1)  (q3 , 0, R)

 (q3, 0)  (q1,1, R)

 (q3,1)  (q2 , 0, R)

 (q3, B)  (q3,1, L)

Solution :

5) (q1,1)  (q3 , 0, R)
(q1, x2 )  (q3, x1, D2 )
1 2 3 1 2
Code1 = 0 10 10 10 10
6)  (q3, 0)  (q1,1, R)
(q3 , x1)  (q1, x2 , D2 )
3 1 1 2 2
Code2 = 0 10 10 10 10
7)  (q3,1)  (q2 , 0, R)
 (q3, x2 )  (q2 , x1, D2 )
Code3 = 03102102101102
8) (q3, B)  (q3,1, L)
 (q3, x3)  (q3, x2, D1)
Code4 = 03103103102101

Thus the string denoted by <M, 1011> is

|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011
111010010001010011000101010010011000100100101001100010001000100101
111011

146

DR W T CHEMBIAN
DR W T CHEMBIAN

2.POST CORRESPONDANCE PROBLEM



Explain about PCP [Nov/Dec 2013]

 Explain PCP and decidable and undecidable problems with example. 
[Apr/May 2015]
1. Post correspondence Problem : CP(P)

An instanceof post correspondence problem CP(P) consist of two lists. A = w 1,
 …, wk and

B = x1, …, xk

of strings over some alphabet 




This instance of PCP hasa solution if there any seque ce of integers i 1, i2,…,
im, with M 1 such that
 
wi1, wi2, …, wim = xi1 xi2 … xim
 
The sequence i1, … im is a solution to this PCP

Example :

Let {O,1} Let A and B be list of three strings.

List A List B

i wi xi

1 1 111

2 10111 10

3 10 0

Solution :

 has a solution
This PCP
M=4
 
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
 
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
101111110 = 101111110

The Solution
147

DR W T CHEMBIAN
DR W T CHEMBIAN

i1 = 2

i2 = 1

i3 = 1

i4 = 3

A modified version of PCP [MPCP]


 
The Modified version of PCP (MPCP) is the following
Given list A and B, of K strings each from  * say
A = w1, w2 …, wk
 
B = x1 , x2 …, xk

This problem has  a solution if there exists sequence of integers i 1,
 i2,…, ir, such that
 
w1wi1 wi2 …wir = xi1 xi2 …xir
The difference between the MPCP a d PCP is that in the MPCP a solution required to
start with the firs string on each list.

Lemma

If PCP were decidable, then MPCP would be decidable. That is,

MPCP reduces to PCP

Proof :

Let
A = w1, w2 …, k and
B = x1, x2 …, xk
be an instance of the MPCP

  to an instance of PCP that has a solution, iff our
We convert this instance of MPCP
MPCP instance has a solution.
  
If PCP were decidable then MPCP would be decidable.
 
 Let  is the alphabet containing all the symbols in List A and B
 
 Let  and not be in 
 
Let yi  be obtained from wi by inserting the symbol after each character of wi

148

DR W T CHEMBIAN
DR W T CHEMBIAN


Let Zi  be obtained from xi by inserting the symbol ahead of each character of
xi
 
Great new words
y0=  y1 Z0 = Z1
yk+1 = $ Zk+1 =  $
Example :

Reduce the following MPCP into PCP

List A List B

wi xi

1 1 111

2 10111 10

3 10 0

Solution :
The lists C and D are constructed from the lists A and B
Let
C = y0 , y1, …. yk+1
D = Z0, Z1, …. Zk+1


List C List D

yi zi

0 1  1 1 1  1

1 1 111

2 10111 1 0

149




DR W T CHEMBIAN
DR W T CHEMBIAN

3 1 0  0

4 $ $

  
Lists C and D represents an instance of PCP

This instance of PCP has a solution iff the instance of MPCP represented by lists A and
list B has a solution.

Undecidability of PCP

Theorem :

PCP is undecidable

Proof :

It is sufficient to show that if MPCP 
were d cidable, then PCP would be decidable
whether a TM accepts a given word.
  
We reduce Lu to MPCP, which again can be reduced to PCP.
For each M and w1 we construct an instance of MPCP that if it has a solution has one
starts with
#q0w# 1q11 #...#k qk
k where
Strings between sucresive #‟s are successive ID‟s in a computation of M with input
w.
  
qx is the final state.

the pairs of strings forming lists A and B of the instance of MPCP are given
Formally
below.
 
The first pair is
List A List B
# #q0w#
 
The remaining pairs are grouped as

Group 1 :

List A List B

x x

150

DR W T CHEMBIAN
DR W T CHEMBIAN

# # for each x in 

Group II :

For each q in Q-F, p in Q and x, y and z in 

List A List B

9x yp if (q, x) (p, y, R)

Zqx pZy if (q, x) (p, y, L)

q# pzy# if (q, B) (p, y, L)

Zq# pzY# if (q, B) (p, y, L)

Group III :

For each q in F, and x and Y in 

List A List B

XqY q

Xq q

qY q

Group IV :

List A List B

q## # for each q in F

(x, y) is a partial solution to MPCP with lists A and B

 if x is a prefix of y. 

 x and y are the concatenation of corresponding strings of lists A and B respectively. 
 
If xy = y then
151

DR W T CHEMBIAN
DR W T CHEMBIAN

Z is the remainder of (x, y)


 
(x, y) =
(#q0 w#1 q11 #2 q2 2 ...#k1qk1k1 ,
#q0 w#1q11 # .... #k qk k # )

Example :

M = ({q1, q2, q3}, (0, 1, B}, {0, 1},  , q1, B,

{q3}) and  is given as

0 1 B

q1 (q2, 1, k) (q2, 0, L) (q2, 1, L)


q2 (q3, 0, L) (q1, 0, R) (q2, 0, R)

q3 - - -

Construct an instance of MPCP with lists A and B

w = 01

Solution :
The first pair is
List A List B
# #q, 01#
 
The remaining pairs are

Group I :

List A List B

0 D

1 1

# #

Group II

152

DR W T CHEMBIAN
DR W T CHEMBIAN

List A List B

q1 , 0 1 q2 from (q1, 0)  (q2 ,1, R)

0q1, 1 q200
from (q1,1)  (q2 , 0, L)
1q1, 1 q2 10

0q1, # q2 01 #
from (q1, B) (q2 ,1, L)
1q1 # q211#

0q2 0 q3 00
from  (q12 , 0)  (q3 , 0, L)
1q2, 0 q0 10

q2 1 0q1 from (q2 ,1) (q1, 0, L)

q2 # 0q2# from (q2 , B) (q2 , 0, R)

Group III

List A List B

0q30 q3

0q31 q3

1q30 q3

1q31 q3

List A List B

0q3 q3

1q3 q3

q3 0 q3

q3 1 q3

Group IV :
153

DR W T CHEMBIAN
DR W T CHEMBIAN

List A List B

q3 # # #

  
M accepts input w = 01 by the sequence of Id‟s

q, 01, 1 q2 1, 1 0 q1, 1 q2 01, q3 1 0 1, q3 01, q3 1, q3

154

DR W T CHEMBIAN
DR W T CHEMBIAN

QUESTION PAPER CODE:80298

B.E/B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2016

Fifth Semester

Computer Science and Engineering

CS6503-THEORY OF COMPUTATION

(Regulations 2013)

Time: Three hours Maximum:100 marks

Answer ALL questions.

PART A - (10 x 2=20 marks)

1. Define Deterministic Finite Automata (DFA).(pg.no:7)

2. What are the closure properties of regular languages?(pg.no:7)

3. What is meant by Context Free Grammar(CFG)?(pg. o:58)

4. State Chomsky normal form theorem.(pg.no:66)

5. When is Push Down Automata (PDA) said to be deterministic? (pg.no:82)

6. What are the conventional notations of Push Down Automata? (pg.no:81)

7.What are the required field of an instantaneous description of a Turing machine? (pg.no:105)

8.List the primary objectives of Turing machines.(pg.no:108)

9. Define Universal Turing machine.(pg.o:130)

10. Define NP-hard and NP-completeness problem. (pg.no:133)

PART B-(5 X 16 =80 MARKS)

m
11 (a) (i) Given ∑=(a,b),construct a DFA which recognize the language L={b abn;m,n>0}.
(6)(pg.no:20)

(ii) Determine the DFA from a given NFA

M=({q0,q1},{a,b},δ,q0,{q1}) with the state table diagram for δ given below.(pg.no:57)


(10)
15
5

DR W T CHEMBIAN
DR W T CHEMBIAN

δ a b

q0 {q0,q1} {q1}

q1 φ {q0,q1}

Or

(b) Discuss the basic approach to convert from NFA to regular expression illudtrate with
an example.(pg.no: 40)

(16)

12 (a) (i) Construct a Context Free Grammar for the language L={an: n is odd} (pg.no:67)(6)

(ii) Define derivation tree. Explain its uses with an example.(pg.no:70) (10)

Or

(b) Obtain a grammar in chomsky Normal Form(CNF) equival nt to the grammar G with the production
P given.(pg.no:75)

S->aAbB ,A->aA/a, B->bB/b.

13. (a) (i) Outline an instantaneous description of a PDA. (pg.no:86) (6)

(ii)State and explain the pumping lemma for CFG (pg.no:93) (10)

Or

(b) with an example, explain the procedu e to obtain a PDA from the given CFG. (16)

14 (a) Discuss the various techniqu s for Turing Machine construction.(pg.no:112) (16)

Or

(b) (i) Write about Multitape turing machines. (pg.no:118) (10)

(ii) Explain highlight the implication of halting Problem.(pg.no:123) (6)

15 (a) (i) Elaborate on primitive recursive function with an example.(pg.no:141) (10)

(ii) Compare recursive language with recursive enumerable languages.(pg.no:133) (6)

Or

(b) (i) What are tractable problems? compare it with intractable problems. (pg.no:143) (10)

(ii) Outline the concept of polynomial time reductions. (pg.no:145) (6)


156

DR W T CHEMBIAN
DR W T CHEMBIAN

QUESTION PAPER CODE:71684

B.E/B.Tech. DEGREE EXAMINATION, APRIL/MAY 2017

Fifth Semester

Computer Science and Engineering

CS6503-THEORY OF COMPUTATION

(Regulations 2013)

Time: Three hours Maximum:100 marks

Answer ALL questions.

PART A - (10 x 2=20 marks)

1. Generate NFA-ϵ to represent a*b|c. (pg.no:58)

2. Show whether a language L={0n12n|n>0} is regular or not using pumping lemma.(pg.no:53)

3. Give language of regular expression of a?(b/c)*.(pg. o:69)

4. Generate CFG for a signed integer constant in C lan uage.

5. Construct a right most derivation of (a+b)*c for using the grammar, and also state that whether a
given grammar is ambiguous or not. (pg.no:71)

6. Differentiate PDA acceptance by empty stack method with acceptance by the final
state method.(pg.no:86)

7. Write short notes Chomsky hi rarchy of language.(pg.no:121)

8. What is Halting problem?(pg no:123)

9. What is primitive recursive function?(pg.no:152)

10. Define NP-completeness.(pg.no:153)

PART B-(5 X 16 =80 MARKS)

11 (a) Construct NFA with epsilon for the RE=(a/b)*ab and convert into DFA and further find the
minimized DFA.(pg.no:38,29,43)

157

DR W T CHEMBIAN
DR W T CHEMBIAN

Or
n

(b) Prove for every n >=1 by mathematical induction i3  {n(n 1) / 2}2 (pg.no:54) (16)
1

12 (a) Given the CFG G, Find CFG G' in CNF generating the language L(G)-{^}(pg.no:75)

S->AACD

A->aAb|^

C->aC|a

D->aDa|bDb|^ Or

(b) Convert the following grammar G into Greibach Normal

form(GNF).(pg.no:77) S->Xa|BB

B->b|Sb

X->b X-

>a

13. (a) (i) Construct a DPDA for even length pali drome. (pg.no:88) (6)

(ii)Prove- if PDA P is constructed from CFG G be the above construction, then

N(P)=L(G)(pg.no:91)(10) Or

(b)Convert the following CFG to PDA nd verify for (a+b) and a++.(16)

I->a|b|Ia||Ib|I0|I1,E->I|E+E|E*E|(E)

14 (a)Construct a TM to reverse the given string (16)(pg.no:125)

Or

(b) Write about Multitape and Multi head turing machineswith suitable
example.(pg.no:118) (16)

15 (a) Explain recursive and recursively enumerable language with suitable example. (16)(pg.no:133)

Or

(b) Explain about tractable and intractable problem with suitable examples.(pg.no:143) (16)

158

DR W T CHEMBIAN

You might also like