4

Say you have an oracle that can determine (in a polynomial time) if there is a Hamilton path in a certain graph. (Reminder: the Hamilton path problem is in NPC).

Describe how to use the oracle in order to find a Hamilton path in a graph, in a polynomial time.

Any ideas?

Shlomi Kriheli
  • 330
  • 1
  • 8

2 Answers2

4

A Hamiltonian path visits every vertex exactly once.

If you have an oracle you can test removing each edge in turn. If the oracle says there is still a path then keep the edge deleted, otherwise restore the edge and try the next one.

Once you have gone through all edges, all that will be left will be the Hamiltonian path.

Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75
  • I'm not sure I understand. When you say we can remove each edge in turn - how do I know that I can necessarily remove an edge from the graph I have in hand? I mean, in some graphs, there might be a chance that even if I try to remove an edge, there still won't be a Hamiltonian path. So why do we remove edges? – Shlomi Kriheli Apr 15 '17 at 21:30
  • The idea is that we start with a graph with lots of edges. The oracle tells us that there is a Hamiltonian path - but not where it is. We try to simplify the graph as much as possible by removing edges while preserving the path. Once we have finished removing edges we will have a very simple chain graph which must be equal to the Hamiltonian path. You are right that sometimes removing an edge will remove the path, but in these cases we put the edge back again and try a different edge. – Peter de Rivaz Apr 15 '17 at 21:46
  • So the oracle actually gets a graph with a lot edges while we know for sure that this graph contains a Hamiltonian path in it, but we don't know where. Removing the edges, as you described, eventually leaves the graph only with the edges that are part of the Hamiltonian path. Right? – Shlomi Kriheli Apr 16 '17 at 08:06
1

If there are n - 1 edges in the graph, we're done (it must be a chain. Otherwise, there's no Hamiltonian path).

Otherwise, we can delete some edge. Let's iterate over all edges. If there's still a path in a graph without a fixed edge, we can remove it and move on.

This solution requires O (m^2) oracle queries, so it works in polynomial time.

kraskevich
  • 18,368
  • 4
  • 33
  • 45