TOC Material
TOC Material
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.
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
Linear-bounded automata
Turing machine
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.
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
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
FQ- 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.
4
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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.
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
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
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
q0 q1
*q1 Φ
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 ≠ Ф)}
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
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
q0 q1
1
0 0 0 0
1
q2 q3
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.
q0
b
b
a
a q1 q2
b
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
0,1
Q0
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])?
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.
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.
14
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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:
*q1 Φ
15
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
= δ (q0, 0)
= q1
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
M = (Q, ∑, δ, q0, F)
Where, Q - finite, non empty set of states
∑- an input alphabet
q0 ЄQ - the start state
FQ- a set of final states
δ a transition function (Q Х ∑ 2Q (2Q is the power set of 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
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
q0 q0, q1
*q1 Φ
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
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
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
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
a/b
a b a
q0 q1 q2 q3
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
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”
26
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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”
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,
HC==> 7C7H.
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
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
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
6
LHS:
S(n+1) = 1 2+ 2 2+3 2+….+(n+1) 2
= _______________
6
(n+1)[n+2][2n+3]
= _______________
6
( n+1) [(n+1)+1][2(n+1)+1]
= ______________________
6
= RHS Hence proved.
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
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.
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
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.
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
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
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
(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]
1 3 + 2 3 + 3 3 + ... + n 3 = n 2 (n + 1) 2 / 4
Left Side = 1 3 = 1
Right Side = 1 2 (1 + 1) 2 / 4 = 1
1 3 + 2 3 + 3 3 + ... + k 3 = k 2 (k + 1) 2 / 4
1 3 + 2 3 + 3 3 + ... + k 3 + (k + 1) 3 = k 2 (k + 1) 2 / 4 + (k + 1) 3
= (k + 1) 2 [ k 2 / 4 + (k + 1) ]
= (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
= {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
δD(S, a) = δN(p, a)
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)
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
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 Φ Φ
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
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
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]
a b
a
a
[p,r]
49
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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
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
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
Step 2
(B,a) δN({q0,q1},a)=δ(q0,a) U δ(q1,a) = {q0,q1}
So δD([q0,q1],a) = [q0,q1] B
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
b
a [q0,q1,q3
[q0,q2]
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}
a,b,c
56
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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
58
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
0 1 2
*q0 {q0,q1,q2} {q1,q2} {q2}
*q1 Φ {q1,q2} {q2}
*q2 Φ Φ {q2}
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
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
ε,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
= {p,q,r}
So δD([q,r],a) = [p,q,r] A
63
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
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
a B
* [q0,q1] [q0,q1] [q1]
*[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 )
pS
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
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
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
={ 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
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
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
b
b
[q1]
Start 0,1
b q0 q1
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
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
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
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)
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
Step 4:
Move[C,a] = {3,8}
ε – closure (Move[C,a]) = {1,2,3,4,6,7,8} 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
a b
A B C
B B D
C B C
D B E
*E B C
84
Prepared By: R.GAJENDIRAN,ASP/IT ,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT I THEORY OF COMPUTATION
a b
A B A
B B D
D B E
*E B A
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:
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
0
A B
B C
C D
*D B
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
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
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
δ (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
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
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
TWO MARKS
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)*
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)*
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)*
Regular
Expression
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.
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.
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).
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.
3 4
ε 0
Start ε ε
ε
1 2
7 8
ε 5 6 ε
1
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
Then L‟={ε,aa,aab,..}
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
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
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
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’.
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,
The advantage of pumping lemma is that this theorem is used to check whether given language is
regular or not.
a,b
a,b
1 2
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)*)*)
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
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)*
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.
(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
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.
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.
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.
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)*;
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 )
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
ε
a
ε ε
ε 2 3 ε a b
6
b 1 1
0 1 7 8 9 0 1
b
4 5
ε ε
a b
ε
ε 3 4 5 b
ε
ε ε 10 11
9
1 2
6 7 8 ε
c
ε ε
To prove, L(A)=L(R).
ADFA, RRegular 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 iInitial state
jFinal state
kNumber 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.
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
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,
(k-1) (k-1)
Rik (k-1) Rkj
Rkk
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).
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
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*
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)
= Φ + Φ.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 )
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
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)
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
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 )
` = 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 )
= 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
= Є+ Φ
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
Step 1:
Consider the path q1 q3 by eliminating the state q2
1 0
q1 q3
0 0
q2
Q1 Q3
00
Where R ij = Φ S=Φ
Qi=0 Pj = 0
R1 =Φ+0Φ*0
=Φ+0Φ 0
R1 = 00
Step 2:
Consider the path q3 q1
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
1+01
0+10
00
Q1 Q3
11
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
qn = q1 α 1n + q2 α 2n + ….. + qn α nn
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
Q2 = q2 1 + q1 1 + q2 01
Q2 = q2 ( 1+01) + q1 1
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 ) *
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
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) *.
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
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
0
0
Start
1
A≡C≡D B≡E
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
δ(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)
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.
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 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})
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) ;
ε
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
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,
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
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
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
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’.
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
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’.
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.
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
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’.
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.
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
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’.
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.
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
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.
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]
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.
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
1
0
0 1
q0,
q0 q0, q2
q1
0
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
1
p,r p,s
0 1
0 1
0,1
q,r
q,s
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.
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
h (L)
h
h
L (L)
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).
*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
q6Final 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
a,b
q0 ≡ q1 ≡ q2 ≡ q3 ≡ q4 ≡ q5 q6
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.
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’.
= 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.
ε 0 ε 1 0
a b b b a b
ε ε
ε
ε 0 1
b b b b b
b
ε
ε 1 0
a b b b b ε
ε
a a
q6 q5
b
Start
q1
q2
a b b
a
b a
a b Start
b q7 q4
q2
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
0 1
q1 q2 q3
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
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.
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
1
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
6. What is the language generated by the grammar G=(V, T, P, S)Where P={ SaSb,Sab} ?
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.
(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.
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
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:
SAbc
AaaA | є
Find the language generated by:
S0S1 | 0A | 0 |1B | 1
A0A | 0
B1B | 1
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 { SaSa , SbSb, Sa, Sb, 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 { S0S0 , S1S1, S0, S1, Sє } which is in palindrome.
19. Let the productions of a grammar be S 0B, A0/0S/1AA, B1/1S/0BB. For the string
0110 find a right most derivation. [**MAY/JUNE 2007**]
String=0110
S0B
01S
011A
0110
S0110
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 SaCa , CaCa |b. Find L(G).
SaCa aba
SaCa aaCaa aabaa
SaCa 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}, {S0S1 ,Sє}, S ).[**Dec 2010**]
Sє , є is in L(G)
S0S1 0є1 01
S0S1 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}, { S0/1/є, S0S0/1S1/S} )
(i) S 0S0 (ii) S 1S1
01S10 10S01
01010 10001 L= { w; w is a palindrome}
25. Consider G whose productions are SaAS/a, ASbA/SS/ba. Show that S aabbaa.
S Aas SaAS
aSbAS ASbA
aabAS Sa
aabbaS Aba
aabbaa Sa
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 = { SaB | bA, Aa | 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 }
6
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
35. Let G be the grammar SaB|bA, Aa|aS|bAA, Bb|b|S|aBB. For the string aaabbabbba
find a leftmost derivation.(May/June‟07)(Apr/May „08)(Nov/Dec 2015)
Solution S aB
aaBB (BaBB)
aaaBBB (BaBB)
aaabBB (Bb)
aaabbB (Bb)
aaabbaBB (BaBB)
aaabbabB (Bb)
aaabbabbS (BbS)
aaabbabbbA (SbA)
aaabbabbba (Aa)
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…}
SAB
AaA/bA / Є
BbB/aB/Є
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)
EE+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
AaaA/ €
40. Derive a string „aababa‟ for the following context free grammar (CFG) Nov/Dec 2017
S aSX / b
XXb/a
Solution: S aSX (S aSX)
aaSXX (Sb)
aabXX (XXb)
aabXbX (Xa)
aababX (Xa)
aababa
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.
8
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
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 ) * }.
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.
10
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
54. Construct a PDA that accepts the language generated by the grammar. SaSbb / 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
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
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.
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
1. δ(q,Є,S)={(q,aAA)}
2. δ(q,Є,A)={(q,aS),(q,bS),(q,a)}
1. δ(q,a,a)={(q,Є)}
2. δ(q,b,b)={(q,Є)}
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
SaSb/ab
69. Write CFG to accept the language defined by, Nov/Dec 2021
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
2. Context sensitive grammar or context dependent grammar (Type1) (for Linear Bounded
Automata )
15
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
Computable languages
Regular language
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.
ABC 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
1) Derive the strings a*(a+b00) using leftmost and rightmost derivation for the following
production.
1. EI
2. EE+E
3. EE*E
4. E(E)
5. Ia
6. Ib
7. IIa
8. IIb
9. II0
10.II1
Solution
Leftmost Derivation
EE*E
I*E (EI)
a*E (Ia)
a*(E) (E (E))
a*(E+E) (EE+E)
a*(I+E) (EI)
a*(a+E) (Ia)
a*(a+I) (EI)
a*(a+I0) (II0)
17
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
a*(a+I00) (II00)
a*(a+b00) (Ib)
Rightmost Derivation
EE*E
E*(E) (E(E))
E*(E+E) (EE+E)
E*(E+I) (EI)
E*(E+I0) (II0)
E*(E+I00) (II0)
E*(E+b00) (Ib)
E*(I+b00) (EI)
E*(a+b00) (Ia)
I*(a+b00) (EI)
a*(a+b00) (Ia)
2) Show that the grammar SaSbS | bSaS | e is ambiguous and what is the language
generated by this grammar? (Nov/Dec 2006)
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
SA1B
A0A | Є
B0B | 1B | Є
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
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
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
D0 | 1 | 2 |…..9 E
Find a parse tree for the string 1+2*3. (6) (Nov/Dec 2015)
Solution 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
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
(a)Leftmost derivation
(b)Rightmost derivation
00BB (B0BB)
001B (B1)
0011S (B1S)
23
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
00110B (S0B)
001101S (B1S)
0011010B (S0B)
00110101 (B1)
(b)Rightmost Derivation
S 0B
00BB (B0BB)
00B1S (B1S)
00B10B (S0B)
00B101S (B1S)
00B1010B (S0B)
00B10101 (B1)
00110101 (B1)
(d)
S 0B
01S (B1S)
011A (S1A)
0110 (A0)
6) Find the language L(G) generated by the grammar G with variables S, A, B terminals a, b
and productions SaB, Bb, BbA, AaB.
Solution
(i)
S aB
Ab (Bb)
24
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
(ii)
S aB
abA (BbA)
abaB (AaB)
abab (Bb)
(iii)
S aB
abA (BbA)
abaB (AaB)
ababA (BbA)
ababaB (AaB)
ababab (Bb)
Leftmost Derivations
S SbS
abS (Sa)
abSbS (SSbS)
ababS (Sa)
ababSbS (SSbS)
abababS (Sa)
abababa (Sa)
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: SaS| 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
S aS
aaSbS
aaSbЄ
aaSb
aaЄb
aab
S aSbS
aSbЄ
aSb
aaSb
aaЄb
aab
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, AbS | aAAb is ambiguous. (May/June 2007)
S abSb
abab (Sa)
S aAb
abSb (AbS)
abab (Sa)
10) Show that the grammar S a | Sa | bSS | SSb | SbS is ambiguous (8) (Nov/Dec2007)
Leftmost Derivation
S Sa
bSSa (SbSS)
baSa (Sa)
baaa (Sa)
S bSS
bSaS (SSa)
baaS (Sa)
baaa (Sa)
28
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
Parse Tree:
SaSb | aAb
AbAa
Aba
Solution:
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
SS+S/S*S/a/b. (May/June 2007)
Solution
S S+S
S*S+S (Ss*S)
a*S+S (Sa)
a*b+S (Sab)
a*b+a*S (Sa)
a*b+a*b (Sb)
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
14) The following grammar generates the language of Regular expression 0*1(0+1)*.
SA1B
A0A | Є
B0B | 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
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.
SA1B / AC
C1B / 1/ Є
A0A / Є
B0B / 1B / Є
Now take the string 001011. Here we show that there exists two left most derivation and it shown
below.
SA1B
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 SaS | aSbS | Є. Show that the grammar is ambiguous
and create unambiguous grammar.
Solution
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
SaS | aCbS | Є
CaCbC | Є
Now take the string aab and derive it by using unambiguous grammar,
S aS
aaCbS
aaebS
aabS
aabЄ
S aab
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”
Solution:
(a)Find the leftmost and rightmost derivation and derivation tree for the string“+* - xyxy”
E+EE
E* EE
E-EE
Ex
Ey
Leftmost Derivation w = + * - xyxy
E + EE
+ * EEE
+ * - xEEE
+ * - xyEE
+ * - xyxE
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 SAB|Є , AaB, BSb (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}
SA
A0A1 | 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.
20. Construct a CFG to generate even add set of palindromes over alphabet {a,b}. Nov/Dec 2017
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
S00/10
P10
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
Solution:
q0 q1 q2 q3 q4
a, z0/z0
b, a/a
c, a/ε ε, z0/ε
w = aabcc
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).
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.
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} )
├ ρ (q1,bbb,aaaz0)
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.
W=aabbcc
41
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
W=abcc
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.
42
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
w = aaaaaabb
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.
Let q0 be the initial state and z0 be the top symbol of the stack initially.
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
w = 0011
(q0, 0011, z0) ├ ρ (q1,011,0z0)
├ ρ (q1,11,00z0)
├ ρ (q2,1,0z0)
├ ρ (q2, Є, z0)
├ ρ (q3, Є, Є) Accepted
So the string 0011 is accepted
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
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
Productions of CFG
P1: S [ q, z0, q]
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]
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,Ф)
Solution:
For the above PDA,
States = {q0, q1}
State Symbols = {X, z0}
Bottom initial stack symbol=z0
Initial state = q0
49
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
Productions of CFG
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
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
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]
51
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
δ(q,*,*)={(q,ε)}
δ(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:
w= abcba
Thus the CFG accepts the string abcba and it‟s accepted by PDA by empty stack.
W=acb
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
Thus the CFG accepts the string aa×a0 and it‟s accepted by PDA by empty stack.
W= (a0+a)
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, Cc and find
the PDA.
Solution:
The PDA is given below:
38. Construct the CFG for L = { 0n10 n | n ≥ 0} and use it to construct PDA.[Nov/Dec 2024]
Solution:
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:
56
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
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
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.
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.
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.
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.
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.
42. How Є -productions are eliminated from a grammar whose language does not have
empty string? Remove Є -productions from the grammar given below.
Sa/aA/B/C AaB/Є BAa CaCD Dddd (Nov/Dec 2020)
Solution:
After Eliminate Є –productions are
Sa/aA/B/C/a
AaB
BAa/a
CaCD
Dddd
43. Write procedure to find PDA to CFG. Give an example for PDA and its CFG.
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
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
w = abcd
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
⇒ 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
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Δ q5Accepted
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
66
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT III THEORY OF COMPUTATION
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
XXb/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 SaAA, AaS | 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
Xax/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.
Sa/aA/B/C AaB/Є BAa CaCD Dddd
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,
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,
71
Prepared By: Mr.R.GAJENDIRAN, ASP/IT
DEPARTMENT OF INFORMATION TECHNOLOGY
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
Each variable and each terminal of G appears in the derivation of some word in L
There are no productions of the form AB. where, A and B are variables.
2. Let G = (V, T, P, S) with the productions given by SaSbS/B/ε, BabB. Eliminate the
useless production.
S aSbS / ε
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)*.
SA
AaA / ε
B bA
Solution: The variable B is useless, since it is used by the start variable or by the variable in the start
production. BbA is a useless production.
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 AB, where both A and B are variables. These
productions can be useful.
Example:
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 BC is a production, then (A,C) is also a
unit pair.
Basis: Non Terminals are V={E,T,F,I}
Induction:
(E,E) EE+T
(E,T) ET*F
(E,F) E(E)
(E,I) EIa|Ib|I0|I1|a|b
(T,T) TT*F
(T,F) T(E)
(T,I) TIa|Ib|I0|I1|a|b
(F,F) F(E)
(F,I) FIa|Ib|I0|I1|a|b
(I,I) IIa|Ib|I0|I1|a|b
TT*F / (E) / Ia / Ib / I0 / I1 / a / b
F(E) / Ia / Ib / I0 / I1 / a / b
I Ia / Ib / I0 / I1 / a / b
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
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.
ii) The new grammar G is obtained by letting into P all non-unit productions of P.
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.
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.
ABC 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)
S ASA | aB S0 S
AB|S SASA | aB
Bb|Є AB|S
Bb|Є
Remove B Є Remove A Є
S0 S S0 S
AB|S|Є AB|S
Bb Bb
S 0A | 1B | C
A 0S | 00
B1|A
C 01
Solution: Clearly S C is a unit production. But while removing SC we have to consider what C
gives. So, we can add a rule to S.
S 0A | 1B| 01
B 1 | 0S | 00
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?
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
(i) |vx| ≥ 1
The pumping lemma can be used to prove a variety of languages are not context free.
SaAA, AaS | bS | a
Solution:
1. δ(q,Є,S)={(q,aAA)}
2. δ(q,Є,A)={(q,aS),(q,bS),(q,a)}
1. δ(q,a,a)={(q,Є)}
2. δ(q,b,b)={(q,Є)}
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.
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.
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.
δ (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
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.
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.
28. List out techniques for Turing machine construction. (Dec -13)
1. Storage in finite control
2. Multiple tracks
3. Checking off symbols
4. Subroutine.
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.
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.
Input tape 1
….. …..
Checking off symbols is useful method when a TM recognizes a language with repeated
strings and also to compare the length of substrings.
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.
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.
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.
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
….. …..
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.
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.
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).
(a,a,R)
(b,b,R)
(Δ, Δ,R)
Start (a,a,R)
qo q1 Halt
(Δ, Δ,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]
(1,1R) (0,0,R)
Start (0,0,R)
qo q1
Halt
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
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.
53. Draw Turing machine to compute double the value of an integer. Nov/Dec2021
(1,X,R) (1,1,L)
(1,1,R)
(B,B,R)
(B,1,L)
q3
Example 4
Find the CNF grammar for the following grammar,
SAB/aB
Aaab/ε
BbbA (May 2009) (10)
Solution 4
Eliminate useless symbols
a,b,ε generates itself
Aε, So ‗A‘ is generating
BbbA, So ‗B‘ is also generating
SAB, So ‗S‘ is also generating
Example 5
Find the CNF for the following grammar,
Sa/abSb/aAb
AbS/aAAb
Solution 5
Eliminate useless symbols:
a,b generates itself
Sa, So ‗S‘ is generating
AbS, So ‗A‘ is also generating.
Generating symbols:
S is reachable
SaAb, 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.
Example 6
Convert the following grammar into CNF
ScBA, SA, AcB, AAbbS, Baaa (Nov/Dec 2012)
Solution 6
ScBA | A,
AcB | AbbS,
Baaa
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
Acaaa
Baaa
Generating symbols = { S, A, B }
b) Eliminate є – Production
There is no nullable symbol and є-Production.
c) Eliminate Unit Production
ScBA | A,
AcB | AbbS,
Baaa
The above grammar after eliminating unit production.
ScBA | cB | AbbS,
AcB | AbbS,
Baaa
d) Find CNF for the above grammar
SC1C2|C1C3|C5 S
AC1C3|C5S
Baaa
C1c
C2BA
C3B
C4Ab
C5bC4
Example 7
Find a grammar equivalent to the following grammar
SAB/CA
Aa
BBC/AB
CaB/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 SCA, C and A are generating, S is also generating. So remove B, and then new
grammar is,
SCA
Aa
Cb
Now find the reachable symbols.
Reachable symbols={S, A, C, a, b}
Now the grammar with no useless symbols is,
SCA
Aa
Cb
Example 8
What is the purpose of normalization? Construct the CNF and GNF for the following
grammar and explain the steps.
(10)
SaAa | bBb | Є
AC | a
BC | b
CCDE | Є
DA | 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.
SaAa | bBb | Є
A a
Bb
Eliminate the Є production
SaAa | bBb | Є
A a
Bb
Eliminate SЄ
SaAa | bBb
C1AA
SAC1
Bb
SBBB
C2BB
SBC2
A1A2A2/0 ......(1)
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
Xb
A a
(vi) A2A1A2/b
(Here i=2,j=1 and i>j(2>1)
So apply rule 1 to replace the production body of A1 to A2
A2A1A2/b
Becomes
A2 A3A4A2/b
Since i<j (2<3), the production remains the same,
A2 A3 A4A2/b ........(2)
(vii) Apply
A3b in (1) & (2)
A1A3A4
Becomes
A1bA4
A2 A3A4A2/b
Becomes
A2 bA4A2/b
GNF Grammar
A1bA4
A2 bA4A2/b
A4a
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 γ α β γ
15. Construct a CFG to generate even add set of palindromes over alphabet {a,b}. Nov/Dec
2017
16. Generate CFG for the language L = { 0i1j0k | i>j+k}. Nov/Dec 2017
S 0S0/1P0
S00/10
P10
17. Find an equivalent grammar in CNF for the grammar: Nov/Dec 2017
SbA/aB
AbbA/aS/a
BaBB/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.
SaB
C2a
SC2 B
AbAA
A C1 AA
C3AA
A C1 C3
AaS
AC2 S
A
AaC1 C3
BaBB
B C2 BB
C4BB
ABbS
C2 C4
B C1S
Bb
A
CNFCare
C
1 3
18. Eliminate the unit production of the following grammar: Nov/Dec 2017
SA/bb
AB/b
BS/a
After Eliminate unit production
Sa/b/bb
Aa/b/bb
Bbb/a
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
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.
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.
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.
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
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.
….. 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
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
a b c
Track1 B B B X B -
Track2 B B B Y B - ……
Track3 B B B Z B -
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)
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
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.
Track1 1 1 1 B B -
Track2 B 1 0 B B - ……
Track3 1 1 1 B B -
7 7 7 7
2 2 2 2
7 5 3 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
7 7
5 5
7 2
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)
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 ∆ ∆ …
a b a c a b a ∆ ∆ … * * a c * * a ∆ ∆ …
* 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 ∆ ∆ …
* 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
* * 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.
Figure 4.14 – The Complete multiplication program uses the subroutine copy.
Instantaneous description on TM
∆ 0 1 1 0 1 1 ∆ …
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)
(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)
…. ∆ 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)
input Accept/reject
Finite
Control
Head 1 Head n
….. …..
Input tape 1
….. …..
Input tape 2
Prepared by: Mr.R.GAJENDIRAN, ASP/IT Page 52
DEPARTMENT OF INFORMATION TECHNOLOGY
….. …..
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;
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.
FINITE
STATE
CONTROL
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
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.
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
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 Δ Δ Δ Δ
(1,1,R)
(Δ, Δ,R)
Start (1,1,R) (Δ,1,R)
q1 q2 Halt
qo
N=4, f(4)=n+1
Instantaneous description
(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)
Instantaneous description
(q0 aabbΔ)├ Xq1abb Δ )├ Xaq1bb Δ )├ Xaq2YbΔ)├ Xq2aYb Δ)├ Xq0aYbΔ)├ XXq1Yb Δ)├
XXYq1b Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ XXYYΔ q4Accepted
(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
Instantaneous description
(Δ, Δ,R)
(b,b,R) (a,a,R)
Start (a,a,R) q2 q3
qo q1
Instantaneous description
(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)
(Δ, Δ,R)
Halt
Check the input w=110011
Instantaneous description
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)
Instantaneous description
(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
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
Instantaneous description
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)
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
q0 0011Δ├ Xq1011 Δ ├ X0q111 Δ )├ X0q2Y1 Δ)├ Xq20Y1 Δ)├ Xq00Y1 Δ)├ XXq1Y1 Δ)├
XXYq11 Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ ├ XXYYΔ q4Accepted
Halt
Instantaneous description
A TM Accepting { ss | s Є { a, b} *}
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
(Even palindrome)
Input w=aba
Instantaneous description
44. Design a TM to implement the function multiplication using the subroutine copy a
string.(Nov/Dec-14)
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
Instantaneous description
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 (2) – The Complete multiplication program uses the subroutine copy.
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)
q0 0011Δ├ Xq1011 Δ ├ X0q111 Δ )├ X0q2Y1 Δ)├ Xq20Y1 Δ)├ Xq00Y1 Δ)├ XXq1Y1 Δ)├
XXYq11 Δ)├ XXYq2YΔ)├ XXq2YYΔ)├ XXq0YYΔ├ XXYq3YΔ├ ├ XXYYΔ q4Accepted
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
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
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
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}
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
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
C1BS
S → AC1
(iii) S → A1A
S → AC2A
C21
C3C2A
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
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
(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
Instantaneous description
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
(Y,Y,R)
(X,X,R)
(Δ, Δ,R) (Y,Y,R)
q4
(Z,Z,R)
(Δ, Δ,R)
Halt
Instantaneous description
PART- A
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) 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
Nov/Dec 2016
PART A
April/May 2017
PART- A
PART- B
Nov/Dec 2017
PART-A
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
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)
Part C
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
PART C
1. Construct a Turing Machine for multiplying two non negative integers using
subroutine.
Nov/Dec 2021
PART A
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
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.
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.
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.
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
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.
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.
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.
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
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.
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.
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
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.
The NP- complete problems are – Traveling salesperson problems, graph coloring
problem.0/1 knapsack problem, Hamiltonian circuit problem.
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)
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.
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.
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
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.
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.
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
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.
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)
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.
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.
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.
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
11
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
A Turing Machine can compute anything that can be computed. This is the strong form of Turing
thesis.
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.
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.
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 unsatisfiable.
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:
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.
2-SAT
3-SAT is NP-complete.
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
δ(q1,1) = (q3, 0, R)
δ(q3, 0) = (q1, 1, R)
δ(q3, 1) = (q2, 0, R)
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)
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.
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
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.
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
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.
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.
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.
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
22
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
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.
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
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.
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.
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.
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.
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') =Ф.
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
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.
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:
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)
• 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.
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
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.
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
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 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.
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 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
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.
38
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
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
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=∞
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
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.
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.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.
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.
The Post's correspondence problem is: Given an instance of PCP, tell whether this instance has a
solution.
Theorem: MPCP reduces to PCP.
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:
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.
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
W
Accept
TM
Loops for ever
Input string
48
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
is unsatisfiable, because:
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
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
50
Prepared By: Mr.R.GAJENDIRAN,ASP/IT,
DEPARTMENT OF INFORMATION TECHNOLOGY
CS3452 UNIT V THEORY OF COMPUTATION
Table 5.1
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
(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
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