Unit 9: Coping with NP-Completeness Course contents:
․
⎯ ⎯ ⎯
Complexity classes Reducibility and NP-completeness proofs Coping with NP-complete problems
Reading:
․
⎯ ⎯
Unit 9
Chapter 34 Chapter 35.1
Y.-W. Chang
1
Complexity Classes ․ ․
Developed by S. Cook and R. Karp in early 1970. The class P: class of problems that can be solved in polynomial time in the size of input. input. ⎯ ⎯ ⎯
․
The class NP (Nondeterministic Polynomial) olynomial):: class of problems that can be verified in polynomial time in the size of input. ⎯
․
Size of input: size of encoded encoded “binar “binary” y” strin strings. gs. Edmonds: Problems in P are considered tractable tractable.. Closed under addition, multiplication, composition, complement complement,, etc.
P = NP?
The class NP-complete (NPC): Any NPC problem can be solved in polynomial time ⇒ All problems in NP can be solved in polynomial time.
Unit 9
Y.-W. Chang
2
Verification Algorithm and Class NP ․
․
Verification algorithm: a 2-argument algorithm A, where one argument is an input string x and x and the other is a binary string y certificate). A verifies x if x if there exists y s.t. y s.t. A answers (called a certificate). “yes.” Exp: The Traveling Salesman Problem (TSP) ⎯
⎯
․ ․
Is TSP NP? Need to check a solution in polynomial time. ⎯ ⎯ ⎯ ⎯
․
Instance: a set of n n cities, cities, distance between each pair of cities, and a bound B . Question: is there a route that starts and ends at a given city, visits every city exactly once, and has total distance ≤ B ?
Guess a tour (certificate). Check if the tour visits every city exactly once. Check if the tour returns to the start. Check if total distance B .
All can be done in O (n ) time, so TSP
Unit 9
Y.-W. Chang
NP.
3
Complexity Classes NP and co-NP ․ ․
Is class NP closed under complement? Class co-NP: co-NP: class of problems whose complement problems are in NP. ⎯
․
NP}.
TSP-Complement: ⎯
⎯
․
co-NP = {L {L:
Instance: a set of n n cities, cities, distance between each pair of cities, and a bound B . Question: are all tours that start and end at a given city, visit every city exactly once, and have total distance > B ?
TSP-Complement ⎯
Unit 9
Equivalently, TSP
NP? co-NP?
Y.-W. Chang
4
Decision & Optimization Problems Decision problems: those having yes/no answers.
․
⎯
⎯
MST: Given a graph G =(V, =(V, E ) and a bound K , is there a spanning tree with a cost at most K ? TSP: Given a set of cities, distance between each pair of cities, and a bound B , is there a route that starts and ends at a given city, visits every city exactly once, and has total distance at most B ?
Optimization problems: those finding a legal configuration such that its cost is minimum (or maximum).
․
⎯
⎯
Unit 9
MST: Given a graph G =(V, =(V, E ), ), find the cost of a minimum spanning tree of G . TSP: Given a set of cities and that distance between each pair of cities, cities, find the the distance distance of a “minimum “minimum route” route” starts and and ends at a given city and visits every city exactly once.
Y.-W. Chang
5
Decision v.s. Optimization Problems Could apply binary search on a decision problem to obtain solutions to its optimization problem. NP-completeness is associated with decision problems. c.f., Optimal solutions/costs, optimal (exact) algorithms
․
․ ․
⎯
Unit 9
optimal exact in the theoretic computer science community.
Y.-W. Chang
6
Polynomial-time Reduction ․
․
Motivation: Let L1 and L2 be two decision problems. Suppose algorithm A2 can solve L2. Can we use A2 to solve L1? Polynomial-time reduction f from f from L1 to L2: L1 P L2 ⎯
f reduces input for L1 into an input for L2 s.t. the reduced input is f reduces a “ye “yes” s” in input put fo forr L2 iff the ori origin ginal al inp input ut is a “yes “yes”” inp input ut for L1.
․
L1 P L2 if polynomial-time computable function f : {0, 1}* {0, 1}* s.t. x L1 iff f (x ) L2, x {0, 1}*. L2 is at least as hard as L1.
f is f is computable in polynomial time.
Unit 9
Y.-W. Chang
7
Significance of Reduction Significance of L1
․
⎯
⎯
․
Unit 9
P
P L2:
polynomial-time algorithm for L2 polynomial-time algorithm for L1 (L2 P L1 P). polynomial-time algorithm for L1 polynomialtime algorithm for L2 (L1 P L2 P).
is transitive, i.e., L1
P L2
and L2
Y.-W. Chang
P L3
L1
P L3
.
8
System of Difference Constraints Revisited ․
․
Example reduction from the system of difference constraints problem to the shortest path one. Constraint graph: Weighted, directed graph G =(V =(V , E ). ). ⎯ V V = = { v 0, v 1, …, v n } E = {(v E = {(v i , v j ): x j - x i ≤ b k } {( {(v v 0, v 1), (v (v 0, v 2),…, (v (v 0, v n )} ⎯ w (v i , v j ) = b k if x j - x i b k is a difference constraint. If G contains G contains no negative-weight cycle, then x = (δ(v 0, v 1), δ(v 0, v 2), …, δ(v 0, v n )) is a feasible feasible solution; solution; no feasible solution, otherwise. ⎯
․
(v0, vj )
xj
Unit 9
(v0, vi ) + w (vi, vj )
xi
bk
Y.-W. Chang
9
Maximum Cardinality Bipartite Matching Revisited ․ ․
․
Example reduction from the matching problem to the max-flow one. Given a bipartite graph G = G = (V (V , E ), ), V V = =L capacity flow network G ' = (V (V ',', E '): '):
R , construct a unit-
V' = V {s , t } E '= {(s {(s , u ): ): u L} {(u {(u , v ): ): u L, v R , (u (u , v) E } {(v {(v , t ): ): v The cardinality of a maximum matching in G = G = the value of a maximum flow in G ' (i.e., |M |M | = |f |f |). |).
Unit 9
Y.-W. Chang
R }. }.
10
Polynomial Reduction: HC ․
P
TSP
The Hamiltonian Circuit Problem (HC) ⎯ ⎯
Instance: an undirected graph G G = = (V, (V, E ). ). Question: is there a cycle in G G that that includes every vertex exactly once?
․
TSP: The Traveling Salesman Problem
․
Claim: HC 1.
2.
Unit 9
P TSP.
Define a function f f mapping mapping any HC instance into a TSP instance, and show that f f can can be computed in polynomial time. Prove that G G has has an HC iff iff the reduced reduced instance instance has has a TSP tour tour with distance B f (x ) TSP). B ((x HC
Y.-W. Chang
11
HC
P TSP:
Step 1
1. Define a reduction function f for HC ─
P TSP.
Given an HC instance G = ( = (V , E ) with n n vertices vertices Create a set of n n cities cities labeled with names in V . Assign distance between u u and and v
Set bound B B = = n . f can f can be computed in O (V 2) time.
─
Unit 9
Y.-W. Chang
12
HC
P TSP:
Step 2
2. G has a HC HC iff the reduc reduced ed instan instance ce has has a TSP with distance B . x ∈ HC ⇒ f (x ) ∈ TSP. —
—
—
—
Unit 9
Suppose the HC is h h = = . Then, h h is is also a tour in the transformed TSP instance. The distance of the tour h h is is n = B since B since there are n consecutive edges in E , and so has distance 1 in f (x ). ). Thus, f (x )
TSP (f (f (x ) has a TSP tour with distance
Y.-W. Chang
B ). ).
13
HC
P TSP:
Step 2 (cont’d)
2. G has a HC iff iff the reduc reduced ed instan instance ce has a TSP TSP with with distance B . f (x ) ∈ TSP x ∈ HC. —
—
—
—
Unit 9
Suppose there is a TSP tour with distance ..
n = B . Let it be
Since distance of the tour n n and and there are n n edges edges in the TSP tour, the tour contains only edges in E . Thus, is a Hamiltonian cycle (x ( x
Y.-W. Chang
HC).
14
HP Application: Crosstalk Minimization Goal: Find a wire ordering s.t. the overall crosstalk is minimized.
․
⎯ ⎯ ⎯
Unit 9
Construct a complete weighted graph G G = = (V, (V, E, W ): ): V wires, W coupling length between each pair of wires. The minimum weighted Hamiltonian path induces the minimum crosstalk.
Y.-W. Chang
15
NP-Completeness ․
A decision problem L (a language L complete (NPC) if 1. 2.
․
․
L L'
NP, and P L for every L'
{0, 1}*) is NP-
NP.
NP-hard: If L satisfies property 2, but not necessarily property 1, we say that L is NP-hard. Suppose L NPC. ⎯
⎯
If L P , then there exists a polynomial-time algorithm for every L' NP (i.e., P = NP). If L P , then there exists no polynomial-time algorithm for any L' NPC (i.e., P NP).
?? tractable
Unit 9
NP-complete problems Y.-W. Chang
intractable
16
Proving NP-Completeness ․
Five steps for proving that L is NP-complete: 1. 2. 3.
4. 5.
Prove L NP. Select a known NP-complete problem L'. Construct a reduction f transforming every instance of L' to an instance of L. Prove that x L' iff f (x ) L for all x {0, 1}*. Prove that f is a polynomial-time transformation. transformation.
A known NP-complete problem L’
Unit 9
f
reduce
Y.-W. Chang
A problem L problem L to be proved NP-complete
17
The Circuit-Satisfiability Problem (Circuit-SAT) ․
The Circuit-Satisfiability Problem (Circuit-SAT): ⎯
⎯
․
A circuit is satisfiable if there exists a set of Boolean input values that makes the output of the circuit to be 1. ⎯
․
Instance: A combinational circuit C C composed composed of AND, OR, and NOT gates. Question: Is there an assignment of Boolean values to the inputs that makes the output of C C to to be 1?
Circuit (a) is satisfiable since = <1, 1, 0> makes the output to be 1.
Circuit-SAT is NP-complete. (Cook, ACM STOC'71) ⎯ ⎯
Circuit-SAT NP. L' NP, L' P Circuit-SAT.
1?
Unit 9
Y.-W. Chang
18
Structure of NP-Completeness Proofs
Unit 9
Y.-W. Chang
19
The Satisfiability Problem (SAT) ․
The Satisfiability Problem (SAT): Instance: A Boolean formula . ⎯ Question: Is there an assignment of truth values to the variables that makes true? Truth assignment: set of values for the variables of φ. Satisfying assignment: a truth assignment that makes φ evaluate to 1. Exp: φ = ((x ((x 1 x 2) ((¬x 1 x 3) x 4)) x 2 ⎯ Truth assignment: = <0, 0, 1, 1>, <0, 1, 0, 1>, etc. ⎯
․ ․
․
Satisfying assignment: = <0, 0, 1, 1>, etc. Satisfiable formula: a formula with a satisfying assignment. ⎯
․
⎯
Unit 9
is a satisfiable formula.
Y.-W. Chang
20
SAT is NP-Complete 1. SAT NP. 2. SAT is NP-hard: Prove that Circuit-SAT ⎯ ⎯
⎯
⎯ ⎯
Unit 9
P SAT.
For each wire x i in circuit C , the formula has a variable x i . The operation of a gate is expressed as a formula with associated variables, e.g., x 10 (x 7 x 8 x 9). = AND of the circuit-output variable with the conjunction ( ) of clauses describing the operation of each gate, e.g., = x 10 (x 4 x 3) (x 5 (x 1 x 2)) (x 6 x 4) (x 7 (x 1 x 2 x 4)) (x 8 (x 5 x 6)) (x 9 (x 6 x 7)) (x 10 (x 7 x 8 x 9)) Circuit C C is is satisfiable formula is satisfiable. (Why?) Given a circuit C , it takes polynomial time to construct .
Y.-W. Chang
21
3SAT is NP-Complete ․
3SAT: Satisfiabili Satisfiability ty of boolean boolean formulas formulas in in 3-conjunctive normal form (3-CNF). (3-CNF). Each clause has exactly 3 distinct literals, e.g., x 2) (x 3 x 2 x 4) ( x 2 x 3 x 4) 3SAT NP (will omit this part for other proofs). 3SAT is NP-hard: SAT P 3SAT. ⎯
․ ․
1.
x 1
Construct a binary Construct binary “parse” “parse” tree for input input formula formula φ and introduce a variable y i for the output of each internal node. = ((x ((x 1
Unit 9
= (x (x 1
x 2)
((
x 1
Y.-W. Chang
x 3)
x 4))
x 2.
22
3SAT is NP-Complete (cont'd) 2. Rewrite φ as the AND of the root variable and a conjunction of clauses describing the operation of each node. ' = y 1 (y 1 (y 2 x 2)) (y 2 (y 3 y 4)) (y 3 (y 4 y 5) (y 5 (y 6 x 4)) (y 6 ( x 1
(x 1 x 2)) x 3)).
3. Convert each clause φ'i into CNF. ⎯
⎯
⎯
Unit 9
Construct the disjunctive normal form for 'i and then apply DeMorgan's DeMor gan's law to get get the CNF CNF formula formula “i . E.g., '1 = (y (y 1 y 2 x 2) (y 1 y 2 x 2) (y 1 y 2 x 2) ( y 1 y 2 x 2) ''1 = ( '1) = ( y 1 y 2 x 2) ( y 1 y 2 x 2) ( y 1 y 2 x 2) (y 1 y 2 x 2).
Y.-W. Chang
23
3SAT is NP-Complete (cont'd) 4. Make each clause C i have exactly 3 distinct literals to get φ '''. ⎯ ⎯
C i has 3 distinct literals: do nothing. C i has 2 distinct literals: C i = (l (l 1 p ). ).
l 2) = (l (l 1
l 2
p ) (l 1
l 2
l = p q ) (l p C i has only 1 literal: C i = l = (l (l p q ) (l q ) (l p q ). ). φ is satisfiable. Claim: The 3-CNF formula φ''' is satisfiable All transformations can be done in polynomial time. ⎯
․ ․
Unit 9
Y.-W. Chang
24
Clique is NP-Complete A clique in G = (V, E ) is a com compl plet ete e subg subgrap raph h of G . The Clique Problem (Clique)
․ ․
⎯ ⎯
Instance: a graph G G = = (V, (V, E ) and a positive integer k |V |. |. Question: is there a clique V ’ V V of of size k ?
Clique NP. Clique is NP-hard: 3SAT
․ ․
⎯
Unit 9
P Clique.
Key: Construct a graph G G such such that clique of size k .
Y.-W. Chang
is satisfiable
G has G has a
25
3SAT ․
․
․
․
P Clique
Let φ = C 1 C 2 … C k be a Boolean formula in 3-CNF with k clauses. Each C r has exactly 3 distinct literals l 1r , l 2r , l 3r . For each C r = (l 1r l 2r l 3r ) in φ, introduce a triple of vertices v r 1, v r 2, v r 3 in V . Build an edge between v i r , v j s if both of the following hold: r s ⎯ v i and v j are in different triples, and r s ⎯ l i is not the negation of l j G can G can be computed from φ in polynomial time.
Unit 9
Y.-W. Chang
26
Is Satisfiable ․
G Has a Clique of Size k
φ is satisfiable ⎯
⎯
⎯
Unit 9
G has G has a clique of size k . φ is satisfiable each C r contains at least one l i r = 1 and each such literal corresponds to a vertex v i r . Pickin Pic king g a “true” “true” lit litera erall from each each C r forms a set of V ' of k vertices. For any two vertices v i r , v j s V ',', r s , l i r = l j s = 1 and thus l i r , l j s cannot be complements. Thus, edge (v ( v i r , v j s ) E .
Y.-W. Chang
27
Is Satisfiable
G Has a Clique of Size k
G has a clique of size k φ is satisfiable. ' of size k V ' contains exactly one ⎯ G has a clique V vertex per triple since no edges connect vertices in the same triple. r r ‘ each C r is ⎯ Assign 1 to each l such that v ∈ V i i satisfied, and so is φ.
․
Unit 9
Y.-W. Chang
28
Vertex-Cover is NP-Complete ․
․
A vertex cover of G = G = (V, (V, E ) is a subset V ’ V such V such that if (u, (u, v ) E , then u V ' or v V '.'. The Vertex-Cover Problem (Vertex-Cover) ⎯ ⎯
․ ․
Instance: a graph G G = = (V, (V, E ) and a positive integer k |V |. |. Question: is there a subset V ’ V of V of size k k such such that each edge in E E has has at least one vertex (endpoint) in V '? '?
Vertex-Cover NP. Vertex-Cover is NP-hard: Clique P Vertex-Cover. ⎯ Ke Key: y: co comp mple leme ment nt of G : = (V, ), = {(u, {(u, v ): ): (u, (u, v )
Unit 9
Y.-W. Chang
E }. }.
29
Vertex-Cover is NP-Complete (cont'd) G Has a Clique of Size k size |V | - k .
․
⎯ ⎯
⎯
⎯
Unit 9
Has a Vertex Cover of
Suppose that G G has has a clique V ’ V with V with |V |V '|'| = k . Let (u, (u, v ) be any edge in (u, v) E at least one of u or u or v v does does not belong to V ' So, u V - V ' or v V - V ‘ edge (u, (u, v ) is covered by V - V '.'. Thus, V - V ' forms a vertex cover of , and | V - V '|'| = |V | - k .
Y.-W. Chang
30
Vertex-Cover is NP-Complete (cont'd) Has a Vertex Cover of size |V ||-k Size k .
․
⎯
⎯ ⎯
Unit 9
Suppose that |V | - k .
G Has a Clique of
has a vertex cover V ’
V with V with |V |V '|'| =
u, v V , if (u, (u, v ) , then u V ' or v V ‘ or both. So, u, v V , if u V ' and v V ',', (u, (u, v ) E V V -- V ' is a clique, and |V | V | - |V '|'| = k .
Y.-W. Chang
31
Clique, Independent-Set, Vertex-Cover ․
․
An independent set of G = G = (V, (V, E ) is a subset V ’ V such V such that G has no edge between any pair of vertices in V '.'. The Independent-Set Problem (Independent-Set) ⎯ ⎯
․
Theorem: The following are equivalent for G = G = (V, (V, E ) and a subset V ‘ of V : 2.
V ' is a clique of G . V ' is an independent set of
3.
V -V ' is a vertex cover of
1.
․
Instance: a graph G G = = (V, (V, E ) and a positive integer k ≤ |V |. |. Question: is there an independent set of size ≥ k ?
. .
Corollary: Independent-Set is NP-complete.
Unit 9
Y.-W. Chang
32
Hitting-Set is NP-Complete ․
A hitting set for a collection C C of of subsets of a set S S is is a subset S’ S such S such that S ' contains at least one element from each subset in C . ⎯
․
The Hitting-Set Problem (Hitting-Set) ⎯ ⎯
․
Instance: Collection C C of of subsets of a set S , positive integer k . Question: does S S contain contain a hitting set for C C of of size ≤ k ?
Hitting-Set is NP-Complete. NP-Complete. ⎯
⎯ ․
S = {1, 2, 3, 4, 5, 6, 7, 8}, C S = C = = {{1}, {3, 5}, {4, 7, 8}, {5, 6}}, S ' can be {1, 4, 5}, {1, 3, 4, 6}, etc.
Restrict to Vertex-Cover by allowing only instances having |c |c | = 2 for all c C . Each set in C edge; element in S ‘ vertex cover.
Proof by restriction is the simplest, and perhaps the most frequently used technique. ⎯
Unit 9
Other examples: Bounded Degree Spanning Tree, Directed HC, Longest Simple Cycle, etc.
Y.-W. Chang
33
Coping with NP-Complete/-Hard Problems ․
Approximation algorithms: ⎯
․
Pseudo-polynomial time algorithms: ⎯
․
E.g., dynamic programming for the 0-1 Knapsack problem.
Probabilistic algorithms: ⎯
․
Guarantee to be a fixed percentage away from the optimum.
Assume some probabilistic distribution of the instances.
Randomized algorithms:
Make use of a randomizer (random # generator) for operation. ․ Restriction: Work on some special cases of the original problem. ⎯ E.g., the maximum independent set problem in circle graphs. ⎯
․
Exponential algorithms/Branch and Bound/Exhaustive search: ⎯
․
Local search: ⎯
․
Feasible only when the problem size is small. Simulated annealing (hill climbing), genetic algorithms, etc.
Heuristics: No formal guarantee of performance.
Unit 9
Y.-W. Chang
34
Exhaustive Search v.s. Branch and Bound
․
TSP example
Backtracking/exhaustive Backtracking/exhaustive search
Branch and bound Unit 9
Y.-W. Chang
35
Simulated Annealing Kirkpatrick, Gelatt, and Vecchi, “Optimization by simulated annealing,” Science , May 1983.
․
Unit 9
Y.-W. Chang
36
Simulated Annealing Basics ․ ․
Non-zero Non-zero probab probabilit ility y for “up-hill “up-hill”” moves. moves. Probability depends on 1. 2.
․ ․ ․
Unit 9
magnitude magnitu de of the “up-hill “up-hill”” mov moveme ement nt total search time
∆C = cost (S ') ') - Cost (S )
T : Control parameter (temperature) Annealing schedule: T =T 0, T 1, T 2, …, where T i = r i T 0, r < 1.
Y.-W. Chang
37
Generic Simulated Annealing Algorithm 1 begin 2 Get an initial solution S ; 3 Get an initial temperature T > 0; 4 while not yet “frozen” do P do do 5 for 1 i P 6 Pick a random neighbor S ' of S ; ∆ cost (S ') 7 ') - cost (S ); ); /* downhill move */ if ∆ 0 then S S' 8 /* uphill move */ if ∆ > 0 then S S ' with probability 9 10 T rT ; /* reduce temperature */ 11 return S 12 end Unit 9
Y.-W. Chang
;
38
Basic Ingredients for Simulated Annealing Analogy:
․
Basic Ingredients for Simulated Annealing: Solution space ⎯ ⎯ Neighborhood structure ⎯ Cost function ⎯ Annealing schedule
․
Unit 9
Y.-W. Chang
39
B*-Tre B*Tree e Based Based Floorpl Floorplann anner er Rev Revisit isited ed Solution space: all feasible B*-trees Neighborhood structure: Find a new solution by
․ ․
⎯ ⎯ ⎯
Op1: rotate a block Op2: delete & insert Op3: swap 2 nodes
Cost function: area & wirelength Annealing schedule: T i = r i T 0, r = 0.9
․ ․
2
2 4 1 13 15
4
7
Op3(7, 3)
6 5
2
12 3
11
1
3
5 15
10
Op2(11, 5)
6
13
7
7
1
12 11 10
13
6 5
15 9
9
12 3
10
11
9 14
14
14
8
8 Unit 9
4
Y.-W. Chang
8 40
Approximation Algorithms Approximation algorithm: An algorithm that returns near-optimal solutions. Ratio (Performance) bound (n ): ): For any input size n , the cost C of the solution produced by an approximation algorithm ρ(n ) of the cost C * of an optimal solution:
․
․
⎯ ⎯
ρ(n )
1. An optimal algorithm has ratio bound 1.
Relative error bound (n ):
․
⎯
Unit 9
ε(n )
ρ(n ) - 1.
Y.-W. Chang
41
Greedy Vertex Cover Algorithm Revisited Greedy heuristic: cover as many edges as possible (vertex with the maximum degree) at each stage and then delete the covered edges. The greedy heuristic cannot always find an optimal solution!
․
․
⎯
The vertex-cover problem is NP-complete.
The greedy heuristic cannot guarantee a constant performance bound.
․
Unit 9
Y.-W. Chang
42
The Vertex-Cover Problem Approx-Vertex-Cover(G ) Approx-Vertex-Cover(G 1. C ; 2. E ' E [G ]; ]; 3. while E ' 4. 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 u or v ; 7. return C . ․
Unit 9
Time complexity: O (E ). ).
Y.-W. Chang
43
Approx-Vertex-Cover Has a Ratio Bound of 2
․ ․
․ ․
Let A denote the set of edges picked in line 4 |C | = 2|A 2|A|. Since no two edges in A share an endpoint, no vertex in any cover is incident on more than one edge in A. Thus, |A |A| |C *| and |C |C | 2 |C |C *|. Recall: For a graph G = (V, (V, E ), ), V ' is a minimum vertex cover V ' is a maximum independent set. ⎯
Unit 9
V -V
Is there any polynomial-time approximation with a constant ratio bound for the maximum independent set problem? Y.-W. Chang
44
Approximation Algorithm for TSP Approx-TSP-Tour(G Approx-TSP-Tour(G ) 1. select a vertex r V [G ] to b be e a “root “root”” vertex vertex;; 2. grow a minimum spanning tree T for T for G from G from root r using r using MST-Prim(G, MST-Prim(G, d, r ); ); 3. Let L be the list of vertices visited in a preorder tree walk of T ; 4. return the HC H that H that visits the vertices in the order L. ․
Unit 9
Time complexity: O (V V lg lg V ). ).
Y.-W. Chang
45
Approx-TSP-Tour with Triangle Inequality ․
․
Inter-city distances satisfy triangle inequality if for all vertices u, v, w V , d (u, w ) d (u, v ) + d (v, w ). ). Approx-TSP-Tour with triangle inequality has a ratio bound of 2. ⎯ ⎯
⎯
Unit 9
With triangle inequality: cost (H ) 2 cost of MST. Let H * denote an optimal tour. H * is formed by some tree plus an edge cost of MST cost (H *). Thus, cost (H ) ≤ 2 cost (H *).
Y.-W. Chang
46
TSP without Triangle Inequality ․
If P NP, there is no polynomial-time approximation algorithm with constant ratio bound ρ for the general TSP. ⎯
⎯
Suppose in contraction that there is such an algorithm A with a constant ρ. We will use A to solve HC in polynomial time. Algorithm for HC 1.
2. 3.
Unit 9
Convert G G = = (V, (V, E ) into an instance I I of of TSP with cities V (resulting in a complete graph G ' = (V, (V, E ')): ')):
Run A on I . If the reported cost ρ |V |, |, the then n retu return rn “Ye “Yes” s” (i. (i.e., e., G contains a tour that is an HC), else return “No.”
Y.-W. Chang
47
Correctness ․
․
․
If G has an HC: G contains a tour of cost | V | by picking edges in E , each with cost of 1. If G does not have an HC: any tour of G ' must use some edge not in E , which has a total cost of ≥ (ρ |V | + 1) + (|V | - 1) > ρ |V |. |. A guarantees to return a tour of cost ρ r cost of an A returns a cost ≤ ρ |V | if G contains an optimal tour HC; A returns a cost > ρ |V |, |, otherwise.
Unit 9
Y.-W. Chang
48