0% found this document useful (0 votes)
23 views59 pages

Npcompleteness

This document discusses NP-completeness and proves that several problems are NP-complete, including SAT, 3SAT, subset sum, and others. It defines NP-completeness, shows that SAT is the first NP-complete problem by reducing any problem in NP to SAT, and proves other problems like 3SAT are NP-complete by reducing SAT to them.

Uploaded by

haninebay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views59 pages

Npcompleteness

This document discusses NP-completeness and proves that several problems are NP-complete, including SAT, 3SAT, subset sum, and others. It defines NP-completeness, shows that SAT is the first NP-complete problem by reducing any problem in NP to SAT, and proves other problems like 3SAT are NP-complete by reducing SAT to them.

Uploaded by

haninebay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

NP-completeness

Lecture in INF4130

Department of Informatics

November 1st, 2018


Recap from Lecture 1 & 2

• Undecidability: no Turing Machine decides L


• Proving undecidability
• First, we proved that the Halting problem is undecidable
• Later, we proved more undecidability-results via reductions
Recap from Lecture 1 & 2

• Undecidability: no Turing Machine decides L


• Proving undecidability
• First, we proved that the Halting problem is undecidable
• Later, we proved more undecidability-results via reductions
• Defined running times for DTMs and NTMs
• Defined the complexity classes P and NP
• We also defined polynomial time reductions, but did not spend much time on them
• Briefly looked at the hierarchy of complexity classes
Today

• Define the notion of NP-completeness


• The NP-complete problems will be the ”hardest” problems in NP
• We will see that NP-complete problems exist, by looking at a proof showing that a
particular problem is NP-complete ”from scratch” (like we did for undecidability with
halting)
• Then we will show the NP-completeness of other problems via (polynomial time)
reductions
• We will try to build up a hierarchy of NP-complete problems
Repetition: Polynomial time reductions

Definition (Polynomial reductions)


Language A is polynomial time reducible to language B, written A ≤P B, if there exists a
polynomial time computable function f : Σ∗ → Σ∗ , where for every w :
w ∈ A ↔ f (w ) ∈ B. The function f is called the polynomial (time) reduction from A to B.
NP-completeness

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

SAT = {hφi | φ is a satisfiable Boolean formula}.


The ”first” NP-complete problem

SAT = {hφi | φ is a satisfiable Boolean formula}.


We will be working with Boolean formulas on a special form called conjunctive normal form
(CNF). A formula on CNF consists of several clauses joined by conjunctions (∧) like this:

C1 ∧ C2 ∧ · · · ∧ Ck .
The ”first” NP-complete problem

SAT = {hφi | φ is a satisfiable Boolean formula}.


We will be working with Boolean formulas on a special form called conjunctive normal form
(CNF). A formula on CNF consists of several clauses joined by conjunctions (∧) like this:

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

SAT = {hφi | φ is a satisfiable Boolean formula}.


We will be working with Boolean formulas on a special form called conjunctive normal form
(CNF). A formula on CNF consists of several clauses joined by conjunctions (∧) like this:

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

The formula will ”simulate” MA on input w . Here is a (simplified) draft of φ:


φ = Init ∧ Legal ∧ Accepting .
The ”first” NP-complete problem III

The formula will ”simulate” MA on input w . Here is a (simplified) draft of φ:


φ = Init ∧ Legal ∧ Accepting .
An essential part of the proof is to show that the reduction only takes polynomial time in the
length of w . In a complete proof we would have to carefully analyze each step of creating φ.
Furthermore, it is possible to create φ to be on CNF, which actually proves that CNFSAT is
NP-complete. This will come in handy later.
Map of NP-complete problems

(CNF)SAT

3SAT
Map of NP-complete problems

(CNF)SAT

3SAT

CLIQUE

SUBGRAPH-
ISOMORPHISM
Map of NP-complete problems

(CNF)SAT

3SAT

SUBSET-SUM HAMPATH CLIQUE

SUBGRAPH-
PARTITION
ISOMORPHISM
Map of NP-complete problems

(CNF)SAT

3SAT

3DM SUBSET-SUM HAMPATH CLIQUE

SUBGRAPH-
PARTITION
ISOMORPHISM
Map of NP-complete problems

(CNF)SAT

3SAT

3DM SUBSET-SUM HAMPATH CLIQUE

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.

Proof that 3SAT is NP-complete: Part I


First we need to show that 3SAT is in NP. Here we can still use a satisfying assignment as our
certificate.
To show that all problems in NP can be polynomial time reduced to 3SAT it is enough to
show that CNFSAT ≤P 3SAT . Such a reduction will take a formula φ on CNF and output a
formula ψ on 3CNF, such that φ is satisfiable if and only if ψ is satisfiable. We show how to do
this on the next slide.
Proof that 3SAT is NP-complete: Part II
For each clause of φ, we replace it with corresponding clauses having exactly 3 literals. If a
clause has one or two literals in φ, we pad these clauses with repeated literals so that we end
up with three literals.
Proof that 3SAT is NP-complete: Part II
For each clause of φ, we replace it with corresponding clauses having exactly 3 literals. If a
clause has one or two literals in φ, we pad these clauses with repeated literals so that we end
up with three literals. For example
(x1 ∨ x2 )
is transformed into
(x1 ∨ x2 ∨ x1 ).
Proof that 3SAT is NP-complete: Part II
For each clause of φ, we replace it with corresponding clauses having exactly 3 literals. If a
clause has one or two literals in φ, we pad these clauses with repeated literals so that we end
up with three literals. For example
(x1 ∨ x2 )
is transformed into
(x1 ∨ x2 ∨ x1 ).
If a clause has more than three literals, we split it up into several new clauses and link them
together with new literals. For example
(x1 ∨ x2 ∨ x3 ∨ x4 ∨ x5 )
is replaced by the clauses
(x1 ∨ x2 ∨ z1 ), (z1 ∨ x3 ∨ z2 ), (z2 ∨ x4 ∨ x5 ).
Proof that 3SAT is NP-complete: Part II
For each clause of φ, we replace it with corresponding clauses having exactly 3 literals. If a
clause has one or two literals in φ, we pad these clauses with repeated literals so that we end
up with three literals. For example
(x1 ∨ x2 )
is transformed into
(x1 ∨ x2 ∨ x1 ).
If a clause has more than three literals, we split it up into several new clauses and link them
together with new literals. For example
(x1 ∨ x2 ∨ x3 ∨ x4 ∨ x5 )
is replaced by the clauses
(x1 ∨ x2 ∨ z1 ), (z1 ∨ x3 ∨ z2 ), (z2 ∨ x4 ∨ x5 ).
Here the zi are fresh variables not mentioned in φ and they work as ”logical glue” in the
reduction. Finally our reduction outputs ψ, the conjunction of our new clauses. It has
polynomial size compared to φ, and preserves satisfiability. Since this reduction shows that
CNFSAT ≤P 3SAT we have proven that 3SAT is NP-complete.
Recall the problem CLIQUE from last lecture:
CLIQUE = {hG , ki | G is an undirected graph with a clique of size k}
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.
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.

Proof that CLIQUE is NP-complete: Part I


Last lecture we discussed possible polynomial certificates for CLIQUE , so we conclude that
CLIQUE ∈ NP. To show that CLIQUE is NP-hard, we show that 3SAT ≤P CLIQUE . The
reduction f takes a formula φ = C1 ∧ C2 ∧ · · · ∧ Ck on 3CNF, and generates the string hG , ki,
such that φ is satisfiable iff G has a clique of size k. We will show that f works correctly, and
that it is computable in polynomial time.
Proof that CLIQUE is NP-complete: Part II
The graph G will consist of k groups of three nodes called triples. Each triple will correspond
to a clause in φ and each node in a triple will correspond to a literal in the corresponding
clause of φ. We can label the nodes with its corresponding literal in φ.
Proof that CLIQUE is NP-complete: Part II
The graph G will consist of k groups of three nodes called triples. Each triple will correspond
to a clause in φ and each node in a triple will correspond to a literal in the corresponding
clause of φ. We can label the nodes with its corresponding literal in φ. Then we connect all
pairs of nodes except:
1 pairs of nodes that are in the same triple
2 pairs of nodes where one is labeled x and the other x for some variable x.
Proof that CLIQUE is NP-complete: Part II
The graph G will consist of k groups of three nodes called triples. Each triple will correspond
to a clause in φ and each node in a triple will correspond to a literal in the corresponding
clause of φ. We can label the nodes with its corresponding literal in φ. Then we connect all
pairs of nodes except:
1 pairs of nodes that are in the same triple
2 pairs of nodes where one is labeled x and the other x for some variable x.
Now we claim that G has a clique of size k if and only if φ can be satisfied.
Proof that CLIQUE is NP-complete: Part II
The graph G will consist of k groups of three nodes called triples. Each triple will correspond
to a clause in φ and each node in a triple will correspond to a literal in the corresponding
clause of φ. We can label the nodes with its corresponding literal in φ. Then we connect all
pairs of nodes except:
1 pairs of nodes that are in the same triple
2 pairs of nodes where one is labeled x and the other x for some variable x.
Now we claim that G has a clique of size k if and only if φ can be satisfied.
If G has a k-clique, then since no two nodes in a triple is connected, the clique must contain
exactly one node from each of the k triples. We assign truth values to the variables by making
the literals of the nodes in the clique true. This is always possible since no contradictory nodes
are not connected. For example, if x is the label of a node in the clique, then no node labeled
x can be in the clique, so it is ”safe” to set x to false. Assigning the variables like described
will satisfy φ since one literal in each clause is true. Thus, in this case φ is satisfiable.
Proof that CLIQUE is NP-complete: Part III
Assume φ is satisfiable. Then there exists an assignment making at least on literal true in each
clause. We form a k-clique in G by selecting a node corresponding to a true literal from each
triple. Since there are k triples in G the size of the clique is k. Furthermore, all the nodes will
have an edge between them since they are from different triples and two nodes representing
contradictory literals could have been selected.
Proof that CLIQUE is NP-complete: Part III
Assume φ is satisfiable. Then there exists an assignment making at least on literal true in each
clause. We form a k-clique in G by selecting a node corresponding to a true literal from each
triple. Since there are k triples in G the size of the clique is k. Furthermore, all the nodes will
have an edge between them since they are from different triples and two nodes representing
contradictory literals could have been selected.
Finally, we claim that the reduction runs in polynomial time, since the number of nodes in G
equals the number of literals in φ (linear), and the number of edges is no more than n2
(quadratic).
Proof that CLIQUE is NP-complete: Part III
Assume φ is satisfiable. Then there exists an assignment making at least on literal true in each
clause. We form a k-clique in G by selecting a node corresponding to a true literal from each
triple. Since there are k triples in G the size of the clique is k. Furthermore, all the nodes will
have an edge between them since they are from different triples and two nodes representing
contradictory literals could have been selected.
Finally, we claim that the reduction runs in polynomial time, since the number of nodes in G
equals the number of literals in φ (linear), and the number of edges is no more than n2
(quadratic).
Since we have shown both that 3SAT ≤P CLIQUE and CLIQUE ∈ NP, we have proven the
theorem.
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 }.
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.
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.

Proof that PARTITION is NP-complete: Part I


To show that PARTITION ∈ NP, we need to find short certificates for yes-instances of
PARTITION. Such a certificate could be a subset of S summing to half the sum of S.
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.

Proof that PARTITION is NP-complete: Part I


To show that PARTITION ∈ NP, we need to find short certificates for yes-instances of
PARTITION. Such a certificate could be a subset of S summing to half the sum of S.
We will show that SUBSET –SUM ≤P PARTITION. The reduction is given hS, ti , where
ΣS = k. If t > k, we already know that we are dealing with a no-instance, so we return the set
{1}, which we know is a no-instance of PARTITION. We then construct the set S 0 to be
S ∪ {N1 , N2 }, where N1 = 2k − t and N2 = k + t. The sum of S 0 is k + 2k − t + k + t = 4k.
Since N1 + N2 is more than half the sum of S 0 they must end up in different subsets in a
correct partition of S 0 .
Proof that PARTITION is NP-complete: Part II
Assume hS, ti ∈ SUBSET –SUM. Then there exists a subset of S, let us call it S1 , summing
to t. This implies that S \ S1 has a sum of k − t. Then, hS 0 i ∈ PARTITION since {N1 } ∪ S1
has a sum of 2k which is the same as the sum of {N2 } ∪ (S \ S1 ).
Proof that PARTITION is NP-complete: Part II
Assume hS, ti ∈ SUBSET –SUM. Then there exists a subset of S, let us call it S1 , summing
to t. This implies that S \ S1 has a sum of k − t. Then, hS 0 i ∈ PARTITION since {N1 } ∪ S1
has a sum of 2k which is the same as the sum of {N2 } ∪ (S \ S1 ).
Assume hS 0 i ∈ PARTITION. Then, since we know that N1 and N2 has to be in different
subsets, hS, ti ∈ SUBSET –SUM.
Proof that PARTITION is NP-complete: Part II
Assume hS, ti ∈ SUBSET –SUM. Then there exists a subset of S, let us call it S1 , summing
to t. This implies that S \ S1 has a sum of k − t. Then, hS 0 i ∈ PARTITION since {N1 } ∪ S1
has a sum of 2k which is the same as the sum of {N2 } ∪ (S \ S1 ).
Assume hS 0 i ∈ PARTITION. Then, since we know that N1 and N2 has to be in different
subsets, hS, ti ∈ SUBSET –SUM.
The reduction is computable in polynomial time, since we added only two elements to S, which
both are at most twice the size of the sum of S. Furthermore, computing k can be done in
polynomial time.
Proof that PARTITION is NP-complete: Part II
Assume hS, ti ∈ SUBSET –SUM. Then there exists a subset of S, let us call it S1 , summing
to t. This implies that S \ S1 has a sum of k − t. Then, hS 0 i ∈ PARTITION since {N1 } ∪ S1
has a sum of 2k which is the same as the sum of {N2 } ∪ (S \ S1 ).
Assume hS 0 i ∈ PARTITION. Then, since we know that N1 and N2 has to be in different
subsets, hS, ti ∈ SUBSET –SUM.
The reduction is computable in polynomial time, since we added only two elements to S, which
both are at most twice the size of the sum of S. Furthermore, computing k can be done in
polynomial time.
We conclude that PARTITION is NP-complete.

You might also like