You are on page 1of 28

Approximation

Algorithms

1
NP-completeness

Do your best then.

2
Coping With NP-Hardness
Brute-force algorithms.
 Develop clever enumeration strategies.
 Guaranteed to find optimal solution.
 No guarantees on running time.

Heuristics.
Develop intuitive algorithms.
Guaranteed to run in polynomial time.
No guarantees on quality of solution.

Approximation algorithms.
• Guaranteed to run in polynomial time.
• Guaranteed to find "high quality" solution, say within 1% of optimum.
Obstacle: need to prove a solution’s value is close to optimum,
without even knowing what optimum value is!
3
Performance guarantees

An approximation algorithm is bounded by


ρ(n)n) if, for all input of size n, the cost c of
the solution obtained by the algorithm is
within a factor ρ(n)n) of the c* of an optimal
solution

4
Different Approaches

 Special graph classes


e.g. vertex cover in bipartite graphs, perfect graphs.
 Fast exact algorithms, fixed parameter algorithms
find a vertex cover of size k efficiently for small k.
 Average case analysis
find an algorithm which works well on average.
 Approximation algorithms

find an algorithm which return solutions that are


guaranteed to be close to an optimal solution.

5
Vertex Cover

Vertex cover: a subset of vertices which “covers” every edge.


An edge is covered if one of its endpoint is chosen.

The Minimum Vertex Cover Problem:


Find a vertex cover with minimum number of vertices.

6
Approximation Algorithms

Key: provably close to optimal.

Let OPT be the value of an optimal solution,


and let SOL be the value of the solution that our algorithm returned.

Constant factor approximation algorithms:

SOL <= cOPT for some constant c.

7
Vertex Cover: Greedy Algorithm 1

Idea: Keep finding a vertex which covers the maximum number of edges.

Greedy Algorithm 1:
1. Find a vertex v with maximum degree.
2. Add v to the solution and remove v and all its incident edges from the graph.
3. Repeat until all the edges are covered.

How good is this algorithm?

8
Vertex Cover: Greedy Algorithm 1

OPT = 6, all red vertices.

SOL = 11, if we are unlucky in breaking ties.


First we might choose all the green vertices.
Then we might choose all the blue vertices.
And then we might choose all the orange vertices. 9
Set cover
A={1,2,3}
B={2,5,6}
C={6,7,3,8,9,4}
D={1,6,7}

Solution{A,D}

10
Vertex Cover: Greedy Algorithm 1

Not a constant factor


k! vertices of degree k
approximation algorithm!

Generalizing
the example!

k!/k vertices of degree k k!/(k-1) vertices of degree k-1 k! vertices of degree 1

OPT = k!, all top vertices.

SOL = k! (1/k + 1/(k-1) + 1/(k-2) + … + 1) ≈ k! log(k), all bottom vertices. 11


Vertex Cover: Greedy Algorithm 1
Is the output from this greedy algorithm give a approximation of optimal solution?

Consider Gi : remaining graph after the choice


of ith vertex in the solution
di : maximum degree of any node in Gi-1
vi : vertex in Gi-1 with maximum degree
deg(n)v,Gi-1) : degree of v in graph Gi-1

Let C* denote the optimal vertex cover of G which contain m number of vertices
|Gi-1| denote the number of edges in the graph Gi-1.

Then

mi=1 d i
 mi=1 |G i-1
| /m  mi=1 |G | /m =|G | = |G| -mi=1 d
m m i
12
Vertex Cover: Greedy Algorithm 1

In m th iterations, algorithm removes at least half the edges of G

Thus
after m.log |G| iterations
all the edges of G have been removed

Algorithm 1 computes a vertex cover of size O(n)optimum. log n)

Greedy Algorithm 1 is an O(n)log n)


approximation algorithm
13
Vertex Cover: Algorithm 2

Greedy approach does not always lead to the best approximation algorithm

C=
while G has atleast one edge
(n)u,v) any edge of G
G = G \ {u, v}
C = C  {u, v}
return C

For edge (n)u, v), at least one of the vertex u or v must be in any
optimal cover

IT FOLLOWS IT IS A 2 APPROXIMATION ALGORITHM


14
VERTEX COVER ALGORITHM
Here is a trivial 2-approximation algorithm
Input is some graph G = (V,E).

APPROX-VERTEX-COVER
1: C ← Ø ;
2: E′ ← E
3: while E′ ≠ Ø; do
4: let (u, v) be an arbitrary edge of E′
5: C ← C {(u, v)}
6: remove from E′ all edges incident on either u or v
7: end while
VERTEX COVER EXAMPLE

b c d b c d

a e f g a e f g

Input Graph Optimal result, Size


3
VECTOR COVER ALGORITHM
EXAMPLE

b c d b c d

a e f g a e f g

Step 1: choose Step 2: choose


edge (c,e) edge (d,g)

b c d b c d

a e f g a e f g

Step 3: choose Result: Size 6


edge (a,b)
PROOF

Theorem. APPROX-VERTEX-COVER is a poly-time


2-approximation algorithm.

Proof. The running time is trivially bounded by O(V *


E)
(at most |E| iterations, each of complexity at most
O(V )).

Correctness: C clearly is a vertex cover.


PROOF cont.
Size of the cover: let A denote set of edges that are picked
({(c, e), (d, g), (a, b)} in example).

1. In order to cover edges in A, any vertex cover, in particular an optimal


cover C*, must include at least one endpoint of each edge in A.

By construction of the algorithm, no two edges in A share an endpoint


(once edge is picked, all edges incident on either endpoint are
removed).

Therefore, no two edges in A are covered by the same vertex in C*, and
|C*| ≥ |A|.
2. When an edge is picked, neither endpoint is already in C, thus
|C| = 2|A|.
Combining (1) and (2) yields
|C| = 2|A| ≤ 2|C*|
q.e.d
Traveling salesman problem
• Given a list of cities and the
distances between each pair of cities,
what is the shortest possible route
that visits each city exactly once and
returns to the origin city?
a d

b f g

h
Assumptions
• Triangle inequality
– If u and v are two vertices distance
between the two is less if we reach
directly than through an intermediate
vertex w.
a d

Example e
Input
b f g (assume
Euclidean
c
distances)
h

a d

b f g

Complete
MST
undirected 23

graph
.approx-2

a d a d

e e

b f g b f g

c c

h h

Walk W Hamiltonian
24
Cycle H
a b c b h b a d e f e g e d a a b c h d e f g a
.approx-2

a d a d

e e

b f g b f g

c c

h h

Walk W Hamiltonian
25
Cycle H
a b c b h b a d e f e g e d a a b c h d e f g a
Solution by approx Exact solution
algorithm
Proof of 2 approx
– H* denote optimal tour
– H denote approximate solution
– T minimum spanning tree
• Cost of MST is less than cost of
optimal tour
)
• Cost of tour is twice that of MST
)
• Using above two equations
)
•  

You might also like