2-CS701 Solved 25 MID Term Most Important
2-CS701 Solved 25 MID Term Most Important
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
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.
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.
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).
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:
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:
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.
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.
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
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:
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.
<
^
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
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.
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
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
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
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
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