0% found this document useful (0 votes)
146 views15 pages

2-CS701 Solved 25 MID Term Most Important

The document discusses 12 questions from a theory of computation exam. The questions cover topics like the halting problem, mapping reducibility, and properties of Turing machines and formal languages.

Uploaded by

4khurra
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)
146 views15 pages

2-CS701 Solved 25 MID Term Most Important

The document discusses 12 questions from a theory of computation exam. The questions cover topics like the halting problem, mapping reducibility, and properties of Turing machines and formal languages.

Uploaded by

4khurra
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/ 15

CS 701 Theory of Computation

25 Most important
Subjective Mid-term Q/A papers
Helpful for in,Sha,Allah 100% Success in
December 2016 mid-term exams of MSCS
A

s5

Special thanks to Respected Sir Habib Ullah Sb.


Question 01:
Show that ATM is not mapping reducible to ETM.

Answer:
Recall that ATM is undecidable, but it is recognizable so its complement ATM is not
recognizable. Note that ETM , the complement of ETM is recognizable, and so since we know ETM is
undecidable, It is also not recognizable.

Proof: We give a proof by contradiction.


Assume, it is false that ATM is not mapping reducible to ETM , so ATM m ETM .
Consider ATM since ATM is mapping reducible to ETM , we immediately get ATM is mapping reducible
A
to ETM .
Since, ETM is recognizable, ATM is also recognizable, but this is false, Hence a contradiction

Question 02:

Prove that every t(n)-time k-tape TM has on equivalent O(t 2 (n)) time single tape
TM.

Answer:
Given a k-tape TM M, we can make 1-tape TM N. N works as follows:
1. On input x, convert input x to #q0#x#, . #(the start configuration of M). This
configuration says that x is on the first tape. The rest of the tape is empty and the machine
is in q0.
2. In each pass over the tape, change the current configuration to the next one.
3. If an accepting configuration is reached, accept.
4. If a rejecting configuration is reached, Reject.

Now we have to estimate, how much time does N require?


On any input x of length n, we make the following claims:
1. M uses at most t(n) cells of its k-tape.
2. Each configuration has length at most k t(n) = O(t(n)).
3. Each pass of N requires at most O(t(n)) steps.
4. N makes at most t(n) passes on its tape.

This shows that N run in time O(t (n) t (n)) O(t 2 (n)) . Here, we use the fact t (n) n .
Thus, the machine convert x to the initial configuration. This takes time O(n). So total time is given
below:
O(n) O(t 2 (n)) O(t 2 (n))
Question 03:
Show that the Post Correspondence Problem (PCP) is decidable over unary alphabet.

Answer:
The Post Correspondence Problem (PCP) is decidable over unary alphabet. We can describe a
Turning Machine M that decides unary PCP.
Given unary PCP instance
1 1
a
1an
b1 ,............, bn
1 1
Let us design a TM M as given below:
M = On Input a1 , b1 ,............., an ,bn
A
1. Check if ai bi for some i. if so, accept.
2. Check if there exist i, j such that ai bi and ai bi . If so, accept otherwise reject.

Question 04:

Which of the following pair of numbers are relatively prime? Show the calculations that
lead to your conclusions. A) 1274 & 10505 B) 7289 & 8029

s5
Answer:

A) For checking the given number 1274 & 10505 that they are relatively prime or not we use
Euclidean algorithm to find Greatest Common Divisor (GCD).

10505 1274 8 313


1274 313 4 22
313 22 14 5
22 5 4 2
5 2 2 1
2 2 1 0

The greatest common divisor of 105050 and 1274 is 1. There for they are relatively prime.

B) For checking the given number 7289 & 8029 that they are relatively prime or not we use
Euclidean algorithm to find Greatest Common Divisor (GCD).
8029 7289 1 740
7289 740 9 629
740 629 1 111
629 111 5 74
111 74 1 37
74 37 2 0

A
The greatest common divisor of 7289 & 8029 is 37. There for they are not relatively prime.

Question 05:

G is a digraph and show that PATH is in Class P. OR Design a polynomial time


algorithm that takes as input a graph G and two vertices s and t and decides if there is a
path from s to t.

Answer:

We have to give a polynomial time algorithm for this problem. That is Start BFS or DFS
from s and if t appears then there is a path from s to t.

Algorithm:

I.On input <G,s,t> where G is a digraph,

s5
II.Mark s.
III.Repeat till no additional nodes are marked:
IV. Scan the edges of G, if an edge (a,b) is found going from a, marked node a to an unmarked
node b, mark b.
V. If t is marked, accept, otherwise reject.

Now we have to compute the size of input. We know that input size is at least m, where m is the
number of nodes in G. Thus we have to show that algorithm runs in the time polynomial in m.

The repeat loop can at most run for m time. Each time all the edges are scanned. Since the
number of edges is al most m2, thus step 2 takes at most m2 time. So the total time is at most m3.
Hence, we have shown that PATH is in p.

Question 06:
A Turning Machine with stay put instead of left is similar to an ordinary turning
machine, but the transition function has the form: Q T Q T R, S . At each point
the machine can move its head right or left it stay in the same position.

Show that this turning machine variant in not equivalent to the usual version. What class
of language does this machine recognize?
Answer:

Remembering what it has written on the tap cells to the left of the current head position is
unnecessary, because the TM is unable to return to these cells and read them.

Using NFA in the actual construction is convenient because it allows E moves which are useful
for simulating the Stay Put TM Transition.

The transition function ' for the NFA is constructed according .


First, we set '(qstart , p) (q0 ) , where q0 is the start state of the TM variant.


Next, we set '(qstart , i ) (qaccept ) for any i.
If ( p, a) (qaccept , b, w) where w=R or S, we set '(q pa , E ) {qaccept } .
A
If ( p, a) ( qreject , b, w) where w=R or S, we set '(q pa , E ) {qreject } .

Question 07:
Show that the collection of Turning-recognizable language is closed under operation of
(i) Union
(ii) Concatenation.

Answer:

I. For any two turning recognizable languages L1 and L2, let M1 and M2 be the TMs that
recognizes the union of L1 and L2:

On input w

s5
Rum M1 and M2 alternatively on w step by step. If either accept, accept. If both halt
and reject, then reject

If any of M1 and M2 accepts w, M1 will accepts w since the accepting TM will come
to its accepting state after a finite number of steps. Note that if both M1 and M2 reject
and either of them does so by looping, then TM will loop.

II. Form any two Turning-recognizable languages L1 and L2, let M1 and M2 are the TMs that
recognize them. We construct a NTM M that recognizes the concatenation of L1 and L2;
On Input w;
1. None deterministically cut w into two parts w = w1w2.
2. Run M1 on w1. If it halts and reject, reject. If it accepts, go to stage 3.
3. Run M2 on w2. If it accepts, accept. If it halts and reject, reject.

If there is a way to cut w into two substrings such that M1 accepts the first part and M2
accepts the second part, w belongs to the concatenation of L1 and L2 and M1 will accept
w after a finite number of steps.
Question 8
Explain
Theorem: ALLCFG is undecidable.
ANSWER:
Theorem: ALLCFG is undecidable.

If ALLCFG is decidable then there is a decider R such that L(R) = ALLCFG


Suppose R decides ALLCFG then consider S
1. On input <M, w>
2. Construct and LBA D as described earlier.
3. Convert D into an equivalent CFG G.
4. Run R on G. If R accepts reject. If R rejects accepts.
A
Note that S is a decider for A TM. A contradiction.

Question 09:
Show that MPCP is undecidable.

Answer:
Assume that MPCP is decidable. Let us say we have a decider R for MPCP. Consider the
following decider S

1. On input < M, w >


2. Construct , p as described in the seven parts.
3. Run R on P.
4. If R accepts, accept.
5. If R rejects, reject.
s5
Then S is a decider for ATM, which is a contradiction to the fact that ATM is undecidable.

Question 10:
If A m B and B is decidable, then A is decidable.

Answer:
Proof: Since B is decidable hence there is a decider M that decides B.
Now, consider the following decider N:

1. On input x
2. Compute y = f(x)
3. Run M on y
4. If M accepts, accept.
5. If M rejects, reject.
Since f is a computable function and M is a decider therefore N is a decider. Furthermore, x is
accepted by N if and only if y is accepted by M. However, y is accepted by M if and only if
yB .
Since f is a reduction therefore, x A if and only if y f ( x) B . Which implies that N accepts
x if and only if x A . This shows that N is a decider for A.

Question 11:
If A m B and B is Turning Recognizable, then A is Turning Recognizable.
Answer:
Let A m B and let f be the reducibility from A to B, Furthermore, since B is turning
recognizable, there is a TM M such that L(M)=B

Consider N:
A
On input x
1. Computer y=f(x)
2. Run M on y
3. if M accepts, accept.
Then it is easy to see that L(N) = A.

Question 12:
let T i, j, k | i, j, k N .show that T is countable.

Answer:
We need to demonstrate a one-to-one f : T N . Let f (i, j, k ) 2i3 j 5k . Function f is one-to-one
because a b, f (a) f (b) . Therefore, T is countable.

Question 13:

s5
Let A be a regular expression. Show that A is decidable.

Answer:
1. Proof is actually one line.
2. If we have a decider M that accepts A.
3. We can switch the accept and reject states to make another decider M.
4. M accepts. A

Lets recall that a language A is Turing recognizable if there is a TM M such that L(M) = A.

Question 14:
The given number 234 and 399 that they are relatively prime or not?
Answer:
For checking the given number 234 and 399 that they are relatively prime or not we use
Euclidean algorithm to find Greatest Common Divisor (GCD).
399 234 1 165
234 165 1 69
165 69 2 27
69 27 2 15
27 15 1 12
15 12 1 3
12 3 4 0

Question 15:
Show that some true statement in TH(N, +, X) are not provable
A
The greatest common divisor of 234 and 399 is 3. There for they are not relatively prime

Answer:
Consider the following algorithm:
1. On input
2. Enumerate all possible proofs 1 ,....,
3. Check if i is a proof of . If it is accept.
4. Check if i is a proof of . if it is reject.

If all true statements are provable then since each statement is either true or false hence or
is provable. Thus the above algorithm will be a decider for TH(N,+,) . This is a contradiction as
we have already proved that TH(N,+,) is not decidable.

Question 16: s5
MINTM is not Turing-Recognizable.

Answer:

Two facts about MINTM.


1 MINTM is infinite.
2 MINTM contains TMs whose length is arbitrarily large.
If MINTM is Turing Recognizable then there is a TM E that enumerates MINTM. We will use E
and the recursion theorem to construct another TM C.

On input w
2 Obtain own description <C>.
3 Run E until a machine D appears with a longer description than that of C.
4 Simulate D on input w.
All we have to note that eventually D will appear as MINTM contains TM with arbitrarily large
descriptions. L(C) = L(D).
However, C has a smaller description than D. So D cannot be in MINTM.

Question 17: A
A={<R>|R is a regular expression describing a language containing at least one string w
that has 111 as substring(i.e.w=x111y for some x,y } show A is decidable.

Answer:
The following TM X decide A.

X = On input R where R is regular Expression:


1. Construct DFA E that accepts 111
* *
.
2. Construct DFA B such that L( B) L( R) L( E ) .

<
^
3. Run TM T on input B where T decides EDFA.
4. If T accepts, reject. If T rejects, accept.
Question 18:
Consider following instance of PCP. Is it possible to find a match? If yes then give the
dominos arrangements. If NO then prove. 1/0. 101/1. 1/001 (5).

Answer:
s5
We can give the number to instances as :

1 101 1
, ,
0 1 001

1 101 1
,
A B

,
C

0 1 001

We have choice for start matching that is pair B where 1 is at start from top and bottom so pair B
is,


101

1
B
Form pair B we can see that 1 is match in top and bottom string but 01 is left in the upper so we
need a pair whose bottom string starts with 0. There are twp pairs A and C.


101 1 101 1
,
0 OR 1 , 001 We can not use C because there will be a mismatch so use A.
1
B A B C

After using B,A from upper 10 and bottom 10 is matched but 11 is left from upper so we need a
pair whose bottom string starts with 1. That is B.

101 1 101


A
1 , 0 , 1 Upper = 101 , Bottom = 101

B A B

After using B,A,B from upper 101 and bottom 101 is matched but 1101 is left from upper so we
need a pair whose bottom string starts with 1. That is B.

101 1 101 101
, , , Upper = 1011 , Bottom = 1011
1 0 1 1
B A B B

After using B,A,B,B from upper 1011 and bottom 1011 is matched but 101101 is left from upper
so we need a pair whose bottom string starts with 1. That is B.

101 1 101 101 101
, , , , Upper = 10111 , Bottom = 10111
1 0 1 1 1
B A B B B
After using B,A,B,B,B from upper 10111 and bottom 10111 is matched but 01101101 is left
from upper so we need a pair whose bottom string starts with 0. That is A and C. If we use C
there will a mismatch.
$
101 1 101 101 101 1

, 0 , 1 , 1 , 1 , 001 Upper = 1011101 , Bottom = 1011100



B
1
o
So we use A
A B B B C


101 1 101 101 101 1
, , , , , Upper = 101110 , Bottom = 101110
1 0 1 1 1 0
B A B B B A

After using B,A,B,B,B,A from upper 101110 and bottom 101110 is matched but 11011011 is left
from upper so we need a pair whose bottom string starts with 1. That is B.

101 1 101 101 101 1 101
, 0 , 1 , 1 , 1 , 0 , 1
1
B A B B B A B
We observe that Upper Values are increasing, we can not use C having bottom 001 because in
upper there will not 00 in it. So, it is not possible to find a match for this instance.

Question 19:

ANSWER:
Theorem: HALTTM is undecidable.

Theorem: HALTTM is undecidable


Suppose that HALTTM is decidable and R decides HALTTM. If we have R then we have no
A
problem on TM that loop endlessly. We can always check if a TM will loop endlessly on a given
input using R. We can use R to make a decider for ATM. We know that ATM is undecidable.
We have a contradiction and that is why R cannot exist.
Given R we can construct S which decides ATM that operates as follows:

1. On input <M, w>


2. Run TM R on input <M, w>.
3. If R rejects, reject.
4. If R accepts, simulate M on w until it halts.
5. If M has accepted w, accept; if M has rejected w, reject.

Note that S will reject <M, w> even if M loops on w.

s5
Question 20: In the silly Post Correspondence Problem, SPCP, in each pair the top string has the
same length as the bottom string. Show that the SPCP is decidable. 10

Answer: The SPCP problem is decidable. It follows from the following claim.
t
Claim: A given SPCP instance has a match if and only if there is a domino i such that
bi
ti bi .
Proof of the claim:
: If a SPCP instance has a match it has to start with some domino. Because the length of
the top and the bottom string is the same in all dominos, the first domino in the match must
surely have the same top and bottom string.
: If there is a domino with the same top and bottom string then this single domino forms a
trivial match of SPCP.

Finally, checking whether there is a domino with the same top and bottom string is easily
decidable by examining the SPCP instance.
Question 21: Check for relatively prime 21 and 14
Solution:
Given numbers are 21 and 14
factors of 21 is 1, 3, 7, 21
factors of 14 is 1, 2, 7, 14
GCD of (21,14) = 7
So 21 and 14 are not relatively prime.
Question 22:
Consider following instance of PCP. Is it possible to find a match? If yes then give the
10 001 01
dominos arrangements. If NO then prove { [ ], [ ], [ ]}
00 10 011

Solution:

<
We can give the number to instances as:

[
10
00
m
A
], [
10
UUM
001

B
], [
01
011
C
] y
We have choice for start matching that is pair C where 0 is at start from top and bottom so pair C
is,

01
[ ]
011
C

Form pair c we can see that 01 is match in top and bottom string but 1 is left in the bottom so we
need a pair whose upper string starts with 1 that is pair A

01 10
[ ],[ ]
011
no am00
C A

Now 0110 string is match from top and bottom,0 is left from bottom so we need a pair, whos upper
string starts with 0, there are two choice either select pair B or C. Lets first try with pair B,

01 10 001
[ ],[ ],[ ]
011 00
m am non 10
C A B

01 10 01
[ ],[ ],[ ]
011
m am 00 non
011
C A B
It does not match, so lets try pair C,

01 10 01
[ ],[ ],[ ]
011 am
uum 00 am011
C A B

Again we have a mismatch. There is no other pair left. So, it is not possible to find a match for this
instance.

Question 23:
Consider following instance of PCP. Is it possible to find a match? If yes then give the
100 1 0
dominos arrangements. If NO then prove { [ ], [ ], [ ]}
1 00 100
Solution:

S3
We can give the number to instances as

Numbering the instances as follows:

100 1 0
< y

#
1 , 00 , 100
o uum
A B
n C

The dominos arrangement which will gives the matching of top and bottom string is:

A, B, A, A, B, C, C


ST
100 1 100 100 1 0 0

_
1 , 00 , 1 , 1 , 00 , 100 , 100

Now if we note the top string that is 1001100100100

If we note bottom string that is 1001100100100

Now the matching is found so this list is called match.

Question 24:
Consider following instance of PCP. Is it possible to find a match? If yes then give the
01 100 10 1 0
dominos arrangements. If NO then prove
{ [ ], [ ], [ ], [ ], [ ]}
100 0 101 010 10

Solution:
We can give the number to instances as :

01 100 10 1 0
[ ], [ ], [ ], [ ], [ ]
100
o 0 101 010 am
nnm 10
A B C D E

We have choice for start matching that is pair C where 1 is at start from top and bottom so pair C is,

10
[ ]
101
n
C

Form pair c we can see that 10 is match in top and bottom string but 1 is left in the bottom so we
need a pair whose upper string starts with 1 that is pair D

10 1
[ ],[ ]

<
101
n 101

y
C D

Now 010 is left from bottom and we need a string that is start from 0 at the
top which is A
10 1 01
[ ],[ ],[ ] Now the matching string is 10101, 0100 is left in the bottom ,
101 010
uuw 100
no
C D A

we need string with 0 from top that is E


10 1 01 0
[ ],[ ],[ ],[ ] now matching string is 101010, 10010 is left in the bottom,
101
a 010
nnm 100 10
non
C D A E

so the best choice pair B


10 1 01 0 100
[ ],[ ],[ ],[ ],[ ] matching is 101010100, 100 is left from bottom
101 010 am
nnm 100 am
10 am
0
C D A E B

10
3>
So choose pair B again
1 01 0 100 100
[ ],[ ],[ ],[ ],[ ],[ ] now 0 is left from bottom so choose pair E
101
a 010
nnm 100 10
nm 0 0
nna
C D A E B B

10 1 01 0 100 100 0
[ ],[ ],[ ],[ ],[ ],[ ],[ ] now 10 s left from bottom, choose pair B
101
a 010 mo
mm 100 non
10 mo
0 nna
0 am
10
C D A E B B E
10 1 01 0 100 100 0 100
[ ],[ ],[ ],[ ],[ ],[ ],[ ],[ ]
101 010 100 10 0 0 10 0
C D A E B B E B

So the matching string is 1010101001000100

Question 25:
Lets recall that a language A is Turing recognizable if there is a TM M such that L(M) = A.

ANSWER:

Every Turing recognizable language is mapping reducible to ATM. This theorem says that ATM
is in some sense the hardest problem out of all Turing recognizable problems. If one could devise an
algorithm for ATM one could devise an algorithm for all Turing recognizable problems. Alas, ATM is not
decidable.
The proof of this theorem is very easy. let A be any Turing recognizable language. We have to show that
A m ATM Let M be a TM such that L(M)=A. Note that M exists since A is Turing-recognizable.
Now, let us consider the function f given by f(x) = <M, x>, clearly x belongs A if and only if M accepts
x.
Which is the same as x belongs A if and only if <M, x> belongs ATM.

sT
05

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy