0% found this document useful (0 votes)
85 views4 pages

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

This document contains solutions to exam questions on computability and complexity. It defines reductions and uses one to prove that the language N EQ is not recognizable. It shows that the language DIV is in P by providing a polynomial-time algorithm. It also defines NP-hard and NP-complete problems and shows that Half-VC is NP-complete via a reduction from Vertex Cover. Finally, it defines c-approximation algorithms and provides a 2-approximation for parallel scheduling.

Uploaded by

lina yosef
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)
85 views4 pages

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

This document contains solutions to exam questions on computability and complexity. It defines reductions and uses one to prove that the language N EQ is not recognizable. It shows that the language DIV is in P by providing a polynomial-time algorithm. It also defines NP-hard and NP-complete problems and shows that Half-VC is NP-complete via a reduction from Vertex Cover. Finally, it defines c-approximation algorithms and provides a 2-approximation for parallel scheduling.

Uploaded by

lina yosef
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/ 4

Computability and Complexity - Final

Exam
Moed A 2022: Solutions

1. (a) Define a reduction.


Solution: Let A, B ⊆ Σ∗ be two languages. A reduction from A to
B is a computable function f : Σ∗ → Σ∗ such that for every input
w ∈ Σ∗ :
w ∈ A ⇔ f (w) ∈ B.
(b) Prove the reduction theorem. That is, prove that if f is a reduction
from A to B, and B is decidable, then A is decidable.
Solution: Let DB be a Turing machine that decides B. We describe
a Turing machine DA that decides A.
Given an input w ∈ Σ∗ , DA first computes f (w), and then outputs
the result of DB on f (w). If DB accepts f (w), it means that f (w) ∈
B and hence w ∈ A.
Now, if DB rejects f (w), it means that f (w) ∈
/ B and hence w ∈ / A.
Thus, DA decides A and so A is decidable.
2. (a) Let L be a language. Define when a Turing machine T decides L,
and when it recognizes L.
Solution:
• T decides L if for every input w, if w ∈ L then T accepts w, and
if w ∈
/ L then T rejects w.
• T recognizes L if for every input w, if w ∈ L then T accepts w,
and if w ∈
/ L then T does not accept w.
(b) Let N EQ = {hM1 , M2 i : L(M1 ) 6= L(M2 )}. Prove that N EQ is not
recognizable.
Solution: We describe a reduction from HALT to N EQ.
Given an input hM, wi for HALT , we define two Turing machines
M1 , M2 as follows:
• M1 erases its input and then runs M on w. If M halts on w,
then M1 accepts.
• M2 always accepts.

1
We claim that hM, wi ∈ HALT if and only if hM1 , M2 i ∈ N EQ.
Assume that hM, wi ∈ HALT . This means that M does not halt
on w. Since M1 runs M on w, it means that M1 does not halt on
any input, and so L(M1 ) = ∅. Since M2 always accepts, we have
L(M2 ) = Σ∗ . Thus, L(M1 ) 6= L(M2 ) and so hM1 , M2 i ∈ N EQ.
Assume that hM, wi ∈ / HALT . This means that M halts on w. Since
M1 runs M on w and then accepts, it means that L(M1 ) = Σ∗ . Since
M2 always accepts, we have L(M2 ) = Σ∗ . Thus, L(M1 ) = L(M2 )
and so hM1 , M2 i ∈
/ N EQ.
Therefore, we have a reduction from HALT to N EQ. Since HALT is
not recognizable, by the reduction theorem N EQ is not recognizable.
3. For natural numbers a, b ∈ N, let

DIV = {ha, bi : There is a number c > 1 that divides a and b}.

(a) Show that DIV ∈ N P .


Solution: We describe a polynomial-time verifier V for DIV . The
input for V is a pair of integers a, b, together with a witness c ∈ N.
V verifies that c > 1 and that c divides a and b. Since this can be
done in polynomial time using long division, V is indeed a polynomial
verifier for DIV , and therefore DIV ∈ N P .
(b) Show that DIV ∈ P .
Solution: We describe a polynomial time algorithm that decides
DIV . Recall that Euclid’s gcd algorithm finds the greatest common
divisor of a and b in polynomial time. Note that ha, bi ∈ DIV if
and only if gcd(a, b) > 0. Therefore, the following algorithm decides
DIV :
Given an input ha, bi, the algorithm first runs Euclid’s gcd algorithm
on a and b. If the result is 1, then ha, bi ∈
/ DIV , and so the algorithm
outputs “No”. Otherwise, the algorithm outputs “Yes”.
Therefore, DIV ∈ P .
4. (a) What are the definitions of an N P -hard language and an N P -complete
language?
Solution:
• A language L is N P -hard if for every language A ∈ N P , there
is a reduction from A to L.
• A language L is N P -complete if L ∈ N P and L is N P -hard.
(b) Let

Half −V C = {hGi : G has a vertex cover containing half of its vertices}.

Show that Half − V C is N P -complete via a polynomial reduction


from V ERT EX − COV ER.

2
Solution: We first show that Half − V C ∈ N P by describing a
polynomial verifier V .
The input for V is a graph G and a witness S ⊆ V (G). V verifies
that |S| = |V (G)|/2 and that S is a vertex cover for G. Since this
can be done in polynomial time, V is indeed a polynomial verifier for
Half − V C, and therefore Half − V C ∈ N P .
We now show that Half − V C is N P -hard. We describe a reduction
from V ERT EX − COV ER to Half − V C. Given an input hG, ki
for V ERT EX − COV ER, we define a graph G0 as follows:
Let n = |V (G)|.
• If k = n/2, set G0 = G.
• If k > n/2, we construct G0 by adding 2k − n isolated vertices to
G.
• If k < n/2, we construct G0 by adding n − 2k + 2 new vertices,
every pair of which is connected by an edge.
We must show that G has a vertex cover of size k if and only if G0
has a vertex cover containing half of its vertices.
Assume that G has a vertex cover S of size k.
• If k = n/2, then S is a vertex cover of G0 containing half of its
vertices.
• If k > n/2, then since |V (G0 )| = 2k, we have again that S is a
vertex cover of G0 containing all of its vertices.
• If k < n/2, then |V (G0 )| = n + m = 2n − 2k + 2. By choosing S 0
to be the union of S and all but one of the new vertices, we get
a vertex cover of size k + m − 1 = n − k + 1 for G0 , as required.
Assume now that G0 has a vertex cover S 0 containing half of its
vertices.
• If k = n/2, then S 0 is a vertex cover of G containing half of its
vertices.
• If k > n/2, then since |V (G0 )| = 2k, we have that S 0 is a vertex
cover of G0 containing k vertices. Therefore, S 0 ∩V (G) is a vertex
cover of G containing at most k vertices. By adding k − |S 0 ∩ G|
arbitrary vertices to S 0 ∩ G, we get a vertex cover S for G of size
k.
• If k < n/2, then |V (G0 )| = 2n − 2k + 2. Since S 0 contains half of
the vertices of G0 , we have that |S 0 | = n − k + 1. Since the new
vertices that we added to G are all connect, S 0 must contain at
least m − 1 of them, so |S 0 ∩ V (G)| ≤ (n − k + 1) − (m − 1) = k.
Once again, if S 0 ∩ V (G) < k, we can construct a vertex cover of
size k for G by adding k − |S 0 ∩ G| arbitrary vertices to S 0 ∩ G.
5. (a) Define a c-approximation algorithm.

3
Solution: A c-approximation algorithm for a problem P is an al-
gorithm A that, given an input x ∈ Σ∗ for P , outputs a solution s
for P such that the ratio between the value of s and the value of an
optimal solution is at most c.
(b) In the parallel-scheduling problem, me must divide n tasks with
completion times t1 , ..., tn to two identical processors, so that the
total time it takes to complete the tasks is minimized. Suggest a 2-
approximation algorithm for the problem, and prove that it is indeed
a 2-approximation.
Solution: The best that an optimal solution can do is to parti-
tion the tasks so that both processors finish at exactly
Pn the same
time. In this case, the total completion time is ( i=1 ti ) /2. The
trivial algorithm that gives the first processor
Pn all of the tasks is a 2-
approximation, since the runtime is i=1 ti , which is at most twice
as much as the time used by an optimal algorithm.

You might also like