Shortest path to visit all nodes in a complete directed graph - algorithm

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.

Related

Undirected weighted graph in polytime

I'm attending a master course in Algorithm for Bioinformatics, and I'm trying to solve some exercise in order to pass the exam. I'm stuck in this problem and I don't understand in which way I have to solve it. Could you help?
Thanks the next few lines are the exercise:
Argue whether you believe that the following problem has a polynomial time algorithm
Input: A complete undirected graph G with non-negative weights on the edges, and a weight bound W.
Solution: A simple path with the maximum possible number of vertices among all paths in G of weight < W.
This is NP-Hard, and thus there is no known polynomial solution to it.
It is easy to reduce this problem from the Hamiltonian Path problem1.
Given a graph G=(V, E), create:
G' = (V, E', w)
Where:
E' = VxV (all edges)
w(u,v) = 1 if (u,v) is in E
2 otherwise
Now, G' has a valid solution with |V| maximal weight if and only if G is hamiltonian.
(->) If 'G' is hamiltonian, then there is a path v1->v2->...->vn. Weights of all these edges is 1, so total weight in G' is |V|-1, making it maximal and valid.
(<-) If there is a path in G' with value<|V|, and we know it is maximal - so if it goes through all vertices - it cannot have edges with w(u,v)=2 (otherwise it will exceed the maximal weight). Then, this path is hamiltonian in G.
(1) A hamiltonian path is a simple path that goes through all vertices in the graph. If a graph has such a path, we call it a hamiltonian graph. The Hamiltonian Path Problem is finding if a graph is hamiltonian or not.

Show np-completeness of Disjoint Hamiltonian Path

Consider the problem of Disjoint Hamiltonian Path:
Input: A graph which may be directed or undirected
Output: Does this graph exist at least 2 Hamiltonian Paths that are edge-disjoint?
Edge-disjoint means that no single edge is shared by two paths.
Show that Disjoint Hamiltonian Path is np-complete.
I have been told that this problem is np-complete, but I couldn't prove it is np-hard. I tried reducing the original Hamiltonian Path and Hamiltonian Cycle to this problem but I couldn't think of a solution.
I came up with the following reduction, not sure if it's the simplest but it is simple.
Suppose G is an undirected graph corresponding to an instance of HP.
Now construct a new graph G' in the following way:
Keep every vertex from G.
For every edge (u,v) in G, create 4 additional vertices and connect them in the following way :
Now it is easy to see that if G has a Hamiltonian path, G' will have two edge-disjoint Hamiltonian paths, because every edge was replaced by some subgraph which itself has two edge-disjoint Hamiltonian paths (go straight or take the curvy edges). And if G' has a HP, then so does G because once you enter the subgraph corresponding to one of the original edges you have no choice but to get out of it on the other end, which corresponds to taking the original edge in G. The only "problem" that could occur is if the path were to start or end inside one of these subgraphs, but then we can just ignore the small part of the path which is inside and still get a HP for G.
And notice that G' has a HP => G has a HP => G' has two edge-disjoint HPs. Thus, G has a HP <=> G' has two edge-disjoint HPs.
The transformation can obviously be done in poly-time, thus your problem is NP-Hard.
The directed case is similar, just direct the edges in the transformed graph accordingly.

Maximum weight path with restricted weights

We know that finding a maximum weight path between two vertices is np-hard. But if we restrict edge weights, for eg. all edge weights are less than some particular value x. I am defining problem below clearly.
I have a directed graph G(V,E) in which weight of every edge is between 1 and |V|. I want to find maximum weight path between the two vertices u and v.
Is this problem polynomial-time solvable?
I am afraid your restricted problem is still NP-hard because finding the longest simple path is NP-complete even if the weights are all equal to 1.
A proof is on wikipedia:
The NP-hardness of the unweighted longest path problem can be shown using a reduction from the Hamiltonian path problem: a graph G has a Hamiltonian path if and only if its longest path has length n − 1, where n is the number of vertices in G. Because the Hamiltonian path problem is NP-complete, this reduction shows that the decision version of the longest path problem is also NP-complete. In this decision problem, the input is a graph G and a number k; the desired output is "yes" if G contains a path of k or more edges, and no otherwise.[1]
If the longest path problem could be solved in polynomial time, it could be used to solve this decision problem, by finding a longest path and then comparing its length to the number k. Therefore, the longest path problem is NP-hard. The question "does there exist a simple path in a given graph with at least k edges" is NP-complete.

Is it possible to use Dijkstra's Shortest Path Algorithm to find the shortest Hamiltonian path? (in Polynomial Time)

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.

Shortest path visiting all nodes without going back to start

Let's say that we have an arbitrary set of nodes and we want the shortest path between the nodes AND we have to visit all the nodes in the graph. It's sort of Travelling Salesman Problem but without going back to the start node again. Assume that we can start from any arbitrary node and end at any arbitrary node (except the starting node), but we have to visit all the nodes in the graph. Is the complexity the same as the Travelling Salesman Problem i.e NP-hard? Is there any known algorithm to solves this problem?
This is still TSP, and is NP-Hard. The algorithms that work on TSP will work on this one as well. Note that the fact that you "do not care" what is the starting node is insignificant, because by trying all possibilities, you multiply the complexity by n.
The reduction from Hamiltonian Path Problem to this problem is fairly trivial:
Given a graph G=(V,E), create a new weighted graph with G'=(V,E',w), where:
E' = V x V (all edges are there)
w(u,v) = 1 if (u,v) is in E
w(u,v) = 2 else
Now, the original graph G has a Hamiltonian Path if and only if shortest path that goes through all vertices is of length |V|.

Resources