Está en la página 1de 39

35.

Approximation Algorithms
Computer Theory Lab.
Chapter 35 P.2
An algorithm that returns near-optimal solutions is called
an approximation algorithm.

Performance bounds for approximation algorithms

Computer Theory Lab.
Chapter 35 P.3
We say an approximation algorithm for the problem has a
ratio bound of ) (n if for any input size n, the cost C of
the solution produced by the approximation algorithm is
within a factor of ) (n of the C* of the optimal solution:
) ( }
*
,
*
max{ n
C
C
C
C
=
This definition applies for both minimization and
maximization problems.

Computer Theory Lab.
Chapter 35 P.4
An approximation scheme for an optimization problem is
an approximation algorithm that takes as input not only an
instance of the problem, but also a value 0 > c such that
for any fixed c , the scheme is a
) 1 ( c +
-approximation
algorithm.

Computer Theory Lab.
Chapter 35 P.5
We say that an approximation scheme is a polynomial-time
approximation scheme if for any fixed
0 > c
, the scheme
runs in time polynomial in the size n of its input instance.

Computer Theory Lab.
Chapter 35 P.6
We say that an approximation scheme is a polynomial-time
approximation scheme if for any fixed 0 > c , the scheme
runs in polynomial in size n of its input instance..
For example, the scheme might have a running time of
) ) / 1 ((
3 2
n O c
.

Computer Theory Lab.
Chapter 35 P.7
We say that an approximation scheme is fully
polynomial-time approximation scheme if its running time
is polynomial both in
1
c
and in the size n of the input
instance, where c is the relative error bound for the
scheme.

Computer Theory Lab.
Chapter 35 P.8
35.1 The vertex-cover problem
The vertex cover problem is to find a vertex cover of
minimum size in a given undirected graph. We call such a
vertex cover an optimal vertex cover.

Computer Theory Lab.
Chapter 35 P.9
APPROX_VERTEX_COVER(G)
1 C |
2 E E G ' ( )
3 while E' = |
4 do let ( , ) u v be an arbitrary edge of E'
5 C C u v ( , )
6 remove from E' every edge incident on either u or v
7 return C

Computer Theory Lab.
Chapter 35 P.10
a
d
e
c b
g f a
d
e
c b
g f
a
d
e
c b
g f a
d
e
c b
g f
a
d
e
c b
g f a
d
e
c b
g f


Complexity: O(E)

Computer Theory Lab.
Chapter 35 P.11
Theorem 35.1 APPROX_VERTEX_COVER has ratio
bound of 2.
Proof.
Let A be the set of selected edges.
| | | |
| | | *|
| | | *|
C A
A C
C C
=
s
s
2
2

Computer Theory Lab.
Chapter 35 P.12
35.2 The traveling salesman problem

triangle inequality
c u w c u v c v w u v w ( , ) ( , ) ( , ) , , s +
Computer Theory Lab.
Chapter 35 P.13
35.2.1 The TSP with triangle inequality

APPROX_TSP_TOUR(G,c)
1 Select a vertex r V G e [ ] to be a root vertex
2 grow a MST T for G from root r using
MST_PRIM(G,c,r)
3 Let L be the list of vertices visited in a preorder
walk of T.
4 return the hamiltonian cycle H that visit the vertices in
the order L.

Computer Theory Lab.
Chapter 35 P.14
a
d
f
c
b
e
g
h
a
d
f
c
b
e
g
h
T
a
d
f
c
b
e
g
h
T
T
a
d
f
c
b
e
g
h
optimal
solution
a
d
f
c
b
e
g
h
H
H*

Computer Theory Lab.
Chapter 35 P.15
Theorem 35.2. APPROX_TSP_TOUR is an approximation
algorithm with ratio bound of 2 for TSP with triangular
inequality.
Proof.

c T c H
c W c T c H
c H c W
c H c H
( ) ( *)
( ) ( ) ( *)
( ) ( )
( ) ( *)
s
= s
s
s
2 2
2

Computer Theory Lab.
Chapter 35 P.16
35.2.2 The general TSP

Theorem 35.3 If NP P = and >1 , there is no
polynomial time approximation algorithm with ratio bound
for some general TSP.
Proof.
Let G V E = ( , ) be an instance of HC.
Let G V E ' ( , ' ) = be the complete graph of V.

Set c u v
if u v E
V otherwise
( , )
( , )
| |
=
e
+

1
1


Computer Theory Lab.
Chapter 35 P.17
35.3 The set-covering problem
An instance ( , ) X F of the set-covering problem consists
of a finite set X and a family F of elements of X, such that
every element of X belongs to at least one subset in F:
X S
S F
=
e

. We say that a subset S F e covers its elements.


The problem is to find a minimum-size C F _ whose
members covers all of X:
X S
S C
=
e

. (37.8)
We say that any C satisfies equation (37.8) covers X.
Computer Theory Lab.
Chapter 35 P.18
S
1
S
3
S
4
S
6
S
2
S
5
minimum-size set cover
C*={S
3
,S
4
,S
5
}
Greedy set cover
C*={S
1
,S
4
,S
5
,S
3
}

Computer Theory Lab.
Chapter 35 P.19
GREEDY_SET_COVER(X,F)
1 U X
2 C |
3 while C = |
4 do select on S F e that maximize | | S U
5 U U S
6 C C S { }
7 return C

running time: polynomial in |X| and |F|.

Computer Theory Lab.
Chapter 35 P.20
Define

=
=
i
H
d
i d
1
1
Theorem 35.4 GREEDY_SET_COVER has a ratio bound
H S S F (max{| || }) e
Proof.
Define
| ) ... ( |
1
1 2 1

=
i i
x
S S S S
c if

x S S S S
i i
e

( ... )
1 2 1

Then
e e e
s =
*
| |
C S S x
x
X x
x
c c C
Computer Theory Lab.
Chapter 35 P.21
Suppose
s
eS x
x
S H c |) (| .

Then | | (| | ) | *| (max{| || })
*
C H S C H S S F
S C
s

s e
e
.

Computer Theory Lab.
Chapter 35 P.22
Proof
e
s
S x
x
S H c |) (| .

Define
| |
| ) ... ( |
0
2 1
S u
S S S S u
i i
=
=


Let k be the least index such that u
k
= 0 . Hence
S S
i
i
k
_
=1

.

Computer Theory Lab.
Chapter 35 P.23
u u
i i
>
1
and u u
i i

1
elements of S are covered for
the first time by S
i
for i=1,2,,k.
.
| ) ... ( |
1
) (
1 2 1
1
1

=

e

=
i i
k
i
i i
S x
x
S S S S
u u c

| ( ... )| | ( ... )| S S S S S S S S
u
i i i
i
>
=

1 2 1 1 2 1
1

1
1
1
1
) (

=

e
s
i
k
i
i i
S x
x
u
u u c .

Computer Theory Lab.
Chapter 35 P.24
NOTE: For any two positive integer a>b, we have
H b H a
i
b a
b
i a
b
( ) ( ) ( ) =

>
= +
1 1
1


|). (| ) (
) 0 ( ) ( ) ( ) (
)) ( ) ( (
0
0 0
1
1
S H u H
H u H u H u H
u H u H c
k
k
i
i i
S x
x
= =
= =
s
=

e

Computer Theory Lab.
Chapter 35 P.25
Corollary 35.5. GREEDY_SET_COVER has a ratio
bound of (ln| | ) X +1 .

Computer Theory Lab.
Chapter 35 P.26
35.5 The subset-sum problem
An exponential-time algorithm
L
L
=
+ =
{ , , , , }
{ , , , , }
12 3 5 9
2 3 4 5 711

Computer Theory Lab.
Chapter 35 P.27
EXACT_SUBSET_SUM(S,t)
1 n S | |
2 L
0
0 < >
3 for i 1 to n
4 do L MERGE LIST L L x
i i i i
+

_ ( , )
1

5 remove from L
i
every element
that is greater than t
6 return the largest element in L
n


Computer Theory Lab.
Chapter 35 P.28
S
P
P
P
S x x x
P P P x
k
i i i i
=
=
=
=
=
= +

{ , , }
{ , }
{ , , , }
{ , , , , , }
{ , ,..., }
( )
1 4 5
0 1
0 1 4 5
0 1 4 5 610
1
2
3
1 2
1 1

Computer Theory Lab.
Chapter 35 P.29
A fully polynomial-time approximation scheme

Let 0 1 < < o .
To trim a list L by o
y is removed from L if - s z y still in L' such that
y z
y
y z y

s s s o o ( ) 1

Computer Theory Lab.
Chapter 35 P.30
Example: o = 01 .
L
L
=< >
=< >
10111215 20 2122 23 24 29
101215 20 23 29
, , , , , , , , ,
' , , , , ,

Computer Theory Lab.
Chapter 35 P.31
Trim( , ) L o
1 m L | |
2 L y ' < >
1

3 last y
1

4 for i 2 to m
5 do if last y
i
< ( ) 1 o
6 then append y
i
onto the end of L'
7 last y
i

8 return L'

Computer Theory Lab.
Chapter 35 P.32
APPROX_SUBSET_SUM( , , ) S t c
1 n S | |
2 L
0
0 < >
3 for i 1 to n
4 do Li MERGE LIST L L x
i i i
+

_ ( , )
1 1

5 L TRIM L
n
i i
( , )
c

6 remove from L
i
every element
that is greater than t
7 let z be the largest value of L
8 return z

Computer Theory Lab.
Chapter 35 P.33
L
t
=< >
=
=
= =
104 102 201,101
308
0 20
4 0 05
, ,
.
/ .
c
o c

Computer Theory Lab.
Chapter 35 P.34
2 L
0
0 =< >
4 L
1
0104 =< > ,
5 L
1
0104 =< > ,
6 L
1
0104 =< > ,
4 L
2
0102104 206 =< > , , ,
5 L
2
0 102 206 =< > , ,
6 L
2
0 102 206 =< > , ,
4 L
3
0102 201,206 303 407 =< > , , , ,
5 L
3
0102 201,303 407 =< > , , ,
6 L
3
0 102 201,303 =< > , ,
4 L
4
0101,102 201,203 302 303 404 =< > , , , , ,
5 L
4
0101,201,302 404 =< > , ,
6 L
4
0101,201,302 =< > ,

Computer Theory Lab.
Chapter 35 P.35
z
z
=
= = + +
=
302
307 104 102 101
2%
*
c

Computer Theory Lab.
Chapter 35 P.36
Theorem 35.8. APPROX_SUBSET_SUM is a fully
polynomial approximation scheme for the subset-sum
problem.
Proof.
By induction on i, one can show that for every element y
in
P
i
that is at most t, there is a
z L
i
e
such that
( ) 1 s s
c
n
y z y
i
.

Computer Theory Lab.
Chapter 35 P.37


* * ) 1 (
) solution optimal ( *
y z y
n
P y
n
n
s s
e
c



Note
n
for
d
dn n n
is
Thus
n
n
n n
n
( ) ( )
( ) ( )
( ) ( )
1 1
1 0 1
1 1
<
>
<
c
c
c c
c
c
increasing

Computer Theory Lab.
Chapter 35 P.38
Hence y z y ( ) * * 1 s s c
Note that the successive element z and z' of L
i

satisfy
z
z
n
'
>

1
1
c
. Thus the number of elements of L
i

is at most log
ln
ln( )
ln
1
1
1

=

s
c
c
c
n
t
t
n
n t

Computer Theory Lab.
Chapter 35 P.39
The algorithm is polynomial in the number n of the input
values given, the number of bits ln t and
1
c
.

APPROX_SUBSET_SUM running time is P n t ( ,ln , ).
1
c