1

The problem is testing whether a graph G contains a Hamiltonian path or not with the one use of hamiltonian cycle Hcycle(V,E) function which gives output true of false whether the G contains Hamiltonian cycle.

I must write a program with polynomial time complexity, which has to decide whether the unoriented graph G contains at least one Hamiltonian path with the use of one Hamiltonian Cycle function which has to give output to this problem.

Also I need to write a program with the opposite problem. (use of Hpath function to find out whether the graph contains Hemiltonian Cycle).

I can't find a solution to this problem. I can use both Hcycle and Hpath only once.

We assume that the function Hcycle and Hpath run in linear time complexity.

Serillan
  • 227
  • 2
  • 8

2 Answers2

0

Every hamiltonian cycle is a hamiltonian path, just break the cycle somewhere.

The other way around doesn't work quite easily. The brute-force solution is: for all hamiltonian paths p, check whether there is edge between start and end of p, if there is, make a cycle. However if HPath returns just some path, there is no way to make a cycle out of it (I guess).

Check Wikipedia

phadej
  • 11,947
  • 41
  • 78
  • The thing is graph G might contain Hamiltonian path and doesn't have to contain Hamiltion cycle. In this case your solution would be bad. – Serillan Nov 10 '13 at 15:35
  • for all hamiltonian paths p,check whether there is edge between start and end of p, *if there is*, make a cycle, *otherwise* there is no cycle. – phadej Nov 10 '13 at 15:37
  • My answer was to your first solution to the first problem. And the second as you have written: HPath returns just some path. – Serillan Nov 10 '13 at 15:45
0

Path by Hcycle(V,E): Call Hcycle() on a graph created by adding one vertex that is connected to all other vertices. If new graph has a cycle than removing new node from that cycle we get path on original graph.

Cycle by Hpath(V,E): Call Hpath() on a graph created by adding one vertex and connecting it to same neighbours as one existing vertex. That means these 2 vertices will have same naighbours. If new graph has a path than at least one path end is on these two vertices. If other vertex is not end, than it is on path third position and by reordering path we can set both vertices to be path end points. Merging these two vertices (since they have same neighbours) we get a cycle in original graph.

Path by Hcycle(V,E): If graph has cycle than it has path also. If graph doesn't have cycle than for each unconnected pair of vertices (v1, v2) add edge between them and check is there a cycle with Hcycle(V,E+(v1,v2)). If there is a cycle than there is a path between v1 and v2 in original graph. Hcycle is called max |V|^2 times.

Cycle by Hpath(V,E): Idea is to force a path to has end vertices we know about. That can be done by constructing graph where two vertices have degree one. Let N(v) be neighbours of v. For an edge (v1,v2) and n1 from N(v1)-v2 and n2 from N(v2)-v1 construct a graph by removing all edges from v1 except to n1, and removing all edges from v2 except to n2. If that graph has a path, than it's ends are on v1 and v2, and our original graph has a circle. Hpath is called max |E|*|V|^2 times.

Ante
  • 5,350
  • 6
  • 23
  • 46
  • Actually the problem is that I can use both Hcycle and Hpath only once. – Serillan Nov 11 '13 at 12:22
  • Are you sure about only one call? If that is a case, than in a graph with a path but without a cycle, you have to find path end points in polynomial time. Which sounds quite complex. – Ante Nov 11 '13 at 14:16
  • I know that's the problem, there must be some way to do it in polynomial time with the help of one call of this function. – Serillan Nov 11 '13 at 15:14
  • Usually, polynomial reduction of one problem to the other, means that solution of second problem can be calculated polynomial times to find solution of the first problem. That is used to show that first problem is in same complexity class as second. – Ante Nov 11 '13 at 16:03
  • I can't see why do you expect any of path ends in the doubled vertex (in Cycle by Hpath). Specifically, if augmented graph contains hamiltionian cycle, you can get path ends anywhere. You should rather add 2 more vertices connected each to one of doubled vertex copies, to enforce path ends there. – Frax Sep 01 '14 at 16:15