NP-Complete Problems [1ex] DPV Chapter 8: NP

Efficient and Not-So-Efficient Algorithms
NP-Complete Problems
DPV Chapter 8: NP-Complete Problems, Part 1
Problem spaces tend to be big:
A graph on n vertices can have up to nn−2 spanning trees.
A graph on n vertices can have Θ(2n ) many paths between verts s and t.
Etc.
Jim Royer
The Good News
EECS
November 24, 2009
In our previous work, out of problems with Θ(2n ) (or worse) many choices,
we have found the right answer in time O(nk ) for some k.
The Bad News
Not all problems are so nice.
Uncredited diagrams are from DPV or homemade.
NP-Completeness
1/1
Search Problems
NP-Completeness
2/1
Propositional Logic
The formulas of propositional logic are given by the grammar:
Search problems are those of the form:
Given: . . .
Find: . . .
P ::= Var | ¬P | P ∧ P | P ∨ P
Var ::= the syntactic category of variables
(with a large search space)
A truth assignment is a function I : Variables → { False, True }.
A truth assignment I determines the value of a formula as follows:
Satisfiability (as a search problem)
Given: A boolean formula in conjunctive normal form (CNF).
Find: A satisfying assignment for it (if it has one).
We need to define some terms.
I[[x]] = True
I[[¬p]] = True
I[[p ∧ q]] = True
I[[p ∨ q]] = True
iff I(x) = True (x a variable)
iff I[[p]] = False
iff I[[p]] = I[[q]] = True.
iff I[[p]] = True or
I[[q]] = True.
A satisfying assignment for a formula p is an I with I[[p]] = True.
The only known algorithms for SAT run in exponential time.
NP-Completeness
3/1
NP-Completeness
4/1
Conjunctive Normal Form
Back to Search Problems, 1
Instead of writing ¬x we write x.
A variable x and the negation of a variable x are called literals.
A clause is a disjunction of literals.
E.g.: (x ∨ y ∨ z).
I: an instance of the problem
S: a possible solution for I
A conjunctive normal form formula is a conjunction of clauses.
E.g.: (x ∨ y ∨ z) ∧ (x ∨ y) ∧ (y ∨ z) ∧ (z ∨ x) ∧ (x ∨ y ∧ z)
Satisfiability (as a search problem)
Given: A boolean formula in conjunctive normal form (CNF).
Find: A satisfying assignment for it (if it has one).
Note the differences with the boolean circuit evaluation problem.
If a CNF formula has n variables, there are 2n possible assignments.
NP-Completeness
Elements of a Search Problem
5/1
Back to Search Problems, 2
C : (Instances)×(Pot. Solutions) → { True, False }
C(I, S) = the result of checking if S solves I
C should be computable in O(|I |k ) for some k.
(This implies that |S| cannot be too large.)
For SAT:
An instance
A pot. solution
poly-time checker
:
:
:
a CNF formula
a truth assignment
boolean circuit evaluation
NP-Completeness
(x ∨ y) ∧ (y ∨ x)
x 7→ True, y 7→ True
6/1
Traveling Salesman
Traveling Salesman (TS) as a search problem
Elements of a Search Problem
I: an instance of the problem
S: a possible solution for I
C : (Instances)×(Pot. Solutions) → { True, False }
C(I, S) = the result of checking if S solves I
C should be computable in O(|I |k ) for some k.
(This implies that |S| cannot be too large.)
Variations of SAT
Horn Clause SAT
2SAT
3SAT
Easy (Chapter 5)
Easy
Hard, it seems
Definition
nSAT is the restricted version of SAT in which each clause as at most n literals.
NP-Completeness
7/1
Given: n vertices and all n · (n − 1)/2-many distances between them
b a budget (number)
Find: An ordering of 1, . . . , n: π (1), π (2), . . . , π (n) (a tour) so that
dπ (1),π (2) + dπ (2),π (3) + · · · + dπ (n),π (1) ≤ b.
Traveling Salesman (TS) as an optimization problem
Given: n vertices and all n · (n − 1)/2-many distances between them.
Find: An ordering of 1, . . . , n: π (1), π (2), . . . , π (n) so that the tour’s cost
dπ (1),π (2) + dπ (2),π (3) + · · · + dπ (n),π (1) is minimal.
The two problems are equivalent:
A solution to the optimization problem, solves the search problem.
(Why?)
Given a way to solve the search problem, you can construct a solution to the
optimization problem via binary search.
(How?)
The only known algorithms for these problems are exponential time.
TS is a restriction of the Minimal Spanning Tree problem in which the MST is
allowed no branches.
NP-Completeness
8/1
Euler and Hamiltonian Paths, 1
Euler and Hamiltonian Paths, 2
Definition
Definition
A path in an undirected graph is an Euler path when it uses each edge of the
graph exactly once. (The path may pass through a vertex many times.)
A path in an undirected graph is a Rudrata path (or more usually a
Hamiltonian path) when it uses each vertex of the graph exactly once.
If the path is a cycle, then it is called an Euler Tour or an Euler Circuit.
If the path is a cycle, then it is called a Rudrata Cycle or Hamiltonian Cycle.
Theorem (Euler)
G has an Euler path ⇐⇒ G is connected and has at most two vertices of odd degree.
Image from: http://en.wikipedia.org/wiki/Hamiltonian_path
Euler Tour: A B . . . K
No Euler Path
Images from: http://en.wikipedia.org/wiki/Eulerian_path
NP-Completeness
There is a nice poly-time algorithm for the Euler Path Search problem.
(See http://en.wikipedia.org/wiki/Eulerian_path.)
All known algorithms for the Hamiltonian Path Search Problem are
exponential-time.
9/1
Cuts and bisections
NP-Completeness
10 / 1
Integer Linear Programming
Definition
A cut in a graph is a set of edges which, if removed,
disconnect the graph.
A minimum cut is a cut of smallest size.
Integer Linear Programming (ILP)
Given: constraints A~x ≤ ~b and objective function ~cT ·~x and goal: g
Find: A vector of integers ~x satisfying A~x ≤ ~b and ~cT ·~x ≥ g.
— or equivalently —
Minimum Cut Problem
Given: An undirected graph G and a budget b (a number),
Find: A cut of G of at most b edges.
Balanced Cut Problem
Given: An undirected graph G = (V, E) and a budget b (a number),
Find: A partition of V: S and T with |S|, |T | ≥ |V |/3 such that the number of edges
between S and T is at most b.
You can use Ford-Fulkerson to solve Min-Cut in poly-time.
The only known algorithms for Balanced-Cut are exponential time.
Balanced-Cuts are important in clustering. (See DPV.)
Given: constraints A~x ≤ ~b
Find: A vector of integers ~x satisfying A0~x ≤ ~b0 .
(~cT ·~x ≥ g is incorporated into the constraints.)
Zero-One Equations (ZOE)
Given: constraints A~x ≤ ~b
Find: A vector of 0’s and 1’s ~x satisfying A0~x ≤ ~b0 .
ILP and ZOE show up in lots of optimization work.
The only known algorithms for Balanced-Cut are exponential time.
Image from: http://en.wikipedia.org/wiki/Cut_(graph_theory)
NP-Completeness
11 / 1
NP-Completeness
12 / 1
Three-dimensional matching
Independent set, vertex cover, and clique, 1
S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani
255
Definition
Figure 8.4 A more elaborate matchmaking scenario. Each triple is shown as a triangularshaped node joining boy, girl, and pet.
Chet
Alice
Bob
3D Matching
Given: R ⊆ A × B × C where |A| = |B| = |C| = n.
Find: A subset M ⊆ R of n many triples such that
if (a, b, c) and (a0 , b0 , c0 ) are distinct elements of M,
then a 6= a0 , b 6= b0 , and c 6= c0 .
Suppose G = (V, E) is an undirected graph and U ⊆ V.
Beatrice
Al
Carol
Armadillo
(a) U is independent when for each u, v ∈ U, (u, v) ∈
/ E.
(b) U is a vertex cover when each edge of E has at least one endpoint in U.
(c) U is a clique when for each distinct u, v ∈ U, (u, v) ∈ E.
Bobcat Canary
2D matching is poly-time (via Ford-Fulkerson).
complete
story we willare
introduce
a few more hard
problems, which will play a role later
The only known algorithms for
3D our
Matching
exponential
time.
in the chapter, when we relate the computational difficulty of all these problems. The reader
is invited to skip ahead to Section 8.2 and then return to the definitions of these problems as
required.
The blue vertices are a
max-sized independent
Recall the BIPARTITE MATCHING problem: given a bipartite graph with n nodes on each side
(the boys and the girls), find a set of n disjoint edges, or decide that no such set exists.set
In for the graph.
Three-dimensional matching
Section 7.3, we saw how to efficiently solve this problem by a reduction to maximum flow.
However, there is an interesting generalization, called 3D MATCHING, for which no polynomial algorithm is known. In this new setting, there are n boys and n girls, but also n pets,
and the compatibilities
among them are specified by a set of triples, each containing a boy, a
NP-Completeness
13 / 1
girl, and a pet. Intuitively, a triple (b, g, p) means that boy b, girl g, and pet p get along well
together. We want to find n disjoint triples and thereby create n harmonious households.
Can you spot a solution in Figure 8.4?
The red vertices are a
min-sized vertex cover
for the graph.
The red vertices are a
max-sized clique for the
graph.
The images are from Wikipedia.
NP-Completeness
14 / 1
Independent set, vertex cover, and clique
Independent set, vertexIncover,
and problem
clique,
2
Independent set, vertex cover, and clique, 3
the
(recall Section 6.7) we are given a graph and an integer g,
INDEPENDENT SET
Definition
Suppose G = (V, E) is an undirected
and the aim is to find g vertices that are independent, that is, no two of which have an edge
between them. Can you find an independent set of three vertices in Figure 8.5? How about
four vertices? We saw in Section 6.7 that this problem can be solved efficiently on trees, but
Independent Set Problem
for general graphs no polynomial algorithm is known.
There are many other search problems about graphs. In VERTEX COVER, for example, the
graph
and
U
⊆
V.
G and b.
input is a graph and a budget b, and the idea is to find b vertices that cover (touch) Given:
every
edge. Can you cover all edges of Figure 8.5 with seven vertices? With six? (And do you see
the An independent set
Find:
(a) U is independent when for each u, v ∈ U, (u, v) ∈
/ E.
for G of size ≥ b.
(b) U is a vertex cover when each edge of E has at least one endpoint in U.
(c) U is a clique when for each distinct u, v ∈ U, (u, v) ∈ E.
Independent Set Problem
Given: G and b.
Find: An independent set for G of size ≥ b.
Vertex Cover Problem
Given: G and b.
Find: A vertex cover for G of size ≤ b.
Clique Problem
Given: G and b.
Find: A clique in G of size ≥ b.
Vertex Cover Problem
Given: G and b.
Find: A vertex cover for G of size ≤ b.
The only known algorithms for these problems are exponential time.
Clique Problem
Given: G and b.
Find: A clique in G of size ≥ b.
NP-Completeness
15 / 1
NP-Completeness
16 / 1
In short, the world is full of search problems, some of which can be solved efficiently
Problems:
Hard
Easyin the following table.
others seem to
be very hard.
This and
is depicted
Longest Path, Knapsack, Subset Sum
The Longest Path Problem
3 SAT
MINIMUM SPANNING TREE
SHORTEST PATH
KNAPSACK
UNARY KNAPSACK
INDEPENDENT SET
INTEGER LINEAR PROGRAMMING
R UDRATA
on trees
LINEAR PROGRAMMING
E ULER
PATH
PATH
MINIMUM CUT
All of the hard problems above are hard for the same reason.
Yes, but . . .
This table is worth contemplating. On the right we have problems that can be
In fact, they are all “the same problem” in disguise.
efficiently. On the
left, we have a bunch of hard nuts that have escaped efficient soluti
many decades or centuries.
NP-Completeness
17 / 1
P and NP, 1
P and NP, 2
Recall: Elements of a Search Problem
Definition
I: an instance of the problem
18 / 1
A decision problem is a problem with an Yes/No answer.
S: a possible solution for I
C : (Instances)×(Pot. Solutions) → { True, False }
C(I, S) = the result of checking if S solves I
C should be computable in O(|I |k ) for some k.
(This implies that |S| cannot be too large.)
Definition (NP and P: As search problems)
(a) An efficient checking algorithm is an algorithm that computes C as above in
O(|I |k )-time for some k.
(b) Each efficient checking algorithm C determines a search problem:
S is a solution for I ⇐⇒ C(I, S) = True.
(c) NP = the class of all search problems that have eff. checking algorithms.
(d) P = the class of all search problems for which one can find solutions (or
determine there are none) in polynomial time.
NP-Completeness
BIPARTITE MATCHING
BALANCED CUT
The only known algorithms for these problems are exponential time.
NP-Completeness
MATCHING
INDEPENDENT SET
Subset Sum
Given: A multiset of integers M and goal G.
Find: An { x1 , . . . , xk } ⊆ M such that G = x1 + · · · + xk .
SAT
LONGEST PATH
3D
Given: Weights w1 , . . . , wn , values v1 , . . . , vn , Total Capacity: W, and Goal: G
(all positive integers).
Find: A selection of items with total weight ≤ W and total value ≥ G.
2 SAT, H ORN
TRAVELING SALESMAN PROBLEM
Knapsack
?? But didn’t we have an LP solution to Knapsack?
Easy problems (in P)
Hard problems (NP-complete)
Given: A undirected graph G.
Find: A longest simple path in G.
(Simple path ≡ a path with no repeated vertices.)
19 / 1
SAT as a decision problem: Does CNF formula F have satisfying assignment?
Hamiltonian Path as a decision problem: Does G have a Hamiltonian Path?
Definition (NP and P: As decision problems)
(a) NP = the class of all decision problems that have eff. checking algorithms.
(b) P = the class of all decision problems that have polytime algorithms.
In Algorithms: search problems are a bit more natural than decision problems.
In Computational Complexity Theory: the reverse
Which is better? The search and decision forms of NP problems are roughly of
equivalent hardness.
?
The $1,000,000,000 Question: P = NP.
Collect your prize here: http://www.claymath.org/millennium/
Q: What is the basis for believing all those problems we just listed are hard?
NP-Completeness
20 / 1
efficient algorithm (besides, of course, the historical fact that many clever mathematicians
and computer scientists have tried hard and failed to find any)? Such evidence is provided
by reductions, which translate one search problem into another. What they demonstrate is
that the problems on the left side of the table are all, in some sense, exactly the same problem,
except that they are stated in different languages. What’s more, we will also use reductions to
showReducing
that theseproblem
problemsAare
hardest
problems
even one of them has a
to the
problem
B search
≈ rephrasing
A in
in NP—if
B’s language
polynomial
time
algorithm,the
then
every problem
NP Problem
has a polynomial
algorithm. Thus
E.g., The
rephrasing
Boolean
CircuitinEval
as an LPtime
problem.
if we believe that P != NP, then all these search problems are hard.
We
defined reductions in Chapter 7 and saw many examples of them. Let’s now specialize
Definition
this definition to search problems. A reduction from search problem A to search problem B
A problem A is reducible to problem B (written: A → B [DPV] or A E B [these
is a polynomial-time algorithm f that transforms any instance I of A into an instance f (I) of
slides]) when
there polynomial-time
are two polytime
computable functions f and h
B, together
S. Dasgupta,with
C.H.another
Papadimitriou,
and U.V. algorithm
Vazirani h that maps any solution S of f (I) back
259
f transforms
I into
a B-instance
(I ).no solution, then neither does
into a solution
h(S) of I;an
seeA-instance
the following
diagram.
If f (I) fhas
I. These two
translationaprocedures
f and
imply
thatan
any
algorithm hfor
can
transforms
B-solution
of fh(Ifor
) for into
A-solution
(S)Bof
I be converted
that
P algorithm
!= hNP—the
finding aSitproof
into an
fortask
A byofbracketing
betweenaf given
and h.mathematical assertion is a search
problem and is therefore in NP (after all, when a formal proof of a mathematical statement is
written out in excruciating detail, Algorithm
it can be checked
for A mechanically, line by line, by an efficient
algorithm). So if P = NP, there would be an efficient method to prove any theorem, thus
eliminating the need for mathematicians! All inSolution
all, there
reasons why it is
S of fare
(I) a variety of
Solution
Instance
h
Instance
fHowever,
(I) Algorithm
h(S)
of I
widely believed
that
P
=
!
NP.
proving
this
has
turned
out
to
be
extremely
difficult,
f
I
B
one of the deepest and most importantfor
unsolved
puzzles
of
mathematics.
No solution to f (I)
Formalizing Reductions, 1
No solution to I
Reductions, again
And
we canthat
finally
class
of the
hardest
search
problems.
Even
if now
we accept
P define
!= NP,the
what
about
the
specific
problems
on the left side of the
table? On the basis of what evidence do we believe that these particular problems have no
NP-Completeness
21 / 1
A search
problem
is NP-complete
allhistorical
other search
reduce
to it.
efficient
algorithm
(besides,
of course, ifthe
factproblems
that many
clever
mathematicians
and computer scientists have tried hard and failed to find any)? Such evidence is provided
This
is a very strong
indeed.
a problem
be NP-complete,
must be useful
by reductions,
whichrequirement
translate one
searchFor
problem
into to
another.
What theyit demonstrate
is
in
solving
every
search
problem
in
the
world!
It
is
remarkable
that
such
problems
exist.
that the problems on the left side of the table are all, in some sense, exactly the same problem,
But they
do,they
andare
thestated
first column
of the
table we What’s
saw earlier
filled
the reductions
most famous
except
that
in different
languages.
more,iswe
willwith
also use
to
examples.
In
Section
8.3
we
shall
see
how
all
these
problems
reduce
to
one
another,
andhas
also
show that these problems are the hardest search problems in NP—if even one of them
a
why all other
search
problems
reduce
them. in NP has a polynomial time algorithm. Thus
polynomial
time
algorithm,
then
everyto
problem
if we believe that P != NP, then all these search problems are hard.
We defined reductions in Chapter 7 and saw many examples of them. Let’s now specialize
Reductions
compose
this definition
to search
problems. A reduction from search problem A to search problem B
I.e.,
A
E
B
and
B E Cf implies
that A Eany
C. instance I of A into an instance f (I) of
is a polynomial-time algorithm
that transforms
B, together
another
algorithm
If with
AEB
and Apolynomial-time
is NP-hard, then
so it B. h that maps any solution S of f (I) back
into a solution h(S) of I; see the following diagram. If f (I) has no solution, then neither does
If Atranslation
is NP-complete
and Bf is
anhNP-problem
with
A E B, for B can be converted
I. These two
procedures
and
imply that any
algorithm
then B isfor
also
NP-complete.
(Why
is this
into an algorithm
A by
bracketing it between
f and
h. handy?)
Formalizing Reductions, 3
∴
∴
Algorithm for A
Instance
I
f
Instance f (I)
Algorithm
for B
Solution S of f (I)
h
No solution to f (I)
Even if we accept that P != NP, what about the specific problems on the left side of the
table? On the basis of what evidence do we believe that these particular problems have no
efficient algorithm (besides, of course, the historical fact that many clever mathematicians
and computer scientists have tried hard and failed to find any)? Such evidence is provided
by reductions, which translate one search problem into another. What they demonstrate is
that the
problems on the left side of the table are all, in some sense, exactly the same problem,
Definition
except that they are stated in different languages. What’s more, we will also use reductions to
A these
problem
is NP-hard
when
all
show(a)
that
problems
are the
hardest
search problems in NP—if even one of them has a
NP-problems
reduce
to
it.
polynomial time algorithm, then every problem in NP has a polynomial time algorithm. Thus
if we(b)
believe
that P is
!=NP-complete
NP, then all when
these itsearch
problems are hard.
A problem
is
We defined
reductions
in Chapter 7 and saw many examples of them. Let’s now specialize
in NP and
NP-hard.
this definition to search problems. A reduction from search problem A to search problem B
is a polynomial-time
thatsotransforms
any instance I of A into an instance f (I) of
If A E B andalgorithm
A is hard,fthen
is B.
B, together
with
another
polynomial-time
algorithm
h that maps any solution S of f (I) back
(Why?)
into a solution h(S) of I; see the following diagram. If f (I) has no solution, then neither does
S. Dasgupta,
C.H.
Papadimitriou,
and
U.V.
259
If Atranslation
E B and
B isprocedures
easy, then
so
is A.hVazirani
I. These two
f and
imply that any algorithm for B can be converted
(Why?)
Imageh.
from http://www.solipsys.co.uk/new/PVsNP.html
into an algorithm for A by bracketing it between f and
that P != NP—the task of finding a proof for a given mathematical assertion is a search
problem and is therefore in NP (after
all, when
Algorithm
foraAformal proof of a mathematical statement is
written out in excruciating detail, it can be checked mechanically, line by line, by an efficient
algorithm). So if P = NP, there would be an efficient
any theorem, thus
Solution Smethod
of f (I) to prove Solution
Instance
h
Instance
f (I) Algorithm
h(S)
of I
eliminating
the need
mathematicians!
All in all, there are a variety of
reasons
why it is
f for
I
for
B
widely believed that P != NP. However, proving thisNohas
turned
out to be extremely difficult,
solution
to f (I)
one of the deepest and most important unsolved puzzles of mathematics. No solution to I
Formalizing Reductions, 2
Reductions,
And now weagain
can finally define the class of the hardest search problems.
NP-Completeness
efficient algorithm (besides, of course, the historical fact that many clever mathematicians
This is a very strong requirement indeed. For a problem to be NP-complete, it must be useful
and computer scientists have tried hard and failed to find any)? Such evidence is provided
in solving every search problem in the world! It is remarkable that such problems exist.
by reductions, which translate one search problem into another. What they demonstrate is
But they do, and the first column of the table we saw earlier is filled with the most famous
that the problems on the left side of the table are all, in some sense, exactly the same problem,
examples.
Inin
Section
8.3 we shalla see
how all these
problems reduce to one another, and also
Steps
proving
reduction
works
except
that they
are stated that
in different
languages.
What’s more, we will also use reductions to
why all other search problems reduce to them.
showArgue
that these
that:problems are the hardest search problems in NP—if even one of them has a
polynomial time algorithm, then every problem in NP has a polynomial time algorithm. Thus
1. f and h are polytime computable. (Some hand waving on this is usually OK.)
if we believe that P != NP, then all these search problems are hard.
2. If f (Ireductions
) has solution
S, then7 Iand
hassaw
solution
(S).
We defined
in Chapter
manyhexamples
of them. Let’s now specialize
this definition
search
problems. then
A reduction
search problem A to search problem B
3. If f (Ito
) has
no solution,
I has nofrom
solution.
is a polynomial-time
algorithm f that transforms any instance I of A into an instance f (I) of
30 . If I has a solution, then f (I ) also has solution.
B, together with another polynomial-time algorithm h that maps any solution S of f (I) back
into a solution
of I;
see the following
diagram.
If f(¬
(I)Bhas
no ¬
solution,
then neither does
3 andh(S)
30 are
equivalent:
(A =⇒
B) ⇐⇒
=⇒
A).
I. These two translation
procedures
f
and
h
imply
that
any
algorithm
for
B
can be converted
0
However,
easier
to prove.
into an algorithm
for3A is
byusually
bracketing
it between
f and h.
Formalizing Reductions, 4
Solution
h(S) of I
No solution to I
And now we can finally define the class of the hardest search problems.
A search problem is NP-complete if all other search problems reduce to it.
NP-Completeness
23 / 1
This is a very strong requirement indeed.
For a problem
to be NP-complete, it must be useful
in solving every search problem in the world! It is remarkable that such problems exist.
22 / 1
Even if we accept that P != NP, what about the specific problems on the left side of the
search
NP-complete
if all
search
reduce toproblems
it.
table?A On
the problem
basis of is
what
evidence do
weother
believe
thatproblems
these particular
have no
Algorithm for A
Instance
I
f
Instance f (I)
Algorithm
for B
Solution S of f (I)
h
No solution to f (I)
Solution
h(S) of I
No solution to I
And now we can finally define the class of the hardest search problems.
NP-Completeness
24 / 1
A search problem is NP-complete if all other search problems reduce to it.
Algorithms
Warm up: Rudrata (s, t)-Path E Rudrata Cycle
The Plan of §8.3
Reductions between search problems.
All of NP
Rudrata (s, t)-Path
Given: G = (V, E) and s, t ∈ V.
Find: A path from s to t in G passing through each vertex once.
S AT
Rudrata Cycle
3S AT
I NDEPENDENT
V ERTEX
COVER
3D
SET
C LIQUE
S UBSET
Given: G = (V, E).
Find: A cycle in G passing through each vertex once.
MATCHING
Rudrata (s, t)-Path E Rudrata Cycle:
Given an instance of Rudrata (s, t)-Path: (G, s, t) construct G0 by adding an new
vertex x and new edges (x, s) and (x, t).
ZOE
SUM
ILP
R UDRATA
CYCLE
TSP
NP-Completeness
If P is a Rudrata-cyclc in G0 , then leaving x, (x, s) and (x, t) out of P gives an
(s, t)-Rudrata path in G.
If G has a (s, t)-Rudrata path P, then adding (x, s) and (x, t) to P yields a Rudrata
cycle in G0 .
∴
If G0 has no Rudrata cycle, then G has no (s, t)-Rudrata path.
25 / 1
NP-Completeness
e reductions
3SAT E Independent Set, 1
w see that the search problems of Section 8.1 can be reduced to one another as
Figure 8.7. As a consequence, they are all NP-complete.
we tackle
3SATthe specific reductions in the tree, let’s warm up by relating two versions
ata problem.
Given: A CNF formula θ in which each clause has at most 3 literals.
Find: A satisfying assignment for θ.
(s, t)-PATH−→R UDRATA C YCLE
Independent Set Problem
26 / 1
3SAT E Independent Set, 2
To build a satisfying assignment of an instance of 3SAT, we have to pick out at
least one literal per clause to be T RUE — consistently!
Consider: (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y ∨ z) ∧ (x ∨ y).
A clause (`1 ∨ `2 ∨ `3 ) is represented by a triangle with verts labeled: `1 , `2 , & `3 .
Idea: If v ∈ U an indep. set and v has label `,
then the truth assignment corresponding to U sets ` to T RUE.
Set g = # of clauses. So any indep. set must have one vertex from each triangle.
R UDRATA CYCLE problem: given a graph, is there a cycle that passes through each
(Why?)
Given:
G
=
(
V,
E
)
and
b.
tly once? We can also formulate the closely related R UDRATA (s, t)- PATH problem,
264
Find: An independent set for G of size ≥ b.
But we have to have consistency checks. We don’t want to set x and x to Algorithms
T RUE.
o vertices s and t are specified, and we want a path starting at s and ending at t
I.e., Find U ⊆ V with |U | ≥ b and (∀u, v ∈ U )[(u, v) ∈
/ E].
an edge between each occurrence of a variable x and each occurrence of x.
rough each vertex exactly once. Is it possible that R UDRATA CYCLE is easier than FigureSo8.8put
graph corresponding to (x ∨ y ∨ z) (x ∨ y ∨ z) (x ∨ y ∨ z) (x ∨ y).
This The
enforces
consistency.
(Why?)
s, t)- PATH? We will show by a reduction that the answer is no.
Puzzle:
uction maps an instance (G = (V, E), s, t) of R UDRATA (s, t)- PATH into an instance
These are very different
looking problems.
!
y
y
y
y
) of R UDRATA CYCLE as follows:
G with an additional vertex x and
How to G
we is
getsimply
a reduction?
ges {s, x} and {x, t}. For instance:
G
s
Think circuits, but not too literally.
G!
x
z
x
z
x
s
NP-Completeness
27 / 1
NP-Completeness
28 / 1
z
x
3SAT E Independent Set, 3
SAT E 3SAT, 1
Construction: 3SAT instance 7→ IS instance
Given an instance of 3SAT C1 , . . . , Ck .
For each clause Ci = (`1 , `2 , `3 ), build a triangle with vertices labeled `1 , `2 , & `3 .
Add an edge between each literal and all of its opposites.
Set g = k.
Construction: IS solution 7→ 3SAT solution
Given an independent set U: for each v ∈ U with label `, set ` to T RUE.
For each variable that does not yet have a truth value, set it to T RUE.
Algorithms
Claim 1: Both
264 constructions are poly-time.
Claim 2: Given an indep. set, we can construct a satisfying assignment for C1 , . . . , Ck .
Figure 8.8 The graph corresponding to (x ∨ y ∨ z) (x ∨ y ∨ z) (x ∨ y ∨ z) (x ∨ y).
Claim 30 : If C1 , . . . , Ck has an satisfying assignment, then there is size g indep. set.
(x ∨ y ∨ z)∧
(x ∨ y ∨ z)∧
(x ∨ y ∨ z)∧
(x ∨ y)
y
x
y
z
NP-Completeness
y
z
x
x
y
z
Construction: SAT instance 7→ 3SAT instance
Translate each clause to sequence of clauses.
(`1 ∨ `2 ∨ · · · ∨ `k ) 7 → (`1 ∨ `2 ∨ y1 ) (y1 ∨ `3 ∨ y2 ) · · · (yk−3 ∨ `k−1 ∨ `k )
where k > 3 and y1 , . . . , yk−3 are new vars.
Clauses with ≤ 3 literals translate to themselves.
Construction: 3SAT solution 7→ SAT solution
Take the truth assignment for the 3SAT formula & restrict it to the original vars.
Claim 1: Both constructions are poly-time.
Claim 2: If the 3SAT formula has satisfying assignment,
then restriction satisfies the SAT formula.
Claim 30 : If the SAT formula is satisfiable, so is the 3SAT formula.
x
29 / 1
Let us think. To form a satisfying truth assignment we must pick one literal from each
clause and give it the value true. But our choices must be consistent: if we choose x in one
clause, we cannot choose x in another. Any consistent choice of literals, one from each clause,
specifies a truth assignment (variables for which neither literal has been chosen can take on
either value).
So, let us represent a clause, say (x ∨ y ∨ z), by a triangle, with vertices labeled x, y, z. Why
triangle? Because a triangle has its three vertices maximally connected, and thus forces us
to pick only one of them for the independent set. Repeat this construction for all clauses—a
clause with two literals will be represented simply by an edge joining the literals. (A clause
with one literal is silly and can be removed in a preprocessing step, since the value of the
variable is determined.) In the resulting graph, an independent set has to pick at most one
literal from each group (clause). To force exactly one choice from each clause, take the goal g
to be the number of clauses; in our example, g = 4.
All that is missing now is a way to prevent us from choosing opposite literals (that is, both
x and x) in different clauses. But this is easy: put an edge between any two vertices that
correspond to opposite literals. The resulting graph for our example is shown in Figure 8.8.
Let’s recap the construction. Given an instance I of 3 SAT, we create an instance (G, g) of
INDEPENDENT SET as follows.
• Graph G has a triangle for each clause (or just an edge, if the clause has two literals),
with vertices labeled by the clause’s literals, and has additional edges between any two
vertices that represent opposite literals.
• The goal g is set to the number of clauses.
Clearly, this construction takes polynomial time. However, recall that for a reduction we
do not just need an efficient way to map instances of the first problem to instances of the
second (the function f in the diagram on page 259), but also a way to reconstruct a solution
to the first instance from any solution of the second (the function h). As always, there are two
things to show.
1. Given an independent set S of g vertices in G, it is possible to efficiently recover a satisfying truth assignment to I.
NP-Completeness
30 / 1