In the general case, since the problem (solution of the version) of the Hamiltonian Put is NP-complete, you cannot hope to get a polynomial time algorithm for finding the Hamiltonian paths. You can speed it up a bit with regular N! β N 2 2 N dynamic programming trick (compute hp [v] [w] [S] = "is there a path that has endpoints v and w and the vertices are a subset of S" for each subset S and every two vertices v and w in it using DP), but it is still exponential.
However, there are many special types of graphs for which Hamiltonian paths always exist, and they can be easily found (see the work of Pos, Dirac, Ore, etc.)
For example, the following is true: if each vertex of the graph has a degree of at least n / 2, then the graph has a Hamiltonian path. In fact, you can find it in O (n 2 ), or IIRC even O (n log n) if you do it more smartly.
[Rough sketch: firstly, just connect all the vertices in some βHamiltonianβ cycle, it doesnβt matter if the edges are actually in the graph. Now for each edge (v, w) of your cycle, which is actually not on the graph, we consider the rest of the cycle: v ... w. Since deg (v) + deg (w)> = n, in your list (in this order) there are consecutive x, y such that w is a neighbor of x and v is a neighbor of y. [Evidence. Consider the {set of all neighbors w} and {the set of all successors in your list of neighbors v}; they should intersect.] Now change your cycle [v ... xy ... wv] to [vy ... wx ... v], instead it has at least one less invalid edge, so you need at most n iterations to get the true Hamiltonian cycle. Read more here .]
BTW: if what you are looking for is just a walk that includes all edges once, it is called Eulerian wandering and for graphs having it (the number of vertices of an odd degree is 0 or 2), you can quite easily find it in polynomial time (fast).
source share