visited[] // array [0..nV-1] to keep track of visited vertices
hasHamiltonianPath(G,src,dest):
| for all vertices v∈G do
| visited[v]=false
| end for
| return hamiltonR(G,src,dest,#vertices(G)-1)
hamiltonR(G,v,dest,d):
| Input G graph
| v current vertex considered
| dest destination vertex
| d distance "remaining" until path found
|
| if v=dest then
| if d=0 then return true else return false
| else
| | visited[v]=true
| | for each (v,w)∈edges(G) ∧ visited[w] do
| | if hamiltonR(G,w,dest,d-1) then
| | return true
| | end if
| | end for
| end if
| visited[v]=false // reset visited mark
| return false
|