Hints¶
Green section¶
Recall the problems:
and
Q1¶
Solving SAT using truth tables
For the following Boolean formulae, count how many satisfying assignments they have, then decide if they are in SAT and DOUBLESAT?

\(\phi_1 = x\land (y\lor \bar x)\land (z\lor \bar y)\)

\(\phi_2 = (x\lor y)\land\big((\overline{x\lor z})\lor(\bar z\land \bar y)\big)\)

\(\phi_3 = (\bar x \lor y \lor z) \land (x \lor \bar y \lor z) \land (x \lor y \lor \bar z)\)
Truth tables:

\(\phi_1\) has only 1 satisfying assignment so
 \(\braket{\phi_1}\in \text{SAT}\)
 \(\braket{\phi_1}\not\in\text{DOUBLESAT}\)

\(\phi_2\) has ....... satisfying assignments so
 \(\braket{\phi_2}\in \text{SAT}\)
 \(\braket{\phi_2} ....... \text{DOUBLESAT}\)

\(\phi_3\) has ......... satisfying assignments so
 \(\braket{\phi_3} ....... \text{SAT}\)
 \(\braket{\phi_3} ....... \text{DOUBLESAT}\)
If you like coding then you can try something like:
print("x y z  Ο1 Ο2 Ο3 ")
for x in [0,1]:
for y in [0,1]:
for z in [0,1]:
phi1 = x and (y or not x) and (z or not y)
phi2 = (x or y) and (not(x or z) or (not z and not y))
phi3 = (not x or y or z) and (x or not y or z) and (x or y or not z)
phi1 = int(phi1)
phi2 = int(phi2)
phi3 = int(phi3)
print("{} {} {}  {} {} {} ".format(x,y,z,phi1,phi2,phi3))
Q2¶
Proving that TRIPLESAT is NPcomplete
Define
Complete the proof below to show that \(\text{TRIPLESAT}\) is NPcomplete.
Proof
We need to show that \(\text{TRIPLESAT}\in\textbf{NP}\) ....... \(\text{SAT}\leq_P \text{TRIPLESAT}\).
[½] \(\text{TRIPLESAT}\in\textbf{NP}\):
On input \(\braket{\phi (x_1,\dots,x_n)}\), nondeterministically guess .... different for the Boolean variables \(x_1,\dots,x_n\), and verify whether they all ........ \(\phi\).
The verification step only costs \(O( ........ )\).
[2/2] \(\text{SAT}\leq_P \text{TRIPLESAT}\):
On input \(\braket{\phi (x_1,\ldots,x_n)}\), introduce 2 new Boolean variables \(a\) and \(b\), and output the formula: \(\(\Psi(x_1,\ldots,x_n, a, b) = \phi (x_1,\ldots,x_n)\,\land (a\lor b).\)\)

(½) If \(\braket{\phi}\in\text{SAT}\) then this means that \(\phi\) has at least ...... satisfying assignment, and therefore \(\phi\,\land (a\lor b)\) has at least ....... satisfying assignments because the added clause \((a\lor b)\) can be satisfied in 3 ways:
\[(a,b)\in\{(1,0), (0,1), (....,....)\}.\]So \(\braket{\Psi} = \braket{\phi\,\land (a\lor b)} \in \text{TRIPLESAT}\).

(2/2) If \(\braket{\phi} \not\in \text{SAT}\) then \(\phi \land (a\lor b)\) .......... have a satisfying assignment because
\[0 \land 0 = 0 \qquad\text{ and }\qquad 0\land ..... = 0.\]So \(\braket{\Psi} = \braket{\phi \land (a\lor b)} \not\in \text{TRIPLESAT}\).
Therefore, \(\text{SAT}\leq_P \text{TRIPLESAT}\), and hence TRIPLESAT is NPcomplete.
Q3¶
A slightly different proof that DOUBLESSP is NPcomplete
Let \(\mathbb{N}= \{1,2,3,\ldots\}\) be the set of natural numbers, and define
Consider the following restricted version of the SubsetSum Problem (SSP)
Here the notation "\(A\subsetneq B\)" means that \(A\subset B\) but \(A\neq B\).
SSPΒ is NPcomplete.
Define:
Complete the proof below to show that \(\text{DOUBLESSP}\in \textbf{NPcomplete}\).
Proof
[½] \(\text{DOUBLESSP}\in {\textbf{NP}}\) because we can ........ if 2 given subsets \(\mathcal{T}_1, \mathcal{T}_2\) of \(\mathcal{S}\) sum to \(t\) and check that \(\mathcal{T}_1\neq \mathcal{T}_2\) in time \(O(.......)\), which is polynomial time.
[2/2] \(\text{SSP}\leq_P \text{DOUBLESSP}\).
Since \(\mathcal{S}\subsetneq \mathbb{N}_t\) then \(\mathcal{S}\) ........ at least an element \(m\) from \(\{1,2,3,\ldots, t1\}\). Select such an \(m\) and build a Β instance \(\braket{\mathcal{S}',t}\) where\(\mathcal{S}'=\mathcal{S}\;\cup\;\{m,tm\}.\)

(½) Showing that: \(\braket{\mathcal{S}, t}\in \text{SSP}\implies \braket{\mathcal{S}', t} .... \text{DOUBLESSP}\).
Since \(\braket{\mathcal{S}, t}\in \text{SSP}\) then there is a subset \(\mathcal T\subset \mathcal{S}\) which ...... to \(t\).
A second solution is given by ........

(2/2) Showing that: \(\braket{\mathcal{S}', t}\in \text{DOUBLESSP}\implies \braket{\mathcal{S}, t}\in .....\).
If \(\braket{\mathcal{S}', t}\in \text{DOUBLESSP}\) then there are two distinct subsets \(\mathcal T\) andΒ Β \(\mathcal U\) of \(\mathcal{S}'\) that both sum to \(t\).
\(\mathcal T\) and \(\mathcal U\) cannot both be \(\{m,tm\}\) because they must be ......... So one of them must be a ........ of \(\mathcal{S}\).
So, \(\braket{\mathcal{S}, t}\in \text{SSP}\).
Q4¶
The CLIQUE problem
Consider the following graph:
and recall that

What is the largest \(k\) for which this graph satisfies CLIQUE?

In general, how many edges does a \(k\)clique have (as a function of \(k\))?

There are two triangles (3cliques): \(\{1,2,3\}\) and \(\{2,3,4\}\). However, there is no 4clique, since there are only 4 nodes, and one edge is missing.
Thus \(k = ...\) is the answer.

All pairs of nodes must have an edge between them, and the number of pairs of \(k\) nodes is
\[{k \choose 2} = \frac{k!}{2!(k2)!} = \frac 12 k(k1).\]
Counting...
The number of choosing \(k\) elements from \(n\) elements is
We read this as "\(n\) choose \(k\)."
You can learn more about it at https://en.wikipedia.org/wiki/Combination
Q5¶
The VERTEXCOVER problem
A vertex cover of an undirected graph \(G\) is a subset of the vertices where every edge of \(G\) touches one of those vertices.
The VERTEXCOVER problem asks whether a graph contains a vertex cover of a specified size:
What is the smallest \(k\) for which the graph from the previous question satisfies VERTEXCOVER?
\(k=2\)
Q6¶
The HAMILTONIANCIRCUIT problem
Do the following graphs have Hamiltonian circuits?

Yes for the first one, e.g. 0111122313144515............

No for the second.
To visit 6 we must have 0 and 3 as its immediate neighbours. This forces the inclusion of the path 063 and makes it impossible to visit .......
Another way to also see it is to realise that we must have the paths 0123 and 0543. This makes it impossible to create a hamiltonian cycle that also includes ........

No for the third. (The proof is a little more involved... and you were not asked for proofs)
Orange section¶
Q7¶
Proving that 3SAT is NPcomplete
Let \(x_1,x_2,\ldots,x_n\) be Boolean variables, and let \(\phi\) be a Boolean formula written in 3cnf (Conjunctive Normal Form, like \(\phi_3\) in the first exercise) given by
where each clause \(c_m\) has the form \(\alpha\lor \beta \lor \gamma\), where each of \(\alpha, \beta, \gamma\) is a literal: a variable \(x_i\) or its negation \(\bar x_i\).
The 3SAT problem is NPcomplete, and asks if a given 3cnf formula is satifiable.
We showed in the lecture that the SubsetSum Problem (SSP) is in P. Now, show that SSP is NPcomplete by reducing 3SAT to it, i.e. show that
You may find it easier if you study the discussion at https://saravananthirumuruganathan.wordpress.com/2011/02/07/detaileddiscussiononnpcompletenessofsubsetsum/ then the proof given in the textbook.
Q8¶
Proving that CLIQUE is NPcomplete
Prove that CLIQUE is NPcomplete by reducing the VERTEXCOVER problem to CLIQUE. (VERTEXCOVER is NPcomplete)
You can use the following reduction from VERTEXCOVER to CLIQUE:
Suppose we are given an instance \(\braket{G,k}\) of VERTEXCOVER. Construct the instance \(\braket{G',nk}\) of CLIQUE, where \(n\) is the total number of nodes of \(G\), and \(G'\) is \(G\) with the set of edges complemented (i.e. \(G'\) has an edge if and only if \(G\) does not have that edge).
We must show that \(G\) has a node cover of size \(k\) if and only if \(G'\) has a clique of size \(nk\).

First, let \(C\) be a node cover of \(G\) of size \(k\). We claim that \(C'\), the complement of the nodes in \(C\), is a clique in \(G'\) of size \(nk\).
Surely \(C'\) is of size ..... Suppose it is not a clique. Then there is a pair of nodes \((u,v)\) that do not have an edge in \(G'\). Thus this edge is in \(G\). But neither \(u\) nor \(v\) is in \(C\), contradicting the assumption that is is a node cover.

Conversely, if \(C'\) is a clique of size \(nk\) in \(G'\), then we claim that \(C\) the complement of \(C'\), is a node cover of size \(k\) in \(G\).
The argument is similar: if \((u,v)\) is an edge of \(G\) not covered by \(C\), then both \(u\) and \(v\) are in ........, but the edge \((u,v)\) is not in \(G'\), contradicting the assumption that \(C'\) is a clique.
Q9¶
Proving that HALFCLIQUE is NPcomplete
Given a graph \(G\) with an even number of vertices \(n\), does \(G\) have an \(n/2\)clique?
Reduce CLIQUE to HALFCLIQUE.
You need to figure out how to add vertices to adjust the size of the largest clique depending on whether \(k=n/2\) or \(k>n/2\) or \(k<n/2\) (e.g., if \(k = n/2\), just produce \(G\)).
Let \((G,k)\) be an instance of CLIQUE, and suppose \(G\) has \(n\) vertices. We produce an instance of the HALFCLIQUE, as follows:

If \(k = n/2\), just produce \(G\).
Note that \(G\) has a halfclique if and only if it has a clique of size \(k\) in this case.

If \(k > n/2\), add \(2k  n\) isolated vertices (vertices with no incident edges).
The resulting graph has a halfclique (whose size must be \((n + (2kn))/2 = 2k\), if and only if \(G\) has a clique of size .......

If \(k < n/2\), add \(n  2k\) vertices, and connect them in all possible ways to each other and to the original vertices of \(G\).
The new graph thus has ......... vertices. The new vertices, plus a clique of size \(k\) in \(G\) form a clique of size \((n2k) + k = nk\), which is half the number of vertices in the new graph.
Conversely, if the new graph has a halfclique, then it must include at least \((nk)  (n2k) = k\) vertices of the graph \(G\), implying that \(G\) has a clique of size ........
These steps complete a reduction of CLIQUE to HALFCLIQUE. It is evidently performable in polynomial time, since the number of new vertices and edges is at most the square of the original number of vertices, and the rules for adding vertices and edges are simple to carry out.
Q10¶
Showing that P is closed under union, concatenation and complementation
Show that the class P is closed under:
 Union.
 Concatenation.
 Complementation.
Test for membership in one language and then, if the input is not in the first, test for membership in the second.
The time taken is no more than the ....... of the times taken to recognize each language.
Since both are in ........, then each can be recognized in ........ time, and the sum of polynomials is a polynomial.
Thus, their union is in P.
Let \(L_1\) and \(L_2\) be languages in P, and suppose we want to recognize their concatenation.
The idea is to try all the possible ways in which we can split the string into a concatenation of 2 strings from the given languages.
The running time of this test is at most \(n\) times the sum of the running times of the recognizers for \(L_1\) and \(L_2\).
Since the latter are both polynomials, so is the running time for the TM just described.
Given a polynomialtime TM \(M\) for \(L\), we construct a TM \(M'\) that decides \(\overline L\) (the complement of \(L\)) as follows:
 On input \(w\):
 Run \(M\) on \(w\).
 If \(M\) accepts, ........; if \(M\) rejects, ........
Since \(M'\) does the opposite of whatever \(M\) does then it decides \(\overline L\).
Furthermore, \(M'\) also runs in polynomial time because it only needs one extra step after \(M\) .........
(Alternative approach: Simply swap the accept and reject state. The running time of the modified machine does not change. )