0% found this document useful (0 votes)
306 views

TOC - Question Answer

The document discusses finite automata and transition systems. It provides definitions for key concepts: - An automaton is a system that transforms inputs without direct human participation. A finite automaton can be represented as a 5-tuple including states, inputs, transitions, initial state, and final states. - A transition system is a graph representing an automaton's behavior, with states as nodes and labeled edges indicating transitions. It is also defined as a 5-tuple. - The difference between a nondeterministic finite automaton (NFA) and deterministic finite automaton (DFA) is that an NFA's transition function maps to sets of states while a DFA's maps to a single state.

Uploaded by

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

TOC - Question Answer

The document discusses finite automata and transition systems. It provides definitions for key concepts: - An automaton is a system that transforms inputs without direct human participation. A finite automaton can be represented as a 5-tuple including states, inputs, transitions, initial state, and final states. - A transition system is a graph representing an automaton's behavior, with states as nodes and labeled edges indicating transitions. It is also defined as a 5-tuple. - The difference between a nondeterministic finite automaton (NFA) and deterministic finite automaton (DFA) is that an NFA's transition function maps to sets of states while a DFA's maps to a single state.

Uploaded by

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

B.

E 5TH SEMESTER (CSE)


Theory of Computation
1. What is automata?
Solution: An automaton is defined as a system where energy, materials and information are
transformed, transmitted and used for performing some functions without direct participation of
man.
Example: automatic machine tools, automatic packing machines, automatic photo printing machine,
etc.
Model of discrete automaton is shown below:

Characteristics
i. Input: At each discrete instants of time t1, t2, … , input values I1,I2, …, each of which can take a
finite number of fixed values from the input alphabet ∑, are applied to the input side of model.
ii. Output: O1, O2, … , Oq are the outputs of the model, each of which can take finite numbers of
fixed values from an output O.
iii. States: At any instant of time the automaton can be in one of the states q1, q2, …, qn.
iv. State relation: The next state of an automaton at any instant of time is determined by present
state and present input.
v. Output relation: Output is related to either state only or to both the input and the state. At
any instant of time the automaton is in some state. On reading an input symbol, the
automaton moves to next state which is given by state relation.

2. What is finite automata and transition graph? What is use of transition graph?
Solution:
Finite Automata: A finite automaton can be represented by 5 tuple ( Q, ∑ , δ , q0, F ) where
i. Q is a finite nonempty set of states.
ii. ∑ is a +inite nonempty set of inputs called input alphabets.
iii. δ is a function which maps Q x ∑ → Q.
iv. q0 ∈ Q is the initial state.
v. F ⊆ Q is the set of final states.
Block diagram of finite automata is shown below:

Page | 1
Finite automata consists of input tape, reading head and finite control which are described below:
i. Input tape: The input tape is divided into squares, each square containing a single symbol from
input alphabet ∑. The end squares of the tape contain end markers ¢ at left end and $ at right
end. Absence of end markers indicates that the tape is of infinite length.
The left to right sequence of symbols between end markers is the input string to be processed.
ii. Reading head: The head examines only one square at a time and can move one square either to
the left or right.
iii. Finite control: The input to finite control is usually symbol under R head, say a, or present
state of machine say q, to give the following outputs:
A motion of R head along the tape to the next square.
The next state of the finite state machine given by δ(q, a).
In some null move, R head remaining to the same square is permitted.
 Transition System: It is also known as transition graph. It is a finite directed labeled graph in
which each vertex (node) represents a state and the directed edges indicate the transition of a
state and the edges are labeled with input/ output. A transition system is shown below:

An initial state is represented by a circle with an arrow pointing towards it (q0). Final state is
represented by two concentric circles (q1). Other states are represented by just a circle. The edges
are labeled by input/ output.
Definition: A transition system is a 5 tuple ( Q, ∑, δ, Q0, F ) where
 Q is finite nonempty set of states
 ∑ is +inite nonempty set of input alphabets
 F is finite nonempty set of final states
 Q0 ⊆ Q and Q0 is nonempty
 δ is a finite subset of Q x ∑* x Q.
 If ( q1, w, q2 ) is in δ, it means : the graph starts at vertex q1, goes along a set of edges, and
reaches the vertex q2. Concatenation of label of all the edges encountered is w.
Consider a transition system given below:

Page | 2
Here Q = {q0, q1}, ∑ = {0, 1}, F = {q1}, Q0 = q0,
The system is in state q0. When input 1 is applied, the system moves to state q1 as there is a directed
edge from q0 to q1 with label 1. And on applying input 0 system remains in same state i.e. q0. When
system is in state q1, on applying 0 system moves to state q0, while on input 1 system remains in
state q1.
Transition system is used to show the behavior of finite automata. We say a transition system
accepts a string w in ∑* if
a) there exist a path which originates from some initial state, goes along the arrows, and terminates
at some final state, and
b) the path value obtained by concatenation of all edge labels of the path is equal to w.

3. Give the formal definition of NFA and differentiate between NFA and DFA.
Solution: Consider the transition diagram
If the automaton is in state {q0} and input symbol is 0, then
next state will be either {q0} or {q1}. Thus some moves of the
machine cannot be determined uniquely by the input symbol and
present state. Such machines are called nondeterministic automata.
A nondeterministic finite automaton (NDFA) is a 5 tuple ( Q, ∑, δ, q0, F ) where
 Q is finite nonempty set of states
 ∑ is +inite nonempty set of input alphabets
 δ is a transition function mapping from Q x ∑ into 2Q, power set of Q (set of all subsets of Q)
 q0 ∈ Q is initial state
 F ⊆ Q is set of final states
 A string w ∈ ∑* is accepted by NDFA M if δ(q0, w) contains some final state.
A deterministic finite automaton (DFA) can be represented by 5 tuple ( Q, ∑ , δ , q0, F ) where
 Q is a finite nonempty set of states.
 ∑ is a +inite nonempty set of inputs called input alphabets.
 δ is a function which maps Q x ∑ → Q.
 q0 ∈ Q is the initial state.
 F ⊆ Q is the set of final states.
The difference between a DFA and NFA is only in transition function. In DFA, transition function
maps on at most one state and in NFA transition function maps on at least state for an input symbol.

4. Prove that for any transition function δ and for any two input strings x and y
δ(q, xy) = δ( δ(q, x), y)
Solution:
We will use property transition function as: for all strings w and input symbol a,
Page | 3
δ(q, aw) = δ( δ(q, a), w )
δ(q, wa) = δ( δ(q, w), a )
Basis: When |y| = 1, y = a∈∑
δ(q, xy) = δ( δ(q, x), y) …..given in question …….equation 1
LHS of equation 1 = δ(q, xy) … put y=a
δ(q, xa) = δ( δ(q, x), a) …. By property
= RHS of equation 1
Assume the result i.e. equation 1 for all strings x and strings y with |y| = n. let y be a string of length
n+1.
Write y = y1a where |y1| = n.
LHS of equation 1 = δ(q, xy1a) = δ(q, x1a) ….. put x1 = xy1
= δ( δ(q, x1), a ) …. By property
= δ( δ(q, xy1), a )
= δ( δ( δ(q, x), y1), a ) …. By induction hypothesis
RHS of equation 1 = δ( δ(q, x), y1a )
= δ( δ( δ(q, x), y1), a ) …. By property 2
Hence LHS = RHS. This proves equation 1 for any string y of length n+1. By the principle of
induction, equation 1 is true for all strings.

5. Define the terms:


a. Moore machine
b. Mealy machine
Solution:
Moore Machine: The Moore machine is a six tuple ( Q, ∑, Δ ,δ, λ, q0 ) where
 Q is finite set of states
 ∑ is input alphabets
 Δ is output alphabet
 δ is a transition function Q x ∑ into Q
 λ is output function mapping Q into Δ
 q0 is initial state
A typical Moore machine is shown below:

 For the input string 0111, transition of states is given by


0 1 1 1
Page | 4
q0  q3  q0  q1  q2
 The output string is 00010.
 For input string Λ, the output is λ (q0) = 0.

Mealy Machine: A Mealy machine is a six tuple ( Q, ∑, Δ ,δ, λ, q0 ) where


 Q is finite set of states
 ∑ is input alphabets
 Δ is output alphabet
 δ is a transition function Q x ∑ into Q
 λ is output function mapping ∑ x Q into Δ
 q0 is initial state
Note: Difference is only in output function λ.
A typical Mealy machine is shown below:

 For the input string 0011, transition of states is given by


0 0 1 1
q1  q3  q2  q4  q3
 The output string is 0100.
 We get an output only on application of an input symbol.
 So for input string Λ, the output is only Λ.

6. Construct minimum state automaton equivalent to transition diagram:

Solution:
 We construct transition table as follows

Page | 5
 Step 1 Construction of Π0:
Since there is only one final state Q10 = {q3}.
Q20 = Q - Q10, Q20 = {q0, q1, q2, q4, q5, q6, q7}.
Hence Π0 = { {q3}, {q0, q1, q2, q4, q5, q6, q7} }
 Step 2 Construction of Π1:
• q3 cannot be partitioned further, so Q11 = {q3}
• Consider q0 & q1 ∈ Q20.
• The entries under a column, corresponding to q0
and q1 are q1 & q0; they lie in Q20.
• The entries under b column are q0 & q2; they also lie in Q20.
• So q0 and q1 are 1 equivalent.
• Consider q0 & q2 ∈ Q20.
• The entries under a column, corresponding to q0 and q2 are q1 & q3; q1 ∈ Q20, q3 ∈ Q10.
• So q0 and q2 are not 1 equivalent.
• Consider q0 & q4 ∈ Q20.
• The entries under a column, corresponding to q0
and q4 are q1 & q3; q1 ∈ Q20, q3 ∈ Q10.
• So q0 and q4 are not 1 equivalent.
• Consider q0 & q5 ∈ Q20.
• The entries under a column, corresponding to q0
and q5 are q1 & q6; they lie in Q20.
• So q0 and q5 are 1 equivalent.
• Consider q0 & q6 ∈ Q20.
• The entries under a & b column, corresponding to q0 and q6 are q1 & q5 and q0 & q6; they lie
in Q20.
• So q0 and q6 are 1 equivalent.
• Consider q0 & q7 ∈ Q20.
• The entries under a column, corresponding to

Page | 6
q1 and q7 are q1 and q6; they lie in Q20.
• But entries under b column are q0 and q3, so they are not 1 equivalent.
• It is clear from table that q2 and q4 are 1 equivalent
• And q2 and q7 are not 1 equivalent
Hence Q11 = {q3}, Q21 = {q0, q1, q5, q6}, Q31 = {q2, q4}, Q41 = {q7}
Π1 = { {q3}, {q0, q1, q5, q6}, {q2, q4}, {q7} }
 Construction of Π2:
• q3 cannot be partitioned further, so Q12 = {q3}
• q7 cannot be partitioned further, so Q22 = {q7}
• Consider q2 & q4 ∈ Q31.
• The entries under a column, corresponding to
q2 and q4 are q3; they lie in Q11.
• The entries under b column are q1 & q5; they also lie in Q21.
• So q2 and q4 are 2 equivalents.
• Consider q0 & q1 ∈ Q21.
• The entries under a column, corresponding to
q0 and q1 are q1 and q0; they lie in Q21.
• The entries under b column are q0 & q2; they lie in different sets, q0 ∈ Q21, while q2 ∈ Q31.
• So q0 and q1 are not 2 equivalents.
• Consider q0 & q5 ∈ Q21.
• The entries under a column, are q1 and q6;
they lie in Q21.
• The entries under b column are q0 & q4; they lie in different sets, q0 ∈ Q21, while q4 ∈ Q31.
• So q0 and q5 are not 2 equivalents.
• Consider q0 & q6 ∈ Q21.
• The entries under a column, are q1 and q5;
they lie in Q21.
• The entries under b column are q0 & q6; they also lie in Q21.
• So q0 and q6 are 2 equivalents.
• Consider q1 & q5 ∈ Q21.
• The entries under a column, are q0 and q6;
they lie in Q21.
• The entries under b column are q2 & q4; they also lie in Q31.
• So q1 and q5 are 2 equivalents.
• Q12 = {q3}, Q22 = {q7}, Q32 = {q2, q4}, Q42 = {q0, q6}, Q52 = {q1, q5}
Hence Π2 = { {q3}, {q0, q6}, {q1, q5}, {q2, q4}, {q7} }.
Page | 7
 Construction of Π3:
• {q3}, {q7} cannot be partitioned further.
• Consider q1 & q5 ∈ Q52.
• The entries under a column, are q0 and q6;
they lie in Q42.
• The entries under b column are q2 & q4; they also lie in Q32.
• So q1 and q5 are 3 equivalents.
• Consider q2 & q4 ∈ Q32.
• The entries under a column, are q3 and q3.
• The entries under b column are q1 & q5; they
also lie in Q52.
• So q2 and q4 are 3 equivalents.
• Consider q0 & q6 ∈ Q42.
• The entries under a column, are q1 and q5; lie in
Q52.
• The entries under b column are q0 & q6; they also lie in Q42.
• So q0 and q6 are 3 equivalents.
• Q13 = {q3}, Q23 = {q7}, Q33 = {q2, q4}, Q43 = {q0, q6}, Q53 = {q1, q5}
• Hence Π3 = { {q3}, {q0, q6}, {q1, q5}, {q2, q4}, {q7} }.
• As Π2 = Π3, Π2 gives the equivalence classes, the minimum state automaton is
M’ = ( Q’, {a, b}, δ’, q0’, F’ ) where
Q’ = { [q3], [q0, q6], [q1, q5], [q2, q4], [q7] }.
q0‘ = [q0, q6]
F’ = [q3], and δ’ is given by

7. Consider a Mealy machine described by the table:

Page | 8
Transform it into Moore machine.
Solution:
We know that λ (output function) for Mealy machine maps ∑ x Q into Δ whereas output function for
Moore machine maps Q into Δ.
 We proceed by splitting states qi into several states, the number of such states being equal to
number of different outputs associated with qi.
 Here q1 is associated with output 1 at each place.
 q2 is associated with two different outputs 0 and 1.
 So split q2 into q20 and q21 for output 0 and 1 respectively.
 q3 is associated with output 0.
 Split q4 into q40 and q41.

 Now reconstruct the table as below

 The pair of states and outputs in next state column can be rearranged as

Page | 9
 The table gives Moore machine.
 Observe that initial state is q1 is associated with output 1.
 Means with input Λ we get an output 1.
 Thus, this Moore machine accepts null sequence, which is not accepted by Mealy machine.
 So, we must add a new starting state q0 with output 0 and transitions identical with q1.

8. Consider Moore machine

Transform it into Mealy machine.


Solution:
Let M1 = ( Q, ∑, Δ, δ, λ, q0 ) be a Moore machine, then equivalent Mealy machine M2 can be
constructed as:
a) Define output function λ’, for Mealy machine as function of present state and input symbol
λ‘ (q, a) = λ ( δ (q, a) ) for all states q and input symbols a
b) The transition function is the same as of Moore machine.

 For every input symbol we form pair consisting of next state and corresponding output.
Page | 10
 State q3 and q1 in next state column should be associated with outputs 0 and 1 respectively,
and 0 for both q2 and q0.
 Now reconstruct the table as below

 We can reduce the number of states in any model by considering states with identical
transitions.
 If two states have identical transitions, then we can delete one of them.

Page | 11
9. Explain two way finite automata.
Solution:
In finite automata head movement is restricted from left to right direction. If we remove such
restriction and allowing head to move in both direction left to right and right to left but in one
direction at a time. This enhancement in finite automata results a new model called two – way
finite automata. This model does not increase power of finite automata.

Let M = ( Q, ∑, δ, q0, F ) be a two – way FA where


 Q is finite nonempty set of states
 ∑ is +inite nonempty set of input alphabets
 F is finite nonempty set of final states
 q0 is initial state
 δ is a finite subset of Q x ∑ → Q x {L, R}
…….(where L stands for left and R for right)
Example:
If δ(p, a) = (q, R) then
 two – way FA reads symbol ‘a’ in present state p
 Moves right one cell and reaches next state q
 Description shows behavior of two – way FA indicating
What is present state?
What is present input symbol under reading head?
What is next state?
What is direction of movement?
 All these together is called Instantaneous Description (ID) of two – way finite automata.

Page | 12
 The head is under input symbol ai.
 Present state is q1.
 After reading this symbol, 2DFA moves in state s
 and head movement is right, then
a1 a2 ….. (q1) ai ai+1 ….. an | a1 a2 ….. ai (s) ai+1 ….. an
 This representation of ∑* Q ∑* is known as ID, which indicates read symbols, present state and
remaining symbols of input string.
 Let ID1 = a1 a2 ….. (q1) ai ai+1 ….. an and
 ID2 = a1 a2 ….. ai (s) ai+1 ….. an
 Then ID1 | ID2
 Similarly ID1, ID2 , ID3, …. IDn at time instants t1, t2, …tn then
 ID1 | ID2 | ID3 | IDn

10. Explain My-hill Nerode’s theorem with example and discuss its properties.
Solution: A given language L is a regular language if and only if set of equivalence classes of L is
finite. Or
1. Language L can be divided into set of all possible strings into separate (mutually exclusive)
classes.
2. If L is a regular language then number of classes created is finite.
3. If number of classes that L has, is finite then L is regular language.
Properties:
Classes are Mutually Exclusive:
Let z be a string and DFA M = (Q, ∑, δ, q0, F) and M accepts L then δ(q0, z) = Φ (if rejected by M and z
∉ L). or
δ(q0, z) = qn, for some qn ∈ F (since M is DFA and hence only one reachable state and z ∈ L).
For all possible strings z, either z belongs to a unique class, say Cn contains it or it is rejected.
Hence classes are mutually exclusive.
If L is a regular language then the number of classes created is finite:
L is a regular language so some DFA M recognizes it. We know that DFA has finite number of states.
So, number of societies it creates is finite. It may be there, some societies may be equivalent and so

Page | 13
if we combine these equivalent societies into one end we can have minimum state DFA and then
societies are disjoint. These disjoint societies are called classes of language L. Hence if L is regular
language then number of classes, it has, is finite.
If number of classes is finite, then L is a regular language:
Let classes be C0, C1, C2, …, Cn for some fixed value of n. We can suppose these classes as states of
DFA such that:
a) The class containing ε (null string) is initial state.
b) For all wi ∈ L the class having wi is the final state.
c) There is a transition (edge) from the state Ci to Cj with label a if x ∈ Ci and xa ∈ Cj.
Hence if number of classes is finite, then L is a regular language.
Example:
Show that L = {anbn : n ≥ 1} is not regular.
Solution:
o In the given language number of a’s is equal to number of b’s.
o So L = {ab, aabb, aaabbb, aaaabbbb…..}
o Depending on the value of n, classes are C1, C2, C3,…., Cn.
o So, if value of n is finite then number of classes are finite.
o Consider n=3 then, C1 = {ab}, C2 = {aabb}, C3 = {aaabbb}
o If value of n is very large (say tends toward infinite), then number of classes are infinite and it
does not satisfy Myhill Nerode theorem.
o So, L is not regular.

11. Design a finite automata that reads strings made up of letters in the word “HOUSE” & recognizes
those strings that contain the word “USE” at anywhere.
Solution: There are 5 symbols in word “HOUSE”. We have to recognize the strings containing the
word “USE” at anywhere. So, our aim is to design a DFA in which symbol ‘U’, ‘S’, and ‘E’ present
contiguous. The word “USE” may be preceded and followed by any combination of symbols ‘H’, ‘O’,
‘U’, ‘S’, and ‘E’ and any number of times.

So, we can represent the language as L = (H+O+U+S+E)*USE(H+O+U+S+E)*


The equivalent transition diagram is shown below

By splitting “USE” the transition diagram shown above can be represented as

Page | 14
The automata shown above is nondeterministic as on applying input ‘U’ the system can move to
state q0 or q1. So, convert this NFA
to DFA.
The transition table can be given
as:

Conversion of NFA to DFA:


The initial state is q0, so start with q0.
Write q0 under State column.
On applying input ‘H’, ‘O’, ‘U’, ‘S’, ‘E’, the system moves to state q0, q0, [q0, q1], q0, q0 respectively.
Here we get [q0, q1] as new state which is not present in state column.
Take union of states q0 and q1 for input columns ‘H’, ‘O’, ‘U’, ‘S’ and ‘E’.
We get q0, q0, [q0, q1], [q0, q2], q0 respectively.
Here [q0, q2] is new state.
Take union of states q0 and q2 for input columns ‘H’, ‘O’, ‘U’, ‘S’ and ‘E’.
We get q0, q0, [q0, q1], q0, and [q0, qf] respectively.
Here [q0, qf] is new state.
Take union of states q0 and qf for input columns ‘H’, ‘O’, ‘U’, ‘S’ and ‘E’.
We get [q0, qf], [q0, qf], [q0, q1, qf], [q0, qf] and [q0, qf] respectively.
Now [q0, q1, qf] is new state.
Take union of states q0, q1 and qf for input columns ‘H’, ‘O’, ‘U’, ‘S’ and ‘E’.
We get [q0, qf], [q0, qf], [q0, q1, qf], [q0, q2, qf] and [q0, qf] respectively.
Now [q0, q2, qf] is new state.
Take union of states q0, q2 and qf for input columns ‘H’, ‘O’, ‘U’, ‘S’ and ‘E’.
We get [q0, qf], [q0, qf], [q0, q1, qf], [q0, qf] and [q0, qf] respectively.
And we do not get any new state which is not present under state column. Stop construction of
table. Now the system represents DFA. The corresponding transition table is given below:

Here q0 is initial state while [q0, qf], [q0, q1, qf] and [q0, q2, qf] are final states. As final state qf of
NFA is associated with these states.
The equivalent transition system can be given as:

Page | 15
12. Consider the transition system and prove that the string recognized by it is
(a + a ( b +aa )* b )* a ( b + aa )* a

Solution:
There are three states so, make three equations for q1, q2 and q3 as follows:
q1 = q1a + q2b + Λ (incoming edges to q1, Λ is added as q1 is initial state)
q2 = q1a + q2b + q3a (incoming edges to q2)
q3 = q2a (incoming edges to q3)
Substitute q3 in q2 equation… we get
q2 = q1a + q2b + q2aa
q2 = q1a + q2 ( b+aa)
q2 = q1a ( b + aa )* by Arden’s rule R = Q + RP  R = QP*
Substitute q2 in q1
q1 = q1a + q1a (b+aa)*b + Λ
q1 = q1 (a + a ( b+aa)* b) + Λ
q1 = Λ (a + a (b + aa)* b)* by Arden’s rule R = Q + RP  R = QP*
Put q1 for q2
q2 = (a + a (b + aa)* b)* a(b + aa)*
Put q2 for q3
q3 = (a + a (b + aa)* b)* a (b + aa)* a
Since q3 is final state, set of strings recognized by graph is
(a + a (b + aa)* b)* a (b + aa)* a

13. Write short notes on closure properties of regular sets.


Solution:
Regular sets are closed under following:
1) Union
2) Concatenation

Page | 16
3) Kleene Closure
4) Complementation
5) Transpose
6) Intersection
Union: Class of two regular sets S and T are closed under union operation. If S and T are two
regular sets then union of these denoted by S + T or S ∪ T is also a regular set.

Concatenation: Class of two sets S and T are closed under concatenation operation. If S and T are
two regular sets then union of these denoted by S T is also a regular set.

Kleene Closure: Class of regular set S is closed under Kleene closure operation. If S is a regular set,
then Kleene closure of this denoted by S* is also a regular set.

Complement: If S is a regular set over some alphabet ∑, then complement of S is denoted by ∑* − S


or S, is also a regular set. Let regular set S is represented as below:

Construction of complement of regular set:


• Change all final states to non-final states.
• Change all non-final states to final states.
∑* − S or S is represented as:

Page | 17
Transpose: If S is a regular set then transpose of S is denoted by SR, is also a regular set. Let regular
set S is represented as below:

Construction of transpose of regular set:


• Change all final states into non-final states and merge all these into one state and make it
initial state.
• Change initial state to final state.
• Reverse the direction of all edges or arches and maintain labels.
SR is represented as:

Intersection: Classes of two sets S and T are closed under intersection operation. If S and T are two
regular sets over ∑, then intersection of these denoted by S ∩ T is also a regular set.

14. Explain Pumping lemma for a regular set and also explain application of Pumping lemma.
Solution:
Pumping lemma shows that specific given languages are not regular.
Statement:
If A is a regular language, then there is a number m (the pumping length) where, if s is any string in
A of length at least m, then s may be divided into three pieces, s = xyz, satisfying the following
conditions:
1. for each i ≥ 0, xyiz ∈ A,
2. |y| > 0, and
3. |xy| ≤ m.
Details of Proof
Consider L - any infinite regular language.
1. L regular → there is a DFA M with L(M) = L.
2. Let DFA have m states (say).
3. Let w in L be of length more than m.
4. δ*(s,w) = f (some final state) must be
δ*(s, w = xyz) = δ*(q,yz) = δ*(q,z) = f
5. So xynz in L for n = 0, 1, 2, 3, ....
Since δ*(s, xynz) = δ*(q, ynz) = δ*(q, y{n-1}z) = ... = δ*(q,z) = f.
Describing
Page | 18
Take an infinite regular language L
DFA that accepts L having m states
Take strings w with w∈ L
There is walk label: w

If string w has length |w| ≥ m number of states


Then, a state q is repeated in the walk w

Write w = xyz

Observation:
Length |xy| ≤ m
Length |y| ≥ 1
The string xz is accepted.
The string xyyz, xyyyz is accepted.
The string xyiz is accepted where i = 0, 1, 2, 3, ….
Application of Pumping lemma
Used to check that certain sets are regular or not.
The following languages are not regular.
1. {anbn | n ≥ 0 }.
2. {w = wR | w in {a,b}* } (language of palindromes).
3. {wwR | w in {a,b}*}.
4. {a{n2} | n ≥ 0}.

15. Using Pumping lemma show that language {anbn : n>0} is not regular.
Solution:
In the language number of a’s is equal to number of b’s. This is the clue to find the contradiction.
Step 1: let L is regular and accepted by DFA M with n states.
Step 2: string w ∈ L such that |w| ≥ n and w = xyiz ∈ L for i ≥0, y ∉ ε, and |xy| ≤ n.
Step 3: selecting substring y (y ≠ ε)
Page | 19
Let w = xyiz for i = 0, that is w = xz
Case 1: when y = ap, then w =an-p bn
number of a’s = n-p and number of b’s = n
number of a’s = number of b’s iff p=0
And number of a’s and b’s is not equal when p > 0
Since y ≠ ε for p>0, so w = xyiz ∉ L.
Case 2: when y = bq, then w =an bn-q
number of a’s = n and number of b’s = n-q
number of a’s = number of b’s only if q=0
And number of a’s and b’s is not equal when q > 0
Since y ≠ ε for q>0, so w = xyiz ∉ L.
Case 3: when y = ap bq, then w =an-p bn-q
xyz = an-p ap bq bn-q,
let i = 2, xy2z = an-p ap bq ap bq bn-q .
xy2z is not in an bn format, hence xy2z ∉ L.
Hence L is not regular.

16. Define regular expression.


Solution:
Regular expressions are useful for representing certain sets of strings in an algebraic fashion. These
describes the languages accepted by finite state automaton. Recursive definition over ∑
1) Any terminal symbol (element of ∑), Λ, Φ are regular expressions.
2) Union of two regular expressions R1 and R2, (R1+R2) is also a regular expression.
3) Concatenation of two regular expressions R1 and R2, (R1R2) is also a regular expression.
4) The iteration (or closure) of a regular expression R, (R*) is also a regular expression.
5) If R is a regular expression then (R) is also a regular expression.
Note:
a) Use x for regular expression to distinguish it from symbol (or string) x.
b) Parenthesis (used in rule 5) influence the order of evaluation of a regular expression.
c) In absence of parenthesis, use hierarchy of operations as iteration (closure), concatenation, and
union (similar to exponentiation, multiplication and addition).

17. Construct a FA equivalent to regular expression (0+1)* (00+11) (0+1)*.


Solution:
1) Construction of transition graph (transition system) equivalent to given regular expression
using Λ moves.

( 0 + 1 )* ( 00 + 11 ) ( 0 + 1 )*

Page | 20
Eliminate concatenation

Eliminate * operation

Eliminate concatenation and +

After elimination of Λ moves

This represents nondeterministic finite automata equivalent to ( 0 + 1 )* ( 00 + 11 ) ( 0 + 1 )*

18. Define grammar.


Solution:
A grammar express languages and is defined as
G = ( VN, ∑, P, S )
VN is finite nonempty set of variables
∑ is +inite nonempty set of terminals
VN ∩ ∑ = Φ
S is special variables (element of VN) called start symbol
P is finite set of production rules.
Page | 21
Elements of P are α → β, where α and β are strings on VN∪∑.
α has at least one symbol from VN.

19. Find a reduced grammar equivalent to the grammar S → aAa, A → bBB, B → ab, C → aB.
Solution:
Step 1: Construct grammar G1 equivalent to G so that every variable in G derives some terminal
string.
Construction of VN
W1 = {B}………{as B → ab is the only production in with a terminal string on the RHS
W2 = W1 ∪ { X ∈ VN | X → α where α ∈ ( ∑ ∪ W1 )* }
W2 = {B} ∪ {C, A} …..{as A → bBB, C → aB
W2 = {A, B, C}
Similarly
W3 = {A, B, C} ∪ {S} ……{as S → aAa
W3 = {S, A, B, C}
W4 = {S, A, B, C} ∪ {∅}
W3 = W4
VN = W3 = {S, A, B, C}
Construction of P’
P’ = { X → α | X, α ∈ (V’N ∪ ∑)* }
Hence, P’ consists of
S → aAa, A → bBB, B → ab, C → aB
Step 2: Construct grammar G2 equivalent to G such that every symbol in G1 appears in some
sentential form.
Construction of Wi for i ≥ 1
W1 = {S} …{S is start symbol
W2 = W1 ∪ {X ∈ VN ∪ ∑ | there exist a production A → α with A ∈ Wi and α containing the symbol X}
W2 = {S} ∪ {a, A} ….{as S → aAa
W2 = {S, A, a}
W3 = {S, A, a} ∪ {b, B}….{as A → bBB

Page | 22
W3 = {S, A, B, a, b}
W4 = {S, A, B, a, b} ∪ {∅}
W4 = {S, A, B, a, b}
W3 = W4
Construction of V’N, ∑’ and P’
V’N = VN ∩ W3
V’N = {S, A, B, C} ∩ {S, A, B, a, b}
V’N = {S, A, B}
∑’ = ∑ ∩ W3
∑’ = {a, b} ∩ {S, A, B, a, b}
∑’ = {a, b}
P’ = { X → α | X ∈ W3 }
P’ = { S → aAa, A → bBB, B → ab }
G’ = ( { S, A, B}, {a, b}, P’, S )
We can see that symbol C is eliminated completely.
Hence, G’ is the reduced grammar.

20. Using Pumping lemma show that L = {anbncn : n≥0} is not context free language.
Solution:
Pumping lemma
1) |vx| ≥ 1
2) |vwx| ≤ n
3) uviwxiy is in L for all i ≥ 0
Assume that L is context free .
L = {abc, aabbcc, aaabbbccc, ….}
Let w = aabbcc
By Pumping lemma, we know that
w = uviwxiy
let u → Λ
y→Λ
w = viwy
w = (aa)i bbcc
for i = 1 w = aabbcc which is in L
for i = 2 w = aaaabbcc which is not in L
Therefore the language is not context free language.

21. Define ambiguity. If G is a grammar S → SbS | a show that G is ambiguous.


Solution:
A context-free grammar G is ambiguous if some string w ∈ L(G) has two or more derivation trees.
In other words, A context-free grammar G is ambiguous if some string w ∈ L(G) has two or more
leftmost derivations (or rightmost derivation).
Page | 23
S → SbS | a
Consider a string abababa
Perform leftmost derivation at each step

S ⇒ SbS
⇒ abS …{ apply S → a
⇒ abSbS …{ apply S → SbS
⇒ abSbSbS …{ apply S → SbS
⇒ ababSbS …{ apply S → a
⇒ abababS …{ apply S → a
⇒ abababa …{ apply S → a

S ⇒ SbS
⇒ SbSbS …{ apply S → SbS
⇒ SbSbSbS …{ apply S → SbS
⇒ abSbSbS …{ apply S → a
⇒ ababSbS …{ apply S → a
⇒ abababS …{ apply S → a
⇒ abababa …{ apply S → a

As we can see that for string abababa we have two leftmost derivations. So the given grammar is
ambiguous.

22. Write short notes on left linear grammar, right linear grammar, context free grammar.
Solution:
General production form of CFG
(V ∪ T)+ → (V ∪ T)* where V is variable (nonterminal), T is terminal

Right Linear Grammar


 Production of form: V → T* V or V → T*
 Left hand side should have a single variable.
 Right hand side consists of any number of terminals optionally followed by a single variable.

Left Linear Grammar


 Production of form: V → VT* or V → T*
 Left hand side should have a single variable.
 Right hand side consists of optional single variable followed by any number of terminals.

Context Free Grammar


A grammar is a 4-tuple (V, ∑, P, S) where
 V is a finite set of variables or non-terminals
 ∑ is a +inite set of terminals (V ∩ ∑ = ∅)

Page | 24
 P is a set of productions or substitution rules of the form A → α where A is a variable and α is a
string with variables and terminals
 S is a variable called the start variable
A grammar is called type 2 or context free if it contains only type 2 productions.
 A type 2 production is of the form
A → α, where A ∈ VN, α ∈ ( VN ∪ ∑ )*
 LHS has no left and right context.
 Example: S → Aa, A → B, B → b, B → Λ, A → abc

23. Explain Chomsky Normal Form and Greibach Normal Form with example.
Solution:
Chomsky Normal Form (CNF)
A context free grammar is in Chomsky normal form (CNF) if every production is of the form A → α,
or A → BC, and S → Λ is in G if Λ ∈ L(G). If Λ is in L(G), we assume that S does not appear on RHS of
any production.
Example:
If productions in G are S → AB | Λ, A → a, B → b, then G is in Chomsky Normal Form (CNF).

Greibach Normal Form (GNF)


A context free grammar is in Greibach normal form (GNF) if every production is of the form A → aα,
where α ∈ VN* and a ∈ ∑ (α may be Λ) and S → Λ is in G if Λ ∈ L(G) and assuming that S does not
appear on RHS of any production.
Example:
Grammar given by S → aAB | Λ, A → bC, B → b, C → c is in GNF.
Advantage of GNF:
 It avoids left recursion.
 It always has terminal at leftmost position in RHS of each production rule.
 It helps in selecting the suitable production in derivation of a string.
 It guarantees derivation length no longer than string length.

24. Reduce the following grammar G into Chomsky normal form.


S → aAD, A → aB | bAB, B → b, D → d.
Solution:
CNF: A context free grammar is in Chomsky normal form if every production is of the form A → α,
or A → BC, and S → Λ is in G if Λ ∈ L(G)
Step 1- Elimination of null productions and unit productions:
As no null productions or unit productions exists, so proceed to step 2.
Step 2- Elimination of terminals on RHS:
G’ = (V’N, {a, b, d}, P1, S)
P1 is constructed as follows:
Page | 25
B → b, D → d are included in P1
S → aAD gives S → CaAD and Ca → a
A → aB gives A → CaB and Ca → a
A → bAB gives A → CbAB and Cb → b
Hence V’N = {S, A, B, D, Ca, Cb }
Step 3- Restricting the number of variables on RHS:
P1 consists of
S → CaAD, A → CaB | CbAB, B → b, D → d, Ca → a, Cb → b
A → CaB, B → b, D → d, Ca → a, Cb → b are included in P2.
S → CaAD is replaced by S → CaC1, C1 → AD
A → CbAB is replaced by A → CbC2, C2 → AB
Let G2 = ({S, A, B, D, Ca, Cb, C1, C2}, {a, b, d}, P2, S)
Where P2 is
S → CaC1, A → CaB | CbC2,
C1 → AD, C2 → AB,
B → b, D → d,
Ca → a, Cb → b

G2 is in CNF and equivalent to G.

25. Construct a grammar in Greibach normal form equivalent to S → AA | a, A → SS | b.


Solution:
A context free grammar is in Greibach normal form (GNF) if every production is of the form A → aα,
where α ∈ VN* and a ∈ ∑ (α may be Λ).
During reduction to GNF we use two types of lemma which are given as:
Lemma 1:
Let A → Bγ be an A production in P.
Let B productions be B → β1 | β2 | … | βs .
Define P1 = (P – {A → Bγ}) ∪ {A → βi γ | 1 ≤ i ≤ s}
Lemma 2:
Let set of A productions be A → Aα1 | … | Aαr | β1 | … | βs (βi‘s do not start with A).
Let Z be a new variable. Let G1 = (VN ∪ {Z}, ∑, P1, S) where P1 is defined as
The set of A productions in P1 are
A → β1 | β2 | … | βs
A → β1Z | β2Z | … | βsZ
The set of Z productions in P1 are
Z → α1 | α2 | … | αr
Z → α1Z | α2Z | … | αrZ

Page | 26
Reduction into GNF:
Step 1:
 The grammar has no null production and is in CNF.
 Nonterminal S and A are renamed as A1 and A2 respectively.
 So productions are A1 → A2 A2 | a, A2 → A1 A1 | b
Step 2:
 A1 productions are in required form (not in GNF).
 They are A1 → A2 A2 | a.
 A2 → b is in required form.
 A2 → A1 A1 is not in required form.
 So apply lemma 1, and resulting productions are A2 → A2A2A1, A2 → aA1
 Till now the productions are
A1 → A2A2 | a
A2 → b
A2 → A2A2A1 | aA1
Step 3:
 Apply lemma 2 to A2 → A2A2A1 (An → Anγ form)
 Let Z2 be new variable.
 Resulting productions are
A2 → aA1, A2 → b
A2 → aA1Z2, A2 → bZ2
Z2 → A2A1, Z2 → A2A1Z2
 Till now the productions are
A1 → A2A2 | a
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → A2A1 | A2A1Z2
Step 4:
 Among A1 productions we retain A1 → a and eliminate A1 → A2A2 using lemma 1.
 Resulting productions are A1 → aA1A2 | bA2 | aA1Z2A2 | bZ2A2
 Till now the productions are
A1 → a | aA1A2 | bA2 | aA1Z2A2 | bZ2A2
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → A2A1 | A2A1Z2
Step 5:
 Z2 productions to be modified are
Z2 → A2A1, Z2 → A2A1Z2 Apply lemma 1.
 Z2 → bA1 | aA1A1 | aA1Z2A1 | bZ2A1
 Z2 → bA1Z2 | aA1A1Z2 | aA1Z2A1Z2 | bZ2A1Z2
 Hence the equivalent grammar is

Page | 27
 G’ = ( {A1, A2, Z2}, {a, b}, P1, A1) where P1 consists of
A1 → a | aA1A2 | bA2 | aA1Z2A2 | bZ2A2
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → bA1 | aA1A1 | aA1Z2A1 | bZ2A1
Z2 → bA1Z2 | aA1A1Z2 | aA1Z2A1Z2 | bZ2A1Z2
 This is the required grammar in GNF.

26. Consider the grammar


S → AB, A → aaA, B → Bb, A → λ, B → λ
Find leftmost derivation, rightmost derivation and derivation tree.
Solution:
Leftmost derivation:
S ⇒ AB
⇒ aaAB ….{ A → aaA
⇒ aaB ….{ A → λ
⇒ aaBb ….{ B → Bb
⇒ aab ….{ B → λ
Rightmost derivation:
S ⇒ AB
⇒ ABb ….{ B → Bb
⇒ Ab ….{ B → λ
⇒ aaAb ….{ A → aaA
⇒ aab ….{ A → λ

Derivation tree for above derivation

27. Explain Chomsky hierarchy of grammar with example.


Solution:
 A type 0 grammar is a grammar without any restriction.
In a production of the form Φ A Ψ → Φ α Ψ,
Page | 28
 A is a variable
 Φ is called left context
 Ψ is called right context
 Φ α Ψ is a replacement string
 In a b A b c d → a b A B b c d
 ab is left context, bcd is right context, α = AB.
 In A C → A, A is left context, Λ is right context. α = Λ.
 The above production erases C.
 For C → Λ, left and right context are Λ. α = Λ.
 A production of the form Φ A Ψ → Φ α Ψ is called type 1 production if α ≠ Λ. (erasing of A is not
permitted).
 A grammar is called type 1 or context sensitive or context dependent if all its productions are
type 1 productions.
 The production S → Λ is allowed in type 1 grammar, but S should not appear on right hand side
of any production.
 Language generated by type 1 grammar is called type1 or context sensitive language.
 A type 2 production is of the form
A → α, where A ∈ VN, α ∈ ( VN ∪ ∑ )*
 LHS has no left and right context.
 Example: S → Aa, A → B, B → b, B → Λ, A → abc
 A grammar is called type 2 or context free if it contains only type 2 productions.
 A production of the form A → a, A → a B is called type 3 production, where A, B ∈ VN, a ∈ ∑
 A grammar is called type 3 or regular grammar if all its productions are type 3 productions.
 S → Λ is also allowed but S should not appear on right hand side of any production.

Page | 29
28. Define Pushdown automata and Turing Machine.
Solution:
Pushdown Automata:
Pushdown automatons are nondeterministic devices. It recognizes context free languages. A finite
automaton cannot accept language L (strings of the form anbn). Why? Because it has to remember
number of a’s in string and hence require infinite number of states. PDAs are enhanced version of
Finite Automata. A finite automata with stack memory can be viewed as PDA. This stack is read/
write memory. Stack memory is infinite and its operation is based on LIFO. Stack memory is known
as pushdown store (PDS).

Description
PDA consists of Finite tape, Reading head (which reads from the tape), Stack memory (pushdown
store, which is read/ write and operated in LIFO fashion). There are two alphabets for input
symbols to be read: One for input tape another for stack. Stack alphabet is denoted by Γ. Input
alphabet is denoted by ∑ . PDA reads from both alphabets (one input from tape and one from top of
stack). After reading both inputs, PDA moves in next state and writes zero or more symbols on the
stack. After writing on the stack, pointer to top of stack is auto adjusted, and points to top of stack.
Same operation is carried out for entire inputs on tape. At end of operation, content of stack
memory is considered as output produced by pda.
Mathematical Description
 PDA is described by 7 tuples: ( Q, ∑, Γ, δ, q0, Z0, F )
 Q is finite nonempty set of states
 ∑ is input alphabet
 Γ is finite nonempty set of pushdown symbols
 δ is transition function, maps from Q x (∑ ∪ {Λ}) x Γ to Q x Γ*
 q0 ∈ Q, is initial state
 Z0 ∈ Γ is starting stack symbol
 F ⊆ Q, set of final states

Page | 30
Turing Machine:
It is simple mathematical model of general purpose computer. It models the computing power of a
computer. It is capable of performing any calculation which can be performed by any computing
machine.
Model:
It can be thought as a finite automaton connected to R/W head. It has a tape, divided into a number
of cells. Each cell can store only one symbol.

The head of Turing machine is capable of reading as well as writing on tape. It can move left or right
or remain static. In one move, the machine examines present symbol under R/W head on tape and
present state of automaton to determine:
o A new symbol to be written on tape in cell under R/W head.
o A motion of R/W head along the tape; either head moves one cell left (L), or one cell right (R).
o The next state of automaton.
o Whether to halt or not.
Definition:
 A Turing machine M is a 7 tuple (Q, ∑, Γ, δ, q0, b, F), where
 Q is finite nonempty set of states
 Γ is finite nonempty set of tape symbols
 b ∈ Γ is the blank
 ∑ is nonempty set of input symbols (subset of Γ) and b∉∑.
 δ is transition function mapping states of finite automaton and tape symbols to states, tape
symbol and movement of head. Q x Γ → Q x Γ x {L, R}
 q0 ∈ Q is the initial state
 F ⊆ Q is set of final states

29. Construct context free grammar G which accepts N(A), where A=( {q0, q1}, {a, b}, {Z0, Z}, δ, q0, Z0, Φ )
and δ is given by
δ (q0, b, Z0) = {(q0, ZZ0)}
δ (q0, Λ, Z0) = {(q0, Λ)}

Page | 31
δ (q0, b, Z) = {(q0, ZZ)}
δ (q0, a, Z) = {(q1, Z)}
δ (q1, b, Z) = {(q1, Λ)}
δ (q1, a, Z0) = {(q0, Z0)}
Solution:
Rule: Let G = (VN, {a, b}, P, S) where VN consists VN = {S} ∪ { [q, Z, q’] | q, q’ ∈ Q, Z ∈ Γ }
So, VN is given by
S, [q0, Z0, q0], [q0, Z0, q1], [q0, Z, q0], [q0, Z, q1], [q1, Z0, q0], [q1, Z0, q1], [q1, Z, q0], [q1, Z, q1],
Rule: S productions are given by S → [q0, Z0, q] for every q in Q.
So, the S productions are
P1: S → [q0, Z0, q0]
P2: S → [q0, Z0, q1]
Rule: Each move not erasing a pushdown symbol given by (q1, Z1Z2…Zm) ∈ δ(q, a, Z) induces many
productions of form
[q, Z, q’] → a[q1, Z1, q2] [q2, Z2, q3] … [qm, Zm, q’] where each states q’, q2 … qm can be any state in Q.
So,
P3: [q0, Z0, q0] → b[q0, Z, q0][q0, Z0, q0]
P4: [q0, Z0, q0] → b[q0, Z, q1][q1, Z0, q0]
P5: [q0, Z0, q1] → b[q0, Z, q0][q0, Z0, q1]
P6: [q0, Z0, q1] → b[q0, Z, q1][q1, Z0, q1]
Rule: Each move erasing a pushdown symbol given by
(q’, Λ) ∈ δ(q, a, Z) induces the production [q, Z, q’] → a.
δ (q0, Λ, Z0) = {(q0, Λ)} gives
P7: [q0, Z0, q0] → Λ
Similarly, other moves induces following productions
δ (q0, b, Z) = {(q0, ZZ)} gives
P8: [q0, Z, q0] → b[q0, Z, q0][q0, Z, q0]
P9: [q0, Z, q0] → b[q0, Z, q1][q1, Z, q0]
P10: [q0, Z, q1] → b[q0, Z, q0][q0, Z, q1]
P11: [q0, Z, q1] → b[q0, Z, q1][q1, Z, q1]
δ (q0, a, Z) = {(q1, Z)} yields
P12: [q0, Z, q0] → a[q1, Z, q0]
P13: [q0, Z, q1] → a[q1, Z, q1]
δ (q1, b, Z) = {(q1, Λ)} gives
P14: [q1, Z, q1] → b
δ (q1, a, Z0) = {(q0, Z0)} gives
P15: [q1, Z0, q0] → a[q0, Z0, q0]
P16: [q1, Z0, q1] → a[q0, Z0, q1]
P1 to P16 gives the productions in P.

Page | 32
30. Design a PDA for the language L = { wcwR | w ∈ (a, b)* }.
Solution:
Note: wR means Reverse order of w i.e. if w=abb then wR = bba.
Therefore w = {Λ, a, b, aa, bb, ab, ba, ………}
As we know that a PDA = (Q, Σ, τ, δ, q0, P0, F) then,
PDA = ( {q0, q1, qf},{a,b,c}, {a,b,P0}, δ, {q0,P0}, {qf} )
δ can be defined as:
1. δ (q0, a, P0) = (q0, aP0)
2. δ (q0, b, P0) = (q0, bP0)
3. δ (q0, a, a) = (q0, aa)
4. δ (q0, b, b) = (q0, bb)
5. δ (q0, a, b) = (q0, ab)
6. δ (q0, b, a) = (q0, ba)
7. δ (q0, c, a) = (q1, a)
8. δ (q0, c, b) = (q1, b)
9. δ (q1, a, a) = (q1, Λ)
10. δ (q1, b, b) = (q1, Λ)
11. δ (q1, Λ, P0) = (qf, P0)
Let w = abb then wR = bba.
Hence, L= abb c bba
δ (q0, abb c bba,P0) ├ (q0, bb c bba, aP0)
├ (q0, b c bba, baP0)
├ (q0, c bba, bbaP0)
├ (q1, bba, bbaP0)
├ (q1, ba, baP0)
├ (q1, a, aP0)
├ (q1, Λ, P0)
├ (qf, Λ, P0)

PDA reaches the final state and all input symbols are processed.
Therefore this is the required PDA for L = { wcwR | w ∈ (a, b)* }.

31. Design a PDA for the language L = { anb2n | n≥1 }.


Solution:
w = {abb, aabbbb, aaabbbbbb, ………}
δ can be defined as:
1. δ (q0, a, P0) = (q0, aP0)
2. δ (q0, a, aP0) = (q0, aaP0)
3. δ (q0, b, a) = (q1, a)
Page | 33
4. δ (q1, b, a) = (q2, Λ)
5. δ (q2, b, a) = (q1, a)
6. δ (q2, Λ, P0) = (q2, Λ)
Proof:
Let w= aabbbb then
δ (q0,aabbbb,P0) ├ (q0, abbbb, aP0)
├ (q0, bbbb, aaP0)
├ (q1, bbb, aaP0)
├ (q2, bb, aP0)
├ (q1, b, aP0)
├ (q2, Λ, P0)
├ (q2, Λ , Λ)

As PDA reached the empty stack and all input symbols are processed, therefore this is the required
PDA for language L = { anb2n | n > 0 }.

32. What are Multitape Turing Machine, Universal Turing Machine, Post Correspondence Problem.
Solution:
Universal Turing Machine (UTM)
General purpose Turing machine is called universal Turing machine. It is powerful enough to
simulate the behavior of any computer, including any Turing machine itself. Universal Turing
machine can simulate the behavior of an arbitrary Turing machine over any ∑. A UTM takes as
input the description of a Turing machine along with initial tape contents and simulates the input
on that Turing machine.
Multi Tape Turing Machine
Multi tape Turing machine has multiple tapes. It can have separate tape head for each of its multiple
tapes. On each move, the machine reads symbols under all the tape heads simultaneously, changes
state according to combination of symbols read and writes new symbols to each of scanned cells
independently. The head movements on the each tape are independent; either one cell right or left
and some time stationary also.
Post Correspondence Problem (PCP)
Definition:
 A correspondence system P is a finite set of ordered pairs of nonempty strings over some
alphabet.
 Let ∑ be an alphabet, the P is finite subset of ∑+ x ∑+.
 A match or solution of P is any string w ∈ ∑ such that pairs (u1, v1), (u2, v2), ……, (un, vn) ∈ P and
w = u1 u2 …. un = v1 v2 …. vn for some n>0.
 The selected pairs (u1, v1), (u2, v2), ……, (un, vn) are not necessarily distinct.
 Let strings u1, u2, …., um are in set U and strings v1, v2,…., vm are in set V, then
Page | 34
 U = { u1, u2, …., um } and V = { v1, v2,…., vm } for some m>0.
 PCP is to determine whether there is any match or not for a given correspondence problem.
Example:
Consider a corresponding system P = { (b, ca), (a, ab), (ca, a), (abc, c) }. Find match if any.
Solution: we represent P as following:
u1 = b, u2 = a, u3 = abc, v1 = ca, v2 = ab, v3 = c.
We have a solution:
w = u3u2 = v2v1 = abca
Application of PCP:
 PCP has very important role in formal languages and also in general life.
 It is used to prove certain problems are undecidable.

33. Explain Church’s Hypothesis.


Solution:
Church’s Thesis
Turing machine capture behaviors of finite automaton and pushdown automaton as well as general
purpose computer system. We consider a Turing machine to be equivalent to an algorithm. Nothing
will be considered as algorithm if it cannot be implemented as a Turing machine. The principle that
Turing machines are formal version of algorithms and no computational procedure will be
considered an algorithm unless it can be implemented as a Turing machine is known as Church’s
Thesis.
As per Church’s Thesis, behavior of a general purpose computer can be simulated by some Turing
machine. It is a thesis, not a theorem since it has no mathematical proof. A Turing machine can
perform all computations (recognization and computation), which are carried out by a general
purpose digital computer. Some arguments for accepting the Church’s Thesis are:
1. No one has been able to suggest a counter example to disprove till now.
2. Some TMs can also perform any thing that can be performed by a digital computer.
3. There are several alternative model of computation like random access machine (RAM), Post
machine (PM) etc., but no one is more powerful than Turing machine.

34. Explain Halting problem of Turing machine.


Solution:
Type 0 languages are recognized by Turing machine. A language is decidable if there is a Turing
machine, which always stops processing in halting state. There are some type 0 languages, which
are not decidable and Turing machine may stop it’s processing in non halting state. This problem is
known as halting problem (HP). A class of problem is solvable (decidable) if there exists some
definite algorithm which always terminates. Otherwise the class of problem is said to be unsolvable
(undecidable).
Statement:
 Given a description of an algorithm and a description of its initial arguments (inputs),
determine whether the algorithm, when executed with these arguments, ever halts.
Page | 35
 The alternative is that the given algorithm runs forever without halting.
There is no general method or algorithm which can solve the halting problem. An algorithm may
contain loops which may be infinite or finite in length depending on input and behavior of
algorithm. The amount of work done in an algorithm depends on input size. Algorithm may consist
of various loops, nested or in sequence. To find the solution of HP one thing can be done. Let
program run with given input and wait for result. If program stops and would conclude that
problem is solved. If program does not stop in a reasonable amount of time, we cannot conclude.
Question arises, “how long we can wait?”. Waiting time may be long enough to exhaust whole life.
We must have answer either YES/ NO. Hence some algorithm required to decide the exact answer.

35. Design a Turing machine M to recognize the language {1n2n3n | n≥1}.


Solution:
Our task is to read and exhaust all symbols 1, 2, and 3 from string. Exhaust one 1, then one 2, then
one 3. Return back to 1, and repeat.
Step 1: Let q1 is initial state. R/W head scans leftmost 1, replace 1 by b, and moves to the right. M
enter q2.
Step 2: On scanning leftmost 2, R/W head replace 2 by b, and moves to the right. M enter q3.
Step 3: On scanning leftmost 3, R/W head replaces 3 by b, and moves to the right. M enter q4.
Step 4: After scanning rightmost 3, R/W head moves to the left until it finds the leftmost 1. As a
result, the leftmost 1, 2 and 3 are replaced by b.
Step 5: Step 1 – 4 are repeated until all 1’s, 2’s and 3’s are replaced by blanks.
Consider string 112233. Change of IDs can be given as:

The transition table can be given as:

Page | 36
36. Define primitive recursive function.
Solution:
A function is primitive recursive if
1. It is an initial function or
2. It is obtained from recursion or composition of initial functions.
Example:
Show that concatenation of two strings over {a, b} is primitive recursive.
Proof:
 We define concatenation as:
f(ε, w2) = w2
f(a1a2…an, w2) = a1f(a2a3…an, w2), where w1, w2 ∈ ∑*.
 We define function f using initial functions as:
f(ε, w1) ≡ CONCATE ε (w1) = w1 and
f(a1a2…an, w2) ≡ CONCATE a1( f(a2a3…an, w2) )
 consider: f(ab, cd)
f(ab, cd) = CONCATE a ( f(b, cd) )
= a f(b, cd)
= a CONCATE b ( f(ε, cd) )
= ab f(ε, cd)
= abcd (since f(ε, w) = w)
 Hence, concatenation is primitive recursive function.

37. Prove that addition and mn of two integers are primitive recursive.
Solution:
Addition function:
We can define function f using initial functions as:
f(m, 0) = m ≡ P11(m) and
f(m, n+1) = f(m, n) + 1 ≡ S( f(m, n) )
Consider f(5, 2)
f(5, 2) = S( f(5, 1) )

Page | 37
= f(5, 1) + 1
= S( f(5, 0) ) + 1
= f(5, 0) + 1 + 1
=5+1+1
=7
Hence, f is a primitive recursive function.
Function (m, n) = mn:
We define f(m, n) by using initial functions as following:
f(m, 0) = m0 = 1 ≡ S( Z(m) )
f(0, n) = 0 ≡ Z(n) and
f(m, n+1) = m * f(m, n) ≡ P11 (m * f(m, n) )
Hence, f(m, n) is primitive recursive function.

38. Compute A(1, 1), A(2, 1), A(1, 2), A(2, 2) by using recursive function.
Solution:
Ackermann’s Function
It is defined by
A(0, y) = y+1
A(x+1, 0) = A(x, 1)
A(x+1, y+1) = A( x, A(x+1, y) )
A(1, 1)
A(1, 1) can be written as A(0+1, 0+1) ….{to do comparison
A(0+1, 0+1) ⇒⇒⇒ A(x+1, y+1) …here x=0 and y=0
We have A(x+1, y+1) = A( x, A(x+1, y) )
So, A(0+1, 0+1) = A(0, A(0+1, 0) )
A(0, A(0+1, 0) ) ⇒⇒⇒ A(0, A(x+1, 0) ) …here x=0
We have A(x+1, 0) = A(x, 1)
So, A(0, A(0+1, 0) ) = A(0, A(0, 1) )
We have A(0, y) = y+1
So, A(0, 1) = 1+1 = 2
Hence, A(0, A(0, 1) ) = A(0, 2)
Finally =3 ….{ A(0,2) = 2+1 = 3
Summary:
A(1, 1) = A(0+1, 0+1)
= A(0, A(1, 0) )
= A(0, A(0, 1) )
= A(0, 2)
= 3
A(1, 2) = A(0+1, 1+1)
= A(0, A(0+1, 1) )

Page | 38
= A(0, A(1, 1) )
= A(0, 3) … {A(1, 1) = 3 previously calculated
= 4
A(2, 1) = A(1+1, 0+1)
= A(1, A(1+1, 0) )
= A(1, A(1, 1) )
= A(1, 3)
= A(0+1, 2+1)
= A(0, A(0+1, 2) ) = A(0, A(1, 2) )
= A(0, 4) … {A(1, 2) = 4 previously calculated
= 5
A(2, 2) = A(1+1, 1+1)
= A(1, A(1+1, 1) )
= A(1, A(2, 1) )
= A(1, 5) … {A(2, 1) = 5 previously calculated
= A(0+1, 4+1)
= A(0, A(0+1, 4) ) = A(0, A(1, 4) )
= A(0, A(0+1, 3+1) ) = 1 + A(0+1, 3+1)
= 1 + A(0, A(0+1, 3) )
= 1 + A(0, A(1, 3) )
= 1 + 1 + A(1, 3) = 1 + 1 + A(0+1, 2+1)
= 1 + 1 + A(0, A(0+1, 2) ) = 1 + 1 + 1 + A(1, 2)
= 1 + 1 + 1 + 4 … {A(1, 2) = 4
= 7

39. Explain space and time complexity theory.


Solution:
Computational complexity of Turing machine is based on two factors: One is amount of time needed
(time complexity) and second is amount of space or storage required in processing of a task (space
complexity). Time complexity is denoted by T and space complexity by S.
Time complexity:
Consider kTM (k-tape Turing machine)

Page | 39
M has k two-way infinite tapes, one of these tapes contains the input and all tapes including input
tape can be written. Time complexity is defined as:
If for every input of length n (n≥0), M makes at most T(n) moves before halting then M is said to be
a T(n) time bounded Turing machine (or of time complexity T(n)).
The language recognized or function computed by M is said to be of time complexity T(n).
Space complexity:
Consider an off-line Turing machine M of k tapes.

M has a read only tape and k-1 one way infinite tapes. Space complexity is defined as:
If for every input stream of length n (n≥0), Turing machine M scans at most S(n) cells on any tape
then M is said to be a S(n) space bound Turing machine or space complexity of S(n) and the
language recognized or function computed by M is said to be of space complexity S(n).
Generally, S(n) is of linear growth. But in some case there may be the different growth rate. If head
writes on the tape then the length of written is included in calculation of space complexity.

40. Write short note on recursive enumerable language.


Solution:
When a Turing machine executes an input there are 4 possible outcomes of execution.
1. Halts and accepts the input
2. Halts and rejects the input

Page | 40
3. Never halts (fall into loop) or
4. Crash
Language recognized by Turing machine is known as recursively enumerable (r. e.) and set of
recursive languages is subset of recursively enumerable set.
Set of recursively enumerable languages are those languages that can be listed (enumerated) by
Turing machine. If a Turing machine can generate all strings in a language, another Turing machine
can accept all the strings. But, we don’t know about rejection of strings that are not in given
language. Strings that are not in given language may be rejected or may cause the Turing machine
to go into an infinite loop. A language is recursive if there exist a Turing machine that accepts every
string of the language and rejects every string that is not in the language.

Page | 41

You might also like