Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
174 views394 pages

TOC Material

The document outlines the course objectives and structure for CS3452 Theory of Computation, focusing on automata theory, regular expressions, context-free grammar, Turing machines, and undecidability. It includes detailed unit descriptions, key concepts, and definitions related to finite automata, regular languages, and computational models. The course aims to equip students with the ability to construct automata, write regular expressions, design grammars, and differentiate between decidable and undecidable problems.

Uploaded by

kalamaashique1
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)
174 views394 pages

TOC Material

The document outlines the course objectives and structure for CS3452 Theory of Computation, focusing on automata theory, regular expressions, context-free grammar, Turing machines, and undecidability. It includes detailed unit descriptions, key concepts, and definitions related to finite automata, regular languages, and computational models. The course aims to equip students with the ability to construct automata, write regular expressions, design grammars, and differentiate between decidable and undecidable problems.

Uploaded by

kalamaashique1
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/ 394

DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT I THEORY OF COMPUTATION

CS3452 THEORY OF COMPUTATION LTPC3003


COURSE OBJECTIVES:
 To understand foundations of computation including automata theory
 To construct models of regular expressions and languages.
 To design context free grammar and push down automata
 To understand Turing machines and their capability
 To understand Undecidability and NP class problems

UNIT I AUTOMATA AND REGULAR EXPRESSIONS 9


Need for automata theory - Introduction to formal proof – Finite Automata (FA) – Deterministic Finite
Automata (DFA) – Non-deterministic Finite Automata (NFA) – Equivalence between NFA and DFA –
Finite Automata with Epsilon transitions – Equivalence of NFA and DFA- Equivalence of NFAs with and
without ε-moves- Conversion of NFA into DFA – Minimization of DFAs.
UNIT II REGULAR EXPRESSIONS AND LANGUAGES 9
Regular expression – Regular Languages- Equivalence of Finite Automata and regular expressions –
Proving languages to be not regular (Pumping Lemma) – Closure properties of regular languages.
UNIT III CONTEXT FREE GRAMMAR AND PUSH DOWN AUTOMATA 9
Types of Grammar - Chomsky„s hierarchy of languages -Context-Free Grammar (CFG) and Languages –
Derivations and Parse trees – Ambiguity in grammars and languages – Push Down Automata (PDA):
Definition – Moves - Instantaneous descriptions -Languages of pushdown automata – Equivalence of
pushdown automata and CFG-CFG to PDA-PDA to CFG – Deterministic Pushdown Automata.
UNIT IV NORMAL FORMS AND TURING MACHINES 9
Normal forms for CFG – Simplification of CFG- Chomsky Normal Form (CNF) and Greibach Normal Form
(GNF) – Pumping lemma for CFL – Closure properties of Context Free Languages –Turing Machine : Basic
model – definition and representation – Instantaneous Description – Language acceptance by TM – TM as
Computer of Integer functions – Programming techniques for Turing machines (subroutines).
UNIT V UNDECIDABILITY 9
Unsolvable Problems and Computable Functions –PCP-MPCP- Recursive and recursively enumerable
languages – Properties - Universal Turing machine -Tractable and Intractable problems - P and NP
completeness – Kruskal‟s algorithm – Travelling Salesman Problem- 3-CNF SAT problems.
COURSE OUTCOMES:
At the end of this course, the students will be able to:
CO1: Construct automata theory using Finite Automata
CO2: Write regular expressions for any pattern
CO3: Design context free grammar and Pushdown Automata
CO4: Design Turing machine for computational functions
CO5: Differentiate between decidable and undecidable problems
TOTAL:45 PERIODS
TEXT BOOKS:
1. Hopcroft J.E., Motwani R. & Ullman J.D., "Introduction to Automata Theory, Languages and
Computations", 3rd Edition, Pearson Education, 2008.
2. John C Martin , "Introduction to Languages and the Theory of Computation", 4th Edition, Tata McGraw
Hill, 2011.
REFERENCES:
1. Harry R Lewis and Christos H Papadimitriou , "Elements of the Theory of Computation", 2nd Edition,
Prentice Hall of India, 2015.
2. Peter Linz, "An Introduction to Formal Language and Automata", 6th Edition, Jones & Bartlett, 2016.
3. K.L.P.Mishra and N.Chandrasekaran, “Theory of Computer Science: Automata Languages and
Computation”, 3rd Edition, Prentice Hall of India, 2006.
1
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

UNIT I AUTOMATA AND REGULAR EXPRESSIONS 9


Need for automata theory - Introduction to formal proof – Finite Automata (FA) – Deterministic
Finite Automata (DFA) – Non-deterministic Finite Automata (NFA) – Equivalence between NFA and
DFA – Finite Automata with Epsilon transitions – Equivalence of NFA and DFA- Equivalence of
NFAs with and without ε-moves- Conversion of NFA into DFA – Minimization of DFAs.

PART A
1. Define Theory of Computation.
The theory of computation describes the basic ideas and models underlying computing. Computation
is the process of execution of an algorithm such that it involves taking some inputs and performing required
operation on it to produce an output.

2. Why are switching circuits called as finite state systems?


A switching circuit consists of a finite number of gates, each of which can be in any one of the two
conditions 0 or 1.Although the voltages assume infinite set of values, the electronic circuitry is designed so
that the voltages corresponding to 0 or 1 are stable and all others adjust to these values. Thus control unit of
a computer is a finite state system.

3. Give the examples designed as finite state system.


Text editors and lexical analyzers are designed as finite state systems. A lexical analyzer scans the
symbols of a program to locate strings corresponding to identifiers, constants etc, and it has to remember
limited amount of information.

4. What is Moore machine and Mealy machine?


A special case of FA is Moore machine in which the output depends on the state of the machine.
An automaton in which the output depends on the transition and current input is called Mealy machine.

5. What are the components of Finite automaton model?


The components of FA model are Input tape, Read control and finite control.
(a)The input tape is divided into number of cells. Each cell can hold one i/p symbol.
(b)The read head reads one symbol at a time and moves ahead.
(c)Finite control acts like a CPU. Depending on the current state and input symbol read from the
input tape it changes state.

6. Define: (i) Finite Automaton (FA) (ii) Transition Diagram [Apr/May2007][Nov/Dec2012]


[Nov/Dec-2024]
 FA consists of a finite set of states and a set of transitions from state to state that occur on input
symbols chosen from an alphabet ∑.
o Finite Automaton is denoted by a 5- tuple (Q, ∑, δ, q0, F),
o Where
 Q is the finite set of states ,
 ∑ is a finite input alphabet,
 q0 in Q is the initial state,
 F is the set of final states and
 δ is the transition mapping function Q* ∑ to Q.

Transition diagram is a directed graph in which 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, then there is an arc labeled „a „from q to p in the
2
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

transition diagram. One state is designated as “Start” state. The final state will be indicated by double
circles.

7. What are the Applications of Automata theory? [May - 2008, 2011, 2012, Dec-2011, 2012]
1. It is base for the formal languages and these formal languages are useful of the programming languages.
2. It plays an important role in complier design.
3. To prove the correctness of the program automata theory is used.
4. In switching theory and design and analysis of digital circuits automata theory is applied.
5. It deals with the design finite state machines

8. Define automata theory. What is the need for automata theory?


Theory of automata is a theoretical branch of computer science and mathematical. It is the study of abstract
machines and the computation problems that can be solved using these machines. The abstract machine is
called the automata. The main motivation behind developing the automata theory was to develop methods to
describe and analyse the dynamic behaviour of discrete systems.
There are four major families of automaton :
 Finite-state machine
 Pushdown automata

 Linear-bounded automata
 Turing machine

9. What is Induction principle? Give an example. [NOV/DEC 2012 ]


The simplest form of mathematical induction infers that a statement involving a natural number n
holds for all values of n. The proof consists of two steps:

1. The basis (base case): prove that the statement holds for the first natural number n. Usually, n = 0 or
n = 1.
2. The inductive step: prove that, if the statement holds for some natural number n, then the statement
holds for n + 1.
The hypothesis in the inductive step that the statement holds for some n is called the induction hypothesis
(or inductive hypothesis). To perform the inductive step, one assumes the induction hypothesis and then
uses this assumption to prove the statement for n + 1.
Whether n = 0 or n = 1 depends on the definition of the natural numbers. If 0 is considered a natural number,
the base case is given by n = 0. If 1 is taken as the first natural number, then the base case is given by n = 1.

Example: Prove by induction that Sn = 1 + 3 + 5 + 7 + ... + 2n-1 = n2

The property is obvious for n = 1.Now assume that the property is valid for n=k
So, we know that Sk = 1 + 3 + 5 + 7 + ... + 2k-1 = k2
We have to prove that property is valid for n = k+1.
3
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

We have to prove: Sk+1 = 1 + 3 + 5 + 7 + ... + 2k-1 + 2k+1 = (k+1)2


Well, Sk+1 = Sk + (2k+1) = k2 + 2k +1 = (k+1)2.
So, the property is true for all natural numbers starting from 1.
10. What is meant by DFA or Define DFA? [MAY/JUNE 2013] [Nov/Dec 2020]
A Deterministic Finite Automata (DFA) consists of finite set of states and a finite set of input symbols. In
DFA, only a single transition occurs form one state to another state on single input symbol.
A Deterministic Finite Automata (DFA) is defined by five tuples
M = (Q, ∑, δ, q0, F)
Where
 M-Finite automata
 Q - finite, non empty set of states
 ∑- finite set of alphabets
 q0 ЄQ - the start state
 F F C Q- a set of final states
 δ a transition function (Q Х ∑  Q)

11. What is a Non-Deterministic Finite Automaton (NDFA)? (Nov/Dec 2013) April/May 2018
An NFA has finite set of states, a finite set of input symbols with one start state and a set of
accepting states. In NFA, δ is a transition function that takes a state and a set of input symbols as argument,
but returns a set of zero, one or more states. NFA allows zero, one or more transitions from a state on the
same input symbol.
The Non-deterministic Finite Automata (NFA) is defined by a five tuple
M = (Q, ∑, δ, q0, F)
Where, Q - finite, non empty set of states
 ∑- an input alphabet
 q0 ЄQ - the start state
 FQ- a set of final states
 δ a transition function (Q Х ∑  2Q (2Q is the power set of Q)

12. Define NFA with ε -transition. Is the NFA‟s with ε -transitions are more powerful than the NFA‟s
without ε –transition?
The NFA with ε moves defined by 5 tuple or quadruple as similarly as NFA, except ε.
M = (Q, ∑, δ, q0, F) with all components as before: Q x (δ U{ ε }) = 2Q
No, NFA with ε transition and NFA without ε -transition have the same power.

13. Define Formal proof.


Formal proof is one in which step by step procedure is used to solve the problem. Here the truth of
the statement is shown by a detailed sequence of steps and reasons. Testing the program is so important, but
if our program is very complex that involving the recursion of iteration, then our code may become
incorrect.

14. What are the Additional Forms of Proof?[Dec 2011, 2012]


The additional forms f proof are as follows,
 Proof about sets
 Proofs by contradiction
 Proofs by counter example

4
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

15. Define Structural Inductions. [NOV/DEC 2011]


In Automata, there are several recursively defined structures such as trees and expressions. The
structural induction deals with the recursive definition that has a basis case in which one or more elementary
structures are defined. There is an inductive step, where more complex structures are defined in terms of
previously defined structures.

16. Difference between proof by contradiction and proof by contrapositive [May/June-2011]


S.No Proof by contradiction Proof by contrapositive
1 If “ A is true then B is also true” is to be proved If “ A is true then B is also true” is to be proved
then by this method we assume A is true and B is then by this method we assume B is false and
false. When we get some sort of contradiction prove that A is also false. This ultimately proves
then we declare that given statement is true. the given statement.
2 A contrapositive (and is equivalent to) A contrapositive has truth value (equivalent to )
I do not have an umbrella⟹it is not raining  It is raining⟹I have an umbrella

17. Obtain the  closure of states q0 and q1 in the following NFA with  transition. [Dec 2014]

Solution:
Є – Closure (q0) = {q0, q1, q2}
Є – Closure (q1) = {q1, q2}

18. How will you find the equivalence of the FA and RE?
The equivalence of the finite automata and the regular expression can be proved by two parts as
follows:
 The first parties obtaining a finite automaton from its regular expression
 The second part is obtaining the regular expression from the finite automata.

19. What is a : (a) String (b) Regular language?


A string x is accepted by a Finite Automaton M = (Q, ∑, δ, q 0, F), if δ (q0, x) = p, for some p in F.
Finite Automata accepts a string x if the sequence of transitions corresponding to the symbols of x leads
from the start state to accepting state.
The language accepted by M is L(M) is the set {x | δ (q0, x) is in F}. A language is regular if it is
accepted by some finite automaton.

20. What is deductive proof?


A deductive proof consists of a sequence of statements, which starts from a hypothesis, or a given
statement to a conclusion. Each step is satisfying some logical principle.

21. Differentiate NFA and DFA. [APRIL/MAY 2007] [NOV/DEC 2011]


Give the difference between DFA and NDFA. Nov/Dec 2018
NFA DFA
Non Deterministic Finite Automata Deterministic Finite Automata

NFA or Non Deterministic Finite Deterministic Finite Automaton is a FA in


Automaton is the one in which there exists which there is only one path for a
5
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

many paths for a specific input from specific input from current state to next
current state to next state. state.
NFA can be used in theory of computation There is a unique transition on each input
because they are more flexible and easier symbol.
to use than DFA.

Accepts input if the last state is in F Accepts input if one of the last states is in
F
The NFA is defined as 5-tuple A DFA M is a five tuple notation that
M=(Q,∑,δ,q0,F). consists of M=(Q,∑,δ,q0,F).
δQ×∑2Q δQ×∑Q
0 ,1 0 ,1
0 0
1 1
q0 q1
q0 q1
0

22. Define proof by contrapositive.


It is other form of if then statement. The contra positive of the statement “if H then C” is “if not C
then not H”.

23. What is Є-closure of a state q0?


Є-Closure (q0) denotes a set of all vertices p such that there is a path from q 0 to p labeled Є. Example:
Є
q0 q1

Є – Closure (q0) = {q0,q1}

24. State Induction principle. [NOV/DEC 2012 ]


Basis: P(1) is true.
Induction: Assume p(k) is true.
P(K+1) is shown to be true. (OR)
If we prove S(i) and we prove that for all n >= i, S(n) implies S(n+1), then we conclude S(n)
for all n >= i.

25. Give any four applications of Finite Automata.


a. It is an useful tool in the design of Lexical analyzer
b. Compiler design
c. Pattern matching
d. File Searching Program
26. Define star closure and positive closure.
1. Star closure –zero or more Occurrence
2. positive closure – one or more occurrence
(e.g.,) a* = {ε, a, aa,….}
a+ = {a, aa,……}
L+ = L* - {ε}
27. Find the language accepted by the following automata.
Some of the accepted strings are baba, baab, abab,…..

6
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

L = {ω: ω Є {a, b}*, strings contains even number of a's and even number of b's}
b q0 a

b a
q0 q0
a b
a b
q0

28. Find the ε -closure of the states 1, 3.

ε -closure(1) = {1,2,3,6,7,4} ε -closure(3) = {3,6,7,1,4,2}

29. Define Finite State Systems.


The finite automaton is a mathematical model of a system, with discrete inputs and outputs and a
finite number of memory configuration called states.

30. What are the methods of formal proof?or State any four types of proofs. Nov/Dec 2020
Methods of formal proof involves,
a. Deductive proof
b. Reduction to definitions
c. Other theorem forms
d. Theorems that appear not to be If-then

31. Define Modus Ponens Rule.


If the hypothesis of some theorem is a previous statement, then the conclusion of that theorem is
true, and can be written down as a statement of our proof. This logical rule is called as MODUS PONUS
rule. That is if we know H is true and if we know (if H then c) is true, then we can conclude that C is true =>
(P (PQ) = Q)

32. Define Mutual Induction.


The group of statements, S1(n),S2(n)…Sk(n) can be replaced by the single statement as,
S1(n) AND S2(n) AND … AND Sk(n)
When there are several independent statements to prove, then we keep the statements separate and to
prove them all in their own parts of the basis and inductive step. This form of proof is called Mutual
Inductions.

33. What is meant by language?


The set of all strings which are chosen from ∑*, where ∑ is particular alphabet is called language. A
set of strings form an alphabet is called a language.
For example If ∑ is an alphabet and L c=∑*, then L is a language over ∑.
Ex. Binary strings {0, 1, 01, 10, 0110,…} is a language over ∑={0,1}
7
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

If ∑ = {a, b} is an alphabet, then ∑* = {ε, a, b, aa, ab…} is a language.

34. Define transition table.


The transition table is the tabular representation of the “delta” (δ) transition function of FA, whose rows
denotes the states and column denotes the input symbols.
Example: 1
q0 q1

The transition table for the above transition diagram is,


1

q0 q1
*q1 Φ

35. What is meant by Transition?


Transition is the process of moving from one state to another state on reading an input symbol.

36. Define the language accepted by NFA and DFA. [NOV/DEC 2008]
The language of DFA M = (Q,∑,δ,q0,F) is denoted by L(M) and it is defined as,
L(M)={(w/δ‟ (q0,w) is in F) }
The language accepted by NFA M=(Q,∑,δ,q0,F) is denoted by L(M) and it is defined as,
L(M)={(w/δ‟ (q0,w) contains a state in F) } (Or)
L(M)={(w/ δ‟ (q0,w) Π F ≠ Ф)}

37. Define NFA with ε transition. [MAY/JUNE 2013]


The NFA can be extended to NFA- ε transition for an empty input string ε.
The NFA – ε is defined as 5 – tuple,
M = (Q, ∑, δ, q0, F)
where,
 Q set of all states
 ∑an input alphabet
 q0q0 ЄQ - the start state
 F set of final states(F<=Q) a set of final states
 δ a transition function (Q Х ∑ u{ ε}  2Q (Q Х ∑*2Q)

38. State the equivalence theorem of NFA and DFA.


If a regular language „L‟ is accepted by a non-deterministic finite automata then there exist a DFA
that accepts „L‟. (Or)
A regular language „L‟ is accepted by some DFA if and only if „L‟ is accepted by some NFA.

39. State the equivalence theorem of NFA with and without epsilon transition.
A language „L‟ is accepted by some ε –NFA iff L is accepted by NFA without ε transition.

(Or)
A language „L‟ is accepted by some NFA with ε transition iff „L‟ is accepted by some DFA.

8
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

40. Define the language accepted by NFA with epsilon transition.


The language accepted by NFA with epsilon transition M = (Q, ∑, δ, q 0, F) is denoted by L(M) and it
is defined as,
L(M)={(w/δ‟ (q0,w) contains a state in F) }
(Or)
L(M)={(w/ δ‟ (q0,w) Π F ≠ Ф)}

41. Construct the DFA that accepts input string of 0‟s and 1‟s that end with 00.
1
1 1
0 q1 0
q0 q2

1 both even number of 0‟s and even number of


42. Design DFA to accept the language L = {w | w has
1‟s}
1

q0 q1
1

0 0 0 0

1
q2 q3

43. Construct NFA with 011 as substring.


1
1/0 1/0
0 1 1
q0 q1 q2 q3

44. Define extended transition function.


The transition function „delta‟ is extended to δ‟ (or) δ‟ extended transition function that operates on
strings and states. The extended transition function describes what happens when we start in any state and
follow any sequence of inputs. If S is the transition function, then the extended transition function
constructed from S is called δ‟.

45. Give the applications of Theory of computation.


a. Compiler Design
b. Robotics
c. Artificial Intelligence
d. Knowledge Engineering

46. Construct the DFA for the following: [Nov/Dec 2011]


(a) All strings that contain exactly 4 zeroes.
(b) All strings that don‟t contain the substring 110.

9
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(a)
1
1 1
1 1
1

a b c d e
0 0
0 0
0
1 0
(b)
0 1
1
q1 q2 q3 q4

47.Draw the transition diagram (automata) for an identifier. (Nov/Dec 2013) (April/May-2024)

Letter/ digit
Start Letter
q0 q1

48. Construct finite automata for the language {0n|n mod 3=2, n ≥ 0}
Solution
L = {0n | n mod 3 = 2, n ≥0}
N = {2, 5, 8, 11, 14, …} 0
L= {02, 05, 08, 011, 014, . . .}
Start
q0 q1 q2
0 0

49. Construct NFA for set of all strings {0,1} that ends with three consecutive 1‟s at its end.

Solution:
The NFA for the given input strings {0,1} is,

1/0 0
1

Start
q0 q1 q2 q3
1 1
1

0
The strings that are accepted by given NFA is
L(M) = {111, 0111, 10111, 10111110……………}

10
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

50. Construct a DFA that will accept strings on {a,b} where the number of b‟s divisible by 3.
Solution.

DFA to accept strings on ∑ = {a,b},where the numbers of b‟s divisible by 3

q0

b
b
a

a q1 q2
b

To satisfy the condition number of b is divisible by 3, the number of b can be { 3, 6, 9, …}


So values of b is { b3, b6, b9 ….}

51. What are the Advantages & Caveats for NFA?


 Great for modeling regular expressions
 String processing
o e.g., grep, lexical analyzer
 But “imaginary”,in the sense that it has to be, implemented deterministically in practice
 Could a non-deterministic state machine be implemented in practice?
o E.g., toss of a coin, a roll of dice

52. List any four ways of theorem proving.[Nov/Dec-2024]


(i) Proof by contradiction.
(ii) Proof by contrapositive.
(iii) Proof by counter example.
(iv) Proof by principle of mathematical induction.

53. Define Automata.


Automata are the kind of machines which take some string as input. This input goes through a finite
numbers of states and may enter in the final state.

54. Construct a DFA for the language over {0,1}* such that it contains “000” as a substring.(May
2011)
1
1,0

Start
q0 q1 q2 q3
0 0 0
11
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

55. Find the set of strings accepted by the finite automata.

0,1

Q0

Set of stings S={€,0,1,00,11,000,111,10,01,…}

56. Define the term epsilon transition. May2013


In the non deterministic finite state machine, the transition that does not require input symbols for state
transition and is capable of transiting to zero or more states with € is called transition.

57. Draw a non-deterministic automaton to accept strings containing the substring 0101.
0, 1
(May/June 2016)

1 0 1 0

Start 1
0 0 1
q1 q2 q3 q4 q5
0 1
+
58. Differentiate L* and L . 1

L* denotes Kleene closure and is given by L* = U Li
i=0
Example: 0* = { ε ,0,00,000,…………..}
Language includes empty words also. ∞
L+ denotes Positive closure and is given by L+= U Li
i=1
+
Example: 0 = {0,00,000,……………………………………..}

59. Construct the finite automata for the regular expression: (a/b)*abb. April/May 2019

ε
a
ε ε
ε
2 3 ε a b b
9 1
6 7 8
0 1 0
b
4 5
ε ε

12
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

60. Write regular expression to represent exponential constants of „C‟ language. Nov/Dec 2021
RE = [0-9](. [0-9])?(E[+-]?[0-9])?

61. Define extended transition diagram. Nov/Dec 2021


The transition function „delta‟ is extended to δ‟ (or) δ‟ extended transition function that operates on
strings and states. The extended transition function describes what happens when we start in any state and
follow any sequence of inputs. If S is the transition function, then the extended transition function
constructed from S is called δ‟.
Processing the sequence Function
Basis: (q0,€)= q0
Induction: n≥1,W=xa
(q0,w)= (q0,xa)
= δ ( (q0,x),a) [ (q0,x)=P]
= (P,a)=r

62. When two states are said to be distinguished? Give example. [Nov/Dec2021]
If two states are not equivalent, then we say that both states are distinguishable states. That is, the
state p is distinguishable from state q if there is at least one string „w‟ such that one of δ(p,w) is
accepting and it reaches final state and δ(q,q) reaches non-accepting state.

63. Define hypothesis


The formal proof can be using deductive proof and inductive proof. The deductive proof consists of
sequence of statements given with logical reasoning in order to prove the first or initial statement. The
initial statement is called hypothesis.

64. Mention any four ways of theorem proving.[Nov/Dec-2024]


 Direct Proof
 Proof by Contradiction
 Mathematical Induction
 Proof by Cases

13
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

PART B
1. Define automata theory. Explain briefly about Deterministic Finite Automata.
Theory of automata is a theoretical branch of computer science and mathematical. It is the study of abstract
machines and the computation problems that can be solved using these machines. The abstract machine is
called the automata. The main motivation behind developing the automata theory was to develop methods to
describe and analyse the dynamic behaviour of discrete systems.
The behavior of these discrete systems is determined by the way that the system is constructed from storage
and combinational elements. Characteristics of such machines include:
 Inputs: assumed to be sequences of symbols selected from a finite set I of input signals. Namely,
set I is the set {x1, x,2, x3... xk} where k is the number of inputs.
 Outputs: sequences of symbols selected from a finite set Z. Namely, set Z is the set {y1, y2, y3 ...
ym} where m is the number of outputs.
 States: finite set Q, whose definition depends on the type of automaton.

There are four major families of automaton:


 Finite-state machine
 Pushdown automata
 Linear-bounded automata
 Turing machine

Deterministic Finite Automata


(i) Definition
(ii) Basic Notations
a) Transition Function
b) Transition Diagram
c) Transition Table
(iii)Extending Transition Function
(iv) Languages of a DFA
(v) Example Problem
(i) Definition
A Deterministic Finite Automata (DFA) consists of finite set of states and a finite set of input symbols. In
DFA, only a single transition occurs form one state to another state on single input symbol.
A Deterministic Finite Automata (DFA) is defined by five tuples
M = (Q, ∑, δ, q0, F)
Where
 M-Finite automata
 Q - finite, non empty set of states
 ∑- finite set of alphabets
 q0 ЄQ - the start state

14
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

 F F C Q- a set of final states


 δ a transition function (Q Х ∑  Q)

(ii) Basic Notations


Transition Function
Transition is the process of moving from one state to another state on reading an input symbol.
δ(q0,a ) = P
Where, q0 --> current state
ainput symbol
p next state

Transition diagram is a directed graph in which 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, then there is an arc labeled „a „from q to p in the
transition diagram. One state is designated as “Start” state. The final state will be indicated by double
circles. 0 ,1
0
1
q0 q1
Transition Table
The transition table is the tabular representation of the “delta” (δ) transition function of FA, whose rows
denotes the states and column denotes the input symbols.
Example:

The transition table for the above transition diagram is,


State 1
1
q0 q1 q0 q1

*q1 Φ

(iii)Extending Transition Function


Processing the sequence Function
Basis: (q0,€)= q0
Induction: n≥1,W=xa
(q0,w)= (q0,xa)
= δ ( (q0,x),a) [ (q0,x)=P]
= (P,a)=r
Example: W=10
(q0,€)= q0
(q0,1)= δ ( (q0, €),1)
= δ (q0, 1)
= q0
(q0,1)= δ ( (q0, €),1)
= δ (q0, 1)
= q0
(q0,10)= δ ( (q0, 1),0)

15
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= δ (q0, 0)
= q1

(iv) Language of DFA


The language of DFA M = (Q,∑,δ,q0,F) is denoted by L(M) and it is defined as,
L(M)={(w/δ‟ (q0,w) is in F) }
(v) Example:

Design DFA to accept the language L = {w | w has both even number of 0‟s and even number of 1‟s}

q0 q1
1

0 0 0 0

1
q2 q3

The string w=11010 1


(q0,Є ) = q0
(q0,1) = δ( (q0,Є),1) = δ(q0,1) = q1
(q0,11) = δ( (q0,1),1) = δ(q1,1) = q0
(q0,110) = δ( (q0,11),0) = δ(q0,0) = q2
(q0,1101) = δ( (q0,110),1) = δ(q2,1) = q3
(q0,11010) = δ( (q0,1101),0) = δ(q3,0) = q1
(q0,110101) = δ( (q0,11010),1) = δ(q1,1) = q0

2. Explain briefly about Non Deterministic Finite Automata.


(i) Definition
(ii) Basic Notations
d) Transition Function
e) Transition Diagram
f) Transition Table
(iii)Extending Transition Function
(iv) Languages of a NFA
(v) Example Problem
(i) Definition
An NFA has finite set of states, a finite set of input symbols with one start state and a set of
accepting states. In NFA, δ is a transition function that takes a state and a set of input symbols as argument,
but returns a set of zero, one or more states. NFA allows zero, one or more transitions from a state on the
same input symbol.

The Non-deterministic Finite Automata (NFA) is defined by a five tuple


16
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

M = (Q, ∑, δ, q0, F)
Where, Q - finite, non empty set of states
 ∑- an input alphabet
 q0 ЄQ - the start state
 FQ- a set of final states
 δ a transition function (Q Х ∑  2Q (2Q is the power set of Q)

(ii) Basic Notations


Transition Function
Transition is the process of moving from one state to another state on reading an input symbol.
δ(q0,a ) = {q0, q1}
Where, q0 --> current state
ainput symbol
p next state

Transition diagram is a directed graph in which 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, then there is an arc labeled „a „from q to p in the
transition diagram. One state is designated as “Start” state. The final state will be indicated by double
circles. 0 ,1
0
1
q0 q1
0

Transition Table
The transition table is the tabular representation of the “delta” (δ) transition function of FA, whose rows
denotes the states and column denotes the input symbols.
Example:
1
1
q0 q1

The transition table for the above transition diagram is,


State 1

q0 q0, q1

*q1 Φ

(iii)Extending Transition Function


Processing the sequence Function
Basis: (q0,€)= q0
Induction: n≥1,W=xa
(q0,w)= (q0,xa)
= δ ( (q0,x),a) [ (q0,x)={P1, P2, P3,…. Pk}
Uki=1 (Pi,a)= δ ({P1, P2, P3,…. Pk},a)
17
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= δ (p1, 1) U δ (p2, 1) …. δ (pk, 1)


={r1, r2, r3… rk}
Example: W=10
(q0,€)= q0
(q0,1)= δ ( (q0, €),1)
= δ (q0, 1)
= {q0, q1}
(q0,1)= δ ( (q0, €),1)
= δ ({q0, q1}, 1)
= δ (q0,1) U δ (q1, 1)
={q0, q1} U ᶲ
={q0, q1}

(vi) Language of DFA


The language accepted by NFA M=(Q,∑,δ,q0,F) is denoted by L(M) and it is defined as,
L(M)={(w/δ‟ (q0,w) contains a state in F) } (Or)
L(M)={(w/ δ‟ (q0,w) Π F ≠ Ф)}

3. Construct a DFA that accepts all the strings on {0, 1} except those containing the string 101.
[APRIL/MAY 2007]
Solution
The strings that are accepted by the given DFA are,
L(M) = {010, 01110, 001101100, ….}
The language of DFA M = (Q, ∑, δ, q0, F) is denoted by L(M) and it is defined as,
L(M) = {(w/ (q0,w) is in F)}

1
1 0

q0 0 q1 q2 q3
1 0

0
4. For the finite state machine M given in the following table, test whether the strings 101101, 111111
are accepted by M. (Apr/May 2007)
state 0 1
Start  * q0 [q0] [q1]
q1 [q3] [q0]
q2 [q0] [q3]
q3 [q1] [q2]

18
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Solution
The DFA for the given transition table is

0
0
1
Start
q0 q1 q2 q3
1 1
0
1

Check whether the string 101101 is accepted by the above DFA. 0


δ(q0, w) = δ(q0,Є ) = q0
Method I
The string w=101101
(q0,1) = δ( (q0,Є),1) = δ(q0,1) = q1
(q0,10) = δ( (q0,1),0) = δ(q1,0) = q3
(q0,101) = δ( (q0,10),1) = δ(q3,1) = q2
(q0,1011) = δ( (q0,101),1) = δ(q2,1) = q3
(q0,10110) = δ( (q0,1011),0) = δ(q3,0) = q1
(q0,101101) = δ( (q0,10110),1) = δ(q1,1) = q0
So the string is accepted.

Method II
The string w=1111
(q0,11111) = δ( (q0,1),1111)
= δ( (q1,1),111)
= δ( (q0,1),11)
= δ( (q1,1),1)
= δ( (q0,Є),1)
= δ(q0,1)= q1  Final State

5. Construct an NFA for the set of strings with {0, 1} ending with 01 and draw the transition table for
the same and check whether the input string 00101 is accepted by above NFA.
Solution:
The transition diagram is, 1/0

Input String = 00101 Start 0 1


q0 q1 q2
The transition table is,
19
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

0 1
 q0 {q0,q1} {q0}
q1 Φ {q2}
*q2 Φ Φ

δ(q0,0) = { q0, q1 }
δ‟(q0,00) = δ (δ(q0,0),0)
= δ ({ q0, q1 },0)
= δ (q0,0) U δ(q1,0)
= { q0, q1 } U Φ = {q0, q1}
δ‟(q0,001) = (δ‟(q0,00),1)
= δ ({ q0, q1 }, 1)
= δ(q0,1) U (q0,1)
= {q0,q2) U Φ
= {q0,q2}
δ‟(q0,0010) = δ(δ‟(q0,001), 0)
= δ( { q0,q2},0
= δ(q0,0) U δ(q2,0)
= {q0,q1} U Φ = {q0,q1}
δ‟(q0,00101) = δ(δ‟(q0,0010),1)
= δ({q0,q1},1)
= δ(q0,1) U (q1,1)
= {q0} U {q2} = {q0,q2}
δ‟ (q0,00101) ∩ F = {q0,q2} ∩ {q2} = {q2}
The string “00101” is accepted.

6. Consider the given NFA and check whether the input “abaab” is accepted or not.
The transition diagram is,
a/ b a/ b
a a
q0 q1 q2

q3

q4
a/ b

M = ({q0, q1, q3, q4}, {a, b}, δ, q0, {q2, q4})

20
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

a b
q0 {q0,q1} {q0,q3}
q1 {q2} Φ
*q2 {q2} {q2}
q3 Φ {q4}
*q4 {q4} {q4}
Input string = abaab
δ(q0,a) = {q0,q1}
δ‟(q0,ab) = δ(δ(q0,a),b)
= δ({q0,q1},b)
= δ(q0,b)Uδ(q1,b)
= ΦU{q0,q3}
= {q0,q3}
δ‟(q0,aba) = δ(δ‟(q0,ab),a)
= δ({q0,q3},a)
= δ(q0,a)Uδ(q3,a)
= {q0,q1}UΦ
= {q0,q1}
δ‟(q0,abaa) = δ(δ‟(q0,aba),a)
= δ({q0,q1},a)
= δ(q0,a)Uδ(q1,a)
= {q0,q1}U{q2}
= {q0,q1,q2}
δ‟(q0,abaab) = δ(δ‟(q0,abaa),b)
= δ({q0,q1,q2),b)
= δ(q0,b)Uδ(q1,b)U(q2,b)
= {q0,q3}UΦU{q2}
= {q0,q3,q2}
δ‟(q0,abaab)∩F = {q0,q2,q3}∩{q2,q4}
= {q2}
The string “abaab” is accepted

21
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

7. Consider the following NFA-Є and find the Є-closure of all input symbols for each state and check
whether the string “abb” is accepted.
c
b
a
Start b Є Є
q0 q1 q2

a b

Solution:
a b c Є
q0 {q0,q1} Ф Ф {q1}
q1 Ф {q1,q2} Ф {q2}
q2 Ф Ф {q2} Ф

Step 1:
Є – Closure (q0) = { q0,q1,q2 }
Є – Closure (q1) = { q1,q2 }
Є – Closure (q2) = { q2 }
Step 2:
Input String w=abb
δ (q0,Є) = Є – Closure (q0) = { q0,q1,q2 }
δ (q0,a) = Є – closure (δ (δ‟ ( q0, Є ) , a) )
= Є – closure (δ { q0, q1, q2 }), a) )
= Є – closure (δ (q0, a) U δ (q1, a) U δ (q2, a) )
= Є – closure ({ q0,q1 })
= Є – closure (q0) U Є – closure (q1)
= {q0,q1,q2}
δ „(q0,ab) = Є – closure (δ (δ‟ ( q0, a ) ,b) )
= Є – closure (δ { q0, q1, q2 }), b) )
= Є – closure (δ (q0, b) U δ (q1, b) U δ (q2, b) )
= Є – closure ({ q1,q2 })
= Є – closure (q1) U Є – closure (q2)
= {q1,q2}
22
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

δ' (q0,abb) = Є – closure (δ (δ‟ ( q0, ab ) ,b) )


= Є – closure (δ {q1, q2 }), b) )
= Є – closure (δ (q1, b) U δ (q2, b) )
= Є – closure ({ q1,q2 })
= Є – closure (q1) U Є – closure (q2)
= {q1,q2}
δ' (q0,abb) ∩ F = {q1, q2 } ∩ {q2} = {q2}  Final State
8. Construct a NFA that accepts the set of all strings {a,b} ending with “aba” as substring and
construct DFA. Use it to construct a DFA accepting the same set of strings. (May/June 2007)
Solution
The NFA for the set of all strings ending with “aba” as substring is,

a/b
a b a
q0 q1 q2 q3

9. Explain the Basic concept of Automata Theory with example.


The automata theory has a basic fundamental unit called set. The set is used to represent the mathematical
model.
Set
Set is defined as collection of objects. These objects are called elements of the set. All the elements are
enclosed within curly brackets “{“and “}” and every element is separated by commas. If „a‟ is an element of
set A then we say that a Є A and if „a‟ is not an element of A then we say that a€ A.
Typically set is denoted by a capital letter. The set can be represented using three methods.
1) Listing method
The elements are listed in the set.
For example: A set of element which is less than 5. Then, A = {0,1,2,3,4}
2) Describing properties
The properties of elements of a set define the set.
For example: A set of vowels. Hence here vowel is a property of the set which defines the set as:
A = {a, e, i, o, u}
3) Recursion method
The recursion occurs to define the elements of the set.
For example: A = { x | x is square of n} where n≤10.
This defines the set as:
23
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

A = {0, 1, 4, 9, 16,…….100}
Subset: The subset A is called subset of set B if every element of set A is present in set B but reverse is not
true. It is denoted by A C B. For example: A = { 1,2,3} and B={1,2,3,4,5} then A CB.
Empty set: The set having no element .it is denoted by A={} and it can written as Ø.
Null string: the null element is denoted by Є. Null element means no value character.
Power set: the power set is a set of all the subsets of its elements.
For example: A = {1,2,3}
Then power set Q={ Ø, {1},{2},{3},{1,2},{1,3},{3,2},{2,3},{1,2,3}}
The number of elements are always equal to 2 n where n is number of elements in original set. As in set A
there are 3 elements. Therefore in power set Q there are 2 3 = 8 elements.
Equal set: the two sets are said to be equal (A=B) if ACB and BCA i.e. every element of set A is an element
of B and every element of B is an element of A.
For example:
A = {1, 2, 3} and B={1,2,3} then A=B.
|A| denotes the length of set A. i.e. number of elements in set A.
For example: if A = {1,2,3,4,5} then |A|=5
Operations on set
Various operations that can be carried out on set are
i) Union
A U B is union operation – If A = {1,2,3} B={1,2,4} then A U B = {1,2,3,4} i.e. combination of both the
sets.
ii) Intersection
A ∩ B is intersection operation – if A={1,2,3} and B={2,3,4} then A ∩ B ={1,2} i.e., collection of common
elements from both the sets.
iii) Difference
A – B is the difference operation – If A = {1, 2, 3} and B = {2, 3, 4} then A – B = {1} i.e. elements which
are there in set A but not in set B.
iv)  is a complement operation – If  = U – A where U is a universal set.
For example:
If U = {10, 20, 30, 40, 50}
A = {10, 20} Then  = U – A = {30, 40, 50}
Cartesian product of Two sets.

24
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The Cartesian product of two sets A and B is a set of all possible ordered pairs whose first component is
member of A and whose second component is member of B. the Cartesian product if denoted by A X B =
{{a, b} | a Є A and b Є B}
For Example: Let A = {a, b} and B = {0, 1, 2}
Then the Cartesian product of A and B is, A X B={(a,0,(a,1),(a,2),(b,0),(b,1),(b,2)}
Cardinality of sets
The cardinality of the set means the number of members in the set. These sets A 1 and A2 have the same
cardinality as there is one to one mapping of the elements of A1 and A2. The different cardinalities of set
can be one to one, one to many, many to one, many to many.
Relations
Relationship is a major aspect between two objects; even this is true in our real life. One object can be
related with the other object by a „mother of‟ relation. Then those two objects form a pair based on this
certain relationship.
Definition: the relation R is a collection for the set S which represents the pair of elements.
For example: (a, b) is in R. we can represent their relation as a R b. the first component of component of
each pair is chosen from a set called domain and second component of each pair is chosen from a set called
range.
Properties of Relations
A relation R on set S is
1. R is reflexive if (a,a) Є R for each a Є A.
2. R is “symmetric” if (b,a) Є R whenever (a,b) Є R.
3. R is “antisymmetric” if whenever (a,b) and (b,a) are both in R, then a=b,
4. R is “transitive” if(a,b) Є R and (b,c) Є R then (a,c) ЄR.

Equivalent relation
A relation is said to be equivalence relation if it is reflexive, symmetric and transitive, over some set S.
Suppose R is a set of relations and S is the set of elements.
For example: S is the set of lines in a plane and R is the relation of lines intersection to each other.
Example: Determine whether R is equivalence relation or not where
A={0,1,2}, R={(0,0),(1,0),(1,1)(2,2),(2,1) }
Solution: the R is reflexive because (0,0) (1,1)(2,2) Є R. where R is not symmetric
Closures of Relations
Sometimes when the relation R is given, it may not be reflexive or transitive.
By adding some pairs we make the relation as reflexive or transitive.

25
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

For example: Let {(a,b),(b,c),(a,a),(b,b)}


Now this relation is not transitive because (a,b),(b,c) is there in relation R but (a,c) is not there in R so we
can make the transitive closure as {(a,a),(b,b)(a,b),(b,c),(a,c)}
We can even define reflexive closure and symmetric closure in the same way.
Kleen Closures
The kleen closure is also called star closure. This is set of strings of any length(including null string Є).
Each string is obtained from input set Σ the kleen star of the empty language Ø is the empty string Є.
Example:
Let Σ={a, b} obtain Σ*= Σ0 U Σ1 U Σ2 U ………
Solution Σ* = { Є, a, b, aa, bb, ba, ab, aba, aaa, bbb, baba, abaab,…….} is a set of string of any length. The
+
positive closure Σ can be defined as Σ1 U Σ2 U Σ3 U………. that means it consists of the strings of any
length except a null string.
Function
A function or a map from a set X into a set Y is a rule which assigns to every element x in X a unique
element in Y which is denoted by f(x) i.e. f: XY
1. f: AB is “ one to one (injective)” if distinct a, a1 Є A, f(a) ≠ f(a1).
2. f: A B is “onto( surjective)” if, for all b Є B, there is some a Є A such that f(a)=b
3. A “total function f” if “bijective” if it is both “one to one” and “onto”

Example:
Let A = {1,2} B = {3,4}
f1 = {(1,3),(2,4)} is bijective
f2 = {(1,4),(2,4)} is neither “one to one” nor “onto”

10. Briefly discuss about the introduction to formal proof.


FORMAL PROOF
Formal proof is one in which step by step procedure is used to solve the problem.
Testing the program is so important, but if our program is very complex that involving the
recursion or iteration, then our code may become incorrect.
To make the iteration or recursion to be correct, then we need to set up an inductive hypothesis and it
helps to reason that the hypothesis is consistent with iteration or recursion.
This process of analyzing the working of a correct program is similar to proving the theorems by
inductive or induction.
Automata theory is used to cover the methodologies of formal proof. The proof may be of,

26
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

 Deductive Formal Proof


o Consists of a sequence of justified steps.
 Inductive Formal Proof
o Recursive proof of a parameterized statement that use the statement itself with lower
values of the parameter.
Methods of formal proof involves,
 Deductive proof
 Reduction to definitions
 Other Theorem forms
 Theorems that appear not to be If-then
DEDUCTIVE PROOF
A deductive proof consists of a sequence of statements whose truth leads from some initial statements called
“hypothesis” or the given statement to a conclusion statement.
Each step in the proof must follow by some accepted logical principle from the given facts or some of the
previous statements in the deductive proof.
Hypothesis consists of independent statements connected by a logical AND. The format is,
“If H then C”
Where,
H  Hypothesis, C Conclusion
Example:
If x>=4, then 2 x >= x 2
REDUCTION TO DEFINITION
If we are not sure how to start a proof, then convert all terms in the hypothesis to their definitions.

Example:
 A set is finite if there is an integer „n‟ such that S has exactly „n‟ elements. Here we define |S|=n
where S is used to denote the number of elements in set „S‟. If the set „S‟ is not finite, then S is
infinite set and it contains more than any integer number of elements.
 If S and T are both subsets of some set U, then T is the complement of S if S U T= U and S ∩ T = Ф.
The definitions are,
o Each element of U is in exactly one of S and T
o T consist of exactly those elements of U that are not in „S‟.
OTHER THEOREM FORMS
 If – Then forms:
27
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The “If-then” forms can be expressed in four ways and they are,
o H implies C
o H only if C
o C if H
o Whenever H holds, C follows
Example
 X ≥ 4 implies 2 x ≥ x 2
 X ≥ 4 only if 2 x ≥ x 2
 2 x ≥ x 2 if x ≥ 4

THEOREMS NOT TO BE IF-THEN STATEMENTS
There are some theorems in which there is no hypothesis. For example,
Sin 2 Ө + cos 2 Ө =1
But in this example, the hypothesis is indirectly present, that is an angle.
So if “Ө is an angle “, then “Sin2 Ө + cos2 Ө =1”

11. Briefly discuss about the additional forms of proof. [Nov/Dec2012]


ADDITIONAL FORMS OF PROOF
 Proofs about sets
 Proofs by contradiction
 Proofs by counter example
(i) Proving Equivalence about sets
The set is a collection of elements or items. By giving proofs about the sets we try to prove certain
properties of the sets.
If E and F are two expressions representing sets, the statement E=F means that the two sets
represented are the same. We can prove the equivalence of sets E=F in the following ways,
 By commutative law of union of two sets R and S as RUS=SUR and E is the expression for
RUS and F is the expression for SUR and by the commutative law of union, we can conclude
that E=F.
 We can prove the set equality E=F by if and only if statement, that is “an element x is in E if
and only if x is in F”
 The set equality E=F can be proved by two if statements as follows,
o If x is in E, then x is in F

28
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

o If x is in F, then x is in E
Contra positive
The contrapositive of the statement “if H then C”, is “if not C then not H”, and it is represented as,
HC==> 7C7H.
To prove that “if H then C” and “if not C, then not H” are logically equivalent, there are four cases to
consider.
 H and C both true
 H true and C false
 C true and H false
 H and C both false

(ii) Proof by Contradiction


To prove the statement “if H then C” is by the form,
H and not C implies Contradiction
Here we assume that the hypothesis and the negation of the conclusion as true and then we complete the
proof by showing the something known to be false. This form of proof is called “Proof by contradiction”
Theorems means that the statements about an infinite number of cases.
Observations means that the statements with finite number of values.
(iii)Proof by Counter examples
Sometimes we need to prove whether the theorem itself is true or false. It is easy to prove that
a statement is not a theorem than to prove it is a theorem.
Example I:
Theorem :All primes are odd.
Proof: If x is integer and x is prime, then x is odd.
Disproof: The integer 2 is prime, but 2 is even.

Example II:
Theorem: There is no pair of integers a and b such that “a mod b = b mod a”.
Proof: If a=2 and b=3 are integers, then
2 mod 3≠ 3 mod 2.
Disproof:
Let a = b = 2, then
a mod b = b mod a, when a=b
2 mod 2 = 2 mod 2 =0
29
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

12. Briefly discuss about the inductive proof. [Nov/Dec2012][April/May 2024]


INDUCTIVE PROOF
Inductive proof deals with recursively defined objects like trees and expressions of various sorts,
such as regular expression.
 Induction on integers
 Structural Inductions
 Mutual Induction
It is also called as proof by mathematical. The proof by mathematical induction can be carried out using
steps
1. Basis: In this we assume the lowest possible value. This is an initial step in the proof of mathematical
induction.
For example,we can prove that the result is true for n=0 or n=1
2. Induction hypothesis: In this step we assign value of n to some value K.That mean we will check
whether the result is true for n=k or not.
Induction on Integers
Suppose if we are given a statement S(n) about an integer „n‟ which is to be proved and we can prove
two things.
1. Basis: We prove S(n) then S(n+1)
2. Induction : If S(n) then S(n+1)
Basis:
Assume n ≥i where „I‟ is the basis integer.
Induction:
Here we have a number of base cases such as,
“s(i) s(i+1) s(i+2)…. s(n)”
Induction Principle:
If we prove S(i) and we prove that for all n ≥ i S(n) implies S(n+1), then we conclude S(n) for all n ≥ i.
Example 1:
Prove the following by induction for all n=0 [APRIL/MAY 2007]
1 2+ 2 2+3 2+….n 2= n(n+1)(2n+1)
____________
6
(OR)
n=1
∑ n(n+1)(2n+1)
30
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

k n2= ____________
6

Solution:
n(n+1)(2n+1)
Let S(n) = 1 2+ 2 2+3 2+….n 2____________
6

Basis
0(0+1)(0+1)
: Let n=0  0 = ----------------- =0
6

1(1+1)(2+1)
n=1  12 = -------------------
6
1(2)(3)
1 = ---------
6
1=1

2(2+1)(4+1)
n=2  12+22 = --------------------
6
2 (3) (5)
1+4 = ------------- Therefore 5=5 Hence Proved
6

Inductive Step: k ≤ n

S(n) = 1 2+ 2 2+3 2+….n 2= n(n+1)(2n+1)


------------------
6
is true for all n values. S(n) is true for all k ≤ n, so now we have to prove S(n+1) is also true.

S(n+1) = 1 2+ 2 2+3 2+….+(n+1) 2 = (n+1)(n+2)(2(n+1)+1)


---------------------------

6
LHS:
S(n+1) = 1 2+ 2 2+3 2+….+(n+1) 2

n(n+1)(2n+1)+ (n+1)2 n(n+1)(2n+1)+6(n+1)2


-------------------------- ------------------------
6 6
(n+1)[n(2n+1)+6(n+1)] ( n+1) [2n 2+n+6n+6]
= -------------------------- = -----------------------
6 6
(n+1)[2n 2+7n+6]
31
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= _______________
6
(n+1)[n+2][2n+3]
= _______________
6
( n+1) [(n+1)+1][2(n+1)+1]
= ______________________
6
= RHS Hence proved.

So S(n+1) is also true. Hence,

S(n) = 1 2+ 2 2+3 2+….n 2= n(n+1)(2n+1)


___________
6
n n
Example 2: Prove that S(n) = a – b is divisible by a-b for all n>0.
Solution:
Given:
For n>0, an – bn is divisible by a-b.
Basis:
n=1  a - b is divisible by a-b
n=2  a2 – b2 is divisible by a – b
Inductive step:
S(n) is true for k ≤ n such that, S(n) = an – bn is divisible by a-b is true
To prove S(n+1)= an+1 – bn+1 is also divisible by a-b
LHS
S(n+1)= an+1 - bn+1 = a . an – b . bn
We know that  S(n) = (an – bn) / (a-b) = k where k is constant
an – bn= k (a-b)
an = bn+ k (a-b)
Sub (2) in equation (1)
= [ bn +k(a-b)] a – b n. b= [ k(a-b)+bn] a- bn . b
=k(a-b) a+bn a – bn . b
= ka(a-b)+bn (a-b)
=(a-b) [ka+bn] is divisible by (a-b). Hence proved
Thus S(n+1)= an+1- bn+1 is also divisible by a-b.
So S(n) = an – bn is divisible by 3.

32
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

STRUCTURAL INDUCTIONS
In Automata, there are several recursively defined structures such as trees and expressions. The
structural induction deals with the recursive definition that has a basis case in which one or more
elementary structures are defined. There is an inductive step, where more complex structures are defined in
terms of previously defined structures.
Example 1: The recursive definition of a tree.
Basis: A single node is a tree, and that node is the root of the tree.
Induction: If T1, T2…. Tk are trees, and then we can form a new tree as follows,
 Begin with a new node N, which is the root of the tree
 Add copies of all the trees T1, T2, … Tk
 Add edges from node N to the roots of each of the trees T 1,T2, … Tk

T1 T2 Tk

STRUCTURAL INDUCTION (Formal Definition)


Let s(x) be a statement about the structures „x‟ that are defined by some particular recursive definition.
By Basis, prove S(x) for the basis structure x.
For inductive step, take a structure „x‟ that the recursive definition says that it is formed from y1, y2,…,yk.
Assume the statements s(y1),s(y2)…s(yk) and use these to prove s(x).
Our conclusion is that s(x) statement is true for all x.
MUTUAL INDUCTIONS
Sometimes, we cannot prove a single statement by induction and we may need to prove the group
of statements S1(n),S2(n),….Sk(n) together by the induction „n‟.
Automata theory involves proving the group of statements, one for each state. Proving the group of
statements is similar to proving the conjunction of all the statements.
For example, the group of statements, S1(n), S2(n)….Sk(n) can be replaced by the single statement as,
S1(n) AND S2(n) AND … AND Sk(n)
When there are several independent statements to prove, then we keep the statements separate and to
prove them all in their own parts of the basis and inductive step. This form of proof is called Mutual
Inductions.

33
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

13. Explain the extended transition function for NFA, DFA and NFA – ε[Nov/Dec 2007]
Extended Transition Function for DFA
The transition function „δ‟ is extended to δ‟ (or) δ‟ extended transition function that operates on
strings and states. The extended transition function describes what happens when we start in any state and
follow any sequence of inputs. If δ is the transition function, then the extended transition function
constructed from δ is called δ‟.
The extended transition function δ‟ that takes a state „q‟ and a string „w‟ and reaches the state „s‟.
That is δ‟ reaches the state„s‟ from „q‟ after processing the sequence of the string „w‟.
Basis:
δ‟ (q, Є) = q  If we are in state q and read no input then we are in state q itself
Induction:
Suppose „w‟ is the string of the form „xy‟, then
δ‟ (q, w) = δ‟ (q, xy) = δ (δ‟ (q, x), y)
For example if the string w=1101. Then the last symbol „1‟ is given to y and the remaining is x. So x=110
and y=1.

Extended Transition Function for NFA


Extending the transition function δ of an NFA to an extended transition function δ‟ that takes a state q and a
string of input symbols w and returns the set of states that the NFA is in starting state q and process the
string w.
Basis:
δ‟ (q, Є) = { q } => If we are in state q and read no input then we are in state q itself. Without reading input
NFA remains in the same state.
Induction:
Suppose „x‟ is the string of the form „wa‟, then
δ‟ (q, x) = δ‟ (q, w) = { P1, P2……Pk }
and

Therefore
δ‟ (q, wa) = δ‟ (q, x) = { R1, R2…..Rn }
The language accepted by NFA M= (Q, Є, δ, q0, F) is denoted by L (M) and it is defined as,
L (M) = { w/ δ‟ (q0, w) contains a state in F) }
34
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(Or)
L (M) = { w/ δ‟ (q0, w) ∩ F ≠ Φ }
Extended Transition Function for NFA-Є
The NFA – Є transition function is extended to δ‟ as δ‟ = Q X Σ*  2Q ,
such that δ‟ (q0, w)
reaches the states p such that, NFA with Є from state q0 on input symbol w reaches p including Є as
transition for an empty input string.
The Є – closure of q0 is (Є – closure (q0)) denotes the set of all states p such that there is a path (or)
transition from q0 to p on Є transition.
Let P be the set of all states { P1, P2,….Pi}
 Then Є – closure (p) = Ū Є – Closure (q)
δ‟ transition function is defined as follows,
Basis:
δ (q, Є) = Є – Closure (q)
Induction:
δ‟ (q, wa) = Є – Closure (P)
Where P= {P/for some r in δ (q, w), P in δ (r, a) }
δ (q, w) = Є- Closure (R)
δ (R, a) = Є – Closure (P)
δ (q, wa) = Ū Є closure (P)
p in R
The language accepted by NFA with Є transition is,
L (M) = { w/ δ (q0, w) contains a state is F }

14. Give Deterministic finite automata accepting the following language over the alphabet. (Nov/Dec
2013) ][April/May 2024]
(1) Number of 1‟s is a multiples of 3 0
0 0

Start 1 1 1
q0 q1 0 q2 0 q3

1
0
L= { 111, 111111, 111111111, …………………………………}

35
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Method I
The string w=111111
(q0,1) = δ( (q0,Є),1) = δ(q0,1) = q1
(q0,11) = δ( (q0,1),1) = δ(q1,1) = q2
(q0,111) = δ( (q0,11),1) = δ(q2,1) = q3
(q0,1111) = δ( (q0,111),1) = δ(q3,1) = q1
(q0,11111) = δ( (q0,1111),1) = δ(q1,1) = q2
(q0,111111) = δ( (q0,11111),1) = δ(q2,1) = q3
So the string is accepted.
(2) Number of 1‟s is not a multiples of 3.
0
0 0

Start 1 0 1
q0 q1 0 q2 0 q2

1
0
15. Draw transition diagram for recognizing the set of all operators in C language.[NOV/DEC 2007]
Transition Diagram for relational operators

Start < =
0 1 2 return(relop, LE)

>
3 return(relop, NE)

other
4 *return(relop, LT)
<
5 return(relop, EQ)

<
< 6 7 return(relop, GE)

other
8 *return(relop, GT)

36
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

16. Write a note on NFA and compare with DFA. (6)


 A nondeterministic finite automaton has the ability to be in several states at once.
 Transitions from a state on an input symbol can be to any set of states.
Let Q be a finite set and let be a finite set of symbols. Also let be a function from Q X to 2Q , let q0
be a state in Q and let A be a subset of Q. We call the elements of Q a state, the transition function, q0
the initial state and F the set of accepting states.
Then a nondeterministic finite automaton is a 5-tuple { Q , , q0 , ,F}
Notes on the definition

1. As in the case of DFA the set Q in the above definition is simply a set with a finite number of
elements. Its elements can be interpreted as a state that the system (automaton) is in.

2. The transition function is also called a next state function. Unlike DFAs an NFA moves into one of
the states given by (q, a) if it receives the input symbol a while in state q. Which one of the states
in (q, a) to select is determined non-deterministically.

3. Note that is a function. Thus for each state q of Q and for each symbol a of (q, a) must be
specified. But it can be the empty set, in which case the NFA aborts its operation.

4. As in the case of DFA the accepting states are used to distinguish sequences of inputs given to the
finite automaton. If the finite automaton is in an accepting state when the input ends i.e. ceases to
come, the sequence of input symbols given to the finite automaton is "accepted". Otherwise it is not
accepted.

5. Note that any DFA is also a NFA.

Transition Function of an NFA

 δ(q, a) is a set of states.

 Extend to strings as follows:

 Basis: δ(q, ε) = {q}

 Induction: δ(q, wa) = the union over all states p in δ(q, w) of δ(p, a)

Language of an NFA
 A string w is accepted by an NFA if δ(q0, w) contains at least one final state.
 The language of the NFA is the set of strings it accepts.

37
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Comparison between NFA and DFA


1. “DFA” stands for “Deterministic Finite Automata” while “NFA” stands for “Nondeterministic
Finite Automata.”
2. Both are transition functions of automata. In DFA the next possible state is distinctly set while in
NFA each pair of state and input symbol can have many possible next states.
3. NFA can use empty string transition while DFA cannot use empty string transition.
4. NFA is easier to construct while it is more difficult to construct DFA.
5. Backtracking is allowed in DFA while in NFA it may or may not be allowed.
6. DFA requires more space while NFA requires less space.
7. While DFA can be understood as one machine and a DFA machine can be constructed for every
input and output.
8. NFA can be understood as several little machines that compute together, and there is no
possibility of constructing an NFA machine for every input and output.

17. Construct NFA with € which accepts a language consisting the strings of any number of a‟s
followed by any number of b‟s followed by any number of c‟s.

Solution: b c
a

Start €
q0 € q1 q2

W= aabbcc
δ(q0, w) = δ(q0,Є ) = q2
Method I
The string w=aabbcc
(q0,a) = δ( (q0,Є),a) = δ(q0,a) = q0
(q0,aa) = δ( (q0,a),a) = δ(q0,a) = q0
(q0,aab) = δ( (q0,aa,b) = δ(q1,b) = q1
(q0,aabb) = δ( (q0,aab),b) = δ(q1,b) = q1
(q0,aabbc) = δ( (q0,aabb),c) = δ(q2,c) = q2
38
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(q0,aabbcc) = δ( (q0,aabbc),1) = δ(q2,c) = q2 So the string is accepted.

18. Construct a DFA accepting all string w over {0,1},such that number of 1‟s in w is 3 mod 4. (Dec-11
8 mark)

0
0 0 0 0

Start 1 1 1
q0 q1 0 q2 0 q2

1
0
19. Given ∑={a,b}, construct a DFA which recognize the language L={b m a bn :m,n>0}
b
b 0

Start b a b
q0 q1 0 q2 0 q2

Solution
The strings that are accepted by the given DFA are,
L(M) = {a,bab, bbabb, ….}
The language of DFA M = (Q, ∑, δ, q0, F) is denoted by L(M) and it is defined as,
L(M) = {(w/ (q0,w) is in F)}
The transition diagram is,
b
b

Start a
q0 q1

Input String = 00101


The transition table is,
a b
 q0 q1 q0
*q1 Φ q1
The string w=bab
39
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(q0, Є) = q0
(q0,b) = δ( (q0, Є),b) = δ(q0,b) = q0
(q0,ba) = δ( (q0,b),a) = δ(q0,a) = q1
(q0,bab) = δ( (q0,ba),b) = δ(q1,b) = q1  Final State
The string bab is accepted.

20. Prove for every n>=1 by Mathematical induction ∑ni3={n(n+1)/2}2 [Nov/Dec 2024]

 Statement P (n) is defined by

1 3 + 2 3 + 3 3 + ... + n 3 = n 2 (n + 1) 2 / 4

STEP 1: We first show that p (1) is true.

Left Side = 1 3 = 1

Right Side = 1 2 (1 + 1) 2 / 4 = 1

hence p (1) is true.

STEP 2: We now assume that p (k) is true

1 3 + 2 3 + 3 3 + ... + k 3 = k 2 (k + 1) 2 / 4

 add (k + 1) 3 to both sides

1 3 + 2 3 + 3 3 + ... + k 3 + (k + 1) 3 = k 2 (k + 1) 2 / 4 + (k + 1) 3

 factor (k + 1) 2 on the right side

= (k + 1) 2 [ k 2 / 4 + (k + 1) ]

 set to common denominator and group

= (k + 1) 2 [ k 2 + 4 k + 4 ] / 4

= (k + 1) 2 [ (k + 2) 2 ] / 4

 We have started from the statement P(k) and have shown that

1 3 + 2 3 + 3 3 + ... + k 3 + (k + 1) 3 = (k + 1) 2 [ (k + 2) 2 ] / 4
Which is the statement P(k + 1).
40
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

21. Prove the equivalence of NFA and DFA using subset function (Nov/Dec 2013). Or
Construct a NFA that accepts all strings that end in 01. Give its transition table and extended
transition function for the input string 00101.Also construct a DFA that the above NFA using subset
construction method.(Nov/Dec 2016)
Equivalence of NFA and DFA
If a Regular Language „L‟ is accepted by a Non-deterministic Finite Automata then there exist a
Deterministic Finite Automata that accepts „L‟. (Or)
A Regular Language „L‟ is accepted by some DFA if and only if „L‟ is accepted by some NFA (Non-
deterministic Finite Automata) (Or)
As every DFA is an NFA, the classes of languages accepted by NFA‟s includes the classes of languages
accepted by Deterministic Finite Automata(DFA) (Or) DFA can simulate NFA
Equivalence of DFA and NFA
NFA‟s are usually easier to “program” in. Surprisingly, for any NFA N there is a DFA D, such that
L(D) = L(N), and vice versa. This involves the subset construction, an important example how an automaton
B can be generically constructed from another automaton A.
Solution:
Step 1: Construct a NFA
L={01,101,001,1101,…}
0,1

0 1
Start q0 q1 q2

Step 2: transition table for NFA


The transition table is,
0 1
 q0 {q0, q1} q0
q1 Φ q2
*q2 Φ Φ
Step 3: Extended Transition function
W= 001
(q0,€)= q0
(q0,0)= δ ( (q0, €),0)
= δ (q0, 0)
41
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= {q0, q1}
(q0,00)= δ ( (q0,0),0)
= δ ({q0, q1}, 0) = δ(q0,0) U δ(q1,0)
= {q0, q1}
(q0,001)= δ ( (q0,00),1)
= δ ({q0, q1}, 1) = δ(q0,1) U δ(q1,1)
= {q0, q1}
The given string is accepted
Subset construction method: Convert from NFA to minimize DFA
Definition:
The number of states of the DFA can be exponential in the number of states of NFA

If D = (QD, Σ, δD, {q0}, FD) constructed from NFA


N = (QN, Σ, δN, q0, FN) by the subset construction then
L(D) = L(N)
The following steps will show how the construct a DFA from an NFA
1) QD is the set of all subsets of QN (i.e. QD = 2QN)
QD = {S: S ⊆ QN}.

Note: |QD| = 2 |QN | , although most states in QD are likely to be garbage.


2) FD = {S ⊆ QN : S ∩ FN ≠ ∅}
3) For every S ⊆ QN and a ∈ Σ,

δD(S, a) = δN(p, a)

Example: Let‟s construct δD from the below NFA Diagram.

0,1

0 1
Start q0 q1 q2

42
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Note: The states of D correspond to subsets of states of N, but we could have denoted the states of D by, say,
A − F just as well.

We can often avoid the exponential blow-up by constructing the transition table for D only for accessible
states S as follows:
Basis: S = {q0} is accessible in D Induction: If state S is accessible, so are the states in Ū a∈Σ {δD(S, a)}
Example: The “subset” DFA with accessible states only.

0 1
Ø Ø Ø
 {q0} {q0, q1} {q0}
{q0, q1} {q0, q1} {q0, q2}
*{q0, q2} {q0, q1} {q0}

43
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Theorem 2.11:
Let D be the “subset” DFA of an NFA N. Then L(D) = L(N).
Proof: First we show an induction on |w| that
δˆD({q0}, w) = δˆN(q0, w)
Basis: w = ε. The claim follows from def.
Induction: δˆD({q0}, xa)  δD(δˆD({q0}, x), a)
 δD(δˆN(q0, x), a)

 δˆN(q0, xa)

Now it follows that L(D) = L(N).

Theorem 2.12:
 A language L is accepted by some DFA if and only if L is accepted by some NFA.
 Proof: The “if” part is Theorem 2.11.
 For the “only if” part we note that any DFA can be converted to an equivalent NFA by modifying the
δD to δN by the rule
o If δD(q, a) = p, then δN(q, a) = {p}.
 By induction on |w| it will be shown in the tutorial that
o if δˆD(q0, w) = p, then δˆN(q0, w) = {p}.

44
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Problems for Conversion of NFA to DFA


22. Explain the steps in conversion of NFA to DFA. Convert the following NFA to DFA. (8).
(Nov/Dec 2013)
Figure shows a nondeterministic finite automaton, whose job is to accept all and only the strings of 0‟s and
1‟s that end in 01. State q0 is the start state, and we can think of the automaton as being in state q0 whenever
it has not yet “guessed” that the final 01 has begun. It is always possible that the next symbol does not begin
the final 01, even if that symbol is 0. Thus, state q0 may transition to itself on both 0 and 1.

1/0
0 1
q0 q1 0 q2

However, if the next symbol is 0, this NFA also guesses that the final 01 has begun. An arc labeled 0 thus
leads from q0 to state q1. Notice that there are two arcs labeled 0 out of q 0. The NFA has the option of going
either to q0 or to q1, and in fact it does both, as we shall see when we make the definitions precise. In state
q1, the NFA checks that the next symbol is 1, and if so, it goes to state q 2 and accepts.
Notice that there is no arc out of q1 labeled 0, and there are no arcs at all out of q2. In these situations, the
thread of the NFA‟s existence corresponding to those states simply “dies”, although other threads may
continue to exist. While a DFA has exactly one arc out of each state for each input symbol, an NFA has no
such constraint; we have seen in Figure cases where the number of arcs is zero, one, and two, for example.
Solution
The transition table for above NFA is,
0 1
q0 {q0,q1} q0
q1 Φ {q2}
*q2 Φ Φ

Starting state = {q0} in NFA.


For DFA, {q0}= [q0] in NFA  A
The input symbols are 0,1 and let δN be the transition of NFA and δD be the transition of DFA.
Step 1
(A,0) δN ({q0}, 0) = {q0,q1}
So δD ([q0], 0) = [q0,q1] B
(A,1) δN ({q0},1) = {q0}
So δD([q0],1) = [q0]  A
45
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 2
(B,0) δN ({q0,q1}, 0) = δ(q0,0) U δ(q1,0)
= {q0,q1} U Φ
= { q0,q1}
So δD ([q0,q1],0) = [q0, q1] B
(B,1) δN({q0,q1},1) = δ(q0,1) U δ(q1,1)
= {q0} U{q2}
= {q0,q2}
So δD ([q0,q1],1) = [q0,q2] C
Step 3
(C,0) δN({q0,q2},0) = δ(q0,0) U δ(q2,0)
= {q0,q1} U Φ
= {q0,q1}
So δD([q0,q2],0) =[q0,q1] B
(C,1) δN ({q0,q2},1) = δ(q0,1) U δ(q2,1)
= {q0} U Φ = {q0}
So δD([q0,q2],1) = [q0] A
Transition table for DFA

1 0

0 [q0,q1]
[q0]

0
1 1

[q0,q2]

0 1
[q0] [q0,q1] [q0]
[q0,q1] [q0,q1] [q0,q2]
*[q0,q2] [q0,q1] [q0]

46
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

23. Consider the following NFA-Є and find the Є-closure of all input symbols for each state and check
whether the string “abb” is accepted.

c
b
a
Start b Є Є
q0 q1 q2

a b
Solution:
a b c Є
q0 {q0,q1} Ф Ф {q1}
q1 Ф {q1,q2} Ф {q2}
q2 Ф Ф {q2} Ф
Step 1:
Є – Closure (q0) = { q0,q1,q2 }
Є – Closure (q1) = { q1,q2 }
Є – Closure (q2) = { q2 }
Step 2:
Input String w=abb
δ (q0,Є) = Є – Closure (q0) = { q0,q1,q2 }
δ (q0,a) = Є – closure (δ (δ‟ ( q0, Є ) , a) )
= Є – closure (δ { q0, q1, q2 }), a) )
= Є – closure (δ (q0, a) U δ (q1, a) U δ (q2, a) )
= Є – closure ({ q0,q1 })
= Є – closure (q0) U Є – closure (q1)
= {q0,q1,q2}
δ „(q0,ab) = Є – closure (δ (δ‟ ( q0, a ) ,b) )
= Є – closure (δ { q0, q1, q2 }), b) )
= Є – closure (δ (q0, b) U δ (q1, b) U δ (q2, b) )
= Є – closure ({ q1,q2 })
= Є – closure (q1) U Є – closure (q2)
= {q1,q2}
δ' (q0,abb) = Є – closure (δ (δ‟ ( q0, ab ) ,b) )
47
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= Є – closure (δ {q1, q2 }), b) )


= Є – closure (δ (q1, b) U δ (q2, b) )
= Є – closure ({ q1,q2 })
= Є – closure (q1) U Є – closure (q2)
= {q1,q2}
δ' (q0,abb) ∩ F = {q1, q2 } ∩ {q2} = {q2}  Final State

24. Convert to a DFA, the following NFA. [MAY/JUNE 2013] [April/May 2024]
δ a b
p {p} {p,q}
q {r} {r}
*r {Φ} {Φ}
Solution
NFA transition diagram for the above NFA is,

a/b
b a/b
Start r
b p q

Starting state = {p}

For DFA,
{q0}= [q0] in NFA  A
Step 1
(A,a) δN({p},a) = {p}
So δD ([p],a) = [p] A
(A,b) δN ({p},b) = {p,q}
So δD([p],b) = [p,q] B
Step 2
(B,a) δN ({p,q},a) = δ (p,a) U δ (q,a)
= {p} U {r}
= {p,r}
So δD ([p,q] , a) = [p,r] C
(B,b) δN({p,q},b) = δ(p,b) U(q,b)
= {p,q} U {r}
48
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

={p,q,r}
So δD ([p,q],b) = [p,q,r] D
Step 3
(C,a) δN({p,r},a) = δ (p,a) U δ(r,a)
= {p} U ф
={p}
So δD ([p,r],a) = [p] A
(C,b) δN({p,r},b)= δ(p,b) U δ(r,b)
= {p,q} U Φ
= {p,q}
So δD([p,r],b) = [p,q] B
Step 4
(D,a) δN({p,q,r},a) = δ(p,a) U δ(q,a) U δ{r,a}
= {p} U {r} U Φ
= {p,r}
So δD([p,r],0) = [p,r] D
(D,b) δN({p,q,r},b) = δ(p,b) U δ (q,b) U δ(r,b)
= {p,q} U {r} U Φ
= {p,q,r}
So δD([p,q,r],b) = [p,q,r] D
The transition table for the DFA is shown below,
A b
[p] [p] [p,q]
[p,q] [p,r] [p,q,r]
*[p,r] [p] [p,q]
*[p,q,r] [p,r] [p,q,r]

DFA Transition Diagram


b
a
b
[p,q] [p,q,r]
[p]

a b
a
a
[p,r]
49
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

25. Convert to a DFA, the following NFA.


0 1
p {p,q} {p}
q {r} {r}
r {s} Φ
*s {s} {s}
Solution
NFA transition diagram for the above NFA is,

1/0
1/0
0 0 0
p q r s
Starting state = {p}
For DFA,
1
{q0}= [q0] in NFA  A
Step 1
(A,0) δN({p},0) = {p,q}
So δD ([p],0) = [p,q] B
(A,1) δN ({p} ,1) = {p}
So δD([p],1) = [p] A
Step 2
(B,0) δN ({p,q},0) = δ (p,0) U δ (q,0)
= {p,q} U {r}
= {p,q,r}
So δD ([p,q] , 0) = [p,q,r] C
(B,1) δN({p,q},1) = δ(p,1) U(q1,1)
= {p} U {r}
={p,r}
So δD ([p,q],1) = [p,r] D
Step 3
(C,0) δN({p,q,r},0) = δ (p,0) U δ(q,0) U δ(r,0)
= {p,q} U {r} U {s}
= {p,q,r,s}
So δD ([p,q,r],0) = [p,q,r,s] E
50
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(C,1) δN({p,q,r},1) = δ(p,1) U δ(q,1) U δ(r,1)


= {p} U {r} U Φ
= {p,r}
So δD([p,q,r],1) = [p,r] D
Step 4
(D,0) δN({p,r},0) = δ(p,0) U δ{r,0}
= {p,q} U {s}
= {p,q,s}
So δD([p,r],0) = [p,q,s] F
(D,1) δN({p,r},1) = δ(p,1) U δ(r,1)
= {p U Φ }
={p}
So δD([p,r],1) = [p] A
Step 5
(E,0) δN({p,q,r,s},0) = δ (p,0) U δ(q,0) U δ(r,0) U δ(s,0)
= {p,q} U {r} U {s} U {s}
So δD([p,q,r,s],0) = [p,q,r,s] E
(E,1) δN({p,q,r,s},1) = δ(p,1) U δ(q,1) U δ(r,1) U δ(s,1)
= {p} U {r} U {s} = {p,r,s}
So δD([p,q,r,s],1) =[p,r,s] G
Step 6
(F,0) δN({p,q,s},0) = δ(p,0) U δ{q,0) U δ(s,0)
= {p,q} U {r} U {s} = {p,q,r,s}
So δD([p,q,s],0) = [p,q,r,s] E
(F,1) δN({p,q,s},1) = δ(p,1) U δ{q,1) U δ(r,1) U δ (s,1)
= {p} U {r} U {s} = {p,r,s}
So δD([p,q,s],1) = [p,r,s]  G
Step 7
(G,0) δN({p,r,s},0) = δ(p,0) U δ(r,0) U δ(s,0)
= {p,q} U {s} = {p,q,s}
So δD([p,r,s],0) = [p,q,s] F
(G,1) δN({p,r,s},1) = δ(p,1) U δ(r,1) U δ(s,1)
= Φ U {p} U {s} ={p,s}
51
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

So δD([p,r,s],1) = [p,s] H
Step 8
(H,0) δN({p,s},0) = δ(p,0) U δ(s,0)
= {p,q} U {s} ={p,q,s}
So δD({p,s},0) = [p,q,s] F
{H,1) δN({p,s},1) = δ(p,1) U δ(s,1)
= {p} U {s} = {p,s}
So δD([p,s],1) = [p,s] H

The transition table for the DFA is shown below,

0 1
[p] [p,q] [p]
[p,q] [p,q,r] [p,r]
[p,q,r] [p,q,r,s] [p,r]
[p,r] [p,q,s] [p]
*[p,q,r,s] [p,q,r,s] [p,r,s]
*[p,q,s] [p,q,r,s] [p,r,s]
*[p,r,s] [p,q,s] [p,s]
*[p,s] [p,q,s] [p,s]
DFA Transition Diagram
1
1
1
[p] [p,q] [p,q,r] [p,r]
0 0 1

0
0
0
1
[p,q,r,s] 0
[p,r]
1
1 [p,q,s]
0
[p,r,s]
1

0
52
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

26. Construct a NFA that accepts the set of all strings {a,b} ending with “aba” as substring and
construct DFA. Use it to construct a DFA accepting the same set of strings. (May/June 2007)
Solution
The NFA for the set of all strings ending with “aba” as substring is,

a/b
a b a
q0 q1 q2 q3

The transition table for the above NFA is given below,


A B
q0 {q0,q1} {q0}
q1 Φ {q0}
q2 {q3} Φ
*q3 Φ Φ
The initial state is {q0} = [q0] A
Step 1

(A,a) δN({q0},a) = δ(q0,a) = {q0,q1}


So δD([q0],a) = [q0,q1] B

(A,b) δN({q0},b) = δ(q0,b) = { q0}


So δD([q0],b) = [q0] A

Step 2
(B,a) δN({q0,q1},a)=δ(q0,a) U δ(q1,a) = {q0,q1}
So δD([q0,q1],a) = [q0,q1] B

(B,b) δN({q0,q1},b)= δ(q0,b) U δ(q1,b) = {q0,q2}


So δD([q0,q1],b) = [q0,q2] C

Step 3
(C,a) δN({q0,q2},a) = δ(q0,a) U δ(q2,a) = {q0,q1,q3}
So δD([q0,q2],a) = [q0,q1,q3] D

53
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(C,b) δN({q0,q2},b) = δ(q0,b) U δ(q2,b) = {q0}


So δD([q0,q2],b) = [q0] A
Step 4
(D,a) δN({q0,q1,q3},a) = δ(q0,a) U δ(q1,a) U δ(q3,a) = {q0,q1}
So δD([q0,q1,q3],a) = [q0,q1] B

(D,b) δN({q0,q1,q3} , b) = δ(q0,b) U δ(q1,b) U δ(q3,b) = { q0,q2}


So δD([q0,q1,q3],b) = [q0,q2] C
DFA transition table
a b
[q0] [q0,q1] [q0]
[q0,q1] [q0,q1] [q0,q2]
[q0,q2] [q0,q1,q3] [q0]
*[q0,q1,q3] [q0,q1] [q0,q2]

DFA transition Diagram


a
b
a
[q0] [q0,q1]
a
b

b
a [q0,q1,q3
[q0,q2]

Problems for Conversion of NFA with Є to NFA without Є


27. Convert the following NFA with Є to NFA without Є

a b c Є
p {q} {p} Φ Φ
q {r} Φ {q} Φ
*r Φ Φ Φ {r}

54
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Solution:
The NFA with Є transition diagram is,

Step 1
Є – Closure (p) = { p, q, r }
Є – Closure (q) = { q, r }
Є – Closure (r) = { r }
Step 2: Processing state p
δ (p, a) = Є – closure (δ (δ‟ ( p, Є ) , a) )
= Є – closure (δ ({ p, q, r }), a) )
= Є – closure (δ (p, a) U δ (q, a) U δ (r, a) )
= Є – closure ({ p })
δ (p, a) = { p, q, r}
δ (p, b) = Є – closure (δ (δ‟ (p, Є), b) )
= Є – closure (δ ({ p, q, r }, b) )
= Є – closure (δ (p, b) U δ (q, b) U δ (r, b) )
= Є – closure (q)
δ (p, b) = { q, r }
δ (p, c) = Є – closure (δ (δ‟ (p, Є) , c) )
= Є – closure (δ ({ p, q, r } , c ) )
= Є – closure (δ (p, c) U δ (q, c) U δ (r, c) )
= Є – closure ( r )
δ (p, c) ={r}
Processing state q
δ (q, a) = Є – closure (δ ( δ‟ (q, Є ), a) )
= Є – closure (δ ({ q, r }, a) )
= Є – closure (δ (q, a) U δ (r, a) )
= Є – closure (Φ)
δ (q, a) =Φ
δ (q, b) = Є – closure ( (δ ( δ‟ (q, Є ), b) )

55
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= Є – closure (δ ({ q, r }, b) )
= Є – closure (δ (q, b) U δ (r, b) )
= Є – closure (q)
δ (q, b) = { q, r }
δ (q, c) = Є – closure ( (δ ( δ‟ (q, Є ), c) )
= Є – closure (δ ({ q, r }, c) )
= Є – closure (δ (q, c) U δ (r, c) )
= Є – closure (r)
δ (q, c) = { r }
Processing state r
δ (r, a) = Є – closure ( (δ ( δ‟ (r, Є ), a) )
= Є – closure (δ ({ r }, a) )
= Є – closure (Φ)
δ (r, a) = Φ
δ (r, b) = Є – closure ( (δ ( δ‟ (r, Є ), b) )
= Є – closure (δ ({ r }, b) )
= Є – closure (Φ)
δ (r, b) = Φ
δ (r, c) = Є – closure ( (δ ( δ‟ (r, Є ), c) )
= Є – closure (δ ({ r }, c ) )
= Є – closure ( r )
δ (r, c) = { r }
NFA Transition Table:

0 1 2
*p {p, q, r} {q, r} {r}
*q Φ {q, r} {r}
*r Φ Φ {r}

NFA Transition Diagram


b c
a
a,b b,c
r
p q

a,b,c

56
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

28. Convert the following NFA- to NFA without Є.

Solution:
The transition table for above NFA with Є is shown below.

0 1 2 Є
q0 {q0} Φ Φ {q1}
q1 Φ {q1} Φ {q2}
*q2 Φ Φ {q2} Φ
Step 1:
Є – Closure (q0) = {q0, q1, q2}
Є – Closure (q1) = {q1, q2}
Є – Closure (q2) = { q2 }
Step 2:
Processing State q0 :
δ (q0, 0) = Є – closure (δ (δ‟ ( q0, Є ) , 0) )
= Є – closure (δ ({q0, q1, q2}), 0) )
= Є – closure (δ (q0, 0) U δ (q1, 0) U δ (q2, 0) )
= Є – closure (q0)
δ (q0, 0) = { q0, q1, q2}
δ (q0, 1) = Є – closure (δ (δ‟ ( q0, Є ) , 1) )
= Є – closure (δ ({q0, q1, q2}), 1) )
= Є – closure (δ (q0, 1) U δ (q1, 1) U δ (q2, 1) )
= Є – closure ( q1 )
δ (q0, 1) = { q1, q2}
δ (q0, 2) = Є – closure (δ (δ‟ ( q0, Є ) , 2) )
= Є – closure (δ ({q0, q1, q2}), 2) )
= Є – closure (δ (q0, 2) U δ (q1, 2) U δ (q2, 2) )
= Є – closure (q2)
δ (q0, 2) = { q2 }

57
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Processing state q1:


δ (q1, 0) = Є – closure (δ (δ‟ ( q1, Є ) , 0) )
= Є – closure (δ ({q1, q2}), 0) )
= Є – closure (δ (q1, 0) U δ (q2, 0) )
= Є – closure (Φ )
δ (q1, 0) ={Φ}
δ (q1, 1) = Є – closure (δ (δ‟ ( q1, Є ) , 1) )
= Є – closure (δ ({q1, q2}), 1) )
= Є – closure (δ (q1, 1) U δ (q2, 1) )
= Є – closure (q1)
δ (q1, 1) = { q1,q2 }
δ (q1, 2) = Є – closure (δ (δ‟ ( q1, Є ) , 2) )
= Є – closure (δ ({q1, q2}), 2) )
= Є – closure (δ (q1, 2) U δ (q2, 2) )
= Є – closure (q2)
δ (q1, 2) = { q2 }

Processing State q2:


δ (q2, 0) = Є – closure (δ (δ‟ ( q2, Є ) , 0) )
= Є – closure (δ ({q2}), 0) )
= Є – closure (Φ)
δ (q2, 0) ={Φ}
δ (q2, 1) = Є – closure (δ (δ‟ ( q2, Є ) , 1) )
= Є – closure (δ ({q2}), 1) )
= Є – closure (Φ)
δ (q2, 1) ={Φ}
δ (q2, 2) = Є – closure (δ (δ‟ ( q2, Є ) , 2) )
= Є – closure (δ ({q2}), 2) )
= Є – closure (q2)
δ (q2, 2) = { q2 }

58
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Transition table for NFA without Є

0 1 2
*q0 {q0,q1,q2} {q1,q2} {q2}
*q1 Φ {q1,q2} {q2}
*q2 Φ Φ {q2}

NFA without Є Transition Diagram:

Problems for Conversion of NFA with Є to DFA Directly


29. Convert the following NFA with ε to DFA directly.

0 1
2

ε ε
q0 q1 q2

SOLUTION:
The transition table is,
0 1 2 ε
q0 q0 Φ Φ q1

q1 Φ q1 Φ q2

*q2 Φ Φ q2 Φ

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

59
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 2
δN(A,0)=ε-closure (δN({q0,q1,q2},0))
= ε-closure(δN(q0,0) U δN(q1,0) U δN(q2,0))
= ε-closure({q0 U Φ U Φ})
=ε-closure{q0}
= {q0,q1,q2}
δD(A,0)= [q0,q1,q2] A

δN(A,1)=ε-closure ( δN({q0,q1,q2},1))
= ε-closure(δN(q0,1) U δN(q1,1) U δN(q2,1))
=ε-closure{q1}
={q1,q2}
δD(A,1)= [q1,q2] B

δN(A,2)=ε-closure (δN({q0,q1,q2},2))
= ε-closure(δN(q0,2) U δN(q1,2) U δN(q2,2))
=ε-closure{q2}
={q2}
δD(A,2)= [q2] C

Step 3
δN(B,0)=(ε-closure δN({q1,q2},0))
= ε-closure(δN(q1,0) U δN(q2,0))
=ε-closure{Φ}

δD(B,0)= Φ
δN(B,1)=(ε-closure δN({q1,q2},1))
= ε-closure(δN(q1,1) U δN(q2,1))
=ε-closure{q1}
= {q1, q2}
δD(B,1)= [q1,q2] B

δN(B,2)=(ε-closure δN({q1,q2},2))
= ε-closure(δN(q1,2) U δN(q2,2))
=ε-closure{q2}
60
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= {q2}
δD(B,2)= [q2] C

Step 4
δN(C,0)=ε-closure (δN({q2},0))
=ε-closure{Φ}

δD(C,0)= Φ
δN(C,1)=ε-closure ( δN({q2},1))
=ε-closure{Φ}

δD(C,1)= Φ

δN(C,2)=ε-closure (δN({q2},2))
=ε-closure{q2}
={q2}
δD(C,2)= [q2] C

DFA TRANSITION TABLE:


0 1 2
[q0,q1,q2] [q0,q1,q2] [q1,q2] [q2]
[q1,q2] Φ [q1,q2] [q2]
[q2] Φ Φ [q2]

30. Consider the following Compute the closure of each state and find its equivalent DFA. (16).
[NOV/DEC 2008]

a b c ε
p Φ {q} {r} {q,r}
q {p} {r} {p,q} Φ
*r Φ Φ Φ Φ

Solution:

61
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The NFA – ε transition diagram is,

ε,c
c
a,c

b
p ε q r

Step 1: b
ε – closure(p) = {p,q,r}
ε – closure(q) = { q}
ε – closure(r) = {r}
Step 2:
ε – closure(p) = {p,q,r} = [p,q,r] A

(A,a) δN({p,q,r},a) = ε – closure(δ({p,q,r},q))


= ε – closure(δ(p,a) U δ(q,a) U δ(r,a)))
= ε – closure({p})
= {p,q,r}
So δD([p,q,r],a) = [p,q,r] A
(A,b) δN({p,q,r},b) = ε – closure((δ({p,q,r},b))
= ε – closure(δ(p,b) U δ(q,b) U δ(r,b))
= ε – closure({q,r})
= ε – closure(q) U ε – closure(r) = {q,r}
So δD([p,q,r],b) = [q,r] B
(A,c) δN({p,q,r},c) = ε – closure(δ({p,q,r},c))
= ε – closure(δ(p,c) U δ(q,c) U δ(r,c))
= ε – closure({p,q,r})
= ε – closure(p) U ε – closure(q) U ε – closure(r)
= {p,q,r}
So δD([p,q,r],c) = [p,q,r] A
Step 3:
(B,a) δN({q,r},a) = ε – closure (δ({q,r},a))
= ε – closure(δ(q,a) U δ(r,a))
= ε – closure({p})
62
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= {p,q,r}
So δD([q,r],a) = [p,q,r] A

(B,b) δN({q,r},b) = ε – closure(δ({q,r},b))


= ε – closure(δ(q,b) U δ(r,b))
= ε – closure (r)
={r}
So δD([q,r],b) = [r] C

(B,c) δN({q,r},c) = ε – closure(δ({q,r},c))


= ε – closure(δ(q,c) U δ(r,c))
= ε – closure({p,q})
= ε – closure (p) U ε – closure(q)
= {p,q,r}
So δD([p,r],c) = [p,q,r] A
Step 4:
(C,a) δN({r},a) = ε – closure(δ(r,a))
= ε – closure (Φ) = Φ
So δD([r],a) = Φ
(C,b) δN({r},b) = ε – closure(δ(r,b))
= ε – closure (Φ) = Φ
So δD([r],b) = Φ
(C,c) δN({r},c)= ε – closure(δ(r,c))
= ε – closure(Φ)= Φ
So δN([r],c) = Φ
DFA Transition Table:
a b c
* [p,q,r] [p,q,r] [q,r] [p,q,r]
*[q,r] [p,q,r] [r] [p,q,r]
*[r] Φ Φ Φ

63
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

DFA Transition Diagram:

a,c

b b
[p,q,r] [q,r] [r]

a,c
31. Convert the following NFA – ε to DFA directly. [April/May 2024]
` a b
ε
q0 q1
Solution:
The NFA – ε transition table is shown below:
a b ε
q0 {q0} Φ {q1}
*q1 Φ {q1} Φ

Step 1:
ε – closure(q0) ={q0,q1}
ε – closure(q1)= {q1}
Step 2:
ε – closure(q0) = {q0,q1} A
(A,a) δN({q0,q1},a) = ε – closure(δ(q0,a) U δ(q1,a))
= ε – closure(q0) = {q0,q1}
So δD([q0,q1],a) = [q0,q1] A
(A,b) δN({q0,q1},b) = ε – closure(δ(q0,b) U δ(q1,b))
= ε – closure(q1) = {q1}
So δD([q0,q1],b) = [q1] B
Step 3:
(B,a) δN({q1},a) = ε – closure(δ(q1,a)) = ε – closure(Φ)
So δD([q1],a) = Φ
(B,b) δN({q1},b) = ε – closure(δ(q1,b))= ε – closure(q1) = {q1}
So δD([q1],b) = [q1] B
64
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

DFA Transition Table:

a B
* [q0,q1] [q0,q1] [q1]
*[q1] Φ [q1]

DFA Transition Diagram:


a b
b
[q0,q1] [q1]

32. Prove the equivalence of NFA and DFA using subset construction.(8) (Nov/Dec 2013)
• For most languages, NFA‟s are easier to construct than DFA‟s
• But it turns out we can build a corresponding DFA for any NFA
– The downside is there may be up to 2n states in turning a NFA into a DFA. However, for
most problems the number of states is approximately equivalent.
Theorem: A language L is accepted by some DFA if and only if L is accepted by some NFA (i.e) L(D) =
L(N) for an appropriately constructed DFA from an NFA.
Informal Proof: It is trivial to turn a DFA into an NFA (a DFA is already an NFA without non-
determinism). The following slides will show how to construct a DFA from an NFA.
Let an NFA N be defined as N = (QN, ,  N,q0, FN).
The equivalent DFA D = (QD, ,δD , {q0 }, FD) where:

1. QD = 2Qn ; i.e. QD is the set of all subsets of QN; that is, it is the power set of QN.
Often, not all of these states are accessible from the start state; these states may be
“thrown away.”
2. FD is the set of subsets S of QN such that S  FN  Ø. That is, FD is all sets of N‟s
states that include at least one accepting state of N.
3. For each set S  QN and for each input symbol a in :
 D ( S , a )    N ( p, a )
pS

65
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

0,1

0 1
Start q0 q1 q2

 That is, to compute δD(S, a) we look at all the states p in S, see what states N goes to starting from p
on input a, and take the union of all those states.
 The power set of these states is: {Ø, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2},{q1, q2}, {q0, q1, q2} }
 New transition function with all of these states and go to the set of possible inputs:

• Many states may be unreachable from our start state. A good way to construct the equivalent DFA
from an NFA is to start with the start states and constructs new states on the fly as we reach them.

Transition Table

0 1
Ø Ø Ø
 {q0} {q0, q1} {q0}
{q0, q1} {q0, q1} {q0, q2}
*{q0, q2} {q0, q1} {q0}

66
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Transition Diagram

33. Convert the regular expression (a+b) * abb into NFA – ε and find the equivalent minimum state
DFA. [NOV/DEC 2008]
Solution:
The NFA for the RE (a+b) * abb is shown below,

ε
a
ε ε
ε 2 3 ε a b b
8 9 1
6 7
0 1 0
b
4 5
ε ε

Step 1: ε
ε – closure (0) ={ 0,1,2,4,7} A
Now process the state A with „a‟ and „b‟.
Step 2:
Move [ A,a] = {3,8} ( Similar to δ( A,a))
ε – closure (Move [ A,a]) = { 1,2,3,4,6,7,8} B
Move [A,b] = {5}
ε – closure (Move[A,b]) = { 1,2,4,5,6,7} C
Step 3:
Move [B,a] = {3,8}
ε – closure (Move [B,a]) = {1,2,3,4,6,7,8} B
Move [ B,b] ={5}
ε – closure (Move [ B,b]) = {1,2,4,5,6,7,9} D
Step 4:
Move[C,a] = {3,8}
ε – closure (Move[C,a]) = {1,2,3,4,6,7,8} B

67
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Move [ C,b] = {5}


ε – closure (Move [ C,b] ) = {1,2,4,5,6,7} C
Step 5:
Move[D,a] = {3,8}
ε – closure (Move[D,a]) = {1,2,3,4,6,7,} B
Move[D,b] ={5,10}
ε – closure (Move[D,b] ) = {1,2,4,5,6,7,10} E

Step 6:
Move [ E,a] = {3,8}
ε – closure (Move [ E,a]) = {1,2,3,4,6,7,8} B
Move [ E,b] = {5}
ε – closure (Move [ E,b] ) = { 1,2,4,5,6,7} C
The transition table for DFA is given below,
a b
A B C
B B D
C B C
D B E
*E B C
To Find Minimized DFA
By using minimized algorithm the minimized DFA is as follows,
[ABCDE]
[ABCD] [E] { E is final state}
[ABC] [D] [E] { Since δ(D,b)= E}
[AC] [B] [D] [E]
A ≡ C , Eliminate C and replace „C‟ by „A‟
The transition table for minimum state DFA is given below,
a b
A B A
B B D
D B E
*E B A

68
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

34. Construct a minimized DFA that can be derived from the following regular expression 0 * ( 01) ( 0
/ 111)*. [ Nov / Dec 2012 ]
Solution
The NFA for the RE 0 * ( 01) ( 0 / 111)* is shown below.
Step 1:
ε – closure (a ) = { a,b,d} A
Step 2:
Move [ A,0 ] = { c,e}
ε – closure (A,0 ) = { b,c,e} B
Move [ A,1 ] = Φ
ε – closure (A,1 ) = Φ
Step 3:
Move [ B,0 ] = {c}
ε – closure (B,0 ) = { b,c,d} C
Move [ B,1 ] = { f }
ε – closure (B,1 ) = { f,g,h,j,o} D
Step 4:
Move [ C, 0 ] = { c,e}
ε – closure (C, 0 ) = {b,c,e} B
Move [ C,1] = Φ
ε – closure (C,1 ) = Φ
Step 5:
Move [ D,0] = {i}
ε – closure (D,0 ) = {g,h,i,j,n,o} E
Move[D,1] = {k}
ε – closure (D,1 ) = {k} F

69
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

b
ε ε

f
ε

ε g
ε

j h

ε
ε
k ε
i
ε
ε
l

ε ε
m

n
ε
ε
o
70
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 6:
Move [E,0] = { i }
ε – closure (E,0 ) = { g,h,i,j,n,o} E
Move [ E,1] = {k}
ε – closure (E,1) = { k } F
Step 7:
Move [ F,0 ] = Φ
ε – closure (F,0 ) = Φ
Move [ F,1] = {l}
ε – closure (F,1 ) = {l } G
Step 8:
Move [ G, 0] = Φ
ε – closure (G, 0 ) = Φ
Move [ G,1] = {m}
ε – closure (G,1) = {g,h,j,m,n,o} H
Step 9:
Move [ H,0 ] = {i}
ε – closure (H,0) = { g,h,i,j,n,o } E
Move [ H,1] = {k}
ε – closure (H,1 ) = { g,h,j,m,n,o } H
The transition table for DFA is given below,
0 1
A B Φ
B C D
C B Φ
*D E F
*E E F
F Φ G
G Φ H
*H E F

71
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

To Find Minimized DFA


By using minimized algorithm the minimized DFA is as follows,
[ A B C D E F G H ]
[ A B C F G ] [ D E H ]
[ A C F ] [ B ] [G] [ D E H ]
[ A C] [ F ] [ B ] [G] [ D E H ]
A ≡ C , Eliminate C and replace „C‟ by „A‟
D ≡ E ≡ H , Eliminate E and H and replace E and H by „D‟
The transition table for minimum state DFA is given below,
0 1
A B Φ
B A D
*D D F
F Φ G
G Φ D

The transition diagram for minimum state DFA is given below,

0
0
1
A B D

1
0
1

F G
1

35. Construct a minimized DFA from the regular expression ( x+y) x ( x+y ) *. Trace for a string w =
xxyx. [NOV/DEC 2011]
Solution:
The NFA for the RE 0 * ( 01) ( 0 / 111)* is shown below.
Step 1:
ε – closure (1 ) = { 1,2,4} A

72
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 2:
Move [ A,x ] = { 3}
ε – closure (A,x ) = { 3,6} B
Move [ A,y ] = { 5 }
ε – closure (A,y ) = { 5 , 6 } C

Step 3:
Move [ B, x ] = {7}
ε – closure (B, x ) = { 7,8,10,13} D
Move [ B, y ] = Φ
ε – closure ( ) = Φ
Step 4:
Move [ C, x ] = { 7}
ε – closure (C, x ) = { 7,8,10,13} D
Move [ C,y] = Φ
ε – closure (C,y ) = Φ
Step 5:
Move [ D,x] = {9}
ε – closure (D,x ) = { 7 , 8, 9, 10, 12 , 13} E
Move[D,y] = { 11 }
ε – closure (D,y ) = { 7, 8 , 10, 11 , 12, 13} F
Step 6:
Move [E,x] = { 9 }
ε – closure (E,x) = {7 , 8, 9, 10, 12 , 13 } E
Move [ E,y] = { 11}
ε – closure (E,y ) = { 7, 8 , 10, 11 , 12, 13 } F
Step 7:
Move [ F,x ] = { 9 }
ε – closure (F,x) = {7 , 8, 9, 10, 12 , 13 }
Move [ F,y] = { 1l}
ε – closure (F,y ) = {7, 8 , 10, 11 , 12, 13 } G
The transition table for DFA is given below,
x y
A B C
73
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

B D Φ
C D Φ
*D E F
*E E F
*F E F
To Find Minimized DFA
By using minimized algorithm the minimized DFA is as follows,
[ A B C D E F ]
[ A B C ] [ D E F ]
[ A ] [ B C ] [ D E F ]
[ A ] [ B C ] [ D E F ]
B ≡ C , Eliminate C and replace „C‟ by „B‟
D ≡ E ≡ F , Eliminate E and F and replace E and F by „D‟.
The transition table for minimum state DFA is given below,

x y
A B B
B D Φ
*D D D

Given w = xxyx
δ( A,xxyx) = δ‟ (δ(A,x),xyx)= δ‟ (δ(B,x),yx) = δ‟ (δ(D,y),x) = δ‟ (δ(D,x)) = D (Final State). The given
string is accepted.
36. Construct NFA with epsilon for the RE=(a/b)*ab and convert into DFA and further find the
minimized DFA (a/b)*ab. (6) (April/May 2017)
The NFA for the RE (a/b) * ab is shown below,

ε
a
ε ε
ε 2 3 ε a b
6 8 1
0 1 7 0
b
4 5
ε ε

74
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 1:
ε – closure (0) ={ 0,1,2,4,7} A
Now process the state A with „a‟ and „b‟.
Step 2:
δ(A,a)= ε – closure (δ [ A,a])
= ε – closure (δ[{ 0,1,2,4,7},a])
= ε – closure(3,8)
={ 3,6,7,1,2,4,8} B
δ(A,b)= ε – closure (δ [ A,b])
= ε – closure (δ[{ 0,1,2,4,7},b])
= ε – closure(5)
={ 5,6,7,1,2,4} C

Step 3: δ(B,a)= ε – closure (δ [ B,a])


= ε – closure (δ[{ 3,6,7,1,2,4,8}a])
= ε – closure(3,8)
={ 3,6,7,1,2,4,8} B
δ(B,b)= ε – closure (δ [ B,b])
= ε – closure (δ[{ 3,6,7,1,2,4,8},b])
= ε – closure(5,9)
={ 5,6,7,1,2,4,9} D
Step 4:
δ(C,a)= ε – closure (δ [ C,a])
= ε – closure (δ[{ 5,6,7,1,2,4},a])
= ε – closure(3,8)
={ 3,6,7,1,2,4,8} B
δ(C,b)= ε – closure (δ [C,b])
= ε – closure (δ[{ 5,6,7,1,2,4},b])
= ε – closure(5)
={ 5,6,7,1,2,4} C
Step 5:
δ(D,a)= ε – closure (δ [ D,a])
= ε – closure (δ[{ 5,6,7,1,2,4,9},a])
= ε – closure(3,8)
75
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

={ 3,6,7,1,2,4,8} B
δ(D,b)= ε – closure (δ [D,b])
= ε – closure (δ[{ 5,6,7,1,2,4,9},b])
= ε – closure(5)
={ 5,6,7,1,2,4} C
The transition table for DFA is given below,
a b
A B C
B B D
C B C
*D B C

To Find Minimized DFA


By using minimized algorithm the minimized DFA is as follows,
[ A B C D ]
[ A B C ] [ D ]
[ A C] [ B ] [ D ]
A ≡ C, Eliminate C and replace „C‟ by „A‟
The transition table for minimum state DFA is given below,

a b
A B A
B B D
*D B A

b a

a b
A B D

a
b

76
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

37. Determine the DFA from a given NFA. M=({q0,q1},{a,b}, δ, q0, {q1}) with the state table diagram for
δ given below. Nov/Dec 2016

a b
 q0 {q0,q1} {q1}
*q1 Φ {q0,q1}
Solution
NFA transition diagram for the above NFA is,
b
a b

Start a
b q0 q1

Starting state = { q0}


For DFA, b

{q0}= [q0] in NFA  A

Step 1
(A,a) δN({q0},a) = {q0,q1}
So δD ([q0],a) = [q0,q1] B
(A,b) δN ({q0},b) = { q1}
So δD([q0],b) = [q1] C
Step 2
(B,a) δN ({q0,q1},a) = δ (q0,a) U δ (q1,a)
= { q0,q1} U Φ
= { q0,q1}
So δD ([q0,q1] , a) = { q0,q1} B
(B,b) δN({q0,q1},b) = δ(q0,b) U(q1,b)
= { q1} U { q0,q1}
={ q0,q1}
So δD ([q0,q1],b) = [q0,q1] B
Step 3
(C,a) δN({q1},a) = Φ
So δD ([q1],a) = Φ
(C,b) δN({q1},b)= {q0,q1}
So δD([q1],b) = [q0,q1] B

77
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The transition table for the DFA is shown below,


A b
[ q0] [q0,q1] [q1]
* [q0,q1] [q0,q1] [q0,q1]
* [q1] Φ [q0,q1]
b/a
DFA Transition Diagram
Start a
b [ q0 ] [q0,q1]

b
b
[q1]

38. Determine DFA from a given NFA: (13) April/May 2018


M=({q0,q1},{0,1}, δ, q0, {q1}) Where δ is given by δ(q0 ,0)= {q0,q1}, δ(q0 ,1)= {q1}, δ(q1 ,0)=Φ,
δ(q1 ,1)= {q0,q1}
1
0 1

Start 0,1
b q0 q1

Starting state = {q0} in NFA.


For DFA,
{q0}= [q0] in NFA  A
The input symbols are 0,1 and let δN be the transition of NFA and δD be the transition of DFA.
Step 1
(A,0) δN ({q0}, 0) = {q0,q1}
So δD ([q0], 0) = [q0,q1] B
(A,1) δN ({q0},1) = {q1}
So δD([q0],1) = [q1] C
Step 2
(B,0) δN ({q0,q1}, 0) = δ(q0,0) U δ(q1,0)
= {q0,q1} U Φ

78
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

= { q0,q1}
So δD ([q0,q1],0) = [q0, q1] B
(B,1) δN({q0,q1},1) = δ(q0,1) U δ(q1,1)
= {q1} U{ q0,q1}
= {q0,q1}
So δD ([q0,q1],1) = [q0,q1] B
Step 3
(C,0) δN({q1},0) = Φ
So δD([q1],0) = Φ
(C,1) δN {q1},1) = {q0,q1}
So δD([q1],1) = [q0,q1] B

Transition table for DFA


0 1
[q0] [q0,q1] [q1]
*[q0,q1] [q0,q1] [q0,q1]
*[q1] Φ [q0,q1]

0,1

Start 0 1
b q0 q0,q1 q1

1
39. Convert the NFA – ε to DFA and list the difference between NFA and DFA. (13) Nov/Dec 2017

a
a ε
q0 q1 q2
Solution:
Step 1:
ε – closure(q0) ={q0}
ε – closure(q1)= { q1,q2}
ε – closure(q2)= {q2}

79
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 2:
ε – closure(q0) = {q0} A
(A,a) δN({q0 },a) = ε – closure(δ(q0,a) )
= ε – closure(q1) = { q1,q2}
So δD([q0],a) = [q1,q2] B
(A,b) δN({q0},b) = ε – closure(δ(q0,b) )
= ε – closure(Φ) = Φ
So δD([q0],b) = Φ
Step 3:
(B,a) δN({q1,q2},a) = ε – closure(δ(q1,a) U δ(q2,a)) = ε – closure(q1) = { q1,q2}
So δD([q1,q2],a) = [q1,q2]
(B,b) δN({q1,q2},b) ε – closure(δ(q1,b) U δ(q2,b)) = ε – closure(q0) = {q0}
So δD([q1,q2],b) = [q0] B

DFA Transition Table:


a B
[q0] [q1,q2] Φ
*[ q1,q2] [q1,q2] [q0]

DFA Transition Diagram:


a
a
[q0] [q1,q2
q1 ]

40. Prove that if a Regular Language „L‟ is accepted by a NFA then there exist a DFA that accepts „L‟.
(or) Prove the equivalence of NFA and DFA.
Prove that for every L recognized by an NFA, There exists an equivalent DFA accepting the same
language L. (Nov/Dec 2020)
Proof:Let
M=(Q, Σ, δ, q0, F) be an NFA for language L. Then define DFA M‟ such that,
M‟=(Q‟, Σ, δ‟, q‟0, F‟)
The states of M‟ are all the subset of M‟. The Q‟=2Q .
80
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

F‟ be the set of all final states in M.


The elements in Q‟ will be denoted by [q1, q2, q3,…. qi] and the elements in Q are denoted by { q0,
q1, q2,…. qi} The [q1, q2, q3,…. qi] will be assumed as one state in Q‟ if in the NFA q 0 is a initial state it is
denoted in DFA as q‟0=[ q0] .We define,
δ‟([q1, q2, q3,…. qi],a)= [P1, P2, P3,…. Pj]
if and only if ,
δ‟({q1, q2, q3,…. qi},a)= {P1, P2, P3,…. Pj}
This means that whenever in NFA, at the current states {q 1, q2, q3,…. qi} if we get input a and it goes
to the next states {P1, P2, P3,…. Pj} then while constructing DFA for it the current state is assumed to be [q1,
q2, q3,…. qi,a].At this state, the input is a and the next is assumed to be [P 1, P2, P3,…. Pj].On applying δ
function on each of the states q1, q2, q3,…. qi the new states may be any of the states from [P1, P2, P3,….
Pj].The theorem can be proved with the induction method by assuming length of input string x .
δ‟(q‟0,x)= [q1, q2, q3,…. qi ]
if and only if,
δ(q0,x)= [q1, q2, q3,…. qi ]
Basis: If length of input string is 0
i.e. |X|=0, that means x is ε then q‟0= [q0]
Induction: If we assume that the hypothesis is true for the input string of length m or less than m. then if x a
is a string of length m+1. Then the function δ‟ could be written as,
δ‟(q‟0,xa)= δ‟(δ‟(q0,x)a)
by the induction hypothesis,
δ‟(q‟0,x)= [P1, P2, P3,…. Pj]
if and only if,
δ(q0,x)= {P1, P2, P3,…. Pj}
By definition of δ‟
δ‟([P1, P2, P3,…. Pj],a)= [r1, r2, r3,…. rK]
if and only if,
δ({P1, P2, P3,…. Pj},a)={r1, r2, r3,…. rK}
Thus
δ‟(q‟0,xa)= [r1, r2, r3,…. rK]
if and only if,
δ(q0,xa)= {r1, r2, r3,…. rK}
is shown by inductive hypothesis.
Thus L(M)= L(M‟)
81
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

41. Prove that for every L accepted by an ε-NFA, then there exists L which is accepted by NFA
without ε transitions. (May -09,Dec-09,Dec-13)
Proof: Let
M=(Q, Σ, δ, q0, F) be an NFA with ε transitions.
Construct M‟=(Q‟, Σ, δ‟, q‟0, F‟) where
F‟=F ᴜ { q0 } if ε-closure consists state off
F otherwise
M‟ is a NFA without ε moves. The δ‟ function can be denoted by δ‟‟ with some input .For example, δ‟(q,a)=
δ‟‟(q,a) for some q in Q and a from Σ. We will apply the method of induction with input X. The X will not
be ε because
δ'(q0, ε)= { q0 }
δ'(q0, ε)= ε –closure( q0 ) . Therefore we will assume length of string to be 1.
Basis: |x|=1.Then x is a symbol a.
δ'(q0, a)= δ'‟(q0, a)

Induction: |x|>1 Let x=wa


δ'(q0, wa)= δ'(δ'(q0, w),a)
By induction hypothesis,
δ'(q0, w)= δ‟(q0, w)=p
Now we all show that δ'(p, a)= δ(q0, wa)
But δ'(p, a)= ᴜ δ‟(q, a)= ᴜ δ‟‟(q, a)
q inp qinp
As p= δ'‟(q0, w)
We have, ᴜ δ‟(q, a)= δ‟'(q0, wa)
qinp
Thus by definition δ‟'
δ‟(q, wa)= δ‟'(q0, wa)
Hence it is proved
Rule for conversion
δ'(q0, a)= ε –closure(δ (δ'(q, ε),a))
where δ'(q, ε)= ε –closure( q )

82
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

42. Prove that for every L recognized by an ε-NFA, There exists an equivalent DFA accepting the
same language L. (Nov/Dec 2020).
Prove that there exists a DFA for every ε –NFA.
Step 1: Consider M=(Q, Σ, δ, q0, F) is a NFA with ε transitions. We have to convert this NFA with ε to
equivalent DFA denoted by
MD=(QD, Σ, δD, q0, FD)
Then obtain,
ε –closure( q0 )={ P1, P2, P3,…. Pn} then [ P1, P2, P3,…. Pn] becomes a start state of DFA.
Now [ P1, P2, P3,…. Pn] ∈ QD
Step 2: We will obtain δ transitions on [ P1, P2, P3,…. Pn] for each input.
δD([ P1, P2, P3,…. Pn],a)= ε –closure(δ(p1, a) ᴜ δ(p2, a) ᴜ… δ(pn, a))
n
= ᴜ ε –closure(δ(pi, a)
i=1
Where a is input ∈ Σ.
Step 3: The states obtained [ P1, P2, P3,…. Pn] ∈ QD .The states containing final state in Pi is a final state in
DFA.

43. Convert the regular expression (a+b) * abb into NFA – ε and find the equivalent minimum state
DFA. [NOV/DEC 2008]
Solution:
The NFA for the RE (a+b) * abb is shown below,

ε
a
ε ε
ε 2 3 ε a b b
6 8 9 1
0 1 7 0
b
4 5
ε ε

Step 1:
ε – closure (0) ={ 0,1,2,4,7} A
Now process the state A with „a‟ and „b‟.
Step 2:
Move [ A,a] = {3,8} ( Similar to δ( A,a))
ε – closure (Move [ A,a]) = { 1,2,3,4,6,7,8} B
Move [A,b] = {5}
ε – closure (Move[A,b]) = { 1,2,4,5,6,7} C

83
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 3:
Move [B,a] = {3,8}
ε – closure (Move [B,a]) = {1,2,3,4,6,7,8} B

Move [ B,b] ={5}


ε – closure (Move [ B,b]) = {1,2,4,5,6,7,9} D

Step 4:
Move[C,a] = {3,8}
ε – closure (Move[C,a]) = {1,2,3,4,6,7,8} B

Move [ C,b] = {5}


ε – closure (Move [ C,b] ) = {1,2,4,5,6,7} C
Step 5:
Move[D,a] = {3,8}
ε – closure (Move[D,a]) = {1,2,3,4,6,7,} B

Move[D,b] ={5,10}
ε – closure (Move[D,b] ) = {1,2,4,5,6,7,10} E
Step 6:
Move [ E,a] = {3,8}
ε – closure (Move [ E,a]) = {1,2,3,4,6,7,8} B

Move [ E,b] = {5}


ε – closure (Move [ E,b] ) = { 1,2,4,5,6,7} C

The transition table for DFA is given below,

a b
A B C
B B D
C B C
D B E
*E B C

To Find Minimized DFA

By using minimized algorithm the minimized DFA is as follows,


[ABCDE]
[ABCD] [E] { E is final state}
[ABC] [D] [E] { Since δ(D,b)= E}
[AC] [B] [D] [E]

A ≡ C , Eliminate C and replace „C‟ by „A‟

84
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The transition table for minimum state DFA is given below,

a b
A B A
B B D
D B E
*E B A

Transition Diagram for Minimization DFA

A B D E

44. Design an ε – NFA (Nondeterministic finite automaton) to recognize the language L, containing
only binary strings of non-zero length whose bits sum to a multiple of 3. Convert ε – NFA into an
equivalent minimized deterministic finite automaton. Illustrate the computation of your model on any
sample input. Nov/Dec 2021
L={000,000000,....}
Daigram ε – NFA:

0 0 0
0 1 2 3
ε

Step 1:
ε – closure (0) ={ 0} A
Now process the state A with „0‟.
Step 2:

ε – closure (Move [ A,0]) = {1} B

Step 3:
ε – closure (Move [B,0]) = {2} C

Step 4:
ε – closure (Move[C,0]) = {3,0} D

Step 5:
ε – closure (Move[D,0]) = {1} B

85
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

The transition table for DFA is given below,

0
A B
B C
C D
*D B

Transition Diagram for Minimization DFA

0 0 0
A B c d

45. State and prove the theorem of mathematical induction. Nov/Dec 2021

Mathematical induction, is a technique for proving results or establishing statements for natural numbers.
This part illustrates the method through a variety of examples.

Definition

Mathematical Induction is a mathematical technique which is used to prove a statement, a formula or a


theorem is true for every natural number.

The technique involves two steps to prove a statement, as stated below −

Step 1(Base step) − It proves that a statement is true for the initial value.

Step 2(Inductive step) − It proves that if the statement is true for the nth iteration (or number n), then it is
also true for (n+1)th iteration ( or number n+1).

How to Do It

Step 1 − Consider an initial value for which the statement is true. It is to be shown that the statement is true
for n = initial value.

Step 2 − Assume the statement is true for any value of n = k. Then prove the statement is true for n = k+1.
We actually break n = k+1 into two parts, one part is n = k (which is already proved) and try to prove the
other part.
Problem
1+3+5+...+(2n−1)=n2 for n=1,2,…
Solution
Step 1 − For n=1,1=12, Hence, step 1 is satisfied.
Step 2 − Let us assume the statement is true for n=k
86
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Hence, 1+3+5+⋯+(2k−1)=k2 is true (It is an assumption)


We have to prove that 1+3+5+...+(2(k+1)−1)=(k+1)2also holds
1+3+5+⋯+(2(k+1)−1)
=1+3+5+⋯+(2k+2−1)
=1+3+5+⋯+(2k+1)
=1+3+5+⋯+(2k−1)+(2k+1)
=k2+(2k+1)
=(k+1)2
So, 1+3+5+⋯+(2(k+1)−1)=(k+1)2 hold which satisfies the step 2.
Hence, 1+3+5+⋯+(2n−1)=n2 is proved.
45. In a programming language, all the following expressions represent Integer and floating point
literals. Construct finite automata that will accept all the different formats and convert the same to
deterministic finite automata, if required. Nov/Dec 2021
Solution:
Finite Automata:

Problems on equivalence and minimization of automata


46. Find the equivalence and Minimization of finite Automata for the following FA
[Nov/Dec 2024]
Solution
1

Start A 0 B 1 0 D
C
1
0
1

0 1

E F 1 G 0 H
0
1

87
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Step 1
Initial state = A, Final state = C
Now construct table filling algorithm and it is shown below.

X
B
C X X

D
X X X
E X X X

F X X X X
G X X X X X X

H X X X X X X

A B C D E F G

Now let us see how the table filling algorithm is done.


 X denotes not equivalent states.
 Blank space  denotes the states that are equivalent.
Similarly we cannot compare the same state to it self such as (A, A), (B, B), (C, C),
(D, D), (E, E), (F, F), (G, G), (H, H)
Step 2
We cannot compare the accepting state to non accepting states. So generally put X on each pair such
as (A, C) (B, C) (D, C) (E, C) (F, C) (G, C) (H, C)
Step 3
Comparing the equivalence of all the pairs.
1. (A, B) – Take the Pair (A, B) to check whether A and B are equivalent states.
δ (A, 0) = B δ (A, 1) = F
δ (B, 0) = G δ (B, 1) = C
So A, B are not equivalent.
2. Take the Pair (A, D) to check whether A and D are equivalent states.
δ (A, 0) = B δ (A, 1) = F
88
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

δ (D, 0) = C δ (D, 1) = G
So A, D are not equivalent.
3. Take the Pair (A, E) to check whether A and E are equivalent states.
δ (A, 0) = B δ (A, 1) = F
δ (E, 0) = H δ (E, 1) = F
(A, 1) (E, 1) goes to the same state.
So now check with input string 01 and 10
δ (A, 01) = C δ (A, 10) = C
δ (E, 01) = C δ (E, 10) = C
So the states A and E are equivalent.
4. Take the Pair (A, F) to check whether A and E are equivalent states.
δ (A, 0) = B δ (A, 1) = F
δ (F, 0) = C δ (F, 1) = G
So A, F are not equivalent.
5. Take the Pair (A, G) to check whether A and G are equivalent states.
δ (A, 0) = B δ (A, 1) = F
δ (G, 0) = G δ (G, 1) = E
So A, G are not equivalent.
6. Take the Pair (A, H) to check whether A and H are equivalent states.
δ (A, 0) = B δ (A, 1) = F
δ (H, 0) = G δ (H, 1) = C
So A, H are not equivalent.
7. Take the Pair (B, D) to check whether B and D are equivalent states.
δ (B, 0) = G δ (B, 1) = C
δ (D, 0) = C δ (D, 1) = G
So B, D are not equivalent.
8. Take the Pair (B, E) to check whether B and E are equivalent states.
δ (B, 0) = G δ (B, 1) = C
δ (E, 0) = H δ (E, 1) = F
So B, E are not equivalent.
9. Take the Pair (B, F) to check whether B and F are equivalent states.

89
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

δ (B, 0) = G δ (B, 1) = C
δ (F, 0) = C δ (F, 1) = G
So B, F are not equivalent.
10. Take the Pair (B, G) to check whether B and G are equivalent states.
δ (B, 0) = G δ (B, 1) = C
δ (G, 0) = G δ (G, 1) = E
(B, 0) and (G, 0) reaches same state.
Take string are 01 and 10
δ (B, 01) = E δ (B, 10) = A
δ (G, 01) = E δ (G, 10) = H
Take the string as 11, B and G are not equivalent, since δ (B, 11), reaches „c‟ and δ (G, 01)
reaches to the state „F‟.
So B and G are equivalent.
11. Take the Pair (B, H) to check whether B and H are equivalent states.
δ (B, 0) = G δ (B, 1) = C
δ (H, 0) = G δ (H, 1) = C
Now (B, 0) and (B, 1) reaches the same state and (H,0) and (H,1) reaches the same state.
Take string are 01 and 10
δ (B, 01) = E δ (B, 10) = A
δ (H, 01) = E δ (H, 10) = A
So take the string 11
δ (H, 11) = C
Take the string 0110
δ (B, 0110) = C δ (H, 0110) = C
So the states B and H are equivalent.

12. Take the Pair (D, E) to check whether D and E are equivalent states.
δ (D, 0) = C δ (D, 1) = G
δ (E, 0) = H δ (E, 1) = F
So D and E are not equivalent.
13. Take the Pair (D, F) to check whether D and F are equivalent states.

90
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

δ (D, 0) = C δ (D, 1) = G
δ (F, 0) = C δ (F, 1) = G
Take the string 11 and 01
δ (D, 11) = E δ (F, 11) = E
δ (D, 01) = C δ (F, 01) = C
So D and F are equivalent.
14. Take the Pair (D, G) to check whether D and G are equivalent states.
δ (D, 0) = C δ (D, 1) = G
δ (G, 0) = G δ (G, 1) = E
So D and G are not equivalent.
15. Take the Pair (D, H) to check whether D and H are equivalent states.
δ (D, 0) = C δ (D, 1) = G
δ (H, 0) = G δ (H, 1) = C
So D and H are not equivalent.
16. Take the Pair (E, F) to check whether E and F are equivalent states.
δ (E, 0) = H δ (E, 1) = F
δ (F, 0) = C δ (F, 1) = G
So E and F are not equivalent.
17. Take the Pair (E, G) to check whether E and G are equivalent states.
δ (E, 0) = H δ (E, 1) = F
δ (G, 0) = G δ (G, 1) = E
So E and G are not equivalent.
18. Take the Pair (E, H) to check whether E and H are equivalent states.
δ (E, 0) = H δ (E, 1) = F
δ (H, 0) = G δ (H, 1) = C
So E and H are not equivalent.
19. Take the Pair (F, G) to check whether F and G are equivalent states.
δ (G, 0) = G δ (G, 1) = E
δ (F, 0) = C δ (F, 1) = G
So F and G are not equivalent.
20. Take the Pair (F, H) to check whether F and H are equivalent states.

91
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

δ (F, 0) = C δ (F, 1) = G
δ (H, 0) = G δ (H, 1) = C
So F and H are not equivalent.
21. Take the Pair (G, H) to check whether G and H are equivalent states.
δ (G, 0) = G δ (G, 1) = E
δ (H, 0) = G δ (H, 1) = C
(G, 0) and (H, 0) reaches same states.
Take the string 11
δ (G, 11) = F δ (H, 11) = C
So the states G and H are not equivalent.
Now the equivalent states are,
Equivalent states: A ≡ E, B ≡ H, D ≡ F, C, G
0 1

1
G D, F
1

A, E 0

0 0

1
B, H C

1
0

Method 2
For the above same problem, the DFA can be minimized by using DFA minimization algorithm.
Construction of the transition table is the first step.
0 1
A B F
B G C
* C A C
D C G

92
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

E H F
F C G
G G E
H G C

[A B C D E F G H]
Now the pair of states (D, F) has same state for the transition of 0 and 1. Similarly the pair (B, H) has the
same states.
 A [B, H] C [D, F] E G
 [A, E, G] C [B, H] [D, F]
Since C is the accepting state, it is always kept separately. Now the new transition table is,
0 1
A [B, H] [D, F]
[B, H] G C
* C A C
[D, F] C G
E [B, H] [D, F]
G G E

Now the state A and E has the same states. So, the new states are,
 G C [A, E] [B, H] [D, F]
Equivalent states: A≡ E, B ≡ H, D≡ F, C, G
Now the new transition table is,

0 1
[A, E] [B, H] [D, F]
[B, H] G C
* C A C
[D, F] C G
G G E

93
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Thus the minimized automata is,

0 1

1
G D, F
1

A, E 0

0 0

1
B, H C

1
0

94
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

UNIVERSITY QUESTIONS
APRIL/MAY 2007
PART-A
1. What is finite automaton?
2. Enumerate the difference between DFA and NFA.
PART-B
1. (a) (i) Prove the following by the principle of induction. (6)
n n(n+1)(2n+1)
2
Σ k = -----------------------------
K=1 6
(ii) For the finite state machine M given in the following table, test whether the strings 101101,
11111 are accepted by M. (4)
0 1
*q0 [q0] [q1]

q1 [q3] [q0]
q2 [q0] [q3]
q3 [q1] [q2]

(iii) Construct a DFA that accepts all the strings on {0,1} except those containing the string 101. (6)
2. (i) Construct a non-deterministic finite automata accepting the same set of strings over {a,b}
ending in aba. Use it to construct a DFA accepting the same set of strings. (16)

NOV/DEC 2007
PART-A
1. List any four ways of theorem proving.
PART-B
1. (i) Draw transition diagram for recognizing the set of all operators in C language. (10)
(ii) Explain the extended transition function NFA,DFA and NFA-ε. (6)

NOV/DEC 2008
PART-A
1. Define languages described by NFA and DFA.
PART-B
2. (i) Consider the following Compute the closure of each state and find its equivalent DFA. (16) [Q.
No: 16]
a b c ε
start p Φ {q} {r} {q,r}
q {p} {r} {p,q} Φ
*r Φ Φ Φ Φ

(ii) Explain the extended transition function NFA, DFA and NFA-ε. (6)

NOV/DEC 2011
PART-A
1. What is structural induction?
2. State the difference between NFA and DFA.
3. Construct the DFA for the following:

95
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

(a) All strings that contain exactly 4 zeroes.


(b) All strings that don‟t contain the substring 110.
NOV/DEC 2012
PART-A

1.Define :
a) Finite Automaton (FA)
b) Transition diagram
2. State the principle of induction.

PART-B
1. (i) Explain the different forms of proof with examples. (8)
(ii) Prove that , if L is accepted by an NFA with ε-transitions , then L is accepted by an NFA without
transitions. (8)
2. Construct a DFA that accept the following language.
{ x € {a,b}: | x|a= odd and | x|b = even.

MAY/JUNE 2013
PART-A
1. What is meant by DFA?
2. Define the term Epsilon transition.

PART-B
1. (i) Convert the following NFA to DFA. (10)
δ a B
P {p} {p,q}
Q {r} {r}
R {Φ} {Φ}
(ii) Write a note on NFA and compare with DFA.(6)

Nov/Dec 2013
Part A
(1) Draw the transition diagram (automata) for an identifier.
(2) What is a non deterministic finite automaton?
Part B

11. (a) (i) Explain the steps in conversion of NFA to DFA. Convert the following NFA to DFA. (8)
1/0
0 1
q0 q1 0 q2

(ii) Prove that, if L is accepted by an NFA with Є transitions, then L is accepted by NFA without Є
transitions. (8)
(b) (i) Prove the equivalence of NFA and DFA using subset construction. (8)
(ii) Give Determinstic finite automata accepting the following language over the alphapet.
(1) Number of 1‟s is a multiples of 3
(2) Number of 1‟s is not a multiples of 3.(8)

96
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Nov/Dec 2015
Part-A
1. What is a finite automaton?
Part-B
11.(a). (i) Prove that “A language L is accepted by some DFA if and only if L is accepted by some
NFA”.(10)
(ii) Construct Finite Automata equivalent to the regular expression (ab+a)*.(6)
(Or)
(b)(i) consider the following ε-NFA for an identifier. Consider the ε-closure of each state and find it‟s
equivalent DFA. (10)
ε
letter
ε 6
5 ε
letter
ε ε
1 2 3 4
ε
7 10

ε 8 9 ε
digit

May/June 2016
Part A
1. Draw non-deterministic automata to accept strings containing the substring 0101.
Part B
11.(a) (i) construct a NFA that accepts all strings that end in 01. Give its transition table and the extended
transition function for the input string 00101. Also construct a DFA for the above NFA using subset
construction method. (10)
(ii) Prove the following by principle of Induction (6). (Example 1))
n
∑ n(n+1)(2n+1)
x=1 x2= -----------------
6

97
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Nov/Dec 2016

PART A
1. Define Deterministic Finite Automata(DFA).

PART B
1. (i) Give ∑={a,b},construct a DFA which recognize the language l={bm a bn :m,n>o}.

(ii) Determine the DFA from a given NFA. M=({q0,q1},{a,b}, δ, q0, {q1}) with thw state table
diagram for δ given below.
a b
 q0 {q0,q1} {q1}
*q1 Φ {q0,q1}
2. Discuss the basic approach to convert from NFA to regular expression. Illustrate with an example.
April/May 2017

PART A
2. Generate NFA- ε to represent a*b/c.

PART B

1. Construct NFA with epsilon for the RE=(a/b)*ab and convert into DFA and further find the
minimized DFA (a/b)*ab. (6)
2. Prove for every n>=1 by Mathematical induction ∑ni3={n(n+1)/2}2
Nov/Dec 2017
PART A
1. Define Finite Automata (FA).

PART B

2. Convert the NFA – ε to DFA and list the difference between NFA and DFA. (13)
(Q.No:59)
b

a
a ε
q0 q1 q2

98
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

April/May 2018

PART A
1. Define Non-deterministic Automata (NFA).
PART B
2. Determine DFA from a given NFA: (13) April/May 2018
M=({q0,q1},{0,1}, δ, q0, {q1}) Where δ is given by δ(q0 ,0)= {q0,q1}, δ(q0 ,1)= {q1}, δ(q1 ,0)=Φ, δ(q1
,1)= {q0,q1}

Nov/Dec 2018

PART A
1. Give the difference between DFA and NDFA.

PART B

2. Convert the following NFA – ε to NFA and then convert the resultant NFA to DFA

D
1
1
1 0
ε ε
A B C

April/May 2019

PART A
1. Construct the finite automata for the regular expression: (a/b)*abb.
PART B
3. Convert NFA – ε for the regular expression (01/10)* 101 and convert it into DFA

Nov/Dec 2020

PART A
4. Define deterministic Finite Automata (DFA).
5. State any four types of proofs.
PART B
1. Prove that for every L recognized by an NFA, There exists an equivalent DFA accepting the same
language L.
2. Prove that for every L recognized by an ε-NFA, There exists an equivalent DFA accepting the
same language L.
99
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION

Nov/Dec 2021

PART A
1. Write regular expression to represent exponential constants of „C‟ language. Q.NO.59
2. Define extended transition diagram. Q.NO.60
PART B
1.Design an ε – NFA (Nondeterministic finite automaton) to recognize the language L, containing only
binary strings of non-zero length whose bits sum to a multiple of 3. Convert ε – NFA into an equivalent
minimized deterministic finite automaton. Illustrate the computation of your model on any sample input.
Q.NO.44
2. (i) State and prove the theorem of mathematical induction. Q.NO.45
(ii) In a programming language, all the following expressions represent Integer and floating point literals.
Construct a finite automata that will accept all the different formats and convert the same to deterministic
finite automata, if required. Q.NO.46

100
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

UNIT II REGULAR EXPRESSIONS AND LANGUAGES 9


Regular expression – Regular Languages- Equivalence of Finite Automata and
regular expressions – Proving languages to be not regular (Pumping Lemma) –
Closure properties of regular languages.

TWO MARKS

1. What is a regular expression? [NOV/DEC 2012]


A regular expression is a string that describes the whole set of strings according to certain syntax rules.
These expressions are used by many text editors and utilities to search bodies of text for certain patterns
etc. Definition is: Let Σ be an alphabet. The regular expression over Σ and the sets they denote are:
i. Φ is a r.e and denotes empty set.
ii. ε is a r.e and denotes the set { ε }
iii. For each „a‟ in Σ, a+ is a r.e and denotes the set {a}.
iv. If „r‟ and „s‟ are r.e denoting the languages R and S respectively then (r+s), (rs) and (r*) are r.e that
denote the sets RUS, RS and R* respectively.
2. What is Arden’s Theorem?
Arden‟s theorem helps in checking the equivalence of two regular expressions. Let P and Q be the two
regular expressions over the input alphabet Σ . The regular expression R is given as :
R=Q+RP
Which has a unique solution as R=QP*.
3. Write a regular expression to denote a language L which accepts all the strings which begin or
end with either 00 or 11. [NOV/DEC 2012]
The r.e consists of two parts:
L1=(00+11) (any no of 0‟s and 1‟s)
=(00+11)(0+1)*
L2=(any no of 0‟s and 1‟s)(00+11)
=(0+1)*(00+11)
Hence r.e R=L1+L2
=[(00+11)(0+1)*] + [(0+1)* (00+11)]

4. Construct a r.e for the language which accepts all strings with atleast two c’s over the set Σ
={c,b}.
(b+c)* c (b+c)* c (b+c)*

Prepared By: R.GAJENDIRAN ,ASP/IT 1


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

5. Construct a r.e for the language over the set _={a,b} in which total number of a’s are divisible
by 3.
( b* a b* a b* a b*)*
6. What is: (i) (0+1)* (ii)(01)* (iii)(0+1) (iv)(0+1)+ ?
(0+1)*= { ε , 0 , 1 , 01 , 10 ,001 ,101 ,101001,…………………}
Any combinations of 0‟s and 1‟s.
(01)*={ ε , 01 ,0101 ,010101 ,…………………………………..}
All combinations with the pattern 01.
(0+1)= 0 or 1,No other possibilities.
(0+1)+= {0,1,01,10,1000,0101,………………………………….}

7. Write the Regular expression denoting a language over Σ ={1} having (i)even length of string
(ii)odd length of a string.
(i) Even length of string R=(11)*
(ii) Odd length of the string R=1(11)*

8. Regular expression for:


(i)All strings over {0,1} with the substring ‘0101’
(ii)All strings beginning with ’11 ‘ and ending with ‘ab’
(iii)Set of all strings over {a,b}with 3 consecutive b’s.
(iv)Set of all strings that end with ‘1’and has no substring ‘00’
(i)(0+1)* 0101(0+1)*
(ii)11(1+a+b)* ab
(iii)(a+b)* bbb (a+b)*
(iv)(1+01)* (10+11)* 1

9. What are the applications of Regular expressions and Finite automata?


Lexical analyzers and Text editors are two applications.
Lexical analyzers: The tokens of the programming language can be expressed using regular expressions.
The lexical analyzer scans the input program and separates the tokens. For eg identifier can be
expressed as a regular expression as:
(letter)(letter+digit)*

Prepared By: R.GAJENDIRAN ,ASP/IT 2


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

If anything in the source language matches with this regular expression then it is recognized as an
identifier. The letter is{A,B,C,………..Z,a,b,c….z} and digit is {0,1,…9}.Thus regular expression
identifies token in a language.
Text editors: These are programs used for processing the text. For example UNIX text editors uses the
regular expression for substituting the strings such as: S/bbb*/b/
Gives the substitute a single blank for the first string of two or more blanks in a given line. In UNIX
text editors any regular expression is converted to an NFA with ε –transitions, this NFA can be then
simulated directly.
10. Regular expression for the language that accepts all strings in which ‘a’ appears tripled over
the set Σ ={a}.
regular expression=(aaa)*

11. What are the applications of pumping lemma? [NOV/DEC 2007]


Pumping lemma is used to check if a language is regular or not.
(i) Assume that the language(L) is regular.
(ii) Select a constant „n‟.
(iii) Select a string (w) in L, such that |w|>n.
(iv) Split the word z into u,v and w such that |uv|<=n and |v|>=1.
(v) You achieve a contradiction to pumping lemma that there exists an „i‟
i
Such that uv w is not in L. Then L is not a regular language.

12. What is the closure property of regular sets?


The regular sets are closed under union, concatenation and Kleene closure.
r1Ur2= r1 +r2
r1.r2= r1r2
( r )*=r*
The class of regular sets are closed under complementation, substitution, homomorphism and inverse
homomorphism.
13. Regular expression for the language such that every string will have at least one ‘a’ followed
by at least one ‘b’.
R=a+b+
14. Write the expression for the language starting with and has no consecutive b’s.
Regular expression=(a+ab)*

Prepared By: R.GAJENDIRAN ,ASP/IT 3


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

15. What is the relationship between FA and regular expression?

Regular
Expression

Deterministic NFA with ε


Finite Automata
NFA without ε
moves

16. What is a : (a) String (b) Regular language? [NOV/DEC 2012]


A string x is accepted by a Finite Automaton M=( Q,∑,δ,q0,F) if δ(q0,x)=p, for some p in F.FA accepts
a string x if the sequence of transitions corresponding to the symbols of x leads from the start state to
accepting state.
The language accepted by M is L(M) is the set {x | δ (q0,x) is in F}. A language is regular if it is
accepted by some finite automaton.
17. List down the operators of the regular expression.
The three operators involved in the Regular Expression are,
(i) The UNION of two languages L and M, denoted by LUM, is the set of strings that are
either in L or M or both.
(ii) The CONCATENATION of languages L and M is the set of strings that can be formed
by taking any string in L and concatenating it with any string in M.
(iii) The regular expression involving the CLOSURE operation and its types are,
 Kleene or star closure
 Positive closure

18. How will you find the equivalence of the FA and RE?
The equivalence of the finite automata and the regular expression can be proved by two parts as
follows:
 The first parties obtaining a finite automaton from its regular expression
 The second part is obtaining the regular expression from the finite automata.

19. Define Myhill Nerode theorem.[Nov/Dec-2024]


The two regular languages are said to be equivalent, if they define the same language by checking the
equivalence, we can minimize the DFA. That is, we can take any DFA, and we can find an equivalent

Prepared By: R.GAJENDIRAN ,ASP/IT 4


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

DFA M‟ with minimum number of states. This way of minimizing DFA by finding an equivalent DFA
with minimized state is said to be Myhill – Nerode theorem.

20. Define equivalent state. [NOV/DEC 2007]


The states p and q are equivalent if “for all input strings q, δ(p,w) is an accepting state if and only if
δ(q,w) is also an accepting state.

21. What is meant by Distinguishable states?


If two states are not equivalent, then we say that both states are distinguishable states. That is, the state
p is distinguishable from state q if there is at least one string „w‟ such that one of δ(p,w) is accepting
and it reaches final state and δ(q,q) reaches non-accepting state.

22. What is the purpose of table filling algorithm?


Table filling algorithm is a recursive discovery of distinguishable pairs in a DFA A=( Q,∑,δ,q0,F). If
the two states are not distinguishable states by the table filling algorithm, then the states are equivalent.

23. Define Pumping Lemma. [NOV/DEC 2024]


The pumping lemma is a way to prove that certain languages are not regular. The closure properties are
used to those languages that are regular.

24. What are the closure properties of regular language? [MAY/JUNE 2007][NOV/DEC-2024]
The principal closure properties of regular languages are,
(i) Union of two regular languages is regular
(ii) Intersection of two regular languages is regular
(iii) Complement of a regular language is regular
(iv) Difference of two regular languages is regular
(v) Reversal of a regular language is regular
(vi) Closure of regular language is regular
(vii) Concatenation of regular language is regular
(viii) Homomorphism of a regular languages is regular
(ix) The Inverse Homomorphism of a regular languages is regular
25. Define homomorphism.
Homomorphism is a function on strings that works by substituting a particular string for each symbol.
The homomorphism of the language „L‟ is denoted as h(L).

Prepared By: R.GAJENDIRAN ,ASP/IT 5


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

h(L)={h(w) / w is in L}

26. The homomorphism function is given as


h(0)=abc, h(1)=m. Find h(L) for the string w=0101.
We know that,
h(L)={h(w)/ w is in L}

W=0101, then
h(L)=h(w)=h(0)h(1)h(0)h(1)=(abc)(m)(abc)(m)=abcmabcm.

27. List down the algebraic properties of regular expression.


If r and s are the regular expression, then the algebraic properties are as follows,
1. r+s=s+r  Commutative for union
2. r+(s+t)=(r+s)+t  Associative for union
3. (rs)t=r(st)  Concatenation is associative
4. r(s+t)=rs+rt, (r+s)t=rt+st  Distribution of union and concatenation
5. ε r=r, r ε =r  identity element
6. r*=(r+ ε)*  Relation between * and ε
7. [r** = r*]  * is idempotent

28. Construct regular expression to finite automata.


R=(0+1)* ε

3 4

ε 0
Start ε ε
ε
1 2
7 8

ε 5 6 ε
1

Prepared By: R.GAJENDIRAN ,ASP/IT 6


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

29. Construct regular expression to finite automata.


i) R = 01

Start 0 1
q0 q1
q2

0
ii) R=0+1
Q1 Q2 ε
ε

Q5
Q0

ε
ε Q3 Q4

iii) R=a*
ε

ε ε
a
1 2 3 4

30. Show that the complement of a regular language is also regular.


The complementation of the regular language „L‟ is denoted as Lc, L‟. The complementation is denoted
as,
L‟ = ∑* - L
The complementation of the regular language „L‟ is the set of strings ∑* that are not in the language L.

If ∑*={ε, a, b,aa, ab, aab,…}


L={a,b,ab}

Then L‟={ε,aa,aab,..}

Prepared By: R.GAJENDIRAN ,ASP/IT 7


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

31. Give English description of the following language (0+10)*1*.


The set of strings with zero or more occurrence of „0‟ or „10‟ followed by zero or more occurrence of
„1‟.
32. Show that L = { a p / P is a prime } is not regular. [NOV/DEC 2011]
Solution:
Let w = a k € L
Representing w = xyz
Such that |xy| ≤ k
|v|≥1
Let xy = a m
y= a j
z = a k-m
i. |xy| ≤ n
m
|a |≤ n m≤n
ii. y ≠ε (or) | y | ≥ 1
j j
a ≠ ε (or) | a | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.

m j i-1 k- m
xyiz = xyy i-1 z = a (a ) a
j(i-1)+k
=a
j(k-1)+n
xykz = a
j(i-1)+k j(0-1)+nk k-j k
Put i=0, xy0z = a =a =a ≠a
Since k-j is not prime. So the given language is not regular.
34. Show that ε * is ε by constructing its NFA using Thompson’s construction. [NOV/DEC 2008]
M1

ε
ε
ε
q0 q1 q2
q3
r1

Prepared By: R.GAJENDIRAN ,ASP/IT 8


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

35. Draw non-deterministic automata to accept strings containing the substring 0101.
(May/June 2016)
0, 1

1 0 1 0

Start 0 1 0 1
q1 q2 q3 q4 q5

0
1

36. Generate NFA- ε to represent a*b/c. (April/May2017)


ε

a ε b ε
2 3 4 5 6
ε ε
start ε
1
9
ε
ε c
7 8

37. Show that the language L= { 0n 1 2n / n ≥ 1} is regular or not using pumping lemma.
[Nov/Dec-2024] (April/May 2017).
Solution:
a. Let us assume that given language „L‟ is a regular language.
b. The number of states of L={ a n b 2n / n ≥ 1} is n+2n = 3n
c. Take one string „w‟ and calculate the length of the string
w= a n b 2n
d. If the length of the string, |w| ≥ n
3n ≥ n
So, we can break into three strings
e. W=xyz, let w = a i b i
Let us make the assumption that w= a i b i

Prepared By: R.GAJENDIRAN ,ASP/IT 9


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

xy= a m
y=aj
z = a i-m b i
To check the assumption
xyz = a m a i-m b i = a m+i-m bi = a i b i
So our assumption is correct.
i. |xy| ≤ n
|am|≤n m≤n
ii.
y ≠ε (or) | y | ≥ 1
a j ≠ ε (or) | a j | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.

xykz = xyy k-1 z = a m (a j) k-1 a i-m b i


= a m +j(k-1)+i-m b i = a i+j(k-1) b i
xykz = a i+j(k-1) b i
Put k=0, xy0z = a i+j(k-1) b i = a i+j(0-1) b i = a i-j b i ≠ a i bi
Put k=1 , xy1z = a i+j(k-1) b i = a i+j(1-1) b i = a i b i = a i bi
Put k=2, xy2z = a i+j(k-1) b i = a i+j(2-1) b i = a i+j b i ≠ a i bi
Since for k=0,2 we have the string that does not belong to the language L, so the language
L={ a n b 2n / n = 1} is not regular.

38. Give language of regular expression a?(b/a)*. (April/May 2017)


L={ ε,a,b,ab,ba,aba,abb,bb,bba,…..}
39. What are the closure properties of regular language? (April/May 2016)
(i) The union of two regular languages are regular.
(ii) The intersection of two regular languages are regular.
(iii) The complement of regular language is regular.
(iv) The difference of two regular languages is regular.
(v)The reversal of a regular language is regular.
(vi)The concatenation of regular language is regular.

Prepared By: R.GAJENDIRAN ,ASP/IT 10


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

40. Write the regular expression for the set of all strings of 0’s and 1’s not containing 101
as substring. (April/May 2018)

(0+1)* 010(0+1)*
41. Write regular expression for the set of strings over {0,1} that have at least one.
Dec 2015
RE=(0*1+)(0+1)*
42. Prove or disprove that (r+s)*=r*+s*.
LHS: (r+s)*= { ε,r,s,rr,ss,rs,sr,…..}= { ε,any combination of r and s}
RHS: r*+s*={ ε,r,rr,rrr,s,ss,sss,…..}= { ε, any combination of only r or any combination of
only s}
LHS≠RHS ie(r+s)* ≠r*+s*
43. State pumping lemma and its advantages. [Dec 14,Dec-07,08,13,17]
Let L be a regular language. Then there exists a constant „n‟ which depends on the regular language „L‟
such that for every string ‟w‟ in L such |w| ≥ n, we can break w into three strings, w= xyz such that,

1. y ≠ ε (Or) |y| > 0 (Or) |y| ≥ 1


2. |xy| ≤ n
3. For all k ≥ 0, the string xy kz is also in L

The advantage of pumping lemma is that this theorem is used to check whether given language is
regular or not.

44. Give the RE for set of all strings ending in 00.[Dec10]


RE=(0+1)*00
45. Construct NFA for RE a*b*. [May-12]

a,b

a,b
1 2

Prepared By: R.GAJENDIRAN ,ASP/IT 11


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

46. Write the regular expression for all strings that contain no more than one occurrence
of aa.
RE=[ab]*aa[ab]*

47. Write the regular expression for even number of a’s and even number of b’s of a
string ={a,b}*.
RE=[aa+bb+(ab+ba)(aa+bb)*ab+ba)]*
48. Write regular expression to recognize the set of strings over {a,b} having odd
number of a’s and b’s and that starts with ‘a’.[ Nov/Dec 2021]

(((aa+bb)*(ab+ba))*+((ab+ba)(aa+bb)*)*)

Prepared By: R.GAJENDIRAN ,ASP/IT 12


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

PART B
1. What is a Regular Expression? Write a regular expression for set of strings that consists
of alternating 0’s and 1’s. (May/June 2016)[April/May 2024]

A regular expression is a string that describes the whole set of strings according to
certain syntax rules. Regular expressions serve as the input language for many systems that
process strings. These expressions are used by many text editors and utilities to search bodies
of text for certain patterns etc.
Regular expressions denote languages. For Example - The regular expression 01*+10*
denotes the language consisting of all strings that are either a single 0 followed by any number
of 1‟s or a single 1 followed by any number of 0‟s.
(i)The three operators involved in the Regular Expression are,
(i) The Union of two languages L and M, denoted by LUM, is the set of strings that are
either in L or M, or both.
Example: If L = {001, 10, 111} are M = {Є, 001}, then LUM = {Є, 10, 001, 111}
(ii) The Concatenation of languages L and M is the set of strings that can be formed by
taking any string in L and concatenating it with any string in M.
Example: If L= {001, 10, 111} and M = {Є, 001} then
L.M (Or) LM = {001, 10, 111, 001001, 10001, 111001}
(iii) The closure of a language L is denoted L* and represents the set of those strings
that can be formed by taking any number of strings from L, possibly with repetitions
(i.e., the same string may be selected more than once) and concatenating all of them.
Example: If L = {0,1}, then L* is all strings of 0‟s and 1‟s
If L = {0,11}, then L* consists of those strings of 0‟s and 1‟s such that the
1‟s come in pairs, e.g., 011, 11110, and Є, but not 01011 or 101.
The regular expression involving the Closure operation and its types are,
 Kleene or star closure
 Positive closure
(ii)Building Regular Expressions
Algebras allow us to construct more expressions by applying a certain set of grouping
operators with their operands, such as parentheses, is required as well.Arithmetic algebra starts

Prepared By: R.GAJENDIRAN ,ASP/IT 13


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

with constants such as integers and real numbers, plus variables, and builds more complex
expressions with arithmetic operators such as + and x.

Example:
Regular expression for the set of strings that consists of alternating 0’s and 1’s.
The (01)* represents those strings of alternating 0‟s and 1‟s that begin with 0 and end with 1.
(10)* represents those strings of alternating 1‟s and 0‟s that begin with 1 and end with 0, while
0(10)* can be used for strings that both begin and end with 0 and 1(01)* serves for strings that
begin and end with 1.
The entire regular expression is (01)*+ (10)*+0(10)*+1(01)*

Prepared By: R.GAJENDIRAN ,ASP/IT 14


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Notice that we use the + operator to take the union of the four languages that together give us all
the strings with alternating 0‟s and 1‟s.

2. Write Regular Expressions for the following languages:


a. The set of strings over alphabet {a,b,c} containing at least one a and
atleast one b.
b. The set of all strings of 0’s and 1’s with at most one pair of a
consecutive 1’s.
c. The set of strings of 0’s and 1’s whose number of 0’s divisible by five.
Solution:
a) a+b+c*
b) (0+1)*11(0+1)*
c) (aaaaa(aaaaa)* + b*))
3. Give English descriptions of the languages of the following regular expressions:
a. a(a+b)*ab
b. a*b+b*b
c. (aa+b)*(bb+a)*
Solution:
a) The set of all strings over {a,b} starting with a and ending with ab.
b) The strings are either strings of a‟s followed by one b or strings of b‟s followed by one a.
c) The set of all strings over {a,b} of the form vw where a occurs in pairs in v and b occurs
in pairs in w.

Regular Expression to Finite Automata ( Thompson’s Theorem)


4. Prove that every regular language defined by a regular expression is also defined
by finite automata.
Theorem
Every regular language defined by a regular expression is also defined by finite automata.
(Or)
Let „r‟ be a regular expression, then there exists a NFA with ε transition that accepts the regular
language L(r).

Prepared By: R.GAJENDIRAN ,ASP/IT 15


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

(Or)
Every language „L‟ that is L(R) for some regular expression „R‟ is also the language L(E) for some
NFA with ε transition „E‟.
To Prove
L(M)=L(R)
Where,
L(M) Language for the regular expression „R‟
L(R) Language for some NFA - ε
Proof

Let L=L(R) for a regular expression R


We show that L=L(E) for some NFA - ε E with the following,
1. Exactly one accepting state
2. No arcs into the initial state
3. No arcs out of the accepting state
Basis
Zero operators. The Basis consists of three parts and the regular expression r must be Φ or any
symbol „a‟ for „a‟ in ∑.
i. r = ε Path from start state to an accepting state for empty input symbol.
ε
q0 q0 qf
(or)

ii. r = Φ No path from start state to an accepting state

q0 qf

iii. r = a Path from start state to final state on processing symbol „a‟.

a
q0 qf

Induction
There are three parts in the induction for the regular expression with the three operators‟ namely
Union, Concatenation and Closure.

Prepared By: R.GAJENDIRAN ,ASP/IT 16


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Assume that the theorem is true for the regular expression with fewer than „i‟ operators, such
that i≥1. Let „r‟ has „i‟ operators where „r‟ is the regular expression.

Case 1: Union of the regular expression


Let r, r1, r2 be the regular expression.
r = r1 + r2 (Or) r = r1 U r2 (Or) r = r1/r2 .
 And „r‟ is the regular expression, which is the union of the regular expression r1 and r2.
 Already, the finite automata exist for the regular expression r1 and r2.
 Now while constructing the automata for the new regular expression r, we create a new starting
state, which has the transition on „ɛ‟ to the starting state of the both the regular expression r1 and
r2.
 Then there is a transition from the final state of both the regular expression r1 and r2 to the new
final state of regular expression „r‟ on ɛ transition. M1

M1

ε Q1 F1
ε r1
ε
r1
ε

qf
Q0

r=r1+r2
Q2 F2
ε r2
ε
ε r2
ε

M2 M2
Where,
M1=(Q1,∑1,δ1,q1,{f1})
M2=(Q2, ∑2, δ2,q2,{f2})
L(M1)=L(r1)
L(M2)=L(r2)
L(M)=L(M1) U L(M2)
M=(Q1UQ2U{q0,qf},∑1U∑2 ,δ1 Uδ2,q0,{qf})
Case 2: Concatenation of the regular expression r1 and r2
r=r1.r2
 Where r is the regular expression formed by concatenating the regular expression r1 and r2.

Prepared By: R.GAJENDIRAN ,ASP/IT 17


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

 While constructing the regular expression r, the starting state of the regular expression r1
becomes the starting state of „r‟.
 Similarly the accepting state of the regular expression „r2‟ becomes the final state of the regular
expression „r‟.
 The concatenation of the regular expression „r‟ is done by providing a path from the final state
of r1 to the start state of r2 on ε transition.
M2
M1

ε
Q0 r1
qf Q1 r2 F1

M1=(Q1,∑1,δ1,q0,{qf}) r = r1.r2
M2=(Q2, ∑2, δ2,q1,{f1})
L(M1)=L(r1)
L(M2)=L(r2)
L(M)=L(M1)L(M2)
M=(Q1UQ2,∑1U∑2 ,δ1 Uδ2,q0,{f1})
Case 3: Closure operation of the regular expression r=r*
Let r1 be the regular expression and r is the regular expression formed by applying closure operation to
the regular expression r1.
 While constructing automata for r, we create a new start and provide a path from new start state
to the starting state of the regular expression r1.
 And provide a path from final state of r1 to the new final state of r on ε transition.
 Include transition path from final state of „r1‟ to the state of r1 on ε input.
 Include transition path from initial start state of „r‟ to the final state of „r‟ on ε input.
M1

ε
ε
ε
q0 q1 q2
r1 q3

ε
L(r1)=L(M1) ;
L(M)=L(M1)*;

Prepared By: R.GAJENDIRAN ,ASP/IT 18


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

M1=(Q1,∑1,δ1,q1,{q2});
M=(Q1U{q0,q3},∑ ,δ,q0,{q3})
Case 4:
The regular expression r is the same for the parenthesized regular expression r, that is r1= (r)
Let
L(r) = L ( M ) L( M ) = L (( M1 ))
L( r1 ) = L ( ( r ) )
L(r1) = L ( M1 )

Converting Regular Expression to Finite Automata


5. Convert the regular expression (a + b ) * a b b into NFA – ε.
Solution :
Step 1: a
a ε
Let w = (a+b) 2 3

6
1
b
4 5
ε
ε
Step 2 :
W= ( a+b) *
ε
a
ε ε
2 3 ε
ε
6 7
0 1
b
4 5
ε
ε

ε
Step 3 :
W= abb a b
b
8 9 10 11
Step 4:
W = (a + b ) * a b b
Combine step 2 and step 3

Prepared By: R.GAJENDIRAN ,ASP/IT 19


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

ε
a
ε ε
ε 2 3 ε a b
6
b 1 1
0 1 7 8 9 0 1
b
4 5
ε ε

6. Construct transition diagram of a finite automata corresponding to the regular


expression. [MAY/JUNE 2007 ]
(ab + c *) * b
Solution :
W= (ab + c *) * b ε

a b

ε
ε 3 4 5 b
ε
ε ε 10 11
9
1 2

6 7 8 ε
c
ε ε

7. Convert the regular expression a ( a+b) * a into NFA – ε.


Solution : ε
a
ε
4 5 ε
a ε ε a
1 2 3 6 9 10
b
ε 7 8 ε

Prepared By: R.GAJENDIRAN ,ASP/IT 20


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Conversion of Finite Automata to Regular Expression


8. Prove that if a Language ‘L’ is accepted by DFA, then L is denoted by a regular
expression R.
Theorem:
If L=L(A) for some DFA „A‟ then there is a regular expression R such that L=L(R).
(Or)
If a Language „L‟ is accepted by DFA, then L is denoted by a regular expression R.

To prove, L(A)=L(R).
ADFA, RRegular expression.
Proof
Let A be the DFA which defines the language „L‟. Let the states of the DFA are {1,2,3….n} for some
integer „n‟. Let us use Rij(k) as the name of a regular expression whose language is the set of strings such
that w is the label of a path from state i to state j in A and that path has no intermediate node whose
number is greater than k.
Rij(k)
Where iInitial state
jFinal state
kNumber of states
Basis:
K=0
All the states are numbered 1 or above. The restriction on path is that the path should not have
intermediate states at all. So the two kinds of path that meet such a condition are as follows.
1. An arc from state i to state j.

i j

2. A path of length „0‟ that consist of only some node i that is a path from the node itself.

Prepared By: R.GAJENDIRAN ,ASP/IT 21


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Case 1:
If i≠j. we must examine DFA „A‟ and find those input symbols „a‟ such that there is a transition
form state i to j on symbol „a‟ the possible cases are,
a) If there is no such symbol a, then Rij(0) = Φ

i j

b) If there is exactly one symbol a, then Rij(0) =a.

a
i j

c) If there are symbols a1,a2..an that label arcs from state i to state j, then
Rij(0) = a1+a2+....+an

a1+a2+....+an
i j

Case 2:
If i=j, then the legal paths are the path of length 0 and all loops from i to itself.
The path of length 0 is represented by the regular expression ε, since that the path has no
symbols. So we add ε to the various expression of the above three cases a,b,c, that is,
a) There is no symbol so the expression becomes ε.
b) One symbol „a‟, so the regular expression ε+a.
c) Multiple symbols of „a‟, so the regular expression becomes ε+ a1+a2+....+an

Induction
Suppose there is a path from state i to state j that goes through no state higher than k and the two
possible cases are,
1. The path does not go through state k at all. The label of the path is in the language R ij(k-1)
2. The path goes through state k at least once. Then we can break the path into seven pieces as
shown below,

Prepared By: R.GAJENDIRAN ,ASP/IT 22


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

(k-1) (k-1)
Rik (k-1) Rkj
Rkk

Breaking the path into several pieces has following,


i. The first path goes from i to state k without passing through k, the last piece of path
goes from k to j without passing through k.
ii. All the pieces in the middle go from k to itself, without passing through the state k, ie
Rij(k-1)
iii. If the path goes through state k only once, then there are no middle pieces, just a path
from I to k and a path from k to j
The set of labels for all, path is represented by the regular expression
Rik(k-1) (Rkk(k-1) )*Rkj(k-1)
Here the first expression represents the path that goes to state k.
The second expression represents the portion that goes from state k to itself
The third expression represents the path that leaves k for the last time and goes to state j.
When we combine the expression for the paths of the above pieces, we have the expression as,

Rij(k-1)= Rij(k-1) +Rik(k-1) (Rkk(k-1) )*Rkj(k-1)


For the labels of all paths from state i to j that go through no state higher than „k‟. Thus we have Rij(n)
for all i and j. And we may assume that state 1 is the initial state and the accepting states could be any
set of the states.
ie, L(A)= U Rij(n)
qj in F

Then the regular expression for the language of the automata is the sum of all expressions Rij(n) such
that state j is an accepting state and
L(A)=L(R).

Prepared By: R.GAJENDIRAN ,ASP/IT 23


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Finite automata to regular expression


9. Convert the following finite automata to regular expression.

0, 1

Start 0
1 2

The general formula for the conversion of finite automata into regular expression is,
R i j ( k) = R i j ( k- 1 ) + R ik
( k- 1 )
(R k k ( k- 1 ) ) * R kj ( k- 1 )
where,
i initial state
j Final state
k total number of states
R Regular expression
For example take the expression R13(2) here i=1, j=3, k=2
Where,
 State 1 is the initial state.
 State 3 is the final state.
The value k represents that there are 2 intermediate states.
Here in the above finite automata i=1, j=2, k=2. By applying the values to the formula,
we get
` R 1 2 ( 2 ) = R 1 2 ( 1 ) +R 1 2 ( 1) (R 2 2 ( 1 ) )* R 2 2 ( 1 )
Now to find the regular expression, the formula is,
R 1 2 ( 2 ) = R 1 2 ( 1 ) +R 1 2 ( 1 ) .(R 2 2 ( 1) )*R 2 2 ( 1 )
Find the values for R 1 2 ( 1 ) and R 2 2 ( 1 ) so, we have find the values for all regular
expression

Prepared By: R.GAJENDIRAN ,ASP/IT 24


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

k=0, i=1 and j=2.


R11(0) = 1
R12(0) = 0
R21(0) = Φ
R 2 2 ( 0 ) = 0 +1
k=1, i=1 and j=2
R 1 2 ( 1 ) = R 1 2 ( 0 ) +R 1 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 2 ( 0 )
= 0 + 1.1 *0
= 0 + 1 (1) * 0
= 0 + 1* 0
=0[Є+1*]
R 1 2 ( 1 ) = 01*
R 2 2 ( 1 ) = R 2 2 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 2 ( 0 )
= (0 +1) + ф (1) * 0  (ф .0 = ф)
= 0 + 1 + ф  (ф + 0 = 0)
R 2 2 ( 1 ) = (0+1)
Now,
R 1 2 ( 2 ) = R 1 2 ( 1 ) +R 1 2 ( 1 ) . (R 2 2 ( 1) ) * R 2 2 ( 1 )
= 01* + 01* (0+1) * (0+1)
= 01* (Є + (0+1)* (0+1)
= 01* (Є + (0+1) *)
= 01 * (0+1)*
Regular expression = 1*0 (0+1)*

Prepared By: R.GAJENDIRAN ,ASP/IT 25


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

10. Find the regular expression corresponding to the finite automata given below,
(May/June 2007)
1
0

0, 1

Start 0
1
q1 q2 q3

Solution
 i = initial state = 1
 j = Final state = 1, 2
 k = number of states = 3
R i j ( k) = R i j ( k- 1 ) + R ik
( k- 1 )
(R k k ( k- 1 ) ) * R kj ( k- 1 )
Result of the regular expression is = R 1 1 ( 3 ) + R 1 2 ( 3 )
Values of the Regular Expression for k=0
R11(0) = 0
R12(0) = 1
R13(0) = Φ
R21(0) = Φ
R22(0) = 1
R23(0) = 0
R31(0) = Φ
R32(0) = Φ
R 3 3 ( 0 ) = 0+1
Now for the value k=1
R 1 1 ( 1 ) = R 1 1 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 1 ( 0 )
= 0 + 00*0
R 1 1 ( 1 ) = 00*

Prepared By: R.GAJENDIRAN ,ASP/IT 26


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

R 1 2 ( 1 ) = R 1 2 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 2 ( 0 )
= 1 + 00*1
= 1 + 0*1
R 1 2 ( 1 ) = 0*1
R 1 3 ( 1 ) = R 1 3 ( 0 ) +R 1 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= Φ +0.0* Φ
R13(1) = Φ
R 2 1 ( 1 ) = R 2 1 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
` = Φ + Φ.0*0
R21(1) = Φ
R 2 2 ( 1 ) = R 2 2 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 2 ( 0 )
= 1 + Φ.0*1
= 1+ Φ
R22(1) = 1
R 2 3 ( 1 ) = R 2 3 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= 0 + Φ.(0)* Φ
= 0+ Φ
R23(1) = 0
R 3 1 ( 1 ) = R 3 1 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ.0*0
= Φ+ Φ
R31(1) = Φ
R 3 2 ( 1 ) = R 3 2 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ.0* 1
R32(1) = Φ
R 3 3 ( 1 ) = R 3 3 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= (0+1) + Φ.0* Φ
R 3 3 ( 1 ) = (0+1)

Prepared By: R.GAJENDIRAN ,ASP/IT 27


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Now for the value k=2:


R 1 1 ( 2 ) = R 1 1 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= 00* +0*1(1)* Φ
R 1 1 ( 2 ) = 00*
R 1 2 ( 2 ) = R 1 2 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= 0*1+0 *1.1*1
= 0*1 (Є+11*)
= 0*111 *
R 1 2 ( 2 ) = 0*11*
R 1 3 ( 2 ) = R 1 3 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= Φ +0*11*0
= Φ + 0*101*
R 1 3 ( 2 ) = 00*11*
R 2 1 ( 2 ) = R 2 1 ( 1 ) + R 2 1 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= Φ + 11* Φ
R21(2)= Φ
R 2 2 ( 2 ) = R 2 2 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 2 ( 1 )
= 1+ 11*1
= 1+11*
= 1 (1*+ Є)
R 2 2 ( 2 ) = 11*
R 2 3 ( 2 ) = R 2 3 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 0 +11*0
= 0 [ Є + 11* ]
R 2 3 ( 2 ) = 011*
R 3 1 ( 2 ) = R 3 1 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= Φ + Φ. 1* Φ
R31(2) = Φ
R 3 2 ( 2 ) = R 3 2 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 2 ( 1 )

Prepared By: R.GAJENDIRAN ,ASP/IT 28


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

= Φ + Φ.1* Φ
R32(2) = Φ
R 3 3 ( 2 ) = R 3 3 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= (0+1) + Φ 1* 0
= (0+1) + Φ
R 3 3 ( 2 ) = (0+1)
Result of the regular expression = R 1 1 ( 3 ) + R 12 ( 3 )
R 1 1 ( 3 ) = R 1 1 ( 2 ) + R 1 3 ( 2) . (R 3 3 ( 2 ) ) * R 3 1 ( 2 )
= 00* + 00*11*(0+1)* Φ
= 00* + Φ
R 1 1 ( 3 ) = 00*
R 1 2 ( 3 ) = R 1 2 ( 2 ) + R 1 3 ( 2) . (R 3 2 ( 2 ) ) * R 3 1 ( 2 )
= 0*11* + 00*11*(0+1)* Φ
= 0*11 + Φ
R 1 2 ( 3 ) = 0*11*
R 1 1 ( 3 ) + R 1 2 ( 3 ) = 00* + 0 * 11* = 0* (0+11*)
Regular Expression = 0* (0 +11*)

(2)
11. Find the regular expression for the set of all strings denoted by R 2 3 from the
DFA given below. [ Nov/Dec 2007]
0

1 1
1 2 3
0

Solution
 i = initial state = 1
 j = Final state = 1, 2
 k = number of states = 3
R i j ( k) = R i j ( k- 1 ) + R ik
( k- 1 )
(R k k ( k- 1 ) ) * R kj ( k- 1 )
Result of the regular expression is = R 2 3 ( 2 )

Prepared By: R.GAJENDIRAN ,ASP/IT 29


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

R11(0) = Є
R12(0) = 1
R13(0) = 0
R21(0) = 0
R22(0) = Є
R23(0) = 1
R31(0) = Φ
R32(0) = Φ
R33(0) = Є
Now for the value k=1
R 1 1 ( 1 ) = R 1 1 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 1 ( 0 )
= Є+ ЄЄ *Є
R11(1) = Є
R 1 2 ( 1 ) = R 1 2 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 2 ( 0 )
= 1 + Є (Є )*1
= 1 +1
R12(1) = 1
R 1 3 ( 1 ) = R 1 3 ( 0 ) +R 1 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= 0 + Є(Є )* 0
=0+0
R13(1) = 0
R 2 1 ( 1 ) = R 2 1 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
` = 0 + 0(Є)* Є
=0+0
R21(1) = 0
R 2 2 ( 1 ) = R 2 2 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 2 ( 0 )
= Є + 0(Є )*1
= 01
R 2 2 ( 1 ) =01

Prepared By: R.GAJENDIRAN ,ASP/IT 30


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

R 2 3 ( 1 ) = R 2 3 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= 1 + 0(Є)*0
= 1+0
R 2 3 ( 1 ) = 1+0
R 3 1 ( 1 ) = R 3 1 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ. Є* Є
= Φ + ΦЄ* 1
= Φ+ Φ1
R31(1) = Φ
R 3 2 ( 1 ) = R 3 2 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ (Є) *1
= Φ + Φ1 = Φ + Φ
R32(1) = Φ
R 3 3 ( 1 ) = R 3 3 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= Є+ Φ(Є)* 0
= Є+ Φ Є0 = Є+ Φ 0 = Є+ Φ
R33(1) = Є
Now for the value k=2:
R 1 1 ( 2 ) = R 1 1 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= Є + 1(01)*0 = Є + 01(01)* = 01(01)*
R 1 1 ( 2 ) = (01)*
R 1 2 ( 2 ) = R 1 2 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= 1+1(01)*(01)
= 1+1(01)*
=1(Є +(01)*)
R 1 2 ( 2 ) = 1(01)*
R 1 3 ( 2 ) = R 1 3 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 0+ 1(01)*(1+0)
= 0+ 1(01)*(1+0)

Prepared By: R.GAJENDIRAN ,ASP/IT 31


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

R 1 3 ( 2 ) = 0+(01)*(11+10)
R 2 1 ( 2 ) = R 2 1 ( 1 ) + R 2 1 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 0+01(01)*0
= 0+(01)*0
= 0 [Є+(01) ]
R 2 1 ( 2 ) = 0(01)*
R 2 2 ( 2 ) = R 2 2 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 2 ( 1 )
= 01+01(01)*01
= 01 (Є+(01)*)
R 2 2 ( 2 ) = 01(01)*
R 2 3 ( 2 ) = R 2 3 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= (1+0)+01(01)*(1+0)
= (1+0)( Є + (01)* )
R 2 3 ( 2 ) = (1+0)(01)
Regular Expression is (1+0) (01)
(3)
12. Find the regular expression for the set of all strings denoted by R 1 3 from the
DFA given below. [ Nov / Dec 2008]

0 1
q1 q2 q3

0 0

Prepared By: R.GAJENDIRAN ,ASP/IT 32


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Solution
 i = initial state = 1
 j = Final state = 1, 2
 k = number of states = 3
R i j ( k) = R i j ( k- 1 ) + R ik
( k- 1 )
(R k k ( k- 1 ) ) * R kj ( k- 1 )
Result of the regular expression is = R 1 2 ( 3 ) + R 1 3 ( 3 )
Values of the Regular Expression for k=0
R11(0) = Є
R12(0) = 0
R13(0) = 1
R21(0) = 0
R22(0) = Є
R 2 3 ( 0 ) = 1+0
R31(0) = Φ
R32(0) = Φ
R33(0) = Є
Now for the value k=1
R 1 1 ( 1 ) = R 1 1 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 1 ( 0 )
= Є + Є Є* Є
R11(1) = Є
R 1 2 ( 1 ) = R 1 2 ( 0 ) + R 1 1 ( 0) . (R 1 1 ( 0 ) ) * R 1 2 ( 0 )
= 0+ Є Є*0
= 0+ 0
R12(1) = 0
R 1 3 ( 1 ) = R 1 3 ( 0 ) +R 1 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= 1+ Є Є*1
= 1+1
R13(1) = 1
R 2 1 ( 1 ) = R 2 1 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )

Prepared By: R.GAJENDIRAN ,ASP/IT 33


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

` = 0 +0 + Є* Є = 0+0
R21(1) = 0
R 2 2 ( 1 ) = R 2 2 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 2 ( 0 )
= Є +0 Є *0
= Є +00
R 2 2 ( 1 ) = 00
R 2 3 ( 1 ) = R 2 3 ( 0 ) +R 2 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= (1+0) + 0 Є *1
= (1+0) + 01 = 1+0+01
= 1+0+( Є+1) = 1+01
= 1(Є +0)
R 2 3 ( 1 ) = 10
R 3 1 ( 1 ) = R 3 1 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ Є* Є
= Φ+ Φ
R31(1) = Φ
R 3 2 ( 1 ) = R 3 2 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 1 ( 0 )
= Φ + Φ Є*0
= Φ+ Φ
R32(1) = Φ
R 3 3 ( 1 ) = R 3 3 ( 0 ) +R 3 1 ( 0 ) . (R 1 1 ( 0) ) * R 1 3 ( 0 )
= Є + Φ Є* 1
R33(1) = Є
Now for the value k=2:
R 1 1 ( 2 ) = R 1 1 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= Є +0(00)*0
= Є+(00)*
R 1 1 ( 2 ) = (00)*
R 1 2 ( 2 ) = R 1 2 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )

Prepared By: R.GAJENDIRAN ,ASP/IT 34


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

= 0+0(00)*(0)
= 0 (Є+(00)*)
R 1 2 ( 2 ) = 0(00)*
R 1 3 ( 2 ) = R 1 3 ( 1 ) + R 1 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 1+0(00)*(10)*
=1+01(00)*
=1(Є+0(00)*)
R 1 3 ( 2 ) =10(00)*
R 2 1 ( 2 ) = R 2 1 ( 1 ) + R 2 1 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 0+0(00)*0
= 0(Є +(00)*)
R 2 1 ( 2 ) = 0(00)*
R 2 2 ( 2 ) = R 2 2 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 2 ( 1 )
= (00)+00(00)*
= 00(Є +(00)*)
R 2 2 ( 2 ) = (00)*
R 2 3 ( 2 ) = R 2 3 ( 1 ) + R 2 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= 10 +00(00)*10
= 10+(00)*10
R 2 3 ( 2 ) = 10(00)*
R 3 1 ( 2 ) = R 3 1 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 1 ( 1 )
= Φ + Φ(00)*0
R31(2) = Φ
R 3 2 ( 2 ) = R 3 2 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 2 ( 1 )
= Φ + Φ(00)*0
R32(2) = Φ
R 3 3 ( 2 ) = R 3 3 ( 1 ) + R 3 2 ( 1) . (R 2 2 ( 1 ) ) * R 2 3 ( 1 )
= Є + Φ (00)*0
= Є+ Φ

Prepared By: R.GAJENDIRAN ,ASP/IT 35


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

R33(2) = Є
Result of the regular expression = R 1 3 ( 3 ) + R 12 ( 3 )
R 1 2 ( 3 ) = R 1 2 ( 2 ) + R 1 3 ( 2) . (R 3 3 ( 2 ) ) * R 3 2 ( 2 )
= 0(00)* + 10(00)*Є* Φ
R 1 2 ( 3 ) = 0(00)*
R 1 3 ( 3 ) = R 1 3 ( 2 ) + R 1 3 ( 2) . (R 3 3 ( 2 ) ) * R 3 3 ( 2 )
= 10(00)*+10(00)*Є*Φ
= 10(00)*+ Φ
R 1 3 ( 3 ) = 10(00)*
R 1 2 ( 3 ) + R 1 3 ( 3 ) = 0(00)* 10(00)*= 0* (0+11*)
= (00)* (0+10) = (00)*(0+10)=(00)*(0(Є+1))
Regular Expression = (00)*01

13. Find the regular expression for the following finite automata using state
elimination technique.

0 1

q1 q2 q1
q2 q3 q1
*q3 q3 q2

Solution:
1 0

q1 q3

0 0

1
1 q2

Prepared By: R.GAJENDIRAN ,ASP/IT 36


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Step 1:
Consider the path q1  q3 by eliminating the state q2

1 0

q1 q3

0 0

q2

==> After eliminating state q2


1
0

Q1 Q3

00

As per the Rule 1 , R = R ij + Q i S * P j

Where R ij = Φ S=Φ
Qi=0 Pj = 0

R1 =Φ+0Φ*0
=Φ+0Φ 0
R1 = 00
Step 2:
Consider the path q3  q1

Prepared By: R.GAJENDIRAN ,ASP/IT 37


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

1 0 0
1
q1 q 11
3
Q1 Q3

1
1 q2

R ij = Φ , Q i = 1, S = Φ, P j = 1

R2 = Φ + 1 Φ * 1
R2 = 11

Step 3:
To eliminate q2, consider path q1  q2  q1

1+0
1
1
q1
0  q1

1
q2

Step 4 :
To eliminate q2, consider path q3  q2  q3

0
0+10
q3

0 q3

1
q2

Prepared By: R.GAJENDIRAN ,ASP/IT 38


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

By combining all the four steps, we get

1+01
0+10

00
Q1 Q3

11

Now as per the rule 2


R= ( R + SU * T) * S U *
Where R = 1 + 01
S = 00
U = 0 + 10
T = 11
Regular expression = ( ( 1+01) + 00(0+10) * 11 ) * 00 ( 0 + 10) *

ARDEN’S THEOREM
14. State and explain the conversion of DFA into regular expression using Arden’s
theorem. Illustrate with an example. [Nov/ Dec 2011][April/May 2024]
1. It is used to find the RE for the given finite state automata.
2. Let P & Q be two regular expressions over Σ. If P does not contain ε, then the equation in
R = Q + RP has a solution R = QP*.
Proof

Q + RP = Q + ( QP* ) P Because R = QP *
= Q ( ε + P * P)
= QP * = R
3. The principle of this theorem is :
i) The FA should not have ε moves.
ii) The FA should have only one start state say q1

Prepared By: R.GAJENDIRAN ,ASP/IT 39


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

iii) Its states are q1,q2, … qn


iv) R is the regular expression representing the set of strings accepted by the FA
v) α ij denotes the set of labels of edges from qi to qj.
If there is no edge
α ij = Φ
We will get
q1 = q1 α 11 + q2 α 21 + ….. + qn α n1 + ε
q2 = q1 α 12 + q2 α 22 + ….. + qn α n2

qn = q1 α 1n + q2 α 2n + ….. + qn α nn

Now by applying repeated substitution we can empress RE in terms of α ij


15. Find the regular expression for the following finite automata using Arden’s
theorem. 0 [Nov/ Dec 2011]
1 1
q1 q2

1
0
0
q3

Solution:
We can obtain regular expression by applying Arden‟s theorem.
Step 1:
i) Check whether FA does not have ε ε – moves
ii) It has only one start state
Step 2:
Express states interms of transitions. The transitions that required to reach q1 from other states is
Q1 = q1 0 +q3 0 + ε  1
Similarly for

Q2 = q2 1 + q1 1 + q3 1  2
Q3 = q 2 0  3
Now substitute 3 in 2

Prepared By: R.GAJENDIRAN ,ASP/IT 40


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Q2 = q2 1 + q1 1 + q2 01
Q2 = q2 ( 1+01) + q1 1

Since q2 is in LHS & RHS ( R = Q + R P ) we can write it has

Q2 = q1 1 ( 1+01) *

Now q1 = q1 0 + q2 00 + ε
= q1 0+ q1 1 ( 1+01) * 00 + ε
= q1 ( 0+1 ( 1+01) * 00) + ε
By applying Arden‟s theorem
Q1 = ε ( 0+1 ( 1+ 01) * 00 ) *
= ( 0+1( 1+01) * 00 ) *

Since q1 is a final state.


Regular expression = ( 0 + 1 ( 1+ 01) * 00) *.

16. Find the regular expression for the following finite automata using Arden’s
theorem.
1
0,1
0
q1 q2

Solution:
We can obtain regular expression by applying Arden‟s theorem.

Step 1:
i) Check whether FA does not have ε – moves
ii) It has only one start state

Prepared By: R.GAJENDIRAN ,ASP/IT 41


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Step 2:
Express states interms of transitions. The transitions that required to reach q1 from other states is
Q1 = q1 1 + ε  1
Similarly for

Q2 = q2 0 + q2 1 + q1 0  2
Since q1 is in LHS & RHS ( R = Q + R P ) we can write it has

Q1 = ε 1 * ( R = QP *)

Now q2 = q2 ( 0+1) + q1 0
= q1 0 ( 0 + 1 ) *
= 1 * 0 ( 0+1) *
Since q2 is a final state.
Regular expression = 1 * 0 ( 0+ 1) *.

PROBLEMS ON TESTING OF EQUIVALENCE OF REGULAR LANGUAGES

17. Verify whether the finite automata machine M1 and M2 shown below are
equivalent over the alphabet {0, 1}

0
1 0
0
Start 1 Start C D
A B

0
1
0
1

Prepared By: R.GAJENDIRAN ,ASP/IT 42


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Finite Automata M1 Finite Automata M2

Solution
Construct the table filling algorithm by combining the states of both the finite automata M1 and
M2.

A=c B
X
B
X
D

D X

E X X X

A B C D

Step 1
Do not compare the accepting and non accepting states. So the states (A, B) (A, E) (B, C) (B,
D) (C, E) (D, E) are not equivalent states.
Step 3
Compare each state to check their equivalent
1. Take (A, C) to check their equivalent
δ (A, 0) = A δ (A, 1) = B
δ (C, 0) = D δ (C, 1) = E
Take string 10
δ (A, 10) = A
δ (C, 10) = C
 So the states A and C while processing the string 0, it reaches final state. And while processing
1, it reaches some non accepting state. It reaches some non accepting state.
So the states A and C are equivalent.
2. Take (A, D) to check their equivalent
δ (A, 0) = A δ (A, 1) = B
δ (D, 0) = D δ (D, 1) = E
Take string 10
δ (A, 10) = A
δ (D, 10) = C

Prepared By: R.GAJENDIRAN ,ASP/IT 43


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

So the states A and D are equivalent.


3. Take (B, E) to check their equivalent
δ (B, 0) = A δ (B, 1) = B
δ (E, 0) = C δ (E, 1) = E
Take string 10
δ (B, 10) = A
δ (E, 10) = C
So states B and E are equivalent.
4. Take (C, D) to check their equivalent
δ (C, 0) = D δ (C, 1) = E
δ (D, 0) = D δ (D, 1) = E
Take string 10
δ (C, 10) = C
δ (D, 10) = C
So states C and D are equivalent
 Here the accepting states of finite automata M1 and M2 are equivalent and non accepting state
of the finite Automata M1 and M2 are equivalent. So the finite automata M1 and M2 equivalent.
The equivalent states are ,
A≡ C, A≡ D, B ≡ E, C ≡D
So the minimized states are,
A≡ C≡ D, B ≡ E,

0
0

Start
1
A≡C≡D B≡E

Prepared By: R.GAJENDIRAN ,ASP/IT 44


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

18. Verify whether the finite automata machine M1 and M2 shown below are
equivalent over the alphabet {a, b}. [MAY/JUNE 2007]

a
b
Start
q1
q2
b

b a a
a q6 q5
b
q2

q2 X a b b
a

q3 X X
b Start
q7 q4
q4 X X

a
q5 X X X

q6 X X X X

q7 X X X X

q1 q2 q3 q4 q5 q6

Solution:
Construct the table filling algorithm by combining the states of both the finite automata M1 and M2.

Step 1
 Here the initial states are q1 and q4 and the final states are q1 and q4. Do not compare the
accepting and non accepting states. So the states { (q1, q1) (q1, q3) (q1, q5) (q1, q6) (q1, q7)
(q4, q2) (q4, q3) (q4, q5) (q4, q6) (q4, q7) are not equivalent states.
Step 2
Compare each state to check their equivalent

Prepared By: R.GAJENDIRAN ,ASP/IT 45


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

1. Take (q1, q4) to check their equivalent


δ(q1, a) = q1 δ(q1, b) = q2
δ(q4, a) = q4 δ(q4, b) = q5
Take string bb
δ(q1, bb) = q1
δ(q4, bb) = q4
So states q1 and q4 are equivalent.
2. Take (q2, q3) to check their equivalent
δ(q2, a) = q3 δ(q2, b) = q1
δ(q3, a) = q2 δ(q3, b) = q3
So the states q2 and q3 are not equivalent
3. Take (q2, q5) to check their equivalent
δ(q2, a) = q3 δ(q2, b) = q1
δ(q5, a) = q6 δ(q5, b) = q4
Take string ba
δ(q2, ba) = q1
δ(q5, ba) = q4
So states q2 and q5 are equivalent.
4. Take (q2, q6) to check their equivalent
δ(q2, a) = q3 δ(q2, b) = q1
δ(q6, a) = q7 δ(q6, b) = q6
So states q2 and q6 are not equivalent.
5. Take (q2, q7) to check their equivalent
δ(q2, a) = q3 δ(q2, b) = q1
δ(q7, a) = q6 δ(q7, b) = q4
Take string aab
δ(q2, aab) = q1
δ(q7, aab) = q4
So states q2 and q7 are equivalent.
6. Take (q3, q5) to check their equivalent
δ(q3, a) = q2 δ(q3, b) = q3
δ(q5, a) = q6 δ(q5, b) = q4
So states q3 and q5 are not equivalent.
7. Take (q3, q6) to check their equivalent

Prepared By: R.GAJENDIRAN ,ASP/IT 46


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

δ(q3, a) = q2 δ(q3, b) = q3
δ(q6, a) = q7 δ(q6, b) = q6
Take string ab
δ(q3, ab) = q1
δ(q6, ab) = q4
So states q3 and q6 are equivalent.
8. Take (q3, q7) to check their equivalent
δ(q3, a) = q2 δ(q3, b) = q3
δ(q7, a) = q6 δ(q7, b) = q4
So states q3 and q7 are not equivalent.
9. Take (q5, q6) to check their equivalent
δ(q5, a) = q6 δ(q5, b) = q4
δ(q6, a) = q7 δ(q6, b) = q6
So states q3 and q5 are not equivalent.
10. Take (q5, q7) to check their equivalent
δ(q5, a) = q6 δ(q5, b) = q4
δ(q7, a) = q6 δ(q7, b) = q4
So states q5 and q7 are not equivalent.
11. Take (q6, q7) to check their equivalent
δ(q6, a) = q7 δ(q6, b) = q6
δ(q7, a) = q6 δ(q7, b) = q4
So states q6 and q7 are not equivalent.
The equivalent states are,
q1 ≡ q4, q2 ≡ q5, q2 ≡ q7, q5 ≡ q7 , q1 ≡ q6
so the minimized states are
q1 ≡ q4, q2 ≡ q5 ≡ q7, q3 ≡ q6
The minimized DFA is,

a b

Start q1 ≡ q4 q3 ≡ q6

b a
b a

q2 ≡ q5 ≡ q7
Prepared By: R.GAJENDIRAN ,ASP/IT 47
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

19. Discuss the basic approach to convert from NFA to regular expression. Illustrate with
an example. (Nov/Dec 2016)
Basis:
Zero operators. The Basis consists of three parts and the regular expression r must be Φ
or any symbol „a‟ for „a‟ in ∑.
iv. r = ε Path from start state to an accepting state for empty input symbol.
ε
q0 qf
q0 (or)

v. r = Φ No path from start state to an accepting state

q0 qf

vi. r = a Path from start state to final state on processing symbol „a‟.

a
q0 qf

Induction
There are three parts in the induction for the regular expression with the three operators‟
namely Union, Concatenation and Closure.
Assume that the theorem is true for the regular expression with fewer than „i‟ operators,
such that i≥1. Let „r‟ has „i‟ operators where „r‟ is the regular expression.

Case 1: Union of the regular expression


Let r, r1, r2 be the regular expression.
r=r1+r2 (or) r=r1 u r2 (or) r=r1/r2

 And „r‟ is the regular expression, which is the union of the regular expression r1 and r2.
 Already, the finite automata exist for the regular expression r1 and r2.

Prepared By: R.GAJENDIRAN ,ASP/IT 48


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

 Now while constructing the automata for the new regular expression r, we create a new
starting state, which has the transition on „ɛ‟ to the starting state of the both the regular
expression r1 and r2.
 Then there is a transition from the final state of both the regular expression r1 and r2 to
the new final state of regular expression „r‟ on ɛ transition. M1

M1

ε Q1 F1
ε r1
r1
ε ε
qf
Q0

r=r1+r2 ε
Q2 r2 F2
ε
ε r2
ε

M2 M2

Where,
M1=(Q1,∑1,δ1,q1,{f1})
M2=(Q2, ∑2, δ2,q2,{f2})
L(M1)=L(r1)
L(M2)=L(r2)
L(M)=L(M1) U L(M2)
M=(Q1 U Q2 U {q0,qf}, ∑1 U∑2 , δ1 U δ2, q0,{qf})

Case 2: Concatenation of the regular expression r1 and r2


r=r1.r2
 Where r is the regular expression formed by concatenating the regular expression r1 and
r2.
 While constructing the regular expression r, the starting state of the regular expression r1
becomes the starting state of „r‟.
 Similarly the accepting state of the regular expression „r2‟ becomes the final state of the
regular expression „r‟.

Prepared By: R.GAJENDIRAN ,ASP/IT 49


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

 The concatenation of the regular expression „r‟ is done by providing a path from the final
state of r1 to the start state of r2 on ε transition.

M2
M1

ε
Q0 qf Q1 r2 F1
r1

r = r1.r2

Where,
M1=(Q1,∑1,δ1,q0,{qf})
M2=(Q2, ∑2, δ2,q1,{f1})
L(M1)=L(r1)
L(M2)=L(r2)
L(M)=L(M1) U L(M2)
M=(Q1 U Q2 , ∑1 U∑2 , δ1 U δ2, q0,{f1})
Case 3: Closure operation of the regular expression r=r*
Let r1 be the regular expression and r is the regular expression formed by applying closure
operation to the regular expression r1.
 While constructing automata for r, we create a new start and provide a path from new
start state to the starting state of the regular expression r1.
 And provide a path from final state of r1 to the new final state of r on ε transition.
 Include transition path from final state of „r1‟ to the state of r1 on ε input.
 Include transition path from initial start state of „r‟ to the final state of „r‟ on ε input.
M1

ε
ε
ε
q0 q1 q2
r1 q3

L(r1)=L(M1) ;
ε

Prepared By: R.GAJENDIRAN ,ASP/IT 50


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

L(M)=L(M1)*;
M1=(Q1,∑1,δ1,q1,{q2});
M=(Q1U{q0,q3},∑ ,δ,q0,{q3})
Case 4:
The regular expression r is the same for the parenthesized regular expression r, that is r1= (r)
Let
L(r) = L ( M )
L(r1) = L ( M1 )
L( M ) = L (( M1 ))
L( r1 ) = L ( ( r ) )
Example:
Converting Regular Expression to Finite Automata
20.Convert the regular expression (a + b )* abb into NFA – ε. (April/May 2024)
Solution :
Step 1:
Let w = (a+b) a
a ε
2 3

6
1
b
4 5
ε
Step 2 : ε

W= ( a+b) *
ε
a
ε ε
2 3 ε
ε
6 7
0 1
b
4 5
ε
ε

ε
Step 3 :
W= abb a b
b
8 9 10 11

Prepared By: R.GAJENDIRAN ,ASP/IT 51


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Step 4:
W = (a + b ) * a b b
Combine step 2 and step 3

ε
a
ε ε
ε 2 3 ε a b
6
b 1 1
0 1 7 8 9 0 1
b
4 5
ε ε

Pumping Lemma
21. Theorem for pumping lemma for regular languages.[Nov/Dec2024]
Theorem:
Let L be a regular language. Then there exists a constant „n‟ which depends on the regular language „L‟
such that for every string ‟w‟ in L such |w| ≥ n, we can break w into three strings, w= xyz such that,

4. y ≠ ε (Or) |y| > 0 (Or) |y| ≥ 1


5. |xy| ≤ n
6. For all k ≥ 0, the string xy kz is also in L

This means that we can always find a non empty string „y‟ that is very near to the beginning of the
string „w‟ that can be pumped. And also this shows that repetition of the string „y‟ with any number of
times or deleting it keeps the resulting string in the regular language „L‟.
Proof:
Suppose L is regular, that is we assume that L is regular language. Then L=L(A) for some DFA „A‟. Let
us assume that DFA „A‟ has „n‟ states. Consider any string „w‟ of length „n‟ or more such that w =
a1,a2….am where m ≥ n and each ai is an input symbol.
We define, δ' (q0,a1a2….ai) = Pi
Where,
 i = 0,1,2……n
 δ is the transition function of A
 q0 is the start state of A

Prepared By: R.GAJENDIRAN ,ASP/IT 52


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

 Pi is the state A is in after reading the first „i‟ symbols of „w‟ and note that p0 = q0.
By the pigeonhole principle, it is not possible for the n+1 different Pi‟s for i=0,1,2,….n to be distinct,
since there are only „n‟ different states.
Thus, we can find two different integers i and j with 0 ≤ i ≤ j ≤ n, such that Pi=Pj.
Now we can break the string w as follows, (w=xyz)
1. x=a1a2…..ai
2. y=ai+1ai+2…..aj
3. z=aj+1aj+2……am
That is,
 x takes us Pi once
 y takes us from Pi back to Pi (Pi=Pj)
 z is the balance of w
The transition diagram is as follows,
y = a i+1………a j

x = a1………aj

P0 P1 Pm
z = aj+1………a m

We have to note that,


 x may be empty if i=0
 Also z may be empty if j=n=m
 y cannot be empty since i< j
Since j<k, the string aj+1……am is of length atleast 1, since k ≤ n, its length is no more than „n‟.
If Pm is in F, such that a1,a2……am is in L(A) then

a1a2…..aj aj+1aj+2…..ak ak+1ak+2……am is also in L(A) and L(M)


δ‟(q0,a1a2…….aj ai+1 ……. ak ak+1ak+2……. aj )
= δ ( δ ( δ „ ( q0, a1a2…..ai), ai+1ai+2…..ak ), ak+1ak+2……. aj )
=δ ( δ ( δ „ ( Pi, ai+1ai+2…..ak ), ak+1ak+2……. aj ) = δ „ ( Pj, ak+1ak+2……. aj) = Pm
Thus a1a2…..ai ai+1ai+2…..ak ak+1ak+2……aj is in L(M) for any i≥0. If the automata A receives the input
xykz for any k ≥ 0.

Prepared By: R.GAJENDIRAN ,ASP/IT 53


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Basis
Let k=0
If k=0, then the automata goes from the starting state P0 to final state Pm on input x. Since Pi is also Pj,
it must be that A goes from Pi to an accepting state on input Z.
Thus A goes from Pj to an accepting state on input z. Thus A accepts xz.

Induction : k>0
If k>0, then A goes from P0 to Pj on input x, circles from Pj to Pj „k‟ times on input yk, and then goes to
the accepting state on input z. Thus for any k ≥0, xykz is also accepted by A, such that xykz is in the
regular language „L‟. Hence proved.
Problems on Pumping Lemma
22. Show that the language L= { a n b n / n ≥ 1} is not regular.
[April/May 2024][Nov/Dec2024]
Solution:
a. Let us assume that given language „L‟ is a regular language.
b. The number of states of L={ a n b n / n ≥ 1} is n+n = 2n
c. Take one string „w‟ and calculate the length of the string
w= a n b n
d. If the length of the string, |w| ≥ n
2n ≥ n
So, we can break into three strings
e. W=xyz, let w = a i b i
Let us make the assumption that w= a i b i
m
xy= a
j
y=a
i-m i
z=a b
To check the assumption
m i-m i m+i-m i
xyz = a a b =a b = ai bi
So our assumption is correct.

iii. |xy| ≤ n
m
|a |≤ n m≤n

Prepared By: R.GAJENDIRAN ,ASP/IT 54


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

iv.
y ≠ε (or) | y | ≥ 1
j j
a ≠ ε (or) | a | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xykz is also in ‘L’.

xykz = xyy k-1 z = a m (a j) k-1 a i-m b i


= a m +j(k-1)+i-m b i = a i+j(k-1) b i
xykz = a i+j(k-1) b i
Put k=0, xy0z = a i+j(k-1) b i = a i+j(0-1) b i = a i-j b i ≠ a i bi
Put k=1 , xy1z = a i+j(k-1) b i = a i+j(1-1) b i = a i b i = a i bi
Put k=2, xy2z = a i+j(k-1) b i = a i+j(2-1) b i = a i+j b i ≠ a i bi

Since for k=0,2 we have the string that does not belong to the language L, so the language
L={ a n b n / n = 1} is not regular.

23. Prove that the set of strings of 0’s and 1’s, such that L={ww / w € {0,1}} is not
regular language. [NOV/DEC 2007]

Solution:
Let w = 0 n 1 n . So L = { 0 n 1 n 0 n 1 n | n ≥ 1}
a) Let us assume that given language „L‟ is a regular language.
b) The number of states of L={ 0 n 1 n 0 n 1 n / n ≥ 1} is n+n+ n+n = 4n
c) Take one string „w‟ and calculate the length of the string
w= 0 n 1 n 0 n 1 n
d) If the length of the string, |w| ≥ n
4n ≥ n
So, we can break into three strings
e) W=xyz, let w = 0 i 1 i 0 i 1 i
Let us make the assumption that w= 0 i 1 i 0 i 1 i
m
xy= 0
j
y=0
i-m i
z=0 1 0i 1i

Prepared By: R.GAJENDIRAN ,ASP/IT 55


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

To check the assumption


m i-m i m+i-m i
xyz = 0 0 1 0i 1i = 0 1 0i 1i = 0i 1i 0i 1i
So our assumption is correct.

v. |xy| ≤ n
m
|0 |≤ n m≤n
vi.
y ≠ε (or) | y | ≥ 1
j j
0 ≠ ε (or) | 0 | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.

xykz = xyy k-1 z = 0m (0 j) k-1 0 i-m 1 i 0 i 1 i


= 0 m +j(k-1)+i-m 1 i 0 i 1 i = 0 i+j(k-1) 1 i 0 i 1 i
xykz = 0 i+j(k-1) 1 i 0 i 1 i
Put k=0, xy0z = 0 i+j(k-1) 1i 0 i 1 i = 0 i+j(0-1) 1 i 0 i 1 i = 0 i-j 1 i 0 i 1 i ≠ 0 i 1 i 0 i 1 i
Put k=1 , xy1z = 0 i+j(k-1) 1 i 0 i 1 i = 0 i+j(1-1) 1 i 0 i 1 i = 0 i 1 i 0 i 1 i = 0 i 1 i 0 i 1 i
Put k=2, xy2z = 0 i+j(k-1) 1 i 0 i 1 i = 0 i+j(2-1) 1 i 0 i 1 i = 0 i+j 1 i 0 i 1 i ≠ 0 i 1 i 0 i 1 i

Since for k=0,2 we have the string that does not belong to the language L, so the language
L={ww / w € {0,1}} is not regular.

24. Show that L = { 1 k = n 2 , n ≥ 1} is not regular language. [NOV/DEC 2007]

Solution:
a) Let us assume that given language „L‟ is a regular language.
k 2
b) The number of states of L={ 1 = n , n ≥ 1} is n 2 = n
c) Take one string „w‟ and calculate the length of the string
k
w= 1 where k = n 2
d) If the length of the string, |w| ≥ n
n2 ≥n
So, we can break into three strings
k
e) W=xyz, let w = 1 where k = n 2

Prepared By: R.GAJENDIRAN ,ASP/IT 56


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

k
Let us make the assumption that w= 1
m
xy= 1
j
y=1
k-m
z=1
To check the assumption
m k-m
xyz = 1 1 = 1 k where k = n 2
So our assumption is correct.

i. |xy| ≤ n
m
|1 |≤ n m≤n
ii. y ≠ε (or) | y | ≥ 1
j j
1 ≠ ε (or) | 1 | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xykz is also in ‘L’.

xykz = xyy k-1 z = 1m (1 j) k-1 1 k-m


= 1 j(k-1)+k
xykz = 1 j(k-1)+k
Put k=0, xy0z = 1 j(k-1)+k = 1 j(0-1)+k = 1 k - j ≠ 1 k
Put k=1 , xy1z = 1 j(k-1)+k = 1 j(1-1)+k = 1 k = 1 k
Put k=2, xy2z = 1 j(k-1)+k = 1 j(2-1)+k = 1 k + j ≠ 1 k

Since for k=0,2 we have the string that does not belong to the language L, so the language
k 2
L = { 1 = n , n ≥ 1} is not regular language.

25. Prove that L= { a n /n = i 2, i ≥ 1} or L={ 0 n /n = i 2, i ≥ 1} is not regular.

Solution:
a) Let us assume that given language „L‟ is a regular language.
n
b) The number of states of L={ a / n = i 2, i ≥ 1} The number of states are n.
c) Take one string „w‟ and calculate the length of the string
n
Let w= a where n = i 2

Prepared By: R.GAJENDIRAN ,ASP/IT 57


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

d) The length of the string, |w| ≥ n


|w| = n
e) So, we can break into three strings
n
W=xyz, let w = a
Let us make the assumption that
m
xy= a
j
y=a
i-m
z=a
f) To check the assumption
m n-m
xyz = a a =an
So our assumption is correct.

i. |xy| ≤ n
m
|a |≤ n m≤n
ii. y ≠ε (or) | y | ≥ 1
j j
a ≠ ε (or) | a | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.

xykz = xyy k-1 z = am (a j) k-1 a n - m


= a j(k-1)+n
xykz = a j(k-1)+n
Put k=0, xy0z = a j(k-1)+n = a j(0-1)+n = a n - j ≠ a n
Put k=1 , xy1z = a j(k-1)+n = a j(1-1)+n = a n = a n
Put k=2, xy2z = a j(k-1)+n = a j(2-1)+n = a n + j ≠ a n
Since for k=0,2 we have the string that does not belong to the language L, so the language
L = { a n /n = i 2, i ≥ 1} is not regular language.

26. Prove that L= { a 2n / n ≥ 1} is regular. [MAY/JUNE 2007 ]


Solution:
g) Let us assume that given language „L‟ is a regular language.
2n
h) The number of states of L={ a / n ≥ 1} The number of states are 2n.

Prepared By: R.GAJENDIRAN ,ASP/IT 58


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

i) Take one string „w‟ and calculate the length of the string
2n
Let w= a
j) The length of the string, |w| ≥ n
|w| = 2n
k) So, we can break into three strings
n
W=xyz, let w = a
Let us make the assumption that
m
xy= a
j
y=a
2n-m
z=a
l) To check the assumption
m 2n - m
xyz = a a = a 2n
So our assumption is correct.
i. |xy| ≤ n
m
|a |≤ n m≤n
ii. y ≠ε (or) | y | ≥ 1
j j
a ≠ ε (or) | a | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xykz is also in ‘L’.
xykz = xyy k-1 z = am (a j) k-1 a 2n - m
= a j(k-1)+2n
xykz = a j(k-1)+2n
Put k=0, xy0z = a j(k-1)+2n = a j(0-1)+2n = a 2n - j ≠ a 2n
Put k=1 , xy1z = a j(k-1)+2n = a j(1-1)+2n = a 2n = a 2n
Put k=2, xy2z = a j(k-1)+n = a j(2-1)+ 2n = a 2n + j ≠ a 2n
Since for k=0,2 we have the string that does not belong to the language L, so the language
L = { a 2n / n ≥ 1} is not regular language.

27. Prove that √ 2 is not rational. [Nov / Dec ‘2011]


Solution:
Proof:
A number is rational if it is a fraction m/n where m,n are integers. i.e. it is the ration of m and n.
A number is if it is not rational; we assume the conclusion is false. i.e. √ 2 is rational.

Prepared By: R.GAJENDIRAN ,ASP/IT 59


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

√ 2 = m / n where m , n are integers. Both m & n cannot be even numbers.


Multiply both sides by n we obtain
n√2 =m Square both the sides.
2 2
2n =m
m 2 is 2 times the integer n 2 , So m2 is even. So m is even
m = 2 k.
2 n 2= ( 2 k ) 2 = 4 k 2  n 2 = 2 k 2
So n 2 is even and hence n is even. Thus we have established both m , n are even which is contradiction
to our assumption.
So √ 2 is irrational.

28. State the pumping lemma for Regular languages. Show that the set L={ 0 i 2 / i ≥ 1} is
not regular. [Nov/Dec 2015 ]
Solution:
a) Let us assume that given language „L‟ is a regular language.
b) The number of states of L={ 0 i2 / i ≥ 1} The number of states are n=i2.
c) Take one string „w‟ and calculate the length of the string
Let w= 0 i2
d)
The length of the string, |w| ≥ n
|w| = n2
e) So, we can break into three strings
W=xyz, let w = 0 i 2
Let us make the assumption that
xy= 0 m
y=0j
z = 0 n-m
f) To check the assumption
xyz = 0 m 0 n - m = 0 n
So our assumption is correct.
i. |xy| ≤ n
|0m|≤n m≤n
ii. y ≠ε (or) | y | ≥ 1

Prepared By: R.GAJENDIRAN ,ASP/IT 60


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

0 j ≠ ε (or) | 0 j | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.
xykz = xyy k-1 z = 0m (0 j) k-1 0 n - m
= 0 j(k-1)+n
xykz = 0 j(k-1)+n
Put k=0, xy0z = 0 j(k-1)+n = 0 j(0-1)+2n = 0n - j ≠ 0n
Put k=1 , xy1z = 0 j(k-1)+n = 0 j(1-1)+n = 0n = 0n
Put k=2, xy2z = 0 j(k-1)+n = 0j(2-1)+ n = 0n + j ≠ 0n
Since for k=0,2 we have the string that does not belong to the language L, so the language
L = { 0 i2 / n ≥ 1} is not regular language.

30. Define regular expression. Show that. [NOV/DEC 2011]


( 1+00 * 1) + ( 1+00 * 1) (0+10*1)* (0+10*1) = 0 * 1( 0+10 * 1)*
Solution:
LHS
= ( 1+00 * 1) + ( 1+00 * 1) (0+10*1)* (0+10*1)
= ( 1+00 * 1) (ε + (0+10*1)* (0+10*1) )
=1 ( ε + 00 * ) ((0+10*1)* (0+10*1) )
= 1 00 * (0+10*1)* [ Since 00* = 0*]
= 0 * 1 (0+10*1)*
= RHS
Hence proved.

29. Explain briefly about Closure Properties of Regular Languages. [Nov/Dec 2017]
Prove that regular expressions are closed under union, intersection and Kleene
closure. [Nov/Dec 2021]

CLOSURE PROPERTIES OF REGULAR LANGUAGES


The principal closure properties of regular languages are,
a. Union of two regular languages is regular
b. Intersection of two regular languages is regular
c. Complement of a regular language is regular
d. Difference of two regular languages is regular

Prepared By: R.GAJENDIRAN ,ASP/IT 61


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

e. Reversal of a regular language is regular


f. Closure of regular language is regular
g. Concatenation of regular language is regular
h. Homomorphism of a regular languages is regular
i. The Inverse Homomorphism of a regular languages is regular

CLOSURE OF REGULAR LANGUAGES UNDER BOOLEAN OPERATIONNS

The closure properties of the regular languages of the three Boolean operations are
(i) Let L and M be languages over alphabet ∑. Then L U M is the language that contains all
strings that are in either or both of L and M.
(ii) Let L and M be languages over alphabet ∑.Then L ∩ M is the language that contains all
strings that are both in L and M.
(iii) Let be languages over alphabet ∑. Then L‟, the complement of L ,is the set of strings in ∑ *
that are not in L.
CLOSURE UNDER UNION
Theorem: If L and M are regular languages, then LUM is also the regular language.
Proof: Since L and M are the regular languages, then they have regular expressions say the language
L=L(R) and M=L(S). Then LUM=L(R+S) by the definition of union operation of regular expressions.

CLOSURE UNDER CONCATENATION


Theorem: If L and M are regular languages, then LM is also the regular language.
Proof: Since L and M are the regular languages, then they have regular expression of the form, L=L(R)
and M=L(S) such that L(M)=L(R).L(S).
L(M)=L(RS)
CLOSURE PROPERTY UNDER CLOSURE OPERATION
Theorem: If L is a regular language, then L* is also a regular language.
Proof: Since L is a regular language, then it has the regular expression of the form of language L=L(R)
such that L*=(L(R))*.
CLOSURE UNDER COMPLEMENTATION
The complementation of the regular language “L” is denoted as Lc, L‟.The complementation is denoted
as,
L’=∑*-L
The complementation of the regular language “L” is the set o0f strings ∑* that are not in L.
If ∑*={ε,a,b,aa,ab,aab,…..}and L={a,b,ab}

Prepared By: R.GAJENDIRAN ,ASP/IT 62


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Then L‟={ε,aa,aab,….}
The steps for finding a regular expression for its complement are as follows,
1. Convert the regular expressions to NFA-ε
2. Convert the NFA-ε to DFA by the subset construction
3. Complement the accepting states of that DFA.
4. Convert the complement DFA into Regular expression using Rij(k) or by using state
elimination technique.
EXAMPLE TO FIND THE REGULAR EXPRESSION FOR ITS COMPLEMENTS
30. Find the complement of the regular expression R=(0+1)*01
Solution:
Step 1: Convert the regular expression to an NFA-ε

3 4 ε 1
0
ε 0 ε 7 8 9 10
ε
2
1 1

ε 5 6

Step 2: Convert the NFA ε to DFA. Else we can find the NFA for the regular expression (0+1)*01
0,1

0 1

q0 q1 q2

Step 3: Complement the DFA by converting it from NFA. The DFA is,

1
0

0 1
q0 q0, q0,
q1 q2
0

Prepared By: R.GAJENDIRAN ,ASP/IT 1 63


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Step 4: Complement the DFA by changing accepting state to non-accepting state.

1
0

0 1
q0,
q0 q0, q2
q1
0

CLOSURE UNDER INTERSECTION


Once we have obtained the union and the complementation of the regular language, then we can obtain the
intersection of the regular languages L and M by the following.
Generally the intersection of two sets is the set of element that are not in the complement of either set.
L∩M= LU M
Theorem:
If L and M are regular language, then the integration of the language L and M is L∩M is also
regular.
Proof: Let L and M be the language of automata
AL=(QL,∑ ,δL,qL,FL)
AM=(QM,∑ ,δM,qM,FM)
Here we are assuming that the alphabets of both the automata are the same. ∑ is the union of the
alphabets of L and M, if those alphabets are different. Now we have to construct the intersection of L and M
L∩M that simulates both AL and AM. Here we assume that both AL and AM are DFA and construct „A‟. The
states of A are pairs of states, the first from AL and the second from AM.
To design the transitions of A , suppose A is the state(p,q) where p is the state of A L and q is the
state of AM. If „a‟ is the input symbol, then the transitions of AL and AM are as follows,
δ(p,a)=s
δ(q,a)=t
ADFA AL∩ AM.
So now the next state of A will be (s,t). So now A has simulated the effect of both AL and AM. This is
shown below in the figure. The automata simulating two other automata and accepting if and only if both
accept is shown below.

Prepared By: R.GAJENDIRAN ,ASP/IT 64


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Input a

Accept
AL
AND

AM
Figure. Closure under intersection
The start of A is the pair of start states of AL and AM. Since we want to accept if and only if both the
automata accept. So we select those pairs (p,q) such that p is the accepting state of Ac and q is the accepting
state of AM. So we can formally define A as,
A= (QL XQM,∑ ,δ,(qL,qM ),FLX FM)
Where
δ((p,a),a)=(δL(p,a), δM(q,a))
So the string „w‟ is accepted by A if and only if both AL and AM accepts the string w.
δ‟((ql,qM),a)=(δ‟L(qL,w),δ‟M (qM,w))
But A accepts the string w if and only if δ‟ ((ql,qM),w) is a pair of accepting states such that,
δ‟L(qL,w)=FL
δ‟M (qM,w)=FM
Thus A accepts the intersection o f L and M.
EXAMPLE PROBLEM
Construct A∩B where A and B are DFA and it is given below.
1 0,1
0,1
start P 0 0q start 1
r s
DFA „A‟ DFA „B‟
SOLUTION

Prepared By: R.GAJENDIRAN ,ASP/IT 65


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

The definition for the DFA „A‟ is A=(Q A,∑,δA,p,q)


The definition for the DFA „B is B=Q B,∑,δB,r,s)
Now we have to construct A∩B and the definition
A∩B=(QAXQB),∑,δAXδB,(p,r),(q,s))
So the DFA for A∩B is,
QAXQB={p,q}X{r.s}={(p,r)(p,s)(q,r)(q,s)} 1

1
p,r p,s

0 1

0 1
0,1
q,r
q,s

CLOSURE UNDER DIFFERENCE


The difference of the regular language L and M is denoted by L-M is denoted by L-M. The
difference L-M is the set of strings that are in language L but not in the language M.
Theorem:
If L and M are regular languages, then the difference L-M is also regular language.
Proof:
The difference of the regular language L-M is denoted as L-M=L∩ M.
By the previously proved theorems, we know that M is regular, L U M is also regular.
CLOSURE UNDER REVERSAL
The reverse of the string W is WR. If the string w is given as,
W=a1a2a3………an
Then WR= an an-1….. a3 a2 a1
EXAMPLE:

If L={001,1011,1111} then
LR={100,1101,1111}
If the language is reversed from the regular language L, then the reversed language is also regular. This
can be proved by two methods.
1. Proof based on Automata
2. Proof based on Regular Expression.

Prepared By: R.GAJENDIRAN ,ASP/IT 66


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Proof based on Automata


Theorem: If L is regular language ,then its reverse LR is also regular
Proof:
Given a language L that is L(A) for some finite Automata A. Now the reverse language L R is
constructed by the following steps.
Step 1: Reverse all the arcs in the transition diagram for A.
Step 2: Make the start state of A be the only accepting state for the new automata.
Step 3: Create a new start state P0 with the transitions on ε to all the accepting states of A.
The resultant automata are the one that simulates A in Reverse and therefore it accepts
the string W if and only if A accepts WR.
Proof based on Regular Expression
Theorem:
If a language L is regular , then its reverse is also regular language. So is L R.
Proof:
Assume that the language defined by the regular expression E is denoted by L(E).
Here we show that there is another regular expression E R which is the reverse of the regular expression
E such that L(ER)=(L(E))R
Where L(ER) is the language of the regular expression ER
Basis:
IF E=ε then εR
IF E=φ then φR =φ
IF E=a then aR=a
Induction:
There are three cases for the regular expression E involving the three operations of the regular
expressions such as union, concatenation and closure.
Case 1:
E=E1+E2 ER= ER1+ ER2
The Reversal of the union of two languages is obtained by computing the reversals of the two languages
and taking the union of those languages.
Case 2:
If E=E1E2 Then ER= ER2ER1
While we finding the reverse of the concatenation, We reverse the order of the two languages as well as
reversing the languages themselves.

Prepared By: R.GAJENDIRAN ,ASP/IT 67


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

L(E1)={01,111}
L (E2)={00,10}
Then L(E1E2)={0100,0110,11100,11110}
The reversal of the language L(E1E2) is L(E1E2)R
L(E1E2)R={0010,0110,00111,01111}
Now we concentrate the reversal of L(E1) and L(E2)
L(ER1)={10,111}
L(ER2)={00,01}
L(ER2ER1)={00,01} {10,111}={0010,0110,00111,01111}
So in general if a word w in L(E) is the concatenation of w 1 from L(E1) and w2 from L(E2) , then
WR=wR2wR1
Case 3:
E=E1* then ER=( ER)*
If there is a string w is in L(E), then wR is the reverse of the string w
w=w1w2w3….. wn
R
w =wn wn-1…… w2 w1
Then the string wR is in the language L(ER1)* since wR is in L(ER) . Thus if the string is in L(E) if and
only if its reversal is in (L(ER1)*)
Homomorph ism
 Homo morphis m is a funct io n on st r ings t hat works by subst it ut ing a part icular
st r ing for each s ymbo l. The ho mo morphis m o f t he language „L‟ is denot ed as h
(L).
 For exa mple if t he funct ion is defined by,
h (0)= ab
h (1) = Є
 By t he above funct ion o f ho mo mo rphism, given any st ring of 0‟s and 1‟s , it
replaces all 0‟s by t he st r ing ab, since h(0)=ab. It replaces all t he occurrence of
t he st r ing 1‟s by Є, since h(1)= Є
 For exa mple if t he st r ing w=0011, t hen
h(w) = h(0) h(0)h(1) h(1)
= (ab)(ab)(Є)(Є)
h(w) = aba b
 So by t he abo ve example, if „h‟ is a ho mo morphis m on alphabet Σ and
w = a1a2……an is a st r ing of symbo ls in Σ t hen

Prepared By: R.GAJENDIRAN ,ASP/IT 68


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

h(w)= h(a1) h(a2)…. h(an).


 So we have t o apply ho mo morphis m funct io n „h‟ t o each symbo l o f st r ing w and
concat enat e t he result s in order. Th us if L is a language over alphabet Σ and h
is a ho mo morphis m on Σ , t hen
h (L) = { h(w)/w is in L}
Theorem
 If L is a regular language over alphabet Σ and h is a homomorphism on Σ, then h (L) is also
regular language.
Proof
 Let L = L(R) for some regular expression R. If E is the regular expression with symbols in Σ.
Let h (E) is the expression that is obtained by replacing each symbol a in Σ that is present in E
by h(a). We have to prove that h® defines the language h(L), such that,
L(h(E))= h(L(E))
Basis
1. If E is Є or Ф, then h (E) is same as E then,
h (Є) = E
h (Ф) = E
Thus L(h(E)) = L(E)
2. If E is Ф or Є, then L(E) contains either no strings or a string with no ymbols.
Thus,
h(L(E)) = L(E)

h (L)

h
h
L (L)

Thus we can conclude


So, L(h(E)) = L(E) = h(L(E))
If E = a for some symbol a in Σ, such that L(E) = a
h(a) = E
and h(L(E)) = { h(a) }
And L(h(E)) is also h(a). so we can conclude
L(h(E)) = h(L(E))

Prepared By: R.GAJENDIRAN ,ASP/IT 69


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Induction
There are three cases in the induction part.
Case 1 : E = F+ G where E, F, G are the regular expressions denoting the language L(E), L(F)
and L(G) respectively. By applying homomorphism to the regular expression as,
h (E) = h (F+G) = h (F) + h(G)
We know that L(E) = L(F) Ú L(G)
So
L(h(E))= h(L(F) Ú L(G))
L(h(E))= h(L(F)) Ú h(L(G))
Case 2: E=FG where E is the regular expression formed by the concatenation of the regular
expression F and G. By applying homomorphism, we get
h (E) = h (FG)
L(F)= L(F) . L(G)
So, L(h(E))= L(h((F) . h(G))
L(h((F) . h(G))
Case 3: E = E1* by applying a homomorphism
h(E)=h(E1)*
We know that L(E) = (L(E))*
So, L(h(E)) = L(h(E))*
h(L(E))= h(L(E))*
Thus by applying homomorphism h to the regular expression for the language L results in a regular
expression that defines the language h(L).

31. Construct a minimum state automata equivalent to a given automata M whose


transition table is given below. [ May/June 2007]
a b
q0 q0 q3
q1 q2 q3
q2 q3 q4
q3 q0 q5
q4 q0 q6
q5 q1 q4

Prepared By: R.GAJENDIRAN ,ASP/IT 70


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

*q6 q1 q3

Step 2:
Do not compare the accepting and non-accepting states. So (q0, q6) (q1.q6) (q2,q6) (q3,q6)
(q5,q6) are not equivalent states. Here,
q0 initial state
q6Final state.
Step 3:
Compare each pair of states to check their equivalent
1. Take pair (q0,q1) to check their equivalent
δ(q0,a)=q0 δ (q1,a)=q2 δ (q0,b)=q3 δ (q1,b)=q5
Take the sting aaa
δ (q0,aaa)=q0
δ (q1,aaa)=q0
Take the string aaabbbb
δ (q0,aaabbbb)=q6
δ (q1,aaabbbb)=q6
So state (q0, q1) are equivalent

Prepared By: R.GAJENDIRAN ,ASP/IT 71


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

2. Take (q0,q2)to check their equivalent


δ(q0,a)=q0 δ(q0,b)=q3 δ(q2,a)=q3 δ(q2,b)=q4
Take the string aaabbbb
δ (q0,aaabbbb)=q6
δ (q2,aaabbbb)=q6
So states q0 and q2 are equivalent states
3. Take (q0,q3) to check their equivalent
δ(q0,a)=q0 δ (q0,b)=q3 δ (q3,b)=q5 δ (q3,a)=q0
Take the string abbbb
δ (q0,abbbb)=q6
δ (q3,abbbb)=q6
So states q0 and q3 are equivalent states
4. Take (q0,q4) to check their equivalent
δ(q0,a)=q0 δ (q0,b)=q3 δ(q4,a)=q0 δ(q4,b)=q6
Take the string abbbb
δ (q0,abbbb)=q6
δ (q4,abbbb)=q6
So states q0 and q4 are equivalent states
5. Take (q0,q5) to check their equivalent
δ(q0,a)=q0 δ (q0,b)=q3 δ(q5,a)=q1 δ(q5,b)=q4
Take the string aaaabbbb
δ (q0,aaaabbbb)=q6
δ (q5,aaaabbbb)=q6
So states q0 and q5 are equivalent states
6. Take (q1, q2) to check their equivalent
δ(q1,a)=q2 δ (q1,b)=q5 δ(q2,a)=q3 δ(q2,b)=q4
Take the string aaaabbbb
δ (q1,aaaabbbb)=q6
δ (q2,aaaabbbb)=q6
So states q1 and q2 are equivalent states
7. Take (q1, q3) to check their equivalent
δ(q1,a)=q2 δ (q1,b)=q5 δ(q3,a)=q0 δ(q3,b)=q5
Take the string bbb
δ (q1,bbb)=q6
δ (q2,bbb)=q6
So states q1 and q3 are equivalent states
8. Take (q1, q4) to check their equivalent
δ(q1,a)=q2 δ (q1,b)=q5 δ(q4,a)=q0 δ(q4,b)=q6
Take the string ababbbb
δ (q1, ababbbb)=q6
δ (q2, ababbbb)=q6
So states q1 and q4 are equivalent states
9. Take (q1, q5) to check their equivalent
δ(q1,a)=q2 δ (q1,b)=q5 δ(q5,a)=q1 δ(q5,b)=q4
Take the string aaaabbbb
δ (q1, aaaabbbb)=q6
δ (q2, aaaabbbb)=q6

Prepared By: R.GAJENDIRAN ,ASP/IT 72


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

So states q1 and q5 are equivalent states


10. Take (q2, q3) to check their equivalent
δ(q2,a)=q3 δ (q2,b)=q4 δ(q3,a)=q0 δ(q3,b)=q5
Take the string aabbbb
δ (q2, aaaabbbb)=q6
δ (q3, aaaabbbb)=q6
So states q2 and q3 are equivalent states
11. Take (q2, q4) to check their equivalent
δ(q2,a)=q3 δ (q2,b)=q4 δ(q4,a)=q0 δ(q3,b)=q6
Take the string aabbbb
δ (q2, aabbbb)=q6
δ (q3, aabbbb)=q6
So states q2 and q4 are equivalent states
12. Take (q2, q5) to check their equivalent
δ(q2,a)=q3 δ (q2,b)=q4 δ(q5,a)=q1 δ(q5,b)=q4
Take the string bb
δ (q2, bb)=q6
δ (q5, bb)=q6
So states q2 and q5 are equivalent states
13. Take (q3, q4) to check their equivalent
δ(q3,a)=q0 δ (q3,b)=q5 δ(q4,a)=q0 δ(q4,b)=q6
Take the string abbbb
δ (q3, abbbb)=q6
δ (q4, abbbb)=q6
So states q3 and q4 are equivalent states
14. Take (q3, q5) to check their equivalent
δ(q3,a)=q0 δ (q3,b)=q5 δ(q5,a)=q1 δ(q5,b)=q4
Take the string aababbbb
δ (q3, aababbba)=q6
δ (q5, aababbba)=q6
So states q3 and q5 are equivalent states
15. Take (q4, q5) to check their equivalent
δ(q4,a)=q0 δ (q4,b)=q6 δ(q5,a)=q1 δ(q5,b)=q4
Take the string aababbbb
δ (q3, aababbba)=q6
δ (q5, aababbba)=q6
So states q4 and q5 are equivalent states
So the equivalent states are,
q0 ≡ q1, q0 ≡q2, q0 ≡q3, q0 ≡q4, q0 ≡q5, q1 ≡ q2, q1 ≡q3, q1 ≡ q4, q1 ≡q5,
q2 ≡q3, q2 ≡q4, q2 ≡q5, q3 ≡ q4, q3 ≡q5, q4 ≡ q5,
So the minimized states are,
Equivalent states:
q0 ≡ q1, q2 ≡ q3, q4 ≡ q5, q6

The minimized DFA is,

Prepared By: R.GAJENDIRAN ,ASP/IT 73


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

a,b

q0 ≡ q1 ≡ q2 ≡ q3 ≡ q4 ≡ q5 q6

Prepared By: R.GAJENDIRAN ,ASP/IT 74


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

32. State and prove any two closure properties of regular Languages.(Nov/Dec 2020)
CLOSURE OF REGULAR LANGUAGES UNDER BOOLEAN OPERATIONNS

The closure properties of the regular languages of the three Boolean operations are
(i) Let L and M be languages over alphabet ∑. Then L U M is the language that contains all
strings that are in either or both of L and M.
(ii) Let L and M be languages over alphabet ∑.Then L ∩ M is the language that contains all
strings that are both in L and M.
(iii) Let be languages over alphabet ∑. Then L‟, the complement of L ,is the set of strings in ∑ *
that are not in L.
CLOSURE UNDER UNION
Theorem: If L and M are regular languages, then LUM is also the regular language.
Proof: Since L and M are the regular languages, then they have regular expressions say the language
L=L(R) and M=L(S). Then LUM=L(R+S) by the definition of union operation of regular expressions.

Prepared By: R.GAJENDIRAN ,ASP/IT 75


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

33.Prove that the following languages are not regular using pumping lemma.
(i) All unary strings of length prime
(ii) L={uu/u€{0,1}*}
Solution:
(ii)Prove that the set of strings of 0’s and 1’s, such that L={uu / u € {0,1}} is not
regular language. Nov/Dec 2020
Solution:
Let u = 0 n 1 n . So L = { 0 n 1 n 0 n 1 n | n ≥ 1}
a) Let us assume that given language „L‟ is a regular language.
b) The number of states of L={ 0 n 1 n 0 n 1 n / n ≥ 1} is n+n+ n+n = 4n
c) Take one string „w‟ and calculate the length of the string
w= 0 n 1 n 0 n 1 n
d) If the length of the string, |w| ≥ n
4n ≥ n
So, we can break into three strings
e) W=xyz, let w = 0 i 1 i 0 i 1 i
Let us make the assumption that w= 0 i 1 i 0 i 1 i
m
xy= 0
j
y=0
i-m i
z=0 1 0i 1i
To check the assumption
m i-m i m+i-m i
xyz = 0 0 1 0i 1i = 0 1 0i 1i = 0i 1i 0i 1i
So our assumption is correct.

vii. |xy| ≤ n
m
|0 |≤ n m≤n
viii.
y ≠ε (or) | y | ≥ 1
j j
0 ≠ ε (or) | 0 | ≥ 1  j ≥ 1
iii. Since the both the conditions are true, for all k ≥ 0, the string xy kz is also in ‘L’.

xykz = xyy k-1 z = 0m (0 j) k-1 0 i-m 1 i 0 i 1 i

Prepared By: R.GAJENDIRAN ,ASP/IT 76


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

= 0 m +j(k-1)+i-m 1 i 0 i 1 i = 0 i+j(k-1) 1 i 0 i 1 i
xykz = 0 i+j(k-1) 1 i 0 i 1 i
Put k=0, xy0z = 0 i+j(k-1) 1i 0 i 1 i = 0 i+j(0-1) 1 i 0 i 1 i = 0 i-j 1 i 0 i 1 i ≠ 0 i 1 i 0 i 1 i
Put k=1 , xy1z = 0 i+j(k-1) 1 i 0 i 1 i = 0 i+j(1-1) 1 i 0 i 1 i = 0 i 1 i 0 i 1 i = 0 i 1 i 0 i 1 i
Put k=2, xy2z = 0 i+j(k-1) 1 i 0 i 1 i = 0 i+j(2-1) 1 i 0 i 1 i = 0 i+j 1 i 0 i 1 i ≠ 0 i 1 i 0 i 1 i
Since for k=0,2 we have the string that does not belong to the language L, so the language
L={uu / u € {0,1}} is not regular.

33. Identify a language L, such that L* = L+. Nov/Dec2021


Let L ⊆ Σ* be a language.Then L^ = L ∪ ^L2 ∪ L^3 ∪....and L^* = L^ +U { 𝜀 }.For more
information,especially the section on the kleene plus.
Thus the statement L^+ = L^* is effectively equivalent to 𝜀 ∈ L^ +. Note that this is not the case
when L itself is empty. In that case, L^ + is also empty, but L^ * is the language containing only the
empty word 𝜀.
Now, by definition L^+ is the union of all non-zero finite repetitions of elements of L .Note that
W^= 𝜀 implies W= 𝜀 for any non-zero natural n. Hence 𝜀 ∈ L^ + implies 𝜀 ∈ L. The converse is,
of course,also true.Therefore, L^ += L^ *iff 𝜀 ∈ L.

34.Find a minimum State Deterministic Finite Automata recognizing the language


corresponding to the regular expression (0*10 + 1 * 0) (01 )*. Nov/Dec 2021
Solution
The NFA for the RE (0*10 + 1 * 0) (01 )*is shown below.

ε 0 ε 1 0
a b b b a b
ε ε
ε
ε 0 1
b b b b b
b
ε

ε 1 0
a b b b b ε
ε

Prepared By: R.GAJENDIRAN ,ASP/IT 77


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

ANNA UNIVERSITY QUESTION


MAY/JUNE 2007
PART A
1. Verify whether L = { a 2n / n= 1 } is regular.
2. Mention the closure properties of regular languages.
PART B
1. Verify whether the finite automata M1 and M2 given below are equivalent
over { a, b}. b

a a
q6 q5
b
Start
q1
q2
a b b
a

b a
a b Start
b q7 q4
q2

2. Construct transition diagram of a finite automata corresponding to the


regular expression ( ab + c * ) * b.
3. Construct a minimum state automata equivalent to a given automata M
whose transition table is given below.
a b
q0 q0 q3
q1 q2 q3
q2 q3 q4
q3 q0 q5
q4 q0 q6
q5 q1 q4
*q6 q1 q3

Prepared By: R.GAJENDIRAN ,ASP/IT 78


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

4. Find the regular expression corresponding


1 to the finite automata given below.
0

0, 1

Start 0
1
q1 q2 q3

NOV/DEC 2007
PART A
1. What is meant by equivalent states in DFA.
2. State pumping lemma and its advantage.
PART B
1. Find the regular expression for the set of all strings denoted by R 2 23 from the
0
DFA given below.
1 1
1 2 3

2. Find whether the language { ww/w is in (1+0) * } and { 1 K/ K=n2, n ≥ 1 } are


regular or not.
3. Show that the regular languages are closed under intersection and reversal.
NOV/DEC 2008
PART A
1. Show that ε * is ε by constructing its NFA using Thompson’s construction.
2. State pumping lemma and its advantage.
PART B
1. Find the regular expression for the set of all strings denoted by R 3 13 from the
1
DFA given below.

0 1
q1 q2 q3

Prepared By: R.GAJENDIRAN ,ASP/IT 79


0 0
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

2. Find whether the language { ww/w is in (1+0) * } and { 1 K/ K=n2, n ≥ 1 } are


regular or not.
3. Show that the regular languages are closed under intersection and reversal.
NOV/DEC 2012
PART A
1. Give regular expressions for the following
L1= set of all strings of 0 and 1 ending in 00
L2 = set of all strings of 0 and 1 beginning with 0 and ending with 1.
2. Differentiate regular expression and regular language.
PART B
1. Using pumping lemma for the regular sets, prove that the language
L = { a n b n \ m > n } is not regular.
2. Prove any two closure properties of regular languages.
3. Construct a minimized DFA that can be derived from the following regular
expression 0* ( 01 ) ( 0 / 111) *.
NOV/DEC 2011
PART A
1. Is the set of strings over the alphabet{0} of the form 0 n where n is not a
prime is regular? Prove or disprove.
PART B
1. Construct a minimized DFA from the regular expression ( x+y) x ( x+y ) *.
Trace for a string w = xxyx.
2. State and explain the conversion of DFA into regular expression using
Arden’s theorem. Illustrate with an example.
3. What are the closure property of regular sets?
4. Define regular expression. Show that
( 1+00 * 1) + ( 1+00 * 1) (0+10*1)* (0+10*1) = 0 * 1( 0+10 * 1)*

Prepared By: R.GAJENDIRAN ,ASP/IT 80


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Nov/Dec 2015
Part-A
1. Write Regular Expression for the set of strings over {0,1} that have atleast one.
Part-B
11 (i) Construct Finite Automata equivalent to the regular expression (ab+a)*.(6)
(ii) State the pumping lemma for Regular languages. Show that the set L={0i2 | i≥1} not
regular.(6)
May/June 2016
Part A
1. State the pumping lemma for regular languages.
Part B
(b) (i) What is a Regular Expression? Write a regular expression for set of strings that consists
of alternating 0‟s and 1‟s. (8)
(ii) Write and explain the algorithm for minimization of a DFA. Using the above algorithm
minimize the following DFA. (8)
1

Start 0 1 0
A B C D

1
0

0 1

E F 1 G 0 H

Prepared By: R.GAJENDIRAN ,ASP/IT 81


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Nov/Dec 2016
PART A
1. What are the closure properties of regular language?
2. Discuss the basic approach to convert from NFA to regular expression. Illustrate with an
example.
April/May 2017
PART A
1. Generate NFA- ε to represent a*b/c.
2. Show that the language L= { 0n 1 2n / n ≥ 1} is regular or not using pumping lemma.
3. Give language of regular expression a?(b/c)*

Nov/Dec 2017
PART A
1. State the definition of pumping lemma for regular set.

PART B
1. Show that the regular language are closed under:
i) Union
ii) Intersection
iii) Kleen closure
iv) Complement
v) Difference.
April/May 2018
PART A
1. Write the regular expression for the set of all strings of 0‟s and 1‟s not containing 101 as
substring.

Nov/Dec 2020
PART A
1. Write the regular expression for all strings that contain no more than one occurrence
of aa.
2. Write the regular expression for even number of a‟s and even number of b‟s of a
string ={a,b}*.
PART B
3. Prove that the following languages are not regular using pumping lemma.
(i) All unary strings of length prime
(ii) L={uu/u€{0,1}*}
4. State and prove any two closure properties of regular Languages.

Prepared By: R.GAJENDIRAN ,ASP/IT 82


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT II THEORY OF COMPUTATION

Nov/Dec 2021

PART A
1. Write regular expression to recognize the set of strings over {a,b} having odd number of a‟s and
b‟s and that starts with „a‟. Q.No. 48

2. When two states are said to be distinguished? Give example. Q.No. 49


PART B
1.(i)Prove that regular expressions are closed under union, intersection and Kleene closure. Q.No.
31
(ii) Identify a language L, such that L* = L+. Q.No. 35
2. Find a minimum State Deterministic Finite Automata recognizing the language corresponding to
the regular expression (0*10 + 1 * 0) (01 )*. Q.No. 36

Prepared By: R.GAJENDIRAN ,ASP/IT 83


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

UNIT III - CONTEXT FREE GRAMMAR AND PUSH DOWN AUTOMATA


Types of Grammar - Chomsky„s hierarchy of languages -Context-Free Grammar (CFG) and Languages –
Derivations and Parse trees – Ambiguity in grammars and languages – Push Down Automata (PDA):
Definition – Moves - Instantaneous descriptions -Languages of pushdown automata – Equivalence of
pushdown automata and CFG-CFG to PDA-PDA to CFG – Deterministic Pushdown Automata.
PART-A

1. Define a Context Free Grammar. [**May/June 2010**](Nov/Dec 2016)


A CFG is a way of describing languages by recursive rules called productions. A CFG
consists of a set of variables, a set of terminal symbols, and a start variable, as well as the
productions. Each production consists of a head variable and a body consisting of a string of zero or
more variables and /or terminals
A CFG is denoted as G = (V, T, P, S)
Where,
V finite set of variables
Tfinite set of terminals
P finite set of productions
SStart symbol

2. What are the applications of Context free languages? [**Dec 2009**]


Context free languages are used in:
 Defining programming languages.
 Formalizing the notion of parsing.
 Translation of programming languages.
 String processing applications.

3. What are the uses of Context free grammars?


Construction of compilers.
 Simplified the definition of programming languages.
 Describes the arithmetic expressions with arbitrary nesting of balanced parenthesis
 Describes block structure in programming languages.
 Model neural nets

4. What is the language generated by CFG or G?


The language generated by Grammar G is (L(G) ) = {w | w in T* and S *=>w }
(1) The string contains only terminals.
(2) The string can be derived from start symbol S.

1
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

5. What is: (a) CFL (b) Sentential Form?


(a) The language of the CFG is the set of terminal strings we can so derive; it is called a context-
free language. The language generated by Grammar G is:
(L(G)) = {w | w in T* and S => w }
(b) Any step in a derivation is a string of terminal and / or variables. We call such a string a
sentential form. If the derivation is leftmost, then the string is a left sentential form.

6. What is the language generated by the grammar G=(V, T, P, S)Where P={ SaSb,Sab} ?
Solution: S  aSb  aaSbb ………………  an bn
Thus the language L(G)={anbn | n≥1}.
The language has strings with equal number of a‟s and b‟s.

7. What is: (a) Derivation (b) Sub tree?


(a) Let G = (V, T, P, S) be the context free grammar. Beginning with the start symbol, we
derive terminal strings by repeatedly replacing a variable by the body of some production
with that variable in the head.

If Aβ is a production of P and a and b are any strings in (VUT)* then α A γ  α β γ

(b) A subtree of a derivation tree is a particular vertex of the tree together with all its
descendants, the edges connecting them and their labels. The label of the root may not be the
start symbol of the grammar.

8. If S  aSb | aAb, A  bAa | ba .Find out the CFL.


S aAb  abab
S aSb  aaAbb  aababb (sub SaAb)
S aSb  aaSbb  aaaAbbb  aaababbb
Thus L = {anbmambn , where n, m>=1}

9. What is meant by left and right sentential form?


Left Sentential Form: If the string a can be generated from the starting symbol by using left
most derivation, such that S==> α is left sentential form.
Right Sentential Form: If the string a can be generated from the starting symbol by using
rightmost derivation, such that S==> α is right sentential

10. What is an ambiguous grammar? [**Dec 2009**][Nov/Dec-2024]


A grammar is said to be ambiguous if it has more than one derivation trees for a sentence or in
other words if it has more than one leftmost derivation or more than one rightmost derivation.

2
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

11. Consider the grammar P= {S aS | aSbS | є} is ambiguous by constructing: (a) Two parse
trees (b) two leftmost derivation (c) rightmost derivation. {****Nov/Dec 2007*****}
Let w = aab
(b) (i) S  aS (ii) S  aSbS
aaSbS  aaSbS
aabS  aabS
aab  aab
(c) (i) S  aS (ii) S  aSbS
aaSbS  aSb
aaSb  aaSbS
aab aaSb
 aab

12. What are the properties of the CFL generated by a CFG?


Each variable and each terminal of G appears in the derivation of some word in L
There are no productions of the form AB. where, A and B are variables.

13. Find the grammar for the language L = {a2nbc, where n>1}.
Let G = ({S, A, B}, {a, b, c} ,P , {S})
Where Production is:
SAbc
AaaA | є
Find the language generated by:
S0S1 | 0A | 0 |1B | 1
A0A | 0
B1B | 1

14. Construct the grammar for the language L= { anban | n>=1}.


The grammar has the production P as:
SaAa
AaAa | b
The grammar is: G ={ {S, A} ,{a, b} ,P, S)}

15. Construct a grammar for the language L which has all the strings which are all
palindrome over S = {a, b}.
G = ({S}, {a, b}, P, S )
Production { SaSa , SbSb, Sa, Sb, Sє } which is in palindrome

3
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

16. Construct the context-free grammar representing the set of palindromes over (0+1)*.
Solution: (Nov/Dec 2015)
G = ({S}, {0, 1}, P, S )
Production { S0S0 , S1S1, S0, S1, Sє } which is in palindrome.

(i) S 0S0 (ii) S 1S1


 01S10  10S01
 01010  10001 L= { w; w is a palindrome}

17. Differentiate sentences Vs sentential forms.


A sentence is a string of terminal symbols. A sentential form is a string containing a mix of
variables and terminal symbols or all variables. This is an intermediate form in doing a
derivation.

18. What is a formal language?


Language is a set of valid strings from some alphabet. The set may be empty, finite or infinite.
L(M) is the language defined by machine M and L( G) is the language defined by Context free
grammar.
The two notations for specifying formal languages are:
1. Grammar or regular expression (Generative approach)
2. Automaton (Recognition approach)

19. Let the productions of a grammar be S 0B, A0/0S/1AA, B1/1S/0BB. For the string
0110 find a right most derivation. [**MAY/JUNE 2007**]
String=0110
S0B
01S
011A
0110
S0110
20. What is Backus-Naur Form (BNF)?
Computer scientists describe the programming languages by a notation called Backus-Naur
Form. This is a context free grammar notation with minor changes in format and some
shorthand.

21. Let G= ( {S, C} ,{a, b}, P, S) where P consists of SaCa , CaCa |b. Find L(G).
SaCa  aba
SaCa aaCaa  aabaa
SaCa  aaCaa  aaaCaaa  aaabaaa
Thus L(G) = { anban , whre n>=1 }

4
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

22. Find L(G) where G= ( {S} ,{0, 1}, {S0S1 ,Sє}, S ).[**Dec 2010**]
Sє , є is in L(G)
S0S1  0є1 01
S0S1 00S11 0011
Thus L(G)= { 0n1n | n>=0}
23. What is meant by inherent ambiguous grammar?
A context free language L is said to be inherently ambiguous if all its grammars are ambiguous
grammar. If even one grammar for L is unambiguous then L is an unambiguous language.
Inherent ambiguous grammars are one for which unambiguous grammars do not exist.

24. Find the language generated by a CFG. G = ( {S}, {0 , 1}, { S0/1/є, S0S0/1S1/S} )
(i) S 0S0 (ii) S 1S1
 01S10  10S01
 01010  10001 L= { w; w is a palindrome}

25. Consider G whose productions are SaAS/a, ASbA/SS/ba. Show that S aabbaa.
S Aas SaAS
 aSbAS ASbA
 aabAS Sa
 aabbaS Aba
 aabbaa Sa

26. What is a parser?


A parser for grammar G is a program that takes as input a string w and produces as output
either a parse tree for w, if w is a sentence of G or an error message indicating that w is not a
sentence of G.

27. Define left most derivation and right most derivation.


Left most derivation: In this method, we replace the left most non-terminal by one of its
production in the grammar. Such a derivation is known as left most derivation and it‟s
represented by using the relation *=> and *=> for one or more steps respectively.
lm lm
Right most derivation: In this method, we replace the right most non-terminal by one of its
production in the grammar. Such a derivation is known as left most derivation and it‟s
represented by using the relation *=> and *=> for one or more steps respectively.
rm rm
28. Construct a context free grammar for generating the language L = {a nbn | n≥1}
(Nov/Dec-2004, 2010, 2013, May-05, 06)
G = {V, T, P, S}
P = { SaSb, Sab}

5
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

29. Construct a CFG over {a,b} generating a language consisting of equal no. of a‟s and b‟s.
(*****May 2011****)
Let G={V, T, P, S}
V = { S, A, B}
T = { a, b}, S is a Start symbol.
P = { SaB | bA, Aa | aS | bAA, B b | bS | aBB }

30. When a grammar is said to be ambiguous? (May 2013) Define Ambiguity. April/May 2018
 A string w is derived ambiguously in context-free grammar G if it has two or more different
leftmost derivations. Grammar G is ambiguous if it generates some string ambiguously.
 Sometimes an ambiguous grammar can be transformed into an unambiguous grammar for the
same language.
 Some context-free grammars can be generated only by ambiguous grammars. These are
known as inherently ambiguous languages.
 L = { ai b j ck | i = j or j = k }

31. What is an unambiguous grammar?


An unambiguous grammar is a kind of grammar which generates unique derivation tree for the
given string.

32. Define Parse Tree (Or) Derivation Tree.


The strings that are derived from the CFG can be represented in a tree format known as Parse
tree or derivation tree. This parse tree clearly shows how the symbols of a terminal strings are
grouped into substrings, each of which belongs to the language of one of the variables of the
grammar.

33. State that the following facts are true or false.


(a) CFL are not closed under intersection and complementation –True.
(b)A regular grammar generates an empty string - True.
(c)A regular language is also context free but not reverse–True.
(d)A regular language can be generated by two or more different grammar–True.
(e)Finite State machine (FSM) can recognize only regular grammar -True.

34. Define Parse Tree (Or) Derivation Tree.


The strings that are derived from the CFG can be represented in a tree format known as Parse
tree or derivation tree. This parse tree clearly shows how the symbols of a terminal strings are
grouped into substrings, each of which belongs to the language of one of the variables of the
grammar.

6
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

35. Let G be the grammar SaB|bA, Aa|aS|bAA, Bb|b|S|aBB. For the string aaabbabbba
find a leftmost derivation.(May/June‟07)(Apr/May „08)(Nov/Dec 2015)

Solution S  aB
aaBB (BaBB)
aaaBBB (BaBB)
aaabBB (Bb)
aaabbB (Bb)
aaabbaBB (BaBB)
aaabbabB (Bb)
aaabbabbS (BbS)
aaabbabbbA (SbA)
aaabbabbba (Aa)
36. Construct a CFG for set of strings that contain equal number of a‟s and b‟s over ∑={a,b}.
(May/June 2016)
Solution: L={ab, aabb, abab, ba, bbaa, baba…}
SAB
AaA/bA / Є
BbB/aB/Є

37. Generate CFG for a signed integer constant in language.(April/May 2017)


ED|-D|-D.D|D.D
D0|1|2|…..9

38. Construct a rightmost derivation of (a+b)*c for using grammar, and also state that
whether a given grammar is ambiguaous one or not. (April/May 2017)
EE+E/E*E/(E)/id
RMD:
E E*E
E*c
(E)*c
(E+E)*c
(E+b)*c
(a+b)*c

7
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

39. Construct a context Free Grammar for the language l={a n |n is odd}. (Nov/Dec 2016)
Solution: L={a, aaa, aaaaa, aaaaaa, …}
S aA
AaaA/ €

40. Derive a string „aababa‟ for the following context free grammar (CFG) Nov/Dec 2017
S  aSX / b
XXb/a
Solution: S  aSX (S aSX)
aaSXX (Sb)
aabXX (XXb)
aabXbX (Xa)
aababX (Xa)
 aababa

41. Define Pushdown Automata. (May/June 2016) OR


What are the conventional notations of push Down Automata? (Nov/Dec 2016)

A PDA is a nondeterministic finite automaton coupled with a stack that can be used to store a
string of arbitrary length. The stack can be read and modified only at its top.

A pushdown Automata M is a system (Q, Σ, Ґ, δ, q0, Z0, F)


Where,
Q is a finite set of states.
Σ is an alphabet called the input alphabet.
Ґ is an alphabet called stack alphabet.
q0 in Q is called initial state.
Z0 in Ґ is start symbol in stack.
F is the set of final states.
δ is a mapping from Q X ( Σ U {Є} ) X Ґ to finite subsets of Q X Ґ*.

42. Define Transition Diagram and Transition Function of PDA.


The transition diagram for PDA‟s in which

 The nodes correspond to the states of the PDA


 An arrow labeled Start indicates the start states, and doubly circled states are accepting as for
finite automata.

8
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Transition Function: δ (q, a, X) = (p, α)


Start a, X | α
q p
An arc labeled a, X | α from state q to state p means that δ(q, a, X) contains the pair (p, α)
perhaps among other pairs. That is, the arc label tells what input is used, and also gives the old and
new tops of the stack.

43. Define Moves of Pushdown Automata.


Moves of a Pushdown Automata
A PDA chooses its next move based on its current state, the next input symbol, and the
symbol at the top of its stack. It may also choose to make a move independent of the input symbol
and without consuming that symbol from the input. Being nondeterministic, the PDA may have
some finite number of choices of move; each is a new state and a string of stack symbols with which
to replace the symbol currently on top of the stack.

44. Specify the two types of moves in PDA.


The move dependent on the input symbol (a) scanned is:
δ(q,a,Z)={ (p1, γ1), (p2,γ2),…..(pm,γ m ) }
Where q and p are states, a is in Σ, Z is a stack symbol and γi is in Ґ*. PDA is in state q, with
input symbol a and Z the top symbol on state enter state pi and replace symbol Z by string γi
The move independent on input symbol is (Є-move):
δ(q,Є,Z) = { ( p1,γ1 ), ( p2,γ2 ),…………( pm,γm ) }.
Is that PDA is in state q, independent of input symbol being scanned and with Z the top
symbol on the stack enter a state pi and replace Z by γi.

45. What are the different types of language acceptances by a PDA and define them?
(Nov/Dec 2015)
For a PDA M=(Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) we define :
1. Acceptance by Final State:
{ w | (q0 , w , Z0 ) ├ ( p, Є , γ ) for some p in F and any stack string γ }.
2. Acceptance by Empty Stack:
N(P) = { w | (q0, w, Z0) ├ ( p, Є, Є ) for any state q}.

46. Is it true that the language accepted by a PDA by empty stack and final states are different
languages.
No, because the languages accepted by PDA„s by final state are exactly the languages
accepted by PDA‟s by empty stack.

9
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

47. Define Deterministic PDA. (or) When is PDA said to be deterministic? April/May 2018
When is push down automata(PDA) said to be deterministic?(Nov/Dec 2016)(Nov/Dec 2020)

A PDA is deterministic if it never has a choice of move for a given state, input symbol
(including Є), and stack symbol. Also, it never has a choice between making a move using a true
input and a move using Є input
A PDA M =( Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) is deterministic if:
1. For each q in Q and Z in Ґ, whenever δ(q, Є, Z) is nonempty then δ(q, a, Z) is
empty for all a in Σ.
2. For no q in Q, Z in Ґ, and a in Σ U {Є} does δ(q, a, Z) contains more than one
element. (E.g.): The PDA accepting {wcw R | w in ( 0+1 ) * }.

48. Define Instantaneous description (ID) in PDA.


o ID represents the configuration of a PDA by a triple (q, w, γ),
o Where,
 q is the state,
 w is the remaining input, and
 γ is the stack contents.
o We show the top of the stack at the left end of γ and the bottom at the right end. Such
a triple is called an Instantaneous Description (ID)

 ID consisting of the state, remaining input, and stack contents to describe the “current
condition” of a PDA. A transition function├ between ID‟s represents single moves of
a PDA.

 If M = (Q, Σ, Ґ, δ, q0, Z0, F) be a PDA. If δ (q, a, X) contains (p, α). Then for all
string w in Σ* and β in Г*.
(q, aw, X β) ├ (p, w, αβ)
 This move reflects the idea that, by consuming a from the input and replacing X on
top of the stack by α, we can go from state q to state p.

49. What is the significance of PDA?


Finite Automata is used to model regular expression and cannot be used to represent non
regular languages. Thus to model a context free language, a Pushdown Automata is used.

10
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

50. When is a string accepted by a PDA?


The input string is accepted by the PDA if:
The final state is reached.
The stack is empty.
51. Give examples of languages handled by PDA. What are the ways of language acceptance in
PDA? April/May 2018
(1) L = {anbn | n>=0}, here n is unbounded, hence counting cannot be done by finite memory.
So we require a PDA, a machine that can count without limit.
(2) L = {wwR | wЄ{a,b}*}, to handle this language we need unlimited counting capability .
52. Is NPDA (Nondeterministic PDA) and DPDA (Deterministic PDA) equivalent?
The languages accepted by NPDA and DPDA are not equivalent.
For example: wwR is accepted by NPDA and not by any DPDA.
53. State the equivalence of acceptance by final state and empty stack.
 If L = L(M2) for some PDA M2 , then L = N(M1) for some PDA M1.
 If L = N(M1) for some PDA M1 , then L = L(M2 ) for some PDA M2
 Where L(M) = language accepted by PDA by reaching a final state.
N(M) = language accepted by PDA by empty stack.

54. Construct a PDA that accepts the language generated by the grammar. SaSbb / aab
Solution: The PDA A = ({q}, {a,b}, {S,a,b}, δ, q,S}
Where:
i) (q, z0, S) = {(q, aSbb), (q, abb)}
ii) (q, a, a ) = {(q, ε)}
iii) (q, b, b ) = {(q, ε)}

55. Construct a PDA that accepts the language generated by the grammar
S aABB, A aB / a, B bA / b

Solution: The PDA A = ({q}, {a, b}, {S, A, B, Z, a, b}, δ, q, S}


Where:
i) (q, z, S) = {(q, aABB)}
ii) (q, z, A ) = {(q, aB, (q,a)}
iii) (q, z, B ) = {(q, bA, (q,b)}
iv) (q, a, a ) = {(q, ε)}
v) (q, b, b ) = {(q, ε)}
56. How do you convert CFG to a PDA?

Let G = (V, T, P, S) be a CFG. Then construct a PDA P that accepts L(G) by empty stack as
follows:
11
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

P = ({q}, T, V U T, δ, q, S) Where δ given by


1) For each variable A,
(q, ε, A) = {(q, β) | Aβ is a production of P}
2) For each terminal a,
(q, a, a) = {(q, ε)}

57. Is it true that NDPA is more powerful than that of DPDA? Justify your answer.
No, NPDA is not powerful than DPDA. Because NPDA may produce ambiguous grammar
by reaching its final state or by emptying its stack. But DPDA produces only unambiguous
grammar.
58. What is the additional feature PDA has when compared with NFA? Is PDA superior over
NFA in the sense L acceptance? Justify your answer.
PDA is superior NFA by having the following additional features.
 Stack which is used to store the necessary tape symbols and use the state to remember the
conditions.
 Two ways of L acceptances, one by reaching its final state and another by emptying its stack.

59. What are the components of PDA?


The PDA usually consists of four components:
 A control unit.
 A Read Unit.
 An input tape.
 A Memory unit.

60. What is the informal definition of PDA?


A PDA is a computational machine to recognize a Context free language. Computational
power of PDA is between Finite automaton and Turing machines. The PDA has a finite
control, and the memory is organized as a stack.

61. What is meant by equivalence of PDA and CFG?


The context free grammar is recognized by the pushdown automata. The languages defined by
PDA‟s are the context free language(Refer Fig No:3.1). There are three classes of languages
that are equivalent to each other and they are
1. The context free languages (i.e) the languages defined by CFG
2. The languages that are accepted by final state by some PDA
3. The language that are accepted by empty stack by some PDA.

Figure 3.1- Organization of constructions showing equivalence of three ways of defining the CFL‟s
12
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

62. State the pumping lemma for CFLs.


Let L be any CFL. Then there is a constant n, depending only on L, such that if z is any string in L
and
|z| > = n, then z = uvwxy such that:
(i) |vx| ≥ 1
(ii) |vwx| ≤ n and
(iii) For all i ≥ 0 uvi wxi y is in L.
63. Compare NFA and PDA.
NFA PDA
The language accepted by NFA is the The language accepted by PDA is Context
regular language. free language.
NFA has no memory. PDA is essentially an NFA with a stack
(memory).
It can store only limited amount of It stores unbounded limit of information.
information.
A language/string is accepted only by It accepts a language either by empty
reaching the final state. Stack or by reaching a final state.

64. What is the main application of pumping lemma in CFLs?


The pumping lemma can be used to prove a variety of languages are not context free.
The CFL pumping lemma as an “adversary game, as follows.”
 We pick a language L that we want to show is not a CFL
 Our “adversary” gets to pick n, which we do not know, and we therefore must plan for any
possible n.
 We get to pick z, and may use n as a parameter when we do so.
 Our adversary gets to break z into uvwxy, subject only to the constraints that |uwx| ≤ n and
vx ≠ Є
 We “win” the game, if we can, by picking i and showing that uvi wxi y is not in L

65. Convert the following CFG to a PDA (Nov/Dec 2015)


SaAA, AaS | bS | a
Solution:

For Non-Terminal „S‟ and „A‟:

1. δ(q,Є,S)={(q,aAA)}

2. δ(q,Є,A)={(q,aS),(q,bS),(q,a)}

For Terminal ‟a‟ and „b‟:


13
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

1. δ(q,a,a)={(q,Є)}

2. δ(q,b,b)={(q,Є)}

66. Does a pushdown Automata has memory? Justify. (May/June 2016)

A PDA has a stack on which it can store a string of “stack symbols”. The pushdown automaton can
“remember” an infinite amount of information. The pushdown automaton can only access the
information on its stack in a last-in-first-out way.

67. Differentiate PDA acceptance by empty stack method with acceptance by the final state
method. (April/May 2017)
For a PDA M=(Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) we define :
(i) Language accepted by final state L(M) as:
* { w | (q0 , w , Z0 ) |-- ( p, Є , γ ) for some p in F and γ in Ґ * }.
(ii) Language accepted by empty / null stack N(M) is:
{ w | (q0,w ,Z0) |----( p, Є, Є ) for some p in Q}.

68. Write a context Free Grammar for the language consisting of equal number of a‟s and b‟s.
(Nov/Dec 2020)
L={ab,aabb,aaaabbb,…}
CFG=({s},{a,b},p,{s}) where P consists of
SaSb/ab
69. Write CFG to accept the language defined by, Nov/Dec 2021

CFG=({s},{a,b,c},p,{s}) where P consists of


SABC
AaaA/ Є
BbB/ Є
CcC/ Є

70. List out the steps for performing LL parsing. Nov/Dec 2021
Algorithm to construct LL(1) Parsing Table:
Step 1: First check all the essential conditions mentioned above and go to step 2.
Step 2: Calculate First() and Follow() for all non-terminals.
1. First(): If there is a variable, and from that variable, if we try to drive all the strings then the
beginning Terminal Symbol is called the First.
2. Follow(): What is the Terminal Symbol which follows a variable in the process of derivation.
Step 3: For each production A –> α. (A tends to alpha)
1. Find First(α) and for each terminal in First(α), make entry A –> α in the table.
2. If First(α) contains ε (epsilon) as terminal than, find the Follow(A) and for each terminal in
Follow(A), make entry A –> α in the table.
3. If the First(α) contains ε and Follow(A) contains $ as terminal, then make entry A –> α in the
table for the $.
14
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

71. Draw pushdown automata to accept all palindromes of odd length. Nov/Dec 2021
1, 0/10
0, 1/01
0, 0/00
1, 1/11
1, z0/1z0 0, 0/ε
0, z0/0z0 1, 1/ε
c, 0/0
c, 1/1
c, z0/z0
ε, z0/ε
q0 q1 q2

72. Formally define the pushdown automata based on the types of acceptance. Nov/Dec 2021

For a PDA M=(Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) we define :


3. Acceptance by Final State:
{ w | (q0 , w , Z0 ) ├ ( p, Є , γ ) for some p in F and any stack string γ }.
4. Acceptance by Empty Stack:
N(P) = { w | (q0, w, Z0) ├ ( p, Є, Є ) for any state q}.
73. What are the different types of grammars/languages?
1. Unrestricted or Phase structure grammar.(Type 0 grammar).(for TMs)

2. Context sensitive grammar or context dependent grammar (Type1) (for Linear Bounded
Automata )

3. Context free grammar (Type 2) (for PDA)


4. Regular grammar (Type 3) (for Finite Automata).

This hierarchy is called as Chomsky Hierarchy.


74. Write short notes on chomskian hierarchy of languages. (April/May 2017)
Define Chomsky Hierarchy of Languages. Apr/May-2018
The chomsky‟s hierarchy represents the class of languages that are accepted by different machine. The
category in Chomsky is as given below (Refer Table 3.1)

Language class Language Grammar Machine Example


Type3 Regular Regular FSM i.e. NFA a*b*
grammar or DFA
Type2 Context free Context free PDA anbn
grammar

15
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Type1 Decidable Context Linear bounded anbncn


languages sensitive automata
grammar
Type0 Computable Unrestricted Turing n!
languages grammar Machine
Table 3.1 – Chomsky hierarchy of language
This is a hierarchy (Refer figure 3.2) therefore every language of type 3 is also of type 2, 1 and 0. Similarly
every language of type 2 is also of type 1 and 0 etc.

Computable languages

Context sensitive languages

Context free languages

Regular language

Figure 3.2 – Chomsky hierarchy of languages

75. What are the two normal forms of CFG? Write their productions format.
The two Normal forms are
i. Chomsky Normal Form (CNF)
ii. Greibach Normal Form (GNF)

CNF:
A context-free grammar is in Chomsky normal form (CNF) if every rule is either of the form.
ABC or A  a
GNF:
Every CFL L without ε cab be generated by a grammar for which every production is of the form A aα,
where A Є V(Variable), a Є T(Terminal), is a string of variables.

16
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

PART - B

EXAMPLE FOR LEFTMOST AND RIGHTMOST DERIVATIONS

1) Derive the strings a*(a+b00) using leftmost and rightmost derivation for the following
production.
1. EI

2. EE+E

3. EE*E

4. E(E)

5. Ia

6. Ib

7. IIa

8. IIb

9. II0

10.II1

Solution
Leftmost Derivation

EE*E

I*E (EI)

a*E (Ia)

a*(E) (E (E))

a*(E+E) (EE+E)

a*(I+E) (EI)

a*(a+E) (Ia)

a*(a+I) (EI)

a*(a+I0) (II0)
17
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

a*(a+I00) (II00)

a*(a+b00) (Ib)

Rightmost Derivation

EE*E

E*(E) (E(E))

E*(E+E) (EE+E)

E*(E+I) (EI)

E*(E+I0) (II0)

E*(E+I00) (II0)

E*(E+b00) (Ib)

E*(I+b00) (EI)

E*(a+b00) (Ia)

I*(a+b00) (EI)

a*(a+b00) (Ia)

2) Show that the grammar SaSbS | bSaS | e is ambiguous and what is the language
generated by this grammar? (Nov/Dec 2006)

Solution - Input string w = aabbab

Leftmost Derivation

S  aaSbSbS

 aaєbSbS

 aabSbS

 aabєbS

 aabbS

18
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

 aabbaSbS

 aabbaєbS

 aabbabS

 aabbabє

 aabbab
Rightmost Derivation

S aSbS

aSbaSbS

aSbaSbЄ

aSbaSb

aSbaЄb

aSbab

aaSbSbab

aaSbЄbab

aaSbbab

aaєbbab

aabbab

3) The following grammar generates the language of Regular expression 0*1(0+1)*.

SA1B

A0A | Є

B0B | 1B | Є

Give leftmost and rightmost derivations of the following strings

a) 00101 b) 1001 c) 00011 (May/June 2006)

Solution - (a) Input String w = 00101

19
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Leftmost Derivation

S A1B

0A1B

00A1B

00Є1B

001B

0010B

00101B

00101Є

00101

Rightmost Derivation

S A1B

A10B

A101B

A101Є

A101

0A101

00A101

00Є101

00101

(b) Input String w = 1001

Leftmost Derivation

S A1B

20
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Є1B

1B

10B

100B

1001B

1001Є

1001
Rightmost Derivation

S A1B

A10B

A100B

A1001B

A1001Є

A1001

Є1001

1001

(c) Input String w = 00011


Leftmost Derivation

S A1B

0A1B

00A1B

000A11B

000Є11B

00011B

00011Є
21
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

00011
Rightmost Derivation

S A1B

A11B

0A11Є

00A11Є

000A11

000 Є 11

00011

4. Given the grammar G = (V,Σ,R,E), where


V={E,D,1,2,3,4,5,6,7,8,9,0,+,-,*,/,(,) }

Σ={1,2,3,4,5,6,7,8,9,0,+,-,*,/,(,) }, and R contains the following rules:

ED | (E) | E+E | E-E | E*E \ E | E

D0 | 1 | 2 |…..9 E

Find a parse tree for the string 1+2*3. (6) (Nov/Dec 2015)
Solution E E
+

Left Most Derivation


D
EE+E

D+E
1
1+E E E
*
1+E*E

1+D*E D

1+2*E
2 D
1+2*3

3 22
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Right Most Derivation


E E
EE+E +

E+E*E

E+E*D
E * E
E+E*3

E+D*3
D
E+2*3
D
D+2*3 D

1+2*3 3

1 2

5) Let G be the grammar S0B|1A, A0|0S|1AA, B1|1S|0BB.

For the string 00110101 find (Apr/May 2004) (May/Jun2007)

(a)Leftmost derivation

(b)Rightmost derivation

(c) Derivation tree

(d) For the string 0110 find a rightmost derivation


Solution
(a) Leftmost Derivation
S 0B

00BB (B0BB)

001B (B1)

0011S (B1S)
23
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

00110B (S0B)

001101S (B1S)

0011010B (S0B)

00110101 (B1)

(b)Rightmost Derivation

S 0B

00BB (B0BB)

00B1S (B1S)

00B10B (S0B)

00B101S (B1S)

00B1010B (S0B)

00B10101 (B1)

00110101 (B1)

(d)

S 0B

01S (B1S)

011A (S1A)

0110 (A0)

6) Find the language L(G) generated by the grammar G with variables S, A, B terminals a, b
and productions SaB, Bb, BbA, AaB.

Solution

(i)
S aB

Ab (Bb)
24
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

(ii)
S aB

abA (BbA)

abaB (AaB)

abab (Bb)

(iii)

S aB

abA (BbA)

abaB (AaB)

ababA (BbA)

ababaB (AaB)

ababab (Bb)

L(G) = { (ab)n = ab, abab, ababab,………. n>=1}

7) If G is a grammar SSbS | a prove that G is ambiguous (Apr/May 2004)

Solution - Let w = abababa

Leftmost Derivations

S SbS

abS (Sa)

abSbS (SSbS)

ababS (Sa)

ababSbS (SSbS)

abababS (Sa)

abababa (Sa)

25
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

S SbS

SbSbS

abSbS

ababS

ababSbS

abababS

abababa

8) Consider the following grammar, S aS | aSbS | Є Show that this grammar is ambiguous.
For the string “aab” that has two parse trees, two left most derivation and two leftmost
derivation and two right most derviations.
Solution:
Production: SaS| aSbS| Є
First Left Most Derivation
S  aS
 aaSbS
 aaЄbS
 aabS
 aabЄ
 aab
Second Left Most Derivation
S aSbS
aaSbS
aaєbS
aabS
aabє S
S aab
Parse tree for left most derivation
S

a
S
S
b S
S
a
b
a
S
a S
Є
Є
Є
Є 26
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

First Rightmost Derivation

S aS

aaSbS

aaSbЄ

aaSb

aaЄb
aab

Second Rightmost Derivation

S aSbS

aSbЄ

aSb

aaSb

aaЄb

aab

Parse tree for Rightmost Derivation

27
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

9) Show that the grammar S  a | abSb | aAb, AbS | aAAb is ambiguous. (May/June 2007)

Solution: Let w = abab

S abSb

abab (Sa)

S aAb

abSb (AbS)

abab (Sa)

w = abab has two different derivations. Hence the grammar is ambiguous

10) Show that the grammar S a | Sa | bSS | SSb | SbS is ambiguous (8) (Nov/Dec2007)

Solution: Let w=baaa

Leftmost Derivation

S Sa

bSSa (SbSS)

baSa (Sa)

baaa (Sa)

S bSS

bSaS (SSa)

baaS (Sa)

baaa (Sa)

28
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Parse Tree:

11) Find out the context free language (May/June 2009)

SaSb | aAb

AbAa

Aba

Solution:

S aSb S aAb S aSb

aaAbb abab aaSbb

aababb aaaAbbb

aaababbb

S aAb S aAb

abAab abAab

abbaab abbaab

L = {The set of strings over Σ={a,b}starting with a and ending with b and substring ba}

29
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

12) Find a derivation tree of a*b+a*b given that a*b+a*b is in L(G) where G is given by
SS+S/S*S/a/b. (May/June 2007)
Solution
S  S+S
 S*S+S (Ss*S)
 a*S+S (Sa)
 a*b+S (Sab)
 a*b+a*S (Sa)
 a*b+a*b (Sb)

13. What is an ambiguous grammar? Explain with the help of an example.[Nov/Dec2024]


(Nov/Dec 2015) (May/June 2016)

Definition: A grammar is said to be ambiguous if it has more than one derivation trees for a
sentence or in other words if it has more than one leftmost derivation or more than one
rightmost derivation.

Example:
Let w = aab
(b) (i) S  aS (ii) S  aSbS
aaSbS  aaSbS
aabS  aabS
aab  aab
(c) (i) S  aS (ii) S  aSbS
aaSbS  aSb
aaSb  aaSbS
aab aaSb
 aab
30
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

PROBLEMS FOR UNAMBIGUOUS GRAMMAR

14) The following grammar generates the language of Regular expression 0*1(0+1)*.

SA1B

A0A | Є

B0B | 1B | Є
a) Show that this grammar is unambiguous. (May/June 2006)

b) Find a grammar for the same language that is ambiguous , demonstrate its ambiguity.

Solution

(a) Let us take w= 001011

S A1B

0A1B

00A1B

00Є1B

001B

0010B

00101B

001011B

001011Є
001011

31
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

So for the string 001011, there is only one derivation and possible parse tree and there is no another
extra way to derive the same string. So the above grammar is unambiguous, and the given grammar
will generate the string of the form 0*1(0+1)*

(b) Find a grammar for the same language that is ambiguous, and demonstrate its ambiguity.

SA1B / AC

C1B / 1/ Є

A0A / Є

B0B / 1B / Є

Now take the string 001011. Here we show that there exists two left most derivation and it shown
below.

First Leftmost derivation

SA1B
0A1B
00A1B
00Є1B
001B
32
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

0010B
00101B
001011B
001011Є
001011
Second Leftmost derivation
S AC
0AC
00AC
00ЄC
001B
0010B
==> 00101B
001011B
001011Є
001011

15) Consider the grammar SaS | aSbS | Є. Show that the grammar is ambiguous
and create unambiguous grammar.

Solution

Let us take w= aab

First Left Most Derivation

S aS

aaSbS

aaЄbS

aabS

aabЄ

S aab
Second Left Most Derivation

33
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

S aSbS

aaSbS

aaЄbS

aabS

aabЄ

S aab

Parse tree - Refer Q.No : 8


The above ambiguous grammar can become unambiguous grammar as follows,

SaS | aCbS | Є

CaCbC | Є
Now take the string aab and derive it by using unambiguous grammar,

S aS

aaCbS

aaebS

aabS

aabЄ

S aab

The parse tree for the unambiguous grammar as follows,

34
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

There is no other way to derive the same string aab, so the ambiguous grammar is changed to
unambiguous by introducing a new non-terminal C.

16) The following grammar generates prefix expressions with operands x and y and binary
operators +, - and * and the grammar is as follows,

E+EE | * EE | -EE | x | y

(a) Find the left most and right most derivation and derivation tree for the string “+ * - xyxy”

(b) Prove that this grammar is unambiguous

Solution:

(a)Find the leftmost and rightmost derivation and derivation tree for the string“+* - xyxy”

E+EE
E* EE
E-EE
Ex
Ey
Leftmost Derivation w = + * - xyxy
E + EE
+ * EEE
+ * - xEEE
+ * - xyEE
+ * - xyxE
E + * - xyxy

Rightmost Derivation w = + * - xyxy


E + EE
+ * Ey
+ * EEy
+ * Exy
+ * - EExy
+ * - Eyxy
E + * - xyxy

35
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

17) Show the derivation steps and construct derivation tree for the string „ababbb‟ by using
leftmost derivation with the grammar SAB|Є , AaB, BSb (May/June 2016)
S
(b) Input String w = ababbb

Leftmost Derivation
A B
S AB

aBB
B
aSbB a

aЄbB
S b
abSb
S b
Є
abABb

abaBBb

abaSbBb A B

abaЄbBb

abaЄbSbb a B

abaЄbЄbb
S b
ababbb

b
S
Є

Є
18. Construct a CFG for the regular expression (011+1)(01). (May/June 2016)
Solution:
L = {01101, 101}
SA
A0A1 | 1A | Є

36
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

19. Define derivation tree. Explain its uses with an example. (Nov/Dec 2016)
Derivation Tree

Let G = (V, T, P, S) be the context free grammar. Beginning with the start symbol, we
derive terminal strings by repeatedly replacing a variable by the body of some production
with that variable in the head.

If Aβ is a production of P and a and b are any strings in (VUT)* then α A γ  α β γ


Example
Find a derivation tree of a*b+a*b given that a*b+a*b is in L(G) where G is given by
SS+S/S*S/a/b (May/June 2007)
Solution
S  S+S
 S*S+S (Ss*S)
 a*S+S (Sa)
 a*b+S (Sab)
 a*b+a*S (Sa)
 a*b+a*b (Sb)

20. Construct a CFG to generate even add set of palindromes over alphabet {a,b}. Nov/Dec 2017

G = ({S}, {a, b}, P, S )


Production { SaSa , SbSb, Sa, Sb, Sє } which is in palindrome.

37
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

21. Generate CFG for the language L = { 0i1j0k | i>j+k}. Nov/Dec 2017

S 0S0/1P0
S00/10
P10
22. Design PDA to accept the language L={wcwR / w={0,1}*}. April 2018
Solution:
The PDA P is defined as,
P = ({q0, q1, q2}, {0, 1, c}, Γ, δ, q0, z0, {q2})
The transition function is given as,
δ(q0, 0, z0) = (q0,0z0)
δ(q0, 0 ,0) = (q0,00)
δ(q0, 1 ,z0) = (q0,1z0)
δ(q0, 1 ,1) = (q0,11)
δ(q0, 0 ,1) = (q0,01)
δ(q0, 1 ,0) = (q0,10)
δ(q0, c ,z0) = (q1,z0)
δ(q0, c ,0) = (q1,0)
δ(q0, c ,1) = (q1,1)
δ(q1, 0 ,0) = (q1,ε)
δ(q1, 1 ,1) = (q1,ε)
δ(q1, ε ,z0) = (q2,ε) 1, 0/10
0, 1/01
The transition diagram is, 0, 0/00
1, 1/11
1, z0/1z0 0, 0/ε
0, z0/0z0 1, 1/ε
c, 0/0
c, 1/1
c, z0/z0
ε, z0/ε
q0 q1 q2

Let us take the string w= 011c110

(q0, 011c110,z0) ├ ρ (q0, 11c110, 0z0)


├ ρ (q0, 1c110,10z0)
├ ρ (q0, c110, 110z0)
38
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

├ρ (q1, 110, 110z0)


├ρ (q1, 10, 10z0)
├ρ (q1, 0, 0z0)
├ρ (q1, ε, z0)
├ρ (q2, ε, ε) Accepted

23. Design a PDA to accept the language L={ an+1bmcn / m, n ≥ 1}

Solution:

The PDA p is defined as,


P = ({q0,q1,q2,q3,q4}, {a,b,c}, Γ, δ, q0, z0, {q4})

The transition function is defined as,

δ(q0, a, z0) = (q0,z0)


δ(q1, a, z0) = (q1,az0)
δ(q1, a, a) = (qa, aa)
δ(q1, b, a) = (q2,a)
δ(q2, b, a) = (q2,a)
δ(q2, c, a) = (q3,ε)
δ(q3, c, a) = (q3,ε)
δ(q3, ε, z0) = (q4,ε)

The transition diagram is shown below,

a, a/aa a, a/aa a, a/aa


a, z0/az0 a, z0/az0 a, z0/az0

q0 q1 q2 q3 q4

a, z0/z0
b, a/a
c, a/ε ε, z0/ε
w = aabcc

(q0, aabcc,z0) ├ ρ (q1,abcc,z0)


├ ρ (q1,bcc,az0)
├ ρ (q2,cc,az0)
├ ρ (q3,c,z0)

39
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

The string aabcc is not accepted since there is no transition δ(q3, c, z0).

24. Design PDA for the language L = {anb2n | n ≥0 } (Nov/Dec 2008)

Solution

Here the idea to design this PDA is that when we read single „a‟ we insert or push two a‟s on the
stack. Then we read „b‟ means, we can pop „a‟ for each b on the top of the stack and when reading
z0 on the stack. We reach final state.

The transition function is, as follows;

δ(q0, a, z0) = (q0,aaz0)


δ (q0, a ,a) = (q0,aaa)
δ (q0, b ,a) = (q1,Є)
δ (q1, b ,a) = (q1,Є)
δ (q1, Є ,z0) = (q2, Є)
δ (q0, Є ,z0) = (q2, Є)

Here after entering the final state, we can have any symbols on the stack since we are
designing

PDA by reaching final state. The transition diagram for L= { an b2n | n ≥ 0 } is shown below,
a, a/ aaa b, a / Є
a, z0 / aaz0
Start

b, a / Є Є, a / Є
q0 q1 q2

Є, z0/ Є
P= ( {q0, q1, q2}, {a, b}, G , d, q0, z0, {q2} )

Let us take w = aabbbb

(q0, aabbbb,z0) ├ ρ (q0,abbbb,aaz0)


├ ρ (q0,bbbb,aaaaz0)
40
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

├ ρ (q1,bbb,aaaz0)

25. Design a PDA to accept the language L = { a m bnc m / n, m ≥ 1} (Nov/Dec 2008)

Solution

The idea to design this PDA is that when we read „a‟ with „a‟ or „z0‟ as the top stack symbol,
push a on to the stack.

When reading b with a on the top stack symbol just change the state and don‟t perform any
operation.

Then while reading „a‟ with „a‟ on the top stack symbol pop the symbol.

The PDA p is defined as,

P= ({q0, q1, q2, q3}, {a, b, c}, Γ, δ , q0, z0, {q3})

The transition function is given as,

δ (q0, a, z0) = (q0,az0)


δ (q0, a ,a) = (q0,aa)
δ (q0, b ,a) = (q1,a)
δ (q1, b ,a) = (q1,a)
δ (q1, c ,a) = (q2,Є)
δ (q2, c ,a) = (q2,Є)
δ (q2, Є , z0) = (q3, Є)

The transition diagram is shown below,

W=aabbcc
41
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

(q0, aabbcc, z0) ├ ρ (q0,abbcc,az0)


├ ρ (q0,bbcc,aaz0)
├ ρ (q1,bcc,aaz0)
├ ρ (q1,cc,aaz0)
├ ρ (q2,c,az0)
├ ρ (q2, Є, z0)
├ ρ (q3, Є, Є)

The string aabbcc is accepted

W=abcc

(q0, abcc, z0) ├ ρ (q0,bcc,az0)


├ ρ (q1,cc,az0)
├ ρ (q2,c,z0) Not Accepted

26. Construct a transition table for PDA which accepts the Language L= { a3nbn | n ≥ 0 }
(Nov/Dec 2012)
Solution

The idea to design this PDA is that reading three a, single a is pushed on to the stack. Then
when we read „b‟ with „a‟ on the top stack symbol, pop the symbol „a‟ form the stack. When
we read „Є‟ with z0 at the top stack symbol, then reached the final state.

The transition function is defined as,

δ (q0, Є, z0) = (q4, Є)


δ (q0, a ,z0) = (q1,z0)
δ (q1, a ,z0) = (q2,z0)
δ (q1, a ,a) = (q2, a)
δ (q2, a ,z0) = (q3, az0)
δ (q2, a, a) = (q3, aa)
δ (q3, b, a) = (q3, Є)
δ (q3, a, a) = (q1, a)
δ(q3,Є,z0) = (q4, Є)

42
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

w = aaaaaabb

(q0, aaaaaabb, z0) ├ ρ (q1,aaaaaabb,z0)


├ ρ (q2,aaaabb,z0)
├ ρ (q3,aaabb,az0)
├ ρ (q1,aabb,az0)
├ ρ (q2,abb,az0)
├ ρ (q3, bb, aaz0)
├ ρ (q3, b, az0)
├ ρ (q3, Є, z0)
├ ρ (q4, Є, Є) Accepted

27. Construct the PDA accepting the language { (ab)n | n ≥1 } by empty stack. (Nov/Dec 2012)
The transition function is defined as,
δ (q0, Є, z0) = (q3, Є)
δ (q0, a ,z0) = (q1,z0)
δ (q1, a ,z0) = (q2,az0)
δ (q1, a ,a) = (q2, aa)
δ (q2, b ,a) = (q2,Є)
δ (q2, a, a) = (q1, a)
δ (q2, Є ,z0) = (q3, Є)

43
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

w = abab
(q0, abab, z0) ├ ρ (q1,bab,az0)
├ ρ (q2,ab,az0)
├ ρ (q1,b,aaz0)
├ ρ (q2, Є, aaz0)
├ ρ (q2, Є, az0)
├ ρ (q2, Є, z0)
├ ρ (q2, Є, Є) Accepted

28. Design a PDA to accept {0n 1n | n≥1}.Draw the transition diagram for the PDA. Show by
instantaneous description that the PDA accepts the string „0011‟. (10) (Nov/Dec
2024)[April/May 2024]

Solution:
L={0n 1n | n≥1}
Here we have to construct a PDA such that the string contains equal number of zero‟s and one‟s and
there is no Є as string.

The transition function is defined as,

Let q0 be the initial state and z0 be the top symbol of the stack initially.

δ (q0, 0, z0) = (q1, 0z0)


δ (q1, 0 ,0) = (q1,00)
δ (q1, 1 ,0) = (q2,Є)
δ (q2, 1 ,0) = (q2, Є)
δ (q2, Є , z0) = (q3,Є)
44
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Where q3is the final state

so PDA p=({q0,q1,q2},{0,1},Г,δ,q0,z0,{q3})
0, 0 / 00 1, 0 / Є

0, z0 / 0z0
Start 1, 0 / Є Є, z0 / Є
q0 q1 q2 q3

Let us check for the string 0011

w = 0011
(q0, 0011, z0) ├ ρ (q1,011,0z0)
├ ρ (q1,11,00z0)
├ ρ (q2,1,0z0)
├ ρ (q2, Є, z0)
├ ρ (q3, Є, Є) Accepted
So the string 0011 is accepted

29. Construct a pushdown automaton to accept the following language L on Σ = {a, b} by


empty stack L= { wwR | w Є Σ +} (May/June 2016) (OR) Constuct a DPDA for even length
palindrome.
(APR/MAY 2017)
The PDA p is defined as
P = ({q0, q1, q2}, {a, b}, Г, δ, q0, z0, {q2})
The transition function is defined as,
δ(q0,a,z0) = (q0,az0)
δ(q0,a,a) = (q0,aa)
δ(q0,b,z0) = (q0,bz0)
δ(q0,b,b) = (q0,bb)
δ(q0,a,b) = (q0,ab)
δ(q0,b,a) = (q0,ba)
δ(q0,Є,z0) = (q1,Є)
δ(q0,Є,a) = (q1,a)
δ(q0,Є,b) = (q1,b)

45
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

δ(q1,a,a) = (q1,Є)
δ(q1,b,b) = (q1,Є)
δ(q1,Є,z0) = (q2,Є)

a, b / ab
b, a / ba
b, b / bb
a,a / aa
b, b / Є
b, z0 / bz0
a, a / Є
a, z0 / az0

Є, a / a
Є, b / b
Start Є, z0 / Є Є, z0 / Є
q0 q1 q2

Let the string w= abba


(q0, abba, z0)
├ ρ (q0, bba, az0)
├ ρ (q0, ba, baz0)
├ ρ (q1, ba, baz0)
├ ρ (q1, a, az0)
├ ρ (q1, Є, z0)
├ ρ (q2 , Є, Є)  Accepted
Problems for converting PDA to CFG

30. Convert the PDA P = ({q, P}, {0, 1},{X,Z0},δ,q,z0) to a CFG if δ is given by
(a) δ(q,1,z0) = {(q,Xz0)}
(b) δ(q,1,X) = {(q,XX)}
(c) δ(q,0,X) = { (P,X)}
(d) δ(q,ε,X) = {(q,ε)}
(e) δ(P,1,X) = {(P,ε)}
(f) δ(P,0,z0) = {(q,z0)}

Solution:
For the above PDA,
States = {q, P}

46
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

State Symbols = {X, z0}


Bottom initial stack symbol = z0
Initial state = q
The CFG for the above PDA is G = (V, T, P, S)
Where, V  Nonterminals
P=(S,[q,X,q], [q,X,P], [P,X,q], [P,X,P], [q,z0,q], [q,z0,P], [P,z0,q], [P,z0,P])
T = {0,1}
S=S
The productions of the grammar by using the PDA are as follows,

Productions of CFG
P1: S  [ q, z0, q]

P2: S  [q, z0, P]

1. δ(q,1, z0) = {(q,X z0)}


P3: [q, z0,q]  1 [q,X,q] [q,z0,q]
P4 : [q, z0,q]  1 [q,X,P] [P,z0,q]
P5 : [q,z0,P]  1 [q,X,q] [q,z0,P]
P6 : [q,z0,P]  1 [q,X,P] [P,z0,P]

2. δ(q,1,X) = {(q,XX)}
P7 : [q, X,q]  1 [q,X,q] [q,X,q]
P8 : [q, X,q]  1 [q,X,P] [P,X,q]
P9 : [q,X,P]  1 [q,X,q] [q,X,P]
P10 : [q,X,P]  1 [q,X,P] [P,X,P]

3.δ(q,0,X) = { (P,X)}
P11: [q, X,q]  0 [P,X,q]
P12 : [q,X,P]  0 [P,X,P]

4. δ(q,ε,X) = {(q,ε)}
P13 : [q,X,q] ε

5. δ(P,1,X) = {(P,ε)}
P14 : [P,X,P]  1

6. δ(P,0,Z0) = {(q,z0)}
P15 : [P, z0,q]  0 [q, z0,q]
P16 : [P, z0,P]  0 [q, z0,P]
47
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

31. Convert the following PDA to the CFG grammar where δ is given by,
P= ({q, p},{0,1}, {Z0,X},δ,q,z0,{P})
{a) δ (q, 0, z0 ) = { (q, X z0)}
(b) δ(q,0,X)={(q, XX)}
(c) δ(q,1,X)={(q, X)}
(d) δ(q,ε,X) = {(P,ε)}
(e) δ(P,ε,X)= {(P,ε)}
(f) δ(P,1,X) = {(P,XX)} [April/May 2024]

Solution:
From the above PDA,
States = {q,P}
Stack Symbols = {X,z0}
Bottom initial stack symbol=z0
Initial state = q
The CFG for the above PDA is G=(V,T,P,S)
Where, V  Nonterminals
P=(S,[q,X,q], [q,X,P], [P,X,q], [P,X,P], [q,z0,q], [q,z0,P], [P,z0,q], [P,z0,P])
T={0,1}
S=S

Productions of CFG

P1: S  [ q, z0, q]

P2: S  [q, z0, P]


1. δ (q,0 , z0 ) = { (q,X z0)}

P3: [q, z0,q]  0 [q,X,q] [q,z0,q]


P4 : [q, z0,q]  0 [q,X,P] [P,z0,q]
P5 : [q,z0,P]  0 [q,X,q] [q,z0,P]
P6 : [q,z0,P]  0 [q,X,P] [P,z0,P]

2.δ(q,0,X)={(q,XX)}
P7 : [q, X,q]  0 [q,X,q] [q,X,q]
P8 : [q, X,q]  0 [q,X,P] [P,X,q]
P9 : [q,X,P]  0 [q,X,q] [q,X,P]
P10 : [q,X,P]  0 [q,X,P] [P,X,P]

48
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

3.δ(q,1,X)={(q,X)}
P11: [q, X,q]  1 [q,X,q]
P12 : [q,X,P]  1 [q,X,P]

4. δ(q,ε,X) = {(P,ε)}
P13 : [q,XP] ε

5. δ(P,ε,X)= {(P,ε)}
P14 : [P,X,P]  ε

6.δ(P,1,X) = {(P,XX)}
P15 : [P, X,q]  1 [P,X,q] [q,X,q]
P16 : [P, X,q]  1 [P,X,P] [P,X,q]
P17 : [P,X,P]  1 [P,X,q] [q,X,P]
P18 : [P,X,P]  1 [P,X,P] [P,X,P]

32. Construct CFG for the following PDA where δ is given by,
P=({q0,q1},{0,1},{X,Z0},δ,q,z0,Ф)

(a) δ(q0,0,z0) = { (q0,Xz0)}


(b) δ(q0,0,X) = { (q0,XX)}
(c) δ(q0,1,X) = { (q1,ε )}

Solution:
For the above PDA,
States = {q0, q1}
State Symbols = {X, z0}
Bottom initial stack symbol=z0
Initial state = q0

The CFG for the above PDA is G = (V,T, P,S)


Where, V  Nonterminals
P = (S,[q0,X,q0], [q0,X, q1], [q1,X,q0], [q1,X, q1], [q0,z0,q0], [q0,z0, q1], [q1,z0,q0], [q1,z0, q1])
T = {0,1}
S=S

The productions of the grammar by using the PDA are as follows,

49
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Productions of CFG

P1: S  [ q0, z0, q0]


P2: S  [q0, z0, q1]

1. δ(q0,0,z0) = { (q0,Xz0)}
P3: [q0, z0,q0]  0 [q0,X,q0] [q0,z0,q0]
P4 : [q0, z0,q0]  0 [q0,X, q1] [q1,z0,q0]
P5 : [q0,z0, q1]  0 [q0,X,q0] [q0,z0, q1]
P6 : [q0,z0, q1]  0 [q0,X, q1] [q1,z0, q1]

2. δ(q0,0,X)={(q0,XX)}
P7 : [q0, X,q0]  0 [q0,X,q0] [q0,X,q0]
P8 : [q0, X,q0]  0 [q0,X, q1] [q1,X,q0]
P9 : [q0,X, q1]  0 [q0,X,q0] [q0,X, q1]
P10 : [q0,X, q1]  0 [q0,X, q1] [q1,X, q1]
3. δ(q0,1,X)={(q1,ε)}
P11: [q0, X,q1]  1

33. Convert PDA to CFG. PDA is given by P = ({p, q},{0,1},{X,Z},δ, q, Z,Φ)


δ is defined by
δ(p,1,Z)={(p, XZ)},
δ(p,Є,Z)={(p, Є)},
δ(p,1,X)={(p, XX)},
δ(q,1,X)={(q, Є)},
δ(p,0,X)={(q, X)},
δ(q,0,Z)={(p, Z)} (Nov/Dec 2015)( Nov/Dec 2020)

Solution:
From the above PDA,
States = {p,q}
Stack Symbols = {X,Z}
Bottom initial stack symbol=Z
Initial state = q
The CFG for the above PDA is G = (V, T, P, S)
Where, V = Nonterminals
P = (S,[q,X,q], [q,X,P], [P,X,q], [P,X,P], [q,z0,q], [q,z0,P], [P,z0,q], [P,z0,P])
T = {0,1}
S=S
Productions of CFG

P1: S  [ q, z0, q]
50
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

P2: S  [q, z0, P]

1. δ(p,1,Z)={(p, XZ)}
P3:[p,Z,p]1[p,X,p][p,Z,p]
P4:[p,Z,p]1[p,X,q][q,Z,p]
P5:[p,Z,q]1[p,X,p][p,Z,q]
P6:[p,Z.q]1[p,X,q][q,Z,q]
\
2. δ(p,Є,Z)={(p, Є)}
P7:[p,Z,p] Є

3. δ(p,1,X)={(p, XX)}
P8:[p,X,p]1[p,X,p][p,X,p]
P9:[p,X,p]1[p,X,q][q,X,p]
P10:[p,X,q]1[p,X,p][p,X,q]
P11:[p,X.q]1[p,X,q][q,X,q]

4. δ(q,1,X)={(q, Є)},
P12:[q,X,q]1

5. δ(p,0,X)={(q, X)},
P13: [p,X,p]0[p,X,p]
P14:[p,X,q]0[p,X,q]
6. δ(q,0,Z)={(p, Z)},
P15: [q, Z,q]  0 [P,Z,q]
P16 : [q,Z,P]  0 [P,Z,P]

Converting CFG To PDA

34. Construct the PDA for the following grammar E  E+E | E * E | a


Solution:
The PDA is given below:

For Non terminal „E‟:


δ(q,ε,E) = { (q, E+E), (q, E*E), (q, a) }

For terminal +,*,a


δ( q,+,+)={(q,ε)}

51
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

δ(q,*,*)={(q,ε)}
δ(q,a,a)={(q,ε)}

Take any string w= a*a+a

(q,a*a+a,E) ├ ρ (q, ε a*a+a, E)


├ ρ (q, a*a+a, E*E)
├ ρ (q, a*a+a, a*E)
├ ρ (q, *a+a, *E)
├ ρ (q, a+a, E)
├ ρ (q, a+a, E+E)
├ ρ (q, a+a, a+E)
├ ρ (q, +a, +E)
├ ρ (q, a, E)
├ ρ (q, a, a)
├ ρ (q, ε, ε)

Thus the CFG accepts the string a*a+a and it‟s accepted by PDA by empty stack.
35. Construct a PDA for the given grammar and check for the validation of abcba and acb.

S  aSa | bSb |c

Solution:

The PDA is given below:

For Non terminal „S‟:


δ(q,ε,E) = { (q,aSa), (q,bSb), (q,c) }
For terminal a,b,c
δ( q,a,a)={(q,ε)}
δ(q,b,b)={(q,ε)}
δ(q,c,c)={(q,ε)}

w= abcba

(q,abcba,S) ├ ρ (q, ε abcba,S)


├ ρ (q, abcba, aSa)
├ ρ (q, bcba, Sa)
├ ρ (q, bcba, bSba)
├ ρ (q, cba,Sba)
├ ρ (q,cba, cba)
52
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

├ ρ (q, ba, ba)


├ ρ (q, a, a)
├ ρ (q, ε, ε)

Thus the CFG accepts the string abcba and it‟s accepted by PDA by empty stack.

W=acb

(q,acb,S) ├ ρ (q, ε acb,S)


├ ρ (q, acb, aSa)
├ ρ (q, cb, Sa)
├ ρ (q, cb, ca)
├ ρ (q, b, a)

The given string w = acb is not accepted by PDA.

36. Construct a PDA for the given grammar and check for the validation of aa×a0 and (a0+a).
E  I | E + E | E × E | (E)
I  a | Ia | 0 | I0
Solution:
The PDA is given below:
For Non terminal „E‟:
δ(q,ε,E) = { (q,I), (q,E+E), (q,E×E),(q,(E)) }
δ(q,ε,I) = { (q,a), (q,Ia), (q,0),(q,I0) }
For terminal +, ×,(,),0,a
δ( q,+,+)={(q,ε)}
δ(q, ×,×)={(q,ε)}
δ(q,(,( )={(q,ε)}
δ(q,),) )={(q,ε)}
δ(q,0,0 )={(q,ε)}
δ(q, a ,a)={(q,ε)}
w= aa×a0

(q, aa×a0,E) ├ ρ (q, ε aa×a0,E)


├ ρ (q, aa×a0, E × E)
├ ρ (q, aa×a0, Ia × E )
├ ρ (q, aa×a0, aa ×E)
├ ρ (q, a×a0,a × E)
├ ρ (q, ×a0, ×E)
├ ρ (q, a0, E)
53
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

├ ρ (q, a0, I0)


├ ρ (q, a0, a0)
├ ρ (q, 0, 0)
├ ρ (q, ε, ε)

Thus the CFG accepts the string aa×a0 and it‟s accepted by PDA by empty stack.

W= (a0+a)

(q, (a0+a),E) ├ ρ (q, ε (a0+a),E)


├ ρ (q, (a0+a), (E))
├ ρ (q, a0+a), E) )
├ ρ (q, a0+a), E+E))
├ ρ (q, a0+a), I0+E ))
├ ρ (q, a0+a), a0+E) )
├ ρ (q, 0+a), 0+E))
├ ρ (q, +a), +E))
├ ρ (q, a), E))
├ ρ (q, a), a))
├ ρ (q, ), ))
├ ρ (q, ε, ε)

Thus the CFG accepts the string (a0+a) and it‟s accepted by PDA by empty stack.

37. Consider the grammar G=(V,T,P,S) when S  aA, A  aABC/bB/a, B b, Cc and find
the PDA.

Solution:
The PDA is given below:

For Non terminal „S‟:


δ(q,ε,S) = { (q,aA) }
δ(q,ε,A) = { (q,aABC), (q,bB), (q,a) }
δ(q,ε,B) = { (q,b) }
δ(q,ε,C) = { (q,c) }
For terminal a,b,c
δ( q,a,a)={(q,ε)}
δ(q,b,b)={(q,ε)}
δ(q,c,c)={(q,ε)}
Take any string w= abb
(q,abb,S) ├ ρ (q, ε abb,S)
54
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

├ ρ (q, abb, aA)


├ ρ (q, bb, A)
├ ρ (q, bb, bB)
├ ρ (q, b, B)
├ ρ (q, b, b)
├ ρ (q, ε, ε)
Thus the CFG accepts the string abb and it‟s accepted by PDA by empty stack.

38. Construct the CFG for L = { 0n10 n | n ≥ 0} and use it to construct PDA.[Nov/Dec 2024]
Solution:

The CFG for L = { 0 n 1 0 n | n ≥ 0}


S  A1 A
A 0A | ε

Non terminals = S,A


Terminals = 1,0, ε
The transition function for the PDA is,
δ( q, ε, S) = { (q,A1A)}
δ(q, ε, A) = {(q,0A), (q,ε) }
δ(q, 0, 0) = {(q,ε)}
δ(q, 1, 1) = {(q,ε)}
δ(q, ε, ε) = {(q,ε)}
Let the string w = 0001
(q, 0001,S) ├ ρ (q, ε 0001,S)
├ ρ (q, 0001, A1A)
├ ρ (q, 0001, 0A1A)
├ ρ (q, 001, A1A)
├ ρ (q, 001, 0A1A)
├ ρ (q, 01, A1A)
├ ρ (q, 01, 0A1A)
├ ρ (q, 1, A1A)
├ ρ (q, 1, 1A)
├ ρ (q, ε, A)
├ ρ (q, ε, ε)
Thus the CFG accepts the string 0001 and it‟s accepted by PDA by empty stack.

55
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

39. Convert the following CFG to PDA verify for (a+b) and a++
I  a/b/Ia/Ib/I0/I1, E  I/E+E/E*E/(E). (April/May 2017)

Solution:
The PDA is given below:

For Non terminal „I,E‟:


δ(q,ε,I) = { (q,a)(q,b), (q,Ia),(q,Ib),(q,I0),(q,I1) }
δ(q,ε,E) = { (q,I), (q,E+E), (q,E*E), (q,(E)) }

For terminal a,b,0,1


δ( q,a,a)={(q,ε)}
δ(q,b,b)={(q,ε)}
δ(q,0,0)={(q,ε)}
δ(q,1,1)={(q,ε)}

Take any string w= (a+b)


(q, (a+b),E) ├ ρ (q, ε (a+b),E)
├ ρ (q, (a+b), (E))
├ ρ (q, a+b), E))
├ ρ (q, a+b), E+E))
├ ρ (q, a+b), I+E))
├ ρ (q, a+b), a+E))
├ ρ (q, a+b), a+E))
├ ρ (q, +b), +E))
├ ρ (q, b), E))
├ ρ (q, b), I))
├ ρ (q, b), b))
├ ρ (q, ), ))
├ ρ (q, ε, ε)
Thus the CFG accepts the string (a+b) and it‟s accepted by PDA by empty stack.

Take any string w= a++

(q, a++,E) ├ ρ (q, ε a++,E)


├ ρ (q, a++, E+E)

The given string w = a++ is not accepted by PDA.

56
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

DETERMINISTIC PUSHDOWN AUTOMATA

40. What are deterministic PDA‟s? Give example for Non-deterministic and deterministic
PDA? (6) (Nov/Dec 2015)

Definition:
A PDA M =( Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) is deterministic if:
1. For each q in Q and Z in Ґ, whenever δ(q, Є, Z) is nonempty then δ(q, a, Z) is
empty for all a in Σ.
2. For no q in Q, Z in Ґ, and a in Σ U {Є} does δ(q, a, Z) contains more than one
element. (E.g): The PDA accepting {wcw R | w in ( 0+1 ) * }.
Solution: 1, 0/10
0, 1/01
0, 0/00
1, 1/11
1, z0/1z0 0, 0/ε
0, z0/0z0 1, 1/ε

ε, z0/z0
q0 q1 q2

ε, 0/0
The above PDA is not a deterministic push down automata and the justification is shown
below. ε, 1/1
ε,z0/z0

1. δ(q,a,X) has at most one member for any q.


2.δ(q,a,X) is non empty, then δ(q, ε, X) must be empty.

Accepting to the first condition, all the transitions of the given PDA satisfies the DPDA. But take
the condition 2 and consider the following transition.

1. δ(q0 , 0, z0) = { (q0, 0z0)}


δ(q0,ε , z0) = { (q1, z0) }

2. δ(q0, 1, z0) = { (q0, 1z0) }


δ(q0, ε, z0) = { (q1, z0)}

3. δ(q0, 1, 1) = { q0,11}
δ(q0, 0, 1) = { q0, 01) }
δ(q0, ε, 1) = {q1, 1}

57
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

From the above transition, we find that δ(q,a,x) for any state q in Q and a in ∑ and X in Γ is
not empty and δ(q, a, X) also is not empty which violates the second condition of DPDA. So the
above PDA is not a Deterministic Push Down Automata.

Refer the Non-deterministic Problem: L={0n 1n | n≥1}.Page.No:12

41. Check whether the following PDA is deterministic,


(a) δ(q, 0, z0) = { (q, Xz0) }
(b) δ(q, 0, X) = { (q , XX) }
(c) δ(q, 1, X) = { (q, X) }
(d) δ(q, ε, X) = { (P, ε) }
(e) δ(P, ε, X) = { (P, ε) }
(f) δ(P, 1, X) = { (P, XX) }
(g) δ(P, 1, z0) = { (q, ε) }

Solution: Let us construct the transition diagram for the above PDA.
1, x/xx
0, x/xx 1, z0/ε
0, z0/0z0 1, x/xx
ε, x/ε

ε, x/ε
q p

The above PDA is not a deterministic push down automata and the justification is shown
below.

1. δ(q,a,X) has at most one member for any q.


2.δ(q,a,X) is non empty, then δ(q,ε,X) must be empty.

Accepting to the first condition, all the transitions of the given PDA satisfies the DPDA. But take
the condition 2 and consider the following transition.

1. δ(q , 0, X) = { (q, XX)}


δ(q, ε , X) = { (P, ε) }
δ(q, 1 , X) = { (q, X) }

2. δ(P, 1, X) = { (P, XX) }


δ(P, ε, X) = { (P, ε)}

58
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

So by seeing the above transition, for δ(q, a, X) is non empty and δ(q, a, X) is also non empty that
violates the second condition of DPDA.

δ(p,1,X) = (P,XX)  Non-Empty

Where q=P, a=1, x=x

δ(P, ε, X) = (P, ε)  Non empty

So the above PDA is not a Deterministic Push Down Automata.

42. How Є -productions are eliminated from a grammar whose language does not have
empty string? Remove Є -productions from the grammar given below.
Sa/aA/B/C AaB/Є BAa CaCD Dddd (Nov/Dec 2020)

Solution:
After Eliminate Є –productions are
Sa/aA/B/C/a
AaB
BAa/a
CaCD
Dddd

43. Write procedure to find PDA to CFG. Give an example for PDA and its CFG.

Algorithm for getting production rules of CFG.


1) If q0 is start state in PDA and qn is final state of PDA then [q0 Z qn ] becomes start state of
CFG. Hence Z represents the stack symbol.
2) The production rule for the ID of the form δ(qi,a,Z0) = (qi+1, Z1, Z2) Can be obtained as

δ(qi, Z0 qi+K) a (qi+1, Z1, qm) (qm, Z2, qi+K)


Where qi+K , qm represents the intermediate states Z0, Z1, Z2 are stack symbols and a is input
symbol.
3) The production rule for the ID of the form δ(qi, a Z0)  (qi+1, Є) can be converted as (qi, Z0
qi+1)a
Let us understand this algorithm with the help of some examples.

59
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

44. Convert PDA to CFG. PDA is given by P = ({p, q},{0,1},{X,Z},δ, q, Z), (Nov/Dec 2015)
δ is defined by
δ(p,1,Z)={(p, XZ)},
δ(p,Є,Z)={(p, Є)},
δ(p,1,X)={(p, XX)},
δ(q,1,X)={(q, Є)},
δ(p,0,X)={(q, X)},
δ(q,0,Z)={(p, Z)},

Solution:
From the above PDA,
States = {p,q}
Stack Symbols = {X,Z}
Bottom initial stack symbol=Z
Initial state = q
The CFG for the above PDA is G = (V, T, P, S)
Where, V = Nonterminals
P = (S,[q,X,q], [q,X,P], [P,X,q], [P,X,P], [q,z0,q], [q,z0,P], [P,z0,q], [P,z0,P])
T = {0,1}
S=S
Productions of CFG

P1: S  [ q, z0, q]
P2: S  [q, z0, P]

1. δ(p,1,Z)={(p, XZ)}
P3:[p,Z,p]1[p,X,p][p,Z,p]
P4:[p,Z,p]1[p,X,q][q,Z,p]
P5:[p,Z,q]1[p,X,p][p,Z,q]
P6:[p,Z.q]1[p,X,q][q,Z,q]
\
2. δ(p,Є,Z)={(p, Є)}
P7:[p,Z,p] Є

3. δ(p,1,X)={(p, XX)}
P8:[p,X,p]1[p,X,p][p,X,p]
P9:[p,X,p]1[p,X,q][q,X,p]
P10:[p,X,q]1[p,X,p][p,X,q]
P11:[p,X.q]1[p,X,q][q,X,q]
60
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

4. δ(q,1,X)={(q, Є)},
P12:[q,X,q]1

5. δ(p,0,X)={(q, X)},
P13: [p,X,p]0[p,X,p]
P14:[p,X,q]0[p,X,q]
6. δ(q,0,Z)={(p, Z)},
P15: [q, Z,q]  0 [P,Z,q]
P16 : [q,Z,P]  0 [P,Z,P]

45. What language over {0, 1} does the CFG with productions
S → 00S|11S|S00|S11|01S01|01S10|10S10|10S01|Є generate? Justify your answer.
Solution

(i)
S 00S

00

(ii)

S 11S

11

(iii)

S 01S01

0101

L(G) = { 00,11,0101,0110,………. n>=1}

46. Design an pushdown automata to recognize the language, L defined by,


and wc is the one‟s complement of w}.Nov/Dec2021

The PDA P is defined as,


P = ({q0, q1, q2}, {0, 1, c}, Γ, δ, q0, z0, {q2})
The transition function is given as,
δ(q0, 0, z0) = (q0,0z0)
δ(q0, 0 ,0) = (q0,00)
δ(q0, 1 ,z0) = (q0,1z0)
61
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

δ(q0, 1 ,1) = (q0,11)


δ(q0, 0 ,1) = (q0,01)
δ(q0, 1 ,0) = (q0,10)
δ(q0, c ,z0) = (q1,z0)
δ(q0, c ,0) = (q1,0)
δ(q0, c ,1) = (q1,1)
δ(q1, 0 ,0) = (q1,ε)
δ(q1, 1 ,1) = (q1,ε)
δ(q1, ε ,z0) = (q2,ε)

Let us take the string w= 011c110

(q0, 011c110,z0) ├ ρ (q0, 11c110, 0z0)


├ ρ (q0, 1c110,10z0)
├ ρ (q0, c110, 110z0)
├ ρ (q1, 110, 110z0)
├ ρ (q1, 10, 10z0)
├ ρ (q1, 0, 0z0)
├ ρ (q1, ε, z0)
├ ρ (q2, ε, ε) Accepted

47. Construct an appropriate model to recognize the language L defined by, Nov/Dec 2021

a, a/aa d, a/ε
a, z0/az0 b, b/bb c, b/ ε

q0 q1 q2 q3 q4

b,a/ba
c,b/ε
d, a/ε ε, z0/ε
The PDA p is defined as,
P = ({q0,q1,q2,q3,q4}, {a,b,c}, Γ, δ, q0, z0, {q4})

62
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

The transition function is defined as,

δ(q0, a, z0) = (q0,az0)


δ(q0, a, a) = (q0,aa)
δ(q0, b, a) = (q1, ba)
δ(q1, b, b) = (q1,bb)
δ(q1, c, b) = (q2,ε)
δ(q2, c, b) = (q2,ε)
δ(q2, d, a) = (q3,ε)
δ(q3, d, a) = (q3,ε)
δ(q3, ε, z0) = (q4,ε)

w = abcd

(q0, abcd,z0) ├ ρ (q0,abcc,z0)


├ ρ (q0,bcd,az0)
├ ρ (q1,cd,baz0)
├ ρ (q2,d,az0)
├ ρ (q3, ε,z0)
├ ρ (q4, ε, ε)

48. Design appropriate automation model for the language defined by the grammar given
below.
S → aSBC
CB → BC
bB → bb
cC → cc
S → aBC
aB → ab
bC → bc Nov/Dec 2021

63
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Solution:

S ⇒ aSBC

⇒ aaBCBC (using S → aBC)

⇒ aabCBC (using aB → ab)

⇒ aabCBC (using CB → HB)

⇒ aabBCC (using HB → HC)

⇒ aabbCC (using HC → BC)

⇒ aabbcC (using bB → bb)

⇒ aabbcc

Construct a TM for L = {aabbcc}.

(Y,Y,R) (Z,Z,R)
(a,a,R) (b,b,R)
(b,b,L)
(a,a,L)
(c,Z,L)
Start (a,X,R) (b,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt

Check the input w=aabbcc

64
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

Instantaneous description
q0 aabbccΔ├ Xq1abbcc Δ ├ Xaq1bbcc Δ ├ XaYq2bccΔ├ XaYbq2cc Δ├ XaYbZq3cΔ├ XaYbq3Zc Δ├
XaYq3bZc Δ├ Xaq3YbZcΔ├ Xq3 aYbZcΔ├ Xq0 aYbZcΔ├ XXq1YbZcΔ├ XXYq1 bZcΔ├ XXYYq2ZcΔ├
XXYYZq2cΔ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0 YYZZΔ├ XXYq4 YZZΔ├ XXYYZZq4
Δ├XXYYZZΔ q5Accepted

49. Design appropriate automation model for the language defined by the grammar given
below.
S → abc/aAbc
Ab → bA
Ac → Bbcc
bB → Bb
S → aBC
aB → aa/aaA. Nov/Dec 2021

Solution:
S→aAbc
→abAc
→abBbcc
→aBbbcc
→aaAbbcc
→aabAbcc
→aabbAcc
→aabbBbccc
→aabBbbccc
→aaBbbbccc
→aaabbbccc
The language generated by this grammar is {anbncn | n≥1}.
Construct a TM for L = {an bn cn / n≥0 }. (May – 08,May – 11)

65
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

(Y,Y,R) (Z,Z,R)
(a,a,R) (b,b,R)
(b,b,L)
(a,a,L)
(c,Z,L)
Start (a,X,R) (b,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt

Check the input w=aabbcc


Instantaneous description
q0 aabbccΔ├ Xq1abbcc Δ ├ Xaq1bbcc Δ ├ XaYq2bccΔ├ XaYbq2cc Δ├ XaYbZq3cΔ├ XaYbq3Zc Δ├
XaYq3bZc Δ├ Xaq3YbZcΔ├ Xq3 aYbZcΔ├ Xq0aYbZcΔ├ XXq1YbZcΔ├ XXYq1bZcΔ├ XXYYq2 ZcΔ├
XXYYZq2cΔ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0 YYZZΔ├ XXYq4 YZZΔ├ XXYYZZq4
Δ├XXYYZZΔ q5Accepted

66
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

ANNA UNIVERSITY QUESTIONS


Nov/Dec 2015
Part-A
1. Let G be the grammar with
SaB|bA,
Aa|aS|bAA,
Bb|bS|aBB.
For the string aaabbabbba find the left most derivation.
2. Construct the context-free grammar representing the set of palindromes over (0+1)*
Part-B
12.(a).(i) Let G=(V,T,P,S)be a Context free Grammar then prove that if the recursive inference
procedure tells us that terminal string W is in the language of variable A, then there is a parse tree
with root A and yields w. (10)
(ii) Given the grammar G = (V, Σ, R, E), where
V={E,D,1,2,3,4,5,6,7,8,9,0,+,-,*,/,(,) }
Σ={1,2,3,4,5,6,7,8,9,0,+,-,*,/,(,) }, and R contains the following rules:
ED | (E) | E+E | E-E | E*E \ E | E
D0 | 1 | 2 |…..9
Find a parse tree for the string 1+2*3. (6)
(Or)
(i) What is an ambiguous grammar? Explain with an example. (6)
May/June 2016
Part A
1. Construct a CFG for set of strings that contain equal number of a‟s and b‟s over ∑={a,b}
Part B
12. (i) When is a grammar said to be ambiguous? Explain with the help of an example.(8)
(ii) Show the derivation steps and construct derivation tree for the string „ababbb‟ by using
leftmost derivation with the grammar SAB|Є , AaB, BSb. (8)
(Or)
(i) Construct a CFG for the regular expression (011+1)(01). (6)
Nov/Dec 2016

67
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

PART A
1. What is meant by Context Free Grammar (CFG)?
PART B
1. (i) Construct a context Free Grammar for the language l={an |n is odd}
(ii) Define derivation tree. Explain its uses with an example.
April/May 2017
PART A
1. Generate CFG for a signed integer constant in language.
2. Construct a rightmost derivation of (a+b)*c for using grammar, and also state that whether a
given grammar is ambiguous one or not.
PART B
Nov/Dec 2017
PART A
1. What are the closure properties of context-free languages?
2. Derive a string „aababa‟ for the following context free grammar(CFG)
S  aSX / b
XXb/a
PART B
1. a) (i) Construct a CFG to generate even add set of palindromes over alphabet {a,b}.
(ii) Generate CFG for the language L = { 0i1j0k | i>j+k}.
April/May 2018
PART A
1. Define Ambiguity.
ANNA UNIVERSITY QUESTIONS
Nov/Dec 2015
Part-A
1. What are the different ways of language acceptances by a PDA and define them?
2. Convert the following CFG to a PDA SaAA, AaS | bS | a.
Part-B
13.(a).(i) Design a PDA to accept {0n1n | n≥1}.Draw the transition diagram for the PDA. Show by
instantaneous description that the PDA accepts the string „0011‟. (10)

68
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

(ii) State the Pumping lemma for CFL and Show that the language L={an bncn | n≥1} is not a
CFL.(6)
(Or)
(b) (i) convert PDA to CFG. PDA is given by P=({p,q},{0,1},{X,Z},δ,q,Z),
δ is defined by δ(p,1,Z)={(p,XZ)}, δ(p,Є,Z)={(p,Є)},δ(p,1,X)={(p,XX)},
δ(q,1,X)={(q,Є)},δ(p,0,X)={(q,X)}, δ(q,0,Z)={(p,Z)}(10)
(ii) What are deterministic PDA‟s? Give example for Non-deterministic and deterministic PDA? (6)
May/June 2016
PART A
1. Does a pushdown Automata has memory? Justify.
2. Define a pushdown automaton?
PART B
13.(a).(i) Construct a pushdown automaton to accept the following language L on Σ = {a, b} by
empty stack L= { wwR | w Є Σ +}
(ii) What is an Instantaneous description of a PDA? How will you represent it? Also give the three
important principles of ID and their transactions. (6)
(Or)
(b) (i) Explain acceptance by final state and acceptance by empty stack of a pushdown automata. (8)
(ii) State pumping Lemma for CFL. Use pumping lemma to show that the language
L = { ai bjck | i <j<k} is not a CFL. (8)
Nov/Dec 2016
PART A
1. When is push down automata(PDA) said to be deterministic?
2. What are the conventional notations of push Down Automata?
PART B
1. (i) Outline an instantaneous description of a PDA.
(ii) State and explain the pumping lemma for CFG.
2. With an example, explain the procedure to obtain a PDA from the given CFG.
April/May 2017
PART A

69
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

1. Differentate PDA acceptance by empty stack method with acceptance by the final state
method.
PART B
1. (i) Constuct a DPDA for even length palindrome.
(ii) Prove –If PDA P is constructed from CFG G by the above construction, then N(P)=L(G)
2. Convert the following CFG to PDA verify for (a+b) and a++
I  a/b/Ia/Ib/I0/I1, E  I/E+E/E*E/(E).
Nov/Dec 2017
PART A
1. Show that L={ap /p is prime} is not context free.
PART B
2. a)(i) Find PDA that accept the given CFG: (Grammar mistake so cannot able to solve the
question)
S  xaax
Xax/bx/€
(ii) Construct PDA for the language an bmcn+m
3. (i) Prove that deterministic and non deterministic PDA are not equivalent.
(ii) Explain pumping Lemma for CFL.
April/May 2018
PART A
2. When is PDA said to be deterministic?
3. What are the ways of language acceptance in PDA?
PART B
4. a)i) Construct PDA for the language (WCWR /W€{0,1}} . (8)
ii) Construct CFG for the constructed PDA.(5)
b)(i) Explain pumping lemma for Context Free Languages with example.(7)
(ii) Show that Deterministic PDA is less powerful than nondeterministic PDA.(6)
Nov/Dec 2020
PART A
1. Write a context Free Grammar for the language consisting of equal number of a‟s and b‟s.
2. Define Deterministic PDA.

70
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION

PART B
3. How Є -productions are eliminated from a grammar whose language does not have empty
string? Remove Є -productions from the grammar given below.
Sa/aA/B/C AaB/Є BAa CaCD Dddd
4. Write procedure to find PDA to CFG. Give an example for PDA and its CFG.
PART C
1. Convert PDA to CFG. PDA is given by P = ({p, q},{0,1},{X,Z},δ, q, Z,Φ)
δ is defined by
δ(p,1,Z)={(p, XZ)},
δ(p,Є,Z)={(p, Є)},
δ(p,1,X)={(p, XX)},
δ(q,1,X)={(q, Є)},
δ(p,0,X)={(q, X)},
δ(q,0,Z)={(p, Z)}
Nov/Dec 2021
PART A
1. Write CFG to accept the language defined by,

2. List out the steps for performing LL parsing.


3. Draw pushdown automata to accept all palindromes of odd length.
4. Formally define the pushdown automata based on the types of acceptance.

PART B
1. What language over {0, 1} does the CFG with productions
S → 00S|11S|S00|S11|01S01|01S10|10S10|10S01|Є generate? Justify your answer.
2. Design an pushdown automata to recognize the language, L defined by,

and wc is the one‟s complement of w}.


3. Construct an appropriate model to recognize the language L defined by,

71
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

UNIT IV - NORMAL FORMS AND TURING MACHINES

Normal forms for CFG – Simplification of CFG- Chomsky Normal Form (CNF) and
Greibach Normal Form (GNF) – Pumping lemma for CFL – Closure properties of Context
Free Languages –Turing Machine: Basic model – definition and representation –
Instantaneous Description – Language acceptance by TM – TM as Computer of Integer
functions – Programming techniques for Turing machines (subroutines).
PART-A

1. What are the properties of the CFL generated by a CFG?

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

There are no productions of the form AB. where, A and B are variables.

2. Let G = (V, T, P, S) with the productions given by SaSbS/B/ε, BabB. Eliminate the
useless production.

Solution: Remove B is useless production because of Variable is not reachable.

S aSbS / ε

3. What is a useful production?

Let G = (V, T, P, S) be a CFG. A variable A Σ V is said to be useful if there is at least one w Σ L(G)
such that S * xAy * w with x, y in (VUT)*.

4. Determine whether the grammar G has a useless production?

SA

AaA / ε

B bA

Solution: The variable B is useless, since it is used by the start variable or by the variable in the start
production. BbA is a useless production.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 1


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


5. What is a useless symbol?

A symbol x is useful if there is a derivation

S  * α x β  * w for some α, β, w ∑ T* or else, it is useful.

6. What do you mean by null production and unit production? Give an example.
(May/June 2016)

Null production

We must eliminate Є-productions, those of the form AЄ for some variable.

Example:

Solution:

Unit production

A unit production is a production of the form AB, where both A and B are variables. These
productions can be useful.

Example:

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 2


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


7. Eliminate the unit production for the following grammar,

E E+T | T

T T*F | F

F (E) | I I Ia | Ib | I0 | I1 | a | b

Solution:

Rules:

1. According to the basis, all the non terminals by itself is unit pair.
2. According to the induction, if(A,B) is a unit pair and if BC is a production, then (A,C) is also a
unit pair.
Basis: Non Terminals are V={E,T,F,I}

So (E,E) (T,T) (F,F) (I,I) are the unit pairs.

Induction:

The steps for eliminating unit productions are,

1. Find all the unit pairs of the grammar.


2. Then for each unit pair (A, B), add to P 1 productions Aα, where Bα is a non unit production
in P.
Unit pairs of the grammar G is, (E,E) (E,T) (E,I) (T,T) (T,F) (T,I) (F,F) (F,I) (I,I)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 3


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Unit pair Production

(E,E) EE+T

(E,T) ET*F

(E,F) E(E)

(E,I) EIa|Ib|I0|I1|a|b

(T,T) TT*F

(T,F) T(E)

(T,I) TIa|Ib|I0|I1|a|b

(F,F) F(E)

(F,I) FIa|Ib|I0|I1|a|b

(I,I) IIa|Ib|I0|I1|a|b

So the grammar after eliminating unit production is as follows,

EE+T / T*F / (E) / Ia / Ib / I0 / I1 / a / b

TT*F / (E) / Ia / Ib / I0 / I1 / a / b

F(E) / Ia / Ib / I0 / I1 / a / b

I  Ia / Ib / I0 / I1 / a / b

8. What are the closure properties of context-free languages?[April/May 2024]

 Closure under union


 Closure under concatenation
 Closure under iteration
 Closure under intersection with a Regular languages.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 4


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


9. Give the steps to eliminate useless symbols. Nov/Dec 2017
To see the useless symbols, we have to find generating and reachable symbols.

Generating symbols

Since S  Є, S is generating.
A  a, so A generates ‗a‘. A is generating.
B  A, A is generating so B is also generating.
Ε, a, b is generating.

Generating symbols={S,A,B,a,b,ε}

Reachable symbols

Starting symbol ‗S‘ is always reachable.


S  ASB/ Є, so A, S, B, Є are also reachable.
A  a, B  bb, so {a, b} are also reachable symbols.

Reachable symbols={S,A,B,a,b,ε}

So all the non terminals and terminals are generating and reachable symbols. So the above CFG
does not have the useless symbols.

10. Write the procedure to eliminate the unit productions.

i) Find all variables B, for each A such that A * B

ii) The new grammar G is obtained by letting into P all non-unit productions of P.

iii) For all A and B satisfying A * B, add to P

Ay1/ y2 / y3 /........./ yn, where By1/ y2 / y3 /........./ yn is the set of productions in P.

11. What is GNF?

Every CFL L without ε cab be generated by a grammar for which every production is of the
form A aα, where A Є V(Variable), a Є T(Terminal), is a string of variables.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 5


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


12. Define Chomsky Normal Form. State Chomsky Normal Form theorem. (Nov/Dec 2016)
April/May 2024

CFGs in certain standard forms are quite useful for some computational problems.

A context-free grammar is in Chomsky normal form (CNF) if every rule is either of the form.

ABC or A  a

Given a CNF: there are no useless symbols, and every production body consists of either two
variables or one terminal

Where a is a terminal and A, B and C are variables – except B and C may not be the start variable. In
addition, we allow the rule S Є if necessary.

13. Derive the rules to remove Є productions with an suitable example. (Dec‘09)

If Є  L, then we cannot do much. S  Є is needed for this.


For all rules of the type A  Є and A is not the start symbol, we proceed as follows:
For occurrence of an A on the right-hand side of a rule, we add a rule with that occurrence deleted.
For a rule like R  uAv, we add the rule R uv (either u or v not Є)
For a rule like R  A, we add R  Є, unless we removed R Є earlier.
For a rule with multiple occurences of A, we add one rule for each combination. R  uAvAw would
add R  uvAw, R  uAvw, and R  uvw.

Consider Add a new start symbol S0

S ASA | aB S0  S

AB|S SASA | aB

Bb|Є AB|S

Bb|Є

Remove B Є Remove A Є

S0  S S0  S

S  ASA| aB| a S ASA | aB | a | SA | AS | S

AB|S|Є AB|S

Bb Bb

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 6


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


14. If the CFG is as below

S 0A | 1B | C

A 0S | 00

B1|A

C  01

Then remove the unit productions.

Solution: Clearly S C is a unit production. But while removing SC we have to consider what C
gives. So, we can add a rule to S.

S 0A | 1B| 01

Similarly BA is also a unit production so we can modify it as

B 1 | 0S | 00

Thus finally we can write CFG without unit production as

S 0A | 1B | 01

A 0S | 00

B 1 | 0S | 00

C 01

15. What are the two major normal forms for context-free grammar?

The two Normal forms are

i. Chomsky Normal Form (CNF)

ii. Greibach Normal Form (GNF)

16. State the pumping lemma for CFLs.

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

|z| > = n, then z = uvwxy such that:

(i) |vx| ≥ 1

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 7


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(ii) |vwx| ≤ n and

(iii) For all i ≥ 0 uvi wxi y is in L.

17. What is the main application of pumping lemma in CFLs?

The pumping lemma can be used to prove a variety of languages are not context free.

The CFL pumping lemma as an “adversary game, as follows.‖

 We pick a language L that we want to show is not a CFL


 Our ―adversary‖ gets to pick n, which we do not know, and we therefore must plan for any
possible n.
 We get to pick z, and may use n as a parameter when we do so.
 Our adversary gets to break z into uvwxy, subject only to the constraints that |uwx| ≤ n and
vx ≠ Є
 We ―win‖ the game, if we can, by picking i and showing that uvi wxi y is not in L

18. Convert the following CFG to a PDA. (Nov/Dec 2015)

SaAA, AaS | bS | a

Solution:

For Non-Terminal ‗S‘ and ‗A‘:

1. δ(q,Є,S)={(q,aAA)}

2. δ(q,Є,A)={(q,aS),(q,bS),(q,a)}

For Terminal ‘a‘ and ‗b‘:

1. δ(q,a,a)={(q,Є)}

2. δ(q,b,b)={(q,Є)}

19. Define a Turing Machines. (May-14,Dec-03,May-06,07) (Nov/Dec 2015) Apr/May-2018


The turing machine is a collection of following components.

M = (Q,∑, Γ,δ,q0,∆ or B,F)

Q is a finite set of states.


Γ is finite set of external symbols.
∑ is a finite set of input symbols.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 8


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Δ or B or B ∈ Γ is a blank symbol majority used as end marker for input.
δ is a transition or a mapping function.

The mapping function shows the mapping from states of finite automata and input symbol on the tape
to the next states, external symbols and the direction for moving the tape head. This is known as a
‗triple‘ or a program for turing machine.

For example: δ(q0 ,a )  (q1 , A, L)

This means that if currently we are reading the input symbol ‗a‘ and we are in q 0 state then we can go
to q1 state by replacing or printing ‗a‘ by A and now move ahead to left.

q0 be the initial state where q0 ∈ Q


F is a set of final states. The final state is such a state where Turing machines halts. Thus Turing
machine is such machine which is used computes a large class of language.

20. What are the required fields of an instantaneous description of a Turing machine? (Nov/Dec
2016). & Give the configuration of Turing machine. Nov/Dec 2017
The instantaneous description can be given as follows.
 Q is the state of the Turing machine.
 The tape head is scanning the ith symbol from left.
 A1 A2 ….An is the input tape portion.

This portion is between leftmost and rightmost cell.

Move of Turing machine can be given as-

δ (q, Ai) = (q1,Y,L) that means move left then you will enter in state q 1 , with output Y on
tape A1 A2 ….Ai-1q Ai Ai+1….An - A1 ,A2 ….Ai-2 q1 Ai-1Y Ai+1….An.

21. Is it possible that a Turing machine could be considered as a computer of functions from
integers to integers? If yes, justify your answer.(Dec-04,May-05)
Yes, Turing machines simulate computer of functions from integers to integers. That means it is the
device for computing integer valued functions. In this scheme integers were represented in unary as
blocks of a single character and machine computed by changing the lengths of blocks or by
constructing new blocks on the input tape.
Turing machine can perform operations such as addition, multiplication, subtraction, division of two
integers. Thus it acts as a computing device.

22. Explain the basic Turing machine model and explain in one move. What are the actions take
place in move in Turing machine?(Dec-04,May-05)
In one move there are three cases either the tape head is pointing any intermediate cell or it is
pointing at the first cell or it pointing at the last cell.
Suppose δ (q, Ai)= (q1,Y,L) then

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 9


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


A1 A2 ….Ai-1q Ai Ai+1….An - A1 ,A2 ….Ai-2 q1 Ai-1Y Ai+1….An
If i=1 then moving left to the blank.
A1 A2 ….Ai-1q Ai Ai+1….An - q1 by A2….An
If i=n and Y=B then
A1 A2 ….An-1q An - A1, A2 ….An-2 q1 An-1. Similarly the tape head can be moved to right.

23. What are the two classes of problems that are solved by the Turing machine?
The two classes of problems that can be solved by the Truing machines are as follows.

1. Those problems that have an algorithm


2. Those that are only solved by Turing machine.
24. What is the various representation of TM?

We can describe TM using:


 Instantaneous Description.
 Transition Table.
 Transition Diagram.

25. What do you mean by universal Turing machine? (Dec-05,13)


Universal Turing machine is a type of TM which is capable of doing anything that any
other TM can do. That means universal TM is a TM that imitates any TMT.

26. What are the features of universal turing machine? (May-07)


Following are the features of universal turing machine (UTM)

 Universal Turing machine is a kind of Turing machine can simulate any other turing
machine. In other words, UTM is a single machine used to compute any computable sequence.
 Another interesting feature of UTM is that it has an ability to manipulate an unbounded
amount of data in finite amount of time.

27. What are the applications of Turing machine? (Dec-12)


Turing is machine is used as a model of general purpose computer. Turing machine is used for
solving computational, recursive, and non recursively enumerable problems. Turing machines can
also be used for representing subroutines.

28. List out techniques for Turing machine construction. (Dec -13)
1. Storage in finite control
2. Multiple tracks
3. Checking off symbols
4. Subroutine.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 10


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


29. What are the possibilities of a TM when processing an input string?

TM can accept the string by entering accepting state.

 It can reject the string by entering non-accepting state.


 It can enter an infinite loop so that it never halts.

30. What are the techniques for Turing machine construction?


 Storage in finite control.
 Multiple tracks.
 Checking off symbols.
 Shifting over
 Subroutines.
31. What is the storage in FC?

The Finite control (FC) stores a limited amount of information. The state of the Finite control
represents the state and the second element represents a symbol scanned.

32. Differentiate Multitape and Multitrack machines. (Dec-08)

1. Multiple tracks
A Multitrack Turing machine is an extension of turing machine having n tracks. The n
symbols are at a time under the read/write head. There is only one read/write head in
multi track TM. (Refer figure 4.1)
For example:
# 1 1 1 1 1 $

B B B B 1 1 B ……

B 1 1 1 B B B

Finite
control
Figure 4.1 - Multitrack TM
2. Multi-tape turing machine
The multitape turing machine is a type of Turing machine in which there are more
than one input tapes. Each tape is divided into cells and each can hold any symbol of
finite tape alphabet. The Multitape TM (Refer figure 4.2) is more powerful than the
basic Turing machine. Because finite control reads more than one input tape and more
symbols can be scanned at a time.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 11


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Finite
Control

Input tape 1

….. …..

Figure 4.2 – Input tape 2


Multitape TM ….. …..

33. When is checking off symbols used in TM?

Checking off symbols is useful method when a TM recognizes a language with repeated
strings and also to compare the length of substrings.

34. When is shifting over Used?

A Turing machine can make space on its tape by shifting all nonblank symbols a finite
number of cells to the right. The tape head moves to the right, repeatedly storing the symbols in
the FC and replacing the symbols read from the cells to the left. The TM can then return to the
vacated cells and prints symbols.

35. What is a multi-head TM?

A k-head TM has some k heads. The heads are numbered 1 through k, and move of the
TM depends on the state and on the symbol scanned by each head. In one move, the heads may
each move independently left or right or remain stationary.

36. What is a 2-way infinite tape TM?

In 2-way infinite tape TM, the tape is infinite in both directions. The leftmost square is not
distinguished. Any computation that can be done by 2-way infinite tape can also be done by
standard TM.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 12


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


37. How can a TM used as a transducer?

A TM can be used as a transducer. The most obvious way to do this is to treat the entire
nonblank portion of the initial tape as input, and to treat the entire blank portion of the tape when
the machine halts as output.

38. What is a multi-tape Turing machine? (Dec-03, 14, May-05, 06, 08) (Nov/Dec 2015)

A multi-tape Turing machine (Refer figure 4.3) consists of a finite control with k-tape
heads and k tapes; each tape is infinite in both directions. On a single move depending on the
state of finite control and symbol scanned by each of tape heads, the machine can change state
print a new symbol on each cells scanned by tape head, move each of its tape head independently
one cell to the left or right or remain stationary.

Finite
Control

Input tape 1

….. …..

Input tape 2

….. …..

Figure 4.3 – Multitape TM

39. What is a multidimensional TM?

The device has a finite control , but the tape consists of a k-dimensional array of cells
infinite in all 2k directions, for some fixed k. Depending on the state and symbol scanned , the
device changes state, prints a new symbol and moves its tape-head in one of the 2k directions,
either positively or negatively ,along one of the k-axes.

40. What is halting problem? (April/May 2017)

The halting problem for TMs is: Given any TM M and an input string w, does M halt on
w? This problem is undecidable as there is no algorithm to solve this problem.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 13


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


41. What is the weak-form of Turing thesis?
A Turing Machine can compute anything that can be computed by a general purpose digital
computer.

42. What is the strong-form of Turing thesis?


A Turing Machine can compute anything that can be computed. This is the strong form of
Turing thesis.

43. What are the reasons for a TM not accepting its input?
i) The TM may halt in a non final state.
ii) The TM may enter into an indefinite loop.

44. Construct a Turing machine to compute ‗n mod 2‘ where n is represented in the tape in
unary form consisting of only 0‘s. (May – 11)

The unary number is represented by 0‘s. The turing machine for the language {L= n mod 2} is as
follows.
(0,0,R)
Start
qo q1

(0,0,R)
(Δ, Δ,R)

Halt

45. Design a Turing machine with not more than states that accepts languages a (a+b) * .
Assume ∑ = {a, b}(May-05).

Let Regular expression = a (a+b) *.The corresponding Turing machine will be

(a,a,R)
(b,b,R)

(Δ, Δ,R)
Start (a,a,R)
qo q1 Halt

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 14


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


46. Design a TM for finding 1‘s complement of a given binary number.(Dec-11)
(1,0,R)
(0,1,R)

(Δ, Δ,R)
Start (1,0,R)
qo q1 Halt

(,B,L)

47. Design a TM that accepts the language of odd integers written in binary.[Nov/Dec 2024]

The binary string that ends with 1 is always an odd integer.

(1,1R) (0,0,R)

Start (0,0,R)
qo q1

(Δ, Δ,L) (1,1,R)

Halt

48. Define Power of turing Machine.

 A Turing machine has great computational capabilities and it can be used as a


general mathematical model for modern computers.
 Turing machine can model even recursive enumerable languages.
 Advantages: TM Model all the computable functions as well as the languages for
which the algorithm is possible.

49. What are the Comparison of FM, PDA and TM?

1. This finite machine is of two types – deterministic finite state machine and non
deterministic finite state machine. Both of these DFA and NFA accept regular language
only. Hence both the machines have equal power i.e. DFA = NFA.
2. We have then learnt push down automata again, pushdown automata consists of two
types of models deterministic PDA and non deterministic PDA. The advantage of PDA

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 15


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


over FA is that PDA has a memory and hence PDA has a memory and hence PDA
accepts large class of languages than FA hence PDA has more power than FA. The non
deterministic PDA accepts the languages of context free grammar power of DPDA is less
than NPDA as NPDA accepts a large class of CFL.
3. The class of two stack or n-stack PDA has more power than one stack DPDA or NPDA.
Hence two-stack/ n-stack PDAS are more powerful.
4. Turing machines can be programmed. Hence TM accepts very large class of languages.
Hence therefore is the most powerful computational model. TM > PDA > FM.
TM accepts regular and non-regular language; context sensitive language as well.

50. What are the Features of turing machine?


Alan turing is father of such a model which has computing capacity of general purpose
computer. Hence this model is used popularly known as turing machine. This machine has
following features.
1. It has external memory which remembers arbitrarily long sequence of input.
2. It has unlimited memory capability.
3. The model has a facility by which the input at left or right on the tape can be read easily.
4. The machine can produce certain output based on its input. Sometimes it may be required
that the same input has to be used to generate the output. So in this machine the
distinction between input and output has been removed. This common set of alphabets
can be used for the turing machine.

51. What are the differences between a finite automata and a Turing machine?
(May/June 2016)
 A finite state machine is just a set of states and transitions. The only memory it has is
what state it is in. Thus, the number of memory states is finite.
 A Turing machine is a finite state machine plus a tape memory. Each transition may be
accompanied by an operation on the tape (move, read, write). Its total possible
configurations is arbitrarily large, regardless of the size of the program; it expands
towards infinity.
 In between the two is a stack machine, which is like a Turing machine except that the
operations are limited to pushing and popping onto the stack.
 A FSM can recognize only regular expressions. A stack machine can recognize context-
free languages. A Turing machine can recognize all recursively enumerable languages.
This is called the Chomsky hierarchy.

52. Define the language recognized by any turing machine.


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

L(M)={W/W in Σ*,q0,W * α1,p α2 }


M
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 16
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

53. Draw Turing machine to compute double the value of an integer. Nov/Dec2021

(1,X,R) (1,1,L)
(1,1,R)

Start (B,B,L) (X,1,R) q2


qo q1

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

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 17


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


PART-B

1. Explain the normal form of CFG.


The two Normal forms are
i. Chomsky Normal Form (CNF)
ii. Greibach Normal Form (GNF)
Convert a CFG to Chomsky normal form
Example 1
Begin with the grammar
SASB/ε
AaAS/a
BSbS/A/bb
(a) Are there any useless symbols? Eliminate them
(b) Eliminate ε productions
(c) Eliminate unit productions
(d) Put the grammar into Chomsky normal form. (Nov/Dec 2015)
Solution
a.Are there any useless symbols? Eliminate them
To see the useless symbols, we have to find generating and reachable symbols.
Generating symbols
 Since S  Є, S is generating.
 A  a, so A generates ‗a‘. A is generating.
 B  A, A is generating so B is also generating.
 Ε, a, b is generating.
Generating symbols={S,A,B,a,b,ε}
Reachable symbols
 Starting symbol ‗S‘ is always reachable.
 S  ASB/ Є, so A, S, B, Є are also reachable.
 A  a, B  bb, so {a, b} are also reachable symbols.
Reachable symbols={S,A,B,a,b,ε}
So all the non terminals and terminals are generating and reachable symbols. So the
above CFG does not have the useless symbols.
(a) Eliminate epsilon productions:
Now we have to find the nullable symbols. The CFG grammar is,
SASB/ε
AaAS/a
BSbS/A/bb
Nullable symbols
Sε, so ‗S‘ is nullable symbol. So eliminate ‗S‘ nonterminal.
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b
So after eliminating ε production, the CFG grammar is,
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 18


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(b) Eliminate unit production:
To find the unit production, we have to find the unit pair for the following grammar,
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b
By basis (S,S) (A,A) (B,B) is unit pair.
By introduction the unit pair is,
 (S,S) and there is no unit production for S.
 (A,A) and there is no unit production for A.
 (B,B) and BA is a unit production, so (B,A) is unit pair.
 (B,A) and A has no unit production.
So the unit pairs of the grammar is,
(S,S)(A,A)(B,B)(B,A)
Unit pair Production
(S,S) SASB/AB
(A,A) AaAS/aA/a
(B,B) BabS/Sb/bS/b/bb
(B,A) BaAS/aA/a
So the CEG grammar after eliminating unit production is as follow,
SASB/AB
AaAS/aA/a
BSbS/Sb/bS/b/aAS/aA/a/bb
(c) Find CNF for the above grammar:
The CNF grammar should have the production of the form ABC, Aa.
Converting the grammar to CNF:
The grammar has already productions in CNF form and the are,
SAB
Aa
Ba/b
Now we have to introduce new variables as,
C1AS, So AC2C1
C2a, So AC2C1/C2 A
C3C4S, So BSC3
C4B, So BSC4/C4S/C4C4
C5SB, So SAC5
So after introducing new non terminals, the CNF grammar is as follows,
SASB/AB
AaAS/aA/a
BSbS/Sb/bS/b/aAS/aA/a/bb
CNF grammer: SAC5/AB
AC2C1/C2 A/a
BSC3/SC4/C4S/C4C4/C2C1/C2A/b/a
C1AS
C2a
C3C4S
C4b C5SB

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 19


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Example 2
Find the CNF for the following grammar,
SaB/bA
AaS/bAA/a
BbS/aBB/b (Nov/Dec 2005) (Nov/Dec 2024)
How a CFG for L is converted into CNF accepting the same language? Convert the
following CFG into CFG in CNF
SbA/aB AbAA/aS/a BaBB/bS/b (Nov/dec 2020)
Solution 2
Eliminate the useless symbols:
 a, b generates itself
 Aa, Bb So {A, B} is generating.
 SbA, Since b, A is generating. ‗S‘ is also generating.
Generating symbol={S, A, B, a, b}
 S is also reachable.
 SaB / bA, So a, b, A, B is also the reachable symbol.
Reachable symbol={S,a,b,A,B}
Since all the variables and terminals are both generating and reachable, the grammar does
not have useless symbols.
Eliminate ε production:
There is no ε production, such that there is no nullable symbol in the grammar.
Eliminate unit production:
The above grammar has no unit production and no unit pair other than (S,S) (A,A) (B,B)
CNF Grammar:
SC1B/C2A
AC1S/C2C3/a
BC2S/C1C4/b
C1a
C2b
C3AA
C4BB
Example 3
Find the Chomsky normal form equivalent to the following grammar,
SaAbB
AaA/a
BbB/b (Dec 2003)(May 2007)
Obtain a grammar in chomsky Normal Form(CNF) equivalent to the grammar G with the
productions P given.
SaAbB
AaA/a
BbB/b (Nov/Dec 2016)
Solution 3
Eliminate useless symbols
 a,b generates itself, So a,b are generating symbol.
 Aa,A generates a, So ‗A‘ is generating symbol.
 Bb,B generates ‗B‘, So ‗B‘ is also generating symbol.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 20


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


 SaAbB, So S is also generating symbol.
Generating symbol={S,A,B,a,b}
 S is always reachable
 SaAbB, So a,A,b,B are reachable.
Reachable symbol={S,A,B,a,b}
Since all the variables and terminals are both generating and reachable, the grammar does
not have useless symbols.
Eliminate ε-production
There is no nullable symbol and ε-production.
Eliminate Unit production
There is no unit production and the grammar has only the (S,S) (A,A) (B,B) as unit pair b
basis.
CNF Grammar:
SC1C3
AC1A/a
BC2B/b
C1a
C2b
C3AC4
C4C2B

Example 4
Find the CNF grammar for the following grammar,
SAB/aB
Aaab/ε
BbbA (May 2009) (10)
Solution 4
Eliminate useless symbols
 a,b,ε generates itself
 Aε, So ‗A‘ is generating
 BbbA, So ‗B‘ is also generating
 SAB, So ‗S‘ is also generating

Generating Symbol = { S,A,B,a,b,ε }


 S is always reachable.
 SAB/aB, So A,B,a is also reachable.
 Aaab, So a,b is also reachable
 Aε, So ε is also reachable.
Reachable symbols= {S,A,B,a,b,ε }
Since all the variables and terminals are both generating and reachable, the
grammar does not have the useless symbols.
Eliminate ε production
Aε, So A is nullable symbol.
Nullable symbol={A}
The grammar after eliminating nullable is ,

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 21


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


SAB/B/aB
Aaab
BbbA/bb
Eliminating Unit production
 (S,S) (A,A) (B,B) are unit pair.
 (S,S) and SB, So (S,B) is unit pair.
 (S,B) and B has no unit production.
 (A,A) and A has no unit production.
 (B,B) and B has no unit production.
Unit pairs = (S,S) (S,B) (A,A) (B,B)
Unit pair Production
(S,S) SAB/aB
(S,B) SbbA/bb
(A,A) Aaab
(B,B) BbbA/bb
The grammar after eliminating unit production
SAB/aB/bbA/bb
Aaab
BbbA/bb
CNF Grammar:
S AB/C1B/C1D1/C2C2
AC1D2
B C1D1/C2C2
C1a
C2b
D1C2A
D2C1C2

Example 5
Find the CNF for the following grammar,
Sa/abSb/aAb
AbS/aAAb
Solution 5
Eliminate useless symbols:
 a,b generates itself
 Sa, So ‗S‘ is generating
 AbS, So ‗A‘ is also generating.
Generating symbols:
 S is reachable
 SaAb, So a,b,A is also reachable.
Reachable symbols={S,A,a,b}
Since all the variables and terminals are generating and reachable, the grammar
does not have reachable symbols.
Eliminating ε- production:
The grammar does not have nullable symbol and ε-production.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 22


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Eliminate Unit production
The grammar does not have unit production and the only unit pair is (S,S) (A,A)
CNF Grammar:
SC1D1/C1D3/a
AC1D4/C2S
C1a
C2b
D1C2D2
D2SC2
D3A C2
D4A D3

Example 6
Convert the following grammar into CNF
ScBA, SA, AcB, AAbbS, Baaa (Nov/Dec 2012)
Solution 6
ScBA | A,
AcB | AbbS,
Baaa
a) Are there any useless symbols? Eliminate them.
To see the useless symbols, we have to find generating and reachable symbols.
S A
S caaa
Acaaa
Baaa
Generating symbols = { S, A, B }
b) Eliminate є – Production
There is no nullable symbol and є-Production.
c) Eliminate Unit Production
ScBA | A,
AcB | AbbS,
Baaa
The above grammar after eliminating unit production.
ScBA | cB | AbbS,
AcB | AbbS,
Baaa
d) Find CNF for the above grammar
SC1C2|C1C3|C5 S
AC1C3|C5S
Baaa
C1c
C2BA
C3B
C4Ab
C5bC4

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 23


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Example 7
Find a grammar equivalent to the following grammar
SAB/CA
Aa
BBC/AB
CaB/b
With no useless symbols.
Solution 7
To eliminate the useless symbols, we have to find the generating and reachable symbols.
Generating symbols ={a, b, A, C, S}
Since SCA, C and A are generating, S is also generating. So remove B, and then new
grammar is,
SCA
Aa
Cb
Now find the reachable symbols.
Reachable symbols={S, A, C, a, b}
Now the grammar with no useless symbols is,
SCA
Aa
Cb

Example 8
What is the purpose of normalization? Construct the CNF and GNF for the following
grammar and explain the steps.
(10)
SaAa | bBb | Є
AC | a
BC | b
CCDE | Є
DA | B | ab (May/June 2016)
Solution 8
To eliminate the useless symbols, we have to find the generating and reachable symbols.
Generating symbols ={a, b, A, B, C, D, E }
Here D and C is a useless symbol. Start Symbol S is not generating D and C.
SaAa | bBb | Є
A a
Bb
Eliminate the Є production
SaAa | bBb | Є
A a
Bb
Eliminate SЄ
SaAa | bBb

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 24


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


A a
Bb
Eliminate Unit Production
The grammar does not have unit production and the only unit pair is (S,S) (A,A)
(B,B)
Find CNF for the above grammar
Aa
SAAA

C1AA
SAC1

Bb
SBBB
C2BB
SBC2

SAC1 | BC2 C1AA


Aa C2BB
Bb
GNF
SAC1
C1AA
SBC2
C2BB
Aa
Bb
Replace the variables S, A and B as A1 , A2 and A3 such that
S = A1
A = A2
B = A3
Now the grammar after replacing the variable becomes,
A1A2C1
C1A2 A2
A1A3C2
C2A3 A3
A2a
A3b
(i) A1A2C2
(Here i=1, j=2 and i<j(1<2) So leave the production as such)
Since i<j(1<2), the production remains the same,
A1A2C2 ......(1)
(ii) C1A2A2
(Here i=1, j=2 and i<j(1<2) So leave the production as such)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 25


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Since i<j(1<2), the production remains the same,
C1A2 A2 ......(2)
(iii) A1A3 C2
(Here i=1, j=3 and i<j(1<3) So leave the production as such)
Since i<j(1<3), the production remains the same,
A1A3 C2 -----------(3)
(iv) C2A3 A2
(Here i=2, j=3 and i<j(2<3) So leave the production as such)
Since i<j(1<3), the production remains the same,
C2A3 A2 -------------(4)
Apply the terminalsA2a and A3b
A1aC1
C1aA2
A1bC2
C2bA3
A2a
A3b
Example 9
1. Given the CFG G, find CFG G‘ in CNF generating the language L(G) – { ˆ}
S  AACD
AaAb | ˆ
CaC | a
D aDa | bDb | ˆ
Solution 9
Eliminate the useless symbols
To eliminate the useless symbols, we have to find the generating and reachable symbols.
Generating symbols ={a, b, ˆ, A, C, D }
Since all the variables and terminals are generating and reachable, the grammar does not
have useless symbols.
Eliminate the Є production
The grammar does not have Є production.
Eliminate Unit Production
The grammar does not have unit production.
S  AACD
AaAb | ˆ
CaC | a
D aDa | bDb | ˆ
Find CNF for the above grammar
S  AACD
LET
C1  AA C2 CD C3  a C4  b
S  C1 C2
A  C3 A C4 C C3C | a D C3 D C3 | C4D C4|ˆ
LET
C5  C3A C6  C3 D C7  C4D
A C5 C4

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 26


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


C  C3C | a
D  C6 C3 | C7 C4|ˆ
CNF GRAMMAR
S  C1 C2
A C5 C4
C  C3C | a
D  C6 C3 | C7 C4|ˆ
C1  AA C2 CD C3  a C4  b
C5  C3A C6  C3 D C7  C4D

Greibach Normal Form (GNF)


Example 10
Convert the following grammar into GNF
SAA/0
ASS/1
Solution 10
Step 1: The grammar definition is
G = (V, T, P, S)
G = ({A, S}, {0, 1}, P, S)
Where the production P consists of,
SAA/0
ASS/1
Step 2: The given grammar is Chomsky normal form such that each production is of the
form AB or Aa
So the given grammar is in CNF
Step 3: Replace the variables S and A as A1 and A2 such that
S = A1
A = A2
Now the grammar after replacing the variable becomes,
A1A2 A2/0
A2A1 A1/1
Step 4: Now process each production for each variable.
(v) A1A2A2/0
(Here i=1, j=2 and i<j(1<2) So leave the production as such)
Since i<j(1<2), the production remains the same,

A1A2A2/0 ......(1)

(vi) A2A1 A1/1


Here i=2,j=1 and i>j So apply rule 1 to replace the production body of A1 to A2.
So the production of A2 becomes,
A2A1A1/1
Becomes,
A2A2A2A1/0A1/1
...........(2)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 27


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(iii) Now consider A2A2A2A1/0A1/1
Here i=j such that i=2, j=2, So apply rule 2 to introduce new variable B2 as
follows,
B2A2A1/A2A1B2
A20A1/1/0A1B2/1B2 .........(3)
(iv) Now apply the production A2 in (3) to (1) So the production becomes,
A1 A2A2/0
Becomes,
A10A1A2/1A2/0A1B2 A2/1B2A2/0 .....(4)
Apply the production A2 in (3) to B2 in (3)
B2A2 A1/A2A1B2
Becomes,
B20A1 A1/1A1/0A1B2A1/1B2A1/ 0A1A1B2/1A1B2/0A1B2 A1B2/1B2 A1B2
After applying all the rules of GNF, the resulting production of the variables
A1,A2,B2 results in the required form of GNF and the resulting grammar is ,
GNF Grammar
A10A1A2/1A2/0A1B2A2/1B2A2/0
A20A1/1/0A1B2/1B2
B20A1A1/1A1/0A1B2A1/1B2A1/ 0A1A1B2/1A1B2/0A1B2A1B2/1B2A1B2
Example 11
Convert the following grammar to GNF
SAB
ABS/b
BSA/a
Solution 11
Step 1: The grammar definition is,
G =({S,A,B},{a,b}, P,S)
Where the production P consists of
SAB
ABS/b
BSA/a
Step 2: The above grammar is in Chomsky normal form. Introduce new variables A1, A2,
A3
Step 3: Replace S = A1, A = A2, B = A3, So the grammar becomes,
A1A2A3
A2A3A1/b
A3A1A2/a
Step 4: Process each production of the grammar
(i) A1A2A3
(Here i=1,j=2 and i<j(1<2) So leave the production as such)
Since i<j (1<2), the production remains the same,
A1A2A3 .......(1)
(ii) A2A3A1/b
(Here i=2,j=3 and i<j(2<3) So leave the production as such)
Since i<j (2<3), the production remains the same,
A2A3A1/b ........(2)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 28


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(iii) A3A1A2/a
(Here i=3,j=1 and i>j(3>1)
So apply rule 1 to replace the production body of A1 to A3, So the production of A3
becomes,
A3A1A2/a
Becomes
A3A2A3A2/a
Now again i=3,j=2 and i>j(3>2) So apply rule 1 to replace the production body of A2
to A3, So the production of A3 becomes,
A3A2A3A2/a
Becomes,
A3A3A1A3A2/bA3 A2/a
Here i=j such that i=3,j=3 So apply rule 2 to introduce new variable B 3 as,
B3A1 A3 A2/A1 A3 A2B3 ……….………………….(3)
A3bA3A2/a/bA3 A2B3/aB3 ………………….…….(4)
(iv) Now apply the production (4) to (2) as follows,
A2 A3A1/b
Becomes,
` A2bA3A2A1/aA1/bA3 A2B3A1/aB3 A1/b ……………………….….(5)
Now apply the production (5) to (1) as follows,
A1A2A3
Becomes,
A1bA3A2A1A3/aA1 A3/bA3 A2
B3A1A3/aB3A1A3/bA3 ………………..(6)
Now apply the production (6) to (3) as follows
B3A1 A3 A2/A1 A3 A2B3
Becomes,
B3b A3A2A1A3 A3A2 | aA1 A3A3 A2 | bA3 A2B3 A1 A3A3 A2 | aB3A1A3 A3A2|
bA3A3A2 | bA3A2 A1 A3A3 A2B3 | aA1 A3A3 A2B3 | bA3A2B3 A1A3 A3 A2B3 |
aB3A1A3A3A2B3 | bA3 A3 A2B3
Example 12
Convert the following grammar G into Greibach Normal Form (GNF)
S  XA | BB
B b |SB
Xb
A a

Solution 12
Step 1: The grammar definition is,
G =({S,A,B,X},{a,b}, P,S)
Where the production P consists of
S  XA | BB
B b |SB
Xb
A a

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 29


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Step 2: The above grammar is in Chomsky normal form. Introduce new variables A1, A2,
A3, A4
Step 3: Replace S = A1, B = A2, X = A3, A = A4 So the grammar becomes,
A1A3A4
A2A1A2/b
A3b
A4a
Step 4: Process each production of the grammar
(v) A1A3A4
(Here i=1,j=3 and i<j(1<3) So leave the production as such)
Since i<j (1<3), the production remains the same,
A1A3 A4 ......(1)

(vi) A2A1A2/b
(Here i=2,j=1 and i>j(2>1)
So apply rule 1 to replace the production body of A1 to A2
A2A1A2/b
Becomes
A2 A3A4A2/b
Since i<j (2<3), the production remains the same,
A2 A3 A4A2/b ........(2)
(vii) Apply
A3b in (1) & (2)
A1A3A4
Becomes
A1bA4
A2 A3A4A2/b
Becomes
A2 bA4A2/b
GNF Grammar
A1bA4
A2 bA4A2/b
A4a

13. Construct a CFG for the regular expression (011+1)(01).(May/June 2016)(6)


Solution: L = {01101, 101}
SA
A0A1 | 1A | Є

14. Define derivation tree. Explain its uses with an example.(Nov/Dec 2016)
Derivation Tree
Let G = (V, T, P, S) be the context free grammar. Beginning with the start symbol, we
derive terminal strings by repeatedly replacing a variable by the body of some
production with that variable in the head.
If Aβ is a production of P and a and b are any strings in (VUT)* then α A γ  α β γ

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 30


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Example
Find a derivation tree of a*b+a*b given that a*b+a*b is in L(G) where G is given by
SS+S/S*S/a/b (May/June 2007)
Solution
S  S+S
 S*S+S (Ss*S)
 a*S+S (Sa)
 a*b+S (Sab)
 a*b+a*S (Sa)
 a*b+a*b (Sb)

15. Construct a CFG to generate even add set of palindromes over alphabet {a,b}. Nov/Dec
2017

G = ({S}, {a, b}, P, S )


Production { SaSa , SbSb, Sa, Sb, Sє } which is in palindrome.

16. Generate CFG for the language L = { 0i1j0k | i>j+k}. Nov/Dec 2017

S 0S0/1P0
S00/10
P10

17. Find an equivalent grammar in CNF for the grammar: Nov/Dec 2017
SbA/aB
AbbA/aS/a
BaBB/bS/b
Step 1: To eliminate the useless symbols, we have to find the generating and reachable
symbols.
Generating symbols ={a, b, S, A, B, }
Here no useless symbol.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 31


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


SbA/aB
AbbA/aS/a
BaBB/bS/b
Step 2: Eliminate the Є production
Here no Є production
Step 3: Eliminate Unit Production
The grammar does not have unit production
SbA/aB
AbAA/aS/a
BaBB/bS/b
Find CNF for the above grammar
SbA
C1b
SC1 A

SaB
C2a
SC2 B

AbAA
A C1 AA

C3AA
A C1 C3

AaS
AC2 S
A
AaC1 C3
BaBB
B C2 BB

C4BB
ABbS
C2 C4

B C1S
Bb
A
CNFCare
C
1 3

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 32


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


C1b
SC1 A
C2a
SC2 B
C3AA
A C1 C3
C3AA
A C1 C3
Aa
C4BB
A C2 C4
B C1S
Bb

18. Eliminate the unit production of the following grammar: Nov/Dec 2017
SA/bb
AB/b
BS/a
After Eliminate unit production
Sa/b/bb
Aa/b/bb
Bbb/a

19. Explain simplification of CFG with examples. April/May 2018


simplification of CFG:
Example
Begin with the grammar
SASB/ε
AaAS/a
BSbS/A/bb
(e) Are there any useless symbols? Eliminate them
(f) Eliminate ε productions
(g) Eliminate unit productions
Solution
(d) Are there any useless symbols? Eliminate them
To see the useless symbols, we have to find generating and reachable symbols.
Generating symbols
 Since S  Є, S is generating.
 A  a, so A generates ‗a‘. A is generating.
 B  A, A is generating so B is also generating.
 Ε, a, b is generating.
Generating symbols={S,A,B,a,b,ε}
Reachable symbols
 Starting symbol ‗S‘ is always reachable.
 S  ASB/ Є, so A, S, B, Є are also reachable.
 A  a, B  bb, so {a, b} are also reachable symbols.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 33


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Reachable symbols={S,A,B,a,b,ε}
So all the non terminals and terminals are generating and reachable symbols. So the
above CFG does not have the useless symbols.
(e) Eliminate epsilon productions:
Now we have to find the nullable symbols. The CFG grammar is,
SASB/ε
AaAS/a
BSbS/A/bb
Nullable symbols
Sε, so ‗S‘ is nullable symbol. So eliminate ‗S‘ nonterminal.
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b
So after eliminating ε production, the CFG grammar is,
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b
(f) Eliminate unit production:
To find the unit production, we have to find the unit pair for the following grammar,
SASB/AB
AaAS/aA/a
BSbS/A/bb/Sb/bS/b
By basis (S,S) (A,A) (B,B) is unit pair.
By introduction the unit pair is,
 (S,S) and there is no unit production for S.
 (A,A) and there is no unit production for A.
 (B,B) and BA is a unit production, so (B,A) is unit pair.
 (B,A) and A has no unit production.
So the unit pairs of the grammar is,
(S,S)(A,A)(B,B)(B,A)
Unit pair Production
(S,S) SASB/AB
(A,A) AaAS/aA/a
(B,B) BabS/Sb/bS/b/bb
(B,A) BaAS/aA/a

So the CEG grammar after eliminating unit production is as follow,


SASB/AB
AaAS/aA/a
BSbS/Sb/bS/b/aAS/aA/a/bb

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 34


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


20. State and prove the pumping lemma for CFL. (Nov/Dec 2012)
State and explain the pumping lemma for CFG.(Nov/Dec 2016) Nov/Dec 2017
Explain pumping lemma for Context Free Languages with example. April/May 2018

Theorem:
Let L be a CFL. Then there exists a constant n such that if z is any string in L such that |z| is at
least n, then we can write z = uvwxy, subject to the following conditions:
1. |vwx| ≤ n. that is, the middle portion is not too long.
2. vx ≠ Є. Suppose v and x are the pieces to be ―pumped‖, this condition says that at least
one of the strings we pump must not be empty.
3. For all i ≥0, uviwxiy is in L. that is, the two strings v and x may be ―pumped‖ any number
of times, including 0, and the resulting string will still be a member of L.
Proof:
 The first step is to find a Chomsky Normal Form grammar G for L.
 Let G = (V, T, P, S) such that L(G) =L-{ε}. There are M variable in G.
 Choose n = 2 M. suppose z in L is of length atleast n.
 By theorem, any parse tree whose longest path is of length M or less must have a yield of
length 2M-1 = n/2 or less. Such a parse tree cannot have yield z, because z is too long.
 Thus any parse tree with yield z has a path of length atleast M+1. But such a path has
atleast M+2 vertices.
 Thus there must be two vertices v1 and v2 on the path. It is possible to divide the tree as in
below figure 4.4; string w is the yield of the subtree whose root is Aj

 For the yield w, at Aj string v and x are the strings to the left and right. There will be no
unit productions in this grammar, so v and x could not both be ε, but one could be. Then
at Ai, string u and y are to its left and right

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 35


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Figure 4.5 – Pumping strings v and x zero times

 Suppose Ai=Aj=A construct a new parse tree figure 4.6 replacing the root Ai and Aj by
A, which has yield w and the resultant tree is given in figure(b), which has yield uwy and
corresponds to the case i=0 in the pattern of strings uvi w xi y.

Figure 4.6 – Pumping strings twice

 The yield of this tree is uv2w x2 y. Likewise we can expand the tree for any number of
times. Thus there are parse trees in G for all strings of the form uvi w xi y.
 Then |vwx| ≤ n, for this choose Ai to be the bottom of the tree i.e., K-i ≤ M. Thus the
longest path in the subtree rooted at Ai is no greater than M+1. According to the theorem,
the subtree rooted at Ai has a yield whose length is not greater than 2 M =n.
 Thus the pumping lemma is proved.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 36


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


21. State the Pumping lemma for CFL and Show that the language L={a n bncn | n≥1} is not
a CFL.(6) (Nov/Dec 2015)
Solution:
a. Assume that the language ‗L‘ is a context free language
b. Let us take the string Z= anbncn
c. The length of the string, |Z| = n+n+n=3n
|Z|≥ n==>3n >n
So,the string Z can be break into five strings as Z=uvwxy
d. Break the string Z as Z=uvwxy
Let us make the assumption that
u = an
vwx = bn
vx = bn-m
y = cn
Now check
Z = uvwxy = anbncn
So our assumption is correct. The two conditions are,
i. |vwx| ≤ n
|bn|≤ n → n ≤ n
ii. |vx| ≥ 1 → |bn-m| ≠ ≥ 1 → n-m ≥ 1
(Or)
vx ≠ ε => bn-m ≠ ε
So the conditions are satisfied.
iii. Since the both the condition are true, for all i ≥ 0, the string uv iwxiy is
also in ‗L‘.
Z = uviwxiy
= uvvi-1wxxi-1y
= anbn(bn-m)i-1cn
Z = anbn(bn-m)i-1cn
Put i=0
Z = anbn(bn-m)i-1cn
Z = anbn(bn-m)0-1cn
Z = anbn(bm-n)cn
Z = an bm cn not in L
Put i=1
Z = anbn(bn-m)i-1cn
Z = anbn(bn-m) 1-1cn
Z = anbncn is in L
Put i=2
Z = anbn(bn-m)i-1cn
Z = anbn(bn-m)2-1cn
Z = an b2n-mcn ≠ L
Since we lead to a contradiction that for the value of i=0,2 the string does not belong to
the language. So the language L = {anbncn /n ≥ 0} is not a context free language.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 37


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


n n n n
22. Show that the language L = { a b c d /n ≥ 0} is not a context free language.
Solution:
a. Assume that the language ‗L‘ is a context free language
b. Let us take the string Z= anbncndn
c. The length of the string, |Z| = n+n+n+n = 4n
|Z| ≥ n ==> 4n > n
So, the string Z can be break into five strings as Z= uvwxy

d.Break the string Z as Z= uvwxy


Let us make the assumption that
u = an
vwx = bn
vx = bn-m
y = cndn
Now check
Z = uvwxy = anbncndn
So our assumption is correct. The two conditions are,
i. |vwx| ≤ n
|bn|≤ n → n ≤ n

ii. |vx| ≥ 1 → |bn-m| ≥ 1 → n-m ≥ 1


(Or)
vx ≠ ε => bn-m ≠ ε
iii. Since the both the conditions are true, for all i ≥ 0,
the string uviwxiy is also in ‗L‘.
Z = uviwxiy
= uvvi-1wxxi-1y
= anbn(bn-m)i-1cndn
Z = anbn(bn-m)i-1cndn
Put i=0
Z = anbn(bn-m)i-1cndn
Z = anbn(bn-m)0-1cndn
Z = anbn(bm-n)cndn
Z = anbn(bm-n) cndn
Z= anbm cndn ≠ L
Put i=1
Z = anbn(bn-m)i-1cndn
Z = anbn(bn-m)1-1cndn
Z = anbncndn = L
Put i=2
Z = anbn(bn-m)i-1cndn
Z = anbn(bn-m)2-1cndn
Z = an b2n-mcndn≠ L
Since we lead to a contradiction that for the value of i=0,2 the string does not belong to
the language. So the language L = {anbncndn /n ≥ 0} is not a context free language.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 38


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

23. Show that the language L = { 0n /n = i2 and n ≥ 0 } is not a context free language.
Solution:
a. Assume that the language ‗L‘ is a context free language
b. Let us take the string Z = 0p where p=i2
c. The length of the string, |Z|= |0p| = p
|Z| ≥ i ==> i2 ≥i
So, the string Z can be break into five strings as Z= uvwxy
d. Break the string Z as Z= uvwxy
Let us make the assumption that
u = 0q
vwx = 0r
vx = 0s
y = 0p-(q+r)
Now check
Z = uvwxy = 0q0r0p-(q+r)0p
So our assumption is correct. The two conditions are,
i. |vwx| ≤ n
|0r|≤ p => r ≤ p
ii. |vx| ≥ 1 =>|0s| ≥ 1 → s ≥ 1
(Or)
vx ≠ ε => 0s ≠ ε
iii. Since the both the conditions are true, for all i ≥ 0,
the string uviwxiy is also in ‗L‘.
Z = uviwxiy
= uvvi-1wxxi-1y
= uvwx(vx) i-1y
= 0q0r (0s)i-10p-(q+r)
Z = 0p (0s)i-1
Put i=0
Z = 0p (0s)i-1
Z = 0p (0s)0-1
Z = 0p-s ≠ L
Put i=1
Z = 0p (0s)1-1
Z =0p (0s)0
Z = 0p = L
Put i=2
Z =0p (0s)2-1
Z = 0p (0s)1
Z = 0p (0s)
Z= 0P+S ≠ L
Since we lead to a contradiction that for the value of i=0,2 the string does not belong to
the language. So the language L = { 0p/ i ≥ 1 }is not a context free language.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 39


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

24. State pumping Lemma for CFL. Use pumping lemma to show that the language
L = { aibjck | i<j<k} is not a CFL. (8)
(May/June 2016)
Pumping Lemma for CFL
Let L be any CFL. Then there is a constant n, depending only on L, such that if z is any string in
L and
|z| > = n, then z = uvwxy such that:
(i) |vx| ≥ 1
(ii) |vwx| ≤ n and
(iii) For all i ≥ 0 uvi wxi y is in L.
L = {aibjck | i<j<k} - Steps
a. Assume that the language ‗L‘ is a context free language
b. Let us take the string Z = aibjck
c. The length of the string, |Z| = n+n+n = 3n
|Z| ≥ n  3n ≥ n
So, the string Z can be break into five strings as Z= uvwxy

d. Break the string Z as Z= uvwxy


Let us make the assumption that
u = ai
vwx = bj
vx = bj-m
y = ck
Now check
Z = uvwxy = aibjck
So our assumption is correct. The two conditions are,
i. |vwx| ≤ n
|bj|≤ n → j ≤ n

ii. |vx| ≥ 1 → |bj-m| ≥ 1 → j-m ≥ 1


(Or)
vx ≠ ε => bj-m ≠ ε
iii. Since the both the conditions are true, for all i ≥ 0, the string uv iwxiy is also in ‗L‘.
Z = uviwxiy
= uvvi-1wxxi-1y
= aibj(bj-m)i-1ck
Z = aibj(bj-m)i-1ck
Put i=0
Z = aibj(bj-m)i-1ck
Z = aibj(bj-m)0-1ck
Z = aibj(bj-n)ck
Z = aibj(bj-n) ck
Z= aibj ck ≠ L
Put i=1
Z = aibj(bj-m)i-1ck

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 40


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Z = a b (bj-m)1-1ck
i j

Z = aibjck = L
Put i=2
Z = aibj(bj-m)i-1ck
Z = aibj(bj-m)2-1ck
Z = ai b2j-mck ≠ L
Since we lead to a contradiction that for the value of i=0,2 the string does not belong to
the language. So the language L = {aibjck /n ≥ 0} is not a context free language.

25. Explain about Basic Model of Turing machine.


The Turing machine can be modeled with the help of following representation.
1. Figure 4.7 The input tape having infinite number of cells, each cell containing one input
symbol, and thus the input string can be placed on a tape. The empty tape is filled by
blank characters.

….. a b c ∆ ∆ ∆ ∆ ∆ ∆ …..
Input tape
Figure 4.7 - input tape

2. Fig 4.8 - Turing machine The finite control and the tape head which is responsible for
reading the current input symbol. The tape head can move to left to right.
3. A finite set of states through which machine has to undergo.
….. ∆ ∆ a b A A B b a ∆ ∆ ∆ …..

Finite
control

Fig 4.8 - Turing machine


4. Finite set of symbols called external symbols which are used in building the logic of
turing machine.

26. Explain the programming techniques for Turing Machine construction. (Nov/ Dec-12)
(May/June-13) (Nov/Dec 2015) (Or) Explain the variations of Turing machines.
(May/June 2016)
Discuss the various techniques for turing machine construction.(Nov/Dec 2016)
Explain techniques for Turing machine construction. (Nov/Dec 2017)
Elaborate on programming techniques for Turing machine construction. April/May 2018

Techniques for Turing machine construction


Construction of turing machine is a process of writing out the complete set of states and
next move function. This is a totally conceptual phenomenon. The turing machine can be
designed with the help of some conceptual tools. Let us discuss some of these tools.
1. Storage in the State

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 41


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


The model of Turing machine has a finite control. This finite control can be used to hold
some amount of information. The finite automata store the information in pair of elements
such as the current state and the current symbol pointed by the tape head. This is just a
conceptual arrangement.
For example – The function δ can be written as follows.
δ([q0,0])([ q1,1], ∆ ,R)
q

a b c

Track1 B B B X B -
Track2 B B B Y B - ……
Track3 B B B Z B -

Figure 4.9 – Storage in the state


This means that if finite control shows the initial state is q 0 and stores the current symbol 0 if
it reads the symbol 1 then the machine goes to next state q 1 replace that 1 by ∆ and moves to
right. This helps in building the transition graph of the language.

Example:
Consider a Turing machine M that looks at the first input symbol, records it in its finite
control, and checks that the symbol does not appear elsewhere on its input. Thus M accepts
the language 01* + 10*.
(1,1,R)

[q1,0]
(0,0,R) (B,B,R)

start
[q0,B] [q1,B]

(1,1,R)
[q1,1] (B,B,R)

Let M=(Q,{0,1},{0,1,B},δ,{ q0,B},B,F)


Where,
Q = {q0, q1}X (0,1,B)
= ([ q0 , 0], [ q0 , 1], [ q0 , B], [ q1 , 1], [ q1 , B])
F = {[q1, B]}

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 42


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


We define δ as follows
(i) (a) δ([ q0 , B],0)=( [ q1 , 0],1,R)
(b) δ([ q0 , B],1)=( [ q1 , 1],1,R)
(i.e.,) q0 is initial state and M moves right. The first components of M‘s state
become q1, and the first symbol seen is stored in the second component.

(ii) (a) δ([ q1 , 0],0)=( [ q1 , 0],1,R)


(b) δ([ q1 , 1],1)=( [ q1 , 1],0,R)

If M has a 0 stored and sees a 1 or vice versa, the M continues to move to the
right.
(iii) (a) δ([ q1 , 0],B)=( [ q1 , B],1,L)
(b) δ([ q1 , 1],B)=( [ q1 , B],0,L)
M enters the final state [q1, B] if it reaches a blank symbol without having first
uncounted a second copy of the leftmost symbol.
For state [q1, 0] and symbol 0 (or) for state [q1, 1] and symbol 1, δ is not defined.
Input string: 1000

δ ([q0,B],0)= ([q1,0],0,R)

δ ([q0,B],1)= ([q1,1],1,R)

δ ([q1,0],1)= ([q1,0],1,R)

δ ([q1,0],B)= ([q1,B],B,R)

δ ([q1,1],0)= ([q1,1],0,R)

δ ([q1,1],B)= ([q1,B],B,R)

2. Multiple tracks
If the input tape is divided into multiple tracks then the input tape will be as
follows. (Refer figure 4.10)
The input which is placed is surrounded by # and $. The unary number equivalent to 5 is
placed on the input tape, on the first track. On the second track unary 2 is placed. If we
construct a TM which subtracts 2 and 5 we get the answer on the third track and that is 3,
in unary form. Thus this TM is for subtracting two unary numbers with the help of
multiple tracks.

a b c
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 43
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Track1 B B B X B -

Track2 B B B Y B - ……

Track3 B B B Z B -

Fig 4.10 - the input tape has multiple tracks on the first track.

For example: Number is prime or not

Track1 1 1 1 B B -

Track2 B 1 0 B B - ……

Track3 1 1 1 B B -

(i) Subtracting 2 from 7, we get

7 7 7 7
2 2 2 2
7 5 3 1

(ii) The Remainder is 1, so increment the value of second track by 1

7 7 7
3 3 3
7 4 1
(iii) The Remainder is 1 , so increment the value of second track by 1

7 7 7
4 4 4
7 3 1

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 44


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(iv) The Remainder is 3 , so increment the value of second track by 1

7 7
5 5
7 2

(v) The Remainder is 2 , so increment the value of second track by 1


7 7
6 6
7 1
(v) The Remainder is 1 , so increment the value of second track by

7
7
7

Now the value of first and second track is equal, so the number 7 is prime number
3. Checking Off Symbols
Checking off symbols is an effective way of recognizing the language by TM.
The symbols are to be placed on the input tape. The symbol which is read is marked by
any special character. The tape head can be moved to the right or left. Let us take some
example and we will see how to build turing machine by checking off symbols.
(Refer figure 4.12)

Example: Construct a turing machine M=(Q, ∑, Γ,δ,q0,B,F) which recognizes the


language L={wcw\w ∈ (a+b)+ }

Solution: In this language the input set is ∑ = {a, b}. The string which when will be
placed on the input tape it will have two distinct parts separated by letter c, such as in the
checking off symbols, each symbol is marked special character.
The simple logic in construction of this TM will be we mark the first letter and
then move to the right till we not get c, the first letter after c will be compared with the
marked letter. If it is same as which we have marked then mark this symbol otherwise go
to reject state. It can be shown as below,

a b A c a b a ∆ ∆ …

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 45


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

a b a c a b a ∆ ∆ … * * a c * * a ∆ ∆ …

Read a and mark it Mark it if it is same as marked

* b a c a b a ∆ ∆ … * * a c * * a ∆ ∆ …

* b a c a b a ∆ ∆ … * * a c * * a ∆ ∆ …

* b a c a b a ∆ ∆ … * * * c * * a ∆ ∆ …

* * * c * * a ∆ ∆ …
* b a c a b a ∆ ∆ …

* b a c * b a ∆ ∆ … * * * c * * a ∆ ∆ …

it is same as marked one

* b a c * b a ∆ ∆ … * * * c * * * ∆ ∆ …

* b a c * b a ∆ ∆ … * * * c * * * ∆ ∆ …

* b a c * b a ∆ ∆ … * * * c * * * ∆ ∆ …

* * a c * b a ∆ ∆ … * * * c * * * ∆ ∆ …

mark it

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 46


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


* * a c * b a ∆ ∆ … * * * c * * * ∆ ∆ …

* * a c * b a ∆ ∆ …
Figure 4.12 – Checking off symbols

* * a c * b a ∆ ∆ …

Now machine goes to accept state. Thus the TM we are scanning each symbol and trying to
recognize the string.

4. Subroutine
A Turing machine as built from a collection of interacting components or ―subroutines.‖
A Turing machine subroutine is a set of states that perform some useful process. This set of
states includes a start state and another state that temporarily has no moves, and that serves as
the ―return‖ state to pass control to whatever other set of states called the subroutine.
(Refer figure 4.13)
The “call” of a subroutine occurs whenever there is a transition to its initial state. Since
the TM has no mechanism for remembering a “return address,” that is, a state to go to after
it finishes, should our design of a TM call for one subroutine to be called from several
states, we can make copies of the subroutine, using a new set of states for each copy. The
―calls‖ are made to the start states of different copies of the subroutine, and each copy
“returns” to a different state.
Example: A TM to implement the function ―multiplication‖. A TM will start with 0m10n1 on
its tape, and will end with 0mn on the tape.
1. The tape has one nonblank string of the form 0i10n10kn for some k.
2. We change a 0 in the first group to B and add n 0‘s to the last group, giving us a string of
the form 0i-110n10(k+1)n .
3. As a result , we copy the group of n 0‘s to the end m times, once each time we change a
0 in the first group to B. when the first group of 0‘s is completely changed to blanks,
there will be mn 0‘s in the last group.
4. The final step is to change the leading 10n1 to blanks.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 47


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Figure 4.13 - The Subroutine copy

Figure 4.14 – The Complete multiplication program uses the subroutine copy.

Instantaneous description on TM

Let consider w = 0010001B


q00010001B ├ Bq6010001B ├B0q610001B
├ B01q10001B ├B01Xq2001B ├ B01X0q201B
├ B01X00q21B ├ B01X001q2B ├B01X001q30B

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 48


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


├ B01X00q310B ├ B01X0q3010B ├B01Xq30010B
├B01Xq10010B ├B01XXq2010B ├ B01XX0q210B
├ B01XX01q20B ├B01XX010q2B ├ B01XX010q30B
├ B01XX01q300B ├ B01XX0q3100B ├B01XXq30100B
├ B01XXq10100B ├B01XXXq2100B ├ B01XXX1q200B
├B01XXX10q20B ├B01XXX100q2B ├B01XXX100q30
├ B01XXX10q300B ├B01XXX1q3000B ├ B01XXXq31000B
├ B01XXXq11000B ├B01XXXq41000B ├ B01XXq401000B
├ B01Xq4001000B ├ B 01q40001000B ├B01q50001000B
├ B01q70001000B ├ B01q80001000B ├Bq9010001000B
├Bq0010001000B ├B0q610001000B ├ BB1q10001000B
├BB1Xq2001000B ├BB1X0q201000B ├BB1X00q21000B
├BB1X001q2000B ├ BB1X0010q200B ├BB1X00100q20B
├ BB1X001000q2B ├BB1X001000q30B ├BB1X00100q300B
├BB1X0010q3000B ├BB1X001q30000B ├BB1X00q310000B
├BB1X0q3010000B ├BB1Xq30010000B ├BB1Xq10010000B
├BB1XXq2010000B ├BB1XX0q210000B ├BB1XX01q20000B
├BB1XX010q2000B ├BB1XX0100q200B ├BB1XX01000q20B
├BB1XX010000q2B ├BB1XX010000q30B ├BB1XX01000q300B
├BB1XX0100q3000B ├BB1XX010q30000B ├ BB1XX01q300000B
├BB1XX0q3100000B ├ BB1XXq30100000B ├ BB1XXq10100000B
├BB1XXXq2100000B ├ BB1XXX1q200000B ├BB1XXX10q20000B
├BB1XXX100q2000B ├BB1XXX1000q200B ├BB1XXX10000q20B
├BB1XXX100000q2B ├BB1XXX100000q30B ├BB1XXX10000q300B
├BB1XXX1000q3000B ├BB1XXX100q30000B ├BB1XXX10q300000B
├BB1XXX1q3000000B ├BB1XXXq31000000B ├BB1XXXq11000000B
├BB1XXXq41000000B ├BB1XX0q41000000B ├BB1Xq4001000000B
├BB1q40001000000B ├BB1q50001000000B ├BB1q70001000000B
├BBq810001000000B ├BBq1010001000000B ├BBBq110001000000B
├BBBBq11 001000000B ├ BBBBBq1101000000B Accepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 49


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


27. Explain briefly about Two way Turing Machine (May/June-04,05, Nov/Dec-
05,08,09,12,13) & Consider two-tape Turing machine(TM) and determine whether the TM
always writes a nonblank symbol on its second tape during the computation on any input
string ‗w‘ formulate this problem as a language and show it is undecidable. Nov/Dec 2017

The Turing machine is widely accepted as a model of computational because of its


versatility in the power of computation. You have already experienced in the previous section,
how powerful this model is the TM can perform string operations, arithmetic computations,
recognizing languages either regular or non regular languages.

∆ 0 1 1 0 1 1 ∆ …

Figure 4.15 - Two Way infinite tape


The Turing machine with infinite tape can also be denoted by.
M = (Q, ∑, Γ, δ, q0, ∆ or B, F)
Where,
Q is a finite, nonempty set of states.
∑ is a nonempty finite set of input symbols
Γ is finite set of Tape symbols.
δ is a Transition function.
q0 is a start state.
B is a blank symbol.
F denotes the final state. The TM halts after reaching in final state.

Theorem: L is recognized by a TM with two way infinite tape if and only if it is recognized
by a TM with one way infinite tape.
Proof:
As theorem states, if any language is recognized by a TM with one way infinite tape then it
should also be recognized by a TM with two way infinite tape.
Let M1 be a TM with one way infinite tape and can be denoted by
M1 = (Q1,∑1, Γ1,δ1,q1, B1,F1)
Similarly, M2 be a TM with two way infinite tape
M2 = (Q2,∑2, Γ2,δ2,q2, B2,F2)

The input tapes are as shown by fig. 4.16


…. ∆ a5 a4 a3 a2 a1 a0 ∆ …
Figure 4.16 – input tapes
In above fig.4.16 the TM with one way infinite tape has a external symbol # placed in the very
first cell from left side. This symbol is used as indicator for the left side termination.
If we want a language l={ q0, q1, q2, q3, q4, q5} sequence then in the two way infinite tape the tape
head is fixed at the rightmost symbol.
The TM M2 can be

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 50


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

(a2,a2,L)
(a0,a0,L) (a1,a1,L)
Start q2
qo q1 q3

(a3,a3,L)

q6 q5 q4
Halt
(∆,∆,S) (a5,a5,L) (a4,a4,L)

δ(q6, ∆) (HALT, ∆,S) leads to HALT state.

…. ∆ a5 a4 a3 a2 a1 a0 ∆ …

Similarly, with one way infinite tape the machine M1 will be Even we can make the TM with one
way infinite tape as a multitrack tape to simulate it as a two way infinite tape. Let us now solve
some interesting problems to see the working of two way infinite tape in the Turing machine.

(a2,a2,L)
(a0,a0,L) (a1,a1,L)
Start q2
qo q1 q3

(a3,a3,L)

q6 q5 q4
Halt
#,#,S) (a5,a5,L) (a4,a4,L)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 51


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


28. Explain about Types of Turing machine. (or) Explain Multi tape and Multi head
Turing machine with suitable example. (April/May 2017)

1. Multiple head Turing machine (Refer figure 4.17)


 A multihead TM is a single tape TM having n heads reading symbols on the same
tape. In one step all the heads sense the scanned symbols and move or write
independently.
 The heads are numbered 1 through n and move of TM depends upon the state and
the symbol scanned by each head.
 In one move the heads may move left, right or remain stationary.
 This type of turing machine is as powerful as one tape turing machine.

input Accept/reject
Finite
Control

Head 1 Head n

….. …..

Figure 4.17 – Multihead TM


2. Multitape Turing machine
The multitape Turing machine (Refer figure 4.18) is a type of Turing machine in which
there are more than one input tapes. Each tape is divided into cells and each can hold any
symbol of finite tape alphabet.
This TM is more powerful than the basic turing machine. Because finite control reads
more than one input tape and more symbols can be scanned at a time.
Finite
Control

Input tape 1

….. …..

Input tape 2
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 52
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

….. …..

Figure 4.18 – Multi tape Turing machine

29. Explain briefly about Multitape Turing Machine. (Or) Show that if L is accepted by a
multitape turing machine,it is accepted by single tape Turing machine also.(Nov/Dec 2006)
Write about Multi tape Turing machines. (Nov/Dec 2016)
Multitape Turing Machine

A multitape Turing machine is shown in figure 4.19 .It consists of a finite control with k tape
heads and k tapes; 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;

(i) Change state;


(ii) Print a new symbol on each of the cells scanned by its tape heads;
(iii)Move each of its tape heads, independently, one cell to the left or right, keep it stationary.

Initially, the input appears on the first tape, and the other tapes are blank. We shall not define the
dive more formally, as the formalism is cumbersome and a straightforward generalization of the
notation for single-tape TM‘s.

MULTITAPE TURING MACHINES

FINITE
STATE
CONTROL

Figure 4.19 – Multi tape TM

A multitape TM is like an ordinary TM with several tapes

 Each tape has its own head for reading/writing


 Initially the input is on tape 1 and other are blank
 Transition function allow for reading, writing, and moving the heads on all tapes
simultaneously.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 53


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Where,

If the machine is in sate qi and heads 1 through k are reading symbol a1 through ak the machine
goes to qj , writes b1 through bk on tapes 1 through k respectively and moves each head to the left
or right as specified by δ.

Theorem :

Every multitape Turing machine has an equivalent single tape Turing machine.

Proof: we show how to convert a multitape TM M into a single tape TM S. The key idea is to
show how to simulate M with S.

Simulating M with S

Assume that M has K tapes

 S simulates the effect of K tapes by storing their information on its single tape
 S uses a new symbol # as a delimiter to separate the contents of different tapes
 S keeps track of the location of the heads by marking with a the symbols where the
heads would be.

Example1:

Figure 4.20 shows how to represent a machine M with 3 tapes by a machine S with one tape.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 54


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Figure 4.20 – Multi tape Machine Simulation

Example2:

We can define Turing machines with multiple tapes. We can imagine the input coming in (on
one tape), and using the other tapes for scratch work. This can easily be stuck into the formalism,
by redefining the transition function: now it takes k tape symbols, and outputs k tape symbols,
and k tape directions.

Theorem: Every Multitape Turing Machine can be transformed into a single tape Turing
Machine (Refer figure 4.21 and 4.22)

1 0 0

FINITE
STATE
CONTROL

FINITE
STATE
CONTROL 1 0 0 # . # . #

Figure 4.21

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 55


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


We can simulate these multiple tapes with one tape, in the following way. We write down the
contents of all these tapes in order, and put a # between two tapes. To keep track of where all the
heads of the multitape machine are, we double the size of the alphabet to include ―marked‖
symbols, and a mark above a symbol indicates the head position.

1 0 0

FINITE
STATE
CONTROL

FINITE
STATE
CONTROL 1 0 0 # . # . #

Figure 4.22

When some tape head moves, we move the mark. When the multi-tape machine makes one of its
tape contents ―longer‖ (by writing over some blanks),the simulation of it moves all the tape
content beyond over by one. Like, suppose the multitape machine adds a 0 to the end of the first
tape. Then everything from the # on is shifted over to the right, and 0 is written.

30. Explain how a Turing machine can be viewed as a computing device on functions
involving integers. (Dec-13)

The TM accepts the computable functions such as addition, multiplication, subtraction, division,
power function, square function, logarithmic function and many more.

For example:

Construct a TM for a successor function for a unary number i.e. f(n) = n+1.

For construction of such TM ∑ ={ 1} . We will go on moving towards right end of the input
tape. The input on the input tape is kept as it is. Only the last symbol Δ is replaced by 1.
Considered the input tape consists of 4. The successor function will give output 5.

1 1 1 1 Δ Δ Δ Δ

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 56


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

(1,1,R)

(Δ, Δ,R)
Start (1,1,R) (Δ,1,R)
q1 q2 Halt
qo

N=4, f(4)=n+1

Instantaneous description

q01111Δ├ 1q1111Δ├11q111Δ├111 q11Δ├1111q1Δ├11111q2Δ├11111ΔhaltAccepted

Computational Languages and Partial Functions:

31. Construct TM for performing addition of two numbers f(m+n)=m+n. (May-2007)


(0, 0,R) (0,0,R)

(0,B,R)
Start (1, 0,R) (B,B,L) q2
qo q1 q3

Example: f(m+n)=m+n
m=3,n=2
f(m+n)=3+2=5
Instantaneous description
(q0000100Δ)├(0q000100Δ)├00q00100Δ├000q0100Δ├0000q100Δ├00000q10Δ├000000q1Δ├00
000q20Δ├00000q3BΔAccepted
32. Construct TM for the language L = {an bn } where n≥1. (May – 09)

(Y,Y,L)
(a,a,R)
(Y,Y,L)
(a,a,R)
Start (a,X,R) (b,Y,L) q2
qo q1

(Y,Y,R) (X,X,R)

q3
(Y,Y,R)

(Δ, Δ,L)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 57


Halt
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Check the input w=aabb

Instantaneous description

(q0 aabbΔ)├ Xq1abb Δ )├ Xaq1bb Δ )├ Xaq2YbΔ)├ Xq2aYb Δ)├ Xq0aYbΔ)├ XXq1Yb Δ)├
XXYq1b Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ XXYYΔ q4Accepted

33. Construct a TM for L = {an bn cn / n≥0 }. [Nov/Dec 2024]

(Y,Y,R) (Z,Z,R)
(a,a,R) (b,b,R)
(b,b,L)
(a,a,L)
(c,Z,L)
Start (a,X,R) (b,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt

Check the input w=aabbcc

Instantaneous description

q0 aabbccΔ├ Xq1abbcc Δ ├ Xaq1bbcc Δ ├ XaYq2bccΔ├ XaYbq2cc Δ├ XaYbZq3cΔ├


XaYbq3 Zc Δ├ XaYq3bZc Δ├ Xaq3YbZcΔ├ Xq3 aYbZcΔ├ Xq0aYbZcΔ├ XXq1YbZcΔ├
XXYq1bZcΔ├ XXYYq2ZcΔ├ XXYYZq2cΔ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0 YYZZΔ├
XXYq4 YZZΔ├ XXYYZZq4 Δ├XXYYZZΔ q5Accepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 58


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


34. Construct a TM which accept the language of aba over ∑ = { a,b}

(Δ, Δ,R)
(b,b,R) (a,a,R)
Start (a,a,R) q2 q3
qo q1

Check the input aba

Instantaneous description

q0aba Δ├ aq1ba Δ├ abq2 Δ├ abaq3Δ├ aba Δ q3Accepted

35. Construct a TM for L = {1n0n1n / n≥0 }.(May – 12)


(Y,Y,R) (Z,Z,R)
(0,0,R) (1,1,R)
(1,1,L)
(0,0,L)
(0,Z,L)
Start (0,X,R) (1,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt
Check the input w=110011

Instantaneous description

q0 110011Δ├ Xq110011 Δ ├ X1q10011Δ ├ X1Yq2011Δ├ X1Y0q211Δ├ X1Y0Zq31Δ├


X1Y0q3Z1 Δ├ X1Yq30Z1 Δ├ X1q3Y0Z1Δ├ Xq3 1Y0Z1Δ├ Xq01Y0Z1Δ├ XXq1Y0Z1Δ├
XXYq10Z1Δ├ XXYYq2 Z1Δ├ XXYYZq21Δ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0 YYZZΔ├
XXYq4 YZZΔ├ XXYYZZq4 Δ├XXYYZZΔ q5Accepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 59


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


36. Construct TM for performing subtraction of two unary numbers f(a-b) = c where a is
always greater than b.(Dec -03,Dec – 05,May -11)

Construct a Turing machine for proper subtraction, which is defined as m-n if m>n and 0
otherwise. Nov/Dec 2020 (B,B,R)

(1,1,R)
(0,0,R) (0,0,L)

(0,1,L) (1,1,L)
Start (0,B,R) (1,1,R) q2 q3
qo q1
1,1,R
(B,B,L)

(1,B,L)
q4 q5 q6
Example: (0,0,L)
(B,0,R)
f(m-n)=m-n ; m>=n

f(m-n)=blank ; if(m<=n)

Note: 1) If m>=n, the result is 0m-n should be on the tape

2) If m<=n, the tape should be blank symbol

Check the input (4-2)(0000100)

Instantaneous description

q0 0000100B├ Bq1000100B├ B000q1100B├ B0001q200B├ B0001q310B├ B000q3110B├


Bq3 000110B├ Bq0 000110B├ BBq100110B├ BB00q1110B├ BB001q210B├ BB0011q20B├
BB0011q31B├ BB q300111B├ BB q000111B├ BBB q10111B├ BBB0 q1111B├ BBB01
q211B├ BBB0111 q2B├ BBB0111 q4B├ BB011 q4 BB├ BBB0 q4 BBBB├ BBB q4 0BBBB├
BB0 q5 0BBBB├ BB000BBBB q5 Accepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 60


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


37. Construct TM for the addition function for the unary number system f(x)=X+1.(May -
07) (Or) Construct a TM for a successor function for a unary number i.e. f(n) = n+1.

(1,1,R)

(Δ, Δ,R)
Start (1,1,R) (Δ,1,R) q2
qo q1 Halt

We just go on moving towards right most end of input stream. The end marker of a string Δ is
replaced by 1

Instantaneous description

q01111ΔΔ├q11111Δ Δ├ 1q1111Δ Δ├ 11q111Δ Δ├ 111q11Δ Δ├ 1111q1Δ Δ├


11111q2ΔAccepted

38. Design a TM for finding 1,s complement of a given binary number. (Dec-11)
(1,0,R)
(0,1,R)
(0,1,R)
Start (1,0,R) (Δ, Δ,R)
q1 q2 halt

Input w=101 (0,1,R)

Instantaneous description

q 1101Δ├0 q201Δ├01q21Δ├010q2Δ├010Δ q2haltAccepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 61


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

39. Design a TM which reverses the given string {abb}. (Dec – 12)
(b,b,R)
(a,a,R) (b,b,L)
(b,b,R) (B,B,R)

(Δ, b,L)
(Δ, Δ,R)
Start (Δ, Δ,L) (b,B,R) q2 q3 q4
qo q1

(Δ, Δ,L)

(b,B,R) (B,B,L)
q5

(a, A,R)

(Δ, a,R) (Δ, Δ,R)


q7 q6 (B,B,R)
Halt
Instantaneous description

q0abbΔΔΔΔ├aq0bbΔΔΔΔ├ abq0bΔΔΔΔ├ abbq0ΔΔΔΔ├ (b,b,R)


abbq0ΔΔΔΔ├ abq1 bΔΔΔΔ├
abBq2ΔΔΔΔ├ abBΔ q3ΔΔΔ├ abBΔ q4 bΔΔ├ abBq4ΔbΔΔ├ abq5 BΔbΔΔ├ aq5 bBΔbΔΔ├ aBq2
BΔbΔΔ├ aBBq2 ΔbΔΔ├ aBB Δ q3 bΔΔ├ aBB Δ bq3 ΔΔ├ aBB Δ q4 bbΔ├ aBB q5Δ bbΔ├ a
q5BB Δ bbΔ├ Aq6BB Δ bbΔ├ ABB q6Δ bbΔ├ ABB Δ q7 bbΔ├ ABB Δ bb q7 Δ├ ABB Δ bbahalt

40. Design a TM to accept the language L = {0n 1n / n≥1} and simulate its action on the
input 0011. (May–14) (Or) Design a Turing-machine to accept the language L={0 n 1n/n≥1
}.Draw the transition diagram. (Also specify the instantaneous description to trace the
string 0011).(10) (Nov/Dec 2015) (Y,Y,L)
(0,0,R)
(Y,Y,L)
(0,0,R)
Start (0,X,R) (1,Y,L) q2
qo q1

(Y,Y,R) (X,X,R)

q3
(Y,Y,R)

(Δ, Δ,L)
Check the input 0011

Halt
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 62
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Instantaneous description

q0 0011Δ├ Xq1011 Δ ├ X0q111 Δ )├ X0q2Y1 Δ)├ Xq20Y1 Δ)├ Xq00Y1 Δ)├ XXq1Y1 Δ)├
XXYq11 Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ ├ XXYYΔ q4Accepted

41. Design a TM for reversing a string on the input tape.(TextBook Problem)

Construct a TM to reverse the given string. (April/May 2017)

Halt

Reverse the input w=abb

Instantaneous description

q0abbΔΔΔΔ├aq0bbΔΔΔΔ├ abq0 bΔΔΔΔ├ abbq0ΔΔΔΔ├ abbq0ΔΔΔΔ├abq1 bΔΔΔΔ├


abBq2ΔΔΔΔ├ abBΔ q3ΔΔΔ├ abBΔ q4 bΔΔ├ abBq4ΔbΔΔ├ abq5 BΔbΔΔ├ aq5 bBΔbΔΔ├ aBq2
BΔbΔΔ├ aBBq2 ΔbΔΔ├ aBB Δ q3 bΔΔ├ aBB Δ bq3 ΔΔ├ aBB Δ q4 bbΔ├ aBB q5Δ bbΔ├ a
q5BB Δ bbΔ├ Aq6BB Δ bbΔ├ ABB q6Δ bbΔ├ ABB Δ q7 bbΔ├ ABB Δ bb q7 Δ├ ABB Δ bbahalt

42. Design a TM to accept the language L = { ss | s Є { a, b} *}.(Textbook Problem)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 63


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(Or) Construct a TM for a language having equal number of a‘s and b‘s

A TM Accepting { ss | s Є { a, b} *}

(q0, Δaba) ├ (q1, Δaba) ├ (q2, ΔAba) ├* (q2, ΔAbaΔ)

├ (q3, ΔAba) ├ (q4, ΔAbA) ├ (q4, ΔAbA)

├ (q1, ΔAba) ├ (q2, ΔABA) ├ (q3, ΔABA)

├ (hr, ΔABA) (reject)

Figure : A Turing machine to accept { ss | s Є {a, b}*}


(q0, Δabaa) ├ (q1, Δabaa) ├ (q2, ΔAbaa) ├* (q2, ΔAbaaΔ)
├ (q3, ΔAbaa) ├ (q4, ΔAbaA) ├ *(q4, ΔAbaA)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 64


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


├ (q1, ΔAbaA) ├ (q2, ΔABaA) ├ (q2, ΔABaA)
├ (q3, ΔABaA) ├ (q4, ΔABAA) ├ (q1, ΔABAA)
├ (q5, ΔABAA) ├ (q5, ΔAbAA) ├ (q5, ΔabAA)
(first phase completed)
├ (q6, ΔabAA) ├ (q8, ΔAbAA) ├ (q8, ΔAbAA)
├ (q9, ΔAbΔA) ├ (q9, ΔAbΔA) ├ (q6, ΔAbΔA)
├ (q7, ΔABΔA) ├ (q7, ΔABΔA) ├ (hr, ΔABΔAΔ) (reject)
(q0, Δabab) ├* ………………
(same as previous case, upto 3rd-from-last move)
├ (q6, ΔAbΔA) ├ (q7, ΔABΔB) ├ (q7, ΔABΔB)
├ (q9, ΔABΔ) ├ (q9, ΔAB) ├ (q6, ΔABΔ)
├ (hr, ΔABΔ) (accept)
43. Construct a TM for checking the palindromes of a string of Odd or even palindromes
for Σ = {a, b}. (Textbook Problem) (or) Construct a Turing machine to accept palindromes
in an alphabet set ∑={a,b}.Trace the strings ‖abab‖ and ―baab‖. May/June 2016
a/a, R
(odd palindrome)
b/b, R Δ/Δ, R
Δ /Δ, L
q2 q3

a/Δ, L
a/Δ, R
Δ/Δ, R Δ/Δ, R a/a, L
q4 ha
q0 q1 b/b, L
b/Δ, R b/Δ, L

Δ/Δ, L
q5 q6 Δ/Δ, R
a/a, R

b/b, R

Δ /Δ, R
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 65
DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

(Even palindrome)

A TM Accepting Palindromes over {a, b}

(q0, Δaa) ├ (q1, Δaa) ├ (q2, ΔΔa) ├* (q2, ΔΔaΔ)

├ (q3, ΔΔa) ├ (q4, ΔΔ) ├ (q1, ΔΔΔ)

├ (ha, ΔΔΔΔ) (accept)

Input w=aba

Instantaneous description

q0Δaba Δ├ Δq1aba Δ├ ΔΔq2ba Δ├ ΔΔbq2a Δ├ ΔΔbaq3 Δ├ ΔΔbaΔ q3 ├ ΔΔbq4ΔΔ ├ ΔΔ q4bΔΔ


├Δ q1ΔbΔΔ ├ ΔΔq1bΔΔ ├ ΔΔΔq5ΔΔ ├ ΔΔq6ΔΔΔ ├ ΔΔΔΔΔhaltAccepted

44. Design a TM to implement the function multiplication using the subroutine copy a
string.(Nov/Dec-14)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 66


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

45. Construct Turing machine (TM) that replace all occurrence of 111 by 101 from
sequence of 0‘s and 1‘s. Nov/Dec 2017

(Δ, Δ,R)
(1,0,R) (1,1,R)
Start (1,1,R) q2 q3
qo q1

Check the input aba

Instantaneous description

q0111 Δ├ 1q111 Δ├ 10q2 1Δ├ 101q3Δ├ 101 Δ q3Accepted

46. Construct a Turing machine that perform unary multiplication (Say 111 ×11 = 111111).
[Nov/Dec 2024]
Construct a Turing Machine for multiplying two non negative integers using subroutine.
Nov/Dec 2020

Figure (1) The Subroutine copy

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 67


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Figure (2) – The Complete multiplication program uses the subroutine copy.

Instantaneous description on TM Refer question number 2

47. Construct truing machine for the language{ WW/W£ {0,1}}. April/May 2018

(X,X,R) (Y,Y,R)
(0,0,R)
(Y,Y,R) (Y,Y,L)
(0,0,L)
Start (0,X,R) (1,Y,L) q2
qo q1

(X,X,R)

(Y,Y,R)

(Δ, Δ,R)
q3 q4
(X,X,L)
(1,1,L)
Halt (1,1,R)
(X,X,R)
(1,Y,R)
(0,X,L)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 68


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Instantaneous description

q0 0011Δ├ Xq1011 Δ ├ X0q111 Δ )├ X0q2Y1 Δ)├ Xq20Y1 Δ)├ Xq00Y1 Δ)├ XXq1Y1 Δ)├
XXYq11 Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ ├ XXYYΔ q4Accepted

48. Explain in detail about Closure Properties of CFL.

T he co nt ext fr ee la nguages ar e clo sed under so m e o per at io n means a ft er


performing t hat part icular operat ion on t hose CFLs t he result ant language is
context free language. These properties are as below
1. The context free languages are closed under union.
2. The context free languages are closed under concate nation.
3. The context free languages are closed under kleen closure.
4. The context free languages are not closed under intersection.
5. The context free languages are not closed under complement.
We will discuss the above ment ioned closure properties of CFL wit h the help of
proofs and examples.
Properties of Context Free Languages

Union: If L1 and L2 are two context free languages, their union L1 ∪ L2 will also be context
free.
For example,
L1 = { anbncm | m >= 0 and n >= 0 } and L2 = { a nbmcm | n >= 0 and m >= 0 }
L3 = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also context free.
L1 says number of a‘s should be equal to number of b‘s and L2 says number of b‘s should be
equal to number of c‘s. Their union says either of two conditions to be true. So it is also
context free language.
Note: So CFL are closed under Union.
Concatenation: If L1 and If L2 are two context free languages, their concatenation L1.L2
will also be context free.
For example,
L1 = { anbn | n >= 0 } and L2 = { c mdm | m >= 0 }
L3 = L1.L2 = { anbncmdm | m >= 0 and n >= 0} is also context free.

L1 says number of a‘s should be equal to number of b‘s and L2 says number of c‘s should be
equal to number of d‘s. Their concatenation says first number of a‘s should be equal to
number of b‘s, then number of c‘s should be equal to number of d‘s. So, we can create a PDA

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 69


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


which will first push for a‘s, pop for b‘s, push for c‘s then pop for d‘s. So it can be accepted
by pushdown automata, hence context free.
Note: So CFL are closed under Concatenation.

Kleene Closure : If L1 is context free, its Kleene closure L1* will also be context free.
For example,
L1 = { anbn | n >= 0 }
L1* = { anbn | n >= 0 }* is also context free.
Note: So CFL are closed under Kleen Closure.

Intersection and complementation: If L1 and If L2 are two context free languages, their
intersection L1 ∩ L2 need not be context free.
For example,
L1 = { anbncm | n >= 0 and m >= 0 } and L2 = (a mbncn | n >= 0 and m >= 0 }
L3 = L1 ∩ L2 = { anbncn | n >= 0 } need not be context free.

L1 says number of a‘s should be equal to number of b‘s and L2 says number of b‘s should be
equal to number of c‘s. Their intersection says both conditions need to be true, but push down
automata can compare only two. So it cannot be accepted by pushdown automata, hence not
contextfree.
Similarly, complementation of context free language L1 which is ∑* – L1, need not be context
free.
Note: So CFL are not closed under Intersection and Complementation.

Theorem 1 : If L 1 and L2 are context free languages then L = L 1 k..) L2 is also context
free. That is, the CFLs are closed under union.
Proof : We will consider two languages L 1 and L 2 which are context free languages.
We can give these languages using context free grammars G 1 and G2 such that G 1 E
L1 and G2 E L2. The G1 can be given as G 1 = {V1 , € , 131 , S1 } where P 1 can be given as
P1 ={
S1—> Al S1 Al | B1 S B1 | €
A1 --> a
B1 —>b
}
Here V1 = {S1, A1 , B1} and S1 is a
start symbol.
Similarly, we can write G2 = {V2, ∑ , P2, S2}
N2 = {S2, A2, B2} and S 2 is a start symbol.
P2 can be given as :
P
2 ={
S2 --> a A2 A2 I b B2 B2
A2 --> b

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 70


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


B2 --> a
}
Now L = L iu L2 gives G E L. This G can be written as G=
{V, , P, S}
V = {S1, Ai, B1, S2, A2, B2}
P = 1P1 u P2}
S is a start symbol
P= { S —> S1 | S2
S 1 ---* A l S1 Al | B 1 S B 1 |€
A1-->a
B1 --> b
S2 --> aA2A2 | bB2B2
A2 --> b
B2 --> a
Thus grammar G is a context free grammar which produces languages L which is
context free language.

Theorem 2 : If L1 and L2 are two context free languages then L1L 2 is CFG. That means
context free languages are closed under concatenation.
Proof :Let L1 is a context free language which can be represented by a context free
grammar G1, such that G 1 € L1 and
G 1 = {V 1 ,∑ , P 1 , S1}
V1 = {S1, A1, B 1}
∑= {a, b}
S 1 is a start symbol and P1 is a set of production rules,
P1 = (S 1 --> A1 S1 A1 |B1 S1 B1|€
A1-->a
Bi --> b
Similarly, L2 is a context free language which can be represented by a context
free
grammar G2, such that G2 E L2 and
G2 = {V2 , ∑ P2, S2}
V2 = {S2, A2 , B2 }
∑= {a, b}
S 2 is a start symbol and P2 is a set of production rules,
P2 = { S2 --> aA2A2 | bB2B2
A2 -> b
B2 -> a
}
Now L = L1 L2 can be obtained by G such that G = G 1 . G2. Therefore
G= {V, ∑, P, S}
V = {S, S 1. A1, B1 , S2, A2, B2}
where S is a start symbol. The production rules, P can be given as
P = { S —> S1 | S2
S 1 - > A1 S 1 A1 |B1 S 1 B1| €
A i --> a

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 71


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


B1—> b
S2 -> aA2A2 | bB2B2
A2 --> b B2 --
>a
As grammar G is context free grammar the language L produced by G is also
context free language. Hence context free languages are closed under concatenation.

Theorem 3 : If L i is context free language then L i is also context free. That means
CFL is closed under kleen closure.
Proof :Let, L i be a context free language represented by G 1 such that G i —> E L i .
The CFG G 1 can be given as
G i = {V 1 , X , P i , S i } where S i is a start symbol
Pi = (S1 —> AiSiAi I B1S1B1 I e
A1 —> a B1 —>b
Now L = L* 1 can be represented by a grammar G such that
G = { (V, / , P, S)
V = {S, S i, Al B1}
and P = S —> Si S I 6
S1 -> Al S1 Al | B1 S1B1
Al —> a
B1 --> b
Thus grammar G is a context free grammar and language L produced by G is also
context free language. Hence context free language are closed under kleen closure.

Theorem 4 : If L 1 and L 2 are two CFLs then L = L 1 n L2 may be CFL or may not be
CFL. That means L is not closed under intersection.
Proof : Let, Li = {O n 1 n 2 i I n 1 , 1}
n n n
L2 = {0 1 2 In?_ 1}

The grammar for L 1 is


S —> AB
A —> 0A1 I 01
B —> 2B 12Similarly L2 can be represented by grammar.
S —> AB
A —> OA | 0
B —> 1B2 | 12
Now if we try to obtain
L = L 1 n L 2 then we get somet imes context free languages and somet imes non
context free languages. Thus we can say that CFLs are not closed under intersection.

Theorem 5 : If L 1 is a CFL then L 1 may or may not be CFL. That means CFL is not
closed under complement.
Proof : Let L 1 and L2 are two CFLs. We will assume that complement of a context
free language is a CFL itself. Hence Li and L'2 both are CFLs. We can also state that
(111 u L2) is context free (since CFLs are closed under union). But (L' 1 u L2) = L1 n L 2 i.e.
L = L 1 n L 2 may or may not be CFL. The L 1 and L2 are arbitrary CFLs, there may exist

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 72


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


L'i and L2 which are not CFL. Hence complement of certain language may be cont ext
free or may not be. Therefore we can say that CFL is not closed under

49. Convert the following grammar to Chomsky Normal form. S → A|AB0|A1A A → A0| Є
B → B1|BC C → CB|CA|1B . Nov/Dec 2021
Solution :
(i) To eliminate the useless symbols, we have to find the generating and reachable
symbols.
Generating symbols ={0, 1 }
Here B and C is a useless symbol. Start Symbol S is not generating B and C.
After Eliminate Productions are
S → A|AB0|A1A
A → A0| Є
(ii) Eliminate the Є production
Eliminate A →Є
After Eliminate the Є production
S → A|AB0|A1A |B0|1A|A1
A → A0| 0
(iii)Eliminate Unit Production
S→A
After Eliminate Unit Production
S → A0| 0|AB0|A1A |B0|1A|A1
A → A0| 0
Find CNF for the above grammar
S → A0| 0|AB0|A1A |B0|1A|A1
A → A0| 0
(i) S → A0| 0
S→0
S → AS
(ii) S → ABS
C1BS
S → AC1
(iii) S → A1A
S → AC2A
C21
C3C2A
S → AC3
(iv) S → BS
(v) S → C2A
(vi) S → A C2
(Viii) A → AS| 0
(iX) A → 0
CNF Grammars:
S→0
S → AS

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 73


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


C1BS
S → AC1
C21
C3C2A
S → AC3
S → BS
S → C2A
S → A C2
A → AS| 0
A→ 0

50. Design appropriate automation model for the language defined by the grammar
given below.
S → aSBC
CB → BC
bB → bb
cC → cc
S → aBC
aB → ab
bC → bc Nov/Dec 2021

Solution:
S ⇒ aSBC
⇒ aaBCBC (using S → aBC)
⇒ aabCBC (using aB → ab)
⇒ aabCBC (using CB → HB)
⇒ aabBCC (using HB → HC)
⇒ aabbCC (using HC → BC)
⇒ aabbcC (using bB → bb)
⇒ aabbcc

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 74


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Construct a TM for L = {aabbcc}.

(Y,Y,R) (Z,Z,R)
(a,a,R) (b,b,R)
(b,b,L)
(a,a,L)
(c,Z,L)
Start (a,X,R) (b,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt

Check the input w=aabbcc

Instantaneous description

q0 aabbccΔ├ Xq1abbcc Δ ├ Xaq1bbcc Δ ├ XaYq2bccΔ├ XaYbq2cc Δ├ XaYbZq3cΔ├


XaYbq3Zc Δ├ XaYq3bZc Δ├ Xaq3YbZcΔ├ Xq3 aYbZcΔ├ Xq0aYbZcΔ├ XXq1YbZcΔ├
XXYq1bZcΔ├ XXYYq2ZcΔ├ XXYYZq2cΔ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0
YYZZΔ├ XXYq4 YZZΔ├ XXYYZZq4 Δ├XXYYZZΔ q5Accepted

51. Design appropriate automation model for the language defined by the grammar
given below.
S → abc/aAbc
Ab → bA
Ac → Bbcc
bB → Bb
S → aBC
aB → aa/aaA. Nov/Dec 2021

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 75


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


Solution:
S→aAbc
→abAc
→abBbcc
→aBbbcc
→aaAbbcc
→aabAbcc
→aabbAcc
→aabbBbccc
→aabBbbccc
→aaBbbbccc
→aaabbbccc
The language generated by this grammar is {anbncn | n≥1}.
Construct a TM for L = {an bn cn / n≥0 }. (May – 08,May – 11)
(Y,Y,R) (Z,Z,R)
(a,a,R) (b,b,R)
(b,b,L)
(a,a,L)
(c,Z,L)
Start (a,X,R) (b,Y,R) q2 q3 (Y,Y,L)
qo q1
(Z,Z,L)

(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)

(Δ, Δ,R)

Halt

Check the input w=aabbcc

Instantaneous description

q0 aabbccΔ├ Xq1abbcc Δ ├ Xaq1bbcc Δ ├ XaYq2bccΔ├ XaYbq2cc Δ├ XaYbZq3cΔ├


XaYbq3Zc Δ├ XaYq3bZc Δ├ Xaq3YbZcΔ├ Xq3 aYbZcΔ├ Xq0aYbZcΔ├ XXq1YbZcΔ├
XXYq1bZcΔ├ XXYYq2ZcΔ├ XXYYZq2cΔ├ XXYYZq3ZΔ├ XXq3 YYZZΔ├ XXq0
YYZZΔ├ XXYq4 YZZΔ├ XXYYZZq4 Δ├XXYYZZΔ q5Accepted

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 76


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 77


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


ANNA UNIVERSITY QUESTIONS
Nov/Dec 2015

PART- A

1. Define a Turing machine?


2. What is a multitape Turing machine?
PART- B

1. (a) (i) Design a Turing-machine to accept the language L = {0n1n / n≥1}.Draw the
transition diagram.(Also specify the instantaneous description to trace the string 0011).
(ii) State and describe the Halting problem for Turing machine. (6)

(b) (i) Explain the programming techniques for Turing Machine construction. (10)

(ii) Describe the Chomsky hierarchy of languages. (6)

(ii) State the Pumping lemma for CFL and Show that the language L={a n bncn | n≥1}
is not a CFL.(6)

May/June 2016

PART- A

1. What are the differences between a finite automata and a Turing machine?
2. What is a Turing Machine?
PART- B

1.(a) (i) Construct a Turing machine to accept palindromes in an alphabet set


∑={a,b}.Trace the strings ‖abab‖ and ―baab‖.
(ii) Explain the variations of Turing machines.
(b) (i) Explain Halting problem. Is it solvable or unsolvable problem? Discuss.
(ii) Describe Chomsky hierarchy of languages with example. What are the devices
that accept these languages?

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 78


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


(iii) State pumping Lemma for CFL. Use pumping lemma to show that the language
L = { ai bjck | i <j<k} is not a CFL. (8)

Nov/Dec 2016

PART A

1. What are the required fields of an instantaneous description of a turing machine?


2. List the primary objects of turing machine.
PART B

1. Discuss the various techniques for turing machine construction.


2. (i) Write about Multi tape Turing machines.
(ii) Explain highlight the implications of halting problem.

(ii) State and explain the pumping lemma for CFG.

April/May 2017

PART- A

1. Write short notes on Chomskian hierarchy of languages.

2. What is halting problem?

PART- B

1. Construct a TM to reverse the given string.


2. Explain Multi tape and Multi head Turing machine with suitable example.

Nov/Dec 2017

PART-A

1. Define Turing Machine. Nov/Dec 2017


2. Give the configuration of Turing machine. (Nov/Dec 2017
3. Show that L={ap /p is prime} is not context free.

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 79


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


PART-B

1. Construct Turing machine (TM) that replace all occurrence of 111 by 101 from
sequence of 0‘s and 1‘s. Nov/Dec 2017
2. Explain techniques for Turing machine construction. Nov/Dec 2017
3. Illustrate the Chomsky grammar classification with necessary example .
Part-C
1. Prove that halting problem is undecidable. Nov/Dec 2017
2. Consider two-tape Turing machine(TM) and determine whether the TM always
writes a nonblank symbol on its second tape during the computation on any input
string ‗w‘ formulate this problem as a language and show it is undecidable.
Nov/Dec 2017
3. (ii) Explain pumping Lemma for CFL.

Apr/May-2018

PART-A

1. Define Turing Machine. Apr/May-2018


2. Define Chomsky hierarchy Turing Machine? Apr/May-2018

PART-B

1. Construct a Turing machine that perform unary multiplication (Say 111 ×11 =
111111) Apr/May-2018
2. Elaborate on programming techniques for Turing machine construction. Apr/May-
2018
3. Construct truing machine for the language { WW/W£ {a,b}}. Apr/May-2018
4. b)(i) Explain pumping lemma for Context Free Languages with example.(7)

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 80


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION

Part C

1. Analyze the limitation of automata for Types 3, Types 2, Types 0 languages.


Apr/May-2018
2. Show that halting problem is undecidable. Apr/May-2018
Nov/Dec-2020

PART-A

1. What are the two normal forms of CFG? Write their productions format.
2. Define the language recognized by any turing machine.
PART-B

1. Construct a Turing machine for proper subtraction, which is defined as m-n if


m>n and 0 otherwise.
2. How a CFG for L is converted into CNF accepting the same language? Convert
the following CFG into CFG in CNF
SbA/aB AbAA/aS/a BaBB/bS/b

PART C

1. Construct a Turing Machine for multiplying two non negative integers using
subroutine.

Nov/Dec 2021

PART A

1. Draw Turing machine to compute double the value


of an integer.
PART B

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 81


DEPARTMENT OF INFORMATION TECHNOLOGY

CS3452 UNIT IV THEORY OF COMPUTATION


2. Convert the following grammar to Chomsky
Normal form .
S → A|AB0|A1A
A → A0| Є
B → B1|BC
C → CB|CA|1B .
3. Design appropriate automation model for the language defined by the grammar
given below.
S → aSBC
CB → BC
bB → bb
cC → cc
S → aBC
aB → ab
bC → bc

4. Design appropriate automation model for the language defined by the grammar
given below.

S → abc/aAbc
Ab → bA
Ac → Bbcc
bB → Bb
S → aBC
aB → aa/aaA

Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 82


DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

UNIT V - UNDECIDABILITY
Unsolvable Problems and Computable Functions –PCP-MPCP- Recursive and recursively
enumerable languages – Properties - Universal Turing machine -Tractable and Intractable
problems - P and NP completeness – Kruskal’s algorithm – Travelling Salesman Problem-
3-CNF SAT problems.

PART A
1. When a problem is said to be decidable and give an example of undecidable problem?
(Nov/Dec-03,12,May-06,05)(Nov/Dec 2015)
A problem whose language is recursive is said to be decidable. Otherwise, the problem is
undecidable. The classes of problems which can be answered as ―Yes‖ are called solvable
or decidable. The classes of problems which can be answered as ―No‖ are called
undecidable problems.
Following are undecidable problems.
i) Whether the language accepted by a TM is empty.
ii) Whether the language accepted by a TM is regular language.
iii) Whether the language accepted by a TM is context free language.

2. Show that the complement of a recursive language is recursive. (Dec-04,may-05)


Theorem: If both a language L and its complement are RE, then L is recursive.
Proof: Let L=L(M1) and L’= L(M2). Both M1 and M2 are simulated in parallel by a TM M. We
can make M a two-tape TM, and then convert it to a one-tape TM, to make the simulation easy
and obvious. One tape of M simulates the tape of M1, while the other tape of Al simulates the
tape of M2. The states of M1 and M2 are each components of the state of M.

Figure (5.1)
Figure (5.1) Simulation of two TM's accepting a language and its complement
If input w to M is in L, then Mi will eventually accept. If so, M accepts and halts. If
w is not in L, then it is in L’, so M2 will eventually accept. When M2 accepts, M halts
without accepting. Thus, on all inputs, M halts, and L(M) is exactly L. Since M always
halts, and L(M) = L, we conclude that L is recursive.

3. Give two properties of Recursively Enumerable Sets which are undecidable.


The languages accepted by Turing machines are called recursively enumerable (RE)
language. Every non-trivial property of RE is undecidables. Here are two such properties.
 Whether the language accepted by a TM is regular language.
 Whether the language accepted by a TM is context free language.
1
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
These are the two properties that are undecidable.

4. When a language is said to be recursive? Is it true that every regular set is not recursive?
(Nov/Dec -05)

A language is said to be recursive if there exists a Turing machine that accepts the strings belonging
to that language and rejects on every string that are not belonging to that language. Every regular
set is not recursive.

5. Differentiate between recursive and recursively enumerable languages. (Apr/May-07)

Recursive
 A language L is said to be recursive if there exists a Turing machine M that accepts L,
and goes to halt state or else M rejects L.
W
Accept
TM
Reject
Input
string
 The recursive languages are called Turing decidable languages.
 Recursive language will halt on every input.
 Every recursive language is also a recursively enumerable.
 If L is recursive language then its complement L’ is also recursive.
Recursively Enumerable
 A language is recursively enumerable if there exists a Turing Machine that accepts every
string of the language and does not accept strings that are not in the language.
W
Accept
TM
Loops for ever
Input string

 The RE is called Turing acceptable languages.


 RE may not halt on every input; it may fall into an infinite loop.
 Every RE language is not recursive.
 There exist RE language L whose complement L’ may not be RE.
 If L and L’ both are recursively enumerable then that L is definitely a recursive
language.

6. When do you say a problem is NP-hard? (Dec-09)

A problem is said to be NP-hard is an algorithm for solving it can be translated into a problem
which is a NP problem. Thus NP-hard is a algorithm for a problem which is at least as hard as
any NP-problem.
For example – Sum of subset problem, travelling salesperson problem.

7. State two languages, which are not recursively enumerable. (Dec-09)

Diagonalization language is not recursively enumerable.


The partially decidable languages or undecidable languages are not recursively enumerable.

2
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
For instance: for given input whether the TM will eventually halt is or not?
This is undecidable and hence is not recursively enumerable.

8. Mention the difference between P and NP problems. (May-12)

P class problems are those problems which can be solved in polynomial time.
For example – The sorting and searching problems are P class problems.
NP class problems are those problems which can be solved in non-deterministic polynomial
time.
For example – Traveling Salesperson Problems, graph coloring problem. The NP
class problems can be NP-Complete and NP – hard problems.

9. What is recursively enumerable? (May-12,Nov/Dec-13)


When is a language said to be recursively enumerable? April/May 2018

A language is recursively enumerable if there exists a Turing Machine that accepts every
string of the language and does not accept strings that are not in the language.
W
Accept
TM
Loops for ever
Input string

10. What are a) Recursively Enumerable b) Recursive sets? (Nov/Dec-13)


Recursively Enumerable
A language is recursively enumerable if there exists a Turing Machine that accepts every
string of the language and does not accept strings that are not in the language.

W
Accept
TM
Loops for ever
Input string

Recursive sets
A language is said to be recursive if there exists a Turing machine that accepts the strings
belonging to that language and rejects on every string that are not belonging to that
language. Every regular set is not recursive.

11. Define the class NP problem. (Nov/Dec-13)

The NP stands for non-deterministic polynomial time. That means all the problems in this
class are solved in non deterministic polynomial time. The problems belonging to this class
are - Traveling salesperson problems, graph coloring problem and Knapsack problem.

12. What do you mean by universal Turing machine? (Nov/Dec-05,13)

Universal Turing machine is a type of TM which is capable of doing anything that any other
TM can do. That means universal TM is a TM that imitates any TMT.

3
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

13. Define the classes P and NP problems. (May-14)


Define the classes P and NP problem. Give example problems for both. Nov/Dec 2020

P class problems - problems that can be solved in ―polynomial time ―are called P
class problems. For example – The sorting and searching problems.
NP class problems - problems that can be solved in non-deterministic polynomial time. For
example – Traveling salesperson problems, graph coloring problem. The NP class problems
can be NP-Complete and NP – hard problems.

14. Give examples for NP-complete Problems.

The NP- complete problems are – Traveling salesperson problems, graph coloring
problem.0/1 knapsack problem, Hamiltonian circuit problem.

15. When we say a problem is decidable? (Or) Define Decidable Problem.

A problem whose language is recursive is said to be decidable. Otherwise the problem is


said to be undecidable. Decidable problems have an algorithm that takes as input an instance
of the problem and determines whether the answer to that instance is ―yes‖ or ―no‖.

16. Define Undecidable language.


The problem is Undecidable if there is no algorithm and we cannot predict whether the input is
accepted by Turing machine or not. Undecidable problem exist if and only if there exists no
algorithm to solve the problem in finite time.

17. Define (a) Recursively Enumerable languages. (b) Recursive Sets.


The languages accepted by Turing machines are called recursively enumerable (RE), and the
subset of RE languages that are accepted by a TM that always halts are called recursive.
Enumerable means that the strings in the language can be enumerated by the TM. The class of
recursively enumerable languages includes CFL’s.
The recursive sets include languages accepted by at least one TM that halts on all inputs.

18. Define Recursive language. (Or) What are recursive languages? Nov/Dec 2020

The languages accepted by Turing machines are called recursively enumerable (RE), and the
subset of RE languages that are accepted by a TM that always halts are called recursive.

19. When a recursively enumerable language is said to be recursive? Is it true that the
language accepted by a non-deterministic Turing machine is different from recursively
enumerable language? (May/June 2016)

A language L is recursively enumerable if there is a TM that accepts L and recursive if there is


a TM that recognizes L. Thus recursively enumerable language is Turing acceptable and
recursive language is Turing decidable languages. No, the language accepted by non-
deterministic Turing machine is same as recursively enumerable language.
4
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

20. What is Church’s Hypothesis?


The notion of computable function can be identified with the class of partial recursive
functions is known as Church-hypothesis or Church-Turing thesis. The Turing machine is
equivalent in computing power to the digital computer.

21. Give an example of undecidable problem.


The undecidable problems are
 Halting problem of the TM.
 Undecidability of ambiguity of CFG’s
 Complement of a list language
 Problems about problem

22. Define Universal Turing machines. (Nov/Dec 2016)


What do you mean by Universal Turing machine? April/May 2018

It is easiest to describe U as a multitape Turing machine(Refer Fig:5.2). In the case of


U, the transitions of M are stored initially on the first tape, along with the string w. A second
tape will be used to hold the simulated tape of M, using the same format as for the code of M.
That is, tape symbol Xi of M will be represented by 0 i, and tape symbols will be separated by
single l's. The third tape of U holds the state of M, with state qi represented by i 0's. A sketch of
U is in Fig.

Figure 5.2 – universal Turing Machine


Universal TMs are TMs that can be programmed to solve any problem, which can be solved by any
Turing machine. A specific Universal Turing machine U is:
Input to U: The encoding ―M‖ of a TM M and encoding ―w‖ of a string w.
Behavior: U halts on input ―M‖ ―w‖ if and only if M halts on input w.
23. What properties of recursive enumerable sets are not decidable?
 Emptiness.
 Finiteness.
 Regularity.
 Context-freedom.
5
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

24. What is a universal language Lu? (Nov/Dec 2015)

The Universal Language: The language Lu consists of strings that are interpreted as a TM
followed by an input for that TM. The string is in Lu if the TM accepts that input. Lu is a good
example of a language that is RE but not recursive.

25. What is a Diagonalization language Ld?

The language Ld, the ―diagonalization‖ language, is the set of strings wi such that wi is not
in L(Mi). That is, Ld consists of all strings w such that the TM M whose code is w does not accept
when given w as input.
The reason La is called a "diagonalization" language can be seen if we consider Fig (5.3).
This table tells for all i and j, whether the TM Mi accepts input string wj: 1 means "yes it does" and
0 means "no it doesn't." We may think of the ith row as the characteristic vector for the language
L(Mi); that is, the 1's in this row indicate the strings that are members of this language.

Figure 5.3 - Diagonalization


26. What properties of RE sets are recursively enumerable?

 L ≠Φ
 L contains at least 10 members.
 w is in L for some fixed w.
 L ∩ Lu ≠ Φ

27. What properties of recursively enumerable sets are not recursively enumerable?
 L=Φ
 L = Σ *.
 L is recursive
 L is not recursive.
 L is singleton.
 L is a regular set.
 L - Lu ≠ Φ.
6
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

28. What are the different types of grammars/languages?


 Unrestricted or Phase structure grammar.(Type 0 grammar).(for TMs)
 Context sensitive grammar or context dependent grammar (Type1) (for Linear Bounded
Automata )
 Context free grammar (Type 2) (for PDA)
 Regular grammar (Type 3) (for Finite Automata).
 This hierarchy is called as Chomsky Hierarchy.

29. Show that AMBIGUITY problem is undecidable.

Consider the ambiguity problem for CFGs. Use the ―yes-no‖ version of AMB. An algorithm
for FIND is used to solve AMB. FIND requires producing a word with two or more parses if one
exists and answers ―no‖ otherwise. By the reduction of AMB to FIND we conclude there is no
algorithm for FIND and Hence no algorithm for AMB.

30. Define PCP or Post Correspondence Problem.

An instance of Post's Correspondence Problem (PCP) consists of two lists of strings over
some alphabet Σ; the two lists must be of equal length. We generally refer to the A and B lists, and
write A=w1, w2…. wk and B=x1, x2…. xk for some integer k. For each i, the pair (wi , xi) is said to
be a corresponding pair.
We say this instance of PCP has a solution, if there is a sequence of one or more integers i 1
,i2,…. im that, when interpreted as indexes for strings in the A and B lists, yield the same string.
That is, wi1, wi2….. wim, = xi1, xi2,….. xim. We say the sequence i1 ,i2,…. im is a solution to this
instance of PCP, if so.

31. Define MPCP or Modified PCP.

It is easier to reduce Lu to PCP if we first introduce an intermediate version of PCP, which


we call the Modified Post's Correspondence Problem, or MPCP. In the modified PCP, there is the
additional requirement on a solution that the first pair on the A and B lists must be the first pair in
the solution. More formally, an instance of MPCP is two lists. A=w1, w2…. wk and B=x1, x2…. xk
and a solution is a list of 0 or more integers i1 ,i2,…. im such that
wi1, wi2….. wim, = xi1, xi2,….. xim.
Notice that the pair (w1, x1) is forced to be at the beginning of the two strings, even though the
index 1 is not mentioned at the front of the list that is the solution. Also, unlike PCP, where the
solution has to have at least one integer on the solution list, in MPCP, the empty list could be a
solution if wi = xi (but those instances are rather uninteresting and will not figure in our use of
MPCP).

32. What is the difference between PCP and MPCP?

This question asks, given two lists of the same number of strings, whether we can pick a
sequence of corresponding strings from the two lists and form the same string by concatenation.
PCP is an important example of an undecidable problem. PCP is a good choice for reducing to other
problems and thereby proving them undecidable. The difference between MPCP and PCP is that in
the MPCP, a solution is required to start with the first string on each list.
7
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

33. What are the concepts used in UTMs?


 Stored program computers.
 Interpretive Implementation of Programming languages.
 Computability.

34. When a language is said to be recursively enumerable or recursive? (may-05,13,14)

A language is recursively enumerable if there exists a Turing Machine that accepts every
string of the language and does not accept strings that are not in the language.

W
Accept
TM
Loops for ever
Input string
A language L is said to be recursive if there exists a Turing machine M that accepts L, and
goes to halt state or else M rejects L.
W
Accept
TM
Reject
Input
string
35. Define decidability (or) decidable problems or Computable Problems.

There exists some algorithm that computes an answer (or output) to any instance of the
problem (or for any input to the function) in a finite number of simple steps. A simple example
is the integer increment operation: f(x) = x + 1.

Some Examples Of Computable Problems – These are four simple examples of the
computable problem:
 Computing the greatest common divisor of a pair of integers.
 Computing the least common multiple of a pair of integers.
 Finding the shortest path between a pair of nodes in a finite graph.
 Determining whether a propositional formula is a tautology.

36. Define undecidability (or) undecidable problems or Non Computable Problems.


[Nov/Dec 2024]

A non-computable is a problem for which there is no algorithm that can be used to solve it. The
most famous example of a non-computability (or undecidability) is the Halting Problem.

Given a description of a Turing machine and its initial input, determine whether the program,
when executed on this input, ever halts (completes)

Some Examples of Non Computable Problems

 Does a given Turing machine M halts on all input?


 Does Turing machine M halt for any input?
 Is the language L(M) finite?
 Does L(M) contain a string of length k, for some given k?
8
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
 Do two Turing machines M1 and M2 accept the same language?

36. Define trivial property.


A property is trivial if it is either empty of is all RE languages.
37. Define Rice Theorem?
Rice's Theorem: Any non trivial property of the languages accepted by Turing machines is
undecidable. For instance, the net of codes for Turing machines whose language is empty is
undecidable by Rice's theorem. In fact, this language is not RE, although its complement — the set
of codes for TM's that accepts at least one string — is RE but not recursive.
38. Let A and B be lists of three strings each, as defined in the following table?

Find the instance of post correspondence Problem.


Solution: Let Σ = {0,1}, and let the A and B lists. In this case, PCP has a solution. For instance, let
m = 4, i1 = 2, i2 = 1, i3 = 1, and i4 = 3; (i.e.,) the solution is the list 2, 1, 1, 3. We verify that this list
is a solution by concatenating the corresponding strings in order for the two lists. That is, w1, w2….
wk and x1, x2…. xk = 01111110. Note this solution is not unique. For instance, 2, 1, 1, 3, 2, 1, 1, 3 is
another solution.

39. Define problem solvable in polynomial Time.


A Turing Machine M is said to be of time complexity T(n) if whenever m given an input w
of length n, m halts after making atmost T(n) moves, regardless of whether or not m accepts.

40. Define the classes P and NP. (May-14)


P consists of all those languages or problems accepted by some Turing Machine that runs in
some polynomial amount of time, as a function of its input length. NP is the class of languages or
problems that are accepted by Nondeterministic TM’s with a polynomial bound on the time taken
along any sequence of non – deterministic choices.

41. Define NP – Complete Problem.


A language is NP-complete if it is in NP, and there is a polynomial-time reduction from
each language in NP to the language in question. We believe strongly that none of the NT-complete
problems are in P, and the fact that no one has ever found a polynomial- time algorithm for any of
the thousands of known NP-complete problems is mutually re-enforcing evidence that none are in
P.
A language L is NP – complete if the following statements are true.
a. L is in NP
b. For every language L’ in NP there is a polynomial time reduction of L’ to L

9
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
42. What are the properties of recursive and Recursively Enumerable Language?
List the properties of recursive and recursive enumerable language. Nov/Dec 2017
1. The complement of a Recursive language is Recursive.
2. The union of two recursive languages is recursive.
3. The union of two RE languages is RE.
4. If a language L and complement L are both RE, then L is recursive.

43. Define Unsolvability. [Nov/Dec 2024]


In the theory of computation we often come across such problems that are answered either
yes or no. The class of problems which can be answered as yes are called solvable or decidable,
otherwise the class of problems is said to be unsolvable or undecidable.

44. Define Tractable and Intractable problems. [Nov/Dec 2024][April/May 2024]


The class of solvable problems is known as decidable problems. That means decidable
problems can be solved in measurable amount of time or space.
The Tractable problems are the class of problems that can be within reasonable time and
space. The Intractable problems are the class of problems that can be solved within polynomial
time. This has lead to two classes of solving problems – P and NP class problems.
45. Identify whether Tower of Hanoi’ problem is tractable or intractable. Justify your answer.
(May/June 2016)
Solution: Yes, Tower of Hanoi’ problem is tractable
Tower of Hanoi puzzle
 The tower, there are n disks of different sizes, and three pegs.
 Initially all the disks are on the first peg in order if size, the largest on the bottom
and the smallest on the top.
 The goal is to move all the disks from peg 1 to peg 3 using peg 2 as auxiliary.
 One disk should be moved at a time and do not place a larger disk on top of a
smaller one.(Refer Fig:5.4)
The following steps are used to move n>1 disks from peg 1 to peg 3, peg 2 as auxiliary.
1. Move n-1 disks recursively from peg 1 to peg 3.( peg 2 as auxiliary).
2. Move the largest disk directly from peg 1 to peg 3.
3. Move n-1 disks recursively from peg 2 to peg 3.( peg 2 as
auxiliary).
For example, if n=1 then the single disks is moved from source peg to destination peg directly.

A B C

10
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Figure 5.4 – Towers of Hanoi
General plan to tower of Hanoi problem
The input size is the number of disks ―n‖.
The algorithm basic operation is moving one disks at a time.
The number of moves M(n) depends only on n.

46. What is primitive recursion function? (April/May 2017)


Definition:
 Let n≥0, g and h are functions of n and n+2 variables respectively.
 The functions abtained from g and h by the operation of primitive recursion is the function
f:Nn+1  N defined by the formula
f(x,0)=g(x)
f(x,k+1)=h(x,k,f(x,k)) ≦ x€ Nn and k≥0
47. Define NP-hard and NP-Completeness problem. (Nov/Dec 2016) (April/May 2017)
NP hard
A problem is said to be NP-hard is an algorithm for solving it can be translated into a problem
which is a NP problem. Thus NP-hard is a algorithm for a problem which is at least as hard as
any NP-problem.
For example – Sum of subset problem, travelling salesperson problem.
NP completeness

A decision problem c is NP-complete if:

1. c is in NP, and
2. Every problem in NP is reducible to c in polynomial time.
c can be shown to be in NP by demonstrating that a candidate solution to c can be verified in
polynomial time.

Note that a problem satisfying condition 2 is said to be NP-hard, whether or not it satisfies
condition 1.A consequence of this definition is that if we had a polynomial time algorithm (on
a UTM, or any other Turing-equivalent abstract machine) for c, we could solve all problems in NP
in polynomial time.

48. Write abort notes on tractable problem. Nov/Dec 2017


The Tractable problems are the class of problems that can be within reasonable time and space.

49. What are the two classes of problems that are solved by the Turing machine?
The two classes of problems that can be solved by the Truing machines are as follows.
1. Those problems that have an algorithm

2. Those that are only solved by Turing machine.

11
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

50. When we say a problem is decidable? (Or) Define Decidable Problem.


A problem whose language is recursive is said to be decidable. Otherwise the problem is said to be
undecidable. Decidable problems have an algorithm that takes as input an instance of the problem
and determines whether the answer to that instance is ―yes‖ or ―no‖.

51. Define Undecidable language. [Nov/Dec 2024]


The problem is Undecidable if there is no algorithm and we cannot predict whether the input
is accepted by Turing machine or not. Undecidable problem exist if and only if there exists no
algorithm to solve the problem in finite time.

52. What is the weak-form of Turing thesis?


A Turing Machine can compute anything that can be computed by a general purpose digital
computer.

53. What is the strong-form of Turing thesis?

A Turing Machine can compute anything that can be computed. This is the strong form of Turing
thesis.

54. When a language is said to be recursively enumerable?

A language is recursively enumerable if there exists a Turing Machine that accepts every string of
the language and does not accept strings that are not in the language.

55. When a language is said to be recursive?

A language L is said to be recursive if there exists a Turing machine M that accepts L, and goes to
halt state or else M rejects L.

56. What are the reasons for a TM not accepting its input?
i) The TM may halt in a non final state.
ii) The TM may enter into an indefinite loop.

57. State Post’s correspondence problem. Nov/Dec2021


An instance of Post's Correspondence Problem (PCP) consists of two lists of strings over
some alphabet Σ; the two lists must be of equal length. We generally refer to the A and B lists, and
write A=w1, w2…. wk and B=x1, x2…. xk for some integer k. For each i, the pair (wi , xi) is said to
be a corresponding pair.
We say this instance of PCP has a solution, if there is a sequence of one or more integers i1
,i2,…. im that, when interpreted as indexes for strings in the A and B lists, yield the same string.
That is, wi1, wi2….. wim, = xi1, xi2,….. xim. We say the sequence i1 ,i2,…. im is a solution to this
instance of PCP, if so.

12
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
58. Define SAT problem.
Boolean Satisfiability or simply SAT is the problem of determining if a Boolean formula is
satisfiable or unsatisfiable.
 Satisfiable : If the Boolean variables can be assigned values such that the formula t urns
out to be TRUE, then we say that the formula is satisfiable.
 Unsatisfiable : If it is not possible to assign such values, then we say that the formula is
unsatisfiable.
Examples:

is satisfiable, because A = TRUE and B = FALSE makes F = TRUE.

is unsatisfiable.

59. Define 2 SAT problem.


2-SAT is a special case of Boolean Satisfiability Problem and can be solved
in polynomial time.
2-SAT limits the problem of SAT to only those Boolean formula which are expressed as a CNF
with every clause having only 2 terms (also called 2-CNF).
Example:

60. Define Conjunctive Normal Form.

A boolean expression is said to be in CNF form if it’s a conjunction of a set of clauses, where each
clause is defined as a disjunction (logical OR) of literals. We can define a literal as a variable or a
negation of a variable.
Example:

61. Define 3 SAT problem.

SAT3 problem is a special case of SAT problem, where Boolean expression should have very strict
form. It should be divided to clauses,such that every clause contains of three literals.

For example,

(x1∨x2∨x3)∧(x4∨x5∨x6)
This Boolean expression in 3SAT form, 2 clauses, each clause contains of 3 literals.

The 3-SAT problem is part of the Karp’s 21 NP-complete problems and is used as the starting point
to prove that the other problems are also NP-Complete. One example is the independent set

13
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
problem. The Independent Set Problem can be shown to be NP-Complete by showing that the 3-
SAT is polynomially reducible to an independent set problem.

62. Differentiate 2-SAT and 3-SAT.

2-SAT

 2-SAT is in P and in NP.

 if any problem in P (or in NP) is not NP complete, then P!=NP.

 so if 2-SAT is not NP-complete, then P!=NP.

 if P!=NP, then NP-complete problems are not in P.


 so if 2-SAT is not NP-complete, then P!=NP and 3-SAT (being NP-complete) is not in P
 3-SAT

 3-SAT is NP-complete.

 if an NP-complete problem is in P, then P=NP.

 if P=NP, then every problem in P is NP-complete.

 2-SAT is in P (and in NP).


 so if 3-SAT is in P, then P=NP and every P (and NP) problem is NP-complete, including 2-
SAT.

14
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

PART-B
A Language That is not recursively Enumerable

Codes for Turing Machines (Nov/Dec 2005) (May/June 2007)


1. Obtain the code for the TM
M = ({q1, q2, q3}, {0, 1), {0, 1, B}, δ, q1 , B, {q2})

Where δ consists of the rules!

δ(q1,1) = (q3, 0, R)

δ(q3, 0) = (q1, 1, R)

δ(q3, 1) = (q2, 0, R)

δ(q3, B) = (q3, 1, L) (Nov/Dec 2005) (May/June 2007)

Solution:
Enumerating the Binary Strings
· In what follows, we shall need to assign integers to all the binary strings so that each string
corresponds to one integer, and each integer corresponds to one string.
· If w is a binary string, treat 1w as a binary integer i. Then we shall call is the ith string. That
is, c is the first string, 0 is the second, 1 the third, 00 the fourth, 01 the fifth, and so on.
· Equivalently, strings are ordered by length, and strings of equal length are ordered
lexicographically. Hereafter, we shall refer to the ith string as wi
Codes for Turing Machines
· Universal TMs are TMs that can be programmed to solve any problem, which can be solved
by any Turing machine.
· A specific Universal Turing machine U is:
o Input to U: The encoding ―M‖ of a TM M and encoding ―w‖ of a string w.
o Behavior: U halts on input ―M‖ ―w‖ if and only if M halts on input w.
· Our next goal is to devise a binary code for Turing machines so that each TM with input
alphabet {0, 1} may be thought of as a binary string. Since we just saw how to enumerate
the binary strings, we shall then have an identification of the Turing machines with the
integers, and we can talk about the ith Turing machine, Mi.
1. To represent a TM M = (Q, {0, 1}, Γ, δ, q1, B, F) as a binary string, we must first assign
integers to the states, tape symbols, and directions L and R.
2. We shall assume the states are q1, q2, ...,qk for some k. The start state will always be q1,
and q2 will be the only accepting state.
· Note that, since we may assume the TM halts whenever it enters an accepting state,
there is never any need for more than one accepting state.
· We shall assume the tape symbols are X1, X2, ...,Xm for some value m.
i. X1 always will be the symbol 0,
ii. X2 will be 1, and
iii. X3 will be B, the blank.
15
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

· However, other tape symbols can be assigned to the remaining integers arbitrarily.
3. We shall refer to direction L as D1 and direction R as D2.
· Since each TM M can have integers assigned to its states and tape symbols in many
different orders, there will be more than one encoding of the typical TM. However, that
fact is unimportant in what follows, since we shall show that no encoding can represent
a TM M such that L(M) = Ld.
· Once we have established an integer to represent each state, symbol, and direction, we
can encode the transition function δ.
· Transition rule is δ(qi, Xj) (qk, Xl, Dm), for some integers i, j, k, l, and m.
· We shall code this rule by the string 0i10j10k10l10m.
· Notice that, since all of i, j, k, l, and m are at least one, there are no occurrences of two
or more consecutive l's within the code for a single transition.
· A code for the entire TM M consists of all the codes for the transitions, in some order,
Separated by pairs of 1's,
C111C211…..C n-111Cn
Where each of the C's is the code for one transition of M.
Example 1: Let the TM in question be
M = ({q1, q2, q3}, {0, 1), {0, 1, B}, δ, q1 , B, {q2})
where δ consists of the rules!

δ(q1,1) = (q3, 0, R)

δ(q3, 0) = (q1,1, R)

δ(q3, 1) = (q2, 0, R)

δ(q3, B) = (q3, 1, L)

The codes for each of these rules, respectively, are:


0100100010100 0001010100100
00010010010100 0001000100010010
For example:
· The first rule can be written as δ(q1 , X2) = (q3,X1, D2)
· Since 1 = X2, 0 = X1 and R = D2.
· Thus, its code is 01102103101102.
· A code for M is:

01001000101001100010101001001100010010010100110001000100010010

· Note that there are many other possible codes for M. In particular, the codes for the four
transitions may be listed in any of 4! Orders, giving us 24 codes for M.
· Code the pairs consisting of a TM and a string, (M, w).
· For this pair we use the code for M followed by 111, followed by w.

 Note that, since no valid code for a TM contains three l's in a row, we can be sure that the
16
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
first occurrence of 111 separates the code for M from to.
· For instance, if M were the TM of Example 9.1, and to were 1011, then the code for (M, w)
would be the string shown at the end of Example 9.1 followed by 1111011.

3. Prove that the diagonalization language (L d) is not a recursively enumerable.


April/May 2018
OR
State and prove that “Diagonalization language is not recursively enumerable”.
Nov/Dec2021

THE DIAGONALIZATION LANGUAGE


· We coded Turing machines so there is now a concrete notion of M1, the ― ith Turing
machine": that TM M whose code is to: the ith binary string. Many integers do not
correspond to any TM at all.
· For instance, 11000 does not begin with 0, and 0010111010010100 is not valid because it
has three consecutive 1’s.
· If wi is not a valid TM code, we shall take Mi to be the TM with one state and no
transitions. That is, for these values of i, Mi is a Turing machine that immediately halts on
any input. Thus, L(Mi) is φ if wi fails to be a valid TM code.
Vital definition:
· The language Ld, the ―diagonalization‖ language, is the set of strings wi such that to; is not
in L(Mi). That is, Ld consists of all strings w such that the TM M whose code is w does not
accept when given w as input.
· The reason La is called a "diagonalization" language can be seen if we consider Fig (5.5).
This table tells for ail i and j, whether the TM Mi accepts input string wj: 1 means "yes it
does" and 0 means "no it doesn't". We may think of the ith row as the characteristic
vector for the language L(Mi); that is, the 1's in this row indicate the strings that are
members of this language.

Figure (5.5) the table that represents acceptance of strings by Turing machines
· The diagonal values tell whether M, accepts w. To construct Ld, we complement the
diagonal.
· For instance, the complemented diagonal would begin 1, 0, 0, 0, .... .
· Thus, La would contain w1= Є, not contain w2 through w4, which are 0, 1, and 00, and so
on.
· The trick of complementing the diagonal to construct the characteristic vector of a language
17
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
that cannot be the language that appears in any row is called diagonalization.
· It works because the complement of the diagonal is itself a characteristic vector describing
membership in some language, namely Ld

3. Prove that Ld is not Recursively Enumerable (Apr/May 2004) (Nov/Dec 2004),


(Apr/May 2005) (Nov/Dec 2005) (May/June 2006), (Nov/Dec 2008) (OR)
Define the language Ld. Show that Ld is not recursively enumerable? (Apr/May 2004)
(Nov/Dec 2004) (Apr/May 2005)
Theorem : Ld is not a Recursively Enumerable Language. That is, there is no Turing machine that
accepts Ld.
Proof: Suppose Ld is accepted by some Turing machine M defined by L(M). Since L d is a language
over alphabet {0, 1} M would be in the list of Turing machines that we have constructed. Since it
includes all Turing machine with input alphabet {0,1}. Thus, there is at least one code for M, say i;
that is M=Mi.
Now, ask if wi is in Ld.
· If wi is in Ld, then Mi accepts wi. But then, by definition of Ld, wi is not in Ld, because Ld
contains only those wj such that Mj does not accept wj.
· Similarly, if wi is not in Ld, then Mi does not accept wi, Thus, by definition of Ld, wi is in Ld.
Since wi can neither be in Ld nor fail to be in Ld, we conclude that there is a contradiction of our
assumption that M exists. That is, Ld is not a recursively enumerable language.
Undecidability of the Universal Language
We can now exhibit. A problem that is RE but not recursive; it is the language Lu. Knowing
that Lu is undecidable (i.e., not a recursive language) is in many ways more valuable than our
previous discovery that Ld is not RE.
The reason is that the reduction of Lu to another problem P can be used to show there is no
algorithm to solve P, regardless of whether or not P is RE. However, reduction of L d to P is only
possible if P is not RE, so Ld cannot be used to show undecidability for those problems that are RE
but not recursive. On the other hand, if we want to show a problem not to be RE, then only L d can
be used; Lu is useless since it is RE.

AN UNDECIDABLE PROBLEM THAT IS RE

4. Show that an Undecidable problem that is RE.


1. Recursive Languages

We call a language L recursive if L = L(M) for some Turing machine M such that:
1. If w is in L, then M accepts (and therefore halts).
2. If w is not in L, then M eventually halts, although it never enters an accepting state.

A TM of this type corresponds to our informal notion of an "algorithm," a well-defined sequence of


steps that always finishes and produces an answer. If we think of the language L as a "problem," as
will be the case frequently, then problem L is called decidable if it is a recursive language, and it is
called undecidable if it is not a recursive language.

18
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Figure (5.6) Relationship between the recursive, RE, and non-RE languages

The existence or nonexistence of an algorithm to solve a problem is often of more


importance than the existence of some TM to solve the problem. As mentioned above, the Turing
machines that are not guaranteed to halt may not give us enough information ever to conclude that a
string is not in the language, so there is a sense in which they have not "solved the problem." Thus,
dividing problems or languages between the decidable — those that are solved by an algorithm —
and those that are undecidable is often more important than the division between the recursively
enumerable languages (those that have TM's of some sort) and the non-recursively-enumerable
languages (which have no TM at all).

Figure 5.6 suggests the relationship among three classes of languages:


1. The recursive languages.
2. The languages that are recursively- enumerable but not recursive.
3. The non-recursively-enumerable (non-RE) languages.

We have positioned the non-RE language L5 properly, and we also show the language L, or
"universal language," that we shall prove not to be recursive, although it is RE.

2 Complements of Recursive and RE languages

A powerful tool in proving languages to belong in the second ring of Fig. 5.6 (i.e., to be RE,
but not recursive) is consideration of the complement of the language. We shall show that the
recursive languages are closed under complementation. Thus, if a language L is RE, but L’, the
complement of L, is not RE, then We know L cannot be recursive. For if L were recursive, then L’
would also be recursive and thus surely RE.

We now prove this important closure property of the recursive languages.

Theorem 9.3: If L is a recursive language, so is L’.

Proof: Let L=L(M) for some TM Al that always halts. We construct a TM M’ such that L’= L(M’)
1. The accepting states of M are made non-accepting states of M with no transitions; i.e., in
these states M will halt without accepting.
2. M’ has a new accepting state r; there are no transitions from r.
19
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
3. For each combination of a non accepting state of M and a tape symbol of Al such that M has
no transition (i.e., M halts without accepting), add a transition to the accepting state r.

Figure (5.7) Construction of a TM accepting the complement of a recursive language

Since M is guaranteed to halt, we know that M is also guaranteed to halt. Moreover, M’


accepts exactly those strings that M does not accept. Thus M’ accepts L’.

Show that if a language L and its complement L’ are both recursively enumerable then L is
recursive.

(Nov/Dec 2003) (Nov/Dec 2004) (Apr/May2005) (May/June 2006) (Nov/Dec 2006) (May/June
2007) (Nov/Dec 2007)

Theorem (9.4): If both a language L and its complement are RE, then L is recursive.

Proof: Let L=L(M1) and L’= L(M2). Both M1 and M2 are simulated in parallel by a TM M. We can
make M a two-tape TM, and then convert it to a one-tape TM, to make the simulation easy and
obvious. One tape of M simulates the tape of M1, while the other tape of Al simulates the tape of
M2. The states of M1 and M2 are each components of the state of M.

Figure (5.8) Simulation of two TM's accepting a language and its complement

If input w to M is in L, then Mi will eventually accept. If so, M accepts and halts. If w is not
in L, then it is in L’, so M2 will eventually accept. When M2 accepts, M halts without accepting.
Thus, on all inputs, M halts, and L(M) is exactly L. Since M always halts, and L(M) = L, we
conclude that L is recursive.

20
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
We may summarize Theorems 9.3 and 9.4 as follows.

A language L and its complement L in the diagram of Fig. 9.2, only the following four are possible:
1. Both L and I, are recursive; i.e., both are in the inner ring.
2. Neither L nor L’ is RE; i.e., both are in the outer ring.
3. L is RE but not recursive and L’ is not RE; i.e., one is in the middle ring and the other is in
the outer ring.
4. L’ is RE hut not recursive, and L is not RE; i.e., the same as (3), but with L and L’ swapped.

In proof of the above, Theorem (9.3) eliminates the possibility that one language (L or L) is
recursive and the other is in either of the other two classes. Theorem (9.4) eliminates the possibility
that both are RE but not recursive.

Example: As an example, consider the language Ld, which we know is not RE. Thus, Ld could not
be recursive. It is, however, possible that Ld’ could be either non-RE or RE but not-recursive. Ld’ is
the set of strings wi such that Mi accepts wi.

This language is similar to the universal language Lu, consisting of all pairs (M, w) such that M
accepts w, the same argument can be used to show Ld’ is RE.

5. What is a universal Turing machine? Bring out its significance. Also construct a Turing
machine to add two numbers and encode it.(Nov/Dec 2024]
Explain universal Turing Machine. Nov/Dec 2017(Nov/Dec 2003), (Apr/May 2005)
(Nov/Dec 2005) (May/June 2006) (Nov/Dec 2006)
We already discussed how a Turing machine could be used to simulate a computer that had
been loaded with an arbitrary program. That is to say, a single TM can be used as a "stored program
computer," taking its program as well as its data from one or more tapes on which input is placed.
In this section, we shall repeat the idea with the additional formality that comes with talking
about the Turing machine as our representation of a stored program.
We define Lu, the universal language, to be the set of binary strings that encode, a pair (M,
w), where M is a TM with the binary input alphabet, and w is a string in (0+1)*, such that w is in
L(M). That is, Lu is the set of strings representing a TM and an input accepted by that TM. We shall
show that there is a TM U, often called the universal Turing machine, such that, Lu = L(U). Since
the input to U is a binary string, U is in fact some M in the list of binary-input Turing machines.
It is easiest to describe U as a multitape Turing machine. In the case of U, the transitions of
M are stored initially on the first tape, along with the string w. A second tape will be used to hold
the simulated tape of M, using the same format as for the code of M. That is, tape symbol Xi of M
will be represented by 0 i, and tape symbols will be separated by single l's. The third tape of U holds
the state of M, with state qi represented by i 0's. A sketch of U is in Fig.5.9

21
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Figure 5.9: Organization of a universal Turing machine

The operation of U can be summarized as follows:


1. Examine the input to make sure that the code for M is a legitimate code for some TM. If not,
U halts without accepting. Since invalid codes are assumed to represent the TM with no
moves, and such a TM accepts no inputs, this action is correct.
2. Initialize the second tape to contain the input w, in its encoded form. That is, for each 0 of
w, place 10 on the second tape, and for each 1 of w, place 100 there.
Note that the blanks on the simulated tape of M, which are represented by 1000, will not
actually appear on that tape; all cells beyond those used for w will hold the blank of U.
However, U knows that, should it look for a simulated symbol of M and find its own blank,
it must replace that blank by the sequence 1000 to simulate the blank of M.
3. Place 0, the start state of M, on the third tape, and move the head of Ws second tape to the
first simulated cell.
4. To simulate a move of M, U searches on its first tape for ,a transition 0i10i10k10110m, such
that 0i is the state on tape 3, and 0j is the tape symbol of M that begins at the position on tape
2 scanned by U. This transition is the one M would next make.
U should follow:
(a) Change the contents of tape 3 to 0k that is, simulate the state change of M. To do so, U first
changes all the 0's on tape 3 to blanks, and then copies 0 k from tape 1 to tape 3.
(b) Replace 0j on tape 2 by 0k; that is, change the tape symbol of M. If more or less space is
needed (i.e., i =1), use the scratch tape and the shifting-over technique to manage the spacing.
(c) Move the head on tape 2 to the position of the next 1 to the left or right, respectively,
depending on whether m = 1 (move left) or m= 2 (move right). Thus, U simulates the move of
M to the left or to the right.
5. If M has no transition that matches the simulated state and tape symbol, then in (4), no
transition will be found. Thus, M halts in the simulated configuration, and U must do
likewise.
6. If M enters its accepting state, then U accepts.
7. In this manner, U simulates M on w. U accepts the coded pair (M,w) if and only if M
accepts w.

22
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Undecidability of the Universal Language

We can now exhibit. A problem that is RE but not recursive; it is the language Lu. Knowing
that Lu is undecidable (i.e., not a recursive language) is in many ways more valuable than our
previous discovery that Ld is not RE. The reason is that the reduction of Lu to another problem P
can be used to show there is no algorithm to solve P, regardless of whether or not P is RE.
However, reduction of Ld to P is only possible if P is not RE, so Ld cannot be used to show
undecidability for those problems that are RE but not recursive. On the other hand, if we want to
show a problem not to be RE, then only Ld can be used; Lu is useless since it is RE.

6. Prove that the undecidability Universal language is recursively enumerable but not recursive
(OR) Define the Language Lu. Show that Lu is recursively enumerable but not recursive.
(Nov/Dec 2003) (Apr/May 2004) (Apr/May 2005) (Nov/Dec 2005) (May/June 2006) (Nov/Dec
2006) (May/June 2009)[Nov/Dec 2024]
Prove that universal language is recursively enumerable but not recursive. Nov/Dec 2020

We can now exhibit. A problem that is RE but not recursive; it is the language Lu. Knowing
that Lu is undecidable (i.e., not a recursive language) is in many ways more valuable than our
previous discovery that Ld is not RE. The reason is that the reduction of Lu to another problem P
can be used to show there is no algorithm to solve P, regardless of whether or not P is RE.
However, reduction of Ld to P is only possible if P is not RE, so Ld cannot be used to show
undecidability for those problems that are RE but not recursive. On the other hand, if we want to
show a problem not to be RE, then only Ld can be used; Lu is useless since it is RE.
Theorem : Lu is RE (Recursively Enumerable) but not recursive.
Proof: We Suppose Assume Lu is recursive. Then Lu, is the complement of Lu’, would also be
recursive. However, if we have a TM M to accept Lu’, then we can construct a TM to accept Ld.
Since we already know that Ld is not RE, we have a contradiction of our assumption that Lu is
recursive.

Figure 5.10 - Reduction of Ld to Lu’


Suppose L(M) = Lu. As suggested by Fig (5.10), we can modify TM M into a TM M' that accepts
Ld as follows.
1. Given string w on its input, M' changes the input to w111w. You may, as an exercise,
write a TM program to do this step on a single tape. However, an easy argument that it can be done
is to use a second tape to copy w, and then convert the two-tape TM to a one-tape TM.
2. M' simulates M on the new input. If w is wi in our enumeration, then M' determines
whether Mi accepts wi. Since M accepts Lu ’, it will accept if and only if Mi does not accept wi (i.e.,)
wi is in Ld.
23
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
3. Thus, M accepts w if and only if w is in Ld. we conclude that Lu, is not recursive.

UNDECIDABLE PROBLEMS ABOUT TURING MACHINES


7. Explain briefly about undecidable problems about TM.

The proof undecidable problem about Turing machines says that any nontrivial property of
Turing machines that depends only on the language the TM accepts must be undecidable.

1. Reductions

If we have an algorithm to convert instances of a problem P1 to instances of a problem P2


that have the same answer, then we say that P1 reduces to P2. We can use this proof to show that P2
is at least as hard as P1. Thus, if Pi is not recursive, then P2 cannot be recursive, If P1 is non-RE,
then A cannot be RE.

Figure 5.11: Reductions turn positive instances into positive, and negative to negative

As suggested in Fig. 5.11, a reduction must turn any instance of P1 that has a "yes" answer
into an instance of P2 with a "yes" answer, and every instance of P1 with a "no" answer must be
turned into an instance of P2 with a "no" answer. Note that it is not essential that every instance of
P2 be the target of one or more instances of P1, and in fact it is quite common that only a small
Fraction of P2 is a target of the reduction.

Formally, a reduction from Pi to P2 is a Turing machine that takes an instance of P1 written


on its tape and halts with an instance of P2 on its tape. In practice, we shall generally describe
reductions as if they were computer programs that take an instance of P 1 as input and produce an
instance of P2 as output. The equivalence of Turing machines and computer programs allows us to
describe the reduction by either means.

The importance of reductions is emphasized by the following theorem:

Theorem 9.7: If there is a reduction from Pi to P2 then:

a) If P1 is undecidable then so is P2
b) If P1 is non-RE, then so is P2

24
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Proof: First suppose P1 is undecidable. If it is possible to decide P2, then we can combine the
reduction from P1 to P2 with the algorithm that derides P2 to construct an algorithm that decides P2.
We are given an instance w of P1. Apply to w the algorithm

that converts w into an instance x of P2. Then apply the algorithm that decides to P2 to x. If that
algorithm says "yes then x is in P2. Because we reduced P1 to P2 we know the answer to w for P1 is
"yes"; (i.e.,) w is in P1. Likewise, if x is not in P2 then w is not in P1, and whatever answer we give
to the question "is x in P2?" is also the correct answer to "is w in P1?"

We have thus contradicted the assumption that P1 is undecidable. Our conclusion is that if P1
is undecidable, then P2 is also undecidable.

(b). Assume that Pi is non-RE, but P2 is RE. Now, we have an algorithm to reduce P i to P2,
but we have only a procedure to recognize P2; that is, there is a TM that says "yes" if its input is in
P2 but may not halt if its input is not in P2. As for part (a), starting with an instance w of P1, convert
it by the reduction algorithm to an instance x of P2. Then apply the TM for P2 to x. If x is accepted,
then accept to.

This procedure describes a TM (which may not halt) whose language is P1. If w is in P1,
then x is in P2, so this TM will accept w. If w is not in P1, then x is not in P2. Then, the TM may or
may not halt, but will surely not accept w. Since we assumed no TM for Pi exists, we have shown
by contradiction that no TM for P2 exists either; i.e., if P1 is non-RE, then P2 is non-RE.

2. TURING MACHINES THAT ACCEPT THE EMPTY LANGUAGE

As an example of reductions involving Turing machines, let us investigate two languages called Le
and Lne. Each consists of binary strings. If w is a binary string, then it represents some TM, Mi, in
the enumeration.

If L(Mi)=Ф, that is, Mi. does not accept any input, then w is in L. Thus, Le is the language
consisting of all those encoded TM's whose language is empty. On the other hand, if L(M) is not the
empty language, then w is in Lne. Thus, Lne, is the language of all codes for Turing machines that
accept at least one input string.

In what follows, it is convenient to regard strings as the Turing machines they represent. Thus, we
may define the two languages just mentioned as;
 Le = { M | L(M) =Ф}
 Lne = {M | L(M)=Ф}

Notice that Le arid Lne are both languages over the binary alphabet {0, 1}, and that they are
complements of one another. We shall see that Lne is the "easier" of the two languages; it is RE but
not recursive. On the other hand, Le is non-RE.

Theorem 9.8: Lne is recursively enumerable.

25
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Proof: We have only to exhibit a TM that accepts Lne. It is easiest to describe a nondeterministic
TM M, whose plan is shown in Fig. 5.12. M can be converted to a deterministic TM.

Figure 5.12: Construction of a NTM to accept Line

The operation of M is as follows.


1. M takes as input a TM code M.
2. Using its nondeterministic capability, M guesses an input to that Mi might accept.
3. M tests whether Mi accepts w. For this part, M can simulate the universal TM U that accepts
L.
4. If Mi accepts w, then Al accepts its own input, which is

In this manner, if Mi accepts even one string, M will guess that string (among all others, of course),
and accept Mi. However, if L(Mi)=Ф, then no guess w leads to acceptance by Mi, so M does not
accept M. Thus, L(M)= Lne.

Our next step is to prove that Lne is not recursive. To do so, we reduce Lu to Lne. That is, we shall
describe an algorithm that transforms an input (M,w) into an output M', the code for another Turing
machine, such that w is in L(M) if and only if L(M’) is not empty. That is, M accepts w if and only
if M' accepts at least one string. The trick is to have M' ignore its input, and instead simulate M on
input w. If M accepts, then M' accepts its own input; thus acceptance of w by M is tantamount to
L(M') being nonempty. If Lne were recursive, then we would have an algorithm to tell whether or
not M accepts w: construct M’ and see whether L(M') =Ф.

Theorem 9.9: Lne is not recursive.

Proof: We shall follow the outline of the proof given above. We must design an algorithm that
converts an input that is a binary-coded pair (M, w) into a TM M' such that L(M’) =Ф if and only if
M accepts input w. The construction of M' is sketched in Fig.5.13. As we shall see, if M does not
accept w, then M' accepts none of its inputs; i.e., L(Ml) =Ф. However, if M accepts w, then M'
accepts every input, and thus L(M1) surely is not Ф.

Figure 5.13: Plan of the TM M' constructed from (M, w) in Theorem 9.9;
accepts arbitrary input if and only if Al accepts w

26
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

M' is designed to do the following:

1. M' ignores its own input x. Rather, it replaces its input by the string that represents TM M
and input string w. Since M' is designed for a specific pair (M, w), which has some length n,
we may construct M' to have a sequence of states q0, q1,…. qn, where go is the start state.

(a) In state qi for i=0, 1,...n-1,M' writes the (i + 1)st bit of the code for (M, w), goes to state
qi+1, and moves right.
(b) In state qn, M' moves right, if necessary, replacing any nonblanks (which would be the
tail of x, if that input to M' is longer than n) by blanks.

2. When M' reaches a blank in state qn, it uses a similar collection of states to reposition its head at
the left end of the tape.

3. Now, using additional states, M' simulates a universal TM U on its present tape.

4. If U accepts, then M' accepts. If U never accepts, then M' never accepts either.

The description of M' above should be sufficient to convince you that you could design a
Turing machine that would transform the code for M and the string w into the code for M'. That is,
there is an algorithm to perform the reduction of Lu to Lne. We also see that if M accepts w, then M’
accepts whatever input x was originally on its tape. The fact that x was ignored is irrelevant; the
definition of acceptance by a TM says that whatever was placed on the tape, before commencing
operation, is what the TM accepts. Thus, if M accepts w, then the code for M' is in Lne.

Conversely, if M does not accept w, then M' never accepts, no matter what its input is.
Hence, in this case the code for M' is not in Lne. We have successfully reduced Lu to Lne by the
algorithm that constructs M' from Al and w; we may conclude that, since Lu is not recursive,
neither is Lne. The existence of this reduction is sufficient to complete the proof. However, to
illustrate the impact of the reduction, we shall take this argument one step further.

If Lne were recursive, then we could develop an algorithm for Lu as follows:


I. Convert (M, w) to the TM M’ as above.
2. Use the hypothetical algorithm for Lne to tell whether or not L(M')=Ф. If so, say M does
not accept w; if L(Ml)=Ф, say M does accept w.

Since we know by Theorem 9.6 that no such algorithm for Lu exists, we have contradicted the
assumption that Lne is recursive, and conclude that Lne is not recursive. Now, we know the status of
Le. If Le were RE, then by Theorem 9.4, both it and Lne would be recursive. Since Lne is not
recursive by Theorem 9.9, we conclude that:

Theorem 9.10 Le is not RE.

27
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
8. State and Prove Rice’s theorem for recursively enumerable index sets. (Nov/Dec 2009)
(Apr/May 2010) (Or) State and explain RICE theorem. (10) (Nov/Dec 2015)

Rice's Theorem and Properties of the RE Languages


The fact that languages like Le and Lne are undecidable is actually a special case of a far
more general theorem: all nontrivial properties of the RE languages are undecidable, in the sense
that it is impossible to recognize by a Turing machine those binary strings that are codes for a TM
whose language has the property.
An example of a property of the RE languages is "the language is context free." It is
undecidable whether a given TM accepts a context-free language, as a special case of the general
principle that all nontrivial properties of the RE languages are undecidable.
A property of the RE languages is simply a set of RE languages. Thus, the property of being
context-free is formally the set of all CFL's. The property of being empty is the set {Ф} consisting
of only the empty language.
A property is trivial if it is either empty (i.e., satisfied by no language at all), or is all RE
languages. Otherwise, it is nontrivial.

• Note that the empty property, Ф, is different from the property of being an empty language, {Ф}.

We cannot recognize a set of languages as the languages themselves. The reason is that the
typical language, being infinite, cannot be written down as a finite-length string that could be input
to a TM. Rather, we must recognize the Turing machines that accept those languages; the TM code
itself is finite, even if the language it accepts is infinite.

Thus, if P is a property of the RE languages, the language Lp is the set of codes for Turing
machines M. such that L(M) is a language in P. When we talk about the decidability of a property
P. we mean the decidability of the language Lp.
Theorem: (Rice's Theorem)
Every nontrivial property of the RE languages is undesirable.
Proof: Let P be a nontrivial property of the RE languages. Assume to begin that Ф, the
empty language, is not in P; we shall return later to the opposite case. Since P is nontrivial, there
must be some nonempty language L that is in P. Let ML be a TM accepting L.
We shall reduce Lu to Lp, thus proving that Lp is undecidable, since Lu is undecidable.
The algorithm to perform the reduction takes as input a pair (M, w) and produces a TM M'. The
design of M' is suggested by Fig. 5.14; L(M’) is Ф if M does not accept w, and L(M') L if M
accepts w.

Figure 5.14 - Construction of M' for the proof of Rice's Theorem

28
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
M’ is a two-tape TM. One tape is used to simulate M on w. Remember that the algorithm
performing the reduction is given M and w as input, and can use this input in designing the
transitions of M'.. Thus, the simulation of M on w is "built into' M'; the latter TM does not have to
read the transitions of M on a tape of its own.
The other tape of M' is used to simulate ML on the input x to M’, if necessary. Again, the
transitions of M’are known to the reduction algorithm and may be "built into" the transitions of
M’. The TM M’ is constructed to do the following:
1. Simulate M on input w. Note that w is not the input to M'; rather, M' writes M and w onto
one of its tapes and simulates the universal TM U on that pair.
2. If M does not accept w, then M’ does nothing else. M' never accepts its own input, x, so
L(M') =Ф. Since we assume φ is not in property P, which means the code for M’ is not in
Lp.
3. If M accepts w, then M’ begins simulating Mt on its own input x. Thus, M' will accept
exactly the language L. Since L is in P, the code for M' is in Lp.
You should observe that constructing M' from M and w can be carried out by an algorithm. Since
this algorithm turns (M, w) into an M' that is in Lp if and only if (M, w) is in Lu, this algorithm is a
reduction of Lu to Lp, and proves that the property P is undecidable.
We are not quite done. We need to consider the case where Ф is in P. If so, consider the
complement property P’, the set of RE languages that do not have property P. By the foregoing, P
is undecidable.
However, since every TM accepts an RE language, Lp, the set of (codes for) Turing
machines that do not accept a language in P is the same as Lp’ the set of TM's that accept a
language in p. Suppose Lp were decidable. Then so would be Lp’ because the complement of a
recursive language is recursive (Theorem 9.3).

9. Write a note on NP problems.(Nov/ Dec – 12) (Or) Write the classes and definition of NP
problems.(Nov/Dec-13) (or) Compare Tractable and untractable problems. April/May 2018
Discuss about the tractable and intractable problems. (Nov/Dec 2015)
Explain Tractable and intractable problem with suitable example. (April/May 2017)
What are tractable problems? Compare it with intractable problems. (Nov/Dec 2016)
Explain how to measure and classify complexity. Nov/Dec 2017
With proper examples, explain P and NP complete problems. Nov/Dec 2024

The Classes P and NP


In this section, we introduce the basic concepts of intractability theory: the classes P and NP of
problems solvable in polynomial time by deterministic and nondeterministic TM's, respectively,
and the technique of polynomial-time reduction. We also define the notion of 'NP-completeness," a
property that certain problems in .MP have; they are at least as hard (to within a polynomial in
time) as any problem in NP.
1 Problems Solvable in Polynomial Time
A Turing machine Al is said to be of time complexity T(n) [or to have "running time T(n)")
if whenever M is given an input iv of length n, M halts after making at most T(n) moves, regardless
of whether or not M accepts. This definition applies to any function T(n), such as T(n)= 50n2 or
T(n) = 3n+5n4; we shall be interested predominantly in the case where T(n) is a polynomial in n. We
say a language L is in class P if there is some polynomial T(n) such that L L(M) for some
deterministic TM Al of time complexity T(n).
29
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
2 An Example: Kruskal's Algorithm
You are probably familiar with many problems that have efficient solutions; perhaps you
studied some in a course on data structures and algorithms. These problems are generally in P. We
shall consider one such problem: finding a minimum-weight spanning tree (MWST) for a graph.
Informally, we think of graphs as diagrams such as that of Fig. 10.1. There are nodes, which
are numbered 1-4 in this example graph, and there are edges between some pairs of nodes. Each
edge has a weight, which is an integer. A spanning tree is a subset of the edges such that all nodes
are connected through these edges, yet there are no cycles. An example of a spanning tree appears
in Fig. 5.15; it is the three edges drawn with heavy lines. A minimum-weight spanning tree has the
least possible total edge weight of all spanning trees.

Figure 5.15: A graph; its minimum-weight spanning tree is indicated by heavy lines
There is a well-known "greedy" algorithm, called Kruskul's Algorithm, for finding a MWST. Here
is an informal outline of the key ideas:
1 Maintain for each node the connected component in which the node appears, using whatever
edges of the tree have been selected so far. Initially, no edges are selected, so every node is then in a
connected component by
2. Consider the lowest-weight edge that has not yet been considered; break ties any way you like. If
this edge connects two nodes that are currently in different connected components then:
 Select that edge for the spanning tree, and

 Merge the two connected components involved, by changing the component number of all
nodes in one of the two components to be the same as the component number of the other.

If, on the other hand, the selected edge connects two nodes of the same component, then this edge
does not belong in the spanning tree; it would create a cycle.
3 Continue considering edges until either all edges have been considered, or the number of edges
selected for the spanning tree is one less than the number of nodes. Note that in the latter case, all
nodes must be in one connected component, and we can stop considering edges.
Example 1: In the graph of Fig. 10.1, we first consider the edge (1, 3), because it has the lowest
weight, 10. Since 1 and 3 are initially in different components, we accept this edge, and make 1 and
3 have the same component number, say "component 1." The next edge in order of weights is (2,3),
with weight 12. Since 2 and 3 are in different components, we accept this edge and merge node 2
into "component 1." The third edge is (1, 2), with weight 15. However, 1 and 2 are now in the same
component, so we reject this edge and proceed to the fourth edge, (3,4). Since 4 is not in
"component 1," we accept this edge. Now, we have three edges for the spanning tree of a 4-node
graph, and so may stop.
It is possible to implement this algorithm (using a computer, not a Turing machine) on a
graph with en nodes and e edges in time 0(m + e log e). A simpler, easier-to-follow implementation
proceeds in e rounds. A table gives the current component of each node. We pick the lowest-weight
remaining edge in 0(e) time, and hind the components of the two nodes connected by the edge in
0(m) time.

30
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
If they are in different components, merge all nodes with those numbers in 0(m) time, by
scanning the table of nodes. The total time taken by this algorithm is O(e(e+m)). This running time
is polynomial in the "size" of the input, which we might informally take to be the sum of e and ns.
When we translate the above ideas to Turing machines, we face several issues:
When we study algorithms, we encounter "problems" that ask for outputs in a variety of
forms, such as the list of edges in a MWST. When we deal with Turing machines, we may only
think of problems as languages, and the only output is yes or no, i.e., accept or reject.
For instance, the MWST tree problem could be couched as: "given this graph G and limit
14, does G have a spanning tree of weight 14' or less?" That problem may seem easier to answer
than the MWST problem with which we are familiar, since we don't even learn what the spanning
tree is. However, in the theory of intractability, we generally want to argue that a problem is hard,
not easy, and the fact that a yes-no version of a problem is hard implies that a more standard
version, where a full answer ascot be computed, is also hard.
While we might think informally of the "size" of a graph as the number of its nodes or
edges, the input to a TM is a string over a finite alphabet. Thus, problem elements such as nodes
and edges must be encoded suitably. The effect of this requirement is that inputs to Turing
machines are generally slightly longer than the intuitive "size" of the input.
However, there are two reasons why the difference is not significant:
I. The difference between the size as a TM input string and as an informal problem input is never
more than a small factor, usually the logarithm of the input size. Thus, what can be done in
polynomial time using one measure can be done in polynomial tune using the other measure.
2. The length of a string representing the input is actually a more accurate measure of the number of
bytes a real computer has to read to get its input. For instance, if a node is represented by an integer,
then the number of bytes needed to represent that integer is proportional to the logarithm of tire
integer's size, and it is not "1 byte for any node" as we might imagine in an informal accounting for
input size.
Example 2: Let us consider a possible code for the graphs and weight limits that could be the input
to the MWST problem. The code has five symbols, 0, 1, the left and right parentheses, and the
comma.
1. Assign integers 1 through on to the nodes.

2. Begin the code with the value of m in binary and the weight limit W in binary, separated by
a comma.

3. If there is an edge between nodes i and j with weight w, place (i, j, w) in the code. The
integers i, j, and w are coded in binary. The order of i and j within an edge, and the order of
the edges within the code are immaterial.

Thus, one of the possible codes for the graph of Fig. 10.1 with limit W = 40 is
100, 101000(1,10,1111)(1,11,1010)(10,11,1100)(10,100,10100)(11,100,10010)
If we represent inputs to the MWST problem as in Example 10.2, then an input of length n
can represent at most 0(n/ logo) edges. It is possible that m, the number of nodes, could be
exponential in n, if there are very few edges. However, unless the number of edges, e, is at least m -
1, the graph cannot be connected and therefore will have no MWST, regardless of its edges.
Consequently, if the number of nodes is not at least some fraction of n/log n, there is no
need to run Kruskal's algorithm at all; we simply say "no; there is no spanning tree of that weight."

31
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Thus, if we have an upper bound on the running time of Kruskal’s algorithm as a function of
m and e, such as the upper bound 0 (e(m+e)) developed above, we can conservatively replace both
m and e by n and say that the running time, as a function of the input length n is 0 (n(n + n)), or
0(n5). In fact, a better implementation of Kruskal's algorithm takes time 0(n log n), but we need not
concern ourselves with that improvement here.
Of course, we are using a Turing machine as our model of computation, while the algorithm we
described was intended to be implemented in a programming language with useful data structures
such as arrays and pointers. However, we claim that in 0(n2) steps we can implement the version of
Kruskal’s algorithm described above on a multitape TM. The extra tapes are used for several jobs:
1. One tape can be used to store the nodes and their current component numbers. The length of
this table is 0(n).

2. A tape can be used, as we scan the edges on the input tape, to hold the currently least edge-
weight found, among those edges that have not been marked "used." We could use a second
track of the input tape to mark those edges that were selected as the edge of least remaining
weight in some previous round of the algorithm. Scanning for the lowest-weight, unmarked
edge takes 0(n) time, since each edge is considered only once, and comparisons of weight
can be done by a linear, right-to-left scan of the binary numbers.

3. When an edge is selected in a round, place its two nodes on a tape. Search the table of nodes
and components to find the components of these two nodes. This task takes 0(n) time.

4. A tape can be used to hold the two components, i and j, being merged when an edge is
found to connect two previously unconnected components. We then scan the table of nodes
and components, and each node found to be in component i has its component number
changed to j. This scan also takes 0 (n) times.

You should thus be able to complete the argument that says one round can be executed in 0(n) time
on a multitape TM. Since the number of rounds, e, is at most n, we conclude that 0(n2) time suffices
on a multitape TM. Now, remember Theorem 8.10, which says that whatever a multitape TM can
do in s steps, a single-tape TM can do in 0(s2) steps. Thus, if the nuiltitape TM takes 0(712) steps,
then we can construct a single-tape TM to do the same thing 0(n2)2) = 0(n4) steps. Our conclusion
is that the yes-no version of the MWST problem, "does graph G have a MWST of total weight W or
less," is in P.
3 Nondeterministic Polynomial Time
A fundamental class of problems in the study of intractability is those problems that can be
solved by a nondeterministic TM that runs in polynomial time. Formally, we say a language L is in
the class MP (nondeterministic polynomial) if there is a nondeterministic TM M and a polynomial
time complexity T(n) such that L = L(M), and when AI is given an input of length n, there are no
sequences of more than T(n) moves of M.
Our first observation is that, since every deterministic TM is a nondeterministic TM that
happens never to have a choice of moves, P C NP. However, it appears that NP contains many
problems lint in P. The intuitive reason is that a NMI running in polynomial time has the ability to
guess an exponential number of possible solutions to a problem and check each one in polynomial
time, "in parallel." However:

32
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
• It is one of the deepest open questions of Mathematics whether P = NP, i.e., whether in fact
everything that can be done in polynomial time by a NTM can in fact be done by a DTM in
polynomial time, perhaps with a higher-degree polynomial.
4 An NP Example: The Traveling Salesman Problem
To get a feel for the power of NP, we shall consider an example of a protean that appears to
be in NP but satin P: the Traveling Salesman Problem (TSP). The input to TSP is the same as to
MWST, a graph with integer weights on the edges such as that of Fig. 10.1, and a weight limit W.
The question asked is whether the graph has a "Hamilton circuit" of total weight at most W.
A Hamilton circuit is a set of edges that connect the nodes into a single cycle, with each
node appearing exactly once. Note that the number of edges on a Hamilton circuit must equal the
number of nodes in the graph.
Example 10.3: The graph of Fig 10.1 actually has only one Hamilton circuit: the cycle (1, 2, 1, 3,
1). The total weight of this cycle is 15 + 20 + 18 + 10 = 63. Thus, if W is 63 or more, the answer is
"yes," and if W< 63 the answer is "no."
However, the TSP on four-node graphs is deceptively simple, since there can never be mote
than two different Hamilton circuits once we account for the different nodes at which the same
cycle can start, and for the direction in which we traverse the cycle. In m-node graphs, the number
of distinct cycles grows as 0(m!), the factorial of en, which is more than 2" for any constant c.
It appears that all ways to solve the TSP involve trying essentially all cycles and computing
their total weight. By being clever, we can eliminate some obviously bad choices. But it seems that
no matter what we do, we must examine an exponential number of cycles before we can conclude
that there is none with the desired weight limit W, or to find one if we are unlucky in the order in
which we consider the cycles.
On the other hand, if we had a nondeterministic computer, we could guess a permutation of
the nodes, and compute the total weight for the cycle of nodes in that order. If there were a real
computer that was nondeterministic, no branch would use more than 0(n) steps if the input was of
length n. On a multitape NTM, we can guess a permutation in 0(n2) steps and check its total weight
in a similar amount of time, Thus, a single-tape NTM can solve the TR' in 0(n4) time at most. We
conclude that the TSP is in NP.

Tractable and possibly Intractable problems: P and NP


There are two groups in which a problem can be classified. The first group of the problems that can
be solved in polynomial time. For example: searching of an element from the list O(logn), sorting
of elements O(logn).
The second group consists of problem that can be solved in non-deterministic polynomial time.
For example: Knapsack problem O(2 n/2) and travelling salesperson problem (O(n22n)).
 Any problem for which answer is either Yes or No is called decision problem. The algorithm
for decision problem is called decision algorithm.
 Any problem that involves the identification of optimal cost (minimum or maximum) is called
optimization problem. The algorithm for optimization problem is called optimization
algorithm.
 Definition of P – problems that can be solved in polynomial time. (―p‖ stands for polynomial).
Examples – searching of key element, sorting of elements, All pair shortest path.
 Definition of NP – It stands for ―non-deterministic polynomial time‖. Note that NP does not
stand for ―non-polynomial‖.

33
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Examples – Travelling Salesperson problem, graph coloring problem, Knapsack problem,
Hamiltonian circuit problems.

Computational complexity
problems

P- class NP- class

NP- complete NP-hard

A problem D is called NP-complete if –


i) It belongs to class NP
ii) Every problem in NP can also solved in polynomial time.

If an NP-hard problem can be solved in polynomial time then all NP-complete problems can
also be solved in polynomial time.
All NP-complete problems are NP-hard but all NP-hard problems cannot be Np-complete.
The NP class problems are the decision problems that can be solved by non-deterministic
polynomial algorithm.
(1) Example of P class problem
Kruskal’s algorithm: In kruskal’s algorithm the minimum weight is obtained. In this
algorithm also the circuit should not be formed. Each has to be selected, from the graph. It
has edges of minimum weights to be adjacent. Let us solve one example by Kruskal’s
algorithm.
Characteristics of Kruskal and Prim algorithm
• Both Prim’s and Kruskal’s Algorithms work with undirected graphs
• Both work with weighted and un-weighted graphs but are more interesting when edges are
weighted
• Both are greedy algorithms that produce optimal solutions

Step 1: Sort all edges in increasing order of their edge weights.

Step 2: Pick the smallest edge.

Step 3: Check if the new edge creates a cycle or loop in a spanning tree.

Step 4: If it doesn’t form the cycle, then include that edge in MST. Otherwise, discard it.

Step 5: Repeat from step 2 until it includes |V| - 1 edges in MST.

34
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Example 1:
1
c
b
6
3 4 4
4
5 5 d
a f 5

6
2
8
e

A spanning tree of a connected graph is its connected acyclic subgraph that contains all the vertices
of the graph.
A tree T is a Spanning tree if a connected graph G(V,E) such that
o Every vertex of G belongs to an edge in T.
o The edge in T form a tree
Minimum Spanning Tree (MST)
A technique of building a spanning tree with minimum cost and weight is known as minimum
spanning tree.

The minimum spanning tree is for the given graph


1
b c
3 4
4
5 d
a f 5

The worst –case running time of this algorithm is O (|E| log |E|), which is dominated by
heap operation.

35
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

36
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

2: Find the minimum spanning tree for the following figure using Kruskal’s algorithm.
1

a c
1 b 2

2 1
2
2 1
e
1 1
3 f d 2

3 3
3
2 3

3 3
g h i

In kruskal’s algorithm, we will start5 with some vertex and will cover all the vertices with minimum
weight. The vertices need not be adjacent.

a b
2

1
1

a b
2

1
1

a b
2 c

1 1

e d
1

a b
2 c

1 1

f e d 2
1

37
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF 1INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

a b
2 c

1 1

f e d 2
1

2
3

i
g h

4. Example of NP class problem :Travelling salesman’s problem

Travelling salesman’s problem (TSP) : This problem can be stated as ― Given a set of cities
and cost to travel between each pair of cities, determine whether there is a path that visits every city
once and returns to the first city. Such that the cost travelled is the tour will be a-b-d-e-c-a and total
cost of tour will be 16.
This problem is NP problem as there may exist some path with shortest distance between the
cities. If you get the solution by applying certain algorithm then travelling salesman problem is NP
complete problem. If we get no solution at all by applying an algorithm then the travelling salesman
belongs to NP hard class.

For Example:
3
a b
6
5
7
1

4
c d
8 2

2 3
e

Hamiltonian cycle

A Hamiltonian cycle in an undirected graph G is a simple cycle that visits every node in G.

Fig. 5.16 - Undirected Graph

38
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Fig. 5.17 - Hamiltonian cycle1

Fig.5.18 - Hamiltonian cycle2 Fig.5.19- Hamiltonian cycle3

Given a complete, undirected, weighted graph G, the traveling salesperson problem (TSP) is to find
a Hamiltonian cycle in G of least total cost.
Given as input
● A complete, undirected graph G, and
● a set of edge weights, which are positive integers, the TSP is to find a Hamiltonian cycle in G
with least total weight.
● Note that since G is complete, there has to be at least one Hamiltonian cycle. The challenge is
finding the least-cost cycle.
● This problem is known to be NP-hard

Naïve approach:

39
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Approximation algorithms
There are two simple approximation algorithms for traveling salesman problem are based on the
greedy technique.
They are
1. Nearest neighbor algorithm
2. Twice around the tree algorithm
Nearest-neighbor algorithm
The following well-known greedy algorithm is based on the nearest-neighbor heuristic: always go
next to the nearest unvisited city.
Procedure
Step 1 Choose an arbitrary city as the start.
Step 2 Repeat the following operation until all the cities have been visited: go to the
unvisited city nearest the one visited last (ties can be broken arbitrarily).
Step 3 Return to the starting city.
Example
For the instance represented by the graph in Figure, with a as the starting vertex, the nearest-
neighbor algorithm yields the tour (Hamiltonian circuit)
1 2 1 6
Sa: a − b − c − d − a
of length 10.
The optimal solution, as can be easily checked by exhaustive search, is the tour and the path is
1 3 1 2
S*: a − b − d − c – a
of length 8.
Thus, the accuracy ratio of this approximation is
r(Sa) =
r(Sa) = = 1.25
(i.e., tour Sa is 25% longer than the optimal tour S*).

1
a b
3

6 3 2
2

d c
1

Instance of traveling salesman problem for illustrating the nearest neighbor algorithm.
40
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Solution : We will apply nearest neighbor algorithm


For the tour for given travelling salesman problem. Hence nearest will produce:
a−b−c−d–a
Sa = 1 2 1 6
Sa = 10
Now the optimal solution can be obtained by exhaustive search. Then tour will be
a − b − d – c-a
S* = 1 +3+1+3
S* = 8
The accuracy ratio r(Sa) will be

(i.e., tour sa is 25% longer than the optimal tour s ).

Unfortunately, except for its simplicity, not many good things can be said about the nearest-
neighbor algorithm. In particular, nothing can be said in general about the accuracy of solutions
obtained by this algorithm because it can force us to traverse a very long edge on the last leg of the
tour. Indeed, if we change the weight of edge (a, d) from 6 to an arbitrary large number w ≥ 6 in
Example 1, the algorithm will still yield the tour a − b − c − d − a of length 4 + w, and the optimal
solution will still be a − b − d − c − a of length
8. Hence,

Which can be made as large as we wish by choosing an appropriately large value of w? Hence,
RA=∞

10. Explain briefly about Polynomial Time Reductions.(Nov/Dec-10,11,May/June-12)


Outline the concept of polynomial time reductions. (Nov/Dec 2016)

Polynomial-Time Reductions

Our principal methodology for proving that a problem P2 cannot be solved in polynomial time (i.e.,
P2 is not in P) is the reduction of a problem Pi, which is known not to be in P, to P2. The approach
was suggested , which we reproduce here as Fig.5.20

Figure 5.20: Reprise of the picture of a reduction


Suppose we want to prove the statement "if P2 is in P, then so is Pl." Since we claim that P1

41
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
is not in P, we could then claim that P2 is not in P either. However, the mere existence of the
algorithm labeled "Construct" in Fig. 10.2 is not sufficient to prove the desired statement.
For instance, suppose that when given an instance of P, of length m, the algorithm produced an
output string of length 2 m, which it fed to the hypothetical polynomial-time algorithm for P. If that
decision algorithm ran in, say, time 0(nk) then on an input of length 2 m it would run in time 0(2km),
which is exponential in m.
Thus, the decision algorithm for P, takes, when given an input of length m time that is
exponential in m. These facts are entirely consistent with the situation where P2 is in P and P1 is
not in P.
Even if the algorithm that constructs a P2 instance from a P, instance always produces an
instance that is polynomial in the size of its input, we can fail to reach our desired conclusion. For
instance, suppose that the instance of P. constructed is of the same size, m, as the Pi instance, but
the construction algorithm itself takes time that is exponential in m, say 0(2 m).
Now, a decision algorithm for P2 that takes polynomial time 0(0) on input of length n only
implies that there is a decision algorithm for P, that takes time 0(2 m + mk) on input of length In.
This running time bound takes into account the fact that we have to perform the translation to P2 as
well as solve the resulting P2 instance. Again it would be possible for P2 to be in P and Pi not.
The correct restriction to place on the translation from P, to P2 is that it requires time that is
polynomial in the length of its input.
Note that if the translation takes time 0(mj) on input of length in, then the output instance of
Ps cannot he longer than the number of steps taken, i.e., it is at most cm' for some constant c. Now,
we can prove that if P2 is in 2, then so is P.
For the proof, suppose that we can decide membership in P2 of a string of length n in time 0(nk).
Then we can decide membership in P1 of a string of length m in time 0(mj + (cmj)k) time; the term
mj accounts for the time to do the translation, and the term (cmj)k accounts for the time to decide
the resulting instance of P2. Simplifying the expression, we see that PI can be solved in time
0(mj + (cmj)k). Since c, j, and k are all constants, this time is polynomial in m, and we conclude P1
is in P.
Thus, in the theory of intractability we shall use polynomial-time reductions only. A reduction from
P1 to P2 is polynomial-time if it takes time that is some polynomial in the length of the P) instance.

Note that as a consequence, the P, instance will be of a length that is polynomial in the length of the
P1 instance.

11. Explain briefly about Post's Correspondence Problem. (Nov/Dec-07,10,11,12,14) (Or)


What is a post corresponding problem (PCP)? Explain with the help of an example.
(May/June 2016)
Definition of Post's Correspondence Problem
An instance of Post's Correspondence Problem (PCP) consists of two lists of strings over
some alphabet Σ; the two lists must be of equal length. We generally refer to the A and B lists, and
write A=w1, w2…. wk and B=x1, x2…. xk for some integer k. For each i, the pair (wi , xi) is said to
be a corresponding pair.
We say this instance of PCP has a solution, if there is a sequence of one or more integers i1
,i2,…. im that, when interpreted as indexes for strings in the A and B lists, yield the same string.
That is, wi1, wi2….. wim, = xi1, xi2,….. xim. We say the sequence i1 ,i2,…. im is a solution to this
instance of PCP, if so.
42
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

The Post's correspondence problem is: Given an instance of PCP, tell whether this instance has a
solution.

Example 9.13: Let Σ = {0,1}, and let the A and B lists be as defined in Fig. 5.21. In this case, PCP
has a solution. For instance, let m = 4, i1 = 2, i2 = 1, i3 = 1, and i4 = 3; (i.e.,) the solution is the list 2,
1, 1, 3. We verify that this list is a solution by concatenating the corresponding strings in order for
the two lists.
That is, w2w1w1w3 = x2x1x1x3 = 01111110. Note this solution is not unique. For instance, 2, 1, 1,
3, 2, 1, 1, 3 is another solution.

Figure:5.21 - An instance of PCP


Example: Here is an example where there is no solution. Again we let E = {0,1}, but now the
instance is the two lists given in above Fig..
Suppose that the PCP instance of above Figure has a solution, say for some m ≥ 1. We claim
i1 = 1. For if i1 = 2, then a string beginning with w2 = 011 would have to equal a string that begins
with x2 = 11.
But that equality is impossible, since the first symbols of these two strings are 0 and 1,
respectively. Similarly, it is not possible that i1 = 3, since then a string beginning with w3 = 101
would have to equal a string beginning with x3 = 011.
If i1 = 1, then the two corresponding strings from lists A and B would have to begin:
A=10…
B=101…
Now, let us see what i2 could be.
1. If i2 = 1, then we have a problem. Since no string beginning with w1w1 = 1010 can match
a string that begins with x1x1=101101;they must disagree at the fourth position.

Figure 5.22
Figure 5.22- Another PCP instance
2. If i2 = 2, we again have a problem, because no string that begins with w1w2 = 10011 can match a
string that begins with x1x2 = 10111; they must differ at the third position.
3. Only i2 = 3 is possible.
If we choose i2 = 3, then the corresponding strings formed from list of integers ii,i3 are:
A: 10101 …..

43
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
B: 101011….
There is nothing about these strings that immediately suggests we cannot extend list 1, 3 to a
solution. However, we can argue that it is not possible to do so. The reason is that we are in the
same condition we were in after choosing i1 = 1.
The string from the B list is the same as the string from the A list except that in the B list there is an
extra 1 at the end. Thus, we are forced to choose i3 = 3, i4 = 3, and so on, to avoid creating a
mismatch. We can never allow the A string to catch up to the B string, and thus can never reach a
solution.
The "Modified" PCP
It is easier to reduce Lu to PCP if we first introduce an intermediate version of PCP, which
we call the Modified Post's Correspondence Problem, or MPCP. In the modified PCP, there is the
additional requirement on a solution that the first pair on the A and B lists must be the first pair in
the solution. More formally, an instance of MPCP is two lists A=w1, w2…. wk and B=x1, x2…. xk
and a solution is a list of 0 or more integers i1 ,i2,…. im such that
wi1, wi2….. wim, = xi1, xi2,….. xim.
Notice that the pair (w1, x1) is forced to be at the beginning of the two strings, even though the
index 1 is not mentioned at the front of the list that is the solution. Also, unlike PCP, where the
solution has to have at least one integer on the solution list, in MPCP, the empty list could be a
solution if wi = xi (but those instances are rather uninteresting and will not figure in our use of
MPCP).

Example 9.15: The lists of Fig. 9.12 may be regarded as an instance of MPCP. However, as an
instance of MPCP it has no solution. In proof, observe that any partial solution has to begin with
index 1, so the two strings of a solution would begin:
A:1…..
B:111….
The next integer could not be 2 or 3, since both w2 and w3 begin with 10 and thus would
produce a mismatch at the third position. Thus, the next index would have to be 1, yielding:
A:11….
B:111111….
We can argue this way indefinitely. Only another 1 in the solution can avoid a mismatch,
but if we can only pick index 1, the B string remains three times as long as the A string, and the two
strings can never become equal.
An important step in showing PCP is undecidable is reducing MPCP to PCP. Later, we
show MPCP is undecidable by reducing Lu to MPCP. At that point, we will have a proof that PCP
is undecidable as well; if it were decidable then we could decide MPCP, and thus Lu.
Given an instance of MPCP with alphabet Σ. we construct an instance of PCP as follows.
First, we introduce a new symbol * that, in the PCP instance, goes between every symbol in the
strings of the MPCP instance. However, in the strings of the A list, the *'s follow the symbols of E,
and in the B list, the *'s precede the symbols of E. The one exception is a new pair that is based on
the first pair of the MPCP instance; this pair has an extra * at the beginning of w1, so it can be used
to start the PCP solution.
A final pair (*, *$) is added to the PCP instance. This pair serves as the last in a PCP
solution that mimics a solution to the MPCP instance.
Now, let us formalize the above construction. We are given an instance of MPCP with lists
A=w1, w2…. wk and B=x1, x2…. xk. We assume * and $ are symbols not present in the alphabet Σ
44
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
of this MPCP instance. We construct a. PCP instance C = y0, y1…. yk+1 and D = z0, z1…. zk+1
follows:
1. For i = 1, 2, ... , k, let yi be wi with a * after each symbol of wi, and let z i be xi with a
* before each symbol of xi.

2. y0 = * y1, and z0 = z1. That is, the 0th pair looks like pair 1, except that there is an extra * at
the beginning of the string from the first list. Note that the 0th pair will be the only pair in
the PCP instance where both strings begin with the same symbol, so any solution to this
PCP instance will have to begin with index 0.

3. yk+1 = $ and zk+1=*$.

Example 9.16: Suppose Fig. 9.12 is an MPCP instance. Then the instance of PCP constructed by
the above steps is shown in Fig. 5.23.

Figure 5.23: Constructing an instance of PCP from an MPCP instance

12. Prove that “MPCP reduces to PCP”.(10) (Nov/Dec 2024)


Define PCP and prove that PCP is undecidable. Nov/Dec 2020
Definition of Post's Correspondence Problem
An instance of Post's Correspondence Problem (PCP) consists of two lists of strings over
some alphabet Σ; the two lists must be of equal length. We generally refer to the A and B lists, and
write A=w1, w2…. wk and B=x1, x2…. xk for some integer k. For each i, the pair (wi , xi) is said to
be a corresponding pair.
We say this instance of PCP has a solution, if there is a sequence of one or more integers i1
,i2,…. im that, when interpreted as indexes for strings in the A and B lists, yield the same string.
That is, wi1, wi2….. wim, = xi1, xi2,….. xim. We say the sequence i1 ,i2,…. im is a solution to this
instance of PCP, if so.

The Post's correspondence problem is: Given an instance of PCP, tell whether this instance has a
solution.
Theorem: MPCP reduces to PCP.

Figure 5.24 - Reductions proving the undecidability of Post's Correspondence


Problem

45
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
PROOF: The construction given above is the heart of the proof. First, suppose that 1,i2,,rn is a
solution to the given MPCP instance with lists A and B.

Then we know wiwi1 wi2….. wim = xi xi1 xi2….. xim. If we were to replace the w's by y's and the x's
by z’s, we would have two strings that were almost the same; y1 yi1 yi2….. yim = z1zi1 zi2….. zim. The
difference is that the first string would be missing a * at the beginning, and the second would be
missing a * at the end. That is,
*y1yi1 yi2….. yim = z1 zi1 zi2….. zim*
However, y0 = * y1, and z0 = z1, so we can fix the initial * by replacing the first index by 0. We then
have:
y0yi1 yi2….. yim = z0zi1 zi2….. zim*
4. We can take care of the final * by appending the index k + 1. Since yk+1 = $ and zk+1=*$. we
have:

y0yi1 yi2….. yim yk+1 = z0zi1 zi2….. zim zk+1


We have thus shown that 0, i1 ,i2 ….. iim ik+1 is a solution to the instance of PCP.
Now, we must show the converse, that if the constructed instance of PCP has a solution, then the
original TVIPCP instance has a solution as well. We observe that a solution to the PCP instance
must begin with index 0 arid end with index k + 1, since only the 0th pair has strings yo and zo that
begin with the same symbol, and only the (k + 1) st pair has strings that end with the same symbol.
Thus, the PCP solution can be written 0, i1 ,i2 ….. iim ik+1

We claim that i1 i2, is a solution to the MPCP instance. The reason is that if we remove the *'s and
the final $ from the string y0 yi1 yi2….. yim yk+1 WC get the string w1wi1 wi2….. wim. Also, if we
remove the *'s and $ from the string z0zi1 zi2….. zim zk+1 we get x1 xi1 xi2….. xim We know that
y0yi1 yi2….. yim yk+1 = z0zi1 zi2….. zim zk+1
so it follows that
wiwi1 wi2….. wim = xi xi1 xi2….. xim

Thus, a solution to the PCP instance implies a solution to the MPCP instance.
We now see that the construction described prior to this theorem is an algorithm that converts an
instance of MPCP with a solution to an instance of PCP with a solution, and also converts an
instance of MPCP with no solution to an instance of PCP with no solution, Thus, there is a
reduction of MPCP to PCP, which confirms that if PCP were decidable, MPCP would also be
decidable.

Completion of the Proof of PCP Undecidability


To reduce Lu to MPCP. That is, given a pair (M, w), we construct an instance (A, B) of MPCP such
that TM AI accepts input w if and only if (A, B) has a solution

The essential idea is that MPCP instance (A, B) simulates, in its partial solutions, the computation
of M on input w. That is. partial solutions will consist of strings that are prefixes of the sequence of
ID's of M: #αi#α2#α3#...., where αi is the initial ID of M with input w, and αi├ αi+1 for all i. The
string from the B list will always be one ID ahead of the string from the A list, unless M enters an
accepting state. In that case, there will be pairs to use that will allow the A list to "catch up" to the B

46
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
list and eventually produce a solution. However, without entering an accepting state, there is no
way that these pairs can be used, and no solution exists.

To simplify the construction of an MPCP instance, we shall invoke Theorem 8.12, which says that
we may assume our TM never prints a blank, and never moves left from its initial head position. In
that case, an ID of the Turing machine will always be a string of the form αqβ, where α and β are
strings of nonblank tape symbols, and q is a state. However, we shall allow β to be empty, if the
head is at the blank immediately to the right of α, rather than placing a blank to the right of the
state. Thus, the symbols of α and β will correspond exactly to the contents of the cells that held the
input, plus any cells to the right that the head has previously visited.

Let M (Q, Σ, Γ, δ, qo, B, F) be a TM satisfying Theorem 8.12, and let w in Σ* be an input string.
We construct an instance of MPCP as follows. To understand the motivation behind our choice of
pairs, remember that the goal is for the first list to be one ID behind the second list, unless M
accepts.
The first pair is:
List A List B
# #qow#
This, pair, which must start any solution according to the rules of MPCP, begins the simulation of
M on input w. Notice that initially, the B list is a complete ID ahead of the A list.
Tape symbols and the separator # can be appended to both lists. The pairs
List A List B
X X for each X in Γ
# #
allow symbols not involving the state to be "copied." In effect, choice of these pairs lets us extend
the A string to match the B string, and at the same time copy parts of the previous ID to the end of
the B string. So doing helps to form the next ID in the sequence of moves of M, at the end of the B
string.

3. To simulate a move of M, we have certain pairs that reflect those moves. For all q in Q - F (i.e., q
is a nonaccepting state), p in Q, and X, Y, and Z in Γ we have:
List A List B
qX Yp if δ(q, X) = (p, Y, R)
ZqX pZY if δ(q, X) = (p, Y, L); Z is any tape symbol
q# Y p# if δ(q, B) = (p, Y, R)
Zq# pZY # if δ(q, B) = (p, Y, L); Z is any tape symbol
Like the pairs of (2), these pairs help extend the B string to add the next ID, by extending the A
string to match the B string. However, these pairs use the state to determine the change in the
current ID that is needed to produce the next ID. These changes — a new state, tape symbol, and
head move — are reflected in the ID being constructed at the end of the B string.

4. If the ID at the end of the B string has an accepting state, then we need to allow the partial
solution to become a complete solution. We do so by extending with "ID's" that are not really ID's
of M, but represent what would happen if the accepting state were allowed to consume all the tape
symbols to either side of it. Thus, if q is an accepting state, then for all tape symbols X and Y, there
are pairs:
47
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
List A List B
X qY q
Xq q
qY q
5 Finally, once the accepting state has consumed all tape symbols, it stands alone as the last ID on
the B string. That is, the remainder of the two strings (the suffix of the B string that must be
appended to the A string to match the B string) is q#. We use the final pair:
List A List B
q## #

13. Describe about Recursive and Recursively Enumerable languages with examples. (6)
(Nov/Dec 2015)(April/May 2017)
Compare recursive languages with recursively enumerable languages. (Nov/Dec 2016)

Recursive
 A language L is said to be recursive if there exists a Turing machine M that accepts
L, and goes to halt state or else M rejects L.
W
Accept
TM
Reject
Input
string

 The recursive languages are called Turing decidable languages


 Recursive language will halt on every input.
 Every recursive language is also a recursively enumerable.
 If L is recursive language then its complement L’ is also recursive.
Recursively Enumerable
A language is recursively enumerable if there exists a Turing Machine that accepts every
string of the language and does not accept strings that are not in the language.

W
Accept
TM
Loops for ever
Input string

 The RE is called Turing acceptable languages.


 RE may not halt on every input; it may fall into an infinite loop.
 Every RE language is not recursive.
 There exist RE language L whose complement L’ may not be RE. If L and L’ both are
recursively enumerable then that L is definitely a recursive language.

48
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

13. Discuss about 3 SAT CNF problem. [April/May 2024]


Boolean Satisfiability Problem
Boolean Satisfiability or simply SAT is the problem of determining if a Boolean
formula is satisfiable or unsatisfiable.
 Satisfiable : If the Boolean variables can be assigned values such that the formula turns out to
be TRUE, then we say that the formula is satisfiable.
 Unsatisfiable : If it is not possible to assign such values, then we say that the formula is
unsatisfiable.

is satisfiable, because A = TRUE and B = FALSE makes F = TRUE.

is unsatisfiable, because:

Conjunctive Normal Form (CNF) or also known as Product of Sums (POS).


CNF : CNF is a conjunction (AND) of clauses, where every clause is a disjunction (OR).
A boolean expression is said to be in CNF form if it’s a conjunction of a set of clauses, where each
clause is defined as a disjunction (logical OR) of literals.

DEFINITION
The 3-SAT problem is part of the Karp’s 21 NP-complete problems and is used as the starting point
to prove that the other problems are also NP-Complete. One example is the independent set
problem. The Independent Set Problem can be shown to be NP-Complete by showing that the 3-
SAT is polynomially reducible to an independent set problem.
A literal in a boolean formula is an occurrence of a variable or its negation. A boolean formula is in
conjunctive normal form, or CNF, if it is expressed as conjunctions (by AND) of clauses, each of
which is the disjunction (by OR) of one or more literals. A boolean formula is in 3-conjunctive
normal form, or 3-CNF-SAT, if each clause has exactly three distinct literals. For example, the
boolean formula (𝑥1 ∨ 𝑥2 ∨ 𝑥̅3 ) ∧ (𝑥̅1 ∨ 𝑥̅2 ∨ 𝑥3 ) ∧ (𝑥1 ∨ 𝑥̅2 ∨ 𝑥
3 ) is in 3-CNF-SAT. The first clause is (x1 𝑥2 ∨ 𝑥̅3 ), which contains the three literals 𝑥1, 𝑥2, and
𝑥̅3.
Concept: - In 3CNF SAT, you have at least 3 clauses, and in clauses, you will have almost 3
literals or constants

V=OR operator
^ =AND operator

These all the following points need to be considered in 3CNF SAT.


49
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

To prove: -
Concept of 3CNF SAT
SAT≤ρ 3CNF SAT
3CNF≤ρ SAT
3CNF ϵ NPC
CONCEPT: - In 3CNF SAT, you have at least 3 clauses, and in clauses, you will have almost 3
literals or constants.
SAT ≤ρ 3CNF SAT:- In which firstly you need to convert a Boolean function created in SAT into
3CNF either in POS or SOP form within the polynomial time
F=X+YZ
= (X+Y) (X+Z)
= (X+Y+ZZ') (X+YY'+Z)
= (X+Y+Z) (X+Y+Z') (X+Y+Z) (X+Y'+Z)
= (X+Y+Z) (X+Y+Z') (X+Y'+Z)
3CNF ≤p SAT: - From the Boolean Function having three literals we can reduce the whole
function into a shorter one.
F= (X+Y+Z) (X+Y+Z') (X+Y'+Z)
= (X+Y+Z) (X+Y+Z') (X+Y+Z) (X+Y'+Z)
= (X+Y+ZZ') (X+YY'+Z)
= (X+Y) (X+Z)
= X+YZ
3CNF ϵ NPC: - As you know very well, you can get the 3CNF through SAT and SAT through
CIRCUIT SAT that comes from NP.
Proof of NPC:-
1. It shows that you can easily convert a Boolean function of SAT into 3CNF SAT and
satisfied the concept of 3CNF SAT also within polynomial time through Reduction
concept.
2. If you want to verify the output in 3CNF SAT then perform the Reduction and convert
into SAT and CIRCUIT also to check the output.

If you can achieve these two points that means 3CNF SAT also in NPC

The truth table


According to the Boolean Algebra for any 3-CNF formula like φ with n variables [ x1, x2, ..., xn ],
the truth table can be formed from Table 5.2 in order to initialize the variables in the given formula
using values in one of the rows in truth table(Table 5.1)

50
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION

Table 5.1

Table 5.2 :𝐓𝐫𝐮𝐭𝐡 𝐭𝐚𝐛𝐥𝐞 𝐚𝐧𝐝 𝐬𝐭𝐫𝐢𝐧𝐠 𝐭𝐚𝐛𝐥𝐞 𝐨𝐟 ɸ

51
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
ANNA UNIVERSITY QUESTIONS

Nov/Dec 2015

PART- A

1) State when a problem is said to be decidable and example of an undecidable problem.


2) What is a universal language Lu?
PART- B

14) a) (i) Prove that ―MPCP reduces to PCP‖. (10)


(ii) Discuss about the tractable and intractable problems. (6)
b) (i) State and explain RICE theorem. (10)
(ii) Describe about Recursive and Recursively Enumerable languages with examples. (6)

(Q.No:15)
May/June 2016
PART- A
1. When is a recursively enumerable language said to be recursive?
2. Identify whether Tower of Hanoi’ problem is tractable or intractable. Justify your
answer.

PART- B
15) a) What is a universal Turing machine? Bring out its significance. Also construct a Turing
machine to add two numbers and encode it. (16)
(Or)
b) What is a post corresponding problem (PCP)? Explain with the help of an example. (10)

Nov/Dec 2016
PART A
1. Define Universal Turing Machine.
2. Define NP-hard and NP-Completeness problem.
PART B
1. (i) Elaborate on primitive recursive functions with an example.
(ii) Compare recursive languages with recursively enumerable languages.
2. (i) What are tractable problems? Compare it with intractable problems.
(ii) Outline the concept of polynomial time reductions.

April/May 2017
PART A
1. What is primitive recursion function?
2. Define NP completeness.

PART B
1. Explain Recursive and Recursively Enumerable languages with suitable examples.

52
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
2. Explain Tractable and intractable problem with suitable example.

Nov/Dec 2017
PART A
1. List the properties of recursive and recursive enumerable language.
2. Write abort notes on tractable problem.

PART B
1. Explain universal Turing Machine.
2. Explain how to measure and classify complexity.

April/May 2018

PART A
1. What do you mean by Universal Turing machine?
2. When is a language said to be recursively enumerable.

PART B
1. Prove that the Diagonalization language (L d) is not a recursively enumerable.
2. Write note on primitive recursive functions.
Part C
1. Compare Tractable and untractable problems.

Nov/Dec 2020

PART A
1. What are recursive languages?
2. Define the classes P and NP problem. Give example problems for both.

PART B

3. Prove that universal language is recursively enumerable but not recursive.


4. Define PCP and prove that PCP is undecidable.

Nov/Dec 2021

PART A
1. State Post’s correspondence problem.
PART B
1. With proper examples, explain P and NP complete problems.
2. State and prove that ―Diagonalization language is not recursively enumerable‖.

53
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
EnggTree.com

Downloaded from EnggTree.com


EnggTree.com

Downloaded from EnggTree.com


EnggTree.com

Downloaded from EnggTree.com


EnggTree.com

Downloaded from EnggTree.com

You might also like