Approximation Algorithms
Approximation Algorithms
Here L is NP-hard.
Example
The halting problem.
This is the problem that given a program P and
input I, will it halt?
This is a decision problem but it is not in NP.
Any NP-complete problem can be reduced to
this one.
The Class NP-complete
If a problem is in NP and also in NP-Hard, then it is
an NP complete problem.
If we know a single problem in NP-Complete that
helps when we are asked to prove some other
problem is NP-Complete
Assume problem P is NP Complete, i.e. all NP
problems are reducible to this problem P.
Now given a different problem P, if we show P
reducible to P, then by transitivity all NP problems
are reducible to P.
The "first" NP-complete Problem
For the technique of reduction, it is required
to have a problem already known to be NP-
complete.
The problem is the circuit-satisfiability
problem.
Given a boolean combinational circuit composed
of AND, OR, and NOT gates, determine whether
there exists some set of boolean inputs to this
circuit that causes its output to be 1.
Important Note
If any NP-complete problem is polynomial-time
solvable, then P = NP. Equivalently, if any problem
in NP is not polynomial-time solvable, then no
NP-complete problem is polynomial-time
solvable.
No polynomial-time algorithm has yet been
discovered for an NP-complete problem, nor has
anyone yet been able to prove that no
polynomial-time algorithm can exist for any one
of them.
Euler diagram
Approximation Algorithms
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.
The 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.
a, b, c, b, h, b, a, d, e, f, e, g, e, d, a
Contd
Full walk W traverses every edge exactly twice, thus
c(W) = 2c(T).
Together with c(T) c(H), this gives
c(W) = 2c(T) 2c(H)
Find a connection between cost of W and cost of "our"
tour.
Problem: W is in general not a proper tour, since vertices
may be visited more than once.
But: using the triangle inequality, we can delete a visit to
any vertex from W and cost does not increase.
Deleting a vertex v from walk W between visits to u and w
means going from u directly to w, without visiting v.
Contd
We can consecutively
remove all multiple
visits to any vertex.
Example:
full walk a,b,c,b,h,b,a,d,e,f,e,g,e,d,a
becomes a,b,c,h,d,e,f,g.
Contd
This ordering (with multiple visits deleted) is
identical to that obtained by pre-order walk of T
(with each vertex visited only once).
It certainly is a Hamiltonian cycle. Lets call it H.
H is just what is computed by Approx-TSP-Tour.
H is obtained by deleting vertices from W , thus
c(H) c(W )
Conclusion:
c(H) c(W) 2c(H)
Contd
Although factor 2 looks nice, there are better
algorithms.
Theres a 3/2 approximation algorithm by
Christofedes (with triangle inequality).
In The general TSP Cost function c does not
satisfy triangle inequality.
Theorem:
If P NP, then for any constant 1, there is no
polynomial time approximation algorithm with
approximation ratio for the general traveling-
salesman problem.
Example
Compute a tour for a given graph satisfying
the triangle inequality. d
Solution:
15
10
c 20
e
Get MST using prims, 25
35
22
let root be a. 40 10 25
25
e 25
e 25
e
35 35 35
22 22 22
40 10 25 40 10 25 40 10 25
30 30 30
b b b
a a a
A B C
d d
a
15 15
10 10
c 20
c 20
10
25
e c 25
e
35 35
22 22
40 10 25 15 25 40 10 25
d b
30 10 30
b b
a e a
D E: MST F: Obtained tour
Contd
Minimum spanning tree cost = 10 + 15 + 10 + 25 = 60
Full walk of MST starting from a: a c d e d c b c a.
Cost of full walk = 2 * 60 = 120. OR
ac + cd + de + ed + dc + cb + bc + ca
= 10 + 15 + 10 + 10 + 15 + 25 + 25 + 10 = 120
Preorder walk starting from a: a c d e b.
Cost of preorder walk = ac + cd + de + eb + ba
= 10 + 15 + 10 + 40 + 30
= 105 < 120. Hence proved.