Hamiltonian Cycles
description
Transcript of Hamiltonian Cycles
HAMILTONIAN CYCLES
Vesal HakamiOctober 30, 2010
2
Hamiltonian Cycles Demystified
• Brief History• Basic Definitions, Initiatives, Sufficient
Conditions, A Backtracking Algorithm • Chiba & Nishezeki’s Linear
Implementation for Internally 4-Connected Plane (I4CP) Graphs (Journal of Algorithms, 1989 – Elsevier)
3
History• Icosian game invented by Sir. William Rowan Hamilton (1805–
1865) in 1857 and sold to a London game dealer in 1859 for 25 pounds.
• Game Description: The corners of a regular dodecahedron are labeled with the names of cities; the task is to find a circular tour along the edges of the dodecahedron visiting each city exactly once.
• Solution Model: Hamiltonian cycle; i.e. look for a cycle in the corresponding dodecahedral graph which contains each vertex exactly once.
The Platonic Solid used in Icosian game;the corresponding Hamiltonian cycle is designated by darkened edges.
4
Basic Definitions
• Hamiltonian Path: A Hamiltonian path is a path (and not a cycle) in G that contains each vertex. It is possible, however, for a graph to have a Hamiltonian path without having a Hamiltonian cycle.
Remarks:• There is no helpful connection between the idea of Eulerian circuits (or
trails) and Hamiltonian cycles (or paths).• There do not exist necessary and sufficient* conditions on a graph G
that guarantee the existence of a Hamiltonian cycle (path).• One may resort to trial and error for particular graphs along with a
number of helpful observations.
• Hamiltonian Cycle: If G = (V, E) is a graph or multi-graph with |V|>=3, we say that G has a Hamiltonian cycle if there is a cycle in G that contains every vertex in V.
Hamiltonian path Hamiltonian cycle
* Necessary and Sufficient Conditions for Hamiltonian based on Linear Diophantine Equation Systems with Cycle Vector, 2009 3rd Intl. Conf. on Genetic and Evolutionary Computing.
5
Example I- A Connected Graph with no Cycle of Odd Length
• Does G contain a Hamiltonian path?• Starting from vertex a, alternatively label each vertex and its
adjacents with x’s and y’s. If G is to have a Hamiltonian path, there must be an alternating sequence of five x's and five y's.
• Recall: A graph G = (V, E) is bipartite iff it contains no cycle of odd length.
G (no cycle of odd length)
x-y vertex labeling
4 x’s and 5 y’s No Hamiltonian pathG is, in fact, a bipartite graph
6
Helpful Hints on Finding Hamiltonian Cycles
The complete graph Kn is Hamiltonian.
If G = (V, E) has a Hamiltonian cycle, then for all vV, deg(v) 2.
If a V and deg(a) = 2, then the two edges incident with vertex a must appear in every Hamiltonian cycle for G.
If a V and deg(a) > 2, then as we try to build aHamiltonian cycle, once we pass throughvertex a, any unused edges incident with a aredeleted from further consideration.
In building a Hamiltonian cycle for G, we cannotobtain a cycle for a sub-graph of G unless itcontains all the vertices of G.
7
Example II- Tournament Graphs• Theorem. A complete digraph (called a tournament)- in which for each distinct pair x, y
of vertices, exactly one of the edges (x, y) or (y, x) is in - always contains a (directed) Hamiltonian path.
• Proof: • Let m 2 with Pm a path containing the m-1 edges (v1, v2), (v2, v3), .... (vm-1, vm).• if m = n, we're finished.• If not,
– let v be a vertex that does not appear in Pm. – If (v, v1) is an edge in , we can extend Pm by adjoining this edge.– If not,
• (v1, v) must be an edge.
• Suppose that (v, v2) is in the graph.
• We have the larger path: (v1, v), (v, v2), (v2, v3), ..., (vm-1, vm).
• If (v, v2) is not an edge in , then (v2, v) must be.
– Continue this process; there are only two possibilities:• (a) For some 1 k m-1, the edges (vk, v), (v, vk+1) are in and we replace (vk, vk+1) with this pair of edges.
• (b) (vm, v) is in and we add this edge to Pm.
• Either case results in a path Pm+1 that includes m+1 vertices and has m edges.
– Repeat this process until we have a path Pn on n vertices.
8
Hamiltonian Path: Sufficient Condition
• Theorem. Let G= (V, E) be a loop-free graph with |V|= n 2. If deg(x) + deg(y) n - 1 for all x, y V, x y, then G has a Hamiltonian path.
• Proof. • I) Connectivity (Proof by Contradiction): G consists of two components C1 (|
C1| = n1) and C2 (|C2| = n2). Let x C1 and y C2. Obviously, deg(x) n1 - 1 and deg(y) n2 - 1; that is, deg(x) + deg(y) (n1 + n2) – 2 n - 2, contradicting the condition given in the theorem; thus, G is connected.
• II) Hamiltonian path construction: – For m 2, let Pm be the path {v1, v2}, {v2, v3}, ... , {vm-1, vm} of length m - 1.
– If v1 is adjacent to any vertex v other than v2, v3, ..., vm, we add the edge {v, v1} to Pm to get Pm+1.
– The same procedure is carried out if vm is adjacent to a vertex other than v1, v2, ..., vm-1.
– If we are able to enlarge Pm to Pn in this way, we get a Hamiltonian path.
9
Hamiltonian Path: Sufficient Condition- Ctd.
• Otherwise,– Pm: {v1, v2}, ..., {vm-1, vm} has v1 and vm adjacent only to vertices in Pm and m < n.– Now, we claim that G has a cycle on these vertices:
• If v1 and vm are adjacent, then the cycle is {v1, v2}, {v2, v3}, ..., {vm-1, vm}, {vm, v1}.• Otherwise,
– v1 is adjacent to a subset S of the vertices in {v2, v3, ..., vm-1}.– If there is a vertex vt S such that vm is adjacent to vt-1, then we can get the
cycle by adding {v1, vt}, {vt-1, vm} to Pm and deleting {vt-1, vt}, as shown in Fig. (a).
– If not,» Let |S| = k < m - 1. » Then, deg(v1) = k and deg(vm) (m - 1) - k» Contradiction! deg(v1) + deg(vm) m - 1 < n - 1.
– Hence, there is a cycle connecting v1, v2, ..., vm.
Fig. (a)
10
Hamiltonian Path: Sufficient Condition- End.
• Now, consider a vertex v V that is not found on this cycle.• G is connected, so there is a path from v to a first vertex vr in the cycle, as shown in Fig. (b).
• Removing the edge {vr-1, vr} (or {v1, vt} if r = t), we get the path (longer than the original Pm) show in Fig. (c).
• Repeating this whole process for the path in Fig. (c), we continue to increase the length until it includes every vertex of G.
Fig. (b)
Fig. (c)
Corollary. The loop-free graph G = (v, E) with |V| 2 has a Hamiltonian path if deg(v) (n - 1)/2 for all v V.
11
Hamiltonian Cycle: Sufficient Condition- Ore (1960)
• Theorem. Let G= (V, E) be a loop-free graph with |V|= n 3. If deg(x) + deg(y) n for all x, y V, x y, then G has a Hamiltonian cycle.
• Proof. • Assume that G does not contain a Hamiltonian cycle. • We add edges to G until we arrive at a sub-graph H of Kn, where H
has no Hamiltonian cycle, but, for any edge e (of Kn) not in H, H + e does have a Hamiltonian cycle.
• Since H Kn, there are vertices a, b V, where {a, b} is not an edge of H but H + {a, b} has a Hamiltonian cycle C.
• The graph H has no such cycle, so the edge {a, b} is a part of cycle C.• The vertices of H (and G) on cycle C are as follows:
12
Hamiltonian Cycle: Sufficient Condition- Ore (1960)- End.
• For each 3 i n, if the edge {b, vi} is in the graph H,– then we claim that the edge {a, vi-1} cannot be an edge of H.
• If both of these edges are in H, for some 3 i n, – we get the Hamiltonian cycle:
for the graph H (which has no Hamiltonian cycle).• Therefore, for each 3 i n, at most one of the edges {b,
vi}, {a, vi-1} is in H.• Consequently,
• Since for all v V, , so we have nonadjacent (in G) vertices a, b, where
𝒅𝒆𝒈 (𝒂)+𝒅𝒆𝒈 (𝒃 )<𝒏 CONTRADICTION!
13
Hamiltonian Cycle: Ore’s Sufficient Condition Corollaries
• Corollary I. If G = (V, E) is a loop-free undirected graph with |V| = n 3, and if deg(v) n/2 for all v V, then G has a Hamiltonian cycle.
• Corollary II. If G = (V, E) is a loop-free undirected graph with |V| = n 3, and if , then G has a Hamiltonian cycle.
• Proof. • Let a, b V, where {a, b} is not in E. [Since a, b are nonadjacent,
we want to show that deg(a) + deg(b) >= n.] • Remove the vertices a and b together with all edges incident on
them from the graph G.• Let H = (V', E') denote the resulting sub-graph.• |E| = |E'| + deg(a) + deg(b) because {a, b} is not in E.
14
Hamiltonian Cycle: Ore’s Sufficient Condition Corollaries- End.
• Since |V'| = n - 2, H is a sub-graph of the complete graph Kn-2, so
• Consequently,
• and we find that:
15
Hamiltonian Cycle: Backtracking Algorithm
• State space tree:– The initial node in level 0– All the remaining n-1 nodes in levels 1, 2, …, n-1– The number of state space tree nodes:
• Promising nodes’ characterization:– The ith node on the path must be adjacent to (i-1)th node– (n-1)th node must be adjacent to node 1 (initial node)– The ith node cannot be one of the first i-1 nodes
• Inputs:– A positive integer n (Number of vertices)– An undirected graph G with n vertices and with adjacency matrix denoted by
the 2D array W• Output:
– The Hamiltonian cycle denoted by the linear array vindex• vindex [i] is the index of the ith node on the cycle.• The Index of the initial node is located in vindex [0].
16
Hamiltonian Cycle: Backtracking Algorithm- End.
• High level call:– vindex[0] = 1;– hamiltonian(0);
void hamiltonian (index i){
index j;if (promising(i)) if (i == n – 1) cout << vindex[0] through vindex[n – 1];else for (j = 2; j <= n; j++) // Try all vertices { // as next one. vindex[i + 1] = j; hamiltonian(i+1); }
}
void promising (index i){
index j;bool switch;if ( i == n – 1 && ! W[vindex[n – 1]] [vindex[0]]) // First vertex must switch = false; // be adjacent toelse if (i > 0 && ! W[vindex[i -1]] [vindex[i]]) // last. ith vertex switch = false; // must be adjacentelse { // to (i – 1)th. switch = true; j = 1; while (j < i && switch) { // Check if vertex is if (vindex[i] == vindex[j]) // already selected. switch = false; j++; }}return switch;
}
17
CHIBA & NISHIZEKI’S LINEAR IMPLEMENTATION FOR I4CP GRAPHS
18
Chiba & Nishizeki’s Algorithm- Overview
• The Hamiltonian cycle problem is NP-complete even for 3-connected planar graphs.
• Tutte proved that a 4-connected planar (4CP) graph necessarily contains a Hamiltonian cycle and that It can be found in polynomial time.
• Prior art for 4CP graphs:– An O(n3) algorithm– A linear algorithm for 4-connected “maximal” planar graphs
• Objective– A linear algorithm for finding a Hamiltonian cycle in
general 4CP graphs
19
Chiba & Nishizeki’s Algorithm- Overview
• Solution methodology– Divide & Conquer with inductive argument:
• Decompose a graph into several small sub-graphs, then find Hamiltonian cycles in sub-graphs by applying the inductive hypothesis to them, and finally combine the Hamiltonian cycles into a Hamiltonian cycle of the whole graph.• Since the decomposed graphs are not always edge-
disjoint, it was non-trivial to verify even the polynomial bounded-ness of the algorithm.
– Key idea: • Avoid the decomposition into non-disjoint sub-graphs.
20
Required Terms and Definitions• Cut-vertex: a vertex whose deletion increases the number of
components.• Separation pair: a separation pair of a 2-connected graph G
is two vertices whose deletion disconnects G. • Splitting: Dividing a graph G into two split graphs G1 and G2.• Merging: the inverse of splitting• Virtual edge: The edge {x, y} in G1 or G2 whether it originally
exists in G1 and G2 or is newly added to G1 and G2.• Separation triple: a separating set of three vertices.• 4-connected graph: a 3-connected graph with no separation
triples.• Block: A block of G is a maximal 2-connected sub-graph of G.
21
Thomassen’s Result from Tutte’s Theorem
Lemma. Let G be a 2-connected plane graph with the outer facial cycle Z. Let s and e = (a, b) be a vertex and an edge, both on Z, and let t be any vertex of G distinct from s. Then G has a path P (called a Tutte path) going from s to t through e such that
– (i) each component of G - P is adjacent to at most three vertices of P, and– (ii) each component of G - P is adjacent to at most two vertices of P if it contains an
edge of Z.
Remark I. The above lemma implies that a 4-connected planar graph G has a Hamiltonian cycle.
22
Thomassen’s Result from Tutte’s Theorem- End.
• Remark II. Let G be a 4-connected and P be a s, t - Tutte path in G. Suppose H is a (G - P)-component then, since G is 4-connected, H must have 4 vertices of attachment in P which is a contradiction because P is a Tutte path.
• Remark III. In a 4-connected planar graph G: Let s and t be two adjacent vertices on Z and let e (s, t) be an edge on Z, then the path P joining s and t through e, assured by the Lemma, must be a Hamiltonian path of G, so P + (s, t) must be a Hamiltonian cycle of G. Thus an algorithm for finding the s-t path P immediately yields an algorithm for finding a Hamiltonian cycle.
• Decomposition strategy– The original graph G is 4-connected. – The sub-graphs into which G is decomposed are no longer 4-
connected.– They inherit the “internally 4-connected (I4C)” property.
23
Internally 4-Connected Plane (I4CP) Graphs
• The I4C property• Intuitively, a graph is internally 4-connected if it contains no separation
pair or triple in the interior.• Formal definition: Let G be a 2-connected plane graph with outer facial
cycle Z. Let s and t be two distinct vertices on Z, and let e = (a, b) be an arbitrary edge on Z such that e (s, t). t a , b and vertices s, a, b and t appear clockwise on Z in this order. (Fig. (a).)
• Possibly s = a as illustrated in Fig. (b). Let r be the vertex on Z counterclockwise next to s, and let f = (r, s) be the edge joining r and s.
24
Internally 4-Connected Plane (I4CP) Graphs- End.
• A plane 2-connected graph G is internally 4-connected with respect to (s, t, e) if G satisfies the following two conditions:(a) If {x, y} is a separation
pair, then(i) every component of
G - {x , y} contains at least one vertex of Z
(ii) each of the three paths Psa, Pbt and Pts contains at most one of x and y.
(b) If {x, y, z} is a separation triple, then every component of G - {x, y, z} contains at least one vertex of Z.
(c), (d) and (e) violate conditions in (a).
(f) violates condition (b).
25
• Vertical separation pair: a separation pair {x, y} is called vertical if
either x Psa- s and y Pbr
or x = s and y Pbt – t.
• Type I Reduction: G is decomposed into two sub-graphs w.r.t. a vertical separation pair.
• {y’, z’} is a horizontal separation pair.
Type I Reduction Using Vertical Separation Pairs:
26
• Let G be an I4CP graph having no vertical separation pair, then G is decomposed into several sub-graphs, called , , and. (If S = a, G is decomposed into and .)
Type II Reduction: , , and
𝑮𝒃
𝑮𝒈𝟐
G
𝑮𝒈𝟒
27
Type II Reduction- ,
• : the block of G – Psa which contains t. is cross-hatched.)
• must entirely contain Pbr, otherwise G would contain a vertical separation pair.
• Repeat splitting of at every separation pair such that one of the two split graphs entirely contains Pbr.
• The component containing Pbr is called Gb, while each of the others is called where g = (x, y) is a virtual edge contained in the component.
𝑮𝒃
𝑮𝒈𝟐
28
Type II Reduction-• maximal sub-graph of G – which can be separated from at each cut-
vertex u.• the sub-graph of G induced by the vertices of and the vertices on Psa
which are adjacent to .• Let x (resp. y) be the vertex of which is nearest to s (resp. a) along . Add a
new edge e’ = (u, y) to if it does not exist, and let be the resulting graph.
29
Type II Reduction-• : schematically, is a graph formed by merging with all the and drawn above .
• Constructively, is defined as:– := ;– while has a virtual edge g’ g, iterate to merge into ; – for each cut-vertex u (x, y) of G – Psa contained in merge to ;– Construct the sub-graph of G induced by the vertices of together with the vertices of Psa adjacent to , and redefine as the sub-graph;– - x – y.
𝑮𝒈𝟐𝟒
30
Type II Reduction Maintains the I4C Property
• Lemma. Let G be an I4CP graph containing no vertical separation pair. Then, all the decomposed graphs , and are I4C w.r.t. (s’ , t’ , e’) if s’ , t’ , e’ are defined as follows:
- Case s’ = bt’ = te’ =
if t r the edge clockwise incident to r on the outer facial cycle of Gb.
If t = rthe edge counterclockwise incident to b.
𝑮𝒃
31
Type II Reduction Maintains the I4C Property- Ctd.
– Case s’ = yt’ = xe’ = the edge counterclockwise incident to y on the outer facial cycle of .
– Case s’ = ut’ = xe’ = (u, y).
– Case s’ = wt’ = ve’ =
if w’ v’ an arbitrary edge on outer path Pw’v’.
If w’ v’ an arbitrary edge on Pwv incident to w’ (= v’).
𝑮𝒈𝟒
𝑮𝒈𝟐
32
Type II Reduction Maintains the I4C Property- End.
• Proof. We verify only the case . Suppose is not I4C w.r.t. (s’ , t’ , e’). Then, must have one of the following three:– a cut-vertex vc.– A separation pair {vp1, vp2} such that both vp1 and vp2 are contained in path Pwa’ or
Pbv’; and
– a separation triple {vt1, vt2, vt3} for which one of the components of - {vt1, vt2, vt3} contains no vertex of the outer facial cycle Z’ of
• In either case, G would contain a separation triple {vc, x, y}, {vp1, vp2, vx}, {vp1, vp2, y}, or {vt1, vt2, vt3} such that the deletion of the triple from G produces a component containing no vertex of Z. This contradicts the I4C-ness of G.
G 𝑮𝒈𝟒
33
An I4C graph w.r.t. (s, t, e) contains a Hamiltonian path connecting s and t through e
• Lemma. Let G be a plane graph having an outer facial cycle Z. Let s and t be two distinct vertices on Z and let e( (s , t) ) be an edge on Z . If G is I4C w.r.t. (s, t, e), then G has a Hamiltonian path P(G, s, t, e) which connects s and t and contains e. Moreover, if G has no vertical separation pair, then P(G, s, t, e) does not contain edge f = (s, r).
• Proof. The proof is by induction on the number n of vertices of a graph G. If n = 3, the claim is clearly true, so we assume that n > 3. There are two cases to consider.– There exists a vertical separation pair {x, y}– G has no vertical separation pairs.
34
An I4C graph w.r.t. (s, t, e) contains a Hamiltonian path connecting s and t through e - Ctd.
• Case 1: There exists a vertical separation pair {x, y}. – Among all vertical separation pairs of G, we choose {x, y} such that Gr has the
smallest number of vertices. We call such a separation pair the rightmost separation pair.
– Consider the case t GI * as shown in Fig.
• Let e’ = (x, y) be a virtual edge.Clearly, Gl is I4C w.r.t. (s, t, e’), while Gr is I4C w.r.t. (x, y, e) (or w.r.t. (y, x, e) if y = b).• By the inductive hypothesis, Gl has
a Hamiltonian path P(Gl , s, t, e’) and Gr has P(Gr , x, y, e).
• G has a Hamiltonian path:P(G , s, t, e) = P(Gl , s, t, e’) + P(Gr , x, y, e) – e’or P(Gl , s, t, e’) + P(Gr , y, x, e) – e’
* The case t GI is handled with a similar understanding.
35
An I4C graph w.r.t. (s, t, e) contains a Hamiltonian path connecting s and t through e - End.
• Case 2: G has no vertical separation pair. – By the inductive hypothesis, all the decomposed graphs , and have Hamiltonian
paths. From them, a Hamiltonian path P(G , s, t, e) of G can be constructed as follows
(Note that edge f = (s, r) is never included in path P):
First set P to Psb + P(Gb , b, t, e’).While there is a virtual edge g = (x, y) in Gb
If g P, thenP : = P – g + P( , y, x, e’). (replace g of P by a H-path of )Merge into Gb ;
If g p, thenConstruct , and set P := P – Pvw + P( , w, v, e’),Delete g from Gb .
For each u of the cut-vertices of G – Psa contained in Gb Set P := P – Pxy + P( , u, x, (u, y)) - (u, y).
36
An Abstract Example
, , and
If g1 is on P(Gb , b, t, e’), then:
37
A Concrete Example
G , ,
38
A Concrete Example- Ctd.
39
A Concrete Example- End.
– In the previous slide,
– The path passes through the virtual edge (1, 7), so a Hamiltonian path of is determined.
– The path passes through the virtual edges (1, 3) and (5, 7) but not (3, 5), so the Hamiltonian paths of , and are determined.
S- t Hamiltonian path
40
The HPATH Algorithm of O(n2)procedure HPATH(G, s, t , e);
beginif G contains exactly three vertices
then {G is a triangle}return a (trivial) Hamiltonian path P(G, s, t, e);
else if G has a vertical separation pairthen Type I reductionelse Type II reduction
end;
• Lemma. There are at most n-3 reductions during one execution of algorithm HPATH.
• Theorem. The algorithm HPATH spends at most O(n2) time.
Time Complexity Analysis
41
Time Complexity Analysis- Ctd.
• Proof. • r: the number of reductions occurred during one execution
of HPATH.• d(i), 1 i r: the number of small graphs into which a graph is
decomposed at the ith reduction; i.e. d(i) is the number of the recursive calls which occurred at the reduction.
d(i) = 2 if the ith reduction is of Type I
1 if the ith reduction is of Type II and none of,is produced.
• r': the number of reductions with d = 1• t: the number of final triangles
42
Time Complexity Analysis- Ctd.• Upper bound on the number of reductions in the
recursive call tree:– Internal nodes Reductions– Children of internal nodes Recursive calls at the reduction– Leaves Final triangles
• The tree has:– t leaves– r internal nodes (r' of which have out-degree 1)
• Recall:The number of internal nodes in a binary tree is one less than the number of leaves.
• The recursive tree has at most t - 1 internal nodes of out-degree 2 or more; thus, we have:
r t – 1 + r’ (1)
43
Time Complexity Analysis- Ctd.
• Upper bound for the total length of paths found in triangles:– A Type I reduction increases by one the total length of paths
which will be found in the two reduced graphs.– In general, the ith reduction increases by d(i) – 1 the total
length of paths which will be found in the d(i) reduced graphs.– Conversely, if d(i) = 1, then the length of a path which will be
found in the reduced graph decreases by at least one.– HPATH initially wishes to find a Hamiltonian path of length n
– 1. Therefore, the upper bound for the total length of paths found in triangles is:
𝒏−𝟏+ ∑𝟏≤𝒊≤ 𝒓
(𝒅 ( 𝒊 )−𝟏 )−𝒓 ′=𝒏−𝟏+𝒓+𝒕−𝟏−𝒓 −𝒓 ′
(2) =
44
Time Complexity Analysis- End.
• The lengths of the Hamiltonian paths found in the final triangles total 2t, we have:
• that is,
• Combining (1) with (3), we get the claimed bound on r:
(3)
r
45
THE END