IT257 DAA Approximation Algorithms
IT257 DAA Approximation Algorithms
1
2
NP-Completeness
3
Coping With NP-Hardness
Brute-force Algorithms.
- Develop clever enumeration strategies.
- Guaranteed to find optimal solution.
- No guarantees on the running time.
Heuristics.
- Develop intuitive algorithms.
- Guaranteed to run in polynomial time.
- No guarantees on the quality of solution.
Approximation Algorithms.
- Guaranteed to run in polynomial time.
- Guaranteed to find "high quality" solution, within 1% of optimum.
Obstacle: We need to prove a solution’s value is close to the optimum,
without even knowing what optimum value is! 4
5
Approximation Algorithms
6
Approximation Algorithms
7
Approximation Ratio Bound
We say an approximation algorithm for the problem has a ratio
bound of (n) if for any input size n, the cost C of the solution
C C*
max{ , } = ( n)
C* C
This applies for both minimization and maximization problems.
8
Performance Guarantees
◼ An approximation algorithm is bounded
by ρ(n) if, for all input of size n, the
cost c of the solution obtained by an
approximation algorithm is within a
factor ρ(n) of c* of an optimal solution.
9
-approximation algorithm
10
Vertex Cover
Vertex Cover: a subset of vertices which “covers” every edge.
An edge is covered if one of its endpoint is chosen.
11
Vertex Cover Problem
◼ Let G=(V, E). The subset S of V that meets
every edge of E is known as the Vertex Cover.
12
Examples of Vertex Cover
13
Vertex Cover Problem
APPROX_VERTEX_COVER(G)
1 C
2 E' E( G )
3 while E'
4 do let ( u, v ) be an arbitrary edge of E'
5 C C {u, v}
6 remove from E' every edge incident on either u or v
7 return C
14
Vertex Cover Problem
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
Complexity: O(E)
15
Vertex Cover Problem
Theorem: APPROX_VERTEX_COVER has ratio bound of 2.
Proof. C*: optimal solution
C: approximate solution
A: the set of edges selected in step 4
Let A be the set of selected edges.
| C| = 2| A| When one edge is selected, 2 vertices are added into C.
| A| | C*|
No two edges in A share a common endpoint.
| C| 2| C*|
16
Traveling Salesperson Problem
Traveling Salesperson Problem (TSP) asks for the shortest
Hamiltonian cycle in a weighted undirected graph.
19
TSP: A Special Case
Demonstration
20
TSP: A Special Case
Demonstration
21
TSP: A Special Case
Demonstration
22
TSP: A Special Case
Demonstration
7 6
1 5
2
3 4
Depth First Traversal and Numbering of Vertices
23
TSP: A Special Case
Demonstration
7 6
1 5
2
3 4
Traveling Salesperson Tour
24
TSP: A Special Case
Demonstration
7 6
1 5
3
2
4
Traveling Salesperson Tour with Cost 2.MST
25
TSP: A Special Case
Demonstration
7 6
1 5
3
2
4
Traveling Salesperson Tour with Reduced Cost 2.MST
26
TSP: A Special Case
Output Quality :
Cost of the tour using this algorithm
2* cost of minimum spanning tree
2* cost of optimal solution
27
TSP: An Improved Heuristic
Locate odd degree vertices in minimum spanning tree (MST)
7
6
1
5
2
3
4
Number of odd degree vertices is even
28
TSP: An Improved Heuristic
Locate odd degree vertices in minimum spanning tree (MST)
1
5
2
Perfect matching of odd degree vertices
29
TSP: An Improved Heuristic
Locate odd degree vertices in minimum spanning tree (MST)
7
6
1
5
2
3 4
Merging the perfect edges with MST
30
Bin Packing Problem
◼ Given n items of sizes a1, a2, …, an, 0 ai 1 for 1 i n,
which are to be placed in bins of unit capability, then the
bin packing problem can be solved by determining the
minimum number of bins to accommodate all the items.
◼ Consider the items of different sizes with lengths of time
of executing different jobs on a standard processor, then
we need to use minimum number of processors which can
finish all the jobs within a fixed time. // Assume that the
longest job takes one unit time i.e. equal to fixed time.
31
Example of Bin Packing Problem
◼ Ex. Given n = 5 items with sizes 0.3, 0.5, 0.8, 0.2, 0.4,
then the Optimal Solution is 3 Bins.
33
An Approximation Algorithm
for the Bin Packing Problem
◼ OPT , ceiling of sum of sizes of all items
◼ C(Bi) + C(Bi+1) 1 (a)(Otherwise, the items in Bi+1
will be put in Bi). C(Bi): The sum of sizes of items packed in bin Bi
◼ C(B1) + C(Bm) 1 (b)(Otherwise, the items in Bm
will be put in B1. )
◼ For m nonempty bins,
C(B1)+C(B2)+…+C(Bm) m/2, (a)+(b) for i=1,..,m
m
FF = m < 2 C( B ) = 2 a 2 OPT
n
i i
i =1 i =1
FF < 2 OPT
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55