0% found this document useful (0 votes)
13 views

Ham Path Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Ham Path Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Hamiltonian Path is NP-Complete

CSC 463
March 5, 2020

1 Hamiltonian Path
A graph G has a Hamiltonian path from s to t if there is an s to t path that visits all of the vertices
exactly once. Similarly, a graph G has a Hamiltonian cycle if G has a cycle that uses all of its vertices
exactly once. We will prove that the problem D-HAM-PATH of determining if a directed graph has an
Hamiltonian path from s to t is NP-Complete.
Theorem 1. D-HAM-PATH is NP-Complete.
Proof. Let G be a directed graph. We can check if a potential s, t path is Hamiltonian in G in polynomial
time. Now, we will give a polynomial-time reduction 3SAT ≤p D-HAM-PATH to complete the proof of
completeness. Vm
Suppose a conjunctive normal form formula φ = i=1 φi has n variables and m clauses. To simplify the
proof, we may assume that no clause in φ contains both a variable xi and its negation xi , since any clause
containing both literals can be removed with φ without affecting its satisfiability. The reduction uses the
following steps.

1. First, for every variable xi , we generate 2m+1 vertices labelled vi,j and add directed edges (vi,j , vi,j+1 )
and (vi,j+1 , vi,j ) for 0 ≤ j ≤ 2m.

2. Next, we connect vertices associated to different variables by adding four directed edges (vi,0 , vi+1,0 ),
(vi,0 , vi+1,2m+1 ), (vi,2m+1 , vi+1,0 ), (vi,2m+1 , vi+1,2m+1 ).
3. Next, we create a vertex labelled cj . If xi appears in clause φj positively, add directed edges (vi,2j−1 , cj )
and (cj , vi,2j ). Otherwise, if xi appears negatively in clause φj , add directed edges (vi,2j , cj ) and
(cj , vi,2j−1 ).

4. Finally, we add two extra vertices s and t connect s by adding (s, v1,1 ), (s, v1,2m+1 ) and connect t by
adding (vn,1 , t) and (vn,2m+1 , t). Call the graph generated Gφ . See Figure 1 for what the resulting
graph looks like.

Now, we have to show that φ is satisfiable if and only if there is Hamiltonian path in Gφ from s to t.
Suppose φ is satisfiable. Then we can visit each variable vertex starting from s by going from vi,0 to vi,2m+1
from left to right if xi is assigned true, and going from vi,2m+1 to vi,0 from right to left if xi is assigned
false, and ending at t after vn,0 or vn,2m+1 is visited. Furthermore, each clause vertex can be visited since
by assumption, each clause φi has some literal li = xk or li = xk that is assigned true. Each vertex cj by
can visited by using the edges (xk,2j−1 , cj ) and (cj , xk,2j ) in the first case, and (xk,2j , cj ) and (cj , xk,2j−1 ) in
the second case, since the path goes right in the graph for variables assigned true and the path goes left for
variables assigned false. Thus, Gφ has a Hamiltonian path if φ is satisfiable.
Conversely, suppose Gφ has an (s, t) Hamiltonian path P . Notice that Gφ without the clause vertices is
Hamiltonian so we need to show that a path doesn’t “get stuck” after visiting a clause vertex. More formally,
it suffices to show that if P visits vi,2j−1 , cj , v in that order, then v = vi,2j . Suppose v 6= vi,2j . Then notice
that the only vertices coming into vi,2j are vi,2j−1 , cj , vi,2j+1 and the only vertices coming out of vi,2j are to
vi,2j−1 and vi,2j+1 . Hence vi,2j must be visited coming in from vi,2j+1 , but now the path is stuck and cannot
continue since vi,2j−1 has already been visited. A similar argument shows that if P visits vi,2j , cj , v in that

1
Figure 1: Reduction from 3SAT to HAM-PATH

order, then v = vi,2j−1 . So a Hamiltonian path in Gφ visits variable vertices in order from the vertices for x1
to the vertices for xn , interleaving the clause vertices in between variables associated to the same variable.
Therefore, an assignment to the variables xi is well defined by noticing which direction the path takes along
the variable vertices for xi in Gφ . By construction, this assignment will satisfy φ since the assignment makes
a literal in each clause true.
The reduction runs in O(mn) time which is a polynomial in the length of the input.

2 Hardness of Approximation for TSP


Once we have proved that the directed Hamiltonian path problem is NP-Complete, then we can use further
reductions to prove that the following problems are also NP-Hard:
• Finding a Hamiltonian path in an undirected graph (by reduction from the directed problem).
• Finding a Hamiltonian cycle in an undirected graph (by reduction from Hamiltonian path).
• Finding a minimum weight Hamiltonian cycle in an weighted, complete graph (by reduction from the
previous problem).
The last problem is also known as the Travelling Salesperson Problem (TSP). It is given that name
since it models the following situation. Given a list of cities and some cost of travelling between each pair of

2
cities (eg. airfare, distance), then a minimum weight Hamiltonian cycle in this graph is a path visiting all of
the cities exactly once and returns the origin city with least cost.
TSP is a problem that arises in many applications, so while we do not expect to find an efficient algorithm
for it due of its NP-hardness, researchers have developed approximation algorithms to solve the problem
in certain special cases. This is a general approach when facing NP-hard search problems. We cannot expect
to find an optimal solution in polynomial time so all we can hope for is to find a good enough approximation
in reasonable time. Unfortunately, there are hardness of approximation results that state that even
searching for an approximation is impossible in polynomial time assuming that P 6= NP.
Theorem 2. Assuming that P 6= NP, there is no polynomial time algorithm that when given a weighted
graph finds a TSP tour that is at most 2 times the shortest tour.
Proof. Let G be an undirected graph with n vertices. We generate a weighted complete graph H based on
G with weights wij = 1 if edge (i, j) exists in G, and weight wij = n + 2 if no edge (i, j) exists in G. Observe
that the shortest TSP tour in H has weight n if G has a Hamiltonian cycle, and otherwise, H has weight at
least 2n + 1.
Hence, if there is an polynomial time algorithm A that 2-approximates a TSP tour in H, we can decide if
G has a Hamiltonian cycle or not, since G has a Hamiltonian cycle iff A outputs a number less than or equal
to 2n. Therefore, if A runs in polynomial-time, we can decide if an undirected graph has a Hamiltonian
cycle in polynomial time, which is impossible assuming P 6= NP.
Now assume that the weights in a TSP instance satisfy the triangle inequality wij ≤ wik + wkj given
vertices i, j, k. We call this new problem Metric-TSP when the weights have this constraint, and note that
it is still NP-hard by reduction by undirected Hamiltonian cycle. However, with this restriction, we can
now find a 2-approximation using the following algorithm.
Algorithm 1. Given a metric TSP instance G,
1. Firstly find a minimum weight spanning tree T in G.
2. Then add a parallel edge to each edge (u, v) in the tree T , and find an Euler cycle E (a cycle visiting
each edge exactly once) using these parallel edges.
3. Convert the Euler cycle E in the previous step into a Hamiltonian cycle H by skipping vertices that
have already been visited. (Eg. if the Euler tour visits v1 , v2 , v1 , v3 . . . , the Hamiltonian cycle visits
v1 , v2 , v3 , . . . )
Note that each step runs in polynomial time and the algorithm is guaranteed to terminate, since we know
that an Euler tour in a graph exists iff each vertex is adjacent to an even number of edges. Now we argue
that this algorithm provides a 2-approximation.
Theorem 3. Metric-TSP can be 2-approximated.
Proof. Let w(H), w(E), w(T ) be the total weight of the Hamiltonian cycle, Euler tour, and minimum span-
ning tree produced by the algorithm, and let O be the optimal TSP tour and w(O) be its weight.
We know that w(H) ≤ w(E) since skipping edges always reduces the weight using the triangle inequality.
Next, we have that w(E) = 2w(T ) since the Euler tour was created by doubling each edge in T . Finally, we
have w(T ) ≤ w(O) since deleting an edge from O produces a spanning tree, and we know that w(T ) is the
weight of the minimum spanning tree.
Hence, combining these inequalities together:

w(H) ≤ w(E) = 2w(T ) ≤ 2w(O),


which means that we have produced a Hamiltonian cycle H of weight at most 2 times the shortest
cycle.
In fact, it is known that Metric-TSP can be 32 -approximated, but improving this approximation only
with the metric assumption has remained an open problem for around 45 years. Adding additional assump-
tions such as assuming that the metric is the usual Euclidean metric in Rd , not just an arbitrary metric
satisfying the triangle inequality, also improves the approximation factor.

You might also like