Hamilton Cycle
Hamilton Cycle
1-2-3-4-5-6-1
1-2-6-5-4-3-1
1-6-2-5-4-3-1
Few graphs which are not hamiltonian Cycle.
Procedure:
Define a solution vector X(Xi……..Xn) where Xi represents the I th visited
vertex of the proposed cycle.
1. Create a cost adjacency matrix for the given graph.
2. The solution array initialized to all zeros except X(1)=1,b’coz the cycle
should start at vertex ‘1’.
3. Now we have to find the next vertex to be visited in the cycle.
4. The vertex from 1 to n are included in the cycle one by one by checking 2
conditions,
i.There should be a path from previous visited vertex to current vertex.
ii..The current vertex must be distinct and should not have been visited
earlier.
6. When these two conditions are satisfied the current vertex is included in
the cycle, else the next vertex is tried.
7. When the nth vertex is visited we have to check, is there any path from
nth vertex to first 8vertex. if no path, the go back one step and after the
previous visited node.
8. Repeat the above steps to generate possible Hamiltonian cycle.
Algorithm Algorithm Nextvalue (k)
{
Repeat
Algorithm Hamiltonian (k) {
{ X [k]=(X [k]+1) mod (n+1); //next vertex
Loop If (X [k]=0) then //No Next Vertex
Next value (k) return;
If (x (k)=0) then If (G [X [k-1], X [k]] 0) then //if there an edge
return; {
If k=n then for j=1 to k-1 do // Check for distinction
Print (x) if (X [j]=X [k]) then break;
Else .
Hamiltonian (k+1); If (j=k) then //if true then the vertex is distinct.
End if If ((k<n) or ((k=n) and G [X [n], X [1]] 0)) then
} //if there is edge between last and first
Repeat return;
} }
} Until (false);
}