Reducing NP-Complete Problems

NP-Completeness: Reductions
CSc 4520/6520
Fall 2013
Slides adapted from David Evans (Virgina) and Costas Busch (RPI)
Definition of NP-Complete
Q is an NP-Complete problem if:
1) Q is in NP
2) every other NP problem polynomial time is
reducible to Q
Getting Started
How do you show that EVERY NP problem
reduces to Q?
One way would be to already have an NPComplete problem and just reduce from
that
P1
P2
P3
P4
Mystery
NP-Complete
Problem
Q
3-SAT
3-SAT = { f | f is in Conjunctive Normal
Form, each clause has exactly 3 literals
and f is satisfiable }
3-SAT is NP-Complete
(2-SAT is in P)
NP-Complete
To prove a problem is NP-Complete show a
polynomial time reduction from 3-SAT
Other NP-Complete Problems:
PARTITION
SUBSET-SUM
CLIQUE
HAMILTONIAN PATH (TSP)
GRAPH COLORING
MINESWEEPER (and many more)
NP-Completeness Proof Method
To show that Q is NP-Complete:
1) Show that Q is in NP
2) Pick an instance, R, of your favorite NPComplete problem (ex: Φ in 3-SAT)
3) Show a polynomial algorithm to transform
R into an instance of Q
Example: Clique
CLIQUE = { <G,k> | G is a graph with a clique
of size k }
A clique is a subset of vertices that are all
connected
Why is CLIQUE in NP?
Reduce 3-SAT to Clique
Pick an instance of 3-SAT, Φ, with k clauses
Make a vertex for each literal
Connect each vertex to the literals in other
clauses that are not the negation
Any k-clique in this graph corresponds to a
satisfying assignment
Example: Independent Set
INDEPENDENT SET = { <G,k> | where G has
an independent set of size k }
An independent set is a set of vertices that
have no edges
How can we reduce this to clique?
Independent Set to CLIQUE
This is the dual problem!
Vertex Cover
Vertex cover of a graph
is a subset of nodes S such that every edge
in the graph touches one node in S
Example:
S = red nodes
Size of vertex-cover
is the number of nodes in the cover
Example: |S|=4
Corresponding language:
VERTEX-COVER = { G, k :
graph G contains a vertex cover
of size k }
Example:
G
G ,4  VERTEX - COVER
Theorem: VERTEX-COVER is NP-complete
Proof:
1. VERTEX-COVER is in NP
Can be easily proven
2. We will reduce in polynomial time
3CNF-SAT to VERTEX-COVER
(NP-complete)
Let  be a 3CNF formula
with m variables
and l clauses
Example:
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
Clause 1
m4
l 3
Clause 2
Clause 3
Formula  can be converted
to a graph G such that:
 is satisfied
if and only if
G Contains a vertex cover
of size k  m  2l
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
Clause 2
Clause 1
Clause 3
Variable Gadgets
x1
x1
x2
x3
x2
Clause Gadgets
nodes
x4
x3
x3
Clause 1
x2
x4
3l nodes
x1
x1
x1
x2
2m
x4
Clause 2
x3
x4
Clause 3
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
Clause 2
Clause 1
x1
x1
x2
x4
x3
x3
Clause 1
x2
x4
x1
x1
x1
x2
x3
x2
Clause 3
x4
Clause 2
x3
x4
Clause 3
First direction in proof:
If  is satisfied,
then G contains a vertex cover of size
k  m  2l
Example:
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
Satisfying assignment
x1  1
x2  0
x3  0
We will show that G contains
a vertex cover of size
k  m  2l  4  2  3  10
x4  1
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
x1  1
x1
x1
x2  0
x2
x3
x2
x4  1
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3  0
x4
x3
x4
Put every satisfying literal in the cover
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
x1  1
x1
x1
x2  0
x2
x3
x2
x4  1
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3  0
x4
x3
x4
Select one satisfying literal in each clause gadget
and include the remaining literals in the cover
This is a vertex cover since every edge is
adjacent to a chosen node
x1
x1
x2
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3
x2
x4
x3
x4
Explanation for general case:
x1
x1
x2
x2
x3
x3
x4
x4
Edges in variable gadgets
are incident to at least one node in cover
Edges in clause gadgets
are incident to at least one node in cover,
since two nodes are chosen in a clause gadget
x2
x1
x1
x1
x3
x2
x4
x3
x4
Every edge connecting variable gadgets
and clause gadgets is one of three types:
x1
x1
x2
Type 1
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3
x2
x4
x3
x4
Type 2
All adjacent to nodes in cover
Type 3
Second direction of proof:
If graph G contains a vertex-cover
of size k  m  2l
then formula  is satisfiable
Example:
x1
x1
x2
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3
x2
x4
x3
x4
To include “internal’’ edges to gadgets,
and satisfy k  m  2l
exactly one literal in each variable gadget is chosen
x1
x1
x2
x3
x2
x4
x3
x4
m chosen out of 2m
exactly two nodes in each clause gadget is chosen
x2
x1
x1
x1
x3
x2
x4
2l chosen out of 3l
x3
x4
For the variable assignment choose the
literals in the cover from variable gadgets
x1
x1
x1  1
x2
x2
x2  0
x3
x3
x3  0
x4
x4
x4  1
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
  (x 1  x 2  x 3 )  ( x 1  x 2  x 4 )  ( x 1  x 3  x 4 )
is satisfied with
x1  1
x1
x1
x2  0
x2
x3
x2
x4  1
x4
x3
x3
x2
x4
x1
x1
x1
x2
x3  0
x4
x3
x4
since the respective literals satisfy the clauses
Dominating Set
Problem:
Dominating-set = {<G, K> | A dominating set of
size K for G exists}
Goal:
Show that Dominating-set is NP-Complete
Dominating Set (Definition)
Problem:
Dominating-set = {<G, K> | A dominating set of
size (at most) K for G exists}
Let G=(V,E) be an undirected graph
A dominating set D is a set of vertices that
covers all vertices
i.e., every vertex of G is either in D or is
adjacent to at least one vertex from D
Dominating Set (Example)
Size-2 example : {Yellow vertices}
e
Dominating Set (Proof Sketch)
Steps:
1) Show that Dominating-set ∈ NP.
2) Show that Dominating-set is not easier than a
NPC problem
We choose this NPC problem to be Vertex cover
Reduction from Vertex-cover to Dominating-set
3) Show the correspondence of “yes” instances
between the reduction
Dominating Set - (1) NP
It is trivial to see that Dominating-set ∈ NP
Given a vertex set D of size K, we check whether
(V-D) are adjacent to D
i.e., for each vertex, v, in (V-D), whether v is
adjacent to some vertex u in D
Dominating Set - (2) Reduction
Reduction - Graph transformation
Construct a new graph G' by adding new vertices and edges to the
graph G as follows:
G
<G,k> ∈ L
Vertex-cover
T
G’
<G’, k> ∈ L’
Dominating-set
Dominating Set - (2) Reduction
Reduction - Graph transformation (Con’t)
For each edge (v, w) of G, add a vertex vw and the edges
(v, vw) and (w, vw) to G'
Furthermore, remove all vertices with no incident edges;
such vertices would always have to go in a dominating
set but are not needed in a vertex cover of G
G
<G,k> ∈ L
Vertex-cover
T
G’
<G’, k> ∈ L’
Dominating-set
Vertex cover
A vertex cover, C, is a set of vertices that
covers all edges
i.e., each edge is at least adjacent to some node
in C
1
2
3
4
{2, 4}, {3, 4}, {1, 2, 3}
are vertex covers
Dominating Set – Graph Transformation
Example
vw
v
w
v
w
vz
wu
vu
z
u
z
u
zu
G
G'
Dominating Set - (3) Correspondence
A dominating set of size K in G’  A vertex cover
of size K in G
 Let D be a dominating set of size K in G’
Case 1): D contains only vertices from G
Then, all new vertices have an edge to a vertex in D
D covers all edges
D is a valid vertex cover of G
Dominating Set - (3) Correspondence
A dominating set of size K in G’  A vertex cover
of size K in G
 Let D be a dominating set of size K in G’
Case 2): D contains some new vertices (vertex in the form
of uv)
(We show how to construct a vertex cover using only old vertices,
otherwise we cannot obtain a vertex cover for G)
For each new vertex uv, replace it by u (or v)
If u ∈ D, this node is not needed
Then the edge u-v in G will be covered
After new edges are removed, it is a valid vertex cover of G (of
size at most K)
Dominating Set - (3) Correspondence
A dominating set of size K in G’  A vertex cover
of size K in G
 Let C be a vertex cover of size K in G
For an old vertex, v ∈ G’ :
By the definition of VC, all edges incident to v are covered
v is also covered
For a new vertex, uv ∈ G’ :
Edge u-v must be covered, either u or v ∈ C
This node will cover uv in G’
Thus, C is a valid dominating for G’ (of size at most K)
Dominating Set - (3)
Correspondence
vw
v
w
v
w
vz
wu
vu
z
u
z
u
zu
Vertex-cover in G
Dominating-set in G'