A language \(B\) is called NP-hard if for every language \(A \in \NP\), \(A \le^P B\).
A language \(B\) is called NP-complete if:
Theorem: If \(B\) is NP-complete and if \(B \in \P\) then \(\P = \NP\).
Proof:
A language \(B\) is called NP-hard if for every language \(A \in \NP\), \(A \le^P B\).
A language \(B\) is called NP-complete if:
Theorem: If \(B\) is NP-complete and if \(B \in \P\) then \(\P = \NP\).
Corollary: If \(\P \ne \NP\) then no NP-complete problem is in \(\P\).
This is the significance of NP-completeness:
if you show your problem is NP-hard, then there is (probably) no efficient algorithm for it.
We can chain reductions together!
Observation: \(\le^P\) is transitive
(if \(A \le^P B\) and \(B \le^P C\), then \(A \le^P C\))
def reduce_A_to_B(x):
"""
reduction from NP prob
A to NP-hard prob B
"""
raise NotImplementedError()
def reduce_B_to_C(x):
"""
reduction from B
to NP-hard prob C
"""
raise NotImplementedError()
def C_decider(x):
"""
hypothetical polynomial-time
decider
"""
raise NotImplementedError()
def A_decider(x):
"""
polynomial time
"""
y = reduce_A_to_B(x)
z = reduce_B_to_C(y)
return C_decider(z)
\(A\) will be a stand-in for any problem in \(\NP\).
Theorem: If \(B\) is \(\NP\)-hard and \(B \le^P C\) for some language \(C\),
then \(C\) is also \(\NP\)-hard.
Proof:
Corollary: If \(B\) is \(\NP\)-complete, \(B \le^P C\),
and \(C \in \NP\), then \(C\) is \(\NP\)-complete.
Finding a reduction from any known-NP-hard problem \(B\) to \(C\) proves that all problems in \(\NP\) are reducible to \(C\)! (\(C\) is NP-hard too.)
Cook-Levin Theorem: \(\probSAT\) and \(\probThreeSAT\) are NP-complete.
Theorem: \(\probIndSet\) and \(\probClique\) are NP-complete.
Proof:
\(\probSubsetSum = \setbuild{\encoding{C, t}}{ C \text{ is a multiset of integers, and } (\exists S \subseteq C) \; t = \sum_{y \in S} y}\)
\(\probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probThreeSAT \le^\P \probSubsetSum\).
Proof:
Given a 3-CNF formula \(\phi\), we must output \((C, t)\) such that: \[ \phi \text{ is satisfiable } \iff (\exists S \subseteq C) \; t = \sum_{y \in S} y \]
Suppose \(\phi\) has \(m\) variables \(x_1,\dots,x_m\) and \(l\) clauses \(c_1,\dots,c_l\).
Let \(C = \{y_1,z_1,y_2,z_2,\dots,y_m,z_m,g_1,h_1,g_2,h_2,\dots,g_l,h_l\}\) be a multiset of \(2m + 2l\) integers, and integer \(t\) defined as follows.
For example, if \(\phi = (x_1 \vee \overline{x_2} \vee x_3) \wedge (\overline{x_1} \vee x_2 \vee x_3) \wedge (x_1 \vee \overline{x_3} \vee x_4)\), here are the integers in base 10:
\[ \begin{array}{c|cccc|cccc} & x_1 & x_2 & x_3 & x_4 & c_1 & c_2 & c_3 \\ \hline y_1 & 1, & 0 & 0 & 0, & 1 & 0 & 1 \\ z_1 & 1, & 0 & 0 & 0, & 0 & 1 & 0 \\ y_2 & & 1 & 0 & 0, & 0 & 1 & 0 \\ z_2 & & 1 & 0 & 0, & 1 & 0 & 0 \\ y_3 & & & 1 & 0, & 1 & 1 & 0 \\ z_3 & & & 1 & 0, & 0 & 0 & 1 \\ y_4 & & & & 1 & 0 & 0 & 1 \\ z_4 & & & & 1 & 0 & 0 & 0 \\ \hline g_1 & & & & & 1 & 0 & 0 \\ h_1 & & & & & 1 & 0 & 0 \\ g_2 & & & & & & 1 & 0 \\ h_2 & & & & & & 1 & 0 \\ g_3 & & & & & & & 1 \\ h_3 & & & & & & & 1 \\ \hline \hline t & 1 & 1 & 1 & 1 & 3 & 3 & 3 \end{array} \]
\(\probSubsetSum = \setbuild{\encoding{C, t}}{ C \text{ is a multiset of integers, and } (\exists S \subseteq C) \; t = \sum_{y \in S} y}\)
\(\probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probThreeSAT \le^\P \probSubsetSum\).
Proof: (\(m=\) number of variables, \(l=\) number of clauses)
\(\phi = (x_1 \vee \overline{x_2} \vee x_3) \wedge (\overline{x_1} \vee x_2 \vee x_3) \wedge (x_1 \vee \overline{x_3} \vee x_4)\)
\[ \begin{array}{c|cccc|cccc} & x_1 & x_2 & x_3 & x_4 & c_1 & c_2 & c_3 \\ \hline y_1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\ z_1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \\ y_2 & & 1 & 0 & 0 & 0 & 1 & 0 \\ z_2 & & 1 & 0 & 0 & 1 & 0 & 0 \\ y_3 & & & 1 & 0 & 1 & 1 & 0 \\ z_3 & & & 1 & 0 & 0 & 0 & 1 \\ y_4 & & & & 1 & 0 & 0 & 1 \\ z_4 & & & & 1 & 0 & 0 & 0 \\ \hline g_1 & & & & & 1 & 0 & 0 \\ h_1 & & & & & 1 & 0 & 0 \\ g_2 & & & & & & 1 & 0 \\ h_2 & & & & & & 1 & 0 \\ g_3 & & & & & & & 1 \\ h_3 & & & & & & & 1 \\ \hline \hline t & 1 & 1 & 1 & 1 & 3 & 3 & 3 \end{array} \]
\(\probSubsetSum = \setbuild{\encoding{C, t}}{ C \text{ is a multiset of integers, and } (\exists S \subseteq C) \; t = \sum_{y \in S} y}\)
\(\probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probThreeSAT \le^\P \probSubsetSum\).
Proof: \((\implies)\): Suppose \(\phi\) is satisfied by \(x=x_1,\dots,x_m\).
\(\phi = (x_1 \vee \overline{x_2} \vee x_3) \wedge (\overline{x_1} \vee x_2 \vee x_3) \wedge (x_1 \vee \overline{x_3} \vee x_4)\)
\[ \begin{array}{c|cccc|cccc} & x_1 & x_2 & x_3 & x_4 & c_1 & c_2 & c_3 \\ \hline y_1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\ z_1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \\ y_2 & & 1 & 0 & 0 & 0 & 1 & 0 \\ z_2 & & 1 & 0 & 0 & 1 & 0 & 0 \\ y_3 & & & 1 & 0 & 1 & 1 & 0 \\ z_3 & & & 1 & 0 & 0 & 0 & 1 \\ y_4 & & & & 1 & 0 & 0 & 1 \\ z_4 & & & & 1 & 0 & 0 & 0 \\ \hline g_1 & & & & & 1 & 0 & 0 \\ h_1 & & & & & 1 & 0 & 0 \\ g_2 & & & & & & 1 & 0 \\ h_2 & & & & & & 1 & 0 \\ g_3 & & & & & & & 1 \\ h_3 & & & & & & & 1 \\ \hline \hline t & 1 & 1 & 1 & 1 & 3 & 3 & 3 \end{array} \]
\(\probSubsetSum = \setbuild{\encoding{C, t}}{ C \text{ is a multiset of integers, and } (\exists S \subseteq C) \; t = \sum_{y \in S} y}\)
\(\probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probThreeSAT \le^\P \probSubsetSum\).
Proof: \((\impliedby)\): Suppose \((\exists S \subseteq C)\ t=\sum_{y \in S} y\).
\(\phi = (x_1 \vee \overline{x_2} \vee x_3) \wedge (\overline{x_1} \vee x_2 \vee x_3) \wedge (x_1 \vee \overline{x_3} \vee x_4)\)
\[ \begin{array}{c|cccc|cccc} & x_1 & x_2 & x_3 & x_4 & c_1 & c_2 & c_3 \\ \hline y_1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\ z_1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 \\ y_2 & & 1 & 0 & 0 & 0 & 1 & 0 \\ z_2 & & 1 & 0 & 0 & 1 & 0 & 0 \\ y_3 & & & 1 & 0 & 1 & 1 & 0 \\ z_3 & & & 1 & 0 & 0 & 0 & 1 \\ y_4 & & & & 1 & 0 & 0 & 1 \\ z_4 & & & & 1 & 0 & 0 & 0 \\ \hline g_1 & & & & & 1 & 0 & 0 \\ h_1 & & & & & 1 & 0 & 0 \\ g_2 & & & & & & 1 & 0 \\ h_2 & & & & & & 1 & 0 \\ g_3 & & & & & & & 1 \\ h_3 & & & & & & & 1 \\ \hline \hline t & 1 & 1 & 1 & 1 & 3 & 3 & 3 \end{array} \]
\(\probSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable Boolean formula}} \quad \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probSAT \le^\P \probThreeSAT\).
Proof:
\(\probSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable Boolean formula}} \quad \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probSAT \le^\P \probThreeSAT\).
Proof:
\(\probSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable Boolean formula}} \quad \probThreeSAT = \setbuild{\encoding{\phi}}{\phi \text{ is a satisfiable 3-CNF formula}}\)
Theorem: \(\probSAT \le^\P \probThreeSAT\).
Proof: