0% found this document useful (0 votes)
147 views162 pages

CS8501 - THEORY OF COMPUTATION - by LearnEngineering - in

This document outlines the course content for CS8501 Theory of Computation. The course covers 5 units: 1) Automata Fundamentals, 2) Regular Expressions and Languages, 3) Context Free Grammar and Languages, 4) Properties of Context Free Languages, and 5) Undecidability. Some key topics include finite automata, regular expressions, pushdown automata, context-free grammars, pumping lemma, Turing machines, and the halting problem. The course aims to introduce formal languages and models of computation.

Uploaded by

KrisHnA 2k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views162 pages

CS8501 - THEORY OF COMPUTATION - by LearnEngineering - in

This document outlines the course content for CS8501 Theory of Computation. The course covers 5 units: 1) Automata Fundamentals, 2) Regular Expressions and Languages, 3) Context Free Grammar and Languages, 4) Properties of Context Free Languages, and 5) Undecidability. Some key topics include finite automata, regular expressions, pushdown automata, context-free grammars, pumping lemma, Turing machines, and the halting problem. The course aims to introduce formal languages and models of computation.

Uploaded by

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

Visit for More : www.LearnEngineering.

in

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

n
CFG – Parse Trees – Ambiguity in Grammars and Languages – Definition of

g.i
the Pushdown Automata – Languages of a Pushdown Automata – Equivalence
of Pushdown Automata and CFG, Deterministic Pushdown Automata.

rin
UNIT IV PROPERTIES OF CONTEXT FREE LANGUAGES
Normal Forms for CFG – Pumping Lemma for CFL – Closure Properties of
ee
CFL – Turing Machines – Programming Techniques for TM.
gin

UNIT V UNDECIDABILITY
Non Recursive Enumerable (RE) Language – Undecidable Problem with RE –
Undecidable Problems about TM – Post‘s Correspondence Problem, The Class
En

P and NP.
TOTAL :45PERIODS
arn

TEXT BOOK:
1. J.E.Hopcroft, R.Motwani and J.D Ullman, ―Introduction to Automata
Le

Theory, Languages and Computations‖, Second Edition, Pearson Education,


2003.
w.

REFERENCES:
1. H.R.Lewis and C.H.Papadimitriou, ―Elements of the theory of
ww

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.

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Department of Computer Science and

Engineering

n
g.i
SUBJECT CODE: CS8 5 0 1

SUBJECT NAME: Theory Of Computation

rin
Regulation: 2017

ee
gin
En
arn
Le
w.
ww

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

TABLE OF CONTENTS
Sl.no Topic Page No
a. Aim & Objective of the subject 1
b. Detailed Lesson Plan 2
Unit I- Introduction To Compilers
c. Part A 4
d. Part B 8
1. Language Processor 8
2. Software Tools used in Compilation 9

n
3. Analysis Part of Compilation 10

g.i
4. Phases Of Compiler 11
5. Cousins Of Compiler 16
6. The Grouping Of Phases 18

rin
7. Compiler Construction Tools 18
Unit II- Lexical Analysis
e.
f.
Part A
Part B ee 20
23
gin
8. Need and Role of Lexical Analyzer 23
9. Input Buffering 25
10. Expressing Tokens by Regular Expressions 26
En

11. Language for Specifying Lexical Analyzer 31


12. Regular Expression to DFA 33
Unit III- Syntax Analysis
arn

g. Part A 35
h. Part B 39
Le

13. Need and Role of the Parser 39


14. Various Terminologies in Parsing 41
15. Context Free Grammars 42
w.

16. Writing a Grammar 45


17. Recursive Descent Parser 48
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

i. Part A 71
j. Part B 74
25. Source Language Issues 74
26. Storage Organization 76
27. Storage Allocation 77
28. Type Systems 81
29. Specification of a Simple Type Checker 86
30. Syntax Directed Definition 88
31. Construction of Syntax Tree 92
32.

n
Parameter Parsing 94
33. Design of a Predictive Translator 96

g.i
Unit V- Code Optimization and Code Generation
k. Part A 100

rin
l. Part B 103
34. Principal Sources of Optimization 103
35.
36.
DAG
ee
Optimization of Basic Blocks
108
113
gin
37. Global Data Flow Analysis 114
38. Issues in the Design of A Code Generator 122
39. A simple Code Generator Algorithm 124
En

40. Peephole Optimization 127


m. Industrial / Practical Connectivity of the subject 130
41. University Question papers
arn
Le
w.
ww

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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:

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

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

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

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

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

Finite State systems – Basic Definitions –


En

T1
2 Finite Automaton 1 2

DFA & NDFA – Finite Automaton with €- moves


arn

3 1 3 T1

4 Regular Languages- Regular Expression 1 4 T1


Le

Equivalence of NFA and DFA T1


5 1 5
I Equivalence of NDFAs with and without €-
w.

T1
6 moves 1 6
ww

Equivalence of finite Automaton and T1


7 regular expressions 1 7

Minimization of DFA T1
8 1 8

Pumping Lemma for Regular sets T1


9 1 9

Problems based on Pumping Lemma. T1


10 1 10

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

Context Free Grammars and Languages T1


13 1 13

Derivations and Languages T1


14 1 14

n
g.i
Ambiguity- Relationship between derivation T1
15 and derivation trees 1 15
II

rin
Simplification of CFG T1
16 1 16
Elimination of Useless symbols - Unit
17
ee
productions- Null productions 1 17
T1
gin
Greiback Normal form T1
18 1 18

Chomsky normal form T1


En

19 1 19

Problems related to CNF and GNF. T1


20 1 20
arn

Pushdown Automata- Definitions T1


21 1 21

Moves – Instantaneous descriptions T1


Le

22 1 22

Deterministic pushdown automata T1


w.

23 1 23
III Equivalence of Pushdown automata and T1
ww

24 CFL 4 27

Pumping lemma for CFL T1


25 2 29

Problems based on pumping Lemma. T1


26 1 30

Definitions of Turing machines T1


27 1 31
IV
28 Models 1 32 T1

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

30 Techniques for Turing machine construction 2 35 T1

31 Multi head and Multi tape Turing Machines 1 36 T1

32 The Halting problem 1 37 T1,T2

n
33 Partial Solvability 1 38 T1,T2

g.i
34 Problems about Turing machine 1 39 T1,T2

rin
Chomskian hierarchy of languages. T1,T2
35 1 40
Unsolvable Problems and Computable
36 Functions
ee 1 41 T1,T2
gin
37 Primitive recursive functions 1 42 T1,T2

Recursive and recursively enumerable


38 2 44 T1,T2
En

languages

39 Universal Turing machine 1 45 T1,T2


arn

V Measuring And Classifying Complexity T1,T2


40 1 46
Tractable and Intractable problems T1,T2
Le

41 1 47

Tractable and possibly intractable problems T1,T2


42 1 48
w.

P and NP completeness T1,T2


43 1 49
ww

Polynomial time reductions T1,T2


44 1 50

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
PART-A

g.i
1. Define the following:
a. Symbol

rin
A symbol is an abstract entity. Letters and digits are symbols.
b. String:
A string is a finite sequence of symbols.
Eg: abc, dog are strings
c. Language:
ee
gin
A language is a set of strings of symbols from one alphabet.
Ф, { ϵ} are languages.
En

Alphabet:
An alphabet is a finite set of symbols.
2. What is relation?
arn

A 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
Le

chosen from a set called a range.


What are the properties of relation?
a. Reflexive:
w.

If aRa for all a in S


b. Irreflexive:
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
ii. Reduction to definition

g.i
iii. Other theorem forms
iv. Theorems that appear not to be if-then statements

rin
5. What are the applications of theory of computation?
i. Compiler design
ii.
iii.
Robotics
ee
Artificial intelligence
gin
iv. Knowledge engineering
6. What is finite state system?
En

Finite state system:

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


arn

and outputs. The system with discrete inputs and outputs. The system can be in
any one of the finite number of internal states and input symbols.
Le

Input Tape
0 + 1 . . .
tape head
w.

Finite
ww

control

7. what is Deterministic Finite Automata(DFA)?

DFA:

DFA is defined by a 5 tuple.

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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 :

n
NFA is defined as 5 tuples

g.i
M = (Q,Σ,δ,q0,F)

rin
Q-> Set of states

Σ -> set of input symbols


ee
δ > is a transition function mapping from
gin
Qx Σ-> 2Q
En

qo -> an initial state

F -> set of final stater F<Q


arn

10. Define the language accepted by finite automata?

The language accepted by FA:


Le

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


w.

L(M)

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
ie. One or more number of occurrences of a string in L

g.i
13. What is regular expression?

rin
Regular Expression:

Ф is a regular expression denoting the language { }


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

14. State the pumping lemma for regular languages.


arn

Pumping lemma:

Let L be a regular set , then there is a constant n and z is any word in L and |Z|>- n
Le

, we can write z = uvw in such a way that

|uv|<- n
w.

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
 A string or word is finite sequence of symbol.

g.i
 Example
a, b and c are symbols and abcd is a string.

rin
 The length of a string w is the number of symbols composing the string.
 It is denoted as w
 Example :
abcd has length 4 ee
gin
The empty string E, the string consisting of zero symbols E =0.
 A prefix of a string is any number of leading symbols of the string.
En

 Example :
String abc has prefixes,
E, a, ab, abc.
arn

 A suffix is any number of trailing symbols of that string.


 Example :
Le

String abc has suffixes


E, c, bc, abc
 A prefix or suffix of a string other than the string itself is called a proper prefix or
w.

suffix.
 The concatenation of two strings is the string formed by writing the first followed
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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 , ...

n
Set Notation :

g.i
 Set is a collection of objects without repetition.
 Finite sets may be specified by two forms

rin
i. listing their members between brachets.
ii. Set former
x | p x 
x in A | p x  ee
 If every member of A is a member of B, then we write A B and say A is
gin
contained in B.
 If A B but A  B , that is every member of A is in B and there is same member of
En

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

Operations on Sets :
1. A  B , the union of A and B is
x| x is in A of x is in B
Le

2. A  B , the intersection of A and B is


x| x is in A and x is in B
w.

3. A – B, the difference of A and B is


x| x is in A and x is not in B
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
 The first component of each pair is chosen from a set called the domain and the

g.i
second component of each pair is chosen from a set called a range.
 If R is a relation and (a, b) is a pair in R then we write a R b.

rin
Properties of Relations :
 We say a relation R on set S is
1. Reflexive
if aRa for all a in S ee
gin
2. Irreflexive
if aRa is false for all a in S
3. Transitive
En

if aRb and bRc imply aRc


4. Symmetric
arn

if aRb implies bRa


5. Asymmetic
if aRb implies that bRa is false.
Le

 Any asymmetric relation must be irreflexive.


Equivalence relation :
w.

 A relation R that is
i. Reflexive
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
 Graph is denoted as G = (V, E)

g.i
 A path in a graph is a sequence of verticle V1, V2, V3, …., Vk k 1, such that there
is an edge (Vi, Vi+1) for each I |  i  k

rin
Directed Graphs:
 A directed graph or digraph consists of a finite set of vertices V and a set of

ee
ordered pairs of vertices E called arcs.
 The arc from V  W is denoted as V  W
gin
 If V  W is an arc, we say
V  Pr edecessorof W
W  Successorof V
En

Trees:
 A tree is a digraph with the following properties
arn

1. Three is one vertex, called the root that has no predecessor and from which
there is a path to every vertex.
Le

2. Each vertex other than the root has exactly one predecessor.
3. The successor of each vertex is ordered from the left.
 If there is a path from vertex V1 to Vertex V2 then V2 is said to be descendant of
w.

V1 and V1 is said to be an ancestor of V2.


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 In format proof
We try to prove that statement B is true because statement A is true.
 The statement A is called hypothesis and B is called conclusion statement.
The four ways of Theorem Proving
(or)
Methods of formal proof.
(1) Deductive Proof
(2) Reduction Proof
(3) Other theorem forms

n
(4) Theorems that appear not to be if then statement.

g.i
Deductive Proof :
 A deductive proof consists of a sequence of statements whose truth leads us from

rin
some initial statement called the hypothesis or the given statement (s) to a
conclusion statement.
 The theorem that is proved when we go from a hypothesis H to a conclusion C is
the statement.
“If H then C”
ee
gin
We say that C is deducted from H
 The hypothesis may be true or false hypically depending on values of its
En

parameters.
Theorem 1
If x  4 then 2 x  x 2
arn

Proof :
 The hypothesis H is x  4
Le

 The hypothesis has a parameter x and thus is neither true of false.


 eg. H is true for x = 6 and false x = 2
w.

 The conclusion C is 2 x  x 2
 This statement also uses parameter x and is true for certain values of x and not
ww

others.
 The intuitive argument that tells the conclusion 2 x  x 2 will be true whenever x  4
 The left side 2x doubles each time x increase by 1
 x 1
2

 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 deduced from x  4
Theorem 2 :

13

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

Statement Justification

1 x = a 2 + b2 + c 2 + d2 Given

2 a 1, b 1, c 1, d 1 Given

3 a 2 1, b 2 1, c 2 1, d 2 1 (2) and properties of arithmetic

x4

n
4 (1) and (3) properties of arithmetic

g.i
5 2x  x2 (5) and Theorem (1)

rin
Reduction to definitions
 If you are not sure how to start a proof convert all terms in the hypothesis to their
definitions.
Theorem :
ee
gin
Let S be a finite subset of some infinite set Let T be the complement of S with
respect to Then T is infinite.
En

Proof :
Original Statement New Statement
arn

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


Le

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

SUT = U and
w.

T is the complement of S
S T 
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 The statement that U is finite contradicts the given statement that U is infinite
 Thus our assumption is contradiction
 So T is infinite
Other Theorem Forms :
 Ways of saying “if – Then”
 The other ways in which if H then C might appear.
1. H implies C
2. H only if C
3. C if H

n
4. whenever H holds, C follows.

g.i
If – And – only – If statements :
 The statement of the form

rin
A if and only if B is actually two if – then statements.
(i) if A then B and
(ii) if B then A
ee
Theorems that appear not to be if – then statements :
 Sometimes we find a theorem that appear not to have a hypothesis.
gin
 An example is the well-known fact from the trigonometry.
 Theorem
En

Sin 2   Cos 2  1
Additional Forms of Proof :
arn

1. Proofs about sets.


2. Proofs by contradiction.
3. Proofs by counter example.
Le

Proving Equivalences about sets :


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

the same.
 Every element in the set epresented by E is in the set represented by F
 And every element in the set represented by F is in the set represented by E.
ww

Example :
 The commutative law of union says that we can take the union of two sets R and S
in either order.
i.e., RUS = SUR
 The commutative law of union says E = F
 The proof of any statement that asserts the equality of two sets E = F, if follows
the form of any if – and – only – if – proof

15

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
Statement Justification

1 x is in R  U(S  T) Given

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

3 ee
x is in R or x in in both S and T (2) and definition of intersection
gin
4 x is in RUS (3) and definition of union

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


En

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


arn

Steps in the „only-if‟ part.


Le

Statement Justification

1 x is in (R  S)  (R  T) Given
w.

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

The Contrapositive :
 The contrapositive of the statement “if H then C” is “if not C then not H”
 A statement and its contrapositive are either both true or both false.
 To see “if H then C” and if not C then not H are logically equivalent.
There are four cases to consider
1. H and C both true
2. H true and C false
3. C true and H false

n
4. H and C both false

g.i
Proof by contradiction :
 Another way to prove a statement of the form.

rin
“if H then C is to prove the statement.
 H and not C implies false hood.
 Start by assuming both the hypothesis H and the negation of the conclusion C
ee
 Complete the proof by showing that something known to be false follows logically
from H and C
gin
 This form of proof is called proof by contradiction.
Counter example :
En

 Statements that have no parameters, or that apply to only a finite number of values
of its parameter are called observations.
 It is easier to prove that a statement is not a theorem than to prove it is a theorem.
arn

Example
All primes are odd.
Le

More formally, we might say


if integer x is a prime, then x is odd
w.

Example
There is no pass of integers a and b such that
a mod b = b mod a
ww

2.A.BASIC DEFINITIONS DFA AND NFA

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

Finite state systems :

17

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 The finite Automaton is a mathematical model of a system with discute inputs and
outputs.
 The system can be in a any one of a finite number of internal configuration or
states.
 The state of the system summarixes the information concerning past inputs that is
needed to determine the behavior of the system on subsequent inputs.
 The primary example of finite automaton is a switching circuit such as control unit
of a computer.
 A switching circuit is composed of a finite number of gates each of which can be

n
in one of two conditions usually 0 and 1

g.i
 The state of a switching network with n gates is thus any one of the 2n assignments
of 0 or 1 to the various gates.

rin
 Text editors and the lexical analyzers found in most compiters are designed as
finite state systems.
0 1 0 1 0 0 0

ee
gin
Finite Control
Basic Definitions :
Deterministic finite automata :
En

 A finite automator (FA) consists of a finite set of states and a set of transitions
from state to state that occur on an inpul symbol chosen from an alphabet 
 For each input symbol there is exactly one transition out of each state.
arn

 One state denoted qo is the initial state in which the transition starts.
 Some states are designated as final states or accepting states.
Le

 The Deterministic finite automata can be represented as a transition diagram or


transition table.
w.

 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
ww

labeled a from state q to state p


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

18

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 The initial state, qo is indicated by the arrow labeled start.

n
 The final state indicated by the double circle.

g.i
 The FA accepts all string of 0‟s and 1‟s in which both the number 0‟s and the
number of 1‟s are even.

rin
 for eg.
The string accepted by the above FA, 11, 1100, 00, 0000, 1111, 110110
Formal Definition of DFA :
ee
 We formally denote a finite automaton by a 5 tube.
gin
M = Q, , , q o , F
Q  is a finite set of states
  is a finite input alphabet
En

qo 
in Q is the initial state
F  F  Q is the set of final states
arn

  is the transition function mapping from Q x  to 

ie  (q, a ) is a state for each state q and input symbol a


Le

 FA is denoted as a finite control


w.

0 1 0 1 0 0 0
ww

Finite Control
 Finite control which is in same state from Q reads a sequence of symbols from
 written on a tape.

 In one move, the FA in state q, scanning a symbol a enters state  (q, a ) and moves
its head one symbol to the right.

 We define a function  from


19

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Q x  * to Q

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

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

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

n
 A string x is said to be accepted by FA

g.i
M = (Q, , , q o , F) if
 (q o , x )  p, for some P in F

rin
 The language accepted by FA, denoted as L(M)
L (M) = x |  (q o , x ) is in F
ee
 The language is a regular set if it is the set accepted by the same FA
gin
Example :
Consider the transition diagram
En
arn
Le
w.

 This FA is denoted as
M = (Q, , , q o , F) where
ww

Q = q 0 , q1 , q 2 , q 3 
  0,1
q0 = q0
F = q 0 
 is given as a transition table
s 0 1

20

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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


find  (q 0 ,110101 )
 (q 0 ,1)  9,

n

g.i
 (q 0 ,110)   ( (q,1),1)
  (q1 ,1)
 q0

rin
 
 (q0 ,110)   ( (q 0 ,11), 0)
  (q0 , 0)
 q2
ee
gin
 
 (q0 ,1101)   ( (q 0 ,110),1)
  (q2 ,1)
En

 q3
 
 (q0 ,11010)   ( (q 0 ,1101), 0)
arn

  (q3 , 0)
 q1
Le

 
 (q 0 ,110101)   ( (q 0 ,11010),1)
  (q1 ,1)
w.

 q 0 F
 Thus 110101 is accepted by the FA Thus 110101 is in L(M)
ww

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

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 Any set accepted by NFA can also be accepted by DFA.


 Example

n
g.i
rin
 The input sequence a1, a2, a3 …. an is accepted by NFA, if the transition
leads from the initial state of final state.
Formal Definition of NFA :
ee
 Formally we denote a NFA by a 5 – tuple
gin
M = (Q, , , q 0 , F)
where
Q  set of states
En

  is a finite input alphabet


qo 
arn

in Q is the initial state


F  F  Q is the set of final states
  is the transition function mapping from Q x  to 
Le

Q x   2Q

 The function  can be extended to a function  mapping from
w.

Q x  * to 2 Q and
ww

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



 
 (q, wa )     (q, w ), a 
(ii)  
Example :
Consider the NFA

22

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i
Let the input w = 01001
Solution :

rin
Q  q 0 , q1 , q 2 , q 3 , q 4 
  0,1
q0 = q0
F = {q2, q4}
ee
gin
:
0 1
En

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


q1  {q2}
arn

q2 {q2} {q2}
q3 {q4} 
q4 {q4} {q4}
Le

 (q0,01001)  q
w.

 (q 0 , 0)  {q, q 3 )
 (q 0 , 01)   ( (q 0 , 0), 1)
ww

=  ({q 0 , q 3 }, 1)
=  (q 0 ,1)   (q 3 ,1)
= {q0,q1)  
= {q0, q1}
 (q 0 , 010 )   ( (q 0 , 01), 0)

=  ( {q 0 , q1 }, 0)

23

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

=  (q 0 , 0)   (q1 , 0)
= {q0,q3)  
= {q0, q3}

 (q 0 , 0100 )   ( (q 0 , 010 ), 1)

=  ( {q 0 , q 3 }, 0)
=  (q 0 ,1)   (q 3 , 0)
= {q0,q3)   {q4}

n
= {q0, q3, q4}

g.i

 (q 0 , 01001 )   ( (q 0 , 0100 ), 1)

=  ( {q 0 , q 3 , q 4 }, 1)

rin
=  (q 0 ,1)   (q 3 ,1)   (q 4 ,1)
= {q0,q1)    {q4}
= {q0, q1, q4} ee
gin
 (q 0 , 01001 )
contains a state in F so the input string 01001 is accepted by the NFA.
En

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
arn

[Nov/Dec 2015]
Le

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

 for every NFA we can construct an equivalent DFA.


Theorem :
ww

Let L be a set accepted by NFA, then there exists a DFA that accepts L.
Proof :
Let M = Q, , , q 0 , F be an NFA which accepts L.
Define a DFA.

M1 Q1 , 1 , 1 , q 0 , F1
1

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 F1 is the set of all states in Q1containing a final state of M.


 An element of Q1will 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

n
1 (q 0 , x) = [q1, q2, …qj]
1

g.i
iff
1 (q 0 , x ) = [q1, q2, …qj]

rin
Basis :
The result is trivial for 1 x 1 = 0, since q01 = [q0] and x must be 

iff
1 ( [q 0 ],   [q 0 ]
ee
gin
 ( q 0 )  q 0
Induction :
En

 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
arn

1 (q 0 , xa)  1 (1 (q 0 , x), a)


1 1

By the inductive hypothesis


1 (q 0 , x) [p1 , p 2 , ...p j ]
1
Le

iff
 (q 0 , x)  [p1 , p 2 , ... p j ]
w.

1 (q 0 , xa)  1 (1 (q 0 , x), a)


1
ww

 1 [p1 , p 2 , .....p j ], a)
 r1 , r2 , ... rk 
iff
1 (q 0 , xa )   ( (q 0 , x), a )
 1 [p1 , p 2 , .....p j ], a)
 r1 , r2 , ... rk 
Thus
25

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

iff
1 (q 0 , xa) [r1 , r2 , ...r k ]
1

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

n
g.i
3.A.FINITE AUTOMATA WITH  -MOVES

rin
 Discuss on Finite Automata with epsilon Transitions. [Nov /Dec 2015]

Finite Automata with  Moves :


ee
 The NFA may be extended to include transitions on the empty input 
 For eg.
gin
En
arn

 We say an NFA accepts a string w if there is some labeled w from the initial state
to a final state of course edges labeled  may be included in the path although the
Le

' s do not appear explicitly in w.


 For eg. the word 002 is accepted by the NFA by the path q0 – q0 – q0 – q1 – q2 – q2
with arcs labeled 0, 0, ,, 2
w.

Formal definition :
 A NFA with  moves to be a 5 – tuple,
ww

M = (Q, , , q 0 , F)
 is the transition function maps
Q x (  to 2 Q
  (q, a ) will consist of all states P such that there is a transition labeled a from q to
p where a is either  or a symbol in 
0 1 2 

26

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

q0 {q0}   {q1}

q1  {q1}  {q2}

[q2]   {q2} 

 - closue (q)
 -closue (q) is the set of all vertices p such that there is a path from q to p labeled
Example :

n
 - closure (q0) = {q0, q1, q2}

g.i
 ie) the path consisting of q0 alone is a from q0 to q0 with all arcs labeled  .
 Path q0 – q1, shows that q1 is in  closure. (q0)

rin
 Path q0 – q1 – q2 shows that q2is in  -closure.

  can be defined as follows :

1.  (q,)   closure(q) ee
gin
2. for w in * and a in 

 (q, wa) =  - closure (p)
Where p = p | 
En


For some p in  ( (q, w )
arn

3.  (R, a )    (q, a )
q in R
 
Le

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

 We can define L (M) as


The language accepted by M ( Q, , , q 0 , F) to be
ww


{w| q  (q,w) contains a state in F}
 Example :
Consider the NFA

27

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in


Find  (q0, q1)
 
 (q0, 01) =  closure ( ( (q 0 , 0), 1)
 

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

g.i

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

rin
 
 (q0, 01) =  closure ( ( (q 0 ,), 0)

ee
=  closure ( ({q 0 , q1 , q 2 ), 0)
=  closure ( (q 0 , 0)   (q, 0)   (q 2, 0))
gin
=  closure ({q 0 }    )
= {q0, q1, q2}
En

 
 (q0, 01) =  closure ( ( (q 0 , 0), 1)
=  closure ( ({q 0 , q1 , q 2 ), 1)
arn

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


=  closure ( {q1 }  )
Le

=  closure{q1 }
= {q1, q2}
w.

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


ww

 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, , , q 0 , F) be an NFA with  - transitions.
Now we have to define NFA without  - move M‟
28

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

1 (q 0 , x )   (q 0 , x )
 This statement may not be true for x 
1 (q 0,)  {q 0 }
while  (q 0 ,)  closure (q 0 )

n
 Therefore we begin our induction at 1

g.i
Basis :
|x|=1

rin
Then x is a symbol a
1 (q 0 , a )   (q 0 , a ) by the definition of 1
Induction :
| x | >1 Let x = wa ee
gin
1(q0, wa)  1( (q0, w), a )

=  ( p, a )
1
En

=   (q , a )
1

q in p
=   (q, a )
arn

q in p
=  (p, a )
Le

 

=  ( (q 0 , w ), a   (q 0 , wa )
w.

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


ww

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

Consider the NFA with  - moves

Find an equivalent NFA without  - moves


29

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
0 1 2

g.i
q0 {q0, q1, q2} {q0, q1} {q2}

rin
q1  {q1, q2} {q2}

q2  
ee
{q2}
 closure(q1 ) {q1 , q 2 }
gin
 closure(q 2 ) {q 2 }
 (q0,) =   closure(q 0 )
En

= {q0, q1, q2}


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

=  closure ( ( (q 0 ,), 0)
=  closure ( ({q 0 , q1 , q 2 }, 0)
Le

=  closure ( (q 0 , 0)   (q1 , 0)   (q 2 , 0))


=  closure ( ({q 0 }    )
w.

= {q0, q1, q2}


ww

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


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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
=  closure ( (q1 , 0)   (q 2 , 0))

g.i
=  closure(  )
=

rin
1 ( q 1 , 0 ) =  closure ( (q1 , 0))
=  closure ( ( (q1 ,), 1)
ee
=  closure ( ({ q1 , q 2 }, 1)
=  closure ( (q1 ,1)   (q 2 ,1) ))
gin
=  closure ({q1 }  )
= {q1, q2}
En

1 ( q 1 , 2 ) =  closure ( (q1 , 2))


=  closure ( ( (q1 ,), 2)
arn

=  closure ( ({ q1 , q 2 }, 2)
=  closure ( (q1 , 2)   (q 2 , 2) )
Le

=  closure ( {q 2 } )
= {q2}
w.

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

=  closure()
=
1 (q 2 ,1) =  closure ( (q 2 ,), 1)
=  closure ( ({q 2 ), 1)
=  closure()
=
1 ( q 2 , 2 ) =  closure ( (q 2 ,), 2)
31

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
Example 2 :

rin
Construct a NFA without  - moves from NFA with  - moves

ee
gin
Solution :
En

 closure (q0) = {q0, q1}


 closure (q1) = {q1}
arn

Let Given NFA with  moves


M = (Q, , , q 0 , F)
Le

We have to find M‟, NFA without  move


M = (Q, , 1 , q 0 , F1 )
w.

F1 = {q0, q1}  closure(q0) containsa statein F


F1 = F {q 0 }
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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


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

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


=  closure()

n
=

g.i
1 (q1 ,1) =  closure (1 (1 (q1 ,), 1)
=  closure (1 ({q 2 ), 1)

rin
=  closure (q1 )
= {q1}
0 1 ee
gin
q0 {q0, q1} {q1}


En

q1 {q1}
arn
Le

4.A.EQUIVALENCE OF FINITE AUTOMATA AND REGULAR EXPRESSIONS


w.

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
Induction :

g.i
One or more operators in the regular expressions.
 Assure that the theorem is true for regular expression with fewer that I operators.

rin
i 1
 Let r have I operators.
Case 1 :
r = r1 + r2 ee
 Both r1 and r2 must have fewer than i operator
gin
 Thus there are 2 NFA‟s
M1 = (Q1 , 1 , 1 , q1 ,{f 1} with
En

= L (M1) = L (r1)
 Assume Q1 and Q2 are disjoint
arn

Let q0  be a new initial state


f0  be a new initial state
 Now we can construct NFA with
Le

M = Q1,  Q2 {q0, f 0}, ,   2, , q0,{f 0})


where  is defined by
w.

(i)  (q 0 ,)  {q1 , q 2 }


(ii)  (q, a )  1 (q, a ) for q in Q1 {f 1}and a in 1 {}
ww

(iii)  (q, a )   2 (q, a ) for q in Q 2 {f 2} and a in  2 {}


(iv) 1 (f 1,)   2 (f 2,)  {f 0}

34

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 Hence
L (M) = L (M1) U L (M2)

n
Any path in the transition diagram of M from q0 to f0 must begin by going to either

g.i
q1 or q2on  . If the path goes to q1 it may follow any path in M1 to f1 and then go to f0
on 

rin
Hence L (M) = L (M1) U L (M2)
Case 2 :
r = r1 r 2
Let M1 and M2 be 2 NFA‟s ee
M1 = Q1 , 1 , 1 , q1 ,{f 1}) with
gin
L (M1) = L (r1)
and
En

M2 = Q 2 ,  2 ,  2 , q 2 ,{f 2}) with


L (M2) = L (r2)
arn

 Assume Q1 and Q2 are disjoint


 No we can construct NFA with
L (M) = L (r)
Le

M = (Q, Q 2 , ,  2 , ,{q1 }, {f 2})


where
w.

 is defined as
(i)  (q, a )  1 (q1 , a ) for q in Q1 {f 1}and a in 1 {}
ww

(ii)  (q, a )   (q1 , a ) for q in Q 2 {f 1}and a in  2 {}


(iii)  (f 1,) {q 2 }
 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 Thus
L (M) = L (M1) L (M2)
ie. L (M) = { xy | x is in L (M1 ) and y is in L (M 2 )}
Case (iii)
r = r1 *
Let M1 = (Q1 , 1 , 1 , q1 ,{f 1}) with
L (M1) = L (r1)

n
Now we can construct NFA

g.i
Let M1 = (Q1 {q 0 , f 0}, 1 , 1 , q 0 ,{f 0}) with
L (M) = L (r)

rin
where
q0  be an new initial state
f0  be an new final state
and  is given by ee
gin
(i)  (q 0 ,)   (f 1,) {q1 , f 0 }
(ii)  (q, a )  1 (q, a ) for q in Q1 {f 1} and a in 1 {}
 Any path from q0 to f0 consists either of a path from q0 to q1 on  followed by
En

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 
arn

Hence :
L (M) = L (M1)
Le
w.
ww

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

36

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

M = ({q1 , ........, q n }, , , q1 , F)
Let
 denote the set of all string x such that  (q i , x )  q j and  (q i , y) = ql for any that is a
k
R ij

prefix of x, then l  k
k
i.e.) R ij
= is the set of all strings that take the FA from state qi to qj without going
though any state numberd higher than k.
 we can define
k
R ij
= is the set of all strings that take the FA from state qi to qj

n
without going through any state numbered higher than k.

g.i
 We can define
k
R recursively. ij
k k 1 k 1 k 1 k 1
R = R (R ) * R  R

rin
ij ik kk kj ij

 The inputs of
k
R are, either
1) in R
k 1
ij
ij

ee
gin
(or)
k 1 k 1
2) Composed of a string R ik
followed by zero of more strings in R kk
followed by
En

k 1
a string R kj

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

k k
r ij
denoting the language R ij

 We can show by induction on k.


Le

Basis :
k=0
is a finite set of strings, each of which is either  or a single symbol.
0
w.

R ij

Induction :
ww

 The recursive formula


k
R ij
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 ) * rkjk 1  rijk 1
 We can conclude
37

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 R ijn
L (M) =
q j in F
Thus L (M) is denoted by the regular expn.
rijn1  rijn2  ...........  rijp
n
whereF {q ji , q j2 , .....q jp}

4.B.CONVERSION OF REGULAR EXPRESSION TO FINITE AUTOMATA

 Construct the Finite Automata equivalent to the Regular Expression…

n
[Nov/DEC 2015]

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

rin
Solution :
Given regular expression
r = 01* + 1
It is of the form r = r1 + r2 whereee
gin
r1 = 01*
r2 = 1
The NFA for r2 = 1
En
arn

Now r1 is of the form


Le

r1 = r3 r4
where r3 = 0
w.

r4 = 1*
The NFA for r3 = 0
ww

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

38

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

The NFA for r4 = r5* = 1*

n
g.i
The NFA for r1 – r3r4 = 01*

rin
ee
gin
En

The NFA for r = r1 + r2


arn
Le
w.
ww

39

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

4.C.CONVERSION OF FINITE AUTOMATA TO REGULAR EXPRESSION

Convent the following DFA to a regular expression


Solution :
Find R ijk for i, j, k
Let k = 0
{ a |  (q i , a )  q j
 if i  j 

R ijo   
{ a |  (q i , a )  q j }  {} if i  j 
 
r110   1

n
r120  0

g.i
r210  
r220   0  1

rin
R ijk ,  R ikk 1 (R kkk1 ) * R kkj1  R ijk 1
rijk  rikk 1 (rkkk 1 ) * rkjk 1  rijk 1
For K = 1 ee
gin
(1)
R 11  r110 (r110 ) * r110  r110
= (1) (1) * (1)  (1)
En

= 1* + (1)
= 1*
arn

r12(1)  r110 (r110 ) * r120  r120


= (1) (1) * 0  0
Le

= 1* + 0
= 1*0
w.

r21(1)  r210 (r110 ) * r110  r210


=  (1) * (1)  
ww

= 1*  
=
r22(1)  r210 (r110 ) * r120  r220
=  (1) * (0)  0 1
= 1*  0  0 1
=    0  1
=  0  1
40

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Let K = 2
r11( 2 )  r121 (r22
1 1
) * r21  r111
= 1* 0 ( 0 1) *  1*
=  1*
= 1*
r12( 2 )  r121 (r22
1 1
) * r22  r121
= 1* 0 ( 0 1) * ( 0 1)  1*
= 1* 0 (0  1) * 1* 0

n
= 1* 0 (0  1) *

g.i
r21( 2 )  r22
1 1
(r22 1
) * r21  r21
1

= ( 0 1) ( 0 1) *   

rin
= (0  1) *   
=
r22( 2)  r22
1 1
(r22 1
) * r22  r22
1

ee
= ( 0 1) ( 0 1) * ( 0 1)  ( 0 1)
gin
= (0  1) *  ( 0  1)
= (0  1) *
En

L (M) = r12( 2)
= 1* 0 (0 + 1)*
arn

L (M) = 1* 0 (0 + 1)*
Le

5.MINIMIZATION OF DFA
w.

 Write and Explain the algorithm for minimization of DFA. Using the above
algorithm minimize the DFA. [MAY/JUNE 2016]
ww

 Discuss on the relation between DFA and Minimal DFA. [NOV/DEC 2015]

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Proof :
Any DFA M = (Q, , , q 0 , F) accepting L defines an equivalence relation that is a
refinement of RL
 Thus the number of states of M is greater than or equal to the number of states of
M1
 If equality holds then each of the states of M can be identified with one of the
states of M1
 Let q be a state of M there must be some x in * such that
 (q 0 , x )  q , otherwise q would be removed from Q

n
 Identify q with the state 1 (q 01 , x ) of M1

g.i
 The identification will be consistent.
 If  (q 0 , x )   (q 0 , y)  q, then x and y are in the same equivalence class of RL.

rin
Thus 1 (q 01 , x)  1 (q 01 , y)
A Minimization Algorithm :
ee
 There is a simple method for finding the minimum state DFA M1, equivalent a
given DFA M = ( Q, , , q0, F)
gin
 Let  be the equivalence relation on the states of M.
 If P  q, we say p is equivalent to q.
En

P  q iff for each input string x


 (p, x ) is an accepting state.
arn

 (q, x ) is an accepting state.


 We say that p is distinguishable from q if there exists on x such that
 (p, x ) is an F and
Le

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


w.

Procedure :
 An X is placed in the table each time a of states that cannot be equivalent.
 Initially an X is placed in each entry corresponding to one find state and one non –
ww

final state.
 Next for each pair of states P and q that are not distinguishable, we consider.
r =  (p, a )
s =  (q, a ) for each input symbol a
 If states r and s have been shown to be distinguishable by some string x, then p and
q are distinguishable by string ax.
 Thus if the string (r,s) in the table has an x, an x is placed at the entry (p, q)
42

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Example :
Minimize the following DFA

n
g.i
rin
Solution :
b x
ee
gin
c x x

d x x x
En

e x x x
arn

f x x x x

g x x x x x x
Le

h x x x x x x
w.

a b c d e f g

 Intially an x placed in each entry corresponding to one final state and one final
ww

state.
The entries
(c, a), (c, b), (c, d), (c, e), (c, f), (c, g), (c, h)
 Now the unmarked pairs are
(a, b) (b, d) (d, e) (l, f) (f, g) (g, h)
(a, d) (b, e) (d, f) (e, g) (f, h)
(a, e) (b, f) (d, g) (e, b)
(a, f) (b, g) (d, b)
43

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

(a, h)
(a, b)
 ( a , 0)  b
(b, g) is unmarked
 ( b, 0)  g
 (a ,1)  f
(f, c) is marked, so mark (a, b)
 (b,1)  c

(a, b)
 ( a , 0)  b

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

g.i
rin
(a, l)
 ( a , 0)  b
 (l, 0)  h ee
(b, g) is unmarked
gin
 (a ,1)  f
(f, f) is unmarked
 (l,1)  f
En

(a, f)
 ( a , 0)  b
(b, c) is marked so mark (a, f)
arn

 ( f , 0)  c

(a, g)
Le

 ( a , 0)  b
(b, g) is unmarked
 ( g , 0)  g
w.

 (a ,1)  f
(f, e) is unmarked
 (g,1)  e
ww

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

44

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

n
(b, f)

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

rin
(b, g)
 ( b, 0)  g
 ( g , 0)  g
(g, g) is unmarked
ee
gin
 (b,1)  c
(e, e) is marked. So place an x in (b, g)
 (g,1)  e
En

(b, h)
 ( b, 0)  g
arn

(g, g) is unmarked
 ( h , 0)  g
 (b,1)  c
(c, c) is unmarked.
 (h ,1)  c
Le

(d, e)
w.

 ( d , 0)  c
(c, h) is unmarked. So place x in (d, e)
 ( e, 0 )  h
ww

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

45

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

n
(d, h)

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

rin
(e, f)
 ( e, 0 )  h
 ( f , 0)  c ee
(h, c) is marked. so place x in (e, f)
gin
(e, h)
 ( e, 0 )  h
En

(h, g) is unmarked.
 ( h , 0)  g
 (e,1)  f
(f, c) is marked. So place an x in (e, h)
arn

 (h ,1)  c

(e, g)
Le

 ( e, 0 )  h
(h, g) is unmarked
 ( g , 0)  g
w.

 (e,1)  f
(f, e) is marked. So place x in (e, g)
 (g,1)  e
ww

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

(f, h)

46

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
(a, e)

g.i
 ( a , 0)  b
(b, h) is unmarked
 ( e, 0 )  h

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

(a, g) ee
gin
 ( a , 0)  b
(b, g) is marked. So pace an x in (a, g)
 ( g , 0)  g
En

(b, h)
 ( b, 0)  g
arn

(g, g) is unmarked
 ( h , 0)  g
 (b,1)  c
(c, c) is unmarked.
 (h ,1)  c
Le

(d, f)
w.

 (d, 0)  c
(c, c) is unmarked
 (f , 0)  c
ww

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

Algorithm :
begin

47

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

for p in F and q in Q-F do mark (p, q) for each pair of disfinct states (p, q)in F x F
or (Q – F) x (Q – F) do
if for some input symbol a
( (p, a ),  (q, a ) is marked then begin mark (p, q)
recursively mark all unkarked pairs on the lists of other paurs that are marked at this step.
end.
else
for all input symbols a do
put (p, q) on the list for ( (p, a ),  (q, a ) unless

n
( (p, a )   (q, a )

g.i
end.
Method II

rin
For the above same problem, the DFA can be minimized using DFA minimization
algorithm.
Solution :
Transition table : ee
gin
0 1

a b f
En

b g c
arn

c a c

d c g
Le

e h f
w.

f c g
ww

f c g

g g c

h g c

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

bh

0 1

a b f

[b,h] g c

*c a c

d c g

n
g.i
e h f

f c g

rin
g c g

Step 2 ee
gin
The pair of status (d, f) are same state transition.
d f
En

0 1 0 1

a b f a [b, h] c
arn

[b,h] g c c a c

Le

*c a c [d, c g
f]
[d,f] c g
w.

e [b, h] [d, f]
e h f
ww

g g e
f h f
Step e
g g e The pair of states (a, e) are same state transition diagram.
a  e

0 1

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

49

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

h]

[b, h] g c

c [a, e] c

[d, f] c g

g g [a, e]

n
 Thus the minimized FA is

g.i
rin
ee
gin
En
arn
Le

6.PUMPING LEMMA FOR REGULAR SETS


 State the Pumping Lemma for Regular Languages. Show that L
w.

0 i2

| i is an int eger i 1 is not regular. [Nov / Dec 2015]
ww

 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.
 If languages is regular it is accepted by a DFA M = Q, , , q0, F) with some
particular number of states n.
50

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 Consider an input of n or more symbols a, a2, … am, m  n and for i = 1, 2 … m let


 (q 0 , a , a 2 .... a i )  q i
 It is not possible for each of the n + 1 states q0, q1, …..qn to be distinct, since there
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…. am in the transition diagram of M.

 Since j<k, the string aj + 1 …. ak is of length atleast 1, and since k  n , its length is

n
no more than m.

g.i
 If qm is in F, that is a, a2 … am is in L (M) then a, a2… aj then a, a2 … ajak+1 … am
is also in L (M)

rin
 Since there is a path from q0 to qm that goes through qj but not around the loop.
 (q 0 , a , .... a j a k 1 .... a m )   ( (q 0 , a 1 ... a j ), a n 1 .... a m

ee
=  (q j , a k 1 ... a m )
=  (q k , a k 1 ... a m )
gin
= qm
 Similary we can go around the loop, as many times.
En

 Thus a, .. aj (aj+1 … a)i ak+1 … am is in L (M)


Applications of pumbing lemma :
arn

 The pumping lemma is useful in proving that certain languages are not regular.
1. Select the language L you wish to prove non-regular and assume that L is
regular.
Le

2. The adversary picks n, the constant mentioned in the pumping lemma.


3. Select a string z in L. The choice may depend implicitly on the value of n.
w.

4. The adversary breaks z into u, v and w subject to the constraints that |uv|  n
and |v|  1.
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
w = ak+1 … am

g.i
 The pumping lemma states that if a regular set contains a long string, z, then it
contains infinite set of string of the form uviw.

rin
Problems based on pumping lemma :
1. Show that the language L = a n b n | n 1 is not regular
Solution : ee
(a) Assume that L = a n b n | n 1 is a regular languages.
gin
(b) Let n be the integer, ie) no of states in the pumping lemma.
(c) Take one string z from L
En

Z = aibi such that | z | n


(4) Break z into 3 strings.
arn

z = uvw
z = ai bi
Le

and mak the assumptions that


uv = am
v = aj
w.

w = ai-m bi
= a i bi
ww

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-mbi
= am+j(k-1) bi

52

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

put k = 0
uvkw = ai-j bi  ai bi
put k = 2
uvkw = ai+j bi  ai bi
Since for k = 0, 2, the strings that does not belong to the language L. So the language is
not regular.

2. Show that L 0i | i is an int eger i 1 is not regular.
2

Solution :

1. Assume L = 0i | i is an int eger i 1 is regular.
2

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

g.i
3. Take one string Z
2
Let Z = O n

rin
4. Break z into z = uvw.
uv = O m 2
V = Oj
W = On2 – m2
2

ee
gin
uvw = Om On  m2
2 2

2
= On
En

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


Since both candidates are true, the string uvkw is also in L
arn

uvkw = uvvk-1w.
= Om O j ( k 1) On m2
2 2 2
Le

= Om O j ( k 1) On m2
2 2 2

for k = 0
w.

uvkw = Om O j On  m2
2 2 2

= On  j2  On
2 2
ww

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

53

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

PART-C

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

n
g.i
Inductive Proofs :
 Theorems can be proved by mathematical induction

rin
 Let P(n) be a statement about a non negative integer n
 The Principal of mathematical induction is that P(n) follows from
(a) P (o)
ee
(b) P (n-1) imples P(n) for n 1
gin
 Condition (a) is called the basis and condition (h) is called the inductive step.
Example 1 :
Prove by mathematical induction.
En

n (n 1) (2n 1)


02 + 12 + 22 + …. + n2 =
6
arn

Solution
n (n 1) (2n 1)
Let P (n) = 12 + 22 + 32 + ….. n2 =
6
Le

Basic Step
for n = 0
w.

n
L.H.S.  i2 = 0
i0
ww

n (n 1) (2n 1)


R.H.S. 0
6
Inductive step
for n = n – 1
n  1 2 (n ) (n 1) (2n 11) n n (n 1) (2n 1)
 i = implies  i2 =
i0 6 i0 6
Since

54

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
=
6

g.i
n (2n 2  3n  1)
=
6

rin
n (n  1) (2n  1)
=
6
L.H.S = R.H.S.
ee
 Thus by induction it is true for all n
gin
Example 2 :
Prove by mathematical induction.
n ( n  1)
0 + 1 + 2 + …. + n =
En

2
Solution
arn

n ( n  1)
Let P (n) = 1 + 2+ 3 + n =
2
Basis Step
Le

for n = 0
n
L.H.S.  i=0
w.

i0
n n (n  1)
R.H.S.  i =
ww

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

55

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
=
2

g.i
n (n  1)
=
2

rin
L.H.S. = R.H.S.
Thus by induction it is true for all n.
Example 3 :
ee
Prove if x  4 then 2 x  x 2 by mathematical inducations
gin
Solution
Basic step :
If x = 4 then 2 4  4 2
En

1616
x = 5 then 25  52
arn

32 25
Inductive step
Le

putx = x + 1
 2 x 1  ( x  1) 2
2 x .2  ( x  1) 2
w.

2 x .2  2 x 2  ( x1) 2
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

2.PROBLEM ON NFA TO DFA

 Convert the following NFA to DFA [Nov/Dec 2015]

Example 1:
1. Let M =  q 0 , q1 0,1, , q 0 , q1 be an 
NFA where  (q 0 , 0)  q 0 , q1 )
 (q 0 ,1)  q1 

n
 (q 0 , 0)  

g.i
 (q 0 ,1)  q 0 , q1 )

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

Transition Table : 1
0 1
arn

[q0] [q0, [q1]


q1,]
Le

[q1]  [q0, q1]


w.

[q0, q1] ? ?
ww

  

To find 1 ( [q 0 , q1 ], 0
 q 0 , q1 , 0  =  (q 0 , 0)   (q1 , 0)
= {q 0 , q1 }  
= {q0, q1}
1( [q 0 , q1 ], 0) = [q 0 , q1 ]
57

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

 M1 = (Q1, 1 , 1 , q 01 , F1 )

n
Q1 = { [q0], [q1], [q0, q1],  }

g.i
 {0,1}
q01 = [q0]

rin
F1 = { [q1], [q0, q1] }
1
0
ee
1
gin
[q0] [q0, [q1]
q1,]
En

[q1]  [q0, q1]

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


arn

  
Le

Transition Diagram
w.
ww

58

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i
rin
Examples 2 :
Consider the following NFA
a b
ee
gin
q0 {q0, {q2}
q1}
En

q1 {q1} {q0}

[q2] {q0} {q1, q2}


arn

Construct an equivalent DFA


Solution :
We construct DFA M1
Le

M1 = (Q1, 1 , 1 , q 01 , F1 )
Q1 = { [q0], [q1], [q2], [q0, q1], [q0, q2], [q1, q2], [q0, q1, q2],  }
w.

 {a, b}
ww

q01 = [q0]
F1 = { [q2], [q0, q1], [q1, q2], [q0, q1, q2] }
1
a b

[q0] [q0, [q2]


q1]

59

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

[q1] [q1] [q0]

[q2] [q0] [q1, q2]

[q0, q1] ? ?

[q0, q2] ? ?

[q1, q2] ? ?

n
[q0, q1, q2 ? ?

g.i
]

rin
To find 1 ( [q 0 , q1 ], a
 q 0 , q1 , a  =  (q 0 , a )   (q1 , a )

ee
= {q 0 , q1 }  { q1 }
= {q0, q1}
gin
 ( [q 0 , q 1 ], a ) = [q 0 , q 1 ]
1

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

 q 0 , q1 , b  =  (q 0 , b)   (q1 , b)
= {q 2 }  { q 0 }
arn

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

To find 1 ( [q 0 , q 2 ], a
Le

 q 0 , q 2 , a  =  (q 0 , a )   (q 2 , a )
w.

= {q 0 , q1 }  { q 0 }
= {q0, q1}
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

n
= {q0, q1, q2}

g.i
 ( [q1 , q 2 ], b) = [q 0 , q1 , q 2 ]
1

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

rin
 q 0 , q1 , q 2 , a  =  (q 0 , a )   (q1 , a )   (q 2 , a )
= {q 0 , q1 }  { q1 } {q 0 }
ee
= {q0, q1,}
gin
 ( [q 0 , q1 , q 2 ], a ) = [q 0 , q1 , ]
1

To find 1 ( [q 0 , q1 , q 2 ], b )
En

 q 0 , q1 , q 2 , b  =  (q 0 , b)   (q1 , b)   (q 2 , b)
= { q 2 }  {q 0 }  {q1 , q 2 }
arn

= {q0, q1, q2}


 ( [q 0 , q1 , q 2 ], b) = [q 0 , q1 , q 2 ]
1
Le

a b
w.

q0 [q0, q1] [q2]


ww

q1 [q1] [q0]

[q2] [q0] [q1, q2]

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

61

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

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

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

62

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
PART-A

g.i
1. Define free grammar.

rin
Grammar G is defines as

G= (V,T,P,S) Where

ee
V = Set of variables or not terminals
gin
T = Set of Terminals
P= set of productions of the form A -> α.
En

Where A -> is a variable


α-> string of terminals and non terminals
arn

S = a special variable, called start symbol.

2. What is derivation?
Le

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

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

3. What are the types of derivation?


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
=> id+id*E

g.i
=> id+id*id

rin
Right most derivation:

ee
If at each step of derivation, a production is applied to the right most non
terminal then the derivation is said to be right most derivation.
gin
Example :

E=> E*E
En

=>E*id
arn

=> E+E*id

4. what is CFL?
Le

The language generated by G is L(G)


w.

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

A string is in L(G) if
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

 If an interior vertex is labeled A, and the sons of A are labeled x1, x2, ….xk from
the left then A  x1 x2 … xk must be a production.

 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

n
g.i
 A tree is a derivation tree for G if

(1) Every vertex has a label, which is a symbol of VUTU { }

rin
(2) The label of the root is S

ee
(3) If a vertex is interior and has label then A must be in V
gin
(4) If vertex has label A and sons vertex A are labeled from left as
x1, x2 … xk then A x1, x 2 ...x k must be a production in p.
En

(5) If a vertex has a label  , then it leaf and is the only son of its
father.
arn

6.What is an ambiguous grammar?

A context free grammar is said to be ambiguous if any word has more than one
Le

parse tree or more than one left most derivation or more than one right most derivation is
said to be an ambiguous grammar.
w.

7.What is an useless symbol?


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

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

g.i
Solution :
We find that ε is in L(G), so we cannot eliminate S-> t and A is nullable. So the

rin
resultant grammar
S-> as|b|E
11.What is unit production? ee
gin
The productions of the form A-> B is called as unit productions.
En

12.Eliminate the unit productions from the grammar

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


arn

Solution
By eliminating the unit productions the resultant grammar is
Le

S-> a
13.What is Chomsky normal form?
w.

A->BC A->a
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

g.i
 When is a grammar said to be ambiguous?Explain with the help of an

rin
example. [May/June 2016]

Grammar Introduction :

ee
 Grammar is denoted as G. which is defined as.
G = (V, T, P, S)
gin
where,
V = set of variables or Non-Terminals.
T = set of Terminals (V and T are disjoint V  T  
En

P = finite set of productions each production is of the form A  


where A is a variable.
arn

 is a string of symbols from (VUT)*


S = is a special variable called the start symbol.
Le

Example :
G = ({E}, {+, *, (,), id} p, E_
where p consists of E  E  E
w.

E  E*E
E  (E)
ww

E id
Notations used in the Grammar.
1. The capital letters denote variables, S is the start symbol, unless otherwise stated.
2. The lower case letters a, b, c, d, e digits and boldface string are terminals.
3. The capital letters x, y and z denote symbols that may be either terminals or
variables.
4. The lower – case letter u, v, w, x, y and z denote strings of terminals.

67

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
4) Type 3 Grammar

g.i
Type 0 Grammar :
 It is understricted Grammar or phase structure grammar.

rin
 A grammar without any restriction.
 The productions are of the form.
Type 1 Grammar :
ee
 It is contest sensitive grammar or context dependent grammar.
gin
 A production of the form.
  is called type 1 production if  
 It is accepted by linear bounded arutomata
En

Type 2 Grammar :
 It is context free grammar.
arn

 A production of the form A  


where AV, and (VUT ) *
 Left hand side has no left context or right context.
Le

 It is accepted by push down automata.


Type 3 Grammar :
w.

 It is regular grammar.
 A production of the form A  a or A  ab, where A, B,  v and a  
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.
 Example
E  E  E | E * E | (E) | id
Deriving a string id + id * using left most derivation.
EEE
lm
 id  E
lm

n
 id  E * E

g.i
lm
 id  id * E
lm

rin
 id  id * id
lm
Right most derivation :
ee
 If at each step in a derivation is applied to the light most variable is said to be right
gin
most derivation.
 Example
E  E  E | E * E | (E) | id
En

 Deriving a string id + id * using left most derivation.


lm
 E EE
arn

 lm
 id  E
Le

lm
  id  E * E
w.

 lm
 id  id * E
lm
ww

  id  id * id
Context free languages (CFL)
 The language generated by G, L (G) is
*
L(G) {w | w is in T * and S  w}
G
 That is,
a string is in L (G) if

69

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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 
 If an interior vertex is labeled A, and the sons of A are labeled x1, x2, ….xk from

n
the left then A  x1 x2 … xk must be a production.

g.i
 The derivation tree.
 If we lead the leaves from left to light, we get the string (id + id) * id.

rin
 More formally Let G (V, T, P, S) be a CFG
 A tree is a derivation tree for G if
(1) Every vertex has a label, which is a symbol of VUTU { }
ee
(2) The label of the root is S
gin
(3) If a vertex is interior and has label then A must be in V
(4) If vertex has label A and sons vertex A are labeled from left as x1, x2 … xk
then A x1, x 2 ...x k must be a production in p.
En

(5) If a vertex has a label  , then it leaf and is the only son of its father.
Ambiguity :
arn

 A context free grammar G such that some word has two parse trees is said to be
ambiguous.
 An equivalent definition of ambiguity is that some word has more than one left
Le

most derivation or more than one right most derivation.


 Example :
w.

Show that the Grammar G


E  E  E | E * E | (E) | id is ambiguous.
ww

Solution :
 Deriving a string id + id * id

70

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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

n
 id  id * E  id  id * E

g.i
lm lm

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

rin
lm lm

Parse tree 1
E ee parse tree 2
E
gin
E + E E * E

id E * E E + E id
En

id id
id id
arn

 For the word id + id * id has two parse trees


 So the grammar is ambiguous.
Le

2.THE RELATIONSHIP BETWEEN DERIVATION AND DERIVATION TREES


w.

 Let G=(V,T,P,S) be a CFG, Then prove that the terminal string W is in the
Language of variable A then there is a Parse Tree with root A and yield α.
ww

[Nov/Dec 2015]

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

71

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
derivation tree.

g.i
Induction :
 Assume that the result ais tree for k-1 interior vertices.

rin
 Suppose that  is the yield of an A-tree with k interior vertices for k>1
 The son‟s of the node A could not all be leaves.

ee
 Let the labels of the sons be x1, x2 … xn in order from the left.
 Then A  x1, x2 …. xn is a production in P.
gin
 If the ith son is not a leaf it is the root of the subtree, and xi must be a variable.
 The portion of  delivered from xi must lie to the left of the symbols delivered
from xj.
En

 Thus we can write  as 1  2 ...  n , where for each I between 1 and n.


1) 1  x i if x i is a ter min al
arn

2) x1   i if x i is a var iable
Case 1 :
Le

(xi is a terminal)
 If  i  x i then x 1 is a terminal such that the derivation tree is.
w.

x1 x2 xn
ww

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

72

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

Simplification of CFG:
 There are several ways to restrict the format of productions without reducing the
generative power of context – free grammar.
 If L is a non empty context free language, then it can be generated by a context
free grammar G with the following properties.

n
 Each variable and each terminal of G appears in the derivation of some word in L.

g.i
 There are no productions of the form A  B , where A and B are variable.
 If  - is not in L, there need be no productions of the form A  E

rin
 If E is not in L, every production be of one of the forms A  BC and A  O
 Also we can make every productions of the form A  a , where  is a string.

ee
There are two special forms of CFG
1. Chomsky Normal form.
gin
2. Greibach Normal form.
Elemination of Useless symbols :
 The useless symbols can be eliminated from a grammar.
En

 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,
arn

where w is in T*
 Otherwise x is useless
Le

 There are two aspects of usefulness


1. Some terminal string must be derivation from x
w.

2. x must occur in some string derivation from s


Lemma 1 :
ww

Given a CFG, G = (V, T, P, S) with L (G) =  we can find an equivalent CFG G1.
G1 = (V1, T, P1, S) such that for each A in V1, there is some w in T* for which
*
A w
Lemma 2:
Given a CFG G = (V, T, P, S), we can find an equivalent Grammar G1 = (V1, T1,
P1, S) such that for each x in V1 U T1there exist  and  in (V1 U T1)* for which
*
S   x
73

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
g.i
Elemination of E-Productions :
 The productions of the form A  E is called E-production
 If E-is in L(G). we cannot eliminate all E-productions from G.

rin
 If E-is not in L(G), we can eliminate the E-productions from G.
 The method is to determine for each variable A, whether
*
 A ee
E, if so it is called as A-nullable
gin
 We may replace each production B x1, x 2 , ... x i ... x n by all productions striking out
some subsets of those x1‟s that are nullable. but we do not include B  E, even if
all xi,s are nullable.
En

Example :
Consider the grammar
arn

S  as | bA |
A 
Eliminate the E-productions.
Le

Solution :
we find that E-is in L(G), so we eliminate S and A-is nullable
w.

so the resultant Grammar


S  as | b |
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
4.CHOMSKY NORMAL FORM
 Construct a equivalent Grammar G in CNF for the Grammar. Also discuss

rin
the procedure to convert the Grammar into CNF. [Nov/Dec 2015]

 Construct the following Grammar in CNF

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

Chomsky normal form (CNF)


 In Chomsky normal form, the productions are of the form
arn

AB
Aa
where A, B, C are variable, a is a term.
Le

Theorem :
 Any context free language without E is generated by a Grammar in which the
w.

productions are of the form A  BC or A  a . Here A, B and C are variable and a


is a terminal.
ww

Proof :
 Let G be a CFG, generating a language not containing E.
 We can find an equivalent grammar G1 = (V, T, P, S) such that p contains no unit
productions or E-productions.
 Thus if a productions has a single symbol on the right, that symbol is a terminal
then the production is an acceptable form.
 If production is of the form A  x1, x2 …. xm where m  2

75

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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


replace xi by ca
 Let the new set of variables be V1 and the few set of productions be P1 consider
G2 (V1, T, P1, S)
 We modify G2 by adding some additional symbols to V1 and replacing some
productions of P1
 For each production
A  B1 B2 ..... Bm of P where m  3 we create a new variables D1, D2, …. Dm-2 and
1

replace A B1 B2 ...... Bm by the set of productions.

n
A B1 D1 , D1 B2 D 2 , .. D 2 B3 D3 , ....

g.i
D m  3 Bm  2 D m  2 , D m  2 Bm 1 Bm
 Let V” be the now set of non-terminals and P” be the new set of productions

rin
G3 = (V”, T, P”, S) is in CNF
Examble :
S  bA | ab
A  bAA | as | a
ee
gin
B  aBB | bs | b
Find an equivalent grammar in CNF
En

Solution :
(1) S  bA is replaced by
S Cb A
arn

Cb  b
(2) S  aB is replaced by
Le

S Ca B
Ca  a
w.

(3) A  bAA is replaced by


A Cb AA
ww

Cb  b
A c b AA is replaced by
A Cb D1
D1 AA
(4) A  aS is replaced by
A Ca S
Ca  a
76

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

(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

n
Cb  b

g.i
(9) B  b is in proper form

rin
Resultant grammar :
1. S Cb A |Ca B
A Cb D1 |Ca S | a
B C b S |Ca D 2 | b ee
gin
D1  AA
D2  BB
Ca  a
En

Cb  b
arn

PART-C
Le

1.GREIBACH NORMAL FORM


w.

 Construct the CNF and GNF for the Grammar.Also Discuss the procedure to
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Let A 1 B 2 be a production in p and B B1 |B2 | ... |Br be the set of all B-
productions
 Let G1 = (V, T, P, S) be obtained from G by deleting the production
A 1 B 2 from p and adding the productions
A 1 B1  2 |1 B2  2 |1 B3  2 | ... |1 Br  2
Then L (G) = L (G1)
Lemma 2:
 Let G = (V, T, P, S) be a CFG
Let A  A1 | A 2 | .... | A r be the set of A-Productions for which A is the left most

n
symbol of RHS

g.i
 Let A B1  B2 | ... |Bs be the remaining A-Productions.
 Let G1 = (VU {B}, T, P, S) be the GFG formed by adding the variable B to V and

rin
replacing all the A-productions by the productions
A Bi 
1) i  i  s
A Bi B
B i 
ee
gin
2) i  i  r
B i B
En

Theorem :
Every context free language without ε- can be generated by a grammar for which
arn

every production is the form A  a , where A is a variable a is and  is a string of


variables.
Proof :
Le

 Let G = (V, T, P, S) be a CFG in CNF generating the CFL L.


 Assume V = {A1, A2, … Am}
w.

 The first step in the construction is to modify the productions so th


 at if
ww

A i A j  is a production, then j>i


 Starting with A1 and proceeding to Am we do this as follows
 We now modify the Ak productions
 If A k 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
A k A   l  k according to Lemma 2 introducting a new variable Bk

78

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 By repeating the above process for each variable, we have only the productions of
the form.
1) A i A j  j  i
2) Ai  a a in T
3) Bi    in (VU {B1 , B2 , ...Bi 1 ) *
 RHS of any production for Am must be a terminal since Am is the highest
numbered variable
 The left most symbol on the RHS of any production for A m-1 must be Am-1 or a
terminal symbol.

n
 At the last step examine the productions for the new variables B1, B2, … Bm

g.i
 No Bi-productions can start with another Bj therefore all Bi-productions have RHS
beginning with terminals or Ai‟s

rin
Example :
Convert into GNF from the Grammar
G = ({A1, A2, A3}, {a, b}, P, A1)
where P consist of ee
gin
A1A 2 A 3
A 2 A 3 A1| b
A 3 A1A 2 | a
En

Solution :
Step 1 :
arn

Since RHS of the productions for A1 and A2 start with terminal or higher
numbered variables we begin with the productions.
A 3 A1A 2
Le

A 3 A 2 A 3| A 2
A 3 A 3 A1A 3 A 2 | bA3 A 2 (A 2 A 3 A1| b)
w.

 The new resultant set of productions


A1A 2 A 3
ww

A 2 A 3 A1| | b
A 3 A 3 A1A 3 A 2 | bA3 A 2 | a
 We now apply lemma 2 to the productions
A 3 A 3 A1A 3 A 2 | bA3 A 2 | a
symbol B3 is introduced and the production A3 A3 A1A3A 2 is replaced by

79

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

A 3  bA 3 A 2 | a
A 3  bA 3 A 2| B3 | aB3
B3 A1A 3 A 2
B2 A1A 3 A 2 B3
 The resultant set of production
A1A 2 A 3
A 2 A 3 A1| b
A 3  bA3 A 2 B3
B3 A1A 3 A 2 B3

n
 Now all the productions with A3 on the RHS that start with terminals.

g.i
 These are used to replace A3 in the productions A 2 A 3 A1 and then the
productions with A2 on the left are used to replace A2 in the production A1A 2 A 3

rin
 The new set of productions
A 3  bA3A2B3|aB3|bA3A2|a
ee
A 2  bA3A2B3A1|aB3A1|bA3A2A1|aA1|b
gin
A1 bA3A2B3A1A3|aB3A1A3|bA3A2A1|aA1A3|aA1A3|bA3
B3  bA3A2B3A1A3A3A2|aB3A1A3A3A2|bA3A2A1A3A3A2|
En

aA1A3A3A2|aA1A3A3A2|bA3A3A2
B3  bA3A2B3A1A3A3A2B3|aB3A1A3A3A2B3|bA3A2A1A3A3A2B3|
aA1A3A3A2B3|aA1A3A3A2B3|bA3A3A2B3
arn
Le
w.
ww

80

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
The stack holds a string of symbols from some alphabet

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

rin
Formal Definition :
 A push Down Automata M is a system
M = (Q, , , , q 0 , Zo , F)
Where ee
gin
Q  is a finite set of states
  is an alphabet called the input alphabet
  is an alphabet called the stack alphabet
En

q0 
in Q is the initial state
Z0  
arn

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
Le

Q x *
w.

2. Define the moves of PDA.


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

 An input symbol is used. Depending on the input symbol, the top symbol
on the stack and the state of a finite control, a number of choice are
possible.
 Each choice consists of next state for the finite control and a string of
symbols to replace the top tack symbol.
 After selecting a choice, the input head is advanced one symbol.
(q, a, z) {( p1 , , ), (p 2 , 2 ),...( p m , m )}

81

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

where
q and p1 l  i  m are states
a is in 
Z 
is a stack symbol
1  is in *
i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any
i enter state p1, replace symbol z by string  i and advance the input head one symbol.
 The second type of move called an  is similar to the first, except that the input

n
symbol is not used and the input head is not advanced after the move

g.i
(q,, z)  {( p1, , ), (p2 , 2 ),...( pm , i )}
ie) The PDA in state q, independent of the input symbol being scanned and with z, the

rin
top symbol on stack, can enter state pi, for any I and replace z by  i . The input head is
not advanced.

ee
3.What is instantaneous description of PDA(ID)?
ID of PDA:
gin
 The ID records the state , input and stack contents
 ID is defined as a triple
(q,w,U)
En

Where q-> is a state in the finite control


W -> is a string of input
arn

U-> is a string of stack symbols.


4.Define the language accepted by PDA
The language is accepted by PDA in two ways.
Le

1. Language accepted by empty stack.


2. Language accepted by final state.
w.

Language accepted by empty stack:


To define the language accepted to be the set of all inputs for which some sequence of
ww

move causes the PDA to empty its stack.


N(M = {w|q0,w,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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

I)for each q in Q and Z in , whenever δ(q,E,Z) is non empty then δ(q,a,Z) is empty for all
a in Σ.
ii) for no q in Q Z in and a in ΣU{e} does δ(q,a,z) contain more than one element.
6.State the pumping lemma for CFL.
Let L be any CFL . then there is a constant n, depending on L, such that
|z| >= n , then we may write
Z = uvwxy such that
i) |vx| >=1
ii) |vwx|<= n

n
iii) For all i>=0 u v iw x i y is in L

g.i
7.What are the closure properties of (FL’s)?
CFL‟s are closed under

rin
1. Union
2. Concatenation
3. Kleen Closure
4. Substitution
5. Homomorphism
ee
gin
6. Inverse homorphism
8.What is context free language derived from the following grammar?
En

S->a S b
S-> ab
Solution
arn

S=> aSb=> aabb


S=>aSb=>aaSbb=> aaa Sbbb
Le

………………=> a n-1 S b n-1


=>an bn
w.

L = { an bn |n>=1}
9.Construct CFG to derive the grammar L ={ an bn |n>=1}
Solution :
ww

S-<ab
S->a S b

83

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
 The stack holds a string of symbols from some alphabet

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

rin
Formal Definition :

ee
 A push Down Automata M is a system
gin
M = (Q, , , , q 0 , Zo , F)
En

Where

Q  is a finite set of states


arn

  is an alphabet called the input alphabet


Le

  is an alphabet called the stack alphabet


w.

q 0  in Q is the initial state


ww

Z 0  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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
symbols to replace the top tack symbol.
 After selecting a choice, the input head is advanced one symbol.

rin
(q, a, z) {( p1 , , ), (p 2 , 2 ),...( p m , m )}

where
ee
gin
q and p1 l  i  m are states

a is in 
En

Z  is a stack symbol
arn

1  is in *
Le

i.e) The PDA in state q with the input symbol a and z top symbol on the stack can for any
w.

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

 The second type of move called an  is similar to the first, except that the input
symbol is not used and the input head is not advanced after the move

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

85

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
(q,w,  i )

g.i
Where q  is a state in the finite control

rin
w  is a string of input

ee
  is a string of stack symbols.
gin
 If M  (Q, , , , q 0 , z 0 , f ) is a PDA we say
En

(q,aw,z  )  (p, w, , )
arn

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

Language accepted by PDA


Le

1. Language accepted by empty stack


w.

 To define the language accepted to be the set of all inputs for which some
ww

sequence of moves causes the PDA to empty its stack.

 For PDA M  (Q, , , , q 0 , z 0 , f ) , we define N(M), the language accepted by


empty stack to be
N(M)  {W1 (q 0 , w , z 0 ) , (P, ,), for some in Q}

2. Language accepted by final state:

86

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 To define the language accepted to be the set of all inputs for which some
choices of moves causes the PDA to enter a final state.

 We define L(M), the language accepted by PDA M by final state to be


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

 If a set of can be accepted by empty stack by some PDA, it can be accepted by


final state by some other PDA and vice versa.

n
g.i
Deterministic push down Automata :

 The PDA is deterministic, if atmost one move is possible from any ID.

rin
 The PDA M = (Q, , , , q 0 , z 0 , F) is deterministic if

ee
1) For each q in Q and z in  , whenever  (q,, z) is non empty then  (q, a, z)
is empty for all a in  .
gin
2) For no q in Q,Z in  and a in  U{}does  (q, a, z) contain more than one
element.
En

 The deterministic and non- deterministic models of PDA, are not equivalent with
arn

respect to the language accepted.


 wwR is accepted by Non-deterministic PDA but not by any Deterministic PDA
Design a PDA accepting L = {wcwR | win (0+1)*} by empty stack
Le

 Solution
w.

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


ww

 Transition Diagram:

87

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i

rin
 where  is defined as

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


ee
gin
 2)  (q1 , O, B) {( q1 , BB)}

 3)  (q1 , O, G) {( q1 , BG )}
En

 4)  (q1 , C , R) {( q2 , R)}


arn

 5)  (q1 , C , B) {( q2 , B)}

 6)  (q1 , C , G) {( q2 , G)}


Le

 7)  (q1 ,1, R) {( q1 , GR )}


w.

 8)  (q1 ,1, B) {( q1 , GB )}


ww

 9)  (q1 ,1, G) {( q1 , GG )}

 10)  (q2 , O, B) {( q2 ,)}

 11)  (q 2 ,, R ) {( q 2 ,)}

 12)  (q 2 ,1, G) {( q 2 ,)}

 Let x = O1C1O
88

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

  (q 2 ,1O, GBR )  (q 2 , O, BR )  (q 2 ,, R )

  (q 2 ,,)

 x = O1C1O is accepted by PDA

n
2.EQUIVALENCE OF PUSHDOWN AUTOMATA AND CFL

g.i
 Prove that “if a Language is accepted by empty stack, by some PDA, it can be

rin
accepted by final stat by some other PDA and Vice versa”

Equivalence of acceptance by final state and empty stack


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

Theorem 1 :
En

 If L is L(M2) for some PDA M2, then L is N(M1) for some PDA M1.
arn

Proof :

 We prove M1 to simulate M2 with the option for


Le

 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 M2
w.

empties its stack without entering a final state


 Let M2 = (Q, , , , q 0 , z 0 , F) be a PDA such that L = L (M2)
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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


1 (q,, z 0 )  (q e ,)
4) For all z in U{x 0 }
1 (q e ,, z)  (q e ,)
 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

n
 Let x be in L(M2), then

g.i
(q0, x,z0)  (q,, ) for some q in F
 Now consider M1 with input x By rule (1)

rin
(q01, x,x0)  (q 0 , x , z 0 , x 0 )

By rule (2) every move of M2 is a legal move for M1 thus.

(q0,x,z0)  (q,, ) ee
gin
By rule (3) and (4)

(q, , , x 0 )  (q e ,,)
En

That is
arn

(q01, x,x0)  (q 0 , x , z 0 , x 0 )  (q,, , x 0 )  (q e ,,)


M1 accepts x by empty stack
Le

L(M2) = N(M1)

Theorem 2:
w.

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

Proof :

 We prove M2 to simulate M1
 M2 enters a final state when and only when M1 empties its stack
 Let M1 = (Q, , , , q 0 , z 0 , ) be a PDA such that L = N(M1)
 Let M2 = (QU{q01, qf},  , U {x0}, 1 , q 01 , x 0 ,{q f })

Where ' is defined as follows


90

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

1) 1 (q 01 ,, x 0 ) {q 0 , z 0 , x 0 )}


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 )  (q f ,)
 Rule(1) causes M2 to enter the initial ID of M1
 Rule(2) allows M2 to simulate M1
 Rule(3) causes M2, when X0 appears to enter a final state, thereby accepting the

n
input x

g.i
 Let x be in N(M1)
(q 0 , x, z 0 )  (q,,)

rin
 Now, consider M2 with input x
(q 0 , x, x 0 )  (q 0 , x, z 0 )
1

ee
(q 0 , x, x 0 )  (q,, x 0 )
(q,, x 0 )  (q f ,,)
gin
 Thus
LM 2   NM1 
En
arn

3.EQUIVALENCE OF CFL AND PDA

 Prove that “If L is a context free Language, then there exists a PDA M, such
Le

that L = N(M)” and “If L is n(m) for some PDA M, then L is a context free
language”.
w.

Theorem 3:
ww

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

Proof:

Let 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Where

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

Whenever A a is in p

 The PDA M simulates left most derivations of G is in GNF each sentential form in
a left most derivation consist of a string of terminals x followed by a string of
variables 
 M stores the suffix  on the left sentential form on its stack after processing the

n
prefix x.

g.i
Theorem 4:

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

Proof :

ee
Let M = ( Q, , , , q 0 , z 0 , ) be the PDA such that L = N(M)
gin
Let G = (V,T,P,S) be a CFG

Where
En

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

new symbol S.

T= 
Le

P  is the set of productions.

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


w.

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

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

rin
| z |  n then we may write

z = uvwxy such that

1) | Vx |  1
ee
gin
2) | Vwx |  n
3) for all I  uvisxiy is in L
En

Proof :

 Let G be a CFG in CNF generating L {  }


arn

 If Z is in L(G) and Z is long, then any parse tree for z must contain a long path
 We prove this by mathematical induction on i, that path of length for z.

Le

If the word generated by a CNF grammar has no path of length greater than I, then
the word length is no greater than 2i-1
w.

Basis :
ww

i = l is trivial

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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


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

n
 But such a path has k + 2 vertices, and all except last vertex are labeled by

g.i
variables.
 Thus there must be some variables that appears twice on the path.

rin
 Some variables must appear twice near the bottom of the path.
 Then there must be two variables V1 and V2 on the path satisfying the following
conditions.
ee
1. The vertices V1 and V2both have the same label say A
2. Vertex V1 is closer to the root than vertex V2
gin
3. The portion of the path from V1 to the leaf is of length atmost k + 1
 Now the subtree T1 and T2 is the subtree generated by vertex V2 and Let Z2 is the
En

yield of subtree T2
Then we can write
arn

Z1 = Z 3 Z2 Z4

 Z3 and Z4 cannot both be  . Since the production used in the derivation of z1 must
Le

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

subtree generated by C.
 Example :
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Example :

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

Solution :

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

Let n  be the constant of Lemma 1.

consider Z = anbnc n

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

g.i
u = am

rin
vwx = an-m bm , w = aj a j

Verify
y = bn-m cn
ee
gin
uvwxy = am an-m bm bn-m cn
En

= n
a bn cn

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


arn

For I = o

uviwxiy = am aj bj bn-m cn
Le

= am+j bn-m jcn # L


w.

For i = 2
ww

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

= a2n-m-j,bm+n-jjcn # L

For i = 0 and i = 2 uviwxiy is not in L so given L = {aib ic i | i  1} is a CFL

PART-C

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

95

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

[May/June 2016]

Solution

Transition Diagram

n
g.i
rin
PDA M is defined as, ee
gin
1)  (q1 , O, R) {( q1 , BR)}
2)  (q1 ,1, R) {( q1 , GR )}
En

3)  (q1 , O, B) {( q1 , BB)} ,(q2,  )}


4)  (q1 , O, G) {( q1 , BG )}
arn

5)  (q1 ,1, B) {( q1 , GB )}


6)  (q1 ,1, G) {( q1 , GG )}( q 2 ,)}
7)  (q2 , O, B) {( q2 ,)}
Le

8)  (q 2 ,1, G) {( q 2 ,)}


w.

9)  (q1 ,, R ) {( q 2 ,)}


10)  (q 2 ,, R ) {( q 2 ,)}
ww

M  ({q1 , q 2 , }, {0,1}, {R, B, G}, ,91 , R , )

Let x=0110

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

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

96

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 (q1 , O, GGBR )  (q 2 ,, R )

 (q1 , O, BGGBR )  (q 2 ,,)

 (q1 ,, BBGGBR )

x = 0110 is accepted by PDA

4) Convert the Grammar

S OSI| A

n
g.i
A IAO| S | E

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

rin
Solution

The Given grammar


ee
gin
G=(V,T,P,S)

Where V = {S,A}
En

T = {0,1}

To construct a PDA M = Q, , , , q 0 , z 0 , )
arn

Where
Le

Q = {P1,q2}

  T {0,1}
w.

 {v}U{z 0 }
ww

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

where  is defined as,

1) (q1 ,, z 0 )  q 2 , S)

For each production

97

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

2)  (q 2 ,, s)  (q 2 , OSI )
3)  (q 2 ,, s)  (q 2 , A)
4)  (q 2 ,, A)  (q 2 , S)
5)  (q 2 ,, A)  (q 2 , IAO)
6)  (q 2 ,, A)  (q 2 ,)

For each terminal

7)  (q 2 , o, O)  (q 2 ,)

n
8)  (q 2 ,1,1)  (q 2 ,)

g.i
9)  (q 2 , o,1)  (q 2 ,)
10)  (q 2 ,1,0)  (q 2 ,)

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

Solution:
ee
gin
Transition Diagram:
En
arn
Le

Transition function 
w.

1) (q 0 , o, z 0 )  (q 0 , Oz 0 )
2) (q 0 , o, o)  (q 0 , oo)
ww

3) (q 0 ,1, o)  (q1 ,)


4) (q1 ,1, o)  (q1 ,)
5) (q1 ,, z 0 )  (q 2 ,)

The PDA is defined as

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

98

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Q = {q0,q1,q2}

 {0,1)

  {0;1, z 0}

F = {q2}

Let us consider the string w = 0011

(q 0 ,0011; z 0 )  (q 0 ,011; oz 0 )  (q 1 ,1;0z 0 )  (q 1 ,; z 0 )  (q 2 ,)

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

rin
2. CONVERSION OF PDA TO CFL
 Convert the given PDA to CFG.
ee [Nov/Dec 2015]
gin
Given PDA

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

where  is given by

 (q 0 , o, z 0 )  (q 0 , xz 0 )
arn

 (q 0 , o, x )  (q 0 , xx )
Le

 (q 0 ,1, x )  (q1 ,)


w.

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

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


ww

(q1 ,, z 0 )  (q1 ,)

Construct a CFG G, generating N(M)

Solution :

V {s, [q 0 , x, q 0 ] , [q 0 , x, q1 ] , [q1 , x, q 0 ], [q1 , x, q1 ][q 0 , z 0 , q 0 ][q 0 , z 0 , q1 ][q1 , z 0 , q 0 ][q1 , z 0 , q1 ]}

99

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

T = {0,1}

The productions for s are

S  [q 0 , z 0 , q 0 ] (from rule 1)

S [q 0 , z 0 , q1 ]

The Productions for each transition functions of M.

1)  (q 0 , o, z 0 )  (q 0 , x, z 0 )

n
g.i
The Productions are

[q 0 , z 0 , q 0 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

rin
[q 0 , z 0 , q 0 ]  o [q 0 , x, q1 ][q1 , z 0 , q 0 ]

ee
[q 0 , z 0 , q1 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q1 ]
gin
[q 0 , z 0 , q1 ]  o [q 0 , x, q1 ][q1 , z 0 , q1 ]

2) There is a move  (q 0 , o, x )  {( q 0 , xx )}
En

The productions are


arn

[q 0 , x, q 0 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

[q 0 , x, q 0 ]  o [q 0 , x, q1 ][q1 , x, q 0 ]
Le

[q 0 , x, q1 ]  o [q 0 , x, q 0 ][q 0 , x, q1 ]
w.

[q 0 , x, q1 ]  o [q 0 , x, q1 ][q1 , x, q1 ]
ww

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

The production is

[q 0 , x, q1 ] 1

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

The production is
100

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

[q1 , x, q1 ] 1

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

The production is

[q1 , x, q1 ] 

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

The production is

n
g.i
[q 0 , x, q1 ] 1

 There are no production for the variable [q1 , x, q 0 ] and [q1 , z 0 , q 0 ]

rin
 As all the productions for [q 0 , x, q 0 ] and [q 0 , z 0 , q 0 ] have [q1 , x, q 0 ] or [q1 , z 0 , q 0 ] on the
right, no string of terminals can be derived from [q 0 , x, q 0 ] or [q 0 , z 0 , q 0 ]
ee
 Deleting all production involving one of these variables on either the right or left, we
gin
end up with the following productions.

S [q 0 , z 0 , q1 ]
En

[q 0 , z 0 , q1 ]  o [q 0 , x, q1 ][q1 , z 0 , q1 ]
arn

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

[q 0 , x, q1 ] 1
Le

[q1 , z0 , q1 ] 
w.

[q1 , x, q1 ] 

[q1 , x, q1 ] 1
ww

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


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

 (q 0 ,1, z 0 ) {( q 0 , xz 0 )}

 (q 0 ,1, x ) {( q 0 , xx )}

101

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 (q 0 ,0, x ) {( q1 , x )}

 (q 0 ,, z 0 ) {( q 0 ,)}

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

 (q1 ,0, z 0 ) {( q 0 , z 0 )}

V {S1 , [q 0 , z 0 , q 0 ] , [q 0 , z 0 , q1 ] , [q1 , z 0 , q 0 ], [q1 , z 0 , q1 ][q 0 , x, q 0 ][q 0 , x, q1 ][q1 , x, q 0 ][q1 , x, q1 ]}

n
T = {0,1}

g.i
P = set of productions

S  [q 0 , z 0 , q 0 ]

rin
S [q 0 , z 0 , q1 ]

1)  (q 0 ,1, z 0 ) {( q 0 , xz 0 )} ee
gin
[q 0 , z 0 , q 0 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

[q 0 , z 0 , q 0 ] 1 [q 0 , x, q1 ][q1 , z 0 , q 0 ]
En

[q 0 , z 0 , q1 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q1 ]
arn

[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]
Le

2)  (q 0 ,1, x )  {( q 0 , xx )}

[q 0 , x, q 0 ] 1 [q 0 , x, q 0 ][q 0 , x, q 0 ]
w.

[q 0 , x, q 0 ] 1 [q 0 , x, q1 ][q1 , x, q 0 ]
ww

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

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

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

[q 0 , x, q 0 ]  0 [q1 , x, q 0 ]

102

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

[q 0 , x , q1 ]  0 [q1 , x , q1 ]

4)  (q 0 ,, z 0 )  {( q 0 ,)}

[q 0 , z 0 , q 0 ] 

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

[q1 , x, q1 ] 1

6)  (q1 ,0, z 0 )  {( q 0 , z 0 )}

n
g.i
[q1 , z 0 , q 0 ]  0 [q 0 , z 0 , q 0 ]

rin
[q1 , z 0 , q1 ]  0 [q 0 , z 0 , q1 ]

 There are no production for the variable [q1 , x, q 0 ]


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

[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]
arn

[q 0 , z o , q 0 ] 1 [q 0 , x, q1 ][q1 , z o , q 0 ]

[q 0 , x, q1 ] 1 [q 0 , x, q1 ][q1 , x, q1 ]
Le

[q 0 , x , q1 ]  0 [q1 , x, q1 ]
w.

[q1 , z 0 , q 0 ] 
ww

[q1 , x, q1 ] 1

[q1 , z o , q 0 ]  0 [q 0 , z o , q 0 ]

[q1 , z o , q1 ]  0 [q 0 , z o , q1 ]

103

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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?

n
The basic modes of a TM has

g.i
a) A finite control
b) An infinite tape

rin
c) A tape head

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

ee
*each cell of the tape holds exactly one symbol.
gin
*The tape head moves in both direction.

a1 a2 ….. a1 … an B B ….
En
arn

Finite
Control
Le
w.

2. What is the formal definition of turing machine?

 Formally, a Turing Machine is donoted


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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.

n
Where q-> is the current state of M

g.i
α 1 , α 2-> is the string in

rin
4. Define moves of a Turing machine.

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


gin
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


En

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


arn

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 accepted by Turing Machine?


Le

The Language accepted by TM:


w.

 The language accepted by M, denoted L (M) is the set of words in  x that cause M
to enter a final state.
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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?

n
Techniques for TM construction:

g.i
1. Storage in the finite control
2. Multiple tracks

rin
3. Checking off symbols
4. Shifting over
5. Subrartines
ee
gin
8.What is multi head and multi tape turing machines?

A multi tape turing machine consists of a finite control with k tape heads and k tapes.
En

Each types is infinite in both directions.

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

machine.

1. Changes state
Le

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

9.What is regular grammar?


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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)

n
The productions are of the form

g.i
α -> β

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

*These grammar derives recursive and recursing enumerable languages these languages
are accepted by Turing Machines. ee
gin
11. What is context sensitive language?

*If the restriction on the production


En

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


arn

*These grammars are type 1 grammar.

*These grammar derives context sensitive language context sensitive language are
Le

accepted by Linear Bounded Automata.

12.Define Linear Bounded Automata.


w.

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


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
the turn instances T and F(T) are the same.

g.i
15.What are the features of Turing Machine?

rin
 It has external memory
 It has unlimited memory capacity


ee
Tape head can be read the input at both sides
It produces certain output based on its input.
gin
16.What are the applications of Turing Machines?

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


En

 Turing machine is used for solving computational , recursive and non recursive
arn

enumerable problems.

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


Le
w.
ww

108

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
Finite

g.i
1. a finite control Control
2. an infinite tape
3. a tape head

rin
 An input tape is divided into cells. The tape has a left most cell but it is infinite to the
right.

ee
 Each cell of the tape may hold exactly one of a finite numbers of tape symbols.
 Initially the n left most cells for n ≥ o hold the input which is string of symbols chosen
gin
from a subset of tape symbols called the input symbols.
 The remaining infinity of cells each hold the blank, which is a special tape symbol
that is not an input symbol.
En

 In one move of the Turing Machine, depending upon the symbol scanned by the tape
head and the state of the finite control
arn

1. Changes state
2. Prints a symbol on the tape cell scanned replacing what was written there
3. Moves its tape head left or right one cell
Le

Formal Definition:
w.

 Formally, a Turing Machine is donoted


M = ( Q, E,  , , qo, B, F )
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
Where

q  is the current state of M

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

Moves of the Turing Machine


ee
 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
gin
suppose  (q1 Xi) = ( P, , L )
En

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


arn

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


Le

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:


w.

 The language accepted by M, denoted L (M) is the set of words in  x that cause M
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Solution

Suppose the input is O m | O n

Finally the TM halts on tape containing Om+n

Suppose w = 00010

0 0 0 1 0

n
g.i
q0

0 0 0 0 B

rin
q1 q1
ee
gin
0 0 0 B B
En

q3
arn
Le

0 1 B

q0 (qo, O, R) (q1, O, R)
w.

q1 (q1, O, R) (q2, B, L)
ww

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

q3 - - -

M = ( Q, , , , q 0 , B, {q 3 }

Q = {q0,q1,q2,q3}
111

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 {0,1)

  {0,1, B}

F = {q3}

Simulating for w = 00010

q0 00010  0q1 0010  00q0 010 

000q010  0000q10  00000q1 B 

n
g.i
0000q2BB0000Bq3

Hence Turing machine performs addition

rin
2.PROGRAMMING TECHNIQUES FOR TURING MACHINE
ee
 Explain the programming techniques for Turing Machine Construction.
[Nov/Dec 2015]
gin
 To describe the complicated TM constructions, some techniques are used,
 The techniques are
En

1. Storage in the finite control


2. Multiple tracks
arn

3. Checking of symbols
4. Shifting over
5. Subroutines
Le

1. Storage in the finite control


 The finite control can be used to hold a finite amount of information.
w.

 The state is written as pair of elements


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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)

n
g.i
 Initially q0 is the control component of the state and M moves right. The
first component of state becomes q1 and the first symbol seen is stored in

rin
the second component.
1) =([q1,0],1,R),
2) =([q1,1],0,R)
ee
 If M has a O stored and sees a 1, or vice versa, then M continues to move to
gin
the right.

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

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

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

 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.
w.

 Thus if M encounters the tape symbol stored in its state. M halts without
ww

accepting.

2. Multiple tracks:

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

B B B B 1 0 1 B B

113

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

B 1 0 0 1 0 1 B B

Finite control

Example:

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

n
Solution:

g.i
 The input is surrounded by C and $ on the first tracks.
 Thus the allowable input symbols are

rin
[ C, B, B]  is identified with C
[O, B, B]  is identified with O

ee
[1, B, B]  is identified with 1
[$, B, B]  is identified with $
gin
[B, B, B]  is identified with B
 To test it its input is prime, the Turing Machine
 Write the number two in binary on the second track.
En

 Copies the first tracks on the third


 The second track is subtracted as many times as possible from the third track, and
arn

leaving the remainders.

 If the remainder is zero, the number on the first track is not a prime.
Le

3. Checking off symbols.


w.

 Checking off symbols is useful for visualizing how a Turing Machine recognizes
languages defined by repeated strings such as
ww

{ w w | w in *}
{w c y | w and y in *, w  y}
{w wR | w in *}
 It is also useful when lengths of substrings must be compared, such as in the
languages
{ai bi | ≥ 1}
{ aibjck 1 i  j, or j  k}

114

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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:

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

d = a, b or B}

rin
 The second component of the state is used store an input symbol
  { [B, d] | d = a, b or c
ee
 The input symbol [B, d] is identified with d
gin
 = [x d] | x = B or and d = 0

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


En

 is defined as
arn

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

4)  ( [q3, d], [, e]) = ( [q3, d], [, e], R)


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

6)  ( [q4, B], [, d]) = ( [q4, B], [, d], L)


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

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


9)  ( [q6, B], [B, d]) = ( [q6, B], [B, d], L)
10)  ( [q6, B], [, d]) = ( [q1, B], [, d], R)
11)  ( [q5, B], [, d]) = ( [q7, B], [, d], R)
12)  ( [q7, B], [B, c]) = ( [q8, B], [B, c], R)
13)  ( [q8, B], [, d]) = ( [q8, B], [, d], R)
14)  ( [q8, B], [B, B]) = ( [q4, B], [, B], L)

115

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Shifting Over:

 A Turing machine can make space on its tape by shifting all non – blank symbols
a finite number of cells to the right.
 The tape head moves to the right, repeatedly store the symbols read in the finite
control
 The symbols are replaced by the symbols read from cells to the left.
 The TM can return to the vacated cells and print symbols of its choosing.

Example :

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

g.i
symbols two cells to the right.

rin
Solution :

 Let the tape of M does not contain blanks between non – blanks.


ee
Let Q contains the states of the form [q,Aa,A2] for q = q1 of q2A1,A2 in 
Let x be a special symbol not used buy M except in shifting process
gin
 M starts the shifting process in state [q1,B,B]
  are defined as
En

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}
arn

3)  ( [ q1 , B, A1 ], A3  ( [q1 , A1 , A3 ], A1, R ) for A1, A 2 , 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  ( [q 2 , B, B], A1, L)
Le

6)  ( [ q1, A1, A2 ], B  ( [q1, A2 , B], A1, R ) for A1, and A2 in   {B, x}


w.

Subroutines :

 The Turing machine can simulate any type of subroutine, include recursive
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 To design a Tm that calls the subroutine a new set for states for the
subroutines is mad, and a move from the return state is specified.
 The call is effected by entering the initial state for the subroutine and the
return is effected by the move from the return state.

Example :

The design of a TM to implement the total recursive function

Solution :

n
 M starts with Om | On on its tape and ends with Omn surrounded by blanks.

g.i
 The general idea is to place a 1 after Om | On and then copy the block of n O‟s onto the
right end m time each time erasing one of the O‟s.

rin
 The  is defined as for copy sub routine as

0 1 2 B

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

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


En

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

 To complete the program for multiplication we add states to convert initial ID q0


Le

Om | On to B Om-1,q,On 1.
w.

i.e

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


ww

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

 (q6, 1), = (q1, 1,R)

 The  is defined Multiplication as

0 1 2 B

117

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

q5 (q7, O, L)

q7 (q8, 1, L)

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

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

q10 (q11, B, R)

n
g.i
q11 (q11, B, R) (q12, B, R)

rin
Simulating for w = 00100

q0 00100
ee
Bq60100  B0q6100  B01q100
gin
B012q20 B012q2 B  B012q300 ….
En

3..MULTIHEAD AND MULTITAPE TURING MACHINE


arn

 Discuss about the Multihead and Multi Tape Turing Machine.


[NOV/DEC 2013]
Le

Multihead and Multi tape turning machine :


w.

 A multitape turning machine consists of a finite control with K tape heads and k
taps.
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

… …

… …

… …

n
g.i
rin
Finite Control
Theorem :

ee
It a language L is accepted by a multitape turning machine. It is accepted by a
single tape turning machine.
gin
Proof :

 Let L be accepted by M, a TM with k tapes


En

 We can construct M2 a single tape TM with 2k tracks


 One track records the contents of the corresponding tape of M.
arn

 The other tape is Blank, except for a Marker that holds the symbol scanned by the
corresponding head of M.
Le

A three tape turning machine


w.

Finite Control
ww

… …

… …

119

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

… …

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

Head 1 x

Tape 1 A1 A2 … .. Am

n
Head 2 x

g.i
Tape 2 B1 B2 … … Bm

rin
Head 3 x

Tape 3 C1 C2 … … Cm
ee
gin

Simulation of three tapes by one


En

 Each move of M1 is simulated by a sweep from left to right and then from right to
arn

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
Le

 M2 sweeps right visiting each of the cells with head markers and recording the
symbol scanned by each head of M1
w.

 When M2 crosses a head marker it must update the count of head markers to its
right
ww

 When no more head markers are to the right M2 has seen the symbols scanned
by each of M1‟s heads.
 Now M2 makes a left until it reaches the left most pass it updates the tape symbol
of M1
 Finally M2 changes the state of M1 recorded in M2‟s control to complete the
simulation of one move of M1
 If new state of M1 is accepting then M2 accepts move of M1
 It takes 2k2 moves of M2 to simulate k moves of M1
120

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
2. Context free languages

g.i
3. Context sensitive languages
4. Recursive and recursively enumerable languages
 The four classes of languages are grammatically charecterised.

rin
 These four classes of languages are called as chomshy hierarchy.

1. Regular Grammar :
ee
 It all productions of a CFG are of the form
gin
A  wB where A, B  are var iables
Aw where w  are string of ter min als
En

then we say the grammar is light lineave.


 If all productions are of the form
A  Bw
arn

AB
then we say the grammar is left lineave.
Le

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


 Regular grammar derives regular languages.
 Regular languages are accepted by finite Automata.
w.

2. Unrestricted Grammar :
ww

 A grammar is used with 4 tube notation.


G = (V, T, P, S)
 The productions are of the form

 

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

121

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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

n
 Context sensitive languages are accepted by linear bounded Automata.

g.i
Linear Bounded Automata (LBA)

rin
 A linear bounded automata is a non-deterministic turning machine satisfying the
following two conditions.

ee
1. Its input alphabet includes two special symbols  and $, the left and right end
marker respectively.
gin
2. The LBA has no moves left from  or right from $, nor may it print another
symbol over or $.
 The LBA is denoted as
En

M = (Q, , , , q0, , $, F)
Where Q, , , , q 0 , and F are as for a Non-deterministic TM
arn

, $,  are symbols in  the left and right end markers.


 The language accepted by M is
Le

L(M) {w | w is in ( {, $) * and q 0  w $ q for some q in F

4. Context free Grammar :


w.

 The CFG is defined as 4 tuples


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

5.A.HALTING PROBLEM
 Explain Halting Problem. Is it solvable or unsolvable problem? Discuss.
[May/June 2016]
The Halting Problem :
 If the problem of whether a TM M accept the string w is unsolvable.
 It cannot be solved for recursively enumerable languages.
 This approach will procedure an answer only if T halts not if it loops forever.

n
Accepts : Given a TM, M and a string w, Does, TM, M accepts w?
 An instance of the problem accepts consists of a pair <M, w> with the universal

g.i
turning machine.
Lu = {<m‟, w‟> | w  L (M) }

rin
 The halting problem is related to the membership problem for recursively
enumerable languages.
Halting Problem :
ee
 For a given turning machine M and a given string w, instead of asuling whether
gin
turning machine accepts w. it asks whether turning machine halts on input w. This
problem is referred as halting problem.
Halts : Given a turning machine M, and a string w does M halts on input w?
En

 We can consider the corresponding language


L(M)  { M1 , W1  | M halts on input w }
arn

Reducing One Decision Problem to another :


 If P1 and P2 are decision problems. P1 is reducible P2 ie) written as
P1 P 2
Le

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

answer for the two instances I and F (I) are the same.
Reducing One language to another :
ww

 If L1 and L2 are languages over alphabet 1 and2 respectively, we say that L1


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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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

n
 To construct M1, the moves of M are simulated by changing the move of the form

g.i
 (p, a )  (h r , b, D) to
 (p, a )  (p, a, s)

rin
 i.e) If M ever arrives in state p with a on the current tape, M1 is stuch in this state
and the symbol for ever.
 M1 will begin by inserting a new symbol # in the left most cell, moving
everything else over one cell. ee
 Then q0 is moved with the tape head to next cell ie.) second cell
gin
 M1 has the same moves as M, as well the additional move
 (q, # )  (q, # , s) for all possible.
En

States q.
 If M ever moves its tape head off, M, will enter an infinite loop, with its tape head
arn

on the left most cell. Ie) It never halts.


 Thus the hulting problem is undecidable.
Le

5.B COMPUTABLE LANGUAGES AND FUNCTIONS


 Explain Turing Machine as a computer of Integer functions with an example.
w.

[Nov/Dec 2013]
COMPUTABLE LANGUAGES AND FUNCTIONS
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.
 The integer 1 0 is represented by the string Oi
 If a function has K arguments i1,i2,... ik, then these integers are initially placed on

n
i1 i2 ik
the tape separated by 1‟s as O | O | O

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

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

ee
If f (i1,i2,... ik,) is defined for all i1,i2,... ik, then we say f is a total recursive
function.
gin
 A function f (i1,i2,... ik,) computed by a TM is called partial recursive function.
PART-C
1. DESIGN OF TURING MACHINES
En

 Design a Turing Machine to accept the Palindromes in an alphabet set .Trace


arn

the strings “0101” and “1001”. [MAY/JUNE 2016]


 Design a Turing Machine to perform addition and proper subtraction.
Le

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


w.

Solution:

 Initially the Turing Machine M contains On 1n followed by an infinity of Blanks.


ww

For eg.
x y
0 0 1 1 B …

q 0 q1 q1 q 2

125

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
q2 (q2, O, L) - (q0, X, R) (q2, Y, L) -

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

rin
q4 - - - - -

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

To verify the string w = 0011


En

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

 q2 x0yl  xq0 0y1 


arn

xq2 0y1

xxq1 y1  xxyq1 l  xxq2 yy 


Le

xq2 xyy  xxq0 yy  xxyq3 y 

xxyyq3 xxyybq4
w.

 The Turing Machine accepts L = { On 1n | n  1}


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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)

n
q7

g.i
q8

rin
M = ( Q, , , , q 0 , B, F)
ee
Q = {q0,q1,q2,q3,q4,q5,q6,q7,q8}
gin
 {0,1)
En

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

Let consider w = 0011


arn

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

x11q10  x110q1B  x11q2 0 

x1q31x  xq3l1x  q3x11x 


w.

xq011x  xyq41x xy1q4x


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

O for M<n

 The TM started with Om, On on its tape and halts on Om –n on its tape.
 M repeatedly replaces its leading O by blank then searches light for a 1 followed by
a O and changes the O to 1.
 Next M moves left until it encounters a blank and then repeats the cycle. The repetition
ends if
1. Searching right for a O, M encounters a blank. Then the n O‟s in O m | On have
all been changed to 1‟s and n + 1 of the m O‟s have been changed to B. M
replaces the n + 1 1‟s by a O and n B‟s leaving m-n O‟s on its tape.

n
2. Beginning the cycle M cannot find a O to change to a blank, because the first

g.i
m O‟s already have been changed. Then n  m, so m – n = O. m replaces all
remaining 1‟s and O‟s by B.

rin
0 1 B

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

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


En

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


arn

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

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


Le

q6 -- -- --
w.

M is defined as
ww

M = {Q, , , , qo, B, F}

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

 = {O, 1}

 = {0, 1, B}

F = {q6}
128

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
UNIT-V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTION

rin
Unsolvable Problems and Computable Functions – Primitive recursive functions –
Recursive and recursively enumerable languages – Universal Turing machine.

ee
MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable
problems- Tractable and possibly intractable problems - P and NP completeness -
gin
Polynomial time reductions.

PART-A
En

1. What is recursive enumerable and recursive set?


arn

Recursive Enumerable set:


The languages accepted by Turing Machines are called as recursive enumerable
languages. Recursively enumerable set includes regular languages and CFL‟s. some
Le

languages in recursive enumerable set are not accepted by TM.


Recursive set:
w.

The subset of recursive enumerable set is called as recursive set. All the languages in the
recursive set are accepted by TM.
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
 The union of two recursive language is recursive.

g.i
 The union of two recursively enumerable language is recursively enumerable.
 If a language L and its complement of are recursively enumerable the L and then L

rin
is recursive.

5.What is universal turing machine?

Universal Turing machine:


ee
gin
If the problem is undecidable.
En

Does the turing machine M accept input w? here both M and w are the parameters
of the problem. In formalizing a problem as a language. The input w is restricted to
be over {0,1} and M to have tape alphabet {0,1,B}. This Turing Machine is referred
arn

as Universal Turing Machine.

6.What is diagonalization language?


Le

In the table if the entry is


w.

0-> means wi is not in L(Mj)


ww

1-> means wi 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
g.i
List A List B

i wi xi

rin
1 1 111

2 10111 10 ee
gin
3 10 0

Solution :
En

 This PCP has a solution


arn

M=4
i1 = 2, i2 = 1, i3 = 1, and i4 = 3,
wi1 wi2 wi3 wi4 = xi1 xi2 xi3 xi4
Le

101111110 = 101111110
The Solution
w.

i1 = 2
ww

i2 = 1

i3 = 1

i4 = 3

8.What is MPCP?

131

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
W1,wi1,…wir = x1 xi1xi2….xir

g.i
9. What is primitive recursive function?

rin
The primitive recursive function is defined as follows

All initial functions are elements of PR

ee
For any k>= 0 and m>= 0 if N k – N ang g1,g2,…gk : Nm -> N are elements of PR ,
gin
then f(g1,g2,…gk) obtained from f and g1, g2,…. Gk by composition is an element
of PR.
En

For any n>=0 any function g:N n+1 -> N in PR and any function.

H: N n+2 -> N in PR.


arn

No other functions are in the set PR.

No other functions are in the set PR.


Le

10.What are the initial functions?


w.

a) constant functions
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
g.i
PART-B
1. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES

rin
 State and prove the closure Properties of recursive and recursively
enumerable languages. [Nov/Dec 2012]
ee
Closure properties of recursive and recursively enumerable languages :
gin
Theorem 1 :
En

The complement of a recursive language is recursive.

Proof :
arn

 Let L be a recursive language and M a tuning machine that halts on all inputs
Le

accepts L.
 Construct M‟ from M so that if M enters final state on input w then m‟ halts with
w.

accepting.
 If M halts without accepting, M‟ enters final state.
ww

 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i
rin
Theorem 2 :
ee
 The union of two recursive language is recursive.
gin
 The union of two recursively enumerable language is recursively enumerable.
En

Proof :

Let L1 and L2 be recursive language accepted by algorithms M1 and M2


arn

 Let L1 and L2 be recursive language accepted by algorithms M1 and M2


Le

 We construct M1, which first simulates M1


 If M1 accepts then M accepts.
w.

 If M1 rejects then M simulates M2 and accepts iff M2 accepts.


 Since both M1 and M2 are algorithms, M is generated to halt.
ww

 Clearly M accepts L1 U L2

134

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i
rin
ee
 For recursively enumerable languages the above construction does not work.
gin
 Since M1 may not halt.
 Instead M can simultaneously simulate M1 and M2 on separate tapes.
En

 If either accepts, then M accepts.


arn
Le
w.
ww

135

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
 Since w is in either L or  we know that exactly one of M1 or M2 will accept.

g.i
 Thus M will always say either „yes‟ or „no‟ but will never say both.

rin
 Since M is an algorithm that accepts L, it follows that L is recursive.

ee
gin
En
arn
Le
w.
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

“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,{q 2 }) be a turning and Blank as the additional tape

n
symbol.

g.i
 We assume that
Q = {q1, q2, … qn}

rin
F = {q2}
 There is no need for more than one final state in any TM, since once it accepts it
may as well halt.
ee
 The symbols 0, 1, B are used with the synonyms x1, x2, x3 respectively.
gin
 Directions L and R used with the synonyms D1 and D2.
 The move  (q i , x j)  q k , x l , D m ) is encods by the binary string.
Oi | O j | O k | O l | O m
En

 A binary code for turning machine M is


||| Code, || Code2 || … || Coder |||.
arn

Where each codeiis of the form 0i10j10k10l10m


 Each move of M is encoded by one of the codei‟s
 The moves need not be in any particulars order
Le

 The pair <M, w> is represented by the string of the form


|||Code1 ||Code2 || … Coder ||| followed by w
w.

 Any such string will be denoted <m, w>


ww

Example :

 Encode the following TM, M <M, 1011> in binary


M = ({q1, q2, q3}, {0, 1}, {0, 1, B},  , q1, B1, {q2})
Where  is
 (q1,1)  (q 3 , 0, R )
 (q 3 , 0)  (q1,1, R )
 (q 3 ,1)  (q 2 , 0, R )

137

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 (q3 , B)  (q3 ,1, L)

Solution :

1)  (q1,1)  (q 3 , 0, R )
 (q1, x 2 )  (q 3 , x1, D2 )
Code1 = 01102103101102
2)  (q3 , 0)  (q1,1, R )
 (q 3 , x1)  (q1, x 2 , D 2 )

n
Code2 = 03101101102102

g.i
3)  (q3 ,1)  (q 2 , 0, R )
 (q3 , x 2 )  (q 2 , x1, D2 )

rin
Code3 = 03102102101102
4)  (q3 , B)  (q3 ,1, L)

ee
 (q 3 , x 3)  (q 3 , x 2 , D1 )
Code4 = 03103103102101
gin
Thus the string denoted by <M, 1011> is
En

|||01|02|03|01|02|03|01|01|02|02||03|02|02|01|02|03|03|03|02|01|||1011

111010010001010011000101010010011000100100101001100010001000100101
arn

111011
Le

3. NON RECURSIVELY ENUMERABLE LANGUAGE

 Prove that Ld is not recursively enumerable


w.

A non – recursively enumerable language :


ww

Lemma :
Ld is not recursively enumerable.
 Suppose we have a list of (0+1)* in canonical order where
w i  is the ith word
M j
is the TM whose code is the integer j written in binary
 We can construct an infinite table that tells for all I and j whether wi is in L (Mj)

138

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 In the table, if the entry is


0 – means wi is not in L(Mj)
1 – 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 Ld. 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.

n
1) If wj is in Ld then (j, j) entry o, implying that wj is not in L(mj) and

g.i
contradiciting Ld = L(Mj)
2) If wj is not in Ld, then the (j, j) entry is 1, implying that wj is in L(Mj) which

rin
contradicts Ld = L(Mj)
 As wj is either in or not in Ld, we conclude that our assumption Ld = L(Mj) is false.
 Thus no TM in the list accepts Ld. And no turning machine accepts Ld.
Lemma :
Ld is not recusively enumerable.
ee
gin
4. THE UNIVERSAL LANGUAGE
En

The Universal Language :


 The universal language Lu is defined to be
arn

{<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 any particulars TM M is equivalent to the question of
Le

whether. <M1, w> is Lu, where M1 is the TM with the tape alphabet {0, 1, B}
equivalent.
w.

Theorem 1 :
Lu is recursively enumerable.
ww

Proof :
 We shall exhibit a three tape TM M1 accepting Lu
 The first tape of M1 is the input tape and the input head on that tape is used to
look up moves of the TM M when given code <M, w> as input.
 The second tape of M1 will simulate of M.
 The alphabet of M is {0, 1, B}, so each, of M‟s tape can be held in one tape cell of
M1‟s second tape.
 The third type holds the state of M with qi represented by Oi

139

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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 oi | oj | for the
same i and j for the same i and j Also check that if oi | 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.

n
4) Let xj be the symbol currently scanned by tape head2 and let Oi be the current

g.i
content of tape 3.
Scan tape 1 from the left end to the second 111 looking for a substring beginning 110i |

rin
Oj11. If no such string is found, halt and reject. M has no next move and has not
accepted.
If such a code is found, let it be oi | oj | ok | ol | om Then put Ok on tape 3 print x2 on the
ee
tape cell scanned by tape head 2 and move that head in Direction Dm.
gin
5) Go to step (3)
 M1 accepts < M, W > if, M accepts w. It is also true that if m run
forever on w, M1 will run forever on <m, w>.
En

 If m halts on w without accepting, M1 does the same on < m1, w >.


 Thus lu is recursively enumerable.
arn

Theorem 2
Lu is not recursive
Proof :
Le

 Suppose A is an algorithm, recognizing lu.


 Then we can recognize Ld as follows.
w.

 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
ww

accept w iff Mi accepts wi

140

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

n
g.i
rin
 Thus we have an algorithm for Ld. since no such algorithm exists, we know our

ee
assumption, that algorithm A for Lu exists is false.
 Hence Lu is recursively enumerable, but not recursive.
gin
En

5.PRIMITIVE RECURSIVE FUNCTION


 Discuss about primitive recursive function.
arn

Primitive Recursive Functions :


 The primitive recursive function is defined as follows.
Le

1. All initial functions are elements of PR


2. For any K  0 and M  0 if Nk – N and g1, g2, … gk; N  N are elements
m
w.

of PR, then
f (g1, g2, … gk) obtained from f and g1 of g2, … gk, by composition is an element PR
ww

n 1
3. For any n  0 any function g : N  N in PR, and any function
h : N n 2  N in PR
n 1
the function f : N  N obtained from g and h by plimitive recursion is in PR.
4. No other functions are in the set PR.
Initial Function :
 The initial function are the following
1. Constant functions :
141

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

For each K  0 and each a  0 , the constant function


C a  Nk  N for every X E Nk
k

In the case K = 0 we may identify the function Cak with the number a
2. The successor function :
N  N is defined by the formula s (x) = x + 1
3. Project Functions
For much K 1 and each I with 1 i  k
the projection function

n
P1 : N k  N is defined by the formula
k

g.i
P i ( x1, x 2 , ..., x i , ... x k )  x i
k

Composition :

rin
 Suppose f is a partial function from Nk to N and for each I with 1  i  k, giis a
partial function from Nm to N. The partial function obtained from f and g1, g2, …,
ee
gk by composition is the partial function h from Nm to N defined by the formula
h(x) = (f (g1 (x), g2 (x), …. gk (x)) (XENm)
gin
The Primate recursion operation :
 Suppose n  0 and g and h are functions of n and n + 2 variables. respectively The
En

function obtained from g and h by the operation of primitive recursion is the


function.
f : N n 1  N defined by the formula
arn

f (x, 0) = g (x)
f (x, k+1) = h (x, k, f (x1k))
Le

for XENn and every K  0


Addition and Multiplication :
w.

 The functions Add and Mult from N x N to N defined by the formulas


Add (x, y) = x + y
ww

Mult (x, y) = x * y
are primitive recursive.
 If Add is obtained from g and h by primitive recursion. g and h must be functions
of one of three variables.
 The equations are
Add (x, 0) = g (x)
Add (x, k+1) = h (x, k, Add (x, k))
 Add (x, 0) is x and so g to be the initial functions P11
142

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 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)
 To Obtain Mult

n
Mult (x, 0) = 0

g.i
Mult (x, k+1) = x * (k + 1)
= Add (x * k, x)

rin
= Add (x, Mult (x, k))
5.A.TRACTABLE AND INTRACTABLE PROBLEM
 Explain about tractable and intractable problem with suitable
ee
examples.(NOV/DEC2016,Apr/May 2017)
gin
Tractable problem
Tracatable problem is a problem which can recognize with in reasonable time
En

and space constraints and can be solved in polynomial time. Those problems for
which no polynomial time algorithm are known requires exponential runtime.
Intractable Problem:
arn

Intractable problems are techniques for showing problems not to be solvable in


polynomial time.
Le

Tractable and possibly Intractable problems:


w.

Some of the complexity classes containing the languages recognizable in


polynomial time and polynomial space are as follows,
Class P= Time(cn k )
ww

c 0, k 0

PSpace=  Space(cn
c 0 , k 0
k
)

Class NP=  NTime(cn


c 0, k 0
k
)

143

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

NPSpace=  NSpace(cn
c 0, k 0
k
)

 The sets P and SPace include any language that can be recognized by aTuring
machine with time complexity or space complexity bounded by some
polynomial
 Generally allowing non-determinstism will allow improvements in the time
complexity that is required to solve many problems.

n
 There are many languages or decision problems in NP for which no determinstic

g.i
polynomial time algorithm are known.
 There are no languages in NP that are known not to be in P.The problem P is the

rin
subset of NP and the following holds
P  NP  PSpace  NPSpace

ee
NP Problem as CNFG satisfiablity problem.
gin
CNF Satisfiablity Problem

The instance of CNF Satisfiablity problem is logical expression which contains


En

variables xi and the logical connectives as ,,  (AND,OR,NOT respectively)


The expression of conjuctiv normal form is givem as follow:
arn

C1  C2  C3  ...... Cn
Where Ci=subexpressions
Each Ci is the disjunction of the literal expression for example,
Le

(x1  x2  x4)  ( x1  x3  x4 ) is the CNF expression with two conjucts.


w.

Primitivity Problem:
This is one of the common decision problem stated as,
ww

"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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

5.B.POLYNOMIAL TIME REDUCTION


 Explain about Polynomial Time reduction with suitable examples.
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

n
is 2m which is fed to the hypothetical polynomial time algorithm for P2. If the decision
algorithm run in O(nK) time , then 0n an input of length 2m, it may take O(2km) which is

g.i
exponential in M.

rin
P1 Instance P2 Instance Decide Yes
Construct

ee
gin
No
En

Reductions:
"L1 is reducible to L2" if there is a computable function 'f' so that checking
whether x  L1 is equivalent to check whether f(x)  L2.
arn

 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
Le

impossible.
 If testing the membership of astring in L2 is possible, then testing a string
w.

after computing 'f' is also possible


 The reducing function'f' should be computable in areasonable amount of
ww

time which 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
 (q1,1)  (q 3 , 0, R )

g.i
 (q 3 , 0)  (q1,1, R )
 (q 3 ,1)  (q 2 , 0, R )

rin
 (q3 , B)  (q3 ,1, L)

Solution :

5)  (q1,1)  (q 3 , 0, R )
ee
gin
 (q1, x 2 )  (q 3 , x1, D2 )
Code1 = 01102103101102
En

6)  (q3 , 0)  (q1,1, R )
 (q 3 , x1)  (q1, x 2 , D 2 )
arn

Code2 = 03101101102102
7)  (q3 ,1)  (q 2 , 0, R )
 (q3 , x 2 )  (q 2 , x1, D2 )
Le

Code3 = 03102102101102
8)  (q3 , B)  (q3 ,1, L)
w.

 (q 3 , x 3)  (q 3 , x 2 , D1 )
ww

Code4 = 03103103102101

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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 = w1, …, wk and
B = x1, …, xk

n
g.i
of strings over some alphabet 

 This instance of PCP has a solution if there any sequence of integers

rin
i1, i2,…, im, with M  1 such that
wi1, wi2, …, wim = xi1 xi2 … xim
ee
 The sequence i1, … im is a solution to this PCP
gin
Example :

Let  {O,1} Let A and B be list of three strings.


En

List A List B
arn

i wi xi

1 1 111
Le

2 10111 10
w.

3 10 0
ww

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
147

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

i1 = 2

i2 = 1

i3 = 1

i4 = 3

A modified version of PCP [MPCP]

n
 The Modified version of PCP (MPCP) is the following.

g.i
Given list A and B, of K strings each from  * say
A = w1, w2 …, wk

rin
B = x1, x2 …, xk
 This problem has a solution if there exists sequence of integers
i1, i2,…, ir, such that
w1wi1 wi2 …wir = xi1 xi2 …xir ee
gin
 The difference between the MPCP and PCP is that in the MPCP a solution
required to start with the firs string on each list.
En

Lemma

If PCP were decidable, then MPCP would be decidable. That is,


arn

MPCP reduces to PCP


Le

Proof :

Let
w.

A = w1, w2 …, wk and
B = x1, x2 …, xk
ww

be an instance of the MPCP


 We convert this instance of MPCP to an instance of PCP that has a solution, iff
our 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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

 Let Zi  be obtained from xi by inserting the symbol  ahead of each character of


xi
 Great new words
y0=  y1 Z0 = Z 1
yk+1 = $ Zk+1 =  $

Example :

Reduce the following MPCP into PCP

n
List A List B

g.i
wi xi

rin
1 1 111

3
10111

10
ee
10

0
gin
En

Solution :

 The lists C and D are constructed from the lists A and B


arn

 Let
C = y0, y1, …. yk+1
D = Z0, Z1, …. Zk+1
Le
w.

List C List D
ww

yi zi

0 1  1 11 1

1 1 1 1 1

2 1 0  1 1 1 10

149

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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.

n
Undecidability of PCP

g.i
Theorem :

PCP is undecidable

rin
Proof :

ee
 It is sufficient to show that if MPCP were decidable, then PCP would be decidable
whether a TM accepts a given word.
gin
 We reduce Lu to MPCP, which again can be reduced to PCP.
 For each M and w1 we construct an instance of MPCP that if it has a solution has
En

one starts with


#q0w# 1 q11 #...#  k q k k
arn

where
 Strings between sucresive #‟s are successive ID‟s in a computation of M with
input w.
Le

 qx is the final state.


 Formally the pairs of strings forming lists A and B of the instance of MPCP are
w.

given below.
 The first pair is
ww

List A List B
# #q0w#
 The remaining pairs are grouped as

Group 1 :

List A List B

x x

150

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
if  (q, B)  (p, y, L)

g.i
q# pzy#

Zq# pzY# if  (q, B)  (p, y, L)

rin
Group III :
ee
gin
For each q in F, and x and Y in 

List A List B
En

XqY q
arn

Xq q

qY q
Le

Group IV :
w.

List A List B
ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Z is the remainder of (x, y)


 (x, y) =
(#q 0 w #1 q11 # 2 q 2 2 ...# k1 q k 1 k1 ,
#q 0 w #1 q1 1 # .... # k q k k # )

Example :

M = ({q1, q2, q3}, (0, 1, B}, {0, 1},  , q1, B, {q3})

and  is given as

n
0 1 B

g.i
q1 (q2, 1, k) (q2, 0, L) (q2, 1, L)

rin
q2 (q3, 0, L) (q1, 0, R) (q2, 0, R)

q3 -
ee- -
gin
Construct an instance of MPCP with lists A and B
En

w = 01

Solution :
arn

 The first pair is


List A List B
Le

# #q, 01#
 The remaining pairs are
w.

Group I :
ww

List A List B

0 D

1 1

# #

Group II

152

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

List A List B

q1, 0 1 q2 from  (q1 , 0)  (q 2 ,1, R )

0q1, 1 q200
from  (q1 ,1)  (q 2 , 0, L)
1q1, 1 q2 10

0q1, # q2 01 #
from  (q1 , B)  (q 2 ,1, L)
1q1 # q211#

n
0q2 0 q3 00

g.i
from  (q12 , 0)  (q 3 , 0, L)
1q2, 0 q0 10

rin
q2 1 0q1 from  (q 2 ,1)  (q1 , 0, L)

q2 # 0q2#
ee from  (q 2 , B)  (q 2 , 0, R )
gin
Group III

List A List B
En

0q30 q3

0q31 q3
arn

1q30 q3
Le

1q31 q3
w.

List A List B
ww

0q3 q3

1q3 q3

q30 q3

q31 q3

Group IV :
153

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

154

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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)

n
Time: Three hours Maximum:100 marks

g.i
Answer ALL questions.

PART A - (10 x 2=20 marks)

rin
1. Define Deterministic Finite Automata (DFA).(pg.no:7)

ee
2. What are the closure properties of regular languages?(pg.no:7)
gin
3. What is meant by Context Free Grammar(CFG)?(pg.no:58)

4. State Chomsky normal form theorem.(pg.no:66)


En

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)


arn

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)


Le

9. Define Universal Turing machine.(pg.o:130)


w.

10. Define NP-hard and NP-completeness problem. (pg.no:133)


ww

PART B-(5 X 16 =80 MARKS)

11 (a) (i) Given ∑=(a,b),construct a DFA which recognize the language L={bmabn;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)
155

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

δ a b

q0 {q0,q1} {q1}

q1 φ {q0,q1}

Or

(b) Discuss the basic approach to convert from NFA to regular expression illudtrate with an
example.(pg.no: 40)

(16)

n
12 (a) (i) Construct a Context Free Grammar for the language L={an: n is odd}.(pg.no:67)(6)

g.i
(ii) Define derivation tree. Explain its uses with an example.(pg.no:70) (10)

rin
Or

ee
(b) Obtain a grammar in chomsky Normal Form(CNF) equivalent to the grammar G with the production
P given.(pg.no:75)
gin
S->aAbB ,A->aA/a, B->bB/b.

13. (a) (i) Outline an instantaneous description of a PDA. (pg.no:86) (6)


En

(ii)State and explain the pumping lemma for CFG (pg.no:93) (10)

Or
arn

(b) with an example, explain the procedure to obtain a PDA from the given CFG. (16)
Le

14 (a) Discuss the various techniques for Turing Machine construction.(pg.no:112) (16)

Or
w.

(b) (i) Write about Multitape turing machines. (pg.no:118) (10)


ww

(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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

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)

n
Time: Three hours Maximum:100 marks

g.i
Answer ALL questions.

PART A - (10 x 2=20 marks)

rin
1. Generate NFA-ϵ to represent a*b|c. (pg.no:58)

ee
2. Show whether a language L={0n12n|n>0} is regular or not using pumping lemma.(pg.no:53)
gin
3. Give language of regular expression of a?(b/c)*.(pg.no:69)

4. Generate CFG for a signed integer constant in C language.


En

5. Construct a right most derivation of (a+b)*c for using the grammar, and also state that whether a
given grammar is ambiguous or not. (pg.no:71)
arn

6. Differentiate PDA acceptance by empty stack method with acceptance by the final state
method.(pg.no:86)
Le

7. Write short notes Chomsky hierarchy of language.(pg.no:121)

8. What is Halting problem?(pg.no:123)


w.

9. What is primitive recursive function?(pg.no:152)


ww

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

Visit for More : www.LearnEngineering.in


Visit for More : www.LearnEngineering.in

Or

n
(b) Prove for every n >=1 by mathematical induction  i3  {n(n  1) / 2}2
1
(pg.no:54) (16)

12 (a) Given the CFG G, Find CFG G' in CNF generating the language L(G)-{^}(pg.no:75)

S->AACD

A->aAb|^

C->aC|a

n
g.i
D->aDa|bDb|^ Or

(b) Convert the following grammar G into Greibach Normal form(GNF).(pg.no:77)

rin
S->Xa|BB

B->b|Sb

X->b
ee
gin
X->a
En

13. (a) (i) Construct a DPDA for even length palindrome. (pg.no:88) (6)

(ii)Prove- if PDA P is constructed from CFG G be the above construction, then N(P)=L(G)(pg.no:91)(10)
arn

Or

(b)Convert the following CFG to PDA and verify for (a+b) and a++.(16)
Le

I->a|b|Ia||Ib|I0|I1,E->I|E+E|E*E|(E)
w.

14 (a)Construct a TM to reverse the given string (16)(pg.no:125)

Or
ww

(b) Write about Multitape and Multi head turing machineswith suitable example.(pg.no:118)
(16)

15 (a) Explain recursive and recursively enumerable language with suitable example. (16)(pg.no:133)

Or

(b) Explain about tractable and intractable problem with suitable examples.(pg.no:143) (16)

158

Visit for More : www.LearnEngineering.in

You might also like