Let G(V,E) be an undirected graph. A Hamiltonian cycle is a cycle that visits each vertex v of G exactly once (except the first vertex, which is also the last vertex in the cycle).
Assume: There Exists an efficient algorithm that determines if a graph has a Hamiltonian cycle (returns True\False). Let's call this alg' D for Determine.
- Prove: There exists an efficient algorithm that returns a Hamiltonian Cycle.
My answer attempt
Assume D(G) = true
Let G'=G (Define G' a copy of G).
For each edge e in E:
G' = G' \ {e} // Remove e from G.
d_boolean = D(G') // Run D alg' on the new Graph.
if d_boolean = false
then G' = G' U {e} // restore e to graph (because e must be in the Hamiltonian Cycle)
// else d_boolean=true we do nothing because e is not an edge on the Hamiltonian Cycle
Return G'
My Question
As you can see, I have an idea of an algorithm to show that one exists. I feel it's the right direction... But how do I prove that this algorithm actually returns the Hamiltonian Cycle?