Test2 Sol
Test2 Sol
1) [ 30 marks ] Recall that a clique in an undirected graph is a set of nodes in which every pair of nodes
is connected by an edge. The textbook defined the language CLIQUE as follows:
The textbook proves that CLIQUE is NP-complete. Define the language TWO-CLIQUES as:
TWO-CLIQUES = { hG, ki | G is an undirected graph that contains two disjoint cliques of size k }
Prove that TWO-CLIQUES is NP-complete. Remember: You need to show two things to show that
a language is NP-complete.
We first need to show that TWO-CLIQUES is in NP. A polynomial time verifier for TWO-CLIQUES
takes hw, ci as input. It rejects if w does not have the form hG, ki. Otherwise, we can have it accept
if c is an encoding of two sets of nodes in G, the sets are both of size k, the two sets are disjoint, and
both sets define cliques in G (ie, for both sets, there is an edge connecting every pair of nodes in the
set), and otherwise it rejects. This can all be done easily in polynomial time.
Alternatively, one could show that TWO-CLIQUES is in NP by describing a nondeterministic Turing
Machine that decides it and that runs in polynomial time.
Next, we need to show that every language in NP can be reduced in polynomial time to TWO-
CLIQUES. We do this by showing that CLIQUE, which is known to be NP-complete, can be reduced
to TWO-CLIQUES, so all languages in NP can be reduced to TWO-CLIQUES using a reduction via
CLIQUE. We could reduce CLIQUE to TWO-CLIQUES in several ways; here is one.
The reduction maps hG, ki to hG0 , ki, where G0 is the graph consisting of all the nodes and edges of
G, along with another k nodes that are connected to each other, but not to any of the nodes from G.
This is easy to do in polynomial time.
We need to show that hG, ki is in CLIQUE iff hG0 , ki is in TWO-CLIQUES. For the forward direction,
if hG, ki is in CLIQUE, then there is a subset of k nodes of G that is a clique, in which case the same
subset of G0 is a clique, and the k nodes in G0 that are not in G also form a clique, so there are two
disjoint cliques of size k, and hence hG0 , ki is in TWO-CLIQUES. In the other direction, if hG0 , ki is
in TWO-CLIQUE, there are two disjoint cliques of size k in G0 . These two cliques can’t both be in
the k nodes of G0 that aren’t in G, and can’t be partly in G and partly out (since there are no edges
between these parts), so there must be a clique of size k in G, and hence hG, ki is in CLIQUE.
2) [ 45 marks total ] Part of the proof in the textbook that SAT is NP-complete shows that for any
language, A, in NP, which is decided by a nondeterministic Turing Machine, N , that runs in polyno-
mial time, there is a function that maps a string w to a string hφi that is an encoding of a Boolean
formula, φ, that is satisfiable iff N accepts w.
The proof shows that there is an algorithm to do this reduction in polynomial time, for some fixed
nondeterministic Turing Machine, N , which runs in some polynomial time bound — say nk + 2, for
some k, where n is the length of the input. The algorithm takes the string w as input and outputs
hφi. The formula φ that it creates has variables that describe the “tableau” for a computation of N
on input w that halts within nk + 2 steps (we’ll let this tableau be nk + 3 by nk + 5 in size). The
rows of the tableau are successive configurations of N , bounded by “#” symbols. The variable xi,j,s
is 1 iff cell (i, j) of the tableau contains symbol s, where s ∈ Q ∪ Γ ∪ {#}.
Recall that the formula φ has the form
1
where φcell enforces that the variables describe a tableau with exactly one symbol in each cell, φstart
enforces that the first configuration is the correct start configuration for input w, φmove enforces
that each configure is followed by a possible successor configuration (same as the previous one if the
machine has halted), and φaccept enforces that the tableau contains an accepting configuration.
Suppose that the input alphabet of machine N is Σ = { 0, 1 }, the tape alphabet is Γ = { 0, 1, },
the state space is Q = { q0 , q1 , qaccept , qreject }, the start state is q0 , and the transition function,
δ : Q × Γ → Q × Γ × {L, R}, is as follows:
δ(q0 , 0) = { (q1 , 1, L), (q1 , 0, R) }, δ(q0 , 1) = { (q1 , 1, L) }, δ(q0 , ) = { (qreject , , L) }
For all the questions below, suppose that the input is w = 011, so that n = 3, and that k = 1, so
the tableau has 6 rows and 8 columns.
a) [ 12 marks ] Fill in the two tableaus below to represent two different accepting computations on
this input.
# q0 0 1 1 #
# q1 1 1 1 #
# 1 q1 1 1 #
# 1 1 q1 1 #
# 1 1 1 q1 #
# 1 1 qaccept 1 #
# q0 0 1 1 #
# 0 q1 1 1 #
# 0 1 q1 1 #
# 0 1 1 q1 #
# 0 1 qaccept 1 #
# 0 1 qaccept 1 #
2
d) [ 9 marks ] The φaccept part of φ is a disjunction (or) of literals. Write down three of these
literals, and say (and explain) how many literals are in this disjunction.
Here are three:
x1,2,q , x3,3,q , x4,7,q
accept accept accept
There are a total of 6 × 8 = 48 such literals, one for each cell, though one could omit the ones
on the edges that are always set to #, which would leave 6 × 6 = 36 literals.
e) [ 10 marks, +1 for each correct, −1 for each wrong, minimum 0 ] The φmove part of φ ensures
that every 2 × 3 “window” of the tableau is legal for the machine N . For each of the following
windows, circle “Yes” or “No” to indicate whether it is legal or not (no explanation is required):
# 0 1 1 1 q1
Legal? Yes No Legal? Yes No
# 0 1 1 1 1
q0 1 1 0 0 1
Legal? Yes No Legal? Yes No
q0 1 1 0 1 1
q1 0 1 # q0 1
Legal? Yes No Legal? Yes No
1 0 1 # q0 0
q0 0 1 q1 1 1
Legal? Yes No Legal? Yes No
1 q0 1 1 q1 1
1 q1 # q0
Legal? Yes No Legal? Yes No
qaccept 1 # q0
3) [ 25 marks ] The class coNP is defined to contain all languages whose complements are in NP — in
other words, L ∈ coNP iff L ∈ NP. A language L is defined to be coNP-complete if L is in coNP and
any other language in coNP is polynomial time reducible to L — in other words, L is coNP-complete
iff L ∈ coNP and for all L0 ∈ coNP, L0 ≤P L.
Prove that SAT is coNP-complete. You may use any parts of the proof that SAT is NP-complete
that are useful for proving this.