Hamiltonian Paths Through Two- and Three-Dimensional Grids

This paper addresses the existence of Hamiltonian paths and cycles in two-dimensional grids consisting of triangles or quadrilaterals, and three-dimensional grids consisting of tetrahedra or hexahedra. The paths and cycles may be constrained to pass from one element to the next through an edge, through a vertex, or be unconstrained and pass through either. It was previously known that an unconstrained Hamiltonian path exists in a triangular grid under very mild conditions, and that there are triangular grids for which there is no through-edge Hamiltonian path. In this paper we prove that a through-vertex Hamiltonian cycle exists in any triangular or tetrahedral grid under very mild conditions, and that there exist quadrilateral and hexahedral grids for which no unconstrained Hamiltonian path exists. The existence proofs are constructive, and lead to an efficient algorithm for finding a through-vertex Hamiltonian cycle.

edges. Additionally, Ref. [5] only addresses triangles, not the other elements considered in this paper.
The main result of this paper is the proof that there always exists a through-vertex Hamiltonian path in grids consisting of triangles or tetrahedra, under very mild conditions. The proof is constructive, which leads to an algorithm to construct such a path. We do not explicitly give the algorithm in this paper, but it follows easily from the proofs of the main theorems. Little is known about the conditions under which a Hamiltonian path exists in grids consisting of quadrilaterals or hexahedra. An algorithm is given that might find a throughvertex Hamiltonian path in a quadrilateral or hexahedral grid, if one exists, and is likely to give a broken path with a small number of discontinuities, i.e., something close to a through-vertex Hamiltonian path.
The remainder of the paper is organized as follows. In Sec. 2 we introduce the notation and define the terms used in this paper. Section 3 addresses triangles and tetrahedra. It reviews previously known results and presents the main results of this paper. In Sec. 4 we discuss quadrilaterals and hexahedra. Section 5 contains the conclusions.

Definitions
For the purposes of this paper, an element, E, is a triangle, quadrilateral, tetrahedron, or hexahedron. An element contains vertices, v, and edges, e, with the obvious definitions, and three-dimensional elements contain faces, f.
A grid, G, is the union of a collection of elements, {E i }, all of the same kind, such that G = ∪E i is a connected, bounded region in ℜ 2 or ℜ 3 , and E°i ∩ E°j = φ, i ≠ j, where E°denotes the interior of element E, and φ is the empty set. We say that E i is an element of G, E i ∈ G. A vertex of E i is a boundary vertex if it lies on the boundary of G, and an interior vertex if it is not a boundary vertex. We say the size of G, G, is N if there are N elements in G. A triangular grid, quadrilateral grid, tetrahedral grid, and hexahedral grid is a grid consisting entirely of triangles, quadrilaterals, tetrahedra and hexahedra, respectively.
A grid is said to be conforming if E i ∩ E j , i ≠ j, is a common vertex, common edge, common face or empty. A vertex of an element is called a hanging node if it lies in the interior of an edge or face of another element. It follows immediately from the definition that a conforming grid has no hanging nodes. A grid is said to be 1-nonconforming if there is at least one hanging node in the grid, all edges contain at most one hanging node, the interior of all faces contain at most one hanging node, and the intersection of two elements is a vertex, edge or face of one of the elements, or empty. See Fig. 1 for examples of conforming and 1-nonconforming grids. This paper will primarily consider triangular and tetrahedral grids that are conforming, and quadrilateral and hexahedral grids that are conforming or 1-nonconforming.
A path with length n in a grid G is a sequence of elements, Hamiltonian path is a path in which every element in G appears exactly once. A Hamiltonian cycle is a cycle in which every element in G appears exactly once except for E 1 = E n + 1 , which appears exactly twice.
A sequence of elements E 1 E 2 . . . E n for which there exists an i with E i ∩ E i + 1 = φ is called a broken path, and the sequence E i E i + 1 is called a discontinuity in the path.
A through-vertex path (through-vertex cycle) is a path (cycle) in which the passage from one element to the next is specified as a common vertex, and the path does not pass through the same vertex when entering and exiting an element. Specifically, it is n -2, and E 1 E 2 . . . E n is a path (cycle). We say that the path passes through v i when going from E i to E i + 1 , and that we come into E i through the in-vertex v i -1 and leave E i through the out-vertex v i . A through-edge path and cycle, and through-face path and cycle are defined similarly. A through-vertex Hamiltonian path is a through-vertex path that is also a Hamiltonian path, and the definitions of the obvious similar terms are similar. An unconstrained path is one that may pass through any of vertices, edges or faces. Although the term is redundant, we will use it when we want to emphasize that the path is not constrained to pass through only vertices, edges or faces. Fig. 2. A local cut vertex is a vertex whose removal causes G to become disconnected locally. Formally, v is a local cut vertex if there exists an R > 0 such that for all 0 < ∈ < R, (G ∩ B (v, ∈)) \ v is disconnected, where B (v, ∈) is the ball of radius ∈ centered at v. Note that a cut vertex is also a local cut vertex. Figure  2(b) illustrates a local cut vertex that is not a cut vertex. In three dimensions, the terms cut edge and local cut edge are defined similarly.

Triangles and Tetrahedra
In this section we present what is known about the existence of the different types of Hamiltonian paths and cycles for conforming triangular and tetrahedral grids. We begin with a review of previously published results. We then give the main results of this paper, which are the existence of through-vertex Hamiltonian cycles under very mild conditions. Counterexamples are presented throughout to show conditions under which Hamiltonian cycles and paths do not exist, and to show that the conditions in the hypotheses of the theorems are essential.
Note that the existence of a cycle implies the existence of a path. Therefore most of the existence statements are made for cycles, and it is understood that the same statement holds for paths.
Conversely, non-existence statements are usually made about paths, and it is understood that the same statement holds for cycles. The exceptions to this are when quoting statements from other papers and when a path exists but a cycle does not.
The following theorem is due to Heber et al. [5].
Theorem 1 There exists a Hamiltonian path for any conforming triangular grid that contains no local cut vertices.
The statement of the theorem in Ref. [5] does not mention the absence of local cut vertices or that the grid must be conforming, however the definition of a grid in that paper is that it be a "simplicial complex coming from the simplicial decomposition of a connected 2D manifold" which implies these conditions. The theorem also holds for Hamiltonian cycles, simply by starting the base case in Heber's inductive proof with a Hamiltonian cycle between two triangles. The hypotheses of the theorem need to be extended slightly because the definition of a cycle assumes at least two elements.
Corollary 1 There exists a Hamiltonian cycle for any conforming triangular grid, of size at least 2, that contains no local cut vertices.
Hamiltonian paths and cycles also exist for tetrahedral grids under similar conditions. This follows immediately from Theorem 2 later in this section.
The following counterexamples show that the absence of cut vertices is an essential condition for Theorem 1, and the absence of local cut vertices is an essential condition for Corollary 1. However, it is not known whether the absence of local cut vertices is essential for the Hamiltonian path. Corollary 1 says that, under very mild conditions, we can always find a Hamiltonian cycle (and hence a Hamiltonian path) in a triangular grid. This is an unconstrained Hamiltonian cycle, i.e., it does not say whether the passage from one element to the next is through a vertex or edge. Indeed, the recursive algorithm implied by the proof of Theorem 1 in Ref. [5] will usually result in passages through both vertices and edges. The obvious question is whether or not through-vertex Hamiltonian cycles or paths and through-edge Hamiltonian cycles or paths exist. The following wellknown counterexample shows that we cannot expect to find a through-edge Hamiltonian path in a triangular grid. In fact, determining whether or not a through-edge Hamiltonian cycle exists in a triangular grid is known to be NP-complete [6]. A similar counterexample can be constructed for through-face Hamiltonian paths in tetrahedral grids.  The situation is less grim for through-vertex Hamiltonian cycles. The main result of this paper is that through-vertex Hamiltonian cycles exist for triangular and tetrahedral grids under conditions similar to those for the existence of an unconstrained Hamiltonian cycle. They again require a conforming grid with no local cut vertices. Triangular grids also require that there be at least one interior vertex, and tetrahedral grids also require that there be no local cut edges.
The following lemma says that, under conditions that will arise in the proofs of the main theorems, we can always find two triangles that share a edge, or two tetrahedra that share a face. Lemma 1 Let G be a conforming triangular (tetrahedral) grid with |G| ≥ 2, no local cut vertices and no local cut edges. Let G 1 ⊂ G contain no local cut vertices and no local cut edges, G 2 = G \ G 1 , |G 1 | ≥ 1, and |G 2 | ≥ 1. Then Proof: For part 1, suppose there are no elements that share an edge (face). Then all connections between elements are vertices (or edges), which must then be local cut vertices (or local cut edges) contradicting the hypothesis that there are no local cut vertices or local cut edges. For part 2, suppose there is no element in G 2 that shares an edge (face) with an element in G 1 . Then G 1 and G 2 are connected by only vertices (and edges), which must then be local cut vertices (or local cut edges).
We first give the main result for tetrahedral grids, where the proof is shorter.
Theorem 2 Let G be a conforming tetrahedral grid with |G| ≥ 2. If G contains no local cut vertices and no local cut edges then there exists a through-vertex Hamiltonian cycle for G.
Proof: We prove this by induction on |G 1 | where G 1 ⊆ G, G 1 satisfies the hypotheses of the theorem, and we can exhibit a through-vertex Hamiltonian cycle for G 1 .
For |G 1 | = 2, let G 1 = {E 1 , E 2 } where E 1 and E 2 are any two elements that share a common face. Lemma 1 insures the existence of these elements. Let v 1 and v 2 be two of the vertices that they share. Then By induction, let k = |G 1 | and suppose we have G 1 ⊂ G, k ≥ 2, G 1 satisfies the hypotheses of the theorem, and The grid and cycle can be extended to size k + 1 as follows.
Let E k + 1 ∈ G \ G 1 be an element that shares a face with some element E i ∈ G 1 . The existence of E k + 1 is guaranteed by Lemma 1. Without loss of generality, assume E i is not E 1 (otherwise, just start the numbering of the cycle with a different element). Since E i has only four vertices, one of the three vertices shared by E i and   E k + 1 must be either E i 's in-vertex v i -1 or E i 's out-vertex v i . Without loss of generality, suppose it is v i (otherwise, just reverse the ordering of the cycle). One of the three shared vertices, say v, must not be v i -1 or v i . Then a through-vertex Hamiltonian cycle in The proof for triangular grids is also a constructive proof that begins with a cycle through two elements and inductively extends this cycle to the complete grid. However, it is a more complicated proof because, in the notation of Theorem 2, we cannot guarantee that E k + 1 shares a vertex with E i that is not v i -1 or v i . In that case, a more complicated extension of the cycle must be performed.

Theorem 3 Let G be a conforming triangular grid with |G| ≥ 2. If G contains no local cut vertices and has at least one interior vertex then there exists a throughvertex Hamiltonian cycle for G.
Proof: As in Theorem 2, we prove this by induction on |G 1 |, and the base case with two triangles is trivial. By induction, suppose we have G 1 ⊂ G, |G 1 | = k ≥ 2, G 1 contains no local cut vertices, and E 1 v 1 E 2 v 2 . . . E k v k E 1 is a through-vertex Hamiltonian cycle for G 1 . The grid and cycle can be extended to a larger size as follows.
Let E k + 1 ∈ G \ G 1 be an element that shares an edge with some element E i ∈ G 1 . The existence of E k + 1 is guaranteed by Lemma 1. Without loss of generality, assume E i is not E 1 (otherwise, just start the numbering of the cycle with a different element). One of the two vertices that E k + 1 shares with E i must be either E i 's in-vertex, v i -1 , or E i 's out-vertex, v i . Without loss of generality, assume it shares the out-vertex (otherwise, just reverse the order of the cycle). There are four cases to consider. Case 1. E k + 1 does not contain v i -1 . This is the easy case that corresponds to the proof of Theorem 2. Let v be the other vertex shared by E k + 1 and E i . Then the new cycle is This extension is illustrated in Fig. 6. The arrows pointing from a vertex to the interior of a triangle or from the interior of a triangle to a vertex denote the in-vertex and out-vertex, respectively. Case 2. E k + 1 contains v i -1 and there is another triangle, E k + 2 , not on the current cycle, that shares an edge and v i with E k + 1 . This case is illustrated in Fig. 7. Let v be the other vertex shared by E k + 1 and E k + 2 . Then the new cycle is Case 3. E k + 1 contains v i -1 and there is another triangle, E k + 2 , that is on the current cycle and shares an edge and v i with E k + 1 . First note that E k + 1 must contain both the in-vertex and out-vertex of E k + 2 , otherwise we could apply case 1 with E k + 2 as E i to add E k + 1 to the cycle. Also note that whenever a triangle not on the cycle contains both the in-vertex and out-vertex of a triangle that is on the cycle, we can "swap" this triangle with the other triangle by removing the other triangle from the cycle and inserting the new triangle in its place, as illustrated in Fig. 8.   Note that if we do not encounter two adjacent elements that are not in the cycle (the first subcase), then we must eventually reach the second subcase because the other triangle adjacent to E i cannot contain the invertex of E i , v i -1 . See Fig. 9. Case 3b. v i is a boundary vertex. This implies that all three vertices of E k + 1 are on the boundary, for if not we could select a different E i , v i -1 and v i (possibly reversing the order of the cycle) such that an interior vertex of E k + 1 is v i . This leads to a natural decomposition of G into three components plus E k + 1 as illustrated in Fig. 10. The intersection of any two components is a vertex of E k + 1 . Each component contains a triangle that shares an edge with E k + 1 because there are no local cut vertices. One component contains E i and a second component contains E k + 2 . If the third component is not empty, let E be the element that shares an edge with E k + 1 . If E is not on the cycle, then apply case 2 (reversing the order of the cycle if necessary). If E is on the cycle and E k + 1 does not contain both the in-vertex and out-vertex of E, then apply case 1 with E as E i . Thus we can assume that E k + 1 contains the in-vertex and out-vertex of all adjacent triangles, so it can be swapped with any of them.
Pick an interior vertex of G, v int . Swap E k + 1 with the neighbor that is in the same component as v int . Apply case 1, 2 or 3a to reinsert the other element, if appropriate. If not, then consider the decomposition around the new element and repeat the process (see Fig. 11). The component that contains v int has at least lost the swapped triangle, and thus is smaller in this decomposition. Since the size of the component containing v int will continue to shrink with each application of this process, it must eventually lead to v int , at which point case 3a applies, unless it ends earlier by applying case 1, 2 or 3a.
Case 4. E k + 1 contains v i -1 and there is no other triangle that shares an edge and v i with E k + 1 , i.e., that edge is on the boundary. Then there must be another triangle that shares v i and an edge with E i , for if that edge of E i was also on the boundary, then v i would be a local cut vertex. Swap E k + 1 with E i , and then apply either case 2 or case 3 to add E i back into the path.
The inclusion of an interior vertex is an essential condition for Theorem 3. The same counterexample can be used as was used in Counterexample 3. However, this example does contain a through-vertex Hamiltonian path. It is not known whether or not the inclusion of an interior vertex is essential for the existence of a through-vertex Hamiltonian path. Fig. 5.

Counterexample 4 There exists a conforming triangular grid with no local cut vertices and no interior vertices for which there is no through-vertex Hamiltonian cycle. See
Since the inclusion of an interior vertex "fixes" Counterexample 4, a natural question is whether it can also "fix" Counterexample 3. The following counterexample says that this is not the case.

Quadrilaterals and Hexahedra
It is not known under what conditions any kind of Hamiltonian path or cycle is guaranteed to exist for quadrilateral and hexahedral grids, or even if there is any characterization. It would certainly be much more stringent conditions than for triangles and tetrahedra, as the following counterexample shows. By replacing the squares with cubes, the same counterexample works for hexahedral grids.

Counterexample 6
There exists a conforming quadrilateral grid with no local cut vertices and at least one interior vertex for which there is no Hamiltonian path. See Fig. 13.
The proofs of Theorems 2 and 3 break down when applied to quadrilaterals and hexahedra because, in the notation of those theorems, E k + 1 is not guaranteed to contain either the in-vertex or out-vertex of E i . Without that condition, it is more difficult, and in some cases impossible, to modify the cycle in a way that adds E k + 1 to it.
However, there are some other transformations of the cycle that can be applied to insert E k + 1 into the cycle in some situations. These include some situations where   11. Second decomposition of G into three components plus a triangle after swapping E k + 1 with a neighbor.  the grid is 1-nonconforming. Most of these transformations apply not only to quadrilaterals and hexahedra, but to any shape of element, including triangles and tetrahedra, and to mixed elements. Thus one could write a general program that applies to any grid. The illustrations will show the application of the transformations to quadrilaterals. They show examples of the transformations, but are not exhaustive.
An algorithm that attempts to find a through-vertex Hamiltonian cycle begins by picking two elements that share an edge (face in three dimensions) and constructing a cycle consisting of these two elements and two of the vertices they share. Then repeatedly pick an element that is not in the cycle but shares an edge (face in three dimensions) with an element in the cycle, and attempt to add it to the cycle by trying all of the following transformations that apply until one succeeds. If none of them succeed then try another element and come back to this one later. If there are elements not yet added to the cycle and none of the transformations work with any of the remaining elements, then you must insert a "broken link" creating a discontinuity in the path, i.e., insert an element such that either it is not adjacent to the previous or next element in the cycle, or the in-vertex and out-vertex do not match. When all elements have been added to the (possibly broken) cycle, the algorithm finishes.
In the following transformations, the cycle contains the segment v i -2 E i -1 v i -1 E i v i E i + 1 v i + 1 and E is an element that shares an edge (face in three dimensions) with E i and is not in the cycle.

Transformation 1 If E contains v i and shares anoth-
This is the same transformation that was used in the proof of Theorem 2.

Transformation 2 If E contains v i -1 and shares another vertex, u ≠ v i , with E i , then replace the segment
This is like the previous transformation, but using the in-vertex instead of the out-vertex. Fig. 15.

Transformation 4 If E contains both v i -1 and v i , and
This is like the previous transformation, but with the change occurring at the out-vertex of E i instead of the in-vertex.

Transformation 5
If E shares a vertex u 1 ≠ v i with E i , and shares a vertex u 2 with E i -1 , u 2 ≠ u 1 and u 2 ≠ v i -2 , then replace the segment with v i - Fig. 16.
This transformation can also handle some forms of hanging nodes, as shown in Fig. 17.
This is like the previous transformation, but with the changes occurring at E i + 1 instead of E i -1 .
Transformation 7 If E contains neither v i -1 nor v i , but it shares a vertex u 1 with E i -1 , u 1 ≠ v i -2 , and shares a vertex u 2 with E i , u 2 ≠ u 1 , then replace the segment Fig. 18.
This is like the previous transformation, but with the changes occurring at E i + 1 instead of E i -1 .

Transformation 9
If E contains v i and there is another element, F, that is not on the cycle, shares a vertex, u 1 ≠ v i , with E, and shares a vertex u 2 with E i , u 2 ≠ u 1 and u 2 ≠ v i -1 , then replace the segment with v i - This transformation can handle some instances of hanging nodes, as shown in Fig. 19. It can also handle case 2 in the proof of Theorem 3, although it places the elements in a different order than that used in the proof.
Transformation 10 If E contains v i -1 and there is another element, F, that is not on the cycle, shares a vertex, u 1 ≠ v i -1 , with E, and shares a vertex u 2 with E i , u 2 ≠ u 1 and u 2 ≠ v i , then replace the segment with v i - This is like the previous transformation, but with E sharing the in-vertex of E i instead of the out-vertex.
Transformation 11 If E contains both v i -1 and v i , then replace the segment with v i -2 E i - This is the swapping of one element for another that was described in case 3 of the proof of Theorem 3. One would next attempt to add E i back into the cycle. If done recursively, this will handle case 3b of Theorem 3.

Conclusion
We considered the existence of various types of Hamiltonian paths and cycles in two-dimensional grids consisting of triangles or quadrilaterals, and threedimensional grids consisting of tetrahedra or hexahedra. The types of Hamiltonian paths and cycles are distinguished by whether passage from one element to the next must be associated with an edge (through-edge Hamiltonian), must be associated with a vertex (throughvertex Hamiltonian), or can pass through either (unconstrained Hamiltonian). The existence results presented in this paper can be summarized as: 1. There exists an unconstrained Hamiltonian path in any conforming triangular grid with no local cut vertices (previously known result). This is easily extended to Hamiltonian cycle. 2. There exist triangular grids for which there is no through-edge Hamiltonian path (previously known result). This also holds for through-face Hamiltonian paths in tetrahedral grids. 3. There exists a through-vertex Hamiltonian cycle (and hence through-vertex Hamiltonian path) for any conforming triangular grid with no local cut vertices and at least one interior vertex. 4. There exists a through-vertex Hamiltonian cycle (and hence through-vertex Hamiltonian path, unconstrained Hamiltonian cycle and unconstrained Hamiltonian path) for any tetrahedral grid that contains no local cut vertices and no local cut edges. 5. There exist rectangular grids for which there is no Hamiltonian path or cycle of any type. This also holds for hexahedral grids.
Examples were given to show that the stated conditions are essential. Some open questions remain: