You are on page 1of 5

JOURNAL OF COMPUTING, VOLUME 3, ISSUE 9, SEPTEMBER 2011, ISSN 2151-9617 HTTPS://SITES.GOOGLE.COM/SITE/JOURNALOFCOMPUTING WWW.JOURNALOFCOMPUTING.

ORG

Hamiltonian Paths in K-alphabet Grid Graphs


Fatemeh Keshavarz-Kohjerdi and Alireza Bagheri
AbstractGiven a graph G, the Hamiltonian path problem is the problem of deciding whether a graph G contains a simple path that visits each vertex of G exactly once. This problem is a NP-complete problem for general grid graphs. In this paper, we provide the necessary and sufficient condition for the Hamiltonian path problem on special class of grid graphs, namely on a Kalphabet grid graphs. Index TermsAlphabet grid graph, Grid graph, Hamiltonian cycle, Hamiltonian path, Rectangular grid graph.

1 INTRODUCTION
he Hamiltonian path problem is to find a path in graph from a starting vertex to an ending vertex such that every vertex is visited once. The problem of deciding whether a given graph has a Hamiltonian path is a wellknown 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]. Rectangular grid graphs first appeared in [4], where Luccio and Mugnia tried to solve the Hamiltonian path problem. Itai et al. [5] 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 [6] 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. [7] improved the algorithm of [5] 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 [8]. Recently, Salman et al. [9] introduced alphabet grid graphs and determined the classes of alphabet grid graphs which contain Hamiltonian cycles. More recently, The Hamiltonian path problem for some classes of grid graphs was studied in [10, 11], and necessary and sufficient conditions for existence of Hamiltonian paths in these grid graphs were given. Moreover, the authors in [12, 13] gave sequential and parallel algorithms for the longest path problem in rectangular

grid graphs. Some results of the grid graphs are investigated in [14, 15, 16]. In this paper, we give the necessary and sufficient condition for existence of Hamiltonian paths in Kalphabet grid graphs. Solving the Hamiltonian path problem for alphabet grid graphs can arises the results that help to solve the problem for general solid grid graphs.

2 PRELIMINARIES
The two-dimensional integer grid G 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 V of this graph, let v x and v y denote x and y coordinates of its corresponding point. A grid graph G g is a finite vertexinduced subgraph of the two-dimensional integer grid. In a grid graph G g , each vertex has degree at most four. A rectangular grid graph R(m,n) (or R for short) is a grid graph whose vertex set is V(m,n)={v|1xm and 1yn} R(m,n) is called a n -rectangle. A solid grid graph is a grid graph without holes. By [5], a vertex v is colored white if v x +v y is even, and is colored black otherwise. The size of R(m,n) is defined to be mn. R(m,n) is called odd-sized if mn is odd, and is called even-sized otherwise. Two different vertices v and v in R(m,n) is called color-compatible if either both vertices v and v are white and R(m,n) is odd-sized, or v and v have different colors and R(m,n) is even-sized. For m,n3, a K-alphabet grid graph K(m,n) (or K for short) is a subgraph of R(3m-2, 5n-4) as shown in Fig 1. 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 A(m,n) we mean a grid graph A(m,n). We use P(A(m,n),s,t) to indicate the problem of finding a Hamiltonian path between vertices s and t in grid graph
P P R R R R R R R R R R R R P P

F. Keshavarz-Kohjerdi, Department of Computer Engineering, Islamic Azad University, North Tehran Branch, Tehran, Iran. A. Bagheri, Department of Computer Engineering & IT, Amirkabir University of Technology, Tehran, Iran.

2011 Journal of Computing Press, NY, USA, ISSN 2151-9617

JOURNAL OF COMPUTING, VOLUME 3, ISSUE 9, SEPTEMBER 2011, ISSN 2151-9617 HTTPS://SITES.GOOGLE.COM/SITE/JOURNALOFCOMPUTING WWW.JOURNALOFCOMPUTING.ORG

A(m,n), and use (A(m,n),s,t) to indicate the grid graph A(m,n) with two specified distinct vertices s and t of it, where A is a rectangular grid graph or a Kalphabet grid graph. (A(m,n),s,t) is Hamiltonian if there is a Hamiltonian path between s and t in A(m,n). In this paper, without loss of generality we assume s x t x , mn and all Kalphabet grid graphs considered here are oddodd.
R R R R

edges on three sides of the rectangular graph. This shows that for an even-sized rectangular graph R, we can always find a Hamiltonian cycle, such that it contains all boundary edges, expect of exactly one side of R which contain an even number of vertices.

Itai et al. [5] showed that if one of the following condition holds, then (R(m,n),s,t) is not Hamiltonian: (F1) R(m,n) is a 1-rectangle and either s or t is not a corner vertex (Fig. 2(a)). (F2) R(m,n) is a 2-rectangle and (s,t) is a nonboundary edge, i.e. (s,t) is an edge and it is not on the outer face (Fig. 2(b)). (F3) R(m,n) is isomorphic to a 3-rectangle R(m,n) such that s and t are mapped to s and t, and: 1. m is even, 2. s is black, t is white, 3. s=2 and s x <t x (Fig. 2(c)) or s 2 and s x <t x -1 (Fig. 2(d)).
P P P P P P P P P P P P R RP P R RP P P P R RP P R RP P

Fig. 3. A Hamiltonian cycle in R(8,5).

4 THE NECESSARY AND SUFFICIENT CONDITION


In this section, we give the necessary and sufficient condition for existence of Hamiltonian paths in K-alphabet grid graphs. Definition 3.1. A separation of a Kalphabet grid graph K(m,n) is a partition of K into four (or five) rectangular grid graphs R 1 , R 2 , R 3 , and R 4 (and R 5 ).
R R R R R R R R R R

A Hamiltonian path problem P(R(m,n),s,t) is called acceptable if s and t are color-compatible and (R,s,t) does not satisfy any of conditions (F1), (F2) and (F3).

In the following, two non-incident edges e 1 and e 2 are parallel, if each end vertex of e 1 is adjacent to some end vertex of e 2 .
R R R R R R R R

Fig.1. A rectangular grid graph R(7,11), (b) a Kalphabet grid graph

K(3,3).

Fig. 2. Rectangular grid graphs in which there is no Hamiltonian path between s and t.

Theorem 2.1. [5] Let R(m,n) be a rectangular grid graph and s and t be two distinct vertices. Then (R(m,n),s,t) is Hamiltonian if and only if P(R(m,n),s,t) is acceptable. Lemma 2.1. [7] R(m,n) has a Hamiltonian cycle if and only if it is even-sized and m,n>1. Fig. 3 shows a Hamiltonian cycle for an even-sized rectangular grid graph, found by Lemma 2.1. Each Hamiltonian cycle found by this lemma contains all the boundary

Lemma 3.2. Let K(m,n) be a K-alphabet grid graph and R be the smallest rectangular grid graph includes K. If (K(m,n),s,t) is Hamiltonian, then (R,s,t) is also Hamiltonian. Proof: Let P be a Hamiltonian path in K. We break the proof into two cases: Case 1. m n>3 or n=3 and m > 3. Since R-K can be partitioned into four even-sized rectangular grid graphs of R 1 (2m-2,n-1), R 2 (m-2,n-1), R 3 (2m-2,n-1) and R 4 (m-2,n-1), then they have Hamiltonian cycles by Lemma 2.3 (i.e. we can find Hamiltonian cycles of R-K, such that they contains all edges of R-K that are parallel to some edge of P). Then combine Hamiltonian cycles on R 1 (2m-2,n-1) and R 2 (m-2,n-1), and R 3 (2m-2,n-1) and R 4 (m-2,n-1) to be two large Hamiltonian cycles and then using two triple parallel edges of P and the Hamiltonian cycle of R-K, we can obtain a Hamiltonian path for R. Case 2. m=n=3. Let R-K be four rectangular grid graphs of R 1 (2m-2,n-1), R 2 (m-2,n-1), R 3 (2m-2,n-1) and R 4 (m-2,n-1) such that two triple vertices (v 1 ,v 2 ) and (v 3 ,v 4 ) be in R 2 (m2,n-1) and R 4 (m-2,n-1), respectively. There exist four edges e 1 , e 2 , e 3 , e 4 in P such that (e 1 ,e3), (e 1 ,e 4 ), (e 2 ,e 4 ) or (e 2 ,e 3 ) is on the boundary of R(m,n) facing R 2 (m-2,n-1) and R 4 (m-2,n-1); see Fig. 4(a). Hence, by combining a Hamiltonian path P and Hamiltonian cycles (in R 1 (2m-2,n-1) and R 3 (2m-2,n-1)) and (v 1 ,v 2 ) and (v 3 ,v 4 ) a Hamiltonian path between s and t is obtained, see Fig. 4(b).
R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R

2011 Journal of Computing Press, NY, USA, ISSN 2151-9617

JOURNAL OF COMPUTING, VOLUME 3, ISSUE 9, SEPTEMBER 2011, ISSN 2151-9617 HTTPS://SITES.GOOGLE.COM/SITE/JOURNALOFCOMPUTING WWW.JOURNALOFCOMPUTING.ORG

10

Since a Kalphabet grid graph K(m,n) partition into four (or five) rectangular grid graphs, then three cases are possible for vertices s and t. Case 1. Both s and t are in K-S. In this case, we construct a Hamiltonian path between s and t in K-S by algorithm of [7], where S is a rectangular grid graph. Since S is three (or four) even-sized rectangular grid graphs, then by Lemma 2.1 they have Hamiltonian cycles. By combining Hamiltonian cycles and the Hamiltonian path, a Hamiltonian path between s and t for (K(m,n),s,t) is obtained, see Fig. 5, 6. Case 2. s and t are in two adjacent rectangular grid graphs Fig. 7(a). Let R p , R q , R c and R d be a separation of a Kalphabet grid graph K(m,n) such that R c and R d are two even-sized rectangular grid graphs. Let P be a Hamiltonian path in K(m,n). We consider two vertices p and q such that s,p are in R P and q,t are in R q , and P(R P ,s,p) and P(R q ,q,t) are acceptable. Then we construct a Hamiltonian path in R P and R q between (s,p) and (q,t), respectively. Two Hamiltonian paths in R P and R q are connected by an edge (p,q) , let this subpath of P be P 1 . Finally, a Hamiltonian path for (K(m,n),s,t) can be obtained by merging P 1 and Hamiltonian cycles in R c and R d , as shown in Fig. 7(b).
R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R R

Fig. 4. A Hamiltonian path in R(7, 11).

Corollary 3.3. Let K(m,n) be a Kalphabet grid graph and R be the smallest including rectangular grid graph K. If (K(m,n),s,t) is Hamiltonian, then s and t must be colorcompatible in R. Therefore, the color-compatibility of s and t in R is a necessary condition for (K(m,n),s,t) to be Hamiltonian. From Corollary 3.3, a Hamiltonian path problem P(K(m,n),s,t) is called acceptable if s and t are colorcompatible. Now, we are shown that all acceptable Hamiltonian path problems have solutions. We divide the given Kalphabet grid graph into four (or five) rectangular grid graphs and we find Hamiltonian paths in them by algorithm of [7]. In the following we discuss the details of this dividing and merging. Definition 3.4. A rectangular grid subgraph S of Kalphabet grid graph K strips a Hamiltonian path problem P(K(m,n),s,t), if: 1) S is even-sized, where S is three (or Four) rectangular grid graphs R 1, R 2 and R 3 (and R 4 ); 2) S and K-S is a separation of K; 3) Both s and t are in K-S; 4) P(K-S,s,t) is acceptable. Definition 3.5. A trisecting on a Kalphabet grid graph K(m,n) is a separation of K into three rectangular grid graphs R s , R t and R g such that, R s and R t are two rectangular grid graphs of R(m,5n-4) and R(m,3n-2), s is in R s and t is in R t .
R R R R R R R R R R R R R R R R R R R R R R

Definition 3.6. A corner vertex on the boundary of R t (resp., R s ) facing R g is called a junction vertex of R t (resp., R s ) if it is white.
R R R R R R R R R

Fig. 5. A strip of K(3, 3).

2011 Journal of Computing Press, NY, USA, ISSN 2151-9617

JOURNAL OF COMPUTING, VOLUME 3, ISSUE 9, SEPTEMBER 2011, ISSN 2151-9617 HTTPS://SITES.GOOGLE.COM/SITE/JOURNALOFCOMPUTING WWW.JOURNALOFCOMPUTING.ORG

11

nian path between s and t. Lemma 3.8. Let P(K(m,n),s,t) be an acceptable Hamiltonian path problem, and (R p ,s,p), (R q ,q,t), R c and R d be a separation of K which P(R p ,s,p) and P(R q ,q,t) are an acceptable and R c and R d are even-sized. If (R p ,s,p) and (R q ,q,t) have a Hamiltonian path between (s,p) and(q,t), respectively, then K(m,n) also has a Hamiltonian path between s and t.
R R R R R R R R R R R R R R R R R R R R

Case 3. s and t are in two non-adjacent rectangular grid graphs. In this case, by definitions of trisecting and junction vertex we finding a Hamiltonian path in R s , R t and R g , then a Hamiltonian path in R g is connected to its neighboring paths by adding an edge between their end vertices, see Fig. 7(c). Hence, we have the following lemma:
R R R R R R R R

Fig. 6. A strip of K(5, 5).

Lemma 3.9. For finding Hamiltonian path, perform a trisecting on (K(m,n),s,t). Then both R s and R t have two junction vertices. Proof: Since both s and t are white and two corner vertices on the boundary of R s (resp., R t ) facing R g are white, then both of them are junction vertices.
R R R R R R R R R R

From Corollary 3.3 and Lemmas 3.7, 3.8 and 3.9 the following theorem holds. Theorem 3.9. Let K(m,n) be a Kalphabet grid graph, and s and t be two distinct vertices of it. K(m,n) has a Hamiltonian path if and only if P(K(m,n),s,t) is acceptable. Theorem 3.9 provides the necessary and sufficient condition for existence of Hamiltonian paths in Kalphabet grid graphs.

CONCLUSION

We provide the necessary and sufficient condition for the Hamiltonian path problem in Kalphabet grid graphs between any two given vertices, where K(m,n) is oddodd. Since the Hamiltonian path problem is NPcomplete in general grid graphs, it remains open if the problem is polynomially solvable in solid grid graphs.

ACKNOWLEDGMENT
The authors wish to express their sincere thanks to the referee for his/her valuable comments.
Fig. 7. (a), (b) A Hamiltonian path in K(3,3), (c) A trisecting on K(3, 3).

Thus, we have two following lemmas: Lemma 3.7. Let P(K(m,n),s,t) be an acceptable Hamiltonian path problem, and S strips it. If K-S has a Hamiltonian path between s and t, then (K(m,n),s,t) has a H milto 2011 Journal of Computing Press, NY, USA, ISSN 2151-9617

JOURNAL OF COMPUTING, VOLUME 3, ISSUE 9, SEPTEMBER 2011, ISSN 2151-9617 HTTPS://SITES.GOOGLE.COM/SITE/JOURNALOFCOMPUTING WWW.JOURNALOFCOMPUTING.ORG

12

References
[1] [2] [3] [4] [5] [6] [7] R. Diestel, Graph Theory, Springer, New York, 2000. M. R. Garey and D. S. Johnson, Computers and Intractability: A Guide to the Theory of NP-completeness, Freeman, San Francisco, 1979. R. J. Gould, Advances on the Hamiltonian problem: a survey, Graphs and Combinatorics, vol. 19, pp. 7-52, 2003. F. Luccio and C. Mugnia, Hamiltonian Paths on a Rectangular Chessboard, Proc. 16th Annual Allerton Conference, pp. 161-173, 1978. A. Itai, C. Papadimitriou and J. Szwarcfiter, Hamiltonian Paths in Grid Graphs, SIAM J. Comput., vol. 11, no. 4, pp. 676-686, 1982. C. Zamfirescu and T. Zamfirescu, Hamiltonian Properties of Grid Graphs, SIAM J. Math., vol. 5, no. 4, pp. 564-570, 1992. S. D. Chen, H. Shen and R. Topor, an Efficient Algorithm for Constructing Hamiltonian Paths in Meshes, J. Parallel Computing, vol. 28, no. 9, pp. 1293-1305, 2002. W. Lenhart and C. Umans, Hamiltonian Cycles in Solid Grid Graphs, Proc. 38th Annual Symposium on Foundations of Computer Science FOCS '97), pp. 496-505, 1997. N. M. Salman, Contributions to Graph Theory, Ph.D. Thesis University of Twente, 2005. F. Keshavarz-Kohjerdi and A. Bagheri, Hamiltonian Paths in some Classes of Grid Graphs, preprint. F. Keshavarz-Kohjerdi, A. Bagheri, and B. Tayfe-Rezaie, Hamiltonian Paths in J-alphabet Grid Graphs, Proc. 2nd World Conference on Information Technology, to appear, 2011. F. Keshavarz-Kohjerdi, A. Bagheri and A. Asgharian-Sardroud, a Linear-time Algorithm for the Longest Path Problem in Rectangular Grid Graphs, Discrete Applied Math., 10.1016/j.dam.2011.08.010. F. Keshavarz-Kohjerdi and A. Bagheri, a Parallel Algorithm for the Longest Path Problem in Rectangular Grid Graphs, preprint. V. S. Gordon, Y. L. Orlovich and F. Werner, Hamiltonian properties of triangular grid graphs, Discrete Math., vol. 308, pp. 6166-6188, 2008. K. Islam, H. Meijer, Y. Nunez, D. Rappaport and H. xiao, Hamiltonian Circuts in Hexagonal Grid Graphs, CCCG, pp. 20-22, 2007. 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.
P P

[8]

[9] [10] [11]

[12]

[13] [14] [15] [16]

Fatemeh Keshavarz-Kohjerdi received the M.S. degree in computer engineering from Islamic Azad University (IAU), North Tehran Branch at Tehran, the B.S. degree in computer engineering from Islamic Azad University, Shiraz Branch at Shiraz. Her research interests include graph theory, algorithms, computational geometry and combinatorics.

Alireza Bagheri received the B.S. and M.S. degrees in computer engineering from Sharif University of Technology (SUT) at Tehran, the Ph.D degree in computer science from Amirkabir University of Technology (AUT) at Tehran. Currently he is an assistant professor in the computer engineering and IT department at Amirkabir University of Technology at Tehran. His research interests include computational geometry, graph drawing and graph algorithms.

2011 Journal of Computing Press, NY, USA, ISSN 2151-9617

You might also like