2

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)

DarkPotatoKing
  • 499
  • 2
  • 9
  • 17
  • 1
    You can use anything to solve anything; it's just that in this case you can't have a [polynomial time reduction](http://en.wikipedia.org/wiki/Polynomial-time_reduction) –  Jun 25 '14 at 00:06
  • 3
    In your first sentence: if "do P and NP coincide?" can be answered with "yes", then your logic is valid. –  Jun 25 '14 at 00:15
  • 1
    There are many NP problems that can be solved in polynomial times when some special condition applies in the problem. This is because sometimes, NP problems are NP problems on their most generic field of application. But when you start to put hypothesis, there can be simplifications. You have multiple "given" in your question, so you stand a chance. – v.oddou Jun 25 '14 at 00:31
  • Currently I'm interpreting the question as "Can I find the shortest Hamiltonian path in a graph (knowing that there exists one) faster than I can find _any_ Hamiltonian path in a graph." Is that about right? – Mooing Duck Jun 25 '14 at 00:35
  • @MooingDuck 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) – DarkPotatoKing Jun 25 '14 at 00:43
  • @MooingDuck since finding a Hamiltonian path is NP and I'm looking for a solution that runs in polynomial time, then as a consequence "yes", but that's not my concern. (sorry if it's confusing) – DarkPotatoKing Jun 25 '14 at 00:48
  • @DPKing: I take it back, you're right, because you can immediately discard N-1 possible end points, making your algorithm an order of magnitude faster than the general algorithm. Of course, it wasn't polynomial to start with so that's not overly helpful. – Mooing Duck Jun 25 '14 at 00:54
  • The question is how much modification is allowed to qualify as a "modified" version of Dijkstra's algorithm versus a complete new beast? – Tarik Jun 25 '14 at 01:14
  • 1
    This question appears to be off-topic because it is about graph theory. It is an interesting question, but I think it would be better suited for http://math.stackexchange.com – Barranka Jun 25 '14 at 01:19
  • @DPKing I can tell you I tried to find a solution to a problem like this some years ago... and I gave up :( (I'll be following this question, just in case someone writes a good solution) – Barranka Jun 25 '14 at 01:20
  • @Tarik I think I worded it incorrectly, what I really needed is just a solution for the problem that can be run in polynomial time, it's just that the first idea that popped into my mind was to modify dijkstra's, but if there is another way to solve it aside from dijstra's, then it's fine – DarkPotatoKing Jun 25 '14 at 01:23
  • @Barranka I wasn't sure where to put this. I've learned about graphing theory in my programming classes, not Math, so I'm more biased to think that it's a programming problem and not math. I thought it belonged here because it has something to do with Time Complexities, which I think is a programming concept. – DarkPotatoKing Jun 25 '14 at 01:29
  • 1
    Might also be a better fit at [Theoretical Computer Science](http://cstheory.stackexchange.com/). – Brad Koch Jun 25 '14 at 02:52
  • Shortest Hamiltonian path? Sure, just solve the traveling salesman and here it is. – n. m. could be an AI Jun 25 '14 at 05:33

2 Answers2

1

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.

dfb
  • 13,133
  • 2
  • 31
  • 52
1

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.

Vincent van der Weele
  • 12,927
  • 1
  • 33
  • 61