Npcompleteness
Npcompleteness
Lecture in INF4130
Department of Informatics
Definition (NP-completeness)
A language L is NP-complete if the two following hold for L:
1 L ∈ NP
2 for any language A in NP, A ≤P L.
If L merely fulfills property (2), we call it NP-hard.
Theorem
If A is NP-complete and A ∈ P, then P = NP.
Theorem
If A is NP-complete and A ∈ P, then P = NP.
The theorem serves as an indication that NP-complete problems probably cannot be solved in
polynomial time. It also partly explains why we are interested in proving that problems are
NP-complete.
Theorem
If A is NP-complete and A ∈ P, then P = NP.
The theorem serves as an indication that NP-complete problems probably cannot be solved in
polynomial time. It also partly explains why we are interested in proving that problems are
NP-complete.
Theorem
If A is NP-complete and A ≤P B and B ∈ NP then B is NP-complete.
Theorem
If A is NP-complete and A ∈ P, then P = NP.
The theorem serves as an indication that NP-complete problems probably cannot be solved in
polynomial time. It also partly explains why we are interested in proving that problems are
NP-complete.
Theorem
If A is NP-complete and A ≤P B and B ∈ NP then B is NP-complete.
Proof
We already know that B ∈ NP. We need to show that all languages in NP can be reduced to
B. Since we know that any language in NP can be reduced to A, and that A can be reduced to
B, we can reduce any language in NP to B. Here we use the fact that polynomial reductions
can be composed to create new polynomial reductions.
The ”first” NP-complete problem
C1 ∧ C2 ∧ · · · ∧ Ck .
The ”first” NP-complete problem
C1 ∧ C2 ∧ · · · ∧ Ck .
Each clause consists of several literals joined by disjunctions (∨). Literals are Boolean variables
or negated Boolean variables (x or x). An example of a formula on CNF could be:
φ = (x ∨ x) ∧ (x ∨ y ) ∧ (y ∨ z ∨ z).
The ”first” NP-complete problem
C1 ∧ C2 ∧ · · · ∧ Ck .
Each clause consists of several literals joined by disjunctions (∨). Literals are Boolean variables
or negated Boolean variables (x or x). An example of a formula on CNF could be:
φ = (x ∨ x) ∧ (x ∨ y ) ∧ (y ∨ z ∨ z).
CNFSAT = {hφi | φ is a satisfiable Boolean formula, on CNF}.
The ”first” NP-complete problem II
Theorem (Cook-Levin)
SAT is NP-complete.
The ”first” NP-complete problem II
Theorem (Cook-Levin)
SAT is NP-complete.
We will not go through the proof, but we will try to get a grip on the fundamental parts.
Proof overview
• Show that SAT ∈ NP (last lecture)
• Create a universal reduction from A ∈ NP to SAT
• The reduction takes an input of A, let us call it w , and produces a formula φ
• Since A ∈ NP, there exists a NTM MA deciding A in time nk for some constant k
• Create a formula φ such that φ is satisfiable if and only if MA has an accepting branch in its
computation on input w
The ”first” NP-complete problem III
(CNF)SAT
3SAT
Map of NP-complete problems
(CNF)SAT
3SAT
CLIQUE
SUBGRAPH-
ISOMORPHISM
Map of NP-complete problems
(CNF)SAT
3SAT
SUBGRAPH-
PARTITION
ISOMORPHISM
Map of NP-complete problems
(CNF)SAT
3SAT
SUBGRAPH-
PARTITION
ISOMORPHISM
Map of NP-complete problems
(CNF)SAT
3SAT
SUBGRAPH-
PARTITION
ISOMORPHISM
Actually, since all problems in NP can be (poly-time) reduced to any NP-complete problem,
and all NP-complete problems are in NP, all NP-complete problems can be reduced to each
other in polynomial time.
We say that a Boolean formula is on 3CNF if it is on CNF and each clause has three literals.
Let 3SAT = {hφi | φ is a satisfiable Boolean formula, on 3CNF}.
We say that a Boolean formula is on 3CNF if it is on CNF and each clause has three literals.
Let 3SAT = {hφi | φ is a satisfiable Boolean formula, on 3CNF}.
Theorem
3SAT is NP-complete.
We say that a Boolean formula is on 3CNF if it is on CNF and each clause has three literals.
Let 3SAT = {hφi | φ is a satisfiable Boolean formula, on 3CNF}.
Theorem
3SAT is NP-complete.
Theorem
CLIQUE is NP-complete.
Recall the problem CLIQUE from last lecture:
CLIQUE = {hG , ki | G is an undirected graph with a clique of size k}
Theorem
CLIQUE is NP-complete.
Theorem
SUBGRAPH–ISOMORPHISM is NP-complete.
Let G and H be two graphs. We say that G is isomorphic to H if there exists a bijection f
from the set of nodes in G to the set of nodes in H, such that u and v are neighbors in G if
and only if f (u) and f (v ) are neighbors in H.
Let SUBGRAPH–ISOMORPHISM = {hG1 , G2 i | G1 is isomorphic to a subgraph of G2 }.
Theorem
SUBGRAPH–ISOMORPHISM is NP-complete.
Proof
To show that the problem is in NP, we claim that a bijection from G1 to a subgraph of G2 is a
suitable polynomial certificate. Our verifier could then check the neighbors and confirm that G1
is isomorphic to a subgraph of G2 .
Let G and H be two graphs. We say that G is isomorphic to H if there exists a bijection f
from the set of nodes in G to the set of nodes in H, such that u and v are neighbors in G if
and only if f (u) and f (v ) are neighbors in H.
Let SUBGRAPH–ISOMORPHISM = {hG1 , G2 i | G1 is isomorphic to a subgraph of G2 }.
Theorem
SUBGRAPH–ISOMORPHISM is NP-complete.
Proof
To show that the problem is in NP, we claim that a bijection from G1 to a subgraph of G2 is a
suitable polynomial certificate. Our verifier could then check the neighbors and confirm that G1
is isomorphic to a subgraph of G2 .
To show that SUBGRAPH–ISOMORPHISM is NP-hard, we will show that
CLIQUE ≤P SUBGRAPH–ISOMORPHISM. The reduction will take a string hG , ki as input
and it will produce hG1 , G2 i such that G1 is isomorphic to a subgraph of G2 iff G contains a
k-clique. We let G1 be a k-clique and G2 = G . The correctness is trivial. Furthermore, the
reduction runs in polynomial time; it copies G (linear) and creates a k-clique (can be done in
quadratic time with respect to k).
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
Proof
Show MY –PROB ∈ NP. This is typically the easiest part of the proof. Try to think of a certificate that w has
property R. Remember that a verifier only has polynomial time, so it cannot hope to read exponential
certificates.
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
Proof
Show MY –PROB ∈ NP. This is typically the easiest part of the proof. Try to think of a certificate that w has
property R. Remember that a verifier only has polynomial time, so it cannot hope to read exponential
certificates.
Now we show that MY –PROB is NP-hard. To do this, it is sufficient to prove that a known NP-complete
problem can be reduced to MY –PROB. Pick the the NP-complete problem A, that resembles MY –PROB the
most. This often makes the reduction simpler. Then, we need to show that A ≤P MY –PROB. To do this, we
create a polynomial time reduction, mapping wA (instances of A) to w (instances of MY –PROB) such that wA
has property RA if and only if w has property R. This is the part of the proof that may involve some ingenuity
on our side. Try to understand how the two problems can be related.
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
Proof
Show MY –PROB ∈ NP. This is typically the easiest part of the proof. Try to think of a certificate that w has
property R. Remember that a verifier only has polynomial time, so it cannot hope to read exponential
certificates.
Now we show that MY –PROB is NP-hard. To do this, it is sufficient to prove that a known NP-complete
problem can be reduced to MY –PROB. Pick the the NP-complete problem A, that resembles MY –PROB the
most. This often makes the reduction simpler. Then, we need to show that A ≤P MY –PROB. To do this, we
create a polynomial time reduction, mapping wA (instances of A) to w (instances of MY –PROB) such that wA
has property RA if and only if w has property R. This is the part of the proof that may involve some ingenuity
on our side. Try to understand how the two problems can be related.
After explaining how the reduction works, we will typically argue that it is correct. First assume wA ∈ A and
show that w ∈ MY –PROB. Then, either assume w ∈ MY –PROB and show that wA ∈ A, or assume wA ∈ /A
and show that w ∈ / MY –PROB.
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
Proof
Show MY –PROB ∈ NP. This is typically the easiest part of the proof. Try to think of a certificate that w has
property R. Remember that a verifier only has polynomial time, so it cannot hope to read exponential
certificates.
Now we show that MY –PROB is NP-hard. To do this, it is sufficient to prove that a known NP-complete
problem can be reduced to MY –PROB. Pick the the NP-complete problem A, that resembles MY –PROB the
most. This often makes the reduction simpler. Then, we need to show that A ≤P MY –PROB. To do this, we
create a polynomial time reduction, mapping wA (instances of A) to w (instances of MY –PROB) such that wA
has property RA if and only if w has property R. This is the part of the proof that may involve some ingenuity
on our side. Try to understand how the two problems can be related.
After explaining how the reduction works, we will typically argue that it is correct. First assume wA ∈ A and
show that w ∈ MY –PROB. Then, either assume w ∈ MY –PROB and show that wA ∈ A, or assume wA ∈ /A
and show that w ∈ / MY –PROB.
Finally we explain that the reduction can be carried out in polynomial time with respect to wA . How hard this
is, will depend on the reduction. Often, just a few lines is sufficient.
A template for proving NP-completeness
Let MY –PROB = { w | w has some property R}. Prove that MY –PROB is NP-complete.
Proof
Show MY –PROB ∈ NP. This is typically the easiest part of the proof. Try to think of a certificate that w has
property R. Remember that a verifier only has polynomial time, so it cannot hope to read exponential
certificates.
Now we show that MY –PROB is NP-hard. To do this, it is sufficient to prove that a known NP-complete
problem can be reduced to MY –PROB. Pick the the NP-complete problem A, that resembles MY –PROB the
most. This often makes the reduction simpler. Then, we need to show that A ≤P MY –PROB. To do this, we
create a polynomial time reduction, mapping wA (instances of A) to w (instances of MY –PROB) such that wA
has property RA if and only if w has property R. This is the part of the proof that may involve some ingenuity
on our side. Try to understand how the two problems can be related.
After explaining how the reduction works, we will typically argue that it is correct. First assume wA ∈ A and
show that w ∈ MY –PROB. Then, either assume w ∈ MY –PROB and show that wA ∈ A, or assume wA ∈ /A
and show that w ∈ / MY –PROB.
Finally we explain that the reduction can be carried out in polynomial time with respect to wA . How hard this
is, will depend on the reduction. Often, just a few lines is sufficient.
We end the proof by explaining that we have showed both that MY –PROB ∈ NP and that MY –PROB is
NP-hard, so therefore MY –PROB is NP-complete.
Let SUBSET –SUM = {hS, ti | S is a multiset of natural numbers, such that there exists a
subset of S summing to t}. SUBSET –SUM can be shown NP-complete by a reduction from
3SAT .
Let SUBSET –SUM = {hS, ti | S is a multiset of natural numbers, such that there exists a
subset of S summing to t}. SUBSET –SUM can be shown NP-complete by a reduction from
3SAT .
Let PARTITION = {hSi | S is a multiset of natural numbers, such that there exists a subset
S 0 of S that sums to exactly half the sum of S}.
Theorem
PARTITION is NP-complete.
Let SUBSET –SUM = {hS, ti | S is a multiset of natural numbers, such that there exists a
subset of S summing to t}. SUBSET –SUM can be shown NP-complete by a reduction from
3SAT .
Let PARTITION = {hSi | S is a multiset of natural numbers, such that there exists a subset
S 0 of S that sums to exactly half the sum of S}.
Theorem
PARTITION is NP-complete.
Theorem
PARTITION is NP-complete.