Hamiltonian Path is a path that connects all nodes without repeat and it is an NP-complete problem.
Is the Shortest Hamiltonian Path (SHP) NP-hard?
What is the difference between travelling salesman problem with SHP?
I assume the SHP problem is the Hamiltonian problem on the edge weighted graph. It is NP-hard because it is at least as hard as the Hamiltonian problem. Assume you have an algorithm to solve the SHP problem, then you apply the algorithm on a weighted graph with all edge weights are 1, it will solve the Hamiltonian problem with the same time complexity.
TSP requires to return to the original vertex and you can visit each vertex more one once. SHP asks for the path which visits every vertex exactly once.
Related
I know that if there are negative cost cycles in a graph, the relative shortest path problem belongs to the np-complete class. I need to prove this by performing a polynomial reduction using the Hamiltonian cycle problem. Could anyone explain it? It would be very helpful.
Given a directed graph with edges having -ve or +ve weights, what is the algorithms to find the smallest weight edges of all paths from vertex s to vertes d?
From Wikipedia
You are describing the Single Source shortest path problem. Which can be solved using Dijkstra's if the edges are only positive or Bellman-Ford if the edges are allowed to be negative as well.
The most important algorithms for solving this problem are:
Dijkstra's algorithm solves the single-source shortest path problem.
Bellman–Ford algorithm solves the single-source problem if edge weights may be negative.
A* search algorithm solves for single pair shortest path using heuristics to try to speed up the search.
Floyd–Warshall algorithm solves all pairs shortest paths.
Johnson's algorithm solves all pairs shortest paths, and may be faster than Floyd–Warshall on sparse graphs.
Viterbi algorithm solves the shortest stochastic path problem with an additional probabilistic weight on each node.
I would find all reachable from s, e.g. by depth first search. Then find all nodes that can reach d (equivalently, all nodes reachable from d in the graph with directions reversed). Now you want the smallest weight edges that start in the first set and end in the second set.
Note: This is almost the same questions as this: Shortest path to visit all nodes
But I have a complete graph.
Problem: Consider a complete undirected graph with nonnegative edge lengths. Question: Compute the shortest path that visits every node at least once.
NB: This is NOT the TSP problem. The path does not have an ending node and the path can pass through nodes more than once.
Other notes:
The number of nodes is small (less than 20).
Problem is still NP-Complete (for decision variant), with reduction from Hamiltonian Path Problem.
Given Hamiltonian Path Problem instance G=(V,E), reduce it to your problem with: G'=(V, E', w) and path length |V| - 1.
Where:
E' = VxV
w(u,v) = 1 if (u,v) is in E
w(u,v) = 2 otherwise
If there is a hamiltonian path in G, then there is a path in G' that costs |V| - 1.
If there is a path in G' that costs |V| - 1, then by following these edges in G, we get a Hamiltonian Paht.
Thus, the above is a polynomial reduction from Hamiltonian Path Problem to this TSP variant, and since Hamiltonian Path Problem is NP-Hard, so is this problem.
Claim
Allowing nodes to be revisited does not make the problem substantially easier.
Explanation
Suppose we wish to find a Hamiltonian path in a graph G. We can turn this into an instance of your problem by setting the edge weights to 1 for edges in G, and edge weights to 10 for edges not in G.
We now have a complete graph H with non-negative edges.
Graph G has a Hamiltonian path if and only if we find the shortest path in H is of length n-1.
Recommendation
Therefore your modified problem is NP-hard, so it seems unlikely that you can do better than simply adapting standard TSP techniques (such as the Held-Karp algorithm ) to solve it.
I have weights from 0 - 10. 0 is the shortest, 10 is longest.
Can I traverse the numbers, 10-x and use Dijkstra for shortest path?
In general finding longest path is NP.
In contrast to the shortest path problem, which can be solved in
polynomial time in graphs without negative-weight cycles, the longest
path problem is NP-hard, meaning that it cannot be solved in
polynomial time for arbitrary graphs unless P = NP.
https://en.wikipedia.org/wiki/Longest_path_problem
No. A cyclic graph will have paths of infinite length, and Dijkstra's marking of visited nodes will not allow you to find long paths.
Generally, finding the longest path kind of feels like a very hard problem.
I've read that the problem of finding whether a Hamiltonian path exists in a graph is NP-Complete, and since Dijkstra's Shortest Path Algorithm runs in Polynomial Time, it cannot be modified to find the shortest Hamiltonian path. (Is this logic valid?)
But what if you are given two nodes (say A and Z) on an undirected graph (with all edges having non-negative costs), and it is given that there is at least one Hamiltonian path with the given nodes (A and Z) as end points. Given these specifications, would it now be possible to modify Dijkstra's algorithm to find the shortest Hamiltonian path with A and Z as endpoints? (in Polynomial Time)
Note: I'm only concerned with finding the shortest Hamiltonian path from two nodes specifically. For example, if there is a graph containing 26 nodes (labelled A to Z), what is the shortest path that passes through all points but starts at A and ends at Z. (I'm not concerned with finding other Hamiltonian paths with different endpoints, just A and Z)
Additional question: If the answer is "No" but there is another algorithm that can be used to solve this, what algorithm is it, and what is its time complexity?
(Note: This question has "hamiltonian-cycle" as a tag, even though I'm looking for a Hamiltonian PATH, because I do not have enough rep to make the tag "hamiltonian-path". However, let's say A and Z is connected by exactly one edge, then the shortest Hamiltonian path can be found by finding the shortest Hamiltonian cycle and then removing the edge connecting A and Z)
No, this is not possible. Your simplified problem is still NP-hard. A reduction from travelling salesman:
Given a graph (V, E), find the shortest path that visits each v in V exactly once. Take an arbitrary vertex v in V. Split v into two vertices v_source and v_sink. Use your algorithm to find the shortest hamiltonian path P from v_source to v_sink. P is the shortest cycle starting and ending at v which visits each v in V. Since P is a cycle, the 'starting' vertex is irrelevant. Therefore, P is also the solution to the travelling salesman problem.
The reduction is obviously polynomial time (constant, actually), so your problem is NP-hard.
But what if you are given two nodes (say A and Z) on an undirected
graph (with all edges having non-negative costs), and it is given that
there is at least one Hamiltonian path with the given nodes (A and Z)
as end points. Given these specifications, would it now be possible to
modify Dijkstra's algorithm to find the shortest Hamiltonian path with
A and Z as endpoints? (in Polynomial Time)
How do you propose to modify it? This only works if there is a single path between A and Z and it visits all the other points on the graph. Otherwise, Dijkstra would terminate some shorter path that only visits some subset of the nodes. If there is a Hamiltonian path between A and Z, you could solve the longest path problem, but this is also NP-hard.