0% found this document useful (0 votes)
9 views17 pages

Graph Theory Lec Hamiltonian Cycle 03

The document discusses Hamiltonian cycles in connected graphs, defining them as round-trip paths that visit every vertex exactly once. It describes a backtracking approach to find Hamiltonian cycles, detailing the process of selecting adjacent vertices and backtracking upon reaching dead ends. An example illustrates the step-by-step selection of vertices to successfully identify a Hamiltonian cycle in a given graph.

Uploaded by

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

Graph Theory Lec Hamiltonian Cycle 03

The document discusses Hamiltonian cycles in connected graphs, defining them as round-trip paths that visit every vertex exactly once. It describes a backtracking approach to find Hamiltonian cycles, detailing the process of selecting adjacent vertices and backtracking upon reaching dead ends. An example illustrates the step-by-step selection of vertices to successfully identify a Hamiltonian cycle in a given graph.

Uploaded by

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

Graph Theory

Hamiltonian Cycle
Hamiltonian Cycle
● Let G = (V, E) be a connected graph with n vertices.
● A Hamiltonian cycle is a round-trip path along n edges of G that
visits every vertex once and returns to its starting position.
● Formally, Hamiltonian cycle begins at some vertex V1 ∈ V and
the vertices of G are visited in the order V1,V2,...,Vn+1, then the
edges (Vi, Vi+1) are in E, 1 <=i<=n, and the Vi are distinct except
for V1 and Vn+1, which are equal.
● How to find the Hamiltonian Cycle for a given graph G?
● We will use the backtracking approach to find such a cycle.
Hamiltonian Cycle: Backtracking
Approach
● We start out search from any arbitrary vertex, say x.
● This vertex ‘x’ becomes the root of our implicit tree.
● The next adjacent vertex is selected on the basis of alphabetical
or numerical order.
● If at any stage an arbitrary vertex, say ‘y’ makes a cycle with
any vertex other than vertex ‘o’ then we say that dead end is
reached. In this case we backtrack one step and again the
search begins by selecting another vertex.
● It should be noted that, after backtracking the element from the
partial solution must be removed.
● The search using backtracking is successful if a Hamiltonian
cycle is obtained.
Example
● Given the following graph G: find the
Hamiltonian circuit using backtracking method.
Example
● Initially we start out search with
vertex ‘1’ the vertex ‘1’ becomes the
root of our implicit tree.
Example
● Initially we start out search with
vertex ‘1’ the vertex ‘1’ becomes the
root of our implicit tree.
● Next we choose vertex ‘2’ adjacent to
‘1’, as it comes first in numerical
order (2, 3, 4).
Example
● Initially we start out search with
vertex ‘1’ the vertex ‘1’ becomes the
root of our implicit tree.
● Next we choose vertex ‘2’ adjacent to
‘1’, as it comes first in numerical
order (2, 3, 4).
● Next vertex ‘3’ is selected which is
adjacent to ‘2’ and which comes first
in numerical order (3,5).
Example
● Initially we start out search with
vertex ‘1’ the vertex ‘1’ becomes the
root of our implicit tree.
● Next we choose vertex ‘2’ adjacent to
‘1’, as it comes first in numerical
order (2, 3, 4).
● Next vertex ‘3’ is selected which is
adjacent to ‘2’ and which comes first
in numerical order (3,5).
● Next we select vertex ‘4’ adjacent to
‘3’ which comes first in numerical
order (4, 5).
Example
● Initially we start out search with
vertex ‘1’ the vertex ‘1’ becomes the
root of our implicit tree.
● Next we choose vertex ‘2’ adjacent to
‘1’, as it comes first in numerical
order (2, 3, 4).
● Next vertex ‘3’ is selected which is
adjacent to ‘2’ and which comes first
in numerical order (3,5).
● Next we select vertex ‘4’ adjacent to
‘3’ which comes first in numerical
order (4, 5).
● Next vertex ‘5’ is selected. If we
choose vertex ‘1’ then we do not get
the Hamiltonian cycle.
Example
● The vertex adjacent to 5 is 2, 3, 4 but
they are already visited. Thus, we get
the dead end.
● So, we backtrack one step and
remove the vertex ‘5’ from our partial
solution.
● The vertex adjacent to ‘4’ are 5,3,1
from which vertex ‘5’ has already
been checked and we are left with
vertex ‘1’
● However, by choosing vertex ‘1’ we
do not get the Hamiltonian cycle. So,
we again backtrack one step.
Example
● Hence we move to 3 and select the
vertex ‘5’ adjacent to ‘3’.
● The vertex adjacent to ‘5’ are (2,3,4)
so vertex 4 is selected.
Example
● Hence we move to 3 and select the
vertex ‘5’ adjacent to ‘3’.
● The vertex adjacent to ‘5’ are (2,3,4)
so vertex 4 is selected.
● The vertex adjacent to ‘4’ are (1, 3, 5)
so vertex ‘1’ is selected.
● Hence we get the Hamiltonian cycle
as all the vertex other than the start
vertex ‘1’ is visited only once, 1- 2- 3-
5- 4- 1.
Example
● The final implicit tree for the Hamiltonian circuit is shown here.
● The number above each node indicates the order in which
these nodes are visited.
Algorithm:Hamiltonian Cycle
Algorithm:Hamiltonian Cycle
Exercise
● Determine the order of magnitude of the worst-
case computing time for the backtracking
procedure that finds all Hamiltonian Cycles?
Exercise
● Which Graph Contains a Hamiltonian Cycle?

You might also like