You are on page 1of 4

Computability and Complexity – solution of 2008 Moed A exam

Dr. Mark Trakhtenbrot

Q1.

Idea of a 1-tape machine:

Scan the input; if at least one X appears after Y, then return FALSE
Run back to the beginning of the input
Repeat until there are unmarked X’s
{mark the first unmarked X;
skip all X’s to the right of it;
skip all already marked Y’s;
mark two Y’s (if there are no such Y’s then return FALSE)
run back to the first unmarked X
}
If some unmarked Y’s remain
Then return FALSE
Else return TRUE

Complexity:
- Scanning the input word: O(n)
- Running back: O(n)
- The loop is repeated n times (for each X in the input); each execution of the loop body
requires time O(n)
- Checking whether any unmarked Y’s remain: O(n)
- Total: O(n) + O(n) + O(n)*O(n) + O(n) = O(n2)

Idea of a 2-tapes machine:

Scan the input


{copy every Y to the second tape;
if at least one X appears after Y, then return FALSE
}
Run back on both tapes (to the beginning of the tapes)
Repeat until there are unmarked X’s
{mark the first unmarked X on the first tape and move one cell to the right;
mark two Y’s on the second tape (if there are no such Y’s then return FALSE);
}
If some unmarked Y’s remain
Then return FALSE
Else return TRUE

Complexity: the difference from the case of 1-tape machine is that here comparison of
amounts of X’s and Y’s takes time O(n) instead of O(n2). Hence the total is also O(n).
Q2.

L1 is not enumerable.
Given a Turing machine M, even if L(M) is decidable, this still doesn’t mean that M itself
decides this language (because it is possible that M doesn’t stop on some inputs). Hence
to check whether L(M) is decidable, it is necessary to search for machine that decides the
language. Such search is not restricted for two reasons:
- there are infinitely many machines to check
- for each of them we have to check that it stops on all inputs (this by itself requires
infinite amount of chaecks)
To summarize, even if M is such that L(M) is decidable, this can’t be checked in finite
amount of steps.

L3 is not enumerable.
To check that the pair <M,k> belongs to L3, we have to run M on all words of length k
and to check that it rejects at least one of them. Even though only finite amount of words
should be checked (e.g. if the alphabet contains 2 letters then there are 2k such words),
but each check can be potentially infinite. The reason is that rejection of a word may
mean that the run of M on it is infinitely long.

L4 is decidable.
Given <M,k>, it is necessary to check how M behaves on all its inputs during the first k
steps. Note that since only k steps are done, it is enough to check M’s behavior on all
inputs of length <=k . There is a finite amount of such input words, and for each of them
only finite amount (namely, k) of steps is done. Hence the entire check is performed in
finite time, and hence the language is decidable.

Q3.
Clearly, inclusion G2  G1 is impossible. For example, the language SAT is NP-
complete, but it is not finite. Hence equality G2=G1 is also impossible.

Finally, inclusion G1  G2 is impossible as well. A counter-example is the empty set


(that contains 0 elements): it is not NP-complete. Otherwise, every language L in NP
should be polynomially reducible to the empty set. This is impossible. The reason is that
for non-empty L there are two possible answers to the question whether a word X
belongs to L, but there is only one answer to such question related to the empty set.
Hence, whatever is a mapping f between words, the following basic requirement in the
definition of reduction A  B is violated:
X belongs to A   f(X) belongs to B
Q4.
A. The required reduction is defined as follows:
We define a mapping f that, given <M,w> (input to the halting problem HTM ), produces
the following Turing machine:

N(x) {
if (x is binary code of an even number)
then {
M(w);
accept
}
else
reject
}

Note that if M stops on the word w , then L accepts every input that is binary code of an
even number (i.e. every input x that ends with 0). In this case N belongs to language L.
On the other side, if M doesn’t stop on word w then machine N doesn’t accept any
word at all (its language is empty) and hence N doesn’t belong to L. To summarize:
<M,w> belongs to HTM   N belongs to L
And hence the defined mapping f is indeed a reduction from HTM to L. Since HTM is
undecidable, L is undecidable as well.

B. The given language L is also not enumerable. To show this, we define a reduction
from the complement of HTM (this complement is known to be not enumerable) to L. The
mapping is defined as follows:

N’(x) {
if (x is binary code of an even number)
then
accept
else{
M(w);
accept
}
}

Note that if M stops on the word w , then N’ accepts every input (regardless of whether it
ends with 0 or not); hence in this case N’ doesn’t belong to L.
On the other side, if M doesn’t stop on word w then machine N’ accepts only all words
that are binary codes of an even numbers. Hence in this case N’ belongs to language L.

To summarize:
<M,w> belongs to complement of HTM   N’ belongs to L
Hence the defined mapping is indeed a reduction from the complement of HTM to L, and
thus L is not enumerable.
Q5.
- Reduction from CLIQUE to L is defined as follows: given <G,k> where G is a graph
and k is a number, it is mapped into the following triple: <G, G, k> (i.e. both G1 and G2
are identical to G). This mapping is obviously a reduction: G contains a clique of size k if
and only if at least one of graphs G1 and G2 contains a clique of size k.

- For A U B , the answers to both questions are “yes”. Examples:


A = SAT , B is the empty set , A U B = SAT (i.e. NP-complete)
A=SAT , B = Σ* , A U B = Σ* (belongs to P)

- For A ∩ B , the answers to both questions are “yes”. Examples:


A = SAT , B is the empty set , A ∩ B is the empty set (belongs to P)
A=SAT , B = Σ* , A ∩ B = SAT (is NP-complete)

- For concatenation A.B , the answer is “yes” ; example:


A = SAT , B = {ε} (i.e. B contains only the empty word},
A.B = SAT (i.e. NP-complete)

You might also like