Beruflich Dokumente
Kultur Dokumente
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..
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
(ii)Suppose w is a string of form xa(w= xa), w∑* and qQ , then δ’(q, w)= δ( δ’(q, x),a)
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
The extended transition function δ‟: Q∑* 2Q is defined as follows.(i) δ‟(q, λ) = {q} (ii)For any
w∑ , a∑ and qQ , δ‟(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
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
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.
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?
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
/n1} is not regular
L = {anbn /n1} 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.
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
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.
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}
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
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
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:
Sacaaacaaaaacaaa( caca)…..aicai an can an ban(cb)
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( s0s1)… 0n s1n0n 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) NTT
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 SaCa, CaCa / b .Find L(G)
Solution:SaCaaaCaa ….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,
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: SA1B0A1B00A1B001B0010B00101B00101(LMD)
SA1BA10BA101B A1010A10100A10100101 (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
B1 | A
C 01 then remove the unit productions.
Answer: S 0A | 1B | 01
A 0S| 00
B1 | 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
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
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 A1A2 A3, A2A3 A1/ b , A3A1A2/ 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 A1A2 A3, A2A3 A1/ b , A3A2A3A2/ b Step:3 Since the right side of the production
A3A2A3A2 begins with a lower numbered variable substitute A2 in A3 the resulting production are
A1A2 A3, A2A3 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) A1a 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
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
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
SbA | aB, AbAA | aS | a, BaBB | 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
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
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
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,qQ, 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
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
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:
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
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
W TM Accept
Input String Loop for ever
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
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
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:
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
www.vidyarthiplus.com
St. Joseph’s College of Engineering /St.Joseph’s Institute of Technology Page No:27 ISO 9001:2008