You are on page 1of 25

APPROXIMATION ALGORITHM

APPROXIMATION ALGORITHMS

Definition: Approximation algorithm


An approximate algorithm is a way of dealing with NP-
completeness for optimization problem.
This technique does not guarantee the best solution.
The goal of an approximation algorithm is to come as close
as possible to the optimum value in a reasonable amount of
time which is at most polynomial time.
VERTEX COVER PROBLEM
Vertex Cover Problem
A vertex cover of a graph is a subset of vertices which
covers every edge.
An edge is covered if one of its endpoint is chosen.
The vertex cover problem: What is the minimum size
vertex cover in G?
Vertex Cover Problem

Problem: Given graph G = (V, E), find smallest s. t. if


V ' V
(u, v) E, then u
V or v V or both.
Vertex Cover : Greedy Algorithm(1)

Idea: Keep finding a vertex which covers the maximum


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

Optimal Solution = 6, select all red vertices.

Greedy approach does not always lead to the best approximation algorithm.
Greedy Algorithm(1): Analysis

Unfortunately if we select the vertices in following order, then we will get worst solution for this
vertex cover problem-
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.

Solution=11;
Vertex Cover : Algorithm(2)

APPROX-VERTEX-COVER(G)
1: C ;
2: E E[G]
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
Algorithm(2): Example

1 2 3 8

4 5 6 7

Initially C = C= 1 2

E = {(1,2) (2,3) (1,4) (2,5) (3,6) (5,6) (3,7) (3,8)}


Algorithm(2): Example

1 2 3 8

4 5 6 7

C= 1 2 3 6

E = {(3,6) (5,6) (3,7) (3,8)}


Algorithm(2): Example (Cont)

1 2 3

4 5 6 7

Are the red vertices a vertex-cover?


Yes

Size = 4
Algorithm(2): Example (Cont)

1 2 3

4 5 6 7

Are the red vertices a vertex-cover?


Yes

Size = 3
Given algorithm returns a vertex cover whose
size is guaranteed to be no more than twice
the size of an optimal vertex cover
TRAVELING SALESMAN PROBLEM
The Travelling Salesman Problem is a classic algorithmic problem
in the field of computer science.
It is focused on optimization. In this context better solution
often means a solution that is cheaper.
The Travelling Salesman Problem describes a salesman who must
travel between N cities.
The order in which he does so is something he does not care
about, as long as he visits each one during his trip, and finishes
where he was at first.
Each city is connected to other close by cities, or nodes, by
airplanes, or by road or railway.
Each of those links between the cities has one or more weights
(or the cost) attached. The cost describes how "difficult" it is to
traverse this edge on the graph, and may be given, for example,
by the cost of an airplane ticket or train ticket, or perhaps by
the length of the edge, or time required to complete the
traversal.
The salesman wants to keep both the travel costs, as well as the
distance he travels as low as possible.
Given a complete undirected graph G=(V, E) that
has nonnegative integer cost c(u, v) associated
with each edge (u, v) in E, the problem is to find
a hamiltonian cycle (tour) of G with minimum
cost.
Suppose c(A) denoted the total cost of the edges in the subset A
subset of E i.e.,

c(A) = u,v in A c(u, v)

Moreover, the cost function satisfies the triangle inequality.


That is, for all vertices u, v, w in V, w have
c(u, w) c(u, v) + c(v, w).

TSP problem is NP-complete.


This means that it is unlikely that we can find a polynomial-time
algorithm for TSP.
TSP with the Triangle-Inequality

When the cost function satisfies the triangle inequality, we can


design an approximate algorithm for TSP that returns a tour
whose cost is not more than twice the cost of an optimal tour.
Outline of an APPROX-TSP-TOUR

First, compute a MST (minimum spanning tree) whose weight is a


lower bound on the length of an optimal TSP tour.

Then, use MST to build a tour whose cost is no more than twice
that of MST's weight as long as the cost function satisfies triangle
inequality.
Operation of APPROX-TSP-TOUR

Let root be a in following given set of points (graph).

Construct MST from root a using MST-PRIM (G, c, r).


List vertices visited in preorder walk. L = {a, b, c, h, d, e, f, g}

which is about 23% shorter.

Optimal TSP tour for a given


Return Hamiltonian cycle. problem (graph) would be
APPROX-TSP-TOUR(G,c)

1. select a vertex r V[G] to be a root vertex

2. compute a minimum spanning tree T for G for root r


using MST-PRIM(G,c,r)

3. let T be the list of vertices visited in a preorder tree walk toT

4. return the hamiltonian cycle H that visits the vertices in the


order L

You might also like