# ORF523: P vs. NP, NP-completeness

We are now going to restrict our attention to Boolean functions ${f : \{0,1\}^* \rightarrow \{0,1\}}$. Computing a Boolean function is called a decision problem, since we need to decide for ${x \in \{0,1\}^*}$ whether or not it is in the set ${L = \{x \in \{0,1\}^* : f(x)=1\}}$. We call such a set ${L}$language.

Note that while for optimization it is more natural to consider functions with values in ${\{0,1\}^*}$ (since one needs to write down the solution of the optimization problem), if one is interested in proving hardness results it is fine to restrict to Boolean functions since one can always consider decision problems of the form ‘does the optimal solution achieve an objective value larger than ${t}$‘, for some ${t>0}$ fixed beforehand. If the latter decision problem is hard, then clearly the corresponding optimization problem is hard.

We define now the class ${\mathbf{P}}$ as the set of languages ${L}$ such that there exists a Turing Machine that computes ${L}$ in polynomial time. One often says that the class ${\mathbf{P}}$ consists of ‘easy’ decision problems.

Next we define the class ${\mathbf{NP}}$ as the set of languages ${L}$ such that there exists some ${c > 0}$, and a polynomial-time Turing Machine ${M}$ with the following property:

$\displaystyle x \in L \Leftrightarrow \exists u \in \{0,1\}^{|x|^{c}} : M(x, u) = 1 .$

In words if ${L \in \mathbf{NP}}$, then for any ${x \in L}$, there exists a ‘small’ certificate ${u}$ such that if provided to the Turing Machine then it can decide in polynomial time the language ${L}$. Thus the class ${\mathbf{NP}}$ consists of decision problems for which one can easily convince someone else that a candidate ${x}$ is indeed a solution to the decision problem (that is whether or not ${x}$ is in ${L}$).

The million dollars question asks whether ${\mathbf{P} = \mathbf{NP}}$. It is widely believe that this is not the case, but nobody has been able to prove it. Informally for problems in ${\mathbf{NP}}$ one simply needs to be able to verify a solution (the certificate), while in ${\mathbf{P}}$ one needs to find the solution. In some sense the question ${\mathbf{P} = \mathbf{NP}}$ is really about the problem of creativity, and whether or not creativity ‘truly’ exists.

NP-completness

We define now a concept of hardness related to the class ${\mathbf{NP}}$. A language ${L}$ is ${\mathbf{NP}}$-hard if for every language ${L' \in \mathbf{NP}}$ there exists a polynomial-time computable function ${f : \{0,1\}^* \rightarrow \{0,1\}^*}$ such that for any ${x \in \{0,1\}^*}$, ${x \in L'}$ if and only if ${f(x) \in L}$. We call the function ${f}$ a polynomial-time reduction of ${L'}$ to ${L}$. Intuitively a decision problem is ${\mathbf{NP}}$-hard if it at least as hard as any other decision problem in ${\mathbf{NP}}$.

The notion of ${\mathbf{NP}}$-hardness can be viewed as a lower bound conditioned on the fact that ${\mathbf{P} \neq \mathbf{NP}}$. Indeed, if ${\mathbf{P} \neq \mathbf{NP}}$, then ${\mathbf{NP}}$-hard decision problems cannot be decided in polynomial time.

If a language ${L}$ is ${\mathbf{NP}}$-hard, and if ${L \in \mathbf{NP}}$, then one says that ${L}$ is ${\mathbf{NP}}$-complete. It is not obvious at first sight that any such language exist. Indeed for a language to be ${\mathbf{NP}}$-complete it means that it is in ${\mathbf{NP}}$, and that it is as hard as any other language in ${\mathbf{NP}}$. In the next section we will see our first example of an ${\mathbf{NP}}$-complete language.

Boolean formulas and the satisfiability problem

Let ${z_1, \hdots, z_n}$ be Boolean variables. A Boolean formula over these variables consists of the variables and the logical operations AND (${\wedge}$), OR (${\vee}$), and NOT (${\neg}$). A Boolean formula ${\phi}$ is satisfiable if there exists an assignment ${x \in \{0,1\}^n}$ to the Boolean variables (that is ${z_i}$ is assigned TRUE if ${x_i=1}$, and FALSE if ${x_i=0}$) such that the corresponding value of the formula ${\phi(x)}$ is TRUE. We define the language ${\mathrm{SAT}}$ as the set of all satisfiable Boolean formulae.

Theorem (Cook-Levin 1971) ${\mathrm{SAT}}$ is ${\mathbf{NP}}$-complete.

Proof: First it is clear that ${\mathrm{SAT} \in \mathbf{NP}}$, since it suffices to provide a truth assignment as a certificate. Now consider a language ${L \in \mathbf{NP}}$. We need to exhibit a polynomial-time algorithm that takes as input ${x \in \{0,1\}^*}$ and outputs a Boolean formula ${\phi_x}$ with the following property: ${x \in L}$ if and only if ${\phi_x}$ is satisfiable (that is we want to reduce ${L}$ to ${\mathrm{SAT}}$). Let ${M}$ be the Turing Machine that proves that ${L \in \mathbf{NP}}$ (with certificate of size ${c(n)}$ and running time ${t(n)}$, both being polynomial). The idea of the proof is that ${\phi_x}$ is a Boolean formula that encodes the run of the Turing Machine on the input ${x}$ and ‘some’ certificate (the certificate being encode as part of the Boolean variables). Let us describe now how to construct the above Boolean formula. We will use the notation:

$\displaystyle x \rightarrow y := \neg x \vee y .$

First we describe the Boolean variables involved: ${T_{i,\sigma,k}}$ (which intuitively encodes the fact that the symbol ${\sigma}$ is on the tape at location ${i}$ during the ${k^{th}}$ step of computation), ${Q_{q,k}}$ (which encodes the fact that the state of the Machine is ${q}$ during the ${k^{th}}$ step of computation), and ${H_{i,k}}$ (which encodes the fact that the head is at location ${i}$ during the ${k^{th}}$ step of computation). Note that we can restrict to ${i, k \leq t(n)}$ so that we have a polynomial number of variables.

The first ‘part’ of the formula ${\phi_x}$ describes the start configuration of ${M}$ on an input where the first portion is given by ${x=(x_1, \hdots, x_n)}$, that is

$\displaystyle Q_{\mathrm{START}, 1} \wedge H_{1, 1} \wedge T_{1, x_1, 1} \wedge T_{2, x_2, 1} \wedge \hdots \wedge T_{n, x_n, 1} .$

Note in particular that the initial symbols on the tape at location ${i=n+1, \hdots, n+c(n)}$ are left free, which is the critical idea since then they can model any possible certificate. The next parts of the formula will model the computation steps, which are of the form (assuming the head moves right for sake of notation)

$\displaystyle \left( H_{i,k} \wedge Q_{q,k} \wedge T_{i, \sigma, k} \right) \rightarrow \left( H_{i+1,k+1} \wedge Q_{\delta(q,\sigma)_1,k} \wedge T_{i, \delta(q,\sigma)_2, k+1} \right) ,$

with the additional constraints that there is only state (respectively one head position and one symbol per location) at each time

$\displaystyle \left( Q_{q,k} \rightarrow \wedge_{q' \neq q} \ \neg {Q}_{q',k} \right) \wedge \left( H_{i,k} \rightarrow \wedge_{i' \neq i} \ \neg {H}_{i',k} \right) \wedge \left( T_{i,\sigma, k} \rightarrow \wedge_{\sigma' \neq \sigma} \ \neg {T}_{i,\sigma',k} \right),$

as well as the fact that a symbol can change only if the head is at the corresponding location (${\sigma \neq \sigma'}$ in the following formula)

$\displaystyle \left( T_{i, \sigma, k} \wedge T_{i, \sigma', k+1} \right) \rightarrow H_{i,k} .$

Taking the AND of the above formulae over all ${q, i, k, \sigma}$ and ${\sigma' \neq \sigma}$, and the AND with the formula that encodes the fact that when the Machine halts its output is ${1}$, one obtains the formula ${\phi_x}$ which is indeed polynomial-time computable. Clearly if ${x \in L}$ then there exists a satisfying assignment that satisfies ${\phi_x}$ (assigning the variables ${T_{i, \sigma, 1}, i=n+1, \hdots, n+c(n)}$ to the value of a valid certificate, and the rest of the variables to what would happen during the computation of the Turing Machine ${M}$ with this certificate), and the converse is also clearly true. $\Box$

More NP-complete problems

By now thousands of problems are known to be ${\mathbf{NP}}$-complete. Here I just want to give a list of a few interesting examples. Many of these examples are languages over pairs ${(G,k)}$ where ${G = (V,E)}$ is a graph and ${k}$ is an integer. The language is then usually the set of such pairs such that in ${G}$ there exists a subgraph with at least ${k}$ vertices and with a certain prespecified structure.

${\mathrm{3SAT}}$

A litteral is a Boolean variable ${z_i}$ or its negation ${\neg {z_i}}$, a clause is an OR of litterals (such as ${z_1 \vee \neg {z}_2 \vee z_5}$), and a CNF is a Boolean formula which is an AND of clauses. A ${k}$CNF is a CNF formula in which all clauses contain at most ${k}$ literals. We denote by ${\mathrm{kSAT}}$ the language of all satisfiable ${k}$CNF formulae. One can show that ${\mathrm{3SAT}}$ is ${\mathbf{NP}}$-complete (by reducing ${\mathrm{SAT}}$ to ${\mathrm{3SAT}}$). One can also show that ${\mathrm{2SAT} \in \mathbf{P}}$. The latter statement is easy to understand: a clause with ${2}$ variables is a statement of the form ${a \rightarrow b}$, thus a ${2}$CNF can be represented as a graph of implications (over the Boolean variables and their negation). Verifying the statisfiability of the formula is then equivalent to searching for paths from a variable to its negation.

${\mathrm{INDSET}}$

Does a given graph contain a subgraph of size at least ${k}$ with no edges between them (such a subgraph is called an independent set)? This ‘question’ (i.e., the corresponding language over pairs of graph and integers) is ${\mathbf{NP}}$-complete.

Let us see how to prove this claim. First it is clear that ${\mathrm{INDSET} \in \mathbf{NP}}$. Thus it suffices now to show how to reduce (in polynomial time) any instance of ${\mathrm{3SAT}}$ to an instance of ${\mathrm{INDSET}}$. Specifically, we show how to map a ${m}$-clause 3CNF ${\phi}$ to a graph ${G}$ with ${7m}$ vertices and such that ${\phi}$ is satisfiable if and only if ${G}$ contains an independent set of size at least ${m}$. The idea is very simple: first for any clause ${C}$ in ${\phi}$ one associates a cluster of ${7}$ vertices in ${G}$ such that each vertex in this cluster corresponds to one of the possible satisfying assignment to the three variables involved in ${C}$ (we repeat one of the assignment in case the clause ${C}$ involves only one or two variables). Then one put an edge between any two vertices in the same cluster, and also an edge between any two vertices that correspond to two inconsistent assignment to the Boolean variables. A minute of thinking shows that clearly this graph has the property we were looking for, and clearly one can construct it in polynomial time.

${\mathrm{CLIQUE}, \mathrm{VERTEXCOVER}, \mathrm{CUT}}$

The following ‘questions’ can be shown to be ${\mathbf{NP}}$-complete via a reduction to ${\mathrm{INDSET}}$:

• Does a graph contain a clique (a subgraph where any two distinct vertices is connected) of size at least ${k}$?
• Does a graph contain a vertex cover (a subset of vertices ${S}$ such that any edge in the graph always have one endpoint ${S}$) of size at most ${k}$?
• Does a graph contain a cut of weight at least ${k}$ (i.e. a subset of vertices ${S}$ such that there is at least ${k}$ edges with one endpoint in ${S}$ and one endpoint in ${S^c}$)?

${\mathrm{PARTITION}}$

The following problem is interesting because it looks extremely simple, yet it is ${\mathbf{NP}}$-complete. Given ${n}$ integers ${a_1, \hdots, a_n}$, does there exist ${S \subset \{1, \hdots, n\}}$ such that ${\sum_{i \in S} a_i = \sum_{i \in S^c} a_i}$?

This entry was posted in Theoretical Computer Science. Bookmark the permalink.