Tutorial 12: Exercise 1 (Compulsory)
Tutorial 12: Exercise 1 (Compulsory)
Tutorial 12
Exercise 1 (compulsory)
Is the following definition of NP-completeness correct? If no, give arguments why not.
Solution:
The definition does not make any sense. The elements in the class NP are languages (sets of strings), not
Turing machines (neither the encodings of Turing machines). Hence M , nor hM i cannot be a member of
NP.
Exercise 2 (compulsory)
Consider the following claims and answer which of them are correct and which of them not. Give precise
arguments.
1. If L1 and L2 are NP-complete, then L1 ≤P L2 and L2 ≤P L1 .
2. If L1 and L2 are NP-complete, then L1 ≤m L2 and L2 ≤m L1 .
3. If L1 ≤P L2 , L2 ≤P L1 , and L1 , L2 ∈ NP, then L1 and L2 are both NP-complete.
4. If L1 is NP-complete and L1 ≤P L2 , then L2 is NP-complete.
Solution:
1. Correct. It follows directly from the definition of NP-completeness (part 2 about NP-hardness).
2. Correct. Surely, if L1 ≤P L2 then also L1 ≤m L2 , and if L2 ≤P L1 then also L2 ≤m L1 . This is
because every polynomial time reduction is also a mapping reduction.
3. Incorrect. Let L1 = L2 = ∅. Surely ∅ ≤P ∅ by a reduction that is e.g. the identity function but ∅
cannot be NP-complete (because none of the langauges in NP, except for ∅ itself, are reducible to ∅).
4. Incorrect. We know that L2 is NP-hard but we have no guarantee that L2 belongs to NP, which is
required for NP-completeness. The correct claim is: If L1 is NP-complete, L2 ∈ NP, and L1 ≤P L2
then L2 is NP-complete.
Exercise 3 (compulsory)
Consider a nondeterministic Turing machine M over the input alphabet Σ = {a}, tape alphabet Γ =
{a, t}, control states Q = {q, qaccept , qreject } and the following δ function:
• δ(q, a) = {(q, a, R), (qreject , t, L)}
• δ(q, t) = {(qaccept , a, R)}
Fill in all legal windows (recall the proof of Cook-Levin Theorem) with the following chosen first rows.
Note that this covers only some of the legal windows. The number of windows in every row indicates how
many possible legal windows you should be able to find. You might use the abbreviations qa for qaccept
and qr for qreject .
a a a a a a a a a a a a
1
C OMPUTABILITY AND C OMPLEXITY T UTORIAL 12
# a a # a a
a q a a q a
a q t
q a a q a a q a a q a a
a a q a a q
Solution:
a a a a a a a a a a a a
a a a q a a t a a a a qr
# a a # a a
# a a # a qr
a q a a q a
a a q qr a t
a q t
a a qa
q a a q a a q a a q a a
a q a a t a qr t a t t a
a a q a a q
a a a a qr a
Exercise 4 (compulsory)
Show that if P=NP then every language B ∈ P, except for ∅ and Σ∗ , is NP-complete.
Solution:
Assume that P=NP. Let B ∈ P such that B 6= ∅ and B 6= Σ∗ . This means that there is a string win ∈ B
and a string wout 6∈ B. We want to show that B is NP-complete.
Surely, the language B is in NP=P (by our assumption). We have to show that B is NP-complete. Let
A be an arbitrary language from NP=P. Hence A has a polynomial time decider MA . We need to argue
that A ≤P B. Here is a poly-time reduction f from A to B:
”On input w:
1. Run MA (decider for A) on w.
2. If MA accepted then output win . If MA rejected then output wout .”
This is a poly-time reduction from A to B, and hence B is NP-complete.
2
C OMPUTABILITY AND C OMPLEXITY T UTORIAL 12
Exercise 5 (optional)
Define the language
ABT M = {hM, x, 1t i | M is a NTM which accepts the input x after no more than t steps}
where 1t here denotes the number t written in unary, i.e., the string 1| .{z
. . 1} . Prove that ABT M is
t occurrences
NP-complete. Hint: Make a direct proof, similarly as Cook-Levin Theorem.
Solution:
We must show that
• ABT M ∈ NP, and
If n = |hM, x, 1t i|, then it is easy to see that the decider uses O(t) · O(n) = O(n2 ) steps.
We must now show that for every L ∈ NP we have L ≤P ABT M . So we must find a polynomial-time
computable function f with the property that w ∈ L ⇐⇒ f (w) ∈ ABT M .
Since L ∈ NP, we know that there exists a nondeterministic Turing machine ML with time complexity
O(nk ) which is a decider for L. We thus know that for any string w we have that w ∈ L if and only if M
accepts w in c · nk of less steps for some constant c. So let
k
f (w) = hM, w, 1c·|w| i
This function clearly satisfies that w ∈ L ⇐⇒ f (w) ∈ ABT M . We now only need to show that f is
polynomial-time computable.
It is not hard to show that we can compute the unary representation of the number c · nk in time
polynomial in n. A two-tape Turing machine for computing the unary representation of c · nk given the
unary representation of n looks as follows:
”On input 1n :
1. Make a copy of n on the second tape.
2. For i := 1 to k
• Create n copies of the string on the second tape.
3. Finally, create c copies of the string that is on the second tape.”
Stage 1 requires O(n) steps. The loop in stage 2 is traversed a total of O(n) times. Each traversal makes
n copies of a string whose length is at most O(nk ); this requires no more than O(n·n2k ) = O(n2k+1 ) steps.
Consequently, in the step 2. the machine uses at most O(n) + nO(n2k+1 ) = O(n2k+2 ) steps. Finally, step
3. uses O(n2k ) steps. Hence the total running time is polynomial (by Theorem 7.8, we can simulate the
two-tape machine by a single-tape machine with only quadratic increase in the time complexity).