This document discusses approximation algorithms for solving NP-hard problems like the traveling salesman problem (TSP) and knapsack problem. It provides an overview of approximation algorithms, defining them as polynomial-time algorithms that provide good but not necessarily optimal solutions. The document then focuses on approximation algorithms for the TSP, describing greedy algorithms like nearest neighbor, minimum spanning tree based algorithms like Christofides, and local search heuristics like 2-opt and Lin-Kernighan. It concludes by noting some applications of approximating the TSP.
1. Approximation Algorithms
for NP – Hard Problems
Dr. P. Subathra
Professor
Dept. of IT
KAMARAJ College of Engg. & Tech.
(AUTONOMOUS)
Madurai
1
2. Approximation Algorithms
• We discuss a different approach to handling
difficult problems of combinatorial
optimization
• Traveling salesman problem and the knapsack
problem
• The decision versions of these problems are
NP-complete.
• The optimization versions fall in the class of
NP-hard problems
2
3. Approximation Algorithms
• There are no known polynomial-time
algorithms for these problems
• So how do we handle them?
• If an instance of the problem in question is
very small
– exhaustive-search algorithm
– dynamic programming technique
– branch-and-bound technique (comparatively
larger problems can be solved)
3
4. Approximation Algorithms
• There is a radically different way of dealing
with difficult optimization problems:
• solve them approximately by a fast algorithm.
• applications where a good but not necessarily
optimal solution will suffice
• approximation algorithms run based on some
problem-specific heuristic.
4
5. Approximation Algorithms
• A heuristic is a common-sense rule drawn
from experience rather than from a
mathematically proved assertion.
5
6. How accurate this approximation is?
• The accuracy of an approximate solution sa to
a problem of minimizing some function f by
the size of the relative error of this
approximation,
where s ∗ is an exact solution to the problem.
6
7. How accurate this approximation is?
• accuracy ratio
• Minimization Problem
• Maximization Problem
• The closer r(sa) is to 1, the better the
approximate solution is.
7
8. POLYNOMIAL-TIME APPROXIMATION
ALGORITHM
DEFINITION
• A polynomial-time approximation algorithm is said to
be a c-approximation algorithm, where c ≥ 1, if the
accuracy ratio of the approximation it produces does
not exceed c for any instance of the problem in
question:
• The best (i.e., the smallest) value of c is called the
performance ratio of the algorithm and denoted RA.
8
9. POLYNOMIAL-TIME APPROXIMATION
ALGORITHM
• We would like to have approximation
algorithms with RA as close to 1 as possible.
• Some approximation algorithms have infinitely
large performance ratios (RA=∞).
9
11. Travelling Salesman Problem
• There are more than a dozen approximation
algorithms that solve TSP in a reasonable
amount of time producing an approximate
solution.
• Example:
– Greedy Algorithms for the TSP
– Minimum-Spanning-Tree–Based Algorithms
– Local Search Heuristics
11
12. Travelling Salesman Problem
– Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
– Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
– Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
12
13. Approximation Algorithm for TSP
Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
13
14. Greedy Algorithms for the TSP:
Nearest-neighbor algorithm
Nearest-neighbor algorithm
• Algorithm:
Step 1 Choose an arbitrary city as the start.
Step 2 Repeat the following operation until
all the cities have been visited:
go to the unvisited city nearest the one
visited last (ties can be broken arbitrarily).
Step 3 Return to the starting city.
14
15. Nearest-neighbor algorithm
With a as the starting vertex,
the nearest-neighbor algorithm
yields the tour (Hamiltonian
circuit) sa:
a − b − c − d − a of length 10.
15
17. Nearest-neighbor algorithm
The accuracy ratio of this
approximation is
• If the last links weight is ∞,
then the cost of the solution
will be infinity.
• Hence, RA =∞for this
algorithm
17
18. Greedy Algorithms for the TSP:
Multifragment-heuristic algorithm
Multifragment-heuristic algorithm
• It is problem of finding a minimum-weight
collection of edges in a given complete
weighted graph so that all the vertices have
degree 2.
18
19. Multifragment-heuristic algorithm
• Step 1
– Sort the edges in increasing order of their weights. (Ties
can be broken arbitrarily.)
– Initialize the set of tour edges to be constructed to the
empty set.
• Step 2
– Repeat this step n times, where n is the number of cities in
the instance being solved:
– add the next edge on the sorted edge list to the set of tour
edges, provided this addition does not create a vertex of
degree 3 or a cycle of length less than n;
– otherwise, skip the edge.
• Step 3
– Return the set of tour edges.
19
20. Multifragment-heuristic algorithm
• Sorted Edges as per weights:
{(a,b), (c,d), (b,c), (a,c), (b,d), (a,d)}
{ 1 , 1 , 2 , 3 , 3 , 6 }
• Initial Tour Set = {}
• Inset edge to Tour Set = {(a,b)} - OK
• Inset edge to Tour Set = {(c,d)} – OK
• Inset edge to Tour Set = {(b,c)} - OK
• Inset edge to Tour Set = {(a,c)} – NO
• Inset edge to Tour Set = {(b,d)} – NO
• Inset edge to Tour Set = {(a,d)} - OK
20
21. Multifragment-heuristic algorithm
• This method is applied to Eucledian Graphs
which follows the below conditions:
– triangle inequality d[i, j ]≤ d[i, k]+ d[k, j] for any
triple of cities i, j, and K
– symmetry d[i, j ]= d[j, i] for any pair of cities i and j
• Accuracy ratio satisfy the following inequality
21
22. Approximation Algorithm for TSP
Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
• There are approximation algorithms for the
traveling salesman problem that exploit a
connection between Hamiltonian circuits and
spanning trees of the same graph.
• Removing an edge from a Hamiltonian circuit
yields a spanning tree, so we use Min Span Tree
to produce a TSP tour
22
23. Minimum-Spanning-Tree–Based Algorithms
Twice-around-the-tree algorithm
• Step 1 Construct a minimum spanning tree of the graph
corresponding to a given instance of the traveling salesman
problem.
• Step 2 Starting at an arbitrary vertex, perform a walk around the
minimum spanning tree recording all the vertices passed by. (DFS
traversal.)
• Step 3 Scan the vertex list obtained in Step 2 and eliminate from it
all repeated occurrences of the same vertex except the starting one
at the end of the list. The vertices remaining on the list will form a
Hamiltonian circuit, which is the output of the algorithm.
23
28. Minimum-Spanning-Tree–Based Algorithms
Christofides Algorithm
• It also uses a minimum spanning tree like twice-
around-the-tree algorithm
• Eulerian circuit exists in a connected multigraph if and
only if all its vertices have even degrees.
• The Christofides algorithm obtains such a multigraph
by adding to the graph the edges of a minimum-weight
matching of all the odd-degree vertices in its minimum
spanning tree.
• Then the algorithm finds an Eulerian circuit in the
multigraph and transforms it into a Hamiltonian circuit
28
29. Christofides Algorithm
Algorithm
Step 1. Find a minimum spanning tree T
Step 2. Find a minimum matching M for the odd-
degree vertices in T
Step 3. Add M to T
Step 4. Find an Euler tour
Step 5. Cut short
29
34. Christofides Algorithm – Step 4
Matching Pair Added to MST Euler Tour / Euler Circuit
a – b- c – e – d – b - a
34
35. Christofides Algorithm – Step 5
Initial Graph Cut Short - Eliminate Repetition
a – b- c – e – d – b - a
a – b - c – e – d - a
Hamiltonian Circuit
35
36. Approximation Algorithm for TSP
Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
• Good approximations to optimal tours can be
obtained by iterative-improvement algorithms,
which are also called local search heuristics.
36
37. LOCAL SEARCH HEURISTICS
• These algorithms start with some initial tour
• On each iteration, the algorithm explores a
neighborhood around the current tour by replacing a
few edges in the current tour by other edges.
• If the changes produce a shorter tour, the algorithm
makes it the current tour and continues by exploring its
neighborhood in the same manner
• otherwise, the current tour is returned as the
algorithm’s output and the algorithm stops
37
38. LOCAL SEARCH HEURISTICS
2-OPT ALGORITHMS
• The 2-opt algorithm works by deleting a pair
of nonadjacent edges in a tour and
reconnecting their endpoints by the different
pair of edges to obtain another Tour
• This operation is called the 2-change.
38
45. Lin-Kernighan algorithm
• The Lin-Kernighan algorithm is a variable-opt
algorithm: its move can be viewed as a 3-opt
move followed by a sequence of 2-opt moves.
45
46. Approximation Algorithms for TSP
– Greedy Algorithms for the TSP
• Nearest-neighbor algorithm
• Multifragment-heuristic algorithm
– Minimum-Spanning-Tree–Based Algorithms
• Twice-around-the-tree algorithm
• Christofides Algorithm
– Local Search Heuristics
• 2-opt algorithms
• 3-opt algorithms
• Lin-Kernighan algorithms
46