Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
ECE750 Lecture 10: NP-completeness and
Approximation Algorithms
Todd Veldhuizen
tveldhui@acm.org
Electrical & Computer Engineering
University of Waterloo
Canada
Nov 20, 2007
1 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Tractable problems I
// //
BB
`
`
`
`
`
//
AA
`
`
`
`
`
//
6 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Tractable problems VI
0 0 0 0 0
0 1 0 0 0
1 0 0 0 0
1 1 0 0 0
0 0 1 0 0
0 1 1 1 1
1 0 0 0 0
1 0 1 1 0
They dier on the input a = 1, b = 0, c = 1. The
answer to the decision problem is NO.
VLSI layout
17 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Decision vs. optimization problems II
verication of circuits
mixed-integer programming
(v
1
,v
2
)E : v
1
V
1
,v
2
V
2
w(v
1
, v
2
)
is true, is false.
29 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Propositional Satisability II
if () =
if () =
( ) =
if () = or () =
otherwise
( ) =
if () = and () =
otherwise
computable in
polynomial time such that y Y if and only if
r (y) Z.
31 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Propositional Satisability IV
Note:
If Y is Karp-reducible to Z, then a
polynomial-time solution for Z would imply a
polynomial time solution for Y.
(We can turn instances of Y into instances of Z in
polynomial time.)
32 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Propositional Satisability V
Dene X Y to mean (X
P
m
Y) (Y
P
m
X). (This
is an equivalence relation, whose equivalence classes
consist of problems that are interreducible. These
equivalence classes are sometimes called degrees.)
[Z]
on equivalence classes by
[X]
[Z]
i X
P
m
Z.
V are
an independent set if for all v
1
, v
2
V
, there is no
edge (v
1
, v
2
) E.
The green vertices form an independent set of size 4.
38 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Example NPC proof: Independent set II
An independent set V
Recall that
, recognizable
in polynomial time. (Here we take
to be binary
strings, for simplicity.)
2. A set of feasible solutions S
, and a polynomial
time algorithm that decides S given a problem instance.
3. An objective function J(I , s) that maps an instance
I D and a solution s S to a cost or prot in Q
+
.
4. An indication of whether we aim to maximize or
minimize J.
46 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Approximation Algorithms III
d
) where c, d are
constants.
4. For maximization problems, replace (1 + ) OPT with
(1 ) OPT.
such that
every edge has at least one end in V
.
3. Objective function: [V
[.
4. It is a minimization problem.
with
[V
[ m is a YES certicate.
.)
2. Output the list of vertices that are endpoints of E
.
Theorem
This approximation algorithm yields a vertex cover of size
2 OPT.
Proof.
57 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
An approximation algorithm for vertex cover IV
Let E
[,
this establishes that the size of the vertex cover is 2 OPT.
Proof: Suppose to the contrary that [E
[ = OPT. By pigeonhole
there must be an edge (v
1
, v
2
) E
is a
vertex cover.
Illustration of a contradiction: if the maximal matching contains 4
edges, it is impossible that there could be a vertex cover of only 3
vertices (green), since this would leave an edge uncovered.
58 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
An approximation algorithm for vertex cover V
V of
vertices to be connected, nd a minimum cost
subtree of G that includes all the vertices in
V
; these are
called Steiner nodes.
62 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Steiner trees III
Example:
a
3
2
4
1
1
b
c
d
4
2
2
4
1
1
1
4
The black vertices are the set V
to be connected.
on V
.
2
3
3
2
3
b
c
d
a
3
64 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Steiner trees V
4. Construct a tree on the original graph G by taking the
union of each path represented by an edge of the
minimum spanning tree on the graph G
. When
necessary, prune edges to remove cycles.
1
4
1
1
b
c
d
a
1
4
2
2
4
1
4
3
2
Theorem
This approximation algorithm produces a network of cost
2 OPT.
The proof involves Euler tours and Hamiltonian cycles; see
e.g. [6].
65 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Steiner trees VI
d
) time, i.e., time
polynomial in n and
1
S of objects with
sS
size(s) B.
sS
prot(s).
68 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Bibliography
Knapsack II
1
): with
each doubling of the amount of time we are willing to
spend, we can halve the distance between the
approximate answer and the optimal answer.
+ if S(i , p) =
sS(i ,p)
size(s) otherwise
5. Given the solutions to A(i , p) for the rst i objects, we
can obtain the solutions for A(i + 1, p) by considering
either taking or not taking object a
i +1
, for each value of
p:
If prot(a
i +1
) < p, then
A(i + 1, p) = min( A(i , p),
size(a
i +1
) + A(i , p prot(a
i +1
)))
Approximation algorithm:
1. Let K =
P
n
, where P is the maximum prot of any
item. We will be eectively rounding prots down to
the nearest multiple of K; as 0, the rounding has
less and less eect.
2. For each object a
i
, let prot
(a
i
) =
prot(a
i
)
K
|.
3. Use dynamic programming to solve this new problem
and nd the most protable set S
.
4. Output S
.
74 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Bibliography
Knapsack VIII
Theorem
This approximation algorithm yields a prot of
(1 ) OPT.
Proof. Let O be a set of objects achieving the optimal
prot. Write OPT = prot(O) for the sum of the prots of
the objects in O. Since for each object our maximum
rounding error of the prot is K, we have
prot(O)
OPT
K prot
(O)
prot with rounding
nK (1)
Rearranging,
K prot
)
must be at least as good as O under the rounded prots:
prot(S
) K prot
(O) (3)
prot(O) nK from Eqn.(2) (4)
= OPT P using K =
P
n
(5)
Since OPT P (assuming no objects are bigger than the
knapsack!),
prot(S
) (1 )OPT
1
).
76 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Bibliography
Where to go from here?
http://www.nada.kth.se/
~
viggo/wwwcompendium/
The compendium is organized hierarchically by problem
class (graph theory, network design, etc.) and for each
problem lists the best known approximation algorithms.
Includes almost 500 references to the literature.
77 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Bibliography
Bibliography I
[1] Gregory J. Chaitin, Marc A. Auslander, Ashok K.
Chandra, John Cocke, Martin E. Hopkins, and Peter W.
Markstein.
Register allocation via coloring.
Computer Languages, 6(1):4757, 1981.
[2] M. R. Garey and D. S. Johnson.
Computers and intractability; a guide to the theory of
NP-completeness.
W.H. Freeman, 1979.
[3] H. R. Lewis and C. H. Papadimitriou.
Elements of the theory of computation.
Prentice-Hall, Englewood Clis, New Jersey, 1981.
[4] A compendium of NP optimization problems, 2006.
78 / 79
ECE750 Lecture
10:
NP-completeness
and Approximation
Algorithms
Todd Veldhuizen
tveldhui@acm.org
Bibliography
Bibliography II
[5] Alan T. Sherman.
On superpolylogarithmic subexponential functions (Part
I).
SIGACT News, 22(1):65, 1991.
[6] Vijay V. Vazirani.
Approximation Algorithms.
Springer-Verlag, 2001.
79 / 79