0% found this document useful (0 votes)
1 views

Approximation Algorithms (2)

The document discusses approximation algorithms, specifically focusing on NP-complete problems and their solutions, including the Traveling Salesman Problem (TSP). It explains the concept of approximation ratios and how they apply to both minimization and maximization problems, detailing an algorithm for TSP that achieves a 2-approximation under the triangle inequality. The document provides a step-by-step example of the APPROX-TSP-TOUR algorithm and its performance in relation to an optimal solution.

Uploaded by

akshitshinchan8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Approximation Algorithms (2)

The document discusses approximation algorithms, specifically focusing on NP-complete problems and their solutions, including the Traveling Salesman Problem (TSP). It explains the concept of approximation ratios and how they apply to both minimization and maximization problems, detailing an algorithm for TSP that achieves a 2-approximation under the triangle inequality. The document provides a step-by-step example of the APPROX-TSP-TOUR algorithm and its performance in relation to an optimal solution.

Uploaded by

akshitshinchan8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Approximation Algorithms

Introduction
• Many problems of practical significance are NP-
complete and can be solved in following ways:
1. If the actual inputs are small, an algorithm with
exponential running time may be perfectly
satisfactory.
2. Identify important special cases that can be solved
in polynomial time.
3. Approximation Algorithm
– Algorithms that runs in polynomial time and
always produce a solution close to the optimal.
Performance Ratios
• An algorithm for a problem has an approximation
ratio of ρ(n) if, for any input of size n, the cost C of
the solution produced by the algorithm is within a
factor of ρ(n) of the cost C* of an optimal solution:
 C C* 
max  * ,    (n)
C C 
• If an algorithm achieves an approximation ratio of
ρ(n), it is called as a ρ(n) -approximation algorithm.
• ρ(n) ≥ 1
– 1-approximation algorithm produces an optimal
solution.
Contd…
• Definitions of approximation ratio and ρ(n)-
approximation algorithm can be applied to both
minimization and maximization problems.
• For a maximization problem,
– 0 < C ≤ C*, and the ratio C*/C gives the factor by which
the cost of an optimal solution is larger than the cost of
the approximate solution.
• For a minimization problem,
– 0 < C* ≤ C, and the ratio C/C* gives the factor by which
the cost of the approximate solution is larger than the
cost of an optimal solution.
Traveling Salesman Problem
Traveling Salesman Problem
• Given a complete undirected graph G = (V, E) with
a nonnegative integer cost c(u,v) associated with
each edge (u,v) ϵ E, find a hamiltonian cycle (a tour)
of G with minimum cost.
• Consider two cases:
– with and without triangle inequality.
– c satisfies triangle inequality, if for all vertices u,
v, w ϵ V, c(u,w) ≤ c(u,v) + c(v,w)
• Finding an optimal solution is NP-complete in both
cases.
TSP with Triangle Inequality
• Compute a minimum spanning tree, whose weight
gives a lower bound on the length of an optimal
traveling-salesman tour.
• Use the minimum spanning tree to create a tour
whose cost is no more than twice that of the
minimum spanning tree’s weight, as long as the cost
function satisfies the triangle inequality.
• Assuming,
– G – a complete undirected graph.
– c – a cost function satisfying the triangle
inequality.
APPROX-TSP-TOUR(G,c)
1. Select a vertex r ϵ G.V to be a “root” vertex

2. Compute a minimum spanning tree T for G


from root r using MST-PRIM(G,c,r)
3. Let H be a list of vertices, ordered according
to when they are first visited in a preorder
tree walk of T
4. return the hamiltonian cycle H
Example

2. A minimum spanning tree T of


1. A complete undirected graph. the complete graph, as computed
Vertices lie on intersections of by MST-PRIM. Vertex a is the
integer grid lines. For example, f root vertex. Only edges in the
is one unit to the right and two minimum spanning tree are
units up from h. The cost shown. The vertices happen to be
function between two points is labeled in such a way that they
the ordinary Euclidean distance. are added to the main tree by
MST-PRIM in alphabetical order.
Contd…

3. A walk of T, starting at a. A full 4. A tour obtained by visiting the


walk of the tree visits the vertices vertices in the order given by
in the order a b c b h b a d e f e g the preorder walk, which is the
e d a. A preorder walk of T lists a tour H returned by APPROX-
vertex just when it is first TSP-TOUR. Its total cost is
encountered, as indicated by the approximately 19.074.
dot next to each vertex, yielding
the ordering a b c h d e f g.
It is known that APPROX-TSP-TOUR is a
Contd… polynomial-time 2-approximation algorithm,
i.e. 19.074 <= 2 * 14.715. The relation is clearly
maintained for the considered example.

Tour H obtained using An optimal tour H* for


APPROX-TSP-TOUR. the original complete
Cost = 19.074 graph. Cost = 14.715
1 2 3 4 5
Example 1 0 2 8 6 1
2 1 0 4 4 2
• Let the starting vertex be '1'. 3 5 3 0 1 5
4 4 7 2 0 1
• Computing MST using Prims. 5 2 6 3 6 0

(i) (ii) (iii) (iv) (v)


• Preorder traversal of MST
– 1 2 5 3 4, or
–1 5 3 4 2
1 2 3 4 5
Contd… 1 0 2 8 6 1
2 1 0 4 4 2
• Computing tour cost. 3 5 3 0 1 5
4 4 7 2 0 1
–1 2 5 3 4 5 2 6 3 6 0
– Cost = c(1,2) + c(2,5) + c(5,3) + c(3,4) + c(4,1)
= 2 + 2 + 3 + 1 + 4 = 12
OR
–1 5 3 4 2
– Cost = c(1,5) + c(5,3) + c(3,4) + c(4,2) + c(2,1)
= 1 + 3 + 1 + 7 + 1 = 13

22

You might also like