Journal of Applied Mathematics

Journal of Applied Mathematics / 2012 / Article

Research Article | Open Access

Volume 2012 |Article ID 475087 | https://doi.org/10.1155/2012/475087

Fatemeh Keshavarz-Kohjerdi, Alireza Bagheri, "Hamiltonian Paths in Some Classes of Grid Graphs", Journal of Applied Mathematics, vol. 2012, Article ID 475087, 17 pages, 2012. https://doi.org/10.1155/2012/475087

Hamiltonian Paths in Some Classes of Grid Graphs

Academic Editor: Jin L. Kuang
Received08 Sep 2011
Revised13 Dec 2011
Accepted28 Dec 2011
Published26 Apr 2012

Abstract

The Hamiltonian path problem for general grid graphs is known to be NP-complete. In this paper, we give necessary and sufficient conditions for the existence of Hamiltonian paths in L-alphabet, C-alphabet, F-alphabet, and E-alphabet grid graphs. We also present linear-time algorithms for finding Hamiltonian paths in these graphs.

1. Introduction

Hamiltonian path in a graph is a simple path that visits every vertex exactly once. The problem of deciding whether a given graph has a Hamiltonian path is a well-known NP-complete problem and has many applications [1, 2]. However, for some special classes of graphs polynomial-time algorithms have been found. For more related results on Hamiltonian paths in general graphs see [3–8].

Rectangular grid graphs first appeared in [9], where Luccio and Mugnia tried to solve the Hamiltonian path problem. Itai et al. [10] gave necessary and sufficient conditions for the existence of Hamiltonian paths in rectangular grid graphs and proved that the problem for general grid graphs is NP-complete. Also, the authors in [11] presented sufficient conditions for a grid graph to be Hamiltonian and proved that all finite grid graphs of positive width have Hamiltonian line graphs. Later, Chen et al. [12] improved the algorithm of [10] and presented a parallel algorithm for the problem in mesh architecture. Also there is a polynomial-time algorithm for finding Hamiltonian cycle in solid grid graphs [13]. Recently, Salman [14] introduced alphabet grid graphs and determined classes of alphabet grid graphs which contain Hamiltonian cycles. More recently, Islam et al. [15] showed that the Hamiltonian cycle problem in hexagonal grid graphs is NP-complete. Also, Gordon et al. [16] proved that all connected, locally connected triangular grid graphs are Hamiltonian, and gave a sufficient condition for a connected graph to be fully cycle extendable and also showed that the Hamiltonian cycle problem for triangular grid graphs is NP-complete. Nandi et al. [17] gave methods to find the domination numbers of cylindrical grid graphs. Moreover, Keshavarz-Kohjerdi et al. [18, 19] gave sequential and parallel algorithms for the longest path problem in rectangular grid graphs.

In this paper, we obtain necessary and sufficient conditions for the existence of a Hamiltonian path in 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, and 𝐸 -alphabet grid graphs. Also, we present linear-time algorithms for finding such a Hamiltonian path in these graphs. Solving the Hamiltonian path problem for alphabet grid graphs may arise results that can help in solving the problem for general solid grid graphs. The alphabet grid graphs that are considered in this paper have similar properties that motivate us to investigate them together. Other classes of alphabet grid graphs have enough differences that will be studied in a separate work.

2. Preliminaries

Some previously established results about the Hamiltonian path problem which plays an important role in this paper are summarized in this section.

The two-dimensional integer grid 𝐺 ∞ is an infinite graph with vertex set of all points of the Euclidean plane with integer coordinates. In this graph, there is an edge between any two vertices of unit distance. For a vertex 𝑣 of this graph, let 𝑣 π‘₯ and 𝑣 𝑦 denote π‘₯ and 𝑦 coordinates of its corresponding point. A grid graph 𝐺 is a finite vertex-induced subgraph of the two-dimensional integer grid. In a grid graph 𝐺 , each vertex has degree of at most four. A rectangular grid graph 𝑅 ( π‘š , 𝑛 ) (or 𝑅 for short) is a grid graph whose vertex set is 𝑉 ( 𝑅 ) = { 𝜐 ∣ 1 ≀ 𝜐 π‘₯ ≀ π‘š , 1 ≀ 𝜐 𝑦 ≀ 𝑛 } . 𝑅 ( π‘š , 𝑛 ) is called an 𝑛 -rectangle. A solid grid graph is a grid graph without holes.

By [10], a vertex 𝑣 is colored white if 𝜐 π‘₯ + 𝜐 𝑦 is even, and is colored black otherwise. The size of 𝑅 ( π‘š , 𝑛 ) is defined to be π‘š 𝑛 . 𝑅 ( π‘š , 𝑛 ) is called odd sized if π‘š 𝑛 is odd, and is called even sized otherwise. Two different vertices 𝜐 and 𝜐 β€² in 𝑅 ( π‘š , 𝑛 ) are called color compatible if either both 𝜐 and 𝜐 β€² are white and 𝑅 ( π‘š , 𝑛 ) is odd sized, or 𝜐 and 𝜐 β€² have different colors and 𝑅 ( π‘š , 𝑛 ) is even sized.

An alphabet grid graph is a finite vertex-induced subgraph of the rectangular grid graph of a certain type, as follows. For π‘š , 𝑛 β‰₯ 3 , an 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) (or 𝐿 for short), 𝐢 -alphabet grid graph 𝐢 ( π‘š , 𝑛 ) (or 𝐢 for short), 𝐹 -alphabet grid graph 𝐹 ( π‘š , 𝑛 ) (or 𝐹 for short), and 𝐸 -alphabet grid graph 𝐸 ( π‘š , 𝑛 ) (or 𝐸 for short) are subgraphs of 𝑅 ( 3 π‘š βˆ’ 2 , 5 𝑛 βˆ’ 4 ) . These alphabet grid graphs are shown in Figure 1, for π‘š = 4 and 𝑛 = 3 . An alphabet grid graph is called odd sized if its corresponding rectangular graph is odd sized, and is called even sized otherwise.

In the following by 𝐴 ( π‘š , 𝑛 ) we mean a grid graph 𝐴 ( π‘š , 𝑛 ) . Let 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) denote the problem of finding a Hamiltonian path between vertices 𝑠 and 𝑑 in grid graph 𝐴 ( π‘š , 𝑛 ) , and let ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) denote the grid graph 𝐴 ( π‘š , 𝑛 ) with two specified distinct vertices 𝑠 and 𝑑 of it. Where 𝐴 is a rectangular grid graph, 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph. ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is Hamiltonian if there is a Hamiltonian path between 𝑠 and 𝑑 in 𝐴 ( π‘š , 𝑛 ) . In this paper, without loss of generality we assume 𝑠 π‘₯ ≀ 𝑑 π‘₯ and π‘š β‰₯ 𝑛 . In the figures, we assume that ( 1 , 1 ) is the coordinates of the vertex in the lower left corner.

An even-sized rectangular grid graph contains the same number of black and white vertices. Hence, the two end vertices of any Hamiltonian path in the graph must have different colors. Similarly, in an odd sized rectangular grid graph the number of white vertices is one more than the number of black vertices. Therefore, the two end vertices of any Hamiltonian path in such a graph must be white. Hence, the color compatibility of 𝑠 and 𝑑 is a necessary condition for ( 𝑅 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) to be Hamiltonian. Furthermore, Itai et al. [10] showed that if one of the following conditions hold, then ( 𝑅 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is not Hamiltonian:

( F 1 )   𝑅 ( π‘š , 𝑛 ) is a 1-rectangle and either 𝑠 or 𝑑 is not a corner vertex (Figure 2(a)). ( F 2 ) 𝑅 ( π‘š , 𝑛 ) is a 2-rectangle and ( 𝑠 , 𝑑 ) is a nonboundary edge, that ( 𝑠 , 𝑑 ) is an edge and it is not on the outer face (Figure 2(b)). ( F 3 ) 𝑅 ( π‘š , 𝑛 ) is isomorphic to a 3-rectangle 𝑅 ξ…ž ( π‘š , 𝑛 ) such that 𝑠 and 𝑑 are mapped to 𝑠 ξ…ž and 𝑑 ξ…ž and all of the following three conditions hold: ( 1 ) π‘š is even, ( 2 ) 𝑠 β€² is black, 𝑑 ξ…ž is white, ( 3 ) 𝑠 β€² 𝑦 = 2 and 𝑠 ξ…ž π‘₯ < 𝑑 ξ…ž π‘₯ (Figure 2(c)) or 𝑠 ξ…ž 𝑦 β‰  2 and 𝑠 ξ…ž π‘₯ < 𝑑 ξ…ž π‘₯ βˆ’ 1 (Figure 2(d)).

A Hamiltonian path problem 𝑃 ( 𝑅 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is called acceptable if 𝑠 and 𝑑 are color compatible and ( 𝑅 , 𝑠 , 𝑑 ) does not satisfy any of conditions (F1), (F2), and (F3).

The following theorem has been proved in [10].

Theorem 2.1. Let 𝑅 ( π‘š , 𝑛 ) be a rectangular grid graph and 𝑠 and 𝑑 be two distinct vertices. Then ( 𝑅 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is Hamiltonian if and only if 𝑃 ( 𝑅 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is acceptable.

Lemma 2.2 (see [12]). 𝑅 ( π‘š , 𝑛 ) has a Hamiltonian cycle if and only if it is even-sized and π‘š , 𝑛 > 1 .

Lemma 2.3 (see [14]). Any 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) ( π‘š , 𝑛 β‰₯ 3 ) has a Hamiltonian cycle if and only if π‘š 𝑛 is even.

Figure 3 shows a Hamiltonian cycle for an even-sized rectangular grid graph and 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ), found by Lemmas 2.2 and 2.3, respectively. Each Hamiltonian cycle found by these lemmas contains all boundary edges on three sides of the rectangular graph and four sides of the 𝐿 -alphabet grid graph. This shows that for an even-sized rectangular graph 𝑅 and 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ) , we can always find a Hamiltonian cycle, such that it contains all boundary edges, except of exactly one side of 𝑅 and two side of 𝐿 which contains an even number of vertices.

3. Necessary and Sufficient Conditions

In this section, we give necessary and sufficient conditions for the existence of a Hamiltonian path in 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, and 𝐸 -alphabet grid graphs.

Definition 3.1. A separation of ( i ) an 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) is a partition of 𝐿 into two disjoint rectangular grid graphs 𝑅 1 and 𝑅 2 , that is, 𝑉 ( 𝐿 ) = 𝑉 ( 𝑅 1 ) βˆͺ 𝑉 ( 𝑅 2 ) , and 𝑉 ( 𝑅 1 ) ∩ 𝑉 ( 𝑅 2 ) = βˆ… , ( i i ) an 𝐢 -alphabet graph 𝐢 ( π‘š , 𝑛 ) is a partition of 𝐢 into a 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ) and a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , that is, 𝑉 ( 𝐢 ) = 𝑉 ( 𝐿 ) βˆͺ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) ) , and 𝑉 ( 𝐿 ) ∩ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) ) = βˆ… , ( i i i ) an 𝐹 -alphabet grid graph 𝐹 ( π‘š , 𝑛 ) is a partition of 𝐹 into a 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) and a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) (or four rectangular grid graphs 𝑅 1 to 𝑅 4 ) , that is, 𝑉 ( 𝐹 ) = 𝑉 ( 𝐿 ) βˆͺ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ) and 𝑉 ( 𝐿 ) ∩ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ) = βˆ… (or 𝑉 ( 𝐹 ) = 𝑉 ( 𝑅 1 ) βˆͺ 𝑉 ( 𝑅 2 ) βˆͺ 𝑉 ( 𝑅 3 ) βˆͺ 𝑉 ( 𝑅 4 ) and 𝑉 ( 𝑅 1 ) ∩ 𝑉 ( 𝑅 2 ) ∩ 𝑉 ( 𝑅 3 ) ∩ 𝑉 ( 𝑅 4 ) = βˆ… ) , ( i v ) an 𝐸 -alphabet grid graph 𝐸 ( π‘š , 𝑛 ) is a partition of 𝐸 into an 𝐹 -alphabet grid graph 𝐹 ( π‘š , 𝑛 ) and a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) or a 𝐢 -alphabet grid graph 𝐢 ( π‘š , 𝑛 ) and a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , that is, 𝑉 ( 𝐸 ) = 𝑉 ( 𝐹 ) βˆͺ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) ) , and 𝑉 ( 𝐹 ) ∩ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) ) = βˆ… or 𝑉 ( 𝐸 ) = 𝑉 ( 𝐢 ) βˆͺ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ) , and 𝑉 ( 𝐢 ) ∩ 𝑉 ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ) = βˆ… .

In the following, two nonincident edges 𝑒 1 and 𝑒 2 are parallel, if each end vertex of 𝑒 1 is adjacent to some end vertex of 𝑒 2 .

Lemma 3.2. Let 𝐴 ( π‘š , 𝑛 ) be an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph and 𝑅 be the smallest rectangular grid graph that includes 𝐴 . If ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is Hamiltonian, then ( 𝑅 , 𝑠 , 𝑑 ) is also Hamiltonian.

Proof. We break the proof into two cases.Case 1 ( 𝐴 ( π‘š , 𝑛 ) is an 𝐿 -alphabet or 𝐢 -alphabet grid graph). Let 𝑃 be a Hamiltonian path in 𝐿 (or 𝐢 ) that is found by Algorithm 1 (or 2). Since 𝑅 βˆ’ 𝐿 (or 𝑅 βˆ’ 𝐢 ) is an even-sized rectangular grid graph of ( 2 π‘š βˆ’ 2 ) Γ— ( 4 𝑛 βˆ’ 4 ) (or ( 2 π‘š βˆ’ 2 ) Γ— ( 3 𝑛 βˆ’ 4 ) ), then by Lemma 2.2 it has a Hamiltonian cycle (i.e., we can find a Hamiltonian cycle of 𝑅 βˆ’ 𝐿 (or 𝑅 βˆ’ 𝐢 ), such that it contains all edges of 𝑅 βˆ’ 𝐿 (or 𝑅 βˆ’ 𝐢 ) that are parallel to some edge of 𝑃 ). Using two parallel edges of 𝑃 and the Hamiltonian cycle of 𝑅 βˆ’ 𝐿 (or 𝑅 βˆ’ 𝐢 ) such as two darkened edges of Figure 4(a), we can combine them as illustrated in Figure 4(b) and obtain a Hamiltonian path for 𝑅 .Case 2. 𝐴 ( π‘š , 𝑛 ) is an 𝐹 -alphabet or 𝐸 -alphabet grid graph. Let 𝑃 be a Hamiltonian path in 𝐹 (or 𝐸 ) that is found by Algorithm 3 (or 4). We consider the following cases.
Subcase 2.1 ( π‘š , 𝑛 > 3 ). Since 𝑅 βˆ’ 𝐹 (or 𝑅 βˆ’ 𝐸 ) can be partitioned into three even-sized rectangular grid graphs of 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , 𝑅 ( 2 , 2 𝑛 βˆ’ 2 ) , and 𝑅 ( 2 π‘š βˆ’ 2 , 2 𝑛 βˆ’ 2 ) (or 𝑅 ( 2 , 3 𝑛 βˆ’ 4 ) , 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , and 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) ), then they have Hamiltonian cycles by Lemma 2.2. Then combine Hamiltonian cycles on 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , 𝑅 ( 2 , 2 𝑛 βˆ’ 2 ) and 𝑅 ( 2 π‘š βˆ’ 2 , 2 𝑛 βˆ’ 2 ) (or 𝑅 ( 2 , 3 𝑛 βˆ’ 4 ) , 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , and 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) ) to be a large Hamiltonian cycle and then using two parallel edges of 𝑃 and the Hamiltonian cycle of 𝑅 βˆ’ 𝐹 (or 𝑅 βˆ’ 𝐸 ), we can obtain a Hamiltonian path for 𝑅 .Subcase 2.2 ( 𝑛 = 3 ). Let 𝑅 βˆ’ 𝐹 be three rectangular grid graphs of 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , 𝑅 ( 2 , 2 𝑛 βˆ’ 2 ) , and 𝑅 ( 2 π‘š βˆ’ 2 , 2 𝑛 βˆ’ 2 ) . We consider the following two subcases.

Subcase   2 . 2 . 1    ( π‘š = 3 ) . Let two vertices 𝑣 1 , 𝑣 2 be in 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) . Using Algorithm 3 there exist two edges 𝑒 1 , 𝑒 2 such that 𝑒 1 ∈ 𝑃 or 𝑒 2 ∈ 𝑃 is on the boundary of 𝐹 ( π‘š , 𝑛 ) facing 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) , see Figure 5(a). Hence by combining a Hamiltonian path 𝑃 and Hamiltonian cycles in 𝑅 ( 2 , 2 𝑛 βˆ’ 2 ) and 𝑅 ( 2 π‘š βˆ’ 2 , 2 𝑛 βˆ’ 2 ) and ( 𝑣 1 , 𝑣 2 ) , a Hamiltonian path between 𝑠 and 𝑑 is obtained, see Figures 5(b) and 5(c).
Subcase 2.2.2 ( π‘š > 3 ) . For π‘š = 4 , let four vertices 𝑣 1 , 𝑣 2 , 𝑣 3 , 𝑣 4 be in 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) . Using Algorithm 3 there exist four edges 𝑒 1 , 𝑒 2 , 𝑒 3 , 𝑒 4 such that 𝑒 1 , 𝑒 2 ∈ 𝑃 , 𝑒 1 , 𝑒 4 ∈ 𝑃 , 𝑒 3 , 𝑒 4 ∈ 𝑃 or 𝑒 2 , 𝑒 3 ∈ 𝑃 are on the boundary of 𝐹 ( π‘š , 𝑛 ) facing 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 βˆ’ 2 ) see Figure 6(a). Therefore, by merging ( 𝑣 1 , 𝑣 2 ) and ( 𝑣 3 , 𝑣 4 ) to these edges and Hamiltonian cycles in 𝑅 βˆ’ 𝐹 we obtain a Hamiltonian path for 𝑅 , see Figure 6(b). For other values of π‘š , the proof is similar to that of π‘š = 4 .
Similar to 𝐹 -alphabet grid graphs, Hamiltonian paths can be found in 𝐸 -alphabet grid graphs for 𝑛 = 3 .

  procedure 𝐿 _HamiltonianPath ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 )
1:  if   𝐿 can be stripped then
2:   let 𝑆 be a strip of 𝐿 , where 𝑆 is an even-sized rectangular grid graph
3:    𝑃 ← 𝑅 _HamiltonianPath ( 𝐿 βˆ’ 𝑆 , 𝑠 , 𝑑 )
4:    𝐷 ← HamiltonianCycle ( 𝑆 )
5:   return MergeStrip ( 𝑃 , 𝐷 , 𝑠 , 𝑑 )
6:  else
7:   let 𝐿 be split to 𝑅 𝑝 and 𝑅 π‘ž
8:    𝑃 1 ← 𝑅 _HamiltonianPath ( 𝑅 𝑝 , 𝑠 , 𝑝 )
9:    𝑃 2 ← 𝑅 _HamiltonianPath ( 𝑅 π‘ž , π‘ž , 𝑑 )
10:   return MergeSplit ( 𝑃 1 , 𝑃 2 , 𝑝 , π‘ž )
11:  end  if

  procedure 𝐢 _HamiltonianPath ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 )
1:  if   𝐢 can be stripped then
2:   let 𝑆 be a strip of 𝐢 , where 𝑆 is an even-sized rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 )
3:    𝑃 ← 𝐿 _HamiltonianPath ( 𝐢 βˆ’ 𝑆 , 𝑠 , 𝑑 )
4:    𝐷 ← HamiltonianCycle ( 𝑆 )
5:   return MergeStrip ( 𝑃 , 𝐷 , 𝑠 , 𝑑 )
6:  else
7:   let 𝐢 be split 𝑅 𝑝 and 𝐿 π‘ž
8:    𝑃 1 ← 𝑅 _HamiltonianPath ( 𝑅 𝑝 , 𝑠 , 𝑝 )
9:    𝑃 2 ← 𝐿 _HamiltonianPath ( 𝐿 π‘ž , π‘ž , 𝑑 )
10:  return MergeSplit ( 𝑃 1 , 𝑃 2 , 𝑝 , π‘ž )
11:  end  if

  procedure 𝐹 _HamiltonianPath ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 )
1:  if   𝐹 can be stripped, where 𝐹 ( π‘š , 𝑛 ) is not odd sized and 𝑠 , 𝑑 βˆ‰ 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 )   then
2:   let 𝑆 be a strip of 𝐹
3:    𝑃 ← 𝐹 βˆ’ 𝑆 _HamiltonianPath ( 𝐹 βˆ’ 𝑆 , 𝑠 , 𝑑 )
4:   /* 𝐹 βˆ’ 𝑆 is a 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) or a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 )
    */
5:    𝐷 ← HamiltonianCycle ( 𝑆 )
6:   return MergeStrip ( 𝑃 , 𝐷 , 𝑠 , 𝑑 )
7:  else
8:   if   𝐹 can be stripped, where 𝐹 ( π‘š , 𝑛 ) is odd sized and 𝑠 , 𝑑 ∈ 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 )   then
9:    let 𝑆 be a strip of 𝐹 , where 𝑆 is three rectangular grid graphs 𝑅 2 , 𝑅 3 and 𝑅 4
10:      𝑃 ← 𝑅 _HamiltonianPath ( 𝑅 1 , 𝑠 , 𝑑 )
11:      𝑐 1 ← HamiltonianCycle ( 𝑅 3 )
12:      𝑐 2 ← HamiltonianCycle ( 𝑅 4 )
13:      𝐢 ← MergeCycles ( 𝑐 1 , 𝑐 2 )
14:      𝐷 ← HamiltonianCycle ( 𝑅 2 )
15:     return MergeStrip ( 𝑃 , 𝐷 , 𝐢 , 𝑠 , 𝑑 )
16:   else
17:    let 𝐹 be split to 𝑅 𝑝 and 𝐿 π‘ž (or 𝐿 𝑝 and 𝑅 π‘ž )
18:      𝑃 1 ← 𝑅 _HamiltonianPath ( 𝑅 𝑝 , 𝑠 , 𝑝 )
19:      𝑃 2 ← 𝐿 _HamiltonianPath ( 𝐿 π‘ž , π‘ž , 𝑑 )
20:     return MergeSplit ( 𝑃 1 , 𝑃 2 , 𝑝 , π‘ž )
21:   end  if
22:  end  if

  procedure 𝐸 _HamiltonianPath ( 𝐸 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 )
1:  let 𝑆 be a strip of 𝐸 , where 𝑆 is an even-sized rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) or
    𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 )
2:   𝑃 ← 𝐸 βˆ’ 𝑆 _HamiltonianPath ( 𝐸 βˆ’ 𝑆 , 𝑠 , 𝑑 )
3:  /* 𝐸 βˆ’ 𝑆 is a 𝐹 -alphabet grid graph 𝐹 ( π‘š , 𝑛 ) or a 𝐢 -alphabet grid graph 𝐢 ( π‘š , 𝑛 ) */
4:   𝐷 ← HamiltonianCycle ( 𝑆 )
5:  return MergeStrip ( 𝑃 , 𝐷 , 𝑠 , 𝑑 )

Combining Lemma 3.2 and Theorem 2.1 the following corollary is trivial.

Corollary 3.3. Let 𝐴 ( π‘š , 𝑛 ) be an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph and 𝑅 be the smallest rectangular grid graph that includes 𝐴 . If ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is Hamiltonian, then 𝑠 and 𝑑 must be color compatible in 𝑅 .

Therefore, the color compatibility of 𝑠 and 𝑑 in 𝑅 is a necessary condition for ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) , ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) , ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) , and ( 𝐸 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) to be Hamiltonian.

Definition 3.4. The length of a path in a grid graph means the number of vertices of the path. In any grid graph, the length of any path between two same-colored vertices is odd and the length of any path between two different-colored vertices is even.

Lemma 3.5. Let 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) and 𝑅 ( π‘š , 5 𝑛 βˆ’ 4 ) be a separation of 𝐿 ( π‘š , 𝑛 ) such that three vertices 𝑣 , 𝑀 , and 𝑒 are in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) which are connected to 𝑅 ( π‘š , 5 𝑛 βˆ’ 4 ) . Assume that 𝑠 and 𝑑 are two given vertices of 𝐿 and 𝑠 β€² = 𝑀 and 𝑑 ξ…ž = 𝑑 , if 𝑠 ∈ 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) let 𝑠 ξ…ž = 𝑠 . If 𝑑 π‘₯ > π‘š + 1 and ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) satisfies condition (F3), then 𝐿 ( π‘š , 𝑛 ) does not have any Hamiltonian path between 𝑠 and 𝑑 .

Proof. Without loss of generality, let 𝑠 and 𝑑 be color compatible. Since π‘š , 𝑛 β‰₯ 3 and by Theorem 2.1 a rectangular grid graph does not have a Hamiltonian path only in condition (F3), so it suffices to prove the lemma for the case 𝑛 = 3 . Assume that 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) satisfies condition (F3). We show that there is no Hamiltonian path in 𝐿 ( π‘š , 𝑛 ) between 𝑠 and 𝑑 . Assume to the contrary that 𝐿 ( π‘š , 𝑛 ) has a Hamiltonian path 𝑃 . Since 𝑛 = 3 there are exactly three vertices 𝑣 , 𝑀 and 𝑒 in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) which are connected to 𝑅 ( π‘š , 5 𝑛 βˆ’ 4 ) , as shown in Figure 7(a). Then the following cases are possible. Case 1. 𝑑 ∈ 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) and 𝑠 βˆ‰ 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) . The following subcases are possible for the Hamiltonian path 𝑃 .Subcase 1.1. The Hamiltonian path 𝑃 of 𝐿 ( π‘š , 𝑛 ) that starts from 𝑠 may enter to 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) for the first time through one of the vertices 𝑣 , 𝑀 , or 𝑒 , pass through all the vertices of 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) and end at 𝑑 , see Figure 7(b). This case is not possible because we assumed that 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) satisfies (F3), in this case 𝑑 ξ…ž = 𝑑 and 𝑠 ξ…ž = 𝑀 .Subcase 1.2. The Hamiltonian path 𝑃 of 𝐿 ( π‘š , 𝑛 ) may enter to 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , pass through some vertices of it, then leave it and enter it again and pass through all the remaining vertices of it and finally end at 𝑑 . In this case, two subpaths of 𝑃 which are in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) are called 𝑃 1 and 𝑃 2 , 𝑃 1 from 𝑣 to 𝑒 ( 𝑣 to 𝑀 or 𝑒 to 𝑀 ) and 𝑃 2 from 𝑀 to 𝑑 ( 𝑒 to 𝑑 or 𝑣 to 𝑑 ). This case is not also possible because the size of 𝑃 1 is odd (even) and the size of 𝑃 2 is even (odd), then | 𝑃 1 + 𝑃 2 | is odd while 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) is even, which is a contradiction.Case 2 ( 𝑠 , 𝑑 ∈ 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) ). The following cases may be considered. Subcase 2.1. The Hamiltonian path 𝑃 of 𝐿 ( π‘š , 𝑛 ) which starts from 𝑠 may pass through some vertices of 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , leave 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑣 (or 𝑒 ), then passes through all the vertices of 𝑅 ( π‘š , 5 𝑛 βˆ’ 4 ) and reenter to 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑀 go to 𝑒 (or 𝑣 ) and pass through all the remaining vertices of 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) and end at 𝑑 . In this case by connecting 𝑣 (or 𝑒 ) to 𝑀 we obtain a Hamiltonian path from 𝑠 to 𝑑 in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , which contradicts the assumption that 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) satisfies ( 𝐹 3 ) .Subcase 2.2. The Hamiltonian path 𝑃 of 𝐿 ( π‘š , 𝑛 ) which starts from 𝑠 may leave 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑣 (or 𝑒 ), then pass through all the vertices of 𝑅 ( π‘š , 5 𝑛 βˆ’ 4 ) and reenter to 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑒 (or 𝑣 ) go to 𝑀 and pass through all the remaining vertices of 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) and end at 𝑑 . In this case, two parts of 𝑃 reside in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) . The part 𝑃 1 starts from 𝑠 ends at 𝑣 (or 𝑒 ), and the part 𝑃 2 starts from 𝑒 (or 𝑣 ) ends at 𝑑 . The size of 𝑃 1 is even and the size of 𝑃 2 is odd while the size of 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) is even, which is a contradiction.Subcase 2.3. Another case that may arise is that the Hamiltonian path 𝑃 of 𝐿 ( π‘š , 𝑛 ) starts from 𝑠 leaves 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑀 and reenters 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) at 𝑣 (or 𝑒 ) and then goes to 𝑑 . But in this case vertex 𝑒 (or 𝑣 ) cannot be in 𝑃 , which is a contradiction. Thus, the proof of Lemma 3.5 is completed.

Lemma 3.6. Let 𝐿 ( π‘š , 𝑛 ) and 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) be a separation of 𝐢 ( π‘š , 𝑛 ) such that three vertices 𝑣 1 , 𝑀 1 , and 𝑒 1 are in 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) which are connected to 𝐿 ( π‘š , 𝑛 ) and π‘₯ ∈ 𝐿 ( π‘š , 𝑛 ) is a adjacent vertex to 𝑀 1 . Assume that 𝑠 and 𝑑 are two given vertices of 𝐢 . If 𝑑 ∈ 𝐿 ( π‘š , 𝑛 ) and 𝑠 ∈ 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , let 𝑠 = π‘₯ and 𝑠 ξ…ž = 𝑀 1 , 𝑑 ξ…ž = 𝑠 , respectively. If ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) does not have a Hamiltonian path or ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) satisfies condition (F3), then 𝐢 ( π‘š , 𝑛 ) does not have a Hamiltonian path between 𝑠 and 𝑑 .

Proof. The proof is similar to the proof of Lemma 3.5, for more details see Figure 8.

Lemma 3.7. Let 𝐿 ( π‘š , 𝑛 ) and 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) be a separation of 𝐹 ( π‘š , 𝑛 ) such that three vertices 𝑣 1 , 𝑀 1 , and 𝑒 1 are in 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) which are connected to 𝐿 ( π‘š , 𝑛 ) and π‘₯ ∈ 𝐿 ( π‘š , 𝑛 ) is an adjacent vertex to 𝑀 1 . Assume that 𝑠 and 𝑑 are two given vertices of 𝐹 . If 𝑠 , 𝑑 ∈ 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) let 𝑠 ξ…ž = 𝑠 and 𝑑 ξ…ž = 𝑑 ; if 𝑠 (or 𝑑 ) ∈ 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) let 𝑠 ξ…ž = 𝑀 1 and 𝑑 ξ…ž = 𝑠 (or 𝑠 ξ…ž = 𝑀 1 and 𝑑 ξ…ž = 𝑑 ); if 𝑑 (or 𝑠 ) ∈ 𝐿 ( π‘š , 𝑛 ) let 𝑠 = π‘₯ ( ( 𝑑 = 𝑠 , 𝑠 = π‘₯ ) or ( 𝑑 = π‘₯ ) ) . If ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) does not have a Hamiltonian path or ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) satisfies the condition (F3), then 𝐹 ( π‘š , 𝑛 ) does not have a Hamiltonian path between 𝑠 and 𝑑 .

Proof. By a similar way as used in the Lemma 3.5 we can prove this lemma; for more details see Figure 9.

Lemma 3.8. Let 𝐹 ( π‘š , 𝑛 ) and 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) or 𝐢 ( π‘š , 𝑛 ) and 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) be a separation of 𝐸 ( π‘š , 𝑛 ) and 𝑠 and 𝑑 be two given vertices in 𝐸 ( π‘š , 𝑛 ) . If ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) or ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) does not have a Hamiltonian path, then 𝐸 ( π‘š , 𝑛 ) does not have a Hamiltonian path between 𝑠 and 𝑑 .

Proof. The proof is similar to the proof of Lemma 3.5, for more details see Figure 10.

From Corollary 3.3 and Lemmas 3.5, 3.6, 3.7, and 3.8, a Hamiltonian path problem 𝑃 ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is called acceptable if 𝑠 and 𝑑 are color-compatible and ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) does not satisfy the condition (F3); 𝑃 ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is called acceptable if 𝑃 ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is acceptable and ( 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) does not satisfy the condition (F3); 𝑃 ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is called acceptable if 𝑃 ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is acceptable and ( 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , 𝑠 ξ…ž , 𝑑 ξ…ž ) does not satisfy the condition (F3); 𝑃 ( 𝐸 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is called acceptable if 𝑃 ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) and ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) are acceptable.

Theorem 3.9. Let 𝐴 ( π‘š , 𝑛 ) be an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet or 𝐸 -alphabet grid graph. If ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is Hamiltonian, then 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is acceptable.

Now, we show that all acceptable Hamiltonian path problems have solutions by introducing algorithms to find Hamiltonian paths (sufficient conditions). Our algorithms are based on a divide-and-conquer approach. In the dividing phase we use two operations stirp and split which are defined in the following.

Definition 3.10. A subgraph 𝑆 of an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet or 𝐸 -alphabet grid graph A strips a Hamiltonian path problem 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) , if all of the following four conditions hold: ( 1 ) 𝑆 is even sized and: ( i ) 𝑆 is a rectangular grid graph; where 𝐴 ( π‘š , 𝑛 ) is a 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) , a 𝐢 -alphabet grid graph 𝐢 ( π‘š , 𝑛 ) and an 𝐸 -alphabet grid graph 𝐸 ( π‘š , 𝑛 ) ; ( i i ) 𝑆 is a 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ) , a rectangular graph 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) or three rectangular grid graphs 𝑅 1 βˆ’ 𝑅 3 ; where 𝐴 ( π‘š , 𝑛 ) is a 𝐹 -alphabet grid graph. ( 2 ) 𝑆 and 𝐴 βˆ’ 𝑆 is a separation of 𝐴 ; ( 3 ) 𝑠 , 𝑑 ∈ 𝐴 βˆ’ 𝑆 ; ( 4 ) 𝑃 ( 𝐴 βˆ’ 𝑆 , 𝑠 , 𝑑 ) is acceptable.

Definition 3.11. Let 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) be a Hamiltonian path problem and ( 𝑝 , π‘ž ) be an edge of 𝐴 , where 𝐴 ( π‘š , 𝑛 ) is an 𝐿 -alphabet, 𝐢 -alphabet, or 𝐹 -alphabet grid graph. Then we say ( 𝑝 , π‘ž ) splits ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) if there exists a separation of ( 1 ) 𝐿 into 𝑅 𝑝 and 𝑅 π‘ž such that ( i ) 𝑠 , 𝑝 ∈ 𝑅 𝑝 and 𝑃 ( 𝑅 𝑝 , 𝑠 , 𝑝 ) is acceptable, ( i i ) π‘ž , 𝑑 ∈ 𝑅 π‘ž and 𝑃 ( 𝑅 π‘ž , π‘ž , 𝑑 ) is acceptable. ( 2 ) 𝐹 (resp., 𝐢 ) into 𝑅 𝑝 and 𝐿 π‘ž or 𝑅 π‘ž and 𝐿 𝑝 ( resp., 𝐿 π‘ž and 𝑅 𝑝 ) such that ( i ) 𝑠 , 𝑝 ∈ 𝑅 𝑝 and 𝑃 ( 𝑅 𝑝 , 𝑠 , 𝑝 ) is acceptable (or 𝑠 , 𝑝 ∈ 𝐿 𝑝 and 𝑃 ( 𝐿 𝑝 , 𝑠 , 𝑝 ) is acceptable), ( i i ) π‘ž , 𝑑 ∈ 𝐿 π‘ž and 𝑃 ( 𝐿 π‘ž , π‘ž , 𝑑 ) is acceptable (or π‘ž , 𝑑 ∈ 𝑅 π‘ž and 𝑃 ( 𝑅 π‘ž , π‘ž , 𝑑 ) is acceptable).In the following, we describe for each alphabet class how the solutions of the subgraphs are merged to construct a Hamiltonian path for the given input graph.

3.1. Hamiltonian Paths in 𝐿 -Alphabet Grid Graphs 𝐿 ( π‘š , 𝑛 )

Since an 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ) may be partitioned into two rectangular grid graphs, then the possible cases for vertices 𝑠 and 𝑑 are as follows.

Case 1 ( 𝑠 , 𝑑 ∈ 𝐿 βˆ’ 𝑆 ). Assume that 𝐿 βˆ’ 𝑆 has a Hamiltonian path 𝑃 by the algorithm of [12], where 𝐿 βˆ’ 𝑆 is a rectangular gird graph. Since 𝑆 is an even-sized rectangular gird graph, then it has Hamiltonian cycle by Lemma 2.2; see Figure 11(a). Therefore, a Hamiltonian path for ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) can be obtained by merging 𝑃 and the Hamiltonian cycle of 𝑆 as shown in Figure 11(b).

Case 2 ( 𝑠 ∈ 𝑅 𝑝 and 𝑑 ∈ 𝑅 π‘ž ). In this case, we construct Hamiltonian paths in 𝑅 𝑝 and 𝑅 π‘ž between ( 𝑠 , 𝑝 ) and ( π‘ž , 𝑑 ) , respectively; see Figure 12(a). Then a Hamiltonian path for ( 𝐿 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) can be obtained by connecting two vertices 𝑝 and π‘ž as shown in Figure 12(b).

3.2. Hamiltonian Paths in 𝐢 -Alphabet Grid Graphs 𝐢 ( π‘š , 𝑛 )

Similar to 𝐿 -alphabet graphs since a 𝐢 -alphabet graph 𝐢 ( π‘š , 𝑛 ) may be partitioned into a 𝐿 -alphabet graph 𝐿 ( π‘š , 𝑛 ) and a rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) , then the possible cases for vertices 𝑠 and 𝑑 are as follows.

Case 1 ( 𝑠 , 𝑑 ∈ 𝐢 βˆ’ 𝑆 ). Assume that 𝐢 βˆ’ 𝑆 has a Hamiltonian path 𝑃 by the Algorithm 1, where 𝐢 βˆ’ 𝑆 is an 𝐿 -alphabet gird graph 𝐿 ( π‘š , 𝑛 ) . Hence, a Hamiltonian path for ( 𝐢 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) can be obtained by merging 𝑃 and the Hamiltonian cycle of 𝑆 as shown in Figure 11(c).

Case 2 ( 𝑠 ∈ 𝑅 𝑝 and π‘ž ∈ 𝐿 π‘ž ). A Hamiltonian path can be found as Figure 12(c).

3.3. Hamiltonian Paths in 𝐹 -Alphabet Grid Graphs 𝐹 ( π‘š , 𝑛 )

For 𝐹 -alphabet grid graphs, we consider the following cases.

Case 1 ( 𝑠 , 𝑑 ∈ 𝐹 βˆ’ 𝑆 , where 𝐹 βˆ’ 𝑆 is 𝐿 ( π‘š , 𝑛 ) ). In this case, we construct a Hamiltonian path between 𝑠 and 𝑑 in 𝐿 ( π‘š , 𝑛 ) by the Algorithm 1. Since 𝑆 is an even-sized rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , then it has a Hamiltonian cycle by Lemma 2.2.

Case 2 ( 𝑠 , 𝑑 ∈ 𝐹 βˆ’ 𝑆 , where 𝐹 βˆ’ 𝑆 is 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ). We construct a Hamiltonian path between 𝑠 and 𝑑 in 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) by the algorithm in [12]. Since 𝑆 is an even-sized 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) , then it has a Hamiltonian cycle by Lemma 2.3.

In two cases, by combining the Hamiltonian cycle of 𝑆 and the Hamiltonian path of 𝐿 or 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , a Hamiltonian path between 𝑠 and 𝑑 for 𝐹 ( π‘š , 𝑛 ) is obtained, see Figures 13(a) and 13(b).

Case 3 ( 𝐹 ( π‘š , 𝑛 ) is odd sized and 𝑠 , 𝑑 ∈ 𝐹 βˆ’ 𝑆 , where 𝐹 βˆ’ 𝑆 is 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ). In this case, 𝑠 and 𝑑 must be white. Since 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) is even sized, then 𝑠 and 𝑑 are not color compatible in 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) , see Figure 14(a). Therefore, we repartition 𝐹 ( π‘š , 𝑛 ) into four rectangular grid graphs 𝑅 1 , 𝑅 2 , 𝑅 3 , and 𝑅 4 , such that 𝑠 , 𝑑 ∈ 𝑉 ( 𝑅 1 ) and 𝑅 2 , 𝑅 3 , and 𝑅 4 are even sized, see Figure 14(b) where the dotted lines represent the strip. In this case, by combining the Hamiltonian cycles in 𝑅 2 , 𝑅 3 , and 𝑅 4 and the Hamiltonian path of 𝑅 1 , a Hamiltonian path between 𝑠 and 𝑑 for ( 𝐹 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is obtained, see Figure 14(c).

Case 4 ( 𝑠 ∈ 𝑅 𝑝 and 𝑑 ∈ 𝐿 π‘ž or 𝑠 ∈ 𝐿 𝑝 and π‘ž ∈ 𝑅 π‘ž ). A Hamiltonian path can be found as Figure 15.

3.4. Hamiltonian Paths in 𝐸 -Alphabet Grid Graphs 𝐸 ( π‘š , 𝑛 )

A Hamiltonian path for an 𝐸 -alphabet grid graph 𝐸 ( π‘š , 𝑛 ) can be found using striping. So we strip 𝐸 ( π‘š , 𝑛 ) such that 𝑠 , 𝑑 ∈ 𝐸 βˆ’ 𝑆 , where 𝐸 βˆ’ 𝑆 is 𝐹 -alphabet 𝐹 ( π‘š , 𝑛 ) or 𝐢 -alphabet 𝐢 ( π‘š , 𝑛 ) . In this case, we construct a Hamiltonian path in 𝐹 ( π‘š , 𝑛 ) (or 𝐢 ( π‘š , 𝑛 ) by Algorithm 3 (or 4). Since 𝑆 is an even-sized rectangular grid graph 𝑅 ( 2 π‘š βˆ’ 2 , 𝑛 ) (or 𝑅 ( 2 π‘š βˆ’ 4 , 𝑛 ) ) , then it has a Hamiltonian cycle by Lemma 2.2. By combining the Hamiltonian cycle of 𝑆 and the Hamiltonian path of 𝐹 or 𝐢 , a Hamiltonian path between 𝑠 and 𝑑 for 𝐸 ( π‘š , 𝑛 ) is obtained, see Figure 13(c).

Thus, we have the following lemmas.

Lemma 3.12. Let ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) be an acceptable Hamiltonian path problem, and 𝑆 strips it, where 𝐴 ( π‘š , 𝑛 ) is an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph. If 𝐴 βˆ’ 𝑆 has a Hamiltonian path between 𝑠 and 𝑑 , then ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) has a Hamiltonian path between 𝑠 and 𝑑 .

Lemma 3.13. Let ( 𝑝 , π‘ž ) be an edge which splits 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) . If ( i )   ( 𝑅 𝑝 , 𝑠 , 𝑝 ) and ( 𝑅 π‘ž , π‘ž , 𝑑 ) , where 𝐴 ( π‘š , 𝑛 ) is 𝐿 -alphabet grid graph 𝐿 ( π‘š , 𝑛 ) , ( i i ) ( 𝐿 π‘ž , π‘ž , 𝑑 ) and ( 𝑅 𝑝 , 𝑠 , 𝑝 ) , where 𝐴 ( π‘š , 𝑛 ) is 𝐢 -alphabet grid graph 𝐢 ( π‘š , 𝑛 ) , ( i i i ) ( 𝑅 𝑝 , 𝑠 , 𝑝 ) and ( 𝐿 π‘ž , π‘ž , 𝑑 ) or ( 𝑅 π‘ž , π‘ž , 𝑑 ) and ( 𝐿 𝑝 , 𝑠 , 𝑝 ) , where 𝐴 ( π‘š , 𝑛 ) is 𝐹 -alphabet grid graph 𝐹 ( π‘š , 𝑛 ) ,
have a Hamiltonian path between ( 𝑠 , 𝑝 ) and ( π‘ž , 𝑑 ) , then 𝐴 ( π‘š , 𝑛 ) also has a Hamiltonian path between 𝑠 and 𝑑 .

Since all the proofs presented in this section were constructive, they give us algorithms for finding a Hamiltonian path in 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, and 𝐸 -alphabet grid graphs. The pseudo-codes of the algorithms are given in Algorithms 1, 2, 3, and 4. In these algorithms, HamiltonianCycle is the procedure that finds the Hamiltonian cycle of a strip based on Lemma 2.2 or Lemma 2.3, MergeStrip is a procedure that merges a path and a cycle(s), MergeCycles is a procedure that combine two Hamiltonian cycles using two parallel edges of 𝑒 1 and 𝑒 2 , MergeSplit is a procedure that connects two paths by simply adding an edge between their end vertices 𝑝 and π‘ž , and R_HamiltonianPath is a procedure that finds a Hamiltonian path in a rectangular grid graph by the algorithm in [12]. The algorithm first checks if the input graph 𝐴 can be stripped, then strips 𝐴 by 𝑆 , and recursively finds a Hamiltonian path of 𝐴 βˆ’ 𝑆 . Otherwise, if 𝐴 can be split, then splits 𝐴 into 𝑅 𝑝 and 𝑅 π‘ž ( 𝐿 π‘ž and 𝑅 𝑝 or 𝑅 π‘ž and 𝐿 𝑝 ), and recursively finds Hamiltonian paths of 𝑅 𝑝 and 𝑅 π‘ž ( 𝐿 π‘ž and 𝑅 𝑝 or 𝑅 π‘ž and 𝐿 𝑝 ). Then these two Hamiltonian paths are merged into a single path, where 𝐴 ( π‘š , 𝑛 ) is an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph.

From Theorem 3.9 and Lemmas 3.12 and 3.13 the following theorem holds.

Theorem 3.14. Let 𝐴 ( π‘š , 𝑛 ) be an 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, or 𝐸 -alphabet grid graph, and 𝑠 and 𝑑 be two distinct vertices of it. 𝐴 ( π‘š , 𝑛 ) has Hamiltonian path if and only if 𝑃 ( 𝐴 ( π‘š , 𝑛 ) , 𝑠 , 𝑑 ) is acceptable.

Theorem 3.14 provides necessary and sufficient conditions for the existence of Hamiltonian paths in 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet and 𝐸 -alphabet grid graphs.

Combining Theorem 3.14 and the Algorithms 1, 2, 3, and 4 we arrive at the main result.

Theorem 3.15. In 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet or 𝐸 -alphabet grid graphs, a Hamiltonian path between any two vertices 𝑠 and 𝑑 can be found in linear time.

Proof. The algorithms divide the problem into some rectangular grid graphs in 𝑂 ( 1 ) . Then we solve the subproblems in linear time using the linear time algorithm in [12]. Then the results are merged in time 𝑂 ( 1 ) using the method proposed in [12].

4. Conclusion and Future Work

In this paper, we presented linear time algorithms for finding a Hamiltonian path in 𝐿 -alphabet, 𝐢 -alphabet, 𝐹 -alphabet, and 𝐸 -alphabet grid graphs between any two given vertices. Since the Hamiltonian path problem is NP-complete in general grid graphs, it remains open if the problem is polynomially solvable in solid grid graphs.

References

  1. R. Diestel, Graph Theory, vol. 173, Springer, New York, NY, USA, 2nd edition, 2000. View at: Publisher Site | Zentralblatt MATH
  2. M. R. Garey and D. S. Johnson, Computers and Intractability, W. H. Freeman and Co., San Francisco, Calif, USA, 1979. View at: Zentralblatt MATH
  3. P. Damaschke, β€œPaths in interval graphs and circular arc graphs,” Discrete Mathematics, vol. 112, no. 1–3, pp. 49–64, 1993. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  4. L. Du, β€œA polynomial time algorithm for hamiltonian cycle (Path),” in Proceedings of the International MultiConference of Engineers and Computer Scientists (IMECS '10), vol. 1, pp. 17–19, Hong Kong, 2010. View at: Google Scholar
  5. R. J. Gould, β€œAdvances on the Hamiltonian problem—a survey,” Graphs and Combinatorics, vol. 19, no. 1, pp. 7–52, 2003. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  6. Y. Gurevich and S. Shelah, β€œExpected computation time for Hamiltonian path problem,” SIAM Journal on Computing, vol. 16, no. 3, pp. 486–502, 1987. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  7. S.-S. Kao and L.-H. Hsu, β€œSpider web networks: a family of optimal, fault tolerant, Hamiltonian bipartite graphs,” Applied Mathematics and Computation, vol. 160, no. 1, pp. 269–282, 2005. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  8. M. S. Rahman and M. Kaykobad, β€œOn Hamiltonian cycles and Hamiltonian paths,” Information Processing Letters, vol. 94, no. 1, pp. 37–41, 2005. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  9. F. Luccio and C. Mugnia, β€œHamiltonian paths on a rectangular chessboard,” in Proceedings of the 16th Annual Allerton Conference, pp. 161–173, 1978. View at: Google Scholar
  10. A. Itai, C. H. Papadimitriou, and J. L. Szwarcfiter, β€œHamilton paths in grid graphs,” SIAM Journal on Computing, vol. 11, no. 4, pp. 676–686, 1982. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  11. C. Zamfirescu and T. Zamfirescu, β€œHamiltonian properties of grid graphs,” SIAM Journal on Discrete Mathematics, vol. 5, no. 4, pp. 564–570, 1992. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  12. S. D. Chen, H. Shen, and R. Topor, β€œAn efficient algorithm for constructing Hamiltonian paths in meshes,” Parallel Computing. Theory and Applications, vol. 28, no. 9, pp. 1293–1305, 2002. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  13. W. Lenhart and C. Umans, β€œHamiltonian cycles in solid grid graphs,” in Proceedings of the 38th Annual Symposium on Foundations of Computer Science (FOCS '97), pp. 496–505, 1997. View at: Google Scholar
  14. A. N. M. Salman, Contributions to graph theory, Ph.D. thesis, University of Twente, 2005.
  15. K. Islam, H. Meijer, Y. Nunez, D. Rappaport, and H. Xiao, β€œHamiltonian circuts in hexagonal grid graphs,” in Proceedings of the CCCG, pp. 20–22, 2007. View at: Google Scholar
  16. V. S. Gordon, Y. L. Orlovich, and F. Werner, β€œHamiltonian properties of triangular grid graphs,” Discrete Mathematics, vol. 308, no. 24, pp. 6166–6188, 2008. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  17. M. Nandi, S. Parui, and A. Adhikari, β€œThe domination numbers of cylindrical grid graphs,” Applied Mathematics and Computation, vol. 217, no. 10, pp. 4879–4889, 2011. View at: Publisher Site | Google Scholar | Zentralblatt MATH
  18. F. Keshavarz-Kohjerdi, A. Bagheri, and A. Asgharian-Sardroud, β€œA linear-time algorithm for the longest path problem in rectangular grid graphs,” Discrete Applied Mathematics, vol. 160, no. 3, pp. 210–217, 2012. View at: Publisher Site | Google Scholar
  19. F. Keshavarz-Kohjerdi and A. Bagheri, β€œAn efficient parallel algorithm for the longest path problem in meshes,” http://arxiv.org/abs/1201.4459. View at: Google Scholar

Copyright © 2012 Fatemeh Keshavarz-Kohjerdi and Alireza Bagheri. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.


More related articles

 PDF Download Citation Citation
 Download other formatsMore
 Order printed copiesOrder
Views7081
Downloads1634
Citations

Related articles

Article of the Year Award: Outstanding research contributions of 2020, as selected by our Chief Editors. Read the winning articles.