Sie sind auf Seite 1von 27

www.vidyarthiplus.

com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

UNIT – I AUTOMATA
PART – A
1 Define proof by contra positive and induction principle
It is the other form of If then statement. The contra positive of the statement „‟If H then C „‟ is „‟If not C
then not H‟‟
Induction Principle
If S(i) is true for n = i ,then it is to be proved that for all n > i , S(n) implies S(n+1) then S(n) is true for all n
≥ i..

2 Define Pumping lemma for regular language.


Let L be a regular language. Then there exists a constant n such that for every string w in L ,|w|>n, z = uvw
such that (i)|uv|<n, |v|>0 then uviw  L for all i.
3 State Arden’s theorem.
Let P and Q be two regular expressions over  . If P does not contain null string  over  then R=Q+RP,
it has the solution R=QP* .
4 Prove that L = { 0n12n / n  1} is not regular.
Let z = uvw = 0n12n, let v = 1m,u = 0n,w = 12n-m
uviw = 0n1mi12n-m,let I = 0 , then uw =0n12n-mL. Therefore L is not regular.
5 Write RE which denotes the language L over the set  = {a,b} such that all the strings do not contain
the substring ab.
RE = (b*a*).
6 Write regular expressions for the following.
(i)Binary numbers that are multiple of 2. (0/1)*.
(ii)Strings of a‟s and b‟s with no consecutive a‟s .b* (abb*)(a / ) (iii) Strings of a‟s and b‟s containing
consecutive a‟s. (a/b)*aa(a/b)*.

7 How a Non deterministic finite state automaton (NFA) differs from a Deterministic finite state
automaton (DFA).
Solution:
DFA NFA
On each input there is one and only one stae On each input the automaton can be in several states
to which the automaton move from its at once
current state
Next state is completed by determining The state is only partially determined by the current
current state and current symbol state and current input symbol
The transition function returns only one The transition function returns zero, one or more
state.(i.e)  : Q X   Q states.(i.e)  : Q X   2 Q

8 Define the languages described by DFA and NFA.


L(DFA) = { w / δ‟(q0,w) is in F}.It is the set of strings w that take the start state q 0 to one of the accepting
states.
L(NFA)= { w / δ‟(q0,w)∩F≠}.It is the set of strings w such that δ‟(q0,w)contains at least one accepting
state.
9 Define extended transition function for a DFA.
The extended transition function δ‟: Q∑* Q is defined as follows.
(i) δ’(q, ε ) = q (ε - Empty)

(ii)Suppose w is a string of form xa(w= xa), w∑* and qQ , then δ’(q, w)= δ( δ’(q, x),a)

10 Define extended transition function for a NFA.

The extended transition function δ‟: Q∑* 2Q is defined as follows.


(i) δ’(q, ε ) = {q}

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:1 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

(ii) Suppose w is of the form xa where a is the final symbol of w and x is the rest of w.
δ’(q,x)= {p1, p2, p3...pk}

k
U δ(pi,a) = {r1, r2, r3,.....rm}
i=1

Therefore δ‟(q,w) ={r1, r2, r3,.....rm}

11 Define extended transition function for a -NFA.

The extended transition function δ‟: Q∑* 2Q is defined as follows.(i) δ‟(q, λ) = {q} (ii)For any
w∑ , a∑ and qQ , δ‟(q, wa ) =   δ( q,a).
*

p δ‟(q, y)
12 Define - closure of a state.

The set of all states reachable from a given state q using λ transitions only. We use λ-closure to denote
the set of all vertices p such that there is a path from q to p labeled λ.
13 Find the - closure of states 1, 2 and 4 in the following transition diagram.
1- 2  3  6
 b
4 5
a b 7

- closure(1) = {1,2,4,3,6},- closure(2) = {2,3,6},- closure(4) = {4}.


14 Define regular expression and give an example.
The language accepted by finite automata are easily described by simple expression called regular
* *
expression Example : ( 0  10 ) 11 ( 0  01 )

15 Construct a finite state machine that accepts exactly those input strings of 0’s and 1’s that ends with
“11”
0 1

1 1
S0 S1
S2

0
1
0
, 0
S3 1

16 Give a regular expression for the set of all strings having odd number of 1’s
RE= 1(0+11)*

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:2 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

17 Construct a DFA for the language L = { anb , n ≥ 0}.


a

a b
s0 s2
s1

a, b
a, b
b

s3

18 Construct a DFA which accepts all strings over ∑ = {0,1} ending with 00.
1 0

0 0 S2
S0 S1

1
1
0 1

S3

19 Give the regular expression for the set of all strings ending in 00.

Regular expression = (0+1)*00


20 When two states are equivalent and distinguishable?

We say that two states p and q are equivalent iff for each input string x , δ(p,x) is an accepting state iff
δ(q,x) is an accepting state. p is distinguishable from q if there exists an x such that δ(p,x) is in F and v is
not in F or vice versa.
21 What are the applications of regular expression?

Regular expression in UNIX, Lexical analysis, Pattern searching


22 Is it true that the language accepted by any NFA is different from the regular language?.Justify your
answer.
No. Any language accepted by DFA,NFA,NFA- is called a regular language. For any finite automaton we
can construct an equivalent regular expression and the language represented by regular expressions is a
regular language.

23 Prove that Q+RP= QP*


R= Q+RP = Q+(Q+RP)P=Q+QP+QP2+QP3+------ = Q(1+P+P2+P3+--------) =Q(+ P+P2+P3+--------)=QP*

Part –B
1. A) State and prove the pumping lemma for regular languages

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:3 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

Statement: Let L be regular language and M = (Q ,, ,q0 ,F) be a finite automata with n-states
.Language L is accepted by M .Let  L and   n, then  can be written as xyz ,where
i) y  1 (ii)xy  n (iii) xyi z  L for all i  0 here yi denotes that y is repeated or pumped i
times.
ii) Proof:
Suppose L is a regular language. and M be a DFA with n states ,such that DFA accepts
the given regular language L.(i.e) is L =L(M), language of M is same as the given
regular language .Consider a string  L and   n, string  can be written as a1a2 …am
with m n..
Let us assume that states of M are given by q0, q1, q2,….qn-1 with q0 as the starting state and
qn-1 as final state .After feeding the first i characters of the word  = a1a2 …am machine will be in
a state ri . *( q0 , a1a2 …ai) = ri .As the word  is fed through the machine M ,the machine will go
through the various states as;qo r1 r2 …… rm-1 qn-1, since the length of .  and   n it is not
possible for the machine to move through distinct states..Let us assume that r i and rj are same.
There is a loop from ri to rj.The string  can be divided into three parts.
i)x = portion before loop = a1a2 …am
ii)y = portion of the loop = ai+1a i +2 …aj
iii) z = portion of the loop = aj+1a j +2 …am .Since y is a portion relating to loop, it can repeat any
number of times.

B) Using pumping lemma for regular sets. Prove that the language L = {a nbn
/n1} is not regular
L = {anbn /n1} is not regular.
let us assume that L is regular and L is accepted by a FA with n states;
(i) Let us choose the string  = anbn ,  = 2n  n. Let us write  as xyz, with
(ii)y 0 and xy  n. since xy  n,y must be of the form ar for some r 0 since xy  n, x
must be of the form as .Now , an bn can be written as
as ar an-s-rbn .let us check whether xyi z for some i = 2 belongs to L.
xy z = as (ar )2an-s-rbn = an +r bn , r 0,number of a‟s in an +r bn is greater than number of
2

b‟s. Therefore, xy2 z  L.Hence by contradiction, therefore the given language is not regular.

2. Obtain the regular expression that denotes the language accepted by

, Using the recursive


relation.

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


Step:1 Find Rij(o) where k=0 R11(0)=ε , R12(0)=0, R13(0)=1, R21(0)=0, R22(0)= ε, R23(0)= 1, R31(0)= φ
R32(0)=0 +1, R33(0)= ε.
Sept:2 Find Rij(1) where k=1 ,here n=3 recursive relation becomes
R11(1)= R11(0)+ R11(0)( R11(0))* R11(0)
R11(1)=ε , R12(1)=0, R13(1)=1, R21(1)=0, o R22(1)= ε+00, R23(1)= 1+01, R31(1)= φ
R32(0)=0 +1, R33(0)= ε.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:4 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

We have to prove the result is true for n=k+1


12 +22+32+……+ k2+(k+1)2= = (k(k+1)(2k+1))/6 + (k+1)2
(2)
Step:3 Find Rij where k=2 ,here n=3 recursive relation becomes
R11(2)= R11(1)+ R12(1)( R22(1))* R21(1)
R11(2)=(00)* , R12(2)=0(00)*, R13(2)=0*1, R21(2)=0(00)*, R22(2)= (00)*, R23(2)= 0*1,
R31(2)= (0+1)(00)*0, R32(2)=(0+1)(00)*, R33(2)= ε+(0+1)0*1
In our example the set of final state F={q2,q3}
L(M)=R12(3)+R13(3) where n=3
Hence the regular expression is RE=0*1((0+1)0*1)*(0+1)(00)*+0(00)*

3. A) Prove that 12 +22+32+……+ n2= ∑n2 = (n(n+1)(2n+1))/6.

Proof: Prove by induction.


Base step: for n=1 L.H.S =1 and R.H.S=1(2)(3)/6=1
Inductive step : Assume the result is true for n=k
12 +22+32+……+ k2= ∑k2 = (k(k+1)(2k+1))/6.
………….. = ((k+1)(k+2)(2k+3))/6 hence it is proved for all values of n
2n+1 n+2
B) Prove that for every integer n≥0 the number 4 +3 is multiple of 13
1 2
Proof by induction .Base step: n=0 L.H.S = 4 +3 =4+9=13 = R.H.S
Induction : n=k the result is true: 42k+1+3k+2 =13 k = 13 x for some integer x
2(k+1)+1
Assume that the result is true for n= k+1. 4 + 3 k+1+2 = 13 (k+1) = 13 x for some integer
x……… = 13(3x+4 )=13x hence it is proved.
2k+1

4. Design FA which accepts even number of 0’s and even no of 1’s.


M = (Σ,Q,δ,q0, F) Σ={0,1},
Q = { q0, q1, q2 ,q3}, F= { q0}
Transition table is given below
 0 1
*q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2

5. Show that if L be a set accepted by an NFA then there exists a DFA that accepts L

For each state [q1, q2 …qi ] in Q1 the transitions for each input symbol  can be obtained as
(a) 1 ([q1, q2 …qi ] , a ) = ( q1, a) ( q2, a)  ………( qi, a)
= [q1, q2 …qk ]Add the state [q1, q2 …qk ] to DFA if it is not already added in Q1
(b)Then find the transitions for input symbol from  for state [q1, q2 …qk ].If we get some state
[q1, q2 …qk ].which is not in Q1 of DFA then add this state Q1.
©If there is no new state generating then stop the process after finding all the transitions.
(d)The state [q1, q2 …qn ] Q1of DFA if any one state qi is a final state of NFA then [q1, q2 … qn ]
becomes a final state . The final state is F 1 of DFA.

6. Convert an NFA to a DFA given NFA M = (Σ,Q,δ,q0, F) Σ={0,1},


Q = { q0, q1, q2 ,q3},F= { q0},

 0 1
q0 { q0} { q0, q1}
q1 { q2} { q2}
q2 { q 3} { q3}

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:5 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

q3 Ø ø

Soltion: L(M)= ( 0  1 ) * 1 ( 0  1 ) ( 0  1 )
M1 = (Σ1,Q1,δ1,q1, F1) ,Σ={0,1},Q1 = 2Q , q1 = q0, F1= { q Q1/ q∩F≠ ø }, δ1(q1,a)=Ụ δ(p,a)
Transition table is given below
 0 1
q0 { q0} { q0, q1}
{ q0,q1} { q0,q2} { q0, q1,q2}
{q0,q2} { q0,q 3} { q0, q1,q3}
{q0,q1,q2} { q0,q2,q3} { q0, q1, q2,q3}
{ q0,q 3} { q0} { q0, q1}
{q0,q1,q3} { q0,q2} { q0, q1,q2}
{q0,q2,q3} { q0,q 3} { q0, q1,q3}
{q0,q1,q2,q3} { q0,q2,q3} { q0, q1, q2,q3}

7. Convert the given NFA to DFA

 0 1
q0 q0
{ q0, q1}
q1 q1
q2
q2 q3 q3

*q3
 q2

New DFA M1 = (Σ1,Q1,δ1,q1, F1) ,Σ={0,1},Q1 = 2Q , q1 = q0, F1= { q Q1/ q∩F≠ ø }, δ1(q1,a)=Ụ
δ(p,a)
Transition table is given below

 0 1
q0 { q0, q1} q0

q1 q2 q1

q2 q3 q3

q3  q2

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

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

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

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

8. Compute -closure (ii) Convert the automaton to a DFA


 ε a b c

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:6 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

P { ф} {p} {q} {r}


q {p} {q} {r} { ф}
r {q} {r} { ф} {p}
Solution: -closure (p)={p,q,r},-closure (q)={q}, },-closure ( r )={r}
Construction of DFA
Transition table is given below Md=(qd,,d,q0,Fd)

d a b c
r   
{q,r} {p,q,r} {r} {p,q,r}
{p,q,r} {p,q,r} {q,r} {p,q,r
   

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:7 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

UNIT - II
PART-A
1 Let G = s , c , a , b , P , s  where P consists of S  aca , C  aca / b ,Find L(G).
Sol:
Sacaaacaaaaacaaa( caca)…..aicai an can an ban(cb)
L(G) = a n b a n /n  0 
2 Find L(G),where G = s , 0 ,1, s  0 s 1, s   , s 
Sol: S  0s1 00s11( s0s1)… 0n s1n0n 1n .
Hence L(G) = s  0 n 1 n / n  0 
3 What is Chomsky Normal form?
Chomsky Normal form:i)NT T. set of NT, ii) NTT
Where, NT- Non terminal, T- terminal
4 Find L(G),where P consists of S  asb , s  ab .
* n n
Sol: S  asb  aasbb  aaasbbb …  a b
Hence L = s  a n b n / n  1 .
5 Let G =(S,C,a,b ,P,S) where P consist of SaCa, CaCa / b .Find L(G)
Solution:SaCaaaCaa ….anba n .Thus L(G) =  an ban / n ≥1.
6 Convert the following grammar G in GNF form S  ABb / a , A  aaA / B , B  bAb
Solution:
A  aXA , X  a , Y  b .The rule for Bwill be B  baY ,
Now convert the rule for S to GNF.
S  aXABY / bAYBY /a,

T S  aXABY / bAYBY / a , A  aXA /bAY, X  a , Y  b .


7 Define a derivation tree for a CFG.
A derivation tree for a CFG G = (V,T,P,S)is a tree satisfying the following:
a)Every vertex has a label which is a symbol of VT .b)The label of the root is S c)the internal
vertices must be in V (d) If n has a label ‟ a‟ and vertices n1,n2,n3,n4,…..nk are sons of the vertex n ,in order
from the left with label X1,X2,X3,X4,…..Xk respectively. Then A X1,X2,X3,X4,…..Xk must be a production
in P (e) If vertex n has label λ then n is a leaf and is only son of its father.
8 What are the closure properties of context- free Language?
CFL is closed under union, concatenation and Klee closure .CFL is also closed under substitution,
homomorphism.CFL is not closed under intersection, complementation. The closure properties of
CFL‟s are used to prove that certain languages are not context free.
9 Let G = s , c , a , b , P , s  ,P = S  asb / a , A  SbA / ss / ba .Find a derivation tree whose yield
aabbaa.
Soln: SaASaSbASaabASaabbaSaabbaa .
10 Show that id+id*id can be generated by two distinct leftmost derivation in the grammar
EE+E/ E*E/ (E)/id
Soln : i)EE+E
id+E id +E*E  id +id*E id +id*id

ii)EE*EE+E*Eid+E*Eid+id*Eid+id*id.thereforeid+id*id can be generated by two distinct


LMD .Thus it is ambiguous.
11 Let G = (N,T,P,S), P = S  A 1 B / a , A  0 A /  , B  0 B / 1 B /  give a leftmost and rightmost
derivation for the string 00101.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:8 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

Soln: SA1B0A1B00A1B001B0010B00101B00101(LMD)
SA1BA10BA101B A1010A10100A10100101 (RMD)
Therefore the given grammar is ambiguous.
12 Write CFG for L(G) = a m b n c p / m  n  p , p  1 .
Soln:P=  S  asc / bpc , s  ac / bc , p  bc .
13 Is context free language is closed under complementation? Justify.
Proof: Let L1 & L2 are the two CFLs. Assume that complement of a CFL is a CFL itself. Hence L „1 &L„2
both are CFLs, thus L „1  L„2 is a CFL,(by rule)but L „1  L„2 = L1 ∩ L2 which may or may not be
CFL. The L1 & L2 are arbitrary CFLs, there may exist L „1 &L„2 which are not CFL. Hence the
complement of certain language may or may not be CF. Therefore, we can say that CFL is not closed
under complement operation.
14 Find L(G) for CFG S  asb / aAb , A  bAa , A  ba .
* n n n n n n
Soln: S  asb  aasbb  a sb  a aAbb  a abAabb 
* n m
a b a b
m n

Hence L = a n b m a m b n / m , n  1 .
15 Find the derivation tree for the grammar, G = s , A , B , a , b , P , s  ,where
P = S  bA / bB , A  ab , B  aBb / a 
16 Define Parse diagram.
A data structure to represent the source program in a compiler is called Parse diagram(tree).A Parse
diagram can have nodes and edges.
17 What are the two major normal forms for context –free grammar?
a)Chomsky Normal form b) Greibach Normal form
18 Consider the CFG G={V,T,S,P} Remove useless symbol
Answer: S  11 A | 11
A 0
19 Eliminate the  production from the CFG given below
A 0 B 1 | 1 B 1
B 0 B | 1 B | 

Answer: A 0 B 1 | 1 B 1 | 01 |11
B 0 B | 1 B | 0| 1
20 If the CFG is as below
S 0A | 1B |C
A 0S| 00
B1 | A
C 01 then remove the unit productions.
Answer: S 0A | 1B | 01
A 0S| 00
B1 | 0S| 00
C 01
PART - B
1 (i) Show that the grammar S  a / abSb / aAb , A  bs / aAAb is ambiguous.
a) S  abSb b) S  aAb
abaAbb abSb
ababSbb ababSbb
abababb abababb

(ii) Consider the following productions

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:9 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

S  aB / bA
for the string aaabbabbba, find leftmost derivation.
A  aS / bAA / a
B  bS / aBB / b

S  aB
aaBB
aaaBBB
aaabBB
aaabbSB
aaabbaBB
aaabbabB
aaabbabbS
aaabbabbbA
aaabbabbba
2 (i)Find a grammar in Chomsky normal form equivalent to

S  AB / aB , A  aab /  , B  bbA
form.
Step1:Eliminate -productions, Null able symbols = {A}
After elimination -productions, we get a set of productions P 1
 S  AB / B / aB 
 
P1   A  aaB 
 
 B  bbA / bb 
Step:2Elimination of the unit production S  B .the equivalent set of productions is given as P 2
 S  AB / bbA / bb / aB 
 
P 2   A  aab 
 
 B  bbA / bb 
Step:3 Every symbol is , in a production of the form S   with ||≥2 should be a variable. This can be
done by adding the two two productions C 1  a , C 2  b The equivalent set is represented as P3
 S  AB / C 2 C 2 A / C 2 C 2 / C 1 B 
 
P3   A  C 1C 1 B 
 
 B  C 2 C 2 A / C 2 C 2 , C 1  a , C 2  b 

Original production Equivalent production in CNF


S  AB S  AB
S  C 2C 2 A S  C 2C 3 , C 3  C 2 A,

S  C 2C 2 / C1B S  C 2C 2 / C1B

A  C 1C 1 B A  C 1C 4 , C 4  C 1 B

B  C 2C 2 A, C1  a B  C 2C 3 , C1  a

B  C 2C 2 ,C 2  b B  C 2C 2 ,C 2  b

(ii) Obtain the Greibach Normal form A1A2 A3, A2A3 A1/ b , A3A1A2/ a
Step:1 The given grammar there is no null production or unit production
Step:2 Every production of the form A i  A j  with I >j must be modified to make i≤j.The resulting
roduction A1A2 A3, A2A3 A1/ b , A3A2A3A2/ b Step:3 Since the right side of the production
A3A2A3A2 begins with a lower numbered variable substitute A2 in A3 the resulting production are
A1A2 A3, A2A3 A1/ b , A3 A3 A1 A3A2/ b A3A2/a
Step :4 the new symbol B is introduced in A3 to derive the first symbol as a terminal strings as per lemma
2 GNF the resulting production (After simplification) A1a A1 A3, bA3 A2A1 A3 , b A3, b A3 A2B3 A1
A3 Similarly we can derive A2,A3 , B3 in GN F form.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:10 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

3 Construct a grammar in GNF which is equivalent to the grammar


S  AA / a , A  SS / b
We can proceed for renaming of variables , variables S and A are renamed as A1 and A2respectiviely .The
set of
Productions after renaming becomes
Step:1 A1  A 2 A 2 , A1  a , A 2  A1 A1 , A 2  b
Step:2 Every production of the form A i  A j  with I >j must be modified to make i≤j (A2 production
should be modified) A2→ A2 A2 A1,A2→aA1 The resulting set of productions is A2→ A2 A2 /a, A2→ A2
A2A1/a A1/b
Step:3 The ) A2 production A2→ A2 A2A1/a A1/b contains left recursion. Left recursion from A2
production can be removed through introduction of B2-producion
A2→ aA1B2/b B2 , B2→ A2A1B2/A2A1
The resulting set of production is
A1  A 2 A 2 / a , A2→ aA1B2/b B2 , B2→ A2A1B2/A2A1

Step:4 A2 production are in GNF form A1 and B2 can be converted to GNF with the help of A2
productions.
The final set of production is in GNF form production rule P is given by
A 2  aA 1 B 2 / bB 2 / aA 1 / b
A1  aA 1 B 2 A 2 / bB 2 A 2 / aA 1 A 2 / bA 2 / a

B 2  aA 1 B 2 A 1 B 2 / bB 2 A 1 B 2 / aA 1 A 2 B 2 / bA 1 B 2 / aA 1 B 2 A 1 / aA 1 A 1 / bA 1

Where set of variables V={A1,A2,B2}


Set of terminals T={a,b} start symbol = A1 set of production P
4 Find a grammar in Chomsky normal form equivalent to
S aAbB, A aA | a, B bB | b
Solution:
S  RT
R  PA
T  QB
A  PA
A a
B QB
Bb
Pa
Qb
5 Begin with the grammar
S 0A0 | 1B1 | BB
A C
B S|A
CS| and simplify using safe order
i) Eliminate  productions.
ii) ) Eliminate unit productions
iii) Eliminate useless symbols
put the grammar in Chomsky‟s normal form
Solution:
S  XY
X0
Y  SX
S  PQ
P1
Q  SP
S  SS

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:11 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

S  YY
S  SS
6 Obtain the Chomsky normal form equivalent to the grammar
SbA | aB, AbAA | aS | a, BaBB | bS | b.
Solution:
S  R1 B
S R2 B
A  R1S
A  R2R3
B b
B  R2S
B  R1R4
R1  a
R2  b
R3  AA
R4  BB
7 Show the context free language are closed under union operation but not under intersection
Step 1:CFL are closed under union
Proof: Let L1 and L2 be two CFL and G1 and G2 be CFG such that G1 € L1 and G2 € L2
G1 = {V1, ∑, P1, S1}
P1={ S1  A1S1A1 | B1SB1| 
A1 --> a
B1  b
}
G2 = {V2, ∑, P2, S2}
P2={ S2  aA2A2 | bB2B2
A2 --> b
B2  a
}
L = L1 U L2 then P = P1 U P2
P={ S  S1| S2
S1  A1S1A1 | B1SB1| 
A1 --> a
B1  b
S2  aA2A2 | bB2B2
A2 --> b
B2  a
}
UNIT III
Part - A
1 Define pushdown Automaton
 A pushdown Automaton is a  - NFA with stack data structure where it can push strings
into and pop strings out of stack.
 It consists of 7-tuples P = ( Q,,,,q0, z0 , F),Where Q is a finite set of states, is a finite
set of input symbols,is a finite set of nonempty stack alphabets,  is a transition
function,q0 is an initial state, Z 0 is the initial start symbol of the stack , F is the set of
accepting states.
  is defined as :Q()  Q*
2 What are the different ways of language acceptances by a PDA and define them
There are two ways of language acceptances,
1)Acceptance by final state .L(M)= w | (q0,w,Z0)  *(q, ,) for some q in F and  in  *

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:12 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

2)Acceptance by empty stack. N(M)= w | (q0,w,Z0)  *(q, ,) for some q in Q.
3 Define the instantaneous descriptions(ID) of pushdown Automaton
Let P= ( Q,,,,q0, z0 , F) be a PDA then the instantaneous description is given by
(q0, x, Z0)= (q1, x)
where q0 is current state, x is current input symbol, Z0 is the current stack symbol, q1 indicates next
state and x represents top of the stack

4 Define Acceptance by Final State


For PDA P= (Q,,,,q0, z0 , F)
L(P)= w | (q0,w,Z0) P * (q, ,) for some state q in F and any stack string .That is, starting in
the initial ID with w waiting on the input, P consumes w from the input and enters an accepting
state.
5 Define Acceptance by Empty stack
For PDA P= ( Q,,,,q0, Z0 , F)
N(P) = w | (q0,w,Z0)  * (q, ,) for some q in Q. N(P) is the set of inputs w that P can consume
and at the same time empty its stack.
6 Define equivalence of acceptance by final state and empty stack
The language accepted by empty stack PDA will also be accepted by final state PDA.
The language accepted by final state PDA will also be accepted by empty stack PDA.
7 Define rules for the conversion of Grammars to PDA
Let G= (V, T, Q, S) be a CFG. Then PDA P that accepts L(G) by empty statck as follows
P=({q}, T, VT, , q, S) where the transition function  is defined by
1. For each variable A, (q,  , A)= {(q, ) | A -->  is a production of P}.
2. For each terminal a, (q, a, a)= {(q, )}.
8 Convert the given expression to PDA
I --> a | b | Ia | Ib | I0 | I1
(q,  , I) = {(q, a), (q,b), (q, Ia), (q, Ib), (q,I0), (q,I1)}
(q, a, a) = {(q, )}, (q, b, b) = {(q, )}, (q, 0, 0) = {(q, )}, (q, 1, 1) = {(q, )}
9 Define Deterministic PDA
A PDA P= ( Q,,,,q0, Z0 , F) is a deterministic if and only if the following two conditions are
met:
1. (q, a, X) has at most one member foe any q in Q, a in  or a = , and X in .
2. (q, a, X) is non empty, for some a in , then (q, , X) must be empty.
10 What is the additional feature a PDA has when compared with NFA?
1. Stack which is used to store the necessary tape symbols and use the state to remember the
conditions.
2. Two ways of language acceptances, one reaching its final state and another by emptying
its stack.
11 State the pumping lemma for CFL’s?
Let L be any CFL. Then there exist a constant n ,depending on L, Such that if z is in L and │z│≥
n, then z = uvwxy such that
i) │vx│≥1,
ii) │vwx│≤ n
iii) For all I ≥ 0 u vi w xi y is in L.
12 Equivalence of PDA and CFG
A language is generated by a CFG,
1. if and only if it is accepted by a pda by empty stack
2. if and only if it is accepted by a pda by final state.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:13 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

13 Construct a pda for the context free grammar


S --> aSA | a
A --> bB
B --> b
(q0, , Z0) = (q1,SZ0)
(q1, ,S)= {(q1, aSA), (q1, a)}
(q1, ,A)={(q1, bB)}
(q1, ,B)={(q1,b)}
(q1, a,a)= {(q1, )}
(q1, ,B)= {(q1,  )}
14 Define Non Deterministic PDA
Nondeterministic PDAs are able to handle situations where more than one choice of action is
available. In principle it is enough to create in every such case new automaton instances that will
handle the extra choices. The problem with this approach is that in practice most of these instances
fail. This can severely affect the automaton's performance as the execution of multiple instances is
a costly operation.
15 Is it true that Non deterministic PDA is more powerful than that of Deterministic PDA.
Justify.
Yes. It is true that non deterministic PDA is more powerful than that of deterministic PDA. This is
because the class of languages accepted by NPDA is larger than that of class of languages accepted
by DPDA.
16 Define the rule for construction of CFG from given PDA
 If q0 is the start state and qn is the final state of PDA then [q0Zqn] becomes the start state of
CFG. Z represents stack symbol.
 For (qi, a, Z0) = (qi+1, Z1Z2)
(qi, Z0 qi+k) ---> a (qi+1 Z1 qm) (qm Z2 qi+k)
 For (qi, a, Z0) = (qi+1, ) can be converted as (qi Z0 qi+1) --> a
17 What are the main applications of pumping lemma in CFL’s?
The main applications of pumping lemma in CFL is to prove a particular language is not a CFL .
Let L be any CFL. Then there exist a constant n ,depending on L, Such that if z is in L and │z│≥
n, then z = uvwxy such that
i) │vx│≥1,
ii) │vwx│≤ n
iii) For all I ≥ 0 u vi w xi y is in L.
18 Design a PDA for accepting a language {L= anbn | n >=1}
The ID:
(q0, a, Z0) = (q0, aZ0), (q0, a, a) = (q0, aa), (q0, b, a) = (q1, ), (q1, b, a) = (q1, ), (q1,  , Z0) = (q2,
)
(q0, aaabbb, Z0) = (q0, aabbb, aZ0)
= (q0, abbb, aaZ0)
= (q0, bbb, aaaZ0)
= (q1, bb, aaZ0)
= (q1, b, aZ0)
= (q1,  , Z0)
= (q2, )
19 Design a PDA for accepting a language {L= anb2n | n >=1}
(q0, a, Z0) = (q0, aaZ0), (q0, a, a) = (q0, aaa), (q0, b, a) = (q1, ), (q1, b, a) = (q1, ), (q1,  , Z0) =
(q2, )

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:14 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

(q0, aaabbbbbb, Z0) = (q0, aabbbbbb, aaZ0)


= (q0, abbbbbb, aaaaZ0)
= (q0, bbbbbb, aaaaaaZ0)
= (q1, bbbbb, aaaaaZ0)
= (q1, bbbb, aaaaZ0)
= (q1, bbb, aaaZ0)
= (q1, bb,a aZ0)
= (q1, b, aZ0)
= (q1,  , Z0)
= (q2, )
20 Show that the language { 0n 1n 2n } is not a context free language
Let the input string z = 0n 1n 2n can be compared with z = uvwxy.
If we assume string uvw containing a's then by uvi w we can pump 0's only but then the input string
becomes {0m 1n 2n | m != n} which is not in L. Again if we assume 0's and 1's are belonging to x
from z = uvwxy then by pumping lemma z = uviwxiy becomes {0m 1m 2n | m!=n } is not in L.
This indicates if we pump v and x any nymber of times the resulting string is not the member of L.
Hence the given language is not context free language.
PART - B
1 (i). Construct a PDA accepting by empty stack the languages {a mbmcn/m,n1}
Solution
Sequence of initial „a‟ should be pushed on to the stack b should be matched with a‟s on the stack.
c‟s should be skipped
The PDA accepting through an empty stack is given by M=({q0,q1,q2},{a,b,c},{a,z0},, q0, z0, )
Transition function  is defined by
( q0, a,z0 ) =( q0, az0 ) , ( q0, a,a ) = ( q0, aa ), ( q0, b,a ) ( q1, ), ( q1, b,a ) = ( q1,  ), ( q1, c, z0 ) = ( q2,  )
( q2, c, z0 ) = ( q2,  ), ( q2, , z0 ) = ( q2,  )
(ii) Find PDA for the given grammar S  0 S 1 / 00 / 11
Solution:
The equivalent PDA, M is given by :
M=({q},{0,1},{0,1,S},, q, S, ),where  is given by
( q, ,S) = {( q, 0S1 ) , ( q, 00 ) , ( q0, 11 )}
( q, 0,0 ) = ( q,  ), ( q, 1,1 ) = {( q,  )}
2 Give the CFG generating the language accepted by the following PDA M==({q0,q1,},{0,1},{z0,x},,
q0, z0, ),with transactions ( q0, 1,z0 ) = {( q0, xz0 )} , ( q0, 1,x ) = {( q0, xx )}, ( q0, 0, x ) = {( q1,
x)}, ( q0, , z0 ) = {( q0, )},( q1, 1, x ) = {( q1, )},( q1, 0 ,z0 ) = {( q0, z0)}
Solution:
Step 1: Add production for the start symbol S  q 0 z 0 q 0  , S  q 0 z 0 q 1 

Step 2: Add production for ( q0, 1,z0 ) = {( q0, xz0 )}


q 0 z 0 q 0   1 q 0 q 0  q 0 z 0 q 0  , q 0 z 0 q 0   1 q 0 x q 1  q 1 z 0 q 0 
q 0 z 0 q 1   1 q 0 x q 0  q 0 z 0 q 1  , q 0 z 0 q 1   1 q 0 x q 1  q 1 z 0 q 1 
Step 3: Add production for, ( q0, 1,x ) = {( q0, xx )}
q 0 xq 0   1 q 0 x q 0  q 0 x q 0  , q 0 x q 0   1 q 0 x q 1  q 1 x q 0 
q 0 x q 1   1 q 0 x q 0  q 0 x q 1  , q 0 x q 1   1 q 0 x q 1  q 1 x q 1 

Setp 4: Add production for( q0, 0, x ) = {( q1, x)}


q 0 xq 0   0 q 1 x q 0  , q 0 xq 0   0 q 1 x q 1 
Setp 5: Add production for ( q0, , z0 ) = {( q0, )} q 0 z 0 q 1   

Step 6: Add production for ( q1, 1, x ) = {( q1, )} q 1 xq 1   1


Step 6: Add production for ( q1, 0 ,z0 ) = {( q0, z0)}= q 1 z 0 q 0   0 q 0 z 0 q 0  , q 1 z 0 q 0   0 q 0 z 0 q 1 

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:15 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

3 Show that if a language L is accepted by a PDA then there exists a CFG generating L.
Proof: For simplicity we will consider a normalized PDA with following properties:
1. There is a single final state qf.
2.It empties the stack before accepting
3.Each transition either pushes a symbol on to the stack or performs a pop operation , but not both
A transition. ( q1, x ,b) ( qj, c) [pop b and push c] can be replaced by couple of transitions
1. ( q1, x ,b) (qtemp, , )
2. (qtemp, , ,)(qj,,c) a new state qtemp has been introduced
Similarly , a transition that neither pushes nor pops anything can be replaced with two transitions:
1.Transition pushing a dummy stack symbol 2. Transition popping a dummy stack symbol
Let us consider the normalized PDA N=( Q,,,,q0, z0 , F) where F={qf}
A word will be accepted by N if it starts in q0 and ends up in qf with an empty stack
The language Lp,q where p,qQ, is defined as consisting of those strings that start at state p with an empty
stack and ends up in q with an empty stack.
4 If L= N(PN) for some PDA PN =( Q,,,N,q0, Z0 ) then there is a PDA PF such that L= L(PF) [From
empty stack to final state]
PF

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:16 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

5 Let L be L(PF) for some PDA PF = (Q,,,F,q0, Z0 , F). Then there is a PDA PN such that L = N(PN)
[From final state to empty stack]

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:17 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

7 Construct a PDA for set of palindrome over the alphabet{ a, b} L(M) = {WcWR}
( q0, a,Z0 ) = ( q0, aZ0 )
( q0, b,Z0 ) = ( q0, bZ0 )
( q0, a,a ) = ( q0, aa)
( q0, b,a ) = ( q0, ba )
( q0, a,b ) = ( q0, ab )
( q0, b,b ) = ( q0, bb )
( q0, c,Z0 ) = ( q1, Z0 )
( q0, c,a ) = ( q1,a )
( q0, c,b) = ( q1, b )
( q1, a,a ) = ( q1,  )
( q1, b,b ) = ( q1,  )
( q1,  , Z0 ) = ( q2, Z0 )
8 If L is a context free language then prove that there exists a PDA M such that L = N(M)

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:18 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

Suppose w is in L(G). Then w has leftmost derivation


S = r1  r2 ….rn (LM)
(q, w, S) ---P (q, yi, αi)
Basis: for i=1, r1 = S. Thus x1 = 1 and y1 = w.since (q, w,S)  (q, w, S) by 0 moves the basis is proved
Induction:
(q, w, S) -* (q, yi, αi) then we have to prove (q, w, S)-*(q, yi+1, αi+1)
UNIT IV
Part – A
1 What is a Turing machine?
Turing machine is a simple mathematical model of a computer.TM has unlimited and unrestricted
memory and is a much more accurate model of a general purpose computer. The TM is a FA with
a R/W head .It has an infinite tape divided into cells, each cell holding one symbol
2 What are the required fields of an ID or configuration of a TM.
It requires i)the state of the TM. ii)the contents of the tape. iii)the position of the tape head on the
tape.
3 Define a Turing machine.
The Turing machine is denoted by M = (Q,,  ,,q0, B , F) Q -Finite set of states,- Finite set of
input symbols ,  -finite set of allowable tape symbols,,q0 -the initial state, B-Blank symbol, F- a set
of final state,  is the transition function defined as :(Q ) ( Q L,R).
4 Define Instantaneous description of turing machine
ID of turing machine is represented as
X1 X2......Xi-1 q Xi Xi+1.....Xn
i) where q is the state of turing machine.
ii) The tape head is scanning the ith symbol from left
iii) X1 X2....Xn is the portion of the tape between the leftmost and the rightmost non blank
5 Represent the ID for the transition function (q, Xi) = (p, Y, L)
X1 X2......Xi-1 q Xi Xi+1.....Xn ├ M X1 X2......Xi-2 p Xi-1Y Xi+1.....Xn
├ reflects the moves of TM. ├ *M will be used to indicate zero, one or more moves.
6 Define the language of Turing machine
Let M= (Q,,  ,,q0, B , F) be a turing machine. Then L(M) is the set of strings w in * such that q0
w ├ * α p β for some state p in F and any tape strings α and β.
7 When a recursively enumerable language is said to be recursive? Is it true that the language
accepted by a non –deterministic TM is different from recursively enumerable language?
A language L is recursively enumerable if there is a TM that accepts L, and recursive if there is
a TM that recognizes L, then it is called L- Turing acceptable(or) Turing Decidable languages. No,
the language accepted by a non –deterministic TM is same as the recursively enumerable language.
8 What is a multiple track Turing machine?
A TM in which the input tape is divided into multiple tracks where each track is having different
inputs is called multiple track TM.
9 When is a function f is said to be Turing Computable?
A TM defines a fn: y = f(x) for string x, y * ,if q0   qf y where q0 initial state, qf is the final
*

state. A function f is Turing computable if there exists a TM that performs a specific function.
10 List out different types of TMs.
Multi tape Turing machine, off-line Turing Machine , Multi track Turing machine & Universal
TM .
11 Define Multitape Turing machine.
A Multitape Turing machine has a finite control with some finite number of tapes. Each tape is
divided into cells and each cell can hold any symbol of the finite tape alphabet. The set of tape
symbol includes a blank, and has a subset called the input symbols, of which the blank is not a
member.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:19 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

12 What does Multitape turing machine contain?


1. The input, a finite sequence of input symbols, is placed on the first tape.
2. All other cells of all the tapes hold the blank.
3. The final control is in initial state.
4. The head of the first tape is at the left end of input.
5. All other tape heads are at some arbitrary cell.
13 Define Subroutines in Turing machine
A Turing machine subroutine is a set of states that performs some useful process. This set of states
includes a start state and another state that temporarily has no moves, and that serves at the return
state to pass control to whatever other set of states called the subroutine
14 Define Non Deterministic Turing machine
Non deterministic turing machine consist of a transition function  such that for each state q and
tape symbol X, (q, X) is a set of triples.
{(q1, Y1, D1), (q2, Y2, D2)..... (qk, Yk, Dk)} where k ia any integer. The NTM can choose, at
each step, any of the triples to be the next move.
15 Define Halting Problem
The halting problem is the problem of determining, from a description of an arbitrary computer
program and an input, whether the program will finish running or continue to run forever.
16 Is Halting problem decidable or undecidable problem
The machine starting at given configuration will halt after finite number of steps or will never reach
to a halt state. For a given configuration and input tape we can't determine whether the machine
will ever halt. This problem is called halting problem. The halting problem is unsolvable. Hence it
is undecidable problem.
17 Define Chomsky Hierarchy
The four classes of languages regular, context-free, context-sensitive, and recursively enumerable
is often referred to as the Chomsky hierarchy. The Chomsky Hierarchy allows the possibility for
the understanding and use of a computer science model which enables a programmer to accomplish
meaningful linguistic goals systematically.
18 Is it possible that a turing machine could be considered as a computer of functions from
integers to integers? If yes justify
Yes, TMs simulate computer of functions from integers to integers. That means it is a device for
computing integer valued functions. In this scheme integers were presented 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.
19 Define Rules of Context sensitive languages
 The CSG may have more than one symbol on the left hand side of their production rules.
 The number symbols on left side must not exceed the number of symbols on right side
 The rule of the form A -->  is not allowed unless A is a start symbol
20 Compare FM, PDA and TM
 Finite Machine is of two types - DFA and NFA. Both DFA and NFA accept regular
language only
 PDA has a memory and hence it accepts large class of language.
 TM can be programmed. Hence TM accepts very large class of language. TM is therfore
most powerful computational model
PART - B
1 Construct a TM for the language L={a nbncn/n ≥0}.
Transition table is given below
Δ a b c x
Q1 xR Q2 xR Q1

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:20 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

Q2 aR Q2 xR Q3 xR Q2
Q3 bR Q3 xR Q4 xR Q3
Q4 cL Q5 xL Q7
Q5 aL Q6 bL Q5 xR Q5
Q6 aL Q6 bR Q1
*Q7
2 Explain the programming techniques of turing machine
(i)Storage in the Finite Control
(i) the finite control can be used to hold the finite amount of information
(ii)It is considerate as a pair of elements where one exercising control and second component
stores a symbol in the finite control
(ii)Multiple tracks: we can imagine the tape of the TM is divided into multiple tracks for any finite k the
symbols on the tape are considered k-tuples one component for each track.
(iii)Checking off symbols:
It is useful trick for visualizing how a TM recognizes languages defined by represented strings
(iv)Sifting over :TM can make space on its tape by shifting all non black symbol a finite number
cells to its right
(v)Subroutines: The general idea is to write part of a TM program to serve as a subroutine ti will have a
designated initial and return state which temporarily has no move and which will be used to effect a return
to the calling routine
3 Design a Turing machine which recognizes palindrome over alphabet {0,1}
δ 0 1 B
Q0 ( Q1,B,R) ( Q4,B,R) ( Q7,B,R)
Q1 ( Q1,0,R) ( Q11,R) ( Q2,B,L)
Q2 ( Q3,B,L) ( Q7,B,R)
Q3 ( Q3,0,R) ( Q3,1,L) ( Q0,B,R)
Q4 ( Q4,0,R) ( Q0,1,R) ( Q5,B,L)
Q5 ( Q6,B,L) ( Q7,B,R)
Q6 ( Q60,L) ( Q6,1,L) ( Q0,B,R)
Q7 - - -
4 Construct a Turing machine compute multiplication with subroutine “copy”
Subroutine copy transition table is given below
δ 0 1 2 B
Q1 ( Q2,2,R) ( Q4,1,L)
Q2 ( Q2,0,R) ( Q2,1,R) ( Q2,2,L)
Q3 ( Q3,0,L) ( Q3,1,L) ( Q1,2,R)
Q4 ( Q5,1,R) ( Q4,0,L)
Additional moves for TM performing multiplication
δ 0 1 2 B
Q5 ( Q7,0,L)
Q7 ( Q8,1,L)
Q8 ( Q9,0,L) ( Q10,B,R)
Q9 ( Q9,0,L) ( Q0,B,R)
Q10 ( Q11,B,R)
Q11 ( Q11,B,R) ( Q12,B,R)
5 Explain Multitape TM and Non deterministic TM
i) A Multi-tape Turing machine is like an ordinary Turing machine with several tapes. Each tape
has its own head for reading and writing. Initially the input appears on tape 1, and the others start
out blank
A k-tape Turing machine can be described as a 6-tuple where:

 is a finite set of states

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:21 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

 is a finite set of the tape alphabet


 is the initial state
 is the blank symbol
 is the set of final or accepting states
 is a partial function called the transition
function, where k is the number of tapes, L is left shift, R is right shift and S is no shift.
ii) A non-deterministic Turing machine (NTM), may have a set of rules that prescribes more
than one action for a given situation. For example, a non-deterministic Turing machine may have
both "If you are in state 2 and you see an 'A', change it to a 'B' and move left" and "If you are in
state 2 and you see an 'A', change it to a 'C' and move right" in its rule set.

6 Write short notes on (i) Context sensitive language


(ii) Chomsky hierarchy
Solution:
Chomsky Hierarchy", a hierarchy of language classes defined by gradually increasing the
restrictions on the form of the productions. Chomsky numbered the four families of grammars (and
languages) that make up the hierarchy and are defined as below.
Let G = ( N , , P, S ) be a grammar
1. G is called a Type-0 or unrestricted, or semi-there or phrase-structure grammar if all

productions are of the form , where and .


2. G is a Type-1 or context-sensitive grammar if each

production in P satisfies such that and . Type-


1 grammar , by special dispensation , is allowed to have the production ,
provided S does not appear on the right-hand side of any production.
3. G is a Type-2 or context-free grammar if each production in P
satisfies i.e. is a single nonterminal.
4. G is a Type-3 or right-linear or regular grammar if each production has one of the following
three forms: , A b, A where A, C N ( with A = C allowed ) and .

7 Construct a TM M for language L={an, bn, n ≥ 1}

a b A B Ϫ
q0 (q1,A,R) - - (q3,B,R) -
q1 (q1,a,R) (q2,B,L) - (q1,B,R) -
q2 (q2,a,L) - (q0,A,R) (q2,B,L) -
q3 - - - (q3,B,R) Halt
halt - - - - -
8 Construct a TM to compute a function f(w)= WR where W ε {a,b}+

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:22 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

UNIT V
Part - A
1 What do you mean by Universal TM.
Universal TM 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 TM.
2 Features of Universal TM
 Universal TM can simulate any other turing machine. Universal TM is a single machine
used to compute any computable sequence.
 Universal TM has an ability to manipulate an unbounded amount of data in finite amount of
time
3 When a problem is said to be decidable and give an example of undecidable problem?
A problem whose language is recursive is said to be decidable. Otherwise the problem is
undecidable . i.e there is no algorithm that takes as input an instance of the problem and determines
whether the answer to that instance is yes or no. Eg. Halting problem
4 When a language is said to be recursively enumerable?
A language is recursively enumerable if there exists a Turing machine that accepts every string
belonging to that language. And if the string does not belong to that language then it can cause the
turing machine to enter ia an infinite loop

W TM Accept

Input string Reject

5 When a language is said to be recursive?


A language is said to be recursive if there exists a turing machine that accepts every string of the
language and every string is rejected if it is not belonging to that language.

W TM Accept
Input String Loop for ever

6 State two languages, which are not recursively enumerable


 Diagonalization language is not recursively enumerable.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:23 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

 The partially decidable languages or undecidable languages are not recursively enumerable.
7 Define problem solvable in polynomial time.
A TM M is said to be of time complexity T(n) if whenever M is given an input w of length n , M
halts after making at most T(n) moves, regardless of whether or not M accepts.
8 Define the classes P and NP.
P consists of all those languages or problems accepted by some TM that runs in some polynomial
amount of time, as a function of its input length.
NP is the class of languages or problems that are accepted by some nondeterministic TM‟s with a
polynomial bound on time taken along any sequence of nondeterministic choices.
9 Define NP complete problem.
A language is NP-complete if the following statements are true.(i)L is in NP (ii)For every language
L‟ in NP there is a polynomial time reduction of L‟ to L.
10 What are tractable problems?.
The problems which are solvable by polynomial time algorithms are called tractable problems. For
eg. The complexity of the Kruskal‟s algorithm is o(e+m) where e , the no. of edges and m the
Number of nodes.
11 What are the properties of recursive and recursively enumerable languages?.
(i)The complement of a recursive language is recursive,(ii)The union of two recursive languages
are recursive. (iii)The union of two recursively enumerable languages are recursively
enumerable.(iv)If a language L and are both recursively enumerable then L is recursive.
12 When do you say a problem is NP - hard?
A problem is said to be NP - hard if an algorithm for solving it can be translated into a problem
which is NP problem. Thus NP - hard is a algorithm for a problem which is atleast as hard as any
NP problem. Example - Sum of subset problem, travelling salesman problem.
13 State two languages, which are not recursively enumerable.
 Diagonalization language is not recursively enumerable
 The partially decidable language or undecidable languages are not recursively enumerable.
14 Define Primitive Recursive function
The set PR of primitive recursive function is defined as follows.
1. All initial functions are elements of PR
2. For every k >= 0 and m>= 0, if f : Nk --> N and g1, g2, .... gk : Nm --> N are elements of
PR, then the function f(g1, g2,...gk) obtained from f and g1, g2,...gkby composition is an element of PR.
3. For every n >= 0, every function : g : N n --> N in PR, and every function h:
Nn+1 --> N obtained from g and h by primitive recursion is in PR.
15 Define intractable problems
A problem that cannot be solved by a polynomial-time algorithm. The lower bound is exponential.
Examples of intractable problems (ones that have been proven to have no polynomial-time
algorithm)
 Towers of Hanoi: we can prove that any algorithm that solves this problem must have a
worst-case running time that is at least 2n − 1.
 List all permutations (all possible orderings) of n numbers.
16 Define Bounded quantification
Let P be an (n+1) - place predicate. The bounded existential quantification of P is the (n+1) - place
predicate Ep defined by
Ep(X, k) = (there exists y with 0 ≤ y ≤ k such that P(X, y) is true)
The bounded universal quantification of P is the (n+1) - place predicate Ap defined by
Ap(X, k) = (for every y satisfying 0 ≤ y ≤ k, P(X, y) is true).
17 Define Polynomial Time reduction

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:24 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

 A polynomial-time reduction is a method of solving one problem by means of a


hypothetical subroutine for solving a different problem (that is, a reduction), that
uses polynomial time excluding the time within the subroutine.
 The three most common types of polynomial-time reduction, are polynomial-time many-
one reductions, truth-table reductions, and Turing reductions.
18 Give two properties of recursively enumerable sets which are undecidable
The language accepted by a TM is called Recursively Enumerable language(RE). Every non trivial
property of RE is undecidable. Such properties are
1. Whether the language accepted by TM is regular.
2. Whether the language accepted by TM is context free language.
19 Show that union of recursive language is recursive
L1 and L2 are recusive language. Then there exists a machine M1 that accepts L1 as well as machine
M2 that accepts L2. We can simulate a machine M that accepts the language L such that L = L1 U
L2. Then construct M which accepts if M1 accepts. If M1 does not accept then M2 simulates M.
That means if M2 accepts then M accepts, if M2 rejects M also rejects. Thus M accepts the language
L = L1 U L2 which is recursive.
20 Define posts correspondence problem.
An instance of posts correspondence problem consists of two lists A = w 1 ,w2, w3,…wk , B = x1
,x2, x3,…xk of strings over some alphabet .This instance of PCP has a solution if there is any
sequence of integers i1,i2,…im with m ≥1 such that .The sequence
i1,i2,…im is a solution to this instance of PCP.
21 Define modified posts correspondence problem.
Given lists A and B of k strings each from * , say A = w1 ,w2, w3,…wk, B = x1 ,x2, x3,…xk does
there exist a sequence of integers i1,i2,…ir such that w1, = .The sequence
i1,i2,…ir is a solution to this instance of MPCP.
Part - B
1 Show that for two recursive language L1 and L2 each of the following is recursive
(i) L1 L2 (ii) L1 L2(iii) L1‟
Proof: L1 L2 is recursive :
Let the Turing machine M1 decides L1 and M2decides L2.
If a word w L1then M1returns “Y” else it returns “N”. Similarly , if a word w L2 then M2 returns “Y”
else it returns “N” Let us construct a Turing machine M3 as given below
(i)output of machine M1 is written on the tape of M3(ii) output of machine M2 is written on the tape of
M3
(iii)The machine M3 returns “Y” os output, if at least on e of the outputs of M 1 , or of M2 is “Y” It
should be clear that M3 decides L1 L2 .As both L1 and L2 are turing decidable after a finite time both
M1 and M2 will halt with answer “Y” or “N”. The machine M3 is activated after M1 and M2 are halted.
The machine M3 halts with answer “Y” if w L1 or w L2 else M3 halts with output “N”.Thus L1 L2
is turing decidable or L1 L2 is recursive.
L1 L2 is recursive :
If a word w L1then M1returns “Y” else it returns “N”. Similarly , if a word w L2 then M2 returns “Y”
else it returns “N” Let us construct a Turing machine M4 as given below
(i)output of machine M1 is written on the tape of M4
(ii) output of machine M2 is written on the tape of M4
(iii)The machine M4 returns “Y” as output, if both outputs of M1 , or of M2 are “Y” otherwise ,M4
returns “N” It should be clear that M4 decides L1 L2 .As both L1 and L2 are turing decidable after a
finite time both M1 and M2 will halt with answer “Y” or “N”. The machine M 4 is activated after
M1 and M2 are halted. The machine M4 halts with answer “Y” if w L1 and w L2 else M4 halts with
answer “N”.Thus L1 L2 is turing decidable or L1L2 is recursive.
L1’ is Recursive:

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:25 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

Let the turing machine M1 decide L1.


Let us construct a turing machine M5 is given below
The output of machine M1 is written on the tape M5.The machine M5 returns as output, if the
output of M1 is “N”, otherwise, M5 returns “N”.
It should be clear that M5 decides L1‟.As L is turing decidable, after a finite M1 will halt with answer
“y” or
“N”. The machine M5 is activated after M1 halts. The machine M5 halts with answer “Y” if w L1 else
M5
halts with answer “N”.
2 Explain Universal Turing machine and Show that the universal language is recursively enumerable
but not recursive
Universal language: A Universal language Lu is the set of binary strings which can be modeled by a turing
machine

Proof: By simulation of the UTM by a Tm we showed that Lu is RE Supoose that Lu were recursive then by
definition its complement Lud would also be recursive .We prove by reduction from L d to Lud that to Lud is
not recursive (Explain)
3 Explain Primitive recursive function
The primitive recursive functions are among the number-theoretic functions, which are
functions from the natural numbers (nonnegative integers) {0, 1, 2, ...} to the natural
numbers. These functions take n arguments for some natural number n and are called n-ary.
The basic primitive recursive functions are given by these axioms:

1. Constant function: The 0-ary constant function 0 is primitive recursive.


2. Successor function: The 1-ary successor function S, which returns the successor of its
argument (see Peano postulates), is primitive recursive. That is, S(k) = k + 1.
3. Projection function: For every n≥1 and each i with 1≤i≤n, the n-ary projection
function Pin, which returns its i-th argument, is primitive recursive.

4 Write short note on (i) NP-Completeness (ii)NP-Hard problems


NP-Completeness: A language is NP-complete if the following statements are true.(i)L is in NP (ii)For
every language L‟ in NP there is a polynomial time reduction of L‟ to L.

NP-Hard problems: If it is obvious the P  NP. It is not known that whether there exists some integer L in
NP which is also accepted by deterministic TM. A language is said to be NP-hard if Li<PL for every
LiP  NP .The language is NP complete if P  NP and L is NP hard
5 Show that the complement of recursive language is recursive
Let the turing machine M1 decide L1.
Let us construct a turing machine M5 is given below
The output of machine M1 is written on the tape M5.The machine M5 returns as output, if the
output of M1 is “N”, otherwise, M5 returns “N”.
It should be clear that M5 decides L1‟.As L is turing decidable, after a finite M1 will halt with answer
“y” or
“N”. The machine M5 is activated after M1 halts. The machine M5 halts with answer “Y” if w L1 else
M5
halts with answer “N”.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:26 ISO 9001:2008
www.vidyarthiplus.com
Name & Code: Theory of Computation & CS6503 Dept: Computer Science Academic Year: 2015-16

6 If language L and its complement L' are both recursively enumerable then show that L and L' is
recursive
Proof:
Consider TM M made up of two TM M1 and M2. The machine M2 is complement of M1 . Both M1
and M2 are simulated in parallel machine M

Accept Accept
M1

M2 Accept Reject

7 Explain polynomial time reductions


A polynomial-time reduction is a method of solving one problem by means of a
hypothetical subroutine for solving a different problem, that uses polynomial time excluding the
time within the subroutine.
The three most common types of polynomial-time reduction,
 A polynomial-time many-one reduction from a problem A to a problem B (both of which
are usually required to be decision problems) is a polynomial-time algorithm for
transforming inputs to problem A into inputs to problem B, such that the transformed
problem has the same output as the original problem.
 A polynomial-time truth-table reduction from a problem A to a problem B (both decision
problems) is a polynomial time algorithm for transforming inputs to problem A into a fixed
number of inputs to problem B, such that the output for the original problem can be
expressed as a function of the outputs for B.
 A polynomial-time Turing reduction from a problem A to a problem B is an algorithm that
solves problem A using a polynomial number of calls to a subroutine for problem B, and
polynomial time outside of those subroutine calls.
8 Write short notes on tractable and intractable problems
Tractable Problem: a problem that is solvable by a polynomial-time algorithm.
examples of tractable problems:
 Searching an unordered list
 Searching an ordered list
 Sorting a list
 Multiplication of integers
 Finding a minimum spanning tree in a graph (even though there‟s a gap)
Intractable Problem: a problem that cannot be solved by a polynomial-time algorithm.
Here are examples of intractable problems
 Towers of Hanoi: we can prove that any algorithm that solves this problem must
have a worst-case running time that is at least 2n − 1.
 List all permutations (all possible orderings) of n numbers.

www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:27 ISO 9001:2008

Das könnte Ihnen auch gefallen