Professional Documents
Culture Documents
Algorithms
1
NP-completeness
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
4
Different Approaches
5
Vertex Cover
6
Approximation Algorithms
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.
8
Vertex Cover: Greedy Algorithm 1
Solution{A,D}
10
Vertex Cover: Greedy Algorithm 1
Generalizing
the example!
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
Thus
after m.log |G| iterations
all the edges of G have been removed
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
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
b c d b c d
a e f g a e f g
b c d b c d
a e f g a e f g
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
)
•