Homework #31 Sample Solution
Total Page:16
File Type:pdf, Size:1020Kb
Homework #31 sample solution:
9-15.
Problem: Hamiltonian path Input: A graph G, and vertices s and t Output: Does G contain a path which starts from s, ends at t, and visits all vertices without visiting any vertex more than once?
To prove Hamiltonian path is NP-complete, we show that Hamiltonian path is both in NP and NP-hard (by reducing Hamiltonian cycle to Hamiltonian path).
Hamiltonian path is in NP because we have a polynomial-time verifier with a path as certificate. The verifier will check if the path is a Hamiltonian path.
To show Hamiltonian path is NP-hard, we reduce Hamiltonian Cycle to it: Let G = (V, E) be a directed graph. Take any vertex u in V, let V’ = V – { v } U { v1, v2 } and
E’ = E U { (v1, u) | (v, u) in E } U { (u, v2, u) | (u, v) in E}. Let G’ = (V’, E’). It’s obvious that G’ can be constructed in polynomial time.
Claim: G has a Hamiltonian cycle iff G’ has a Hamiltonian path.
Proof of the claim is omitted here.