Uploaded by tzadikkatamar1

חישוביות וסיבוכיות - פתרון למבחו לדוגמא - 388840

advertisement
Example Exam Solution
Computability
1. (a) The runtime of a Turing machine M is a function T : N → N, where T (n)
is the maximal number of steps that M performs on an input of length n.
The class T IM E(t(n)) is the class of languages L such that there exists a
Turing machine M that decides L and whose runtime is O(t(n)).
(b) In this question, we must show that REG, the class of regular languages, is
contained in T IM E(n).
Let L ∈ REG. Then there is a deterministic automaton A = (Q, Σ, δ, q0 , F )
whose language is L. We can easily convert A into a Turing machine M ,
that reads the input from left to right and keeps track of A’s state. M will
accept if and only if when it first sees the character, the current state is in
F.
Formally, M = (Q0 , Σ, Γ, δ 0 , q0 , qaccept , qreject ), where:
•
•
•
•
Q0 = Q ∪ {qaccept , qreject .
Γ = Σ ∪ { }.
δ 0 (q, σ) = (δ(q, σ), R) for every σ ∈ Σ.
δ 0 (q, ) = qaccept if q ∈ F , and δ 0 (q, ) = qreject if q ∈
/ F.
So M will decide L in n + 1 steps, and therefore L ∈ T IM E(n).
1
2. (a) Let A, B ⊂ Σ∗ be languages. A polynomial reduction from A to B is a
function f : Σ∗ → Σ∗ that receives an input for A and returns an input for
B such that:
• f is computable in polynomial time.
• for every w ∈ Σ∗ , w ∈ A ⇔ f (w) ∈ B.
(b) We will show that 2 − CLIQU E is N P -hard via a polynomial reduction
from the language
CLIQU E = {hG, ki : G has a clique of size k}
We saw in class that CLIQU E is N P -complete, and therefore if there is
a polynomial reduction from CLIQU E to 2 − CLIQU E, it implies that
2 − CLIQU E is N P -hard.
We define f (hG, ki) = hG0 , ki, where G0 consists of two disjoint copies of G.
Clearly, f is computable in polynomial time.
Note that if G has a clique of size k, then that clique appears in each of the
disjoint copies of G in G0 , and therefore G0 has at least 2 different cliques of
size k.
On the other hand, if G0 has 2 cliques of size k, then in particular it has a
clique of size k. Now, this clique must lie completely in one of the disjoint
copies of G, since there aren’t any edges between the two copies. Thus, this
clique is actually contained in G, and so G has a clique of size k.
We have shown that G has a clique of size k if and only if G0 has two cliques
of size k, and so
hG, ki ∈ CLIQU E ⇔ f (hG, ki) ∈ 2 − CLIQU E.
Thus, f is a polynomial reduction from CLIQU E to 2−CLIQU E as desired.
2
3. (a) Assume that we have an algorithm for an optimization problem. Let OPT
be the value of an optimal solution, and let ALG be the value of the solution
returned by the algorithm. We say that the algorithm is a c-approximation
if for every input the following holds.
• For a minimization problem, we require
ALG
≤ c.
OP T
• For a maximization problem, we require
OP T
≤ c.
ALG
(b) Let COP T = {e1 , ..., ek } be an optimal solution, and let V be G’s vertex set.
Since COP T is a legal edge cover, we have ∪ki=1 ei = V , and therefore
|V | = | ∪ki=1 ei | ≤ ∪ki=1 |ei | =
k
X
2 = 2k.
i=1
Thus, OP T = k ≥ |V |/2.
On the other hand, note that each iteration of the greedy algorithm adds
one edge to C and covers at least one vertex, so the number of edges in the
greedy solution is at most |V |. Thus,
ALG ≤ |V | ≤ 2OP T ⇒
as desired.
3
ALG
≤2
OP T
4. (a) A configuration of a Turing machine is a triple consisting of the current
state, the head position and the contents of the tape.
The computation tree of a non-deterministic Turing machine N on an input
w is a tree whose nodes are configurations, such that:
• The root is the start configuration of N on w.
• The children of a node C are all of the configurations that can be obtained from C by means of one computation step. In a deterministic
machine, each node would have one child, but in a nondeterministic
machine, the number of C’s children can be greater than one.
• The leaves are all either accepting configurations or rejecting configurations.
(b) The idea of the algorithm is to nondeterministically guess k, and then to
accept if and only if the first tape has exactly k 2 a’s.
The trick to calculating k 2 is to go over a string of length k over and over
again. At each iteration, we cross out a single letter. When the entire string
has been crossed out, we stop.
Here is an implementation-level description:
i. Verify that the first tape contains an input string of the form an . If
n = 0, accept.
ii. Write a sequence of 1’s on the second tape, while also advancing the first
head. Decide non-deterministically when to stop. When the first head
reaches the end of the a’s, return both heads to the start positions.
After this stage, the second tape contains a string of the form 1k for
some 1 ≤ k ≤ n.
iii. Advance both heads until the second head reaches the end of the 1’s.
Cross out the first uncrossed 1 on the second tape. If at some point the
first head reaches the end of the a’s, reject.
iv. Return the second head to the start of the tape, while the first head
stays where it is.
v. Repeat steps (iii) and (iv) until all of the 1’s have been crossed out.
When this happens, then if the first head has reached the end of the
a’s, accept. Else, reject.
4
5. (a) Post’s lemma states that a language L is decidable if and only if both L and
its complement L are both recognizable.
Proof: If L is decidable, then there is a Turing machine T that decides L.
Thus, T recognizes L, and so L is recognizable.
By switching T ’s accept and reject states, we get a Turing machine that
decides L. Thus, L is decidable and therefore it is recognizable.
For the other direction, assume that both L and L are recognizable. Let T
be a Turing machine that recognizes L, and let T 0 be a Turing machine that
recognizes L.
We define a new two tape Turing machine M that decides L. On an input
w, M first copies it to the second tape. It then runs T on the first tape
and T 0 on the second tape. If T accepts, M accepts, and if T 0 accepts, M
rejects. We have
w ∈ L ⇒ T accepts w ⇒ M accepts w
w∈
/ L ⇒ w ∈ L ⇒ T 0 accepts w ⇒ M rejects w.
Thus, M decides L, so L is decidable.
As a corollary, if L is undecidable and recognizable, then its complement
must be unrecognizable, since if both L and L were recognizable, L would
be decidable by the lemma.
(b) Note that L is recognizable. We have
L = {hM i : M accepts the empty input}.
By running M on the empty input (using the universal Turing machine), we
can recognize L. Thus, L is recognizable.
We can show that L is not decidable via a reduction from HALT . Given
an input hM, wi for HALT , we define f (hM, wi) to be the description of a
Turing machine M 0 that operates as follows:
i.
ii.
iii.
iv.
Delete the input.
Writes w on the tape.
Run M on w.
If M halts, M 0 accepts.
Now,
hM, wi ∈ HALT ⇔ M halts on w ⇔ M 0 accepts the empty input ⇔ hM 0 i ∈ L
Thus, f is a reduction from HALT to L, and so L is undecidable.
Now, by Post’s lemma, since L is recognizable but not decidable, it follows
that L is not recognizable.
5
Download