0% found this document useful (0 votes)
291 views

Hamilton Cycle

The document defines and provides an algorithm for finding a Hamiltonian cycle in a graph. A Hamiltonian cycle is a round trip path that visits each vertex exactly once and returns to the starting vertex. The algorithm takes a graph as input and defines a solution vector to represent the order of visited vertices. It initializes the first vertex and then recursively tries different options for the next vertex, checking that an edge exists and the vertex has not been visited before. If a full cycle is generated without violations, it is printed as the solution.

Uploaded by

Srinivasulu S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
291 views

Hamilton Cycle

The document defines and provides an algorithm for finding a Hamiltonian cycle in a graph. A Hamiltonian cycle is a round trip path that visits each vertex exactly once and returns to the starting vertex. The algorithm takes a graph as input and defines a solution vector to represent the order of visited vertices. It initializes the first vertex and then recursively tries different options for the next vertex, checking that an edge exists and the vertex has not been visited before. If a full cycle is generated without violations, it is printed as the solution.

Uploaded by

Srinivasulu S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

HAMILTONIAN CYCLES:

• Let G=(V,E) be a connected graph with ‘n’ vertices. A


HAMILTONIAN CYCLE is a round trip path along ‘n’
edges of G which every vertex once and returns to its
starting position.

• If the Hamiltonian cycle begins at some vertex V1


belongs to G and the vertex are visited in the order of
V1,V2…….Vn+1,then the edges are in E,1<=I<=n and the
Vi are distinct except V1 and Vn+1 which are equal.
 
Consider an example graph G1:

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);
}

You might also like