Presentation is loading. Please wait.

Presentation is loading. Please wait.

Odds and Ends HP ≤ p HC (again) –Turing reductions Strong NP-completeness versus Weak NP-completeness Vertex Cover to Hamiltonian Cycle.

Similar presentations


Presentation on theme: "Odds and Ends HP ≤ p HC (again) –Turing reductions Strong NP-completeness versus Weak NP-completeness Vertex Cover to Hamiltonian Cycle."— Presentation transcript:

1 Odds and Ends HP ≤ p HC (again) –Turing reductions Strong NP-completeness versus Weak NP-completeness Vertex Cover to Hamiltonian Cycle

2 Example: HP ≤ p HC Hamiltonian Path –Input: Undirected Graph G = (V,E) –Y/N Question: Does G contain a Hamiltonian Path? Hamiltonian Cycle –Input: Undirected Graph G = (V,E) –Y/N Question: Does G contain a Hamiltonian Cycle?

3 Specification of R(x) Consider any undirected graph G = (V,E) as input x R(x) will be a graph G’ = (V’, E’) where –V’ = V union {v} where v is not in V –E’ = E union {(v,w) | w in V} Argument that R(x) has polynomial size –We add exactly 1 node and |V| edges.

4 x is yes  R(x) is yes Suppose graph G has a Hamiltonian Path Let this path be v 1, v 2, …, v n We now argue that v 1, v 2, …, v n, v is a Hamiltonian Cycle in G’ –First, all nodes in V’ are included exactly once above or else v 1, v 2, …, v n would not be a HP in G –Since G’ has all the edges that G has, (v i,v i+1 ) is an edge in E’ for 1 ≤ i ≤ n-1 –Finally, since E’ contains edge (v,w) for all w in V, it must be the case that E’ contains edges (v n, v) and (v,v 1 ).

5 R(x) is yes  x is yes Suppose graph G’ has a Hamiltonian Cycle Let this cycle be v 1, v 2, …, v n, v We now argue that v 1, v 2, …, v n is a Hamiltonian Path in G –First, all nodes in V are included exactly once above or else v 1, v 2, …, v n, v would not be a HC in G’ –Since the only extra edges in E’ compared to E are edges involving node v, it must be the case that E contains edge (v i,v i+1 ) for 1 ≤ i ≤ n-1

6 Turing Reducibility Consider the following alternate reduction. Given graph G, output  (n 2 ) graphs G v,w = (V,E v,w ) where –E v,w = E union {(v,w)} where v,w are nodes in V This is not a polynomial-time reduction because we are outputting  (n 2 ) graphs. However, this idea can be used to show that if HC can be solved in polynomial time, then HP can be solved in polynomial time. –Run each graph G v,w through our procedure that solves HC. –If HC says yes for any one of these graphs, return yes. –Otherwise return no. This more general reduction is often called a Turing reduction. We allow ourselves to use the procedure that solves HC (or  2 ) a polynomial number of times rather than just once.

7 Number Problems Problems where the inputs are numbers –Prime number problem: Input: Integer n Yes/No Question: Is n prime? –Partition problem Input: Set S of n numbers {s 1, …, s n } Yes/No Question: Is there an S’ subset of S such that the sum of numbers in S’ = the sum of numbers in S – S’. What is the input size for these problems?

8 Knapsack Problem 0-1 Knapsack optimization problem –Input Capacity K n items with weights w i and values v i –Yes/No Question Find a set of items S such that –the sum of weights of items in S is at most K –the sum of values of items in S is maximized We gave a dynamic programming solution for this problem We showed that Partition ≤ p Knapsack on hw 8 Is this a contradiction?

9 Definining subproblems Define P(i,w) to be the problem of choosing a set of objects from the first i objects that maximizes value subject to weight constraint of w. –Impose an arbitrary ordering on the items V(i,w) is the value of this set of items Original problem corresponds to V(n, K)

10 Recurrence Relation/Running Time V(i,w) = max (V(i-1,w-w i ) + v i, V(i-1, w)) –A maximal solution for P(i,w) either uses item i (first term in max) or does NOT use item i (second term in max) V(0,w) = 0 (no items to choose from) V(i,0) = 0 (no weight allowed) What is the running time of this solution? –Number of table entries: –Time to fill each entry:

11 Example w A = 2 v A = $40 w B = 3 v B = $50 w C = 1 v C = $100 w D = 5 v D = $95 w E = 3 v E = $30 Weight Items

12 Weak NP-completeness An NP-complete problem is called “weakly NP- complete” if it has in its description one or more integer parameters and the corresponding problem where these parameters are represented in unary is in P. An NP-complete problem is strongly NP- complete if the problem is still NP-complete even if integer parameters are encoded in unary

13 Vertex Cover to Ham Cycle Edge Component: For every edge in the Minimum Vertex Cover problem, we create a component in the Hamiltonian Cycle Problem: v u u u v v

14 Observations…. u u v v u u v v u u v v There are only three possible ways that a cycle can include all of the vertices in this component. Key property: If a path enters v (u), it leaves on v’ (u’)

15 u u u u Node Selection u v v w w u x x All components that represent edges connected to node u are strung together into a chain. If there are V vertices, then we will have V of these chains, all interwoven. Choosing a node u corresponds to traversing such a chain

16 u v v v u u u u w w u x x y y v v z z v vu yw xz Vertex cover = (v,u)

17 u v v v u u u u w w u x x y y v v z z v vu yw xz Vertex cover = (v,w,x)

18 Tying the Chains Together If we want to know if its possible to cover the original graph using only k vertices, this would be the same as seeing if we can include all of the vertices using only k chains. How can we include exactly k chains in the Hamiltonian Cycle problem? We must add k extra vertices and connect each of them to the beginning and end of every chain. Since each vertex can only be included once, this allows k chains in the final cycle.

19 Beginning a Transform

20 The Final Transform for k=1


Download ppt "Odds and Ends HP ≤ p HC (again) –Turing reductions Strong NP-completeness versus Weak NP-completeness Vertex Cover to Hamiltonian Cycle."

Similar presentations


Ads by Google