Next Article in Journal
Simple and Robust Boolean Operations for Triangulated Surfaces
Next Article in Special Issue
Clique Transversal Variants on Graphs: A Parameterized-Complexity Perspective
Previous Article in Journal
Short Memory-Based Human Strategy Modeling in Social Dilemmas
Previous Article in Special Issue
An Algorithm for the Numbers of Homomorphisms from Paths to Rectangular Grid Graphs
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

The Longest (s, t)-Path Problem on O-Shaped Supergrid Graphs

by
Fatemeh Keshavarz-Kohjerdi
1 and
Ruo-Wei Hung
2,*
1
Department of Mathematics and Computer Science, Shahed University, Tehran 3319118651, Iran
2
Department of Computer Science and Information Engineering, Chaoyang University of Technology, Wufeng, Taichung 413310, Taiwan
*
Author to whom correspondence should be addressed.
Mathematics 2023, 11(12), 2712; https://doi.org/10.3390/math11122712
Submission received: 6 May 2023 / Revised: 6 June 2023 / Accepted: 12 June 2023 / Published: 15 June 2023
(This article belongs to the Special Issue Graph Theory: Advanced Algorithms and Applications)

Abstract

:
The longest ( s , t ) -path problem on supergrid graphs is known to be NP-complete. However, the complexity of this problem on supergrid graphs with or without holes is still unknown.In the past, we presented linear-time algorithms for solving the longest ( s , t ) -path problem on L-shaped and C-shaped supergrid graphs, which form subclasses of supergrid graphs without holes. In this paper, we will determine the complexity of the longest ( s , t ) -path problem on O-shaped supergrid graphs, which form a subclass of supergrid graphs with holes. These graphs are rectangular supergrid graphs with rectangular holes. It is worth noting that O-shaped supergrid graphs contain L-shaped and C-shaped supergrid graphs as subgraphs, but there is no inclusion relationship between them. We will propose a linear-time algorithm to solve the longest ( s , t ) -path problem on O-shaped supergrid graphs. The longest ( s , t ) -paths of O-shaped supergrid graphs have applications in calculating the minimum trace when printing hollow objects using computer embroidery machines and 3D printers.

1. Introduction

All graphs considered in this paper are undirected and simple. Let G be a graph. We denote the vertex set and the edge set of G by V ( G ) and E ( G ) , respectively. A Hamiltonian path (resp., cycle) on graph G is a simple path (resp., cycle) that visits every vertex of G exactly once. The Hamiltonian path (cycle) problem involves determining whether a graph has a Hamiltonian path (cycle). A Hamiltonian ( s , t ) -path is a Hamiltonian path in a graph that starts from vertex s and ends at vertex t. A graph is Hamiltonian-connected if it contains a Hamiltonian ( s , t ) -path for every two distinct vertices s , t in the graph. The longest ( s , t ) -path in a graph is the path from s to t that visits the most vertices. The longest ( s , t ) -path problem on a graph involves determining whether the graph contains a Hamiltonian ( s , t ) -path and finding the longest ( s , t ) -path if it is not. The above problems are NP-complete for general graphs [1,2], as well as for various special graph classes, including undirected path graphs [3], circle graphs [4], split graphs [5], triangular grid graphs [6], supergrid graphs [7], bipartite graphs [8], grid graphs [9], and so on. Next, we will discuss the conditions under which a Hamiltonian ( s , t ) -path does not exist. Let G be a connected graph and V 1 V ( G ) . We say that V 1 is a vertex cut if removing V 1 from G results in a disconnected graph. Moreover, a vertex v V ( G ) is called a cut vertex if removing v from G makes it disconnected [10]. Let us consider that s is a cut vertex of G. Then, removing s from G results in some disjoint connected components. Since a Hamiltonian path from s to t must pass through all vertices of G exactly once and the path from s to other components must pass through s at least twice, a Hamiltonian ( s , t ) -path does not exist. The same holds true for t. In addition, a Hamiltonian ( s , t ) -path does not exist when { s , t } is a vertex cut of G using similar arguments. Thus, if s or t is a cut vertex of G or if { s , t } is a vertex cut of G, then graph G contains no Hamiltonian ( s , t ) -path.
Supergrid graphs are proposed to solve the calculation of stitch paths on computer embroidery machines [7]. If we input a colored picture, computer image software first processes it into blocks of different colors; then, the stitch algorithm calculates each stitch path in every block and transfers it to the computerized embroidery machine for embroidery work. Figure 1 shows the operation flow of a computerized embroidery machine. The supergrid graph is mainly used in the calculation of the stitch path. Considering the operation of computer embroidery machines, each needle point is an integer coordinate, and its moving direction includes its eight directions: up, down, left, right, upper-left, upper-right, upper-left, and lower-left. We can express each needle point as a lattice, as shown in Figure 2a, and the eight adjacent lattices are the next possible positions where the needle point may move to, so we can represent the lattice as a vertex of the graph, and there are edge adjacencies among them. Figure 2b is a graph representation of Figure 2a. Then, the block generated by each image software is a supergrid graph. The supergrid graph is then defined as follows: each vertex v with integer coordinates is represented as ( v x , v y ) , where v x and v y are the x- and y-coordinates of v, respectively. In the graphical representations in this paper, we use ( 1 , 1 ) as the coordinates of the uppermost left vertex of a supergrid graph. For two vertices u and v of a supergrid graph, ( u , v ) is an edge if and only if | u x v x | 1 and | u y v y | 1 . In other words, u is one of the following vertices: ( v x , v y 1 ) , ( v x , v y + 1 ) , ( v x 1 , v y 1 ) , ( v x 1 , v y ) , ( v x 1 , v y + 1 ) , ( v x + 1 , v y 1 ) , ( v x + 1 , v y ) , or ( v x + 1 , v y + 1 ) . Supergrid graphs include grid graphs and triangular grid graphs as subgraphs. Although they have an identical set of vertices, their edge sets are entirely distinct. Therefore, these graph classes do not belong to each other; that is, a supergrid graph is not necessary a grid graph or a triangular grid graph, and vice versa. Clearly, grid graphs are bipartite and planar [9], but triangular grid and supergrid graphs are not always bipartite or planar.
The Hamilton path problem on supergrid graphs is known to be NP-complete [7]; hence, the longest ( s , t ) -path problem is also NP-complete for supergrid graphs. However, these two problems for supergrid graphs with or without holes are still open. This paper proposes a linear-time algorithm to solve the longest ( s , t ) -path problem on O-shaped supergrid graphs, which are a subclass of hollow supergrid graphs. A preliminary version of this paper has appeared in [11], and a preprint version of the paper has been posted on the arXiv system [12], an open platform for scholarly research exchange. The related research works are introduced as follows: Recently, Hamiltonian path (cycle) and Hamiltonian-connected problems for grid, triangular grid, and supergrid graphs have received much attention. Itai et al. [9] showed that Hamiltonian path and cycle problems for grid graphs are NP-complete and gave necessary and sufficient conditions for rectangular grid graphs to be Hamiltonian-connected. Zamfirescu et al. [13] provided sufficient conditions for a grid graph to have a Hamiltonian cycle and showed that all grid graphs of positive width have Hamiltonian line graphs. Chen et al. [14] improved the Hamiltonian path algorithm for rectangular grid graphs and presented a parallel algorithm for the Hamiltonian path problem with two given end vertices. Lenhart and Umans [15] showed that the Hamiltonian cycle problem on solid grid graphs can be solved in polynomial time. In addition to grid graphs, researchers have studied Hamiltonian cycle and path problems on triangular and hexagonal grid graphs, as well as alphabet grid graphs. Keshavarz-Kohjerdi and Bagheri [16] presented a linear-time algorithm for computing the longest ( s , t ) -paths in L-shaped grid graphs. Recently, Nishat et al. [17] designed a linear-time algorithm to reconfigure any 1-complex s , t Hamiltonian path to a canonical Hamiltonian path in rectangular grids. Supergrid graphs, a more complex type of graph, have also been studied. Hung et al. [7] proved that Hamiltonian cycle and path problems on supergrid graphs are NP-complete, while showing that every rectangular supergrid graph is Hamiltonian. In subsequent studies, researchers explored the complexities of Hamiltonian problems for special subclasses of supergrid graphs, such as linear-convex [18] and rectangular supergrid graphs [19]. In [20,21], we presented linear-time algorithms for solving the longest ( s , t ) -path problem on L-shaped and C-shaped supergrid graphs, which form two subclasses of supergrid graphs without holes. In this paper, we study the Hamiltonian and longest ( s , t ) -path problems for O-shaped supergrid graphs, which are rectangular supergrid graphs with rectangular holes. We prove that O-shaped supergrid graphs are always Hamiltonian and Hamiltonian-connected except for a few conditions and present a linear-time algorithm to compute the longest ( s , t ) -path under these exceptional conditions. This study can be regarded as the first attempt to solve the Hamiltonian and longest ( s , t ) -path problems on supergrid graphs with holes.
The Hamiltonian connectivity of O-shaped supergrid graphs can also be applied to compute the minimum trace of 3D printers as follows [11]: Let us consider a 3D printer with a hollow object (O-type object) being printed. The software produces a series of thin layers, designs a path for each layer, combines these paths of produced layers, and transmits the above paths to the 3D printer. Because 3D printing is performed layer by layer (see Figure 3a), each layer can be considered as an O-shaped supergrid graph. Let us suppose that there are k layers under the above 3D printing. If the Hamiltonian connectivity of O-shaped supergrid graphs holds true, then we can find a Hamiltonian ( s i , t i ) -path of an O-shaped supergrid graph O i , where O i , 1 i k , represents a layer under 3D printing. Thus, we can design an optimal trace for the above 3D printing, where t i is adjacent to s i + 1 for 1 i k 1 . In this application, we restrict the 3D printer nozzle to be located at integer coordinates. As an example, Figure 3a shows the five layers, O 1 O 5 , of a 3D print for an O-type object, and Figure 3b depicts the Hamiltonian ( s i , t i ) -paths of O i for 1 i 5 ; the result of this 3D printing is shown in Figure 3c.
The following is the organization of the paper: Section 2 introduces notations, observations, and previously established results, along with verification of the Hamiltonicity of O-shaped supergrid graphs. In Section 3, conditions are discovered that prohibit the existence of Hamiltonian ( s , t ) -paths in O-shaped supergrid graphs. Section 4 presents that O-shaped supergrid graphs are Hamiltonian-connected except for the conditions mentioned in Section 3. An algorithm for computing the longest ( s , t ) -paths of O-shaped supergrid graphs in linear time is described in Section 5. Finally, conclusions are provided in Section 6.

2. Notations and Background Results

This section introduces several terms and symbols, along with the presentation of some prior observations and established results related to the Hamiltonicity and Hamiltonian connectivity of rectangular supergrid graphs. For any graph-theoretic terminology that is not defined in this paper, please refer to [10].
Let G be a finite, undirected, and simple graph. Let S V ( G ) and u , v V ( G ) . The subgraph of G induced by S is denoted by G [ S ] , while the subgraph induced by V ( G ) S is denoted by G S . We use G v to represent G { v } in general. If ( u , v ) E ( G ) , we say that u is adjacent to v and that u and v are incident to edge ( u , v ) . We use u v to indicate that u and v are adjacent and u v to indicate that they are not adjacent. An edge ( u , v ) is adjoined by a vertex w if w u and w v . Two edges, e 1 = ( u 1 , v 1 ) and e 2 = ( u 2 , v 2 ) , are said to be parallel and are denoted by e 1 e 2 , if u 1 u 2 and v 1 v 2 . A vertex adjacent to vertex v is called a neighbor of v. The set of neighbors of v in G is denoted by N G ( v ) , and the set of neighbors along with v itself is denoted by N G [ v ] = N G ( v ) { v } . The degree of vertex v in G, denoted by d e g G ( v ) , is the number of vertices adjacent to v. A path P of length | P | in G, denoted by v 1 v 2 v | P | 1 v | P | , is an ordered sequence of vertices ( v 1 , v 2 , , v | P | 1 , v | P | ) , such that ( v i , v i + 1 ) E ( G ) for 1 i < | P | , and all vertices except v 1 , v | P | in the sequence are distinct. The first and last vertices visited by P are denoted by s t a r t ( P ) and e n d ( P ) , respectively. We use v i P to indicate that P visits vertex v i , and ( v i , v i + 1 ) P to represent that P visits edge ( v i , v i + 1 ) . A path from v 1 to v k is denoted by ( v 1 , v k ) -path. Additionally, we use P to refer to the set of vertices visited by path P if it is clear from the context. A cycle is a path C with | V ( C ) | 3 and s t a r t ( C ) = e n d ( C ) . Two paths (or cycles), P 1 and P 2 , in graph G are vertex disjoint if V ( P 1 ) V ( P 2 ) = . If e n d ( P 1 ) s t a r t ( P 2 ) , then two vertex-disjoint paths P 1 and P 2 can be concatenated into a path, which is denoted by P 1 P 2 .
A two-dimensional supergrid, denoted by S , is an infinite graph with vertices corresponding to all points (vertices) in the plane with integer coordinates. Two vertices in S are adjacent if and only if the difference between their x- or y-coordinates is, at most, 1. A supergrid graph is a finite vertex-induced subgraph of S . Each vertex v in a supergrid graph can be represented as ( v x , v y ) , where v x and v y are the x- and y-coordinates of v, respectively. The set of possible adjacent vertices of a vertex v = ( v x , v y ) in a supergrid graph includes ( v x , v y 1 ) , ( v x , v y + 1 ) , ( v x 1 , v y 1 ) , ( v x 1 , v y ) , ( v x 1 , v y + 1 ) , ( v x + 1 , v y 1 ) , ( v x + 1 , v y ) , and ( v x + 1 , v y + 1 ) . An edge ( u , v ) is called horizontal (resp., vertical) if u y = v y (resp., u x = v x ), and it is said to be crossed if it is neither horizontal nor vertical. Next, we define some special supergrid graphs studied in the paper, as follows.
Definition 1.
Graph R ( m , n ) is a supergrid graph with vertex set V ( R ( m , n ) ) consisting of all vertices of the form v = ( v x , v y ) , with 1 v x m and 1 v y n . A supergrid graph is called a rectangular supergrid graph if it is isomorphic to R ( m , n ) for some positive integers m and n. When R ( m , n ) is considered, it is called an n-rectangle.
For m , n 2 , a rectangular supergrid graph R ( m , n ) contains four boundaries, each consisting of boundary edges. A path that visits all vertices and edges of a single boundary in R ( m , n ) and that has a length equal to the number of visited vertices is called a boundary path. A vertex v = ( v x , v y ) in R ( m , n ) is called the upper-left (resp., upper-right, down-left, and down-right) corner, if for any vertex w = ( w x , w y ) R ( m , n ) , w x v x , and w y v y (resp., w x v x and w y v y , w x v x and w y v y , and w x v x and w y v y ). In this paper, we assume that ( 1 , 1 ) are the coordinates of the vertex in the upper-left corner in all figures, unless explicitly stated otherwise.
Definition 2.
Let us suppose that R ( m , n ) is a rectangular supergrid graph. We define L ( m , n ; k , l ) as the supergrid graph obtained from R ( m , n ) by removing the subgraph R ( k , l ) located in the upper-right corner with coordinates ( m , 1 ) . An L-shaped supergrid graph is a supergrid graph isomorphic to L ( m , n ; k , l ) (see Figure 4a).
Definition 3.
Let R ( m , n ) be a rectangular supergrid graph. We define a C-shaped supergrid graph C ( m , n ; k , l ; c , d ) as a subgraph of R ( m , n ) obtained by removing the subgraph R ( k , l ) located at the vertex with coordinates ( m , c + 1 ) . Additionally, R ( m , n ) and R ( k , l ) must have exactly one border side in common, and we require that m 2 , n 3 , k , l , c , d 1 and n = c + d + l (see Figure 4b).
Definition 4.
Let us consider a rectangular supergrid graph R ( m , n ) . An O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) is obtained by removing subgraph R ( k , l ) from vertex ( m b , c + 1 ) of R ( m , n ) . Graphs R ( m , n ) and R ( k , l ) do not share any border side. Parameters m , n , k , l , a , b , c , d satisfy m , n 3 , k , l , a , b , c , d 1 , m = a + b + k and n = c + d + l (see Figure 4c).
When proving our results, it is necessary to partition a supergrid graph G into k disjoint parts, where k 2 . We define such an operation on G as follows.
Definition 5.
Let us consider a supergrid graph G. A separation operation on G is a partition of G into k vertex-disjoint supergrid subgraphs G 1 , G 2 , ⋯, G k , i.e., V ( G ) = V ( G 1 ) V ( G 2 ) V ( G k ) and V ( G i ) V ( G j ) = for i j and 1 i , j k , where k 2 . A separation is referred to as vertical if it comprises a set of horizontal edges and as horizontal if it comprises a set of vertical edges.
Let ( G , s , t ) be a supergrid graph G with two distinct specified vertices s and t. We assume without loss of generality that s x t x for the remainder of the paper, unless we explicitly state otherwise. We denote a Hamiltonian path between s and t in G as H P ( G , s , t ) . If a Hamiltonian ( s , t ) -path exists in G, we say that H P ( G , s , t ) exists. In the following, we present some previously established results.
Let R ( m , n ) be a rectangular supergrid graph with dimensions m n 2 . Let us consider a cycle C of R ( m , n ) , and let H be a boundary of R ( m , n ) , which is a subgraph of R ( m , n ) . We denote the restriction of C to H by C | H . If | C | H | = 1 , i.e., C | H is a boundary path on H, C | H is referred to as a flat face on H. If | C | H | > 1 and C | H contains at least one boundary edge of H, then C | H is called a concave face on H. A Hamiltonian cycle of R ( m , 3 ) is said to be canonical if it contains three flat faces on two shorter boundaries and one longer boundary, and one concave face on the other boundary, where the shorter boundary consists of three vertices. For n = 2 or n 4 , a Hamiltonian cycle of R ( m , n ) is referred to as canonical if it contains three flat faces on three boundaries and one concave face on the other boundary. The following lemma shows the result from [7] that verifies the Hamiltonicity of rectangular supergrid graphs.
Lemma 1
(See [7]). The following statements are true for rectangular supergrid graph R ( m , n ) , where m n 2 :
( 1 ) If n = 3 , then R ( m , 3 ) has a Hamiltonian cycle that is canonical.
( 2 ) If n = 2 or n 4 , R ( m , n ) contains four canonical Hamiltonian cycles, with each having a concave face on a different boundary.
In Section 1 and in [19], we verified that if s or t is a cut vertex of R ( m , n ) , or if { s , t } is a vertex cut of R ( m , n ) , then H P ( R ( m , n ) , s , t ) does not exist. Thus, H P ( R ( m , n ) , s , t ) does not exist if the following condition is satisfied:
(F1)
s or t is a cut vertex of R ( m , n ) , or { s , t } is a vertex cut of R ( m , n ) (see Figure 5a,b).
We demonstrated in [20] that in addition to condition (F1) (shown in Figure 6a,b), H P ( L ( m , n ; k , l ) , s , t ) does not exist when any of the following conditions are satisfied.
(F2)
For an L-shaped supergrid graph G, there exists a vertex w G , such that d e g G ( w ) = 1 , w s , and w t (see Figure 6c).
(F3)
m k = 1 , n l = 2 , l = 1 , k 2 , and { s , t } = { ( 1 , 2 ) , ( 2 , 3 ) } or { ( 1 , 3 ) , ( 2 , 2 ) } (see Figure 6d).
In addition to conditions (F1) and (F2) depicted in Figure 7a–c, respectively, we demonstrated in [21] that the existence of a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) is prohibited if ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies any of the following conditions.
(F4)
m = 3 , a = m k = 2 , and either of the following: c = 1 , and { s , t } = { ( 1 , 1 ) , ( 2 , 2 ) } or { ( 1 , 2 ) , ( 2 , 1 ) } ; or d = 1 , and { s , t } = { ( 1 , n ) , ( 2 , n 1 ) } or { ( 1 , n 1 ) , ( 2 , n ) } (see Figure 7d).
(F5)
n = 3 , k = c = d = 1 , and one the following:
 (1) a 2 , s x = t x = m 1 , and | s y t y | = 2 (see Figure 7e);
 (2) a = 2 , s x = 1 , t x = 2 , and | s y t y | = 2 (see Figure 7f);
 (3) a > 2 , s x < m 1 , and t = ( m 1 , 2 ) (see Figure 7g).
(F6)
a = m k = 1 , and s y , t y c or s y , t y > c + l (see Figure 7h).
Theorem 1
(See [19,20,21]). A Hamiltonian ( s , t ) -path exists in a rectangular, L-shaped, or C-shaped supergrid graph G with vertices s and t, if and only if ( G , s , t ) does not satisfy conditions ( F 1 ) ( F 6 ) .
The Hamiltonian ( s , t ) -path in R ( m , n ) that was constructed in [19] is known as the canonical path. This path satisfies the property that it contains at least one boundary edge from each boundary.
Lemma 2
(See [19]). If R ( m , n ) is a rectangular supergrid graph, such that m , n 1 , and s and t are two distinct vertices of R ( m , n ) , and if condition ( F 1 ) is not satisfied, then there exists a canonical Hamiltonian ( s , t ) -path in R ( m , n ) , meaning that H P ( R ( m , n ) , s , t ) exists.
Assuming that ( R ( m , n ) , s , t ) does not satisfy condition (F1), we define three vertices w = ( 1 , 1 ) , z = ( 2 , 1 ) , and f = ( 3 , 1 ) of R ( m , n ) with m 3 and n 2 . In [20], it was demonstrated that a Hamiltonian ( s , t ) -path Q exists in R ( m , n ) with ( z , f ) Q if the following condition (F7) is satisfied; otherwise, ( w , z ) Q .
(F7)
n = 2 and { s , t } { { w , z } , { ( 1 , 1 ) , ( 2 , 2 ) } , { ( 2 , 1 ) , ( 1 , 2 ) } } , or n 3 and { s , t } = { w , z } .
The following lemma summarizes the previous results.
Lemma 3
(See [20]). Suppose that R ( m , n ) is a rectangular supergrid graph with m 3 and n 2 , and let s and t be two distinct vertices in R ( m , n ) . In addition, let w = ( 1 , 1 ) , z = ( 2 , 1 ) , and f = ( 3 , 1 ) . If ( R ( m , n ) , s , t ) does not satisfy condition ( F 1 ) , then there exists a canonical Hamiltonian ( s , t ) -path Q in R ( m , n ) such that ( z , f ) Q if ( R ( m , n ) , s , t ) satisfies condition ( F 7 ) , and ( w , z ) Q otherwise.
In [21], we derived the following lemma for a three-rectangle R ( m , 3 ) .
Lemma 4
(See [21]). Let s and t be two distinct vertices of R ( m , 3 ) , and let z 1 = ( m , 1 ) , z 2 = ( m , 2 ) , and z 3 = ( m , 3 ) be three other vertices of R ( m , 3 ) . Let us suppose that { s , t } { z 1 , z 2 , z 3 } = . Then, there exists a Hamiltonian ( s , t ) -path of R ( m , 3 ) that contains both edges e 12 = ( z 1 , z 2 ) and e 23 = ( z 2 , z 3 ) .
The Hamiltonicities of L-shaped and C-shaped supergrid graphs were verified in [20,21] as follows.
Theorem 2
(See [20,21]). Let us consider L ( m , n ; k , l ) (resp., C ( m , n ; k , l ; c , d ) ) as an L-shaped (resp., C-shaped) supergrid graph. It contains a Hamiltonian cycle if and only if it does not satisfy condition ( F 8 ) (resp., ( F 9 ) ), which is defined as follows:
(F8)
There exists a vertex w in L ( m , n ; k , l ) such that d e g L ( m , n ; k , l ) ( w ) = 1 .
(F9)
a ( = m k ) = 1 , or there exists a vertex w V ( C ( m , n ; k , l ; c , d ) ) satisfying d e g C ( m , n ; k , l ; c , d ) ( w ) = 1 .
The following propositions, which relate cycles, paths, and vertices, were presented in [7,18,19] and will be used in the proofs of our results.
Proposition 1
(See [7,18,19]). Let C 1 and C 2 be two cycles in a graph G that do not share any vertices; let C 1 and P 1 be a cycle and a path in G, such that V ( C 1 ) V ( P 1 ) = ; and let x be a vertex in G V ( C 1 ) or G V ( P 1 ) . The following statements hold true:
( 1 ) If there exist two edges e 1 C 1 and e 2 C 2 such that e 1 e 2 , then C 1 and C 2 can be combined into a cycle of G (see Figure 8a).
( 2 ) If there exist two edges e 1 C 1 and e 2 P 1 such that e 1 e 2 , then C 1 and P 1 can be combined into a path of G (see Figure 8b).
( 3 ) If vertex x adjoins an edge ( u 1 , v 1 ) of C 1 (or P 1 ), then C 1 (or P 1 ) and x can be combined into a cycle (or path) of G (see Figure 8c).
( 4 ) If there exists an edge ( u 1 , v 1 ) C 1 such that u 1 s t a r t ( P 1 ) and v 1 e n d ( P 1 ) , then C 1 and P 1 can be combined into a cycle C of G (see Figure 8d).
We demonstrated in [19,20,21] that the problem of finding the longest ( s , t ) -path in R ( m , n ) , L ( m , n ; k , l ) , and C ( m , n ; k , l ; c , d ) can be resolved in linear time.
Theorem 3.
According to [19,20,21], an ( s , t ) -path of maximum length can be calculated in O ( m n ) linear time for a rectangular supergrid graph R ( m , n ) with m n 2 , an L-shaped supergrid graph L ( m , n ; k , l ) , or a C-shaped supergrid graph C ( m , n ; k , l ; c , d ) , given two distinct vertices s and t within the graph.
The focus of this paper is to examine the O-shaped supergrid graph denoted by O ( m , n ; k , l ; a , b , c , d ) , which has the structure illustrated in Figure 4c. Due to its symmetry, we limit our analysis to the following three cases, excluding the isomorphic ones:
  • a = b = c = d = 1 ;
  • a 2 and c = 1 ;
  • a , b , c , d 2 .
The above case that a 2 and c = 1 can be further divided into four subcases: b = d = 1 , b = 1 and d 2 , b 2 and d = 1 , and b , d 2 . These subcases are illustrated in Figure 9. Depending on the positions of s and t in O ( m , n ; k , l ; a , b , c , d ) , we can consider the following cases for the aforementioned three cases: s x , t x a ; s x a and t x a + 1 ; and s x , t x a + 1 .
We first verify the Hamiltonicity of O-shaped supergrid graphs with the following theorem.
Theorem 4.
For any O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) , there exists a Hamiltonian cycle contained within it.
Proof. 
To obtain two disjoint supergrid subgraphs R 1 = R ( a , n ) and R 2 = C ( m a , n ; k , l ; c , d ) from O ( m , n ; k , l ; a , b , c , d ) , we first make one vertical separation, as shown in Figure 10a. Let p = ( a , 1 ) and q = ( a , n ) be two vertices of R 1 , and let r 1 = ( a + 1 , 1 ) and r 2 = ( a + 1 , n ) be two vertices of R 2 , as depicted in Figure 10b. Note that p r 1 and q r 2 . Since ( R 1 , p , q ) does not satisfy condition (F1), ( R 1 , p , q ) contains a Hamiltonian ( p , q ) -path P 1 according to Lemma 2. Similarly, ( R 2 , r 2 , r 1 ) contains a Hamiltonian ( r 2 , r 1 ) -path P 2 according to Theorem 1, as it does not satisfy conditions (F1)–(F2) and (F4)–(F6). Then, P = P 1 P 2 forms a Hamiltonian ( p , r 1 ) -path of O ( m , n ; k , l ; a , b , c , d ) . Since s t a r t ( P ) e n d ( P ) , P is a Hamiltonian cycle of O ( m , n ; k , l ; a , b , c , d ) . The constructed Hamiltonian cycle is depicted in Figure 10b.    □
We can see from the above construction that if a = 1 , then the constructed Hamiltonian cycle H C of O ( m , n ; k , l ; a , b , c , d ) satisfies H C | R 1 being a flat face.

3. Forbidden Conditions for Hamiltonian Connectivity in O-Shaped Supergrid Graphs

This section aims to identify all cases where O-shaped supergrid graphs do not contain a Hamiltonian ( s , t ) -path. Although there are no cut vertices in these graphs, there are vertex cuts. Therefore, we have a forbidden condition, referred to as condition (F1), for the non-existence of H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) (see Figure 11a,b).
In the following, we explore the other forbidden conditions for the non-existence of a Hamiltonian ( s , t ) -path in O-shaped supergrid graphs. We examine the sizes of parameters a, b, c, and d, and list the forbidden conditions as follows.
(F10)
When a = b = c = d = 1 and s t , { s , t } is not a vertex cut, and one of the following cases occurs:
(1) s { ( 1 , 1 ) , ( 1 , n ) } , s x t x , and s y t y (see Figure 11c);
(2) l 3 , s or t { ( 1 , 1 ) , ( 1 , n ) } , s x = t x , and | s y t y | > 2 (see Figure 11d).
(F11)
When c = 1 , a , b , d 2 , k 5 , and s t , { s , t } is not a vertex cut, and a + 3 s x ( or t x ) a + k 2 (see Figure 11e).
(F12)
c = d = 1 , a , b 2 , k 3 , and one of the following cases occurs:
(1) s x a and t x a + 3 (see Figure 12a);
(2) a + 1 s x a + k 2 and t x a + k + 1 (see Figure 12b).
(F13)
b = c = 1 , a 2 , s t , and one of the following cases occurs:
(1) s x , t x a + 1 ; t = ( m , 1 ) ; d = 1 , or d 2 and s y , t y c + l ; and one of the following occurs:
   (1.1) k 3 , s y = 1 , and s x m 3 (see Figure 12c,d);
   (1.2) s y = n and s x m 1 (see Figure 13a);
   (1.3) l 3 , s x = t x , and s y 4 (see Figure 13b,c);
(2) d 2 ; t x a + 1 ; t y c + l ; s x a , or s x a + 1 and s y c + l + 1 ; and one of the following occurs:
   (2.1) k 3 , t y = 1 , and a + 3 t x m 1 (see Figure 13d);
   (2.2) l 3 , t x = m , and 2 t y l 1 (see Figure 13e);
   (2.3) k , l 3 and t = ( m , 1 ) (see Figure 13f);
(3) d = 1 ; s x a ; t x a + 1 ; and 2 t y c + l , or k 3 and t x a + 3 (see Figure 13g,h).
The following lemma presents the necessary condition for the existence of a Hamiltonian ( s , t ) -path in O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) .
Lemma 5.
If H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) exists, then ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) must not satisfy conditions ( F 1 ) and ( F 10 ) ( F 13 ) .
Proof. 
If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies any of conditions (F1) or (F10)–(F13), we can show that H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not exist as follows: For condition (F1), the lemma clearly holds true, as shown in Figure 11a,b. For conditions (F10)–(F13), we can refer to Figure 11c–e, Figure 12, and Figure 13. Let v and u be two vertices depicted in these figures. It is clear that no Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) can contain both vertices u and v.    □
All possible cases for the forbidden conditions for the existence of a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) are considered in this section. In the next section, we prove that if ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy conditions (F1) and (F10)–(F13), then O ( m , n ; k , l ; a , b , c , d ) contains a Hamiltonian ( s , t ) -path.

4. The Hamiltonian Connectivity of O -Shaped Supergrid Graphs

This section aims to demonstrate the existence of a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) when ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy conditions (F1) and (F10)–(F13). The following three lemmas consider the following three cases individually: s x , t x a ; s x a and t x a + 1 ; and s x , t x a + 1 .
Lemma 6.
Let us assume that O ( m , n ; k , l ; a , b , c , d ) is an O-shaped supergrid and that s and t are two distinct vertices in the graph. If s x , t x a and ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy conditions ( F 1 ) and ( F 10 ) , then it follows that O ( m , n ; k , l ; a , b , c , d ) has a Hamiltonian ( s , t ) -path.
Proof. 
Due to symmetry, we only need to examine three cases: a = b = c = d = 1 ; a 2 and c = 1 ; and a , b , c , d 2 . The cases that are isomorphic, as shown in Section 2, are not considered. Then, there are the following three cases.
Case 1: a = b = c = d = 1 . We first make a vertical separation on O ( m , n ; k , l ; a , b , c , d ) to obtain two disjoint supergrid subgraphs R 1 = R ( m 1 , n ) and R 2 = C ( m m 1 , n ; k , l ; c , d ) , where m 1 = a (see Figure 14a). Then, we consider s t , or s t together with either l 2 , or l 3 and either s y , t y 3 or s y , t y n 2 . Let the following hold: s t ; l 3 ; and either s , t { ( 1 , 1 ) , ( 1 , n ) } , or s or t { ( 1 , 1 ) , ( 1 , n ) } and | s y t y | > 2 . Then, ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F1) or (F10). Without loss of generality, we assume that t y < s y , and for the case s t , we assume that t = ( 1 , 1 ) . We partition R 1 horizontally into two subgraphs R 11 and R 12 , where R 11 = R ( m 1 , n 1 ) and R 12 = R ( m 1 , n n 1 ) , and n 1 = t y if s t ; otherwise, n 1 = t y + 1 (see Figure 14b,c). Let q V ( R 11 ) , p V ( R 12 ) , and w , z V ( R 2 ) such that p w , q z , z = ( m 1 + 1 , 1 ) , w = ( m 1 + 1 , n ) , p = ( m 1 , n ) , and q = ( m 1 , 1 ) if s t ; otherwise, q = ( m 1 , 2 ) . We consider ( R 2 , w , z ) . Since z x = w x = m 1 + 1 = a + 1 , z y = 1 , and w y = n , it is clear that ( R 2 , w , z ) does not satisfy conditions (F1)–(F2) and (F4)–(F6). We then consider ( R 11 , q , t ) and ( R 12 , s , p ) . If either of these subgraphs satisfies condition (F1), then ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F10), which is a contradiction. Therefore, neither ( R 11 , q , t ) nor ( R 12 , s , p ) satisfies condition (F1). As ( R 12 , s , p ) , ( R 11 , q , t ) , and ( R 2 , w , z ) fail to satisfy conditions (F1)–(F2) and (F4)–(F6), Theorem 1 implies the existence of Hamiltonian paths P 1 , P 2 , and P 3 in R 12 , R 2 , and R 11 , respectively, with endpoints ( s , p ) , ( w , z ) , and ( q , t ) (refer to Figure 14d). Concatenating these paths as P = P 1 P 2 P 3 results in a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) , as shown in Figure 14e.
Case 2: a 2 and c = 1 . We can divide this into two subcases based on the size of a:
Case 2.1: a = 2 . For this subcase, we begin by conducting a vertical separation on O ( m , n ; k , l ; a , b , c , d ) . This results in two separate supergrid subgraphs, R 1 = R ( m 1 , n ) and R 2 = C ( m m 1 , n ; k , l ; c , d ) , where m 1 = a (refer to Figure 15a). Depending on whether or not s , t { ( m 1 , 1 ) , ( m 1 , n ) } , we consider the following subcases.
Case 2.1.1: s or t { ( m 1 , 1 ) , ( m 1 , n ) } . We can assume, without loss of generality, that t { ( m 1 , 1 ) , ( m 1 , n ) } . Then, t = ( m 1 , 1 ) or t = ( m 1 , n ) as the following two subcases.
Case 2.1.1.1: t = ( m 1 , 1 ) . In this subcase, we first perform both vertical and horizontal separations on R 1 , which results in two separated supergrid subgraphs, R 11 and R 12 , with R 11 = R ( 1 , t y ) and R 12 = L ( m 1 , n ; 1 , t y ) (refer to Figure 15b,c). We then choose q V ( R 11 ) , p V ( R 12 ) , and w , z V ( R 2 ) such that p w , q z , z = ( m 1 + 1 , 1 ) , w = ( m 1 + 1 , n ) , q = ( m 1 , 1 ) = t , and p = ( m 1 , n ) if s ( m 1 , n ) ; otherwise, p = ( m 1 , n 1 ) . We then consider ( R 2 , w , z ) and ( R 12 , s , p ) and show that they do not satisfy certain conditions necessary for the existence of a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . Specifically, ( R 2 , w , z ) violates conditions (F1)–(F2) and (F4)–(F6), since z x = w x = m 1 + 1 = a + 1 , z y = 1 , and w y = n . On the other hand, ( R 12 , s , p ) violates conditions (F1), (F2), and (F3), due to the relationship between s and p. Despite these complications, we can construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) by following an approach similar to that in Case 1. Figure 15b,c depict the Hamiltonian ( s , t ) -paths constructed in this subcase.
Case 2.1.1.2: t = ( m 1 , n ) . In the case of d = 1 , we can construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) using symmetry, similarly to Case 2.1.1.1. Specifically, we set R 11 = R ( 1 , 1 ) , R 12 = L ( m 1 , n ; 1 , 1 ) , q = ( m 1 , n ) , p = ( m 1 , 1 ) , w = ( m 1 + 1 , 1 ) , and z = ( m 1 + 1 , n ) (refer to Figure 15d). In the case of d 2 , we perform vertical and horizontal separations on R 1 to obtain two disjoint supergrid subgraphs, R 11 and R 12 , where R 11 = R ( 1 , 1 ) and R 12 = L ( n , m 1 ; 1 , 1 ) (see Figure 15d). We then choose q V ( R 11 ) , p V ( R 12 ) , and w , z V ( R 2 ) such that p w , q z , z = ( m 1 + 1 , n ) , w = ( m 1 + 1 , 1 ) , q = ( m 1 , n ) = t , and p = ( m 1 , 1 ) if s ( m 1 , 1 ) ; otherwise, p = ( m 1 , 2 ) . We can then construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) using an approach similar to that in Case 1. An example of the Hamiltonian ( s , t ) -path constructed in this subcase is shown in Figure 15d.
Case 2.1.2: s , t { ( m 1 , 1 ) , ( m 1 , n ) } . Assuming t y s y without loss of generality, there are two cases to consider. First, let us consider s y t y . In this case, a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 1, where n 1 = t y (see Figure 15e). Next, let us consider s y = t y . Then, a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 2.1.1.1, where R 12 = L ( m 1 , n n 1 + 1 ; 1 , 1 ) , R 11 = L ( m 1 , n 1 ; 1 , 1 ) , and n 1 = s y (see Figure 15f). Figure 15e,f depict the Hamiltonian ( s , t ) -paths of O ( m , n ; k , l ; a , b , c , d ) constructed in this subcase.
Case 2.2: a 3 . To obtain two separated supergrid subgraphs R 1 = R ( m 1 , n ) and R 2 = O ( m m 1 , n ; k , l ; 1 , b , c , d ) , we perform a vertical separation on O ( m , n ; k , l ; a , b , c , d ) . The value of m 1 is determined as a 1 , as shown in Figure 16a. The resulting subcases depend on the locations of s and t and can be categorized as the following three subcases.
Case 2.2.1: s , t R 1 . Based on the value of m 1 and the relationship between s y and t y , we can divide it into the following two subcases.
Case 2.2.1.1: Either m 1 3 , or m 1 = 2 and one of the following: s y t y , s y = t y = 1 , or s y = t y = n . In this subcase, { s , t } is not a vertex cut of R 1 (refer to Figure 16b). We consider ( R 1 , s , t ) and check that it does not easily satisfy condition (F1). Therefore, according to Lemmas 3–4, there exists a Hamiltonian ( s , t ) -path P 1 in R 1 in which one edge e 1 faces R 2 . Applying Theorem 4, R 2 contains a Hamiltonian cycle H C 2 such that one flat face faces R 1 . Then, there exist two edges e 1 P 1 and e 2 H C 2 such that e 1 e 2 (as shown in Figure 16b). According to Statement (2) of Proposition 1, P 1 and H C 2 can be combined into a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . The construction of such a Hamiltonian path is depicted in Figure 16c.
Case 2.2.1.2: m 1 = 2 and 2 s y = t y n 1 . In this subcase, { s , t } is a vertex cut of R 1 . We then separate R 1 horizontally into two disjoint supergrid subgraphs R 11 = R ( m 1 , n 1 ) and R 12 = R ( m 1 , n n 1 ) , where n 1 = s y if s y n 1 , and n 1 = s y 1 if s y = n 1 (see Figure 16d,e). If n 1 = s y , then s and t belong to R 11 ; otherwise, they belong to R 12 . Without loss of generality, let us assume that s and t are both in R 11 . Since s y = t y = n 1 , ( R 11 , s , t ) does not satisfy condition (F1). By Lemmas 3 and 4, R 11 contains a Hamiltonian ( s , t ) -path P 11 in which one edge e 11 is facing R 2 . By Lemma 1 and Theorem 4, R 12 and R 2 each contain a Hamiltonian cycle, H C 12 and H C 2 , respectively. Hence, there exist four edges, i.e., e 1 , e 2 H C 2 , e 11 P 11 , and e 12 H C 12 , such that e 1 e 11 and e 2 e 12 , as illustrated in Figure 16d. By Statements (1) and (2) of Proposition 1, P 11 , H C 12 , and H C 2 can be combined into a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . The construction of such a Hamiltonian path is depicted in Figure 16d. For the case where s and t belong to R 12 , a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed in the same way, as shown in Figure 16e.
Case 2.2.2: s , t R 2 . Since s x and t x are both less than or equal to a, we know that s x = t x = a (refer to Figure 16a and Figure 17a). Without loss of generality, let t y < s y . We perform a vertical separation and a horizontal separation on R 2 to create three disjoint supergrid subgraphs R 21 = R ( 1 , t y ) , R 22 = R ( 1 , n t y ) , and R 23 = C ( m m 1 1 , n ; k , l ; c , d ) . Let R a = R 1 R 22 . Then, R a = L ( a , n ; 1 , t y ) (see Figure 17a). A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 2.1.1.1, where p V ( R a ) , q V ( R 21 ) , and w , z V ( R 23 ) (see Figure 17a–c).
Case 2.2.3: s R 1 and t R 2 . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 2.2.2. Refer to Figure 17d for the construction of the path.
Case 3: a , b , c , d 2 . To construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) when a = 2 , we can use the same approach as in Case 2.1. Similarly, for a 3 , we can construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) using the same method as in Case 2.2.    □
Lemma 7.
Let us assume that O ( m , n ; k , l ; a , b , c , d ) is an O-shaped supergrid and that s and t are two distinct vertices in the graph. If s x a , t x a + 1 , and ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy conditions ( F 1 ) and ( F 10 ) ( F 13 ) , then there exists a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) .
Proof. 
Let us consider that a = b = c = d = 1 . In this case, t y = s y ; s { ( 1 , 1 ) , ( 1 , n ) } ; and either t x a + 2 , or k = 2 and t { ( m , 1 ) , ( m , n ) } . Let the following hold: k 3 ; t x a + 3 ; and either s { ( 1 , 1 ) , ( 1 , n ) } and t y s y , or s { ( 1 , 1 ) , ( 1 , n ) } . Then, ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F1) or (F10). So, s y = t y = 1 or s y = t y = n , and it can be considered equivalent to Case 1 in Lemma 6. Thus, we assume that a 2 for the following cases. Additionally, for the case where b = c = d = 1 , we can assume without loss of generality that s y , t y c + l . We now consider the following cases.
Case 1: c = 1 . In this case, a 2 and c = 1 . There are four subcases, each with different sizes of b, c, and d (refer to Figure 9). Depending on the placement of t, we examine the following subcases.
Case 1.1: a + 1 t x a + k and t y = 1 . In this subcase, either t x a + 2 , or b , d 2 and t x a + k 1 . Let the following hold: b = 1 or d = 1 , k 3 , and t x a + 3 ; or b , d 2 , k 5 , and a + 3 t x a + k 2 . Then, ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies (F11)–(F13). Note that the former ( b = 1 or d = 1 , k 3 , and t x a + 3 ) satisfy condition (F12) or (F13), and the latter ( b , d 2 , k 5 , and a + 3 t x a + k 2 ) satisfy condition (F11). Next, we can consider the subsequent subcases.
Case 1.1.1: t x = a + 1 . First, we make a vertical separation on O ( m , n ; k , l ; a , b , c , d ) and obtain two separated supergrid subgraphs: R 1 = R ( m 1 , n ) and R 2 = C ( m m 1 , n ; k , l ; c , d ) , where m 1 = a (refer to Figure 18a,b). We select p V ( R 1 ) and q V ( R 2 ) such that p q , q = ( m 1 + 1 , n ) , and p = ( m 1 , n ) if s ( m 1 , n ) ; otherwise, p = ( m 1 , n 1 ) . Next, we consider ( R 2 , q , t ) . As t y = 1 and q y = n , it is evident that ( R 2 , q , t ) does not satisfy conditions (F1), (F2), and (F4)–(F6). We also examine ( R 1 , s , p ) , where condition (F1) holds if m 1 = 2 and s y = p y = n 1 . However, this contradicts the fact that p = ( m 1 , n ) when s ( m 1 , n ) . Therefore, ( R 1 , s , p ) does not satisfy condition (F1). Because ( R 1 , s , p ) and ( R 2 , q , t ) fail to satisfy conditions (F1), (F2), and (F4)–(F6), according to Theorem 1, there must exist a Hamiltonian ( s , p ) -path P 1 and a Hamiltonian ( q , t ) -path P 2 of R 1 and R 2 , respectively (as shown in Figure 18c). Finally, P = P 1 P 2 yields a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , which is depicted in Figure 18d.
Case 1.1.2: t x = a + 2 . In this subcase, k 2 . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed, following a method similar to that in Case 1.1.1, where we set R 1 = C ( m 1 , n ; 1 , l ; c , d ) and R 2 = C ( m m 1 , n ; k 1 , l ; c , d ) , and set m 1 = a + 1 (refer to Figure 18e). The resulting Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) is also shown in Figure 18e.
Case 1.1.3: b , d 2 and t x a + k 1 . In this subcase, we have a + k t x a + k 1 . Therefore, either t = ( a + k , 1 ) , or t = ( a + k 1 , 1 ) . Then, we have the following two subcases.
Case 1.1.3.1: t = ( a + k , 1 ) . In this subcase, we have that k 3 . We can construct a Hamiltonian ( s , t ) -path for O ( m , n ; k , l ; a , b , c , d ) by making two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) resulting in two disjoint subgraphs R 1 = C ( n , m ; l + c , k ; a , b ) and R 2 = R ( k , c ) , as shown in Figure 19a. We then select vertices p V ( R 1 ) and q V ( R 2 ) such that p q , q = ( a + 1 , 1 ) and p = ( a , 1 ) if s ( a , 1 ) ; otherwise, p = ( a , 2 ) . Next, we consider ( R 1 , s , p ) . Since a , b , d 2 , we only need to show that ( R 1 , s , p ) fails to satisfy condition (F1). If s y = p y = 2 , then condition (F1) holds, but it contradicts p = ( a , 1 ) when s ( a , 1 ) . We then consider ( R 2 , q , t ) . Since q = ( a + 1 , 1 ) and t = ( a + k , 1 ) , it is clear that ( R 2 , q , t ) does not satisfy condition (F1). Similarly to Case 1.1.1, we construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . Figure 19a shows such a constructed Hamiltonian ( s , t ) -path.
Case 1.1.3.2: t = ( a + k 1 , 1 ) . In this subcase, we have k 4 . We then perform a vertical separation on O ( m , n ; k , l ; a , b , c , d ) to obtain two supergrid subgraphs R 1 = C ( t x , n ; t x a , l ; c , d ) and R 2 = C ( m t x , n ; 1 , l ; c , d ) that are disjoint (refer to Figure 19b). We consider ( R 1 , s , t ) and note that since a , d 2 , t = ( a + k 1 , 1 ) , and s x a , it does not satisfy conditions (F1), (F2), and (F4)–(F6). Thus, according to Theorem 1, R 1 has a Hamiltonian ( s , t ) -path. We can construct a Hamiltonian ( s , t ) -path P 1 of R 1 using the algorithm in [21], and we can ensure that one edge e 1 of P 1 faces R 2 . Using Theorem 2, R 2 contains a Hamiltonian cycle H C 2 that can be constructed so that one flat face of H C 2 faces R 2 (refer to Figure 19c). Thus, there are two edges e 1 P 1 and e 2 H C 2 such that e 1 e 2 (see Figure 19c). Using Statement (2) of Proposition 1, P 1 and H C 2 can be combined into a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . Figure 19d shows the construction of such a Hamiltonian path.
Case 1.2: b = 1 and t y c + l . In this subcase, one of the following applies: k 2 or l 2 , and t = ( m , 1 ) ; or d 2 and t y c + l 1 . If either l 3 and 2 t y c + l 2 , or l , k 3 and t = ( m , 1 ) , then ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F13). According to the position of t, we consider the following three subcases.
Case 1.2.1: t = ( m , 1 ) . In this subcase, k 2 or l 2 . We can divide this subcase into the following two subcases.
Case 1.2.1.1: k 2 . We can construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) using an approach similar to that in Case 1.1.1. When k = 1 , we consider R 1 = R ( m 1 , n ) , R 2 = C ( m m 1 , n ; k , l ; c , d ) , and m 1 = a (see Figure 20a). When k = 2 , we consider R 1 = C ( a + 1 , n ; 1 , l ; c , d ) and R 2 = C ( m a 1 , n ; 1 , l ; c , d ) (see Figure 20b). The Hamiltonian ( s , t ) -paths of O ( m , n ; k , l ; a , b , c , d ) constructed using these cases are also depicted in Figure 20a,b.
Case 1.2.1.2: k 3 and l 2 . To obtain three disjoint supergrid subgraphs R 1 = R ( a , n ) , R 2 = L ( m a , n 1 ; k , n 1 c ) , and R 3 = R ( m a , d ) if l = 1 (otherwise, R 3 = L ( m a , n n 1 ; k , l n 1 + c ) ), where n 1 = t y + 1 = 2 (see Figure 20c,d), we perform vertical and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) . Then, we select p V ( R 1 ) and q V ( R 2 ) , such that p q , q = ( a + 1 , 1 ) and p = ( a , 1 ) if s ( a , 1 ) ; otherwise, p = ( a , 2 ) . We consider ( R 1 , s , p ) first. If a = 2 and s y = p y = 2 , then condition (F1) is satisfied, which is a contradiction, since p = ( a , 1 ) when s ( a , 1 ) . Next, we consider ( R 2 , q , t ) . Since b = c = 1 , q = ( a + 1 , 1 ) , and t = ( m , 1 ) , it is easy to check that ( R 2 , q , t ) does not satisfy conditions (F1), (F2), and (F3). Therefore, using Theorem 1, there exists a Hamiltonian ( s , p ) -path P 1 of R 1 and a Hamiltonian ( q , t ) -path P 2 of R 2 . We note that P 1 is a canonical Hamiltonian path of R 1 . Then, we obtain a Hamiltonian ( s , t ) -path of R 1 R 2 by combining P 1 and P 2 , which is depicted in Figure 20e. Using Lemma 1, R 3 contains a canonical Hamiltonian cycle H C 3 . We can place one flat face of H C 3 to face R 1 . Then, we can find two edges e 1 P and e 3 H C 3 such that e 1 e 3 (see Figure 20f). Using Statement (2) of Proposition 1, we can combine P and H C 3 into a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . The construction of such a Hamiltonian path is shown in Figure 20f.
Case 1.2.2: t = ( m , c + l ) . To construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , we follow an approach similar to that in Case 1.1.3.1, where two disjoint supergrid subgraphs R 1 = L ( m , n ; k + b , c + l ) and R 2 = L ( k + b , c + l ; k , l ) are as shown in Figure 21a,b.
Case 1.2.3: t = ( m , c + l 1 ) . In this subcase, l 2 . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 1.2.1.2. Here, let n 1 = t y (as shown in Figure 21c).
Case 1.3: d 2 and one of the following: b 2 , and either t y 2 , or t y = 1 and t x > a + k ; or b = 1 and t y c + l + 1 . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed in a way similar to that in Case 1.1.1. We set q to be ( m 1 + 1 , 1 ) , and if s ( m 1 , 1 ) , then p = ( m 1 , 1 ) ; otherwise, p = ( m 1 , 2 ) (refer to Figure 21d,e). Note that d , b 2 ; q = ( m 1 + 1 , 1 ) ; and either t x > a + k , or t x a + k and t y > c + l . Therefore, it is easy to verify that ( R 2 , q , t ) does not satisfy conditions (F1), (F2), and (F4)–(F6).
Case 2: a , b , c , d 2 . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed, similarly to Case 1.1.1, depicted in Figure 18c,d, where m 1 = a and where p and q are chosen as follows:
p = ( m 1 , n ) and q = ( m 1 + 1 , n ) , if s ( m 1 , n ) and t ( m 1 + 1 , n ) ; p = ( m 1 , 1 ) and q = ( m 1 + 1 , 1 ) , if s = ( m 1 , n ) and t = ( m 1 + 1 , n ) ; p = ( m 1 , n ) and q = ( m 1 + 1 , n 1 ) , if s ( m 1 , n ) and t = ( m 1 + 1 , n ) ; p = ( m 1 , n 1 ) and q = ( m 1 + 1 , n ) , otherwise .
Let us consider ( R 2 , q , t ) . As b , c , and d are greater than or equal to 2, and q x = m 1 + 1 and t x m 1 + 1 , it is obvious that ( R 2 , q , t ) does not satisfy conditions (F1), (F2), and (F4)–(F6). Now, let us consider ( R 1 , s , p ) . Condition (F1) holds only if s y = p y = n 1 or s y = p y = 2 . However, this contradicts p = ( m 1 , n ) when s ( m 1 , n ) or p = ( m 1 , 1 ) when s ( m 1 , 1 ) . Therefore, ( R 1 , s , p ) does not satisfy condition (F1).
We have considered any case for constructing a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , where s x a and t x a + 1 . Thus, this lemma holds true.    □
Lemma 8.
Let us assume that O ( m , n ; k , l ; a , b , c , d ) is an O-shaped supergrid and that s and t are two distinct vertices in the graph. If s x , t x a + 1 and ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy conditions ( F 1 ) and ( F 10 ) ( F 13 ) , then there exists a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) .
Proof. 
Using symmetry, we can only consider the cases of a 2 and c = 1 , and a = b = c = d = 1 and a , b , c , d 2 (please refer to the discussion after Theorem 3). The cases of a = b = c = d = 1 and a , b , c , d 2 are isomorphic to Lemmas 6 and 7. Thus, we assume that a 2 and c = 1 in the following. If c = d = 1 and s x , t x a + k , then it must be the case that s y = t y = 1 or s y = t y = n . If s y = 1 and t y = n , then { s , t } is a vertex cut of O ( m , n ; k , l ; a , b , c , d ) , which satisfies condition (F1). Therefore, without loss of generality, let us assume that s y = t y = 1 when c = d = 1 and s x , t x a + k . We now consider the following three cases.
Case 1: One of the following cases holds:
        (1) b 2 , and ( s x , t x > a + k ) or ( s x a + k and t x > a + k ) ;
        (2) d 2 , and s y > c + l or t y > c + l .
In these cases, let us assume that the vertex in the upper-right corner has coordinates ( 1 , 1 ) if b 2 , or in the down-right corner if d 2 in O ( m , n ; k , l ; a , b , c , d ) . Using the same arguments as in the proofs of Lemmas 6 and 7, we can construct a Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) in these cases. It is worth noting that these cases are equivalent to the assumptions made in Lemmas 6 and 7.
Case 2: s y = t y = 1 and s x , t x a + k . If s t , then ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F1). Thus, s t . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed similarly to Case 1.1.1 of Lemma 7, where R 1 = C ( m 1 , n ; m 1 a , l ; c , d ) , R 2 = C ( m m 1 , n ; a + k m 1 , l ; c , d ) , and m 1 = s x (see Figure 21f).
Case 3: b = c = 1 ; d = 1 , or d 2 and s y , t y c + l ; and s x = t x = m , or s x m 1 and t x = m . A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed in this case, assuming that the vertex in the upper-right corner has coordinates ( 1 , 1 ) . The construction is similar to that in Case 1 of Lemma 6, when s x = t x = m , and Lemma 7, when s x a + k ( = m 1 ) and t x = m .    □
The Hamiltonian connectivity of O-shaped supergrid graphs is verified with the following theorem, which is based on Lemma 5 and Lemmas 6–8.
Theorem 5.
A Hamiltonian ( s , t ) -path exists in the O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) with distinct vertices s and t, if and only if conditions ( F 1 ) and ( F 10 ) ( F 13 ) are not satisfied by ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) .

5. The Longest (s, t)-Path Algorithm

In Theorem 5, we know that if ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies one of the conditions ((F1) and (F10)–(F13)), then ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) contains no Hamiltonian ( s , t ) -path. So, in this section, for these cases, we first establish upper bounds on the lengths of the longest paths between s and t. We then demonstrate that these upper bounds are equivalent to the lengths of the longest ( s , t ) -paths in O ( m , n ; k , l ; a , b , c , d ) . It is worth noting that isomorphic cases are excluded, and we assume that s x t x . The cases that we consider are limited to a = b = c = d = 1 , a 2 , and c = 1 ; and a , b , c , d 2 (see Section 2). In this context, we use L ^ ( G , s , t ) to denote the lengths of the longest paths between s and t, and U ^ ( G , s , t ) to represent the upper bound on the length of the longest paths between s and t, where G is a rectangular, L-shaped, C-shaped, or O-shaped supergrid graph. Note that the length of a path is defined as the number of vertices on the path. The following lemmas present these upper bounds.
Our initial focus is on the scenario where { s , t } forms a vertex cut of O ( m , n ; k , l ; a , b , c , d ) . In this case, we determine the upper bound of the length of the longest ( s , t ) -path using the following lemma.
Lemma 9.
Let us assume that c = 1 and that { s , t } is a vertex cut of O ( m , n ; k , l ; a , b , c , d ) . The following conditions are satisfied:
( O 1 )
If k 3 and s y = t y = 1 , then the length of any path between s and t cannot exceed m × n k × l t x + s x + 1 (refer to Figure 22a).
( O 2 )
If b = 1 , a + 1 s x a + k , s y = 1 , and t x = m , then the length of any path between s and t cannot exceed m × n k × l t y m + s x + 2 (refer to Figure 22b).
( O 3 )
If d = 1 , a + 1 s x , t x a + k , s y = 1 , and t y = n , then the length of any path between s and t cannot exceed max { L ^ ( R 1 , s , t ) , L ^ ( R 2 , s , t ) } , where R 1 = C ( t x , n ; t x a , l , c , d ) , R 2 = C ( m m 1 , n ; a + k m 1 , l , c , d ) , and m 1 = s x 1 (refer to Figure 22c,d).
Proof. 
Let us consider Figure 22a–d. When we remove s and t from O ( m , n ; k , l ; a , b , c , d ) , we obtain two separated components, R 1 and R 2 . Therefore, any simple path between s and t can only pass through one of these components, implying that its length cannot exceed the size of the largest component. For condition (O1) (resp., condition (O2)), the length of any path between s and t is equal to max { t x s x + 1 , m × n k × l t x + s x + 1 } (resp., max { t y + m s x , m × n k × l t y m + s x + 2 } ). Since a × n + b × n + d × k > t x s x + 1 (resp., a × n + d × ( k + b ) > t y + m s x ), it is apparent that the length of any path between s and t cannot exceed m × n k × l t x + s x + 1 (resp., m × n k × l t y m + s x + 2 ).    □
The next lemma provides an upper bound for the length of the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) , when { s , t } is not a vertex cut and c = 1 , under the assumption that the graph satisfies conditions (F11)–(F13).
Lemma 10.
Let ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfy condition ( F 11 ) , ( F 12 ) , or ( F 13 ) (cases ( 1.1 ) , ( 1.2 ) , ( 2 ) , and ( 3 ) of ( F 13 ) ). Then, the following implications hold true:
( 1 )
If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition ( F 11 ) , then the length of any ( s , t ) -path cannot exceed max { m × n k × l t x + u x + 1 , m × n k × l v x + t x + 1 } , where u = ( a + 1 , 1 ) , v = ( a + k , 1 ) , t y = 1 , and a + 3 t x a + k 2 (refer to Figure 23a).
( 2 )
If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies case (2.1) of condition ( F 13 ) , then the length of any ( s , t ) -path cannot exceed max { m × n k × l t x + u x + 1 , m × n k × l z y m + t x + 1 } , where u = ( a + 1 , 1 ) , z = ( m , c + l 1 ) , t y = 1 , and a + 3 t x m 1 (refer to Figure 23b).
( 3 )
If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies case (2.2) or (2.3) of condition ( F 13 ) , then the length of any ( s , t ) -path cannot exceed max { m × n k × l m + u x t y + 2 , m × n k × l v y + t y + 1 } , where u = ( a + 1 , 1 ) , v = ( m , c + l ) , t x = m , and 1 t y l 1 (refer to Figure 23c).
( 4 )
If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition ( F 12 ) , case (1.1) or (3) of ( F 13 ) , then the length of any ( s , t ) -path cannot exceed max { L ^ ( R 1 , s , u ) + L ^ ( R 2 , q , t ) , L ^ ( R 1 , s , v ) + L ^ ( R 2 , z , t ) } (refer to Figure 23d,e and Figure 23f,g), where u = ( m 1 , 1 ) , q = ( m 1 + 1 , 1 ) , v = ( m 1 , n ) , z = ( m 1 + 1 , n ) , R 1 = C ( m 1 , n ; m 1 a , l ; c , d ) , and R 2 = C ( m m 1 , n ; a + k m 1 , l ; c , d ) if k > 1 (otherwise, R 2 = R ( b , n ) ), and m 1 = a + 1 if s x a (otherwise, m 1 = s x ).
Proof. 
Let us examine Figure 23. It is evident that for the longest ( s , t ) -path P in O ( m , n ; k , l ; a , b , c , d ) , starting from s, P must traverse all or some vertices of R 1 , exit R 1 via u or v, enter R 2 via q or z, and terminate at t. Therefore, the length of any path between s and t cannot exceed max { L ^ ( R 1 , s , u ) + L ^ ( R 2 , q , t ) , L ^ ( R 1 , s , v ) + L ^ ( R 2 , z , t ) } .    □
We finally consider the remaining conditions for the case where { s , t } is not a vertex cut of O ( m , n ; k , l ; a , b , c , d ) . Specifically, we consider condition (F10) and case (1.3) of condition (F13).
Lemma 11.
Let a = c = 1 and s = ( 1 , 1 ) . If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies the following condition ( O 4 ) , then the length of any ( s , t ) -path cannot exceed max { L ^ ( R 1 , s , u ) + L ^ ( R 2 , q , t ) , L ^ ( R 1 , s , v ) + L ^ ( R 2 , z , t ) } (see Figure 24a–c), where R 1 = C ( n 1 , m ; 1 , k ; a , b ) and R 2 = C ( n n 1 , m ; l 1 , k ; a , b ) if l > 1 ; otherwise, R 2 = R ( m , d ) , n 1 = 1 , u = ( 1 , c + 1 ) , q = ( 1 , c + 2 ) , v = ( m , c + 1 ) , and z = ( m , c + 2 ) .
Condition ( O 4 ) is defined below.
(O4)
One of the following cases holds:
(1)
d = 1 , t y = n , and s x t x (case (1) of condition (F10));
(2)
s x = t x , l 3 , and t y 4 (case (2) of condition (F10) and case (1.3) of condition (F13)).
Proof. 
The proof follows an approach similar to that of Lemma 10 and can be visualized in Figure 24a–c.    □
Let us define condition (O0) as follows:
( O 0 )
None of the conditions (F1), (F10), (F11), (F12), or (F13) are satisfied by ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) .
Checking whether any ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies one of conditions (O0), (O1), (O2), (O3), (O4), (F11), (F12), and (F13) is a straightforward task. If ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies (O0), then U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = m n k l . Otherwise, U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) can be calculated using Lemmas 9–11. These calculations are summarized below, where | G | = m × n k × l :
U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = | G | t x + s x + 1 , if ( O 1 ) holds ; | G | t y m + s x + 2 , if ( O 2 ) holds ; max { L ^ ( R 1 , s , t ) , L ^ ( R 2 , s , t ) } , if ( O 3 ) holds ; max { | G | t x + u x + 1 , | G | v x + t x + 1 } , if ( F 11 ) holds ; max { | G | t x + u x + 1 , | G | z y m + t x + 1 } , if case ( 2.1 ) of ( F 13 ) holds ; max { | G | m + u x t y + 2 , | G | v y + t y + 1 } , if case ( 2.2 ) or ( 2.3 ) of ( F 13 ) holds ; max { L ^ ( R 1 , s , u ) + L ^ ( R 2 , q , t ) , L ^ ( R 1 , s , v ) + L ^ ( R 2 , z , t ) } , if ( O 4 ) , ( F 12 ) , or ( F 13 ) ( case 1.1 or 3 ) holds ; m n k l , if ( O 0 ) holds .
Next, we demonstrate how to find the longest ( s , t ) -path for O-shaped supergrid graphs. It should be noted that if ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (O0), then according to Theorem 5, it contains a Hamiltonian ( s , t ) -path.
Lemma 12.
When ( O ( m , n ; k , l ; a , b c , d ) , s , t ) satisfies any of conditions ( O 1 ) ( O 4 ) and ( F 11 ) ( F 13 ) , it follows that L ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) .
Proof. 
To prove this lemma, we construct an ( s , t ) -path P with length equal to U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) . We consider the following cases.
Case 1: Conditions (O1) and (O2) hold. Using Lemma 9, we obtain U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = m × n k × l t x + s x + 1 and U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = m × n k × l t y m + s x + 2 for conditions (O1) and (O2), respectively. We consider Figure 22a,b and make a vertical separation on O ( m , n ; k , l ; a , b , c , d ) to create two disjoint supergrid subgraphs R 1 = C ( m 1 , n ; m 1 a , l ; c , d ) , and either R 2 = C ( m m 1 , n ; a + k m 1 , l ; c , d ) if s x m 1 or R 2 = R ( b , n ) if s x = m 1 , where m 1 = s x (see Figure 25a,b). We select a vertex p V ( R 1 ) and a vertex q V ( R 2 ) such that p q , p = ( m 1 , n ) , and q = ( m 1 + 1 , n ) . We then construct the longest ( s , p ) -path P 1 in R 1 and the longest ( q , t ) -path P 2 in R 2 using the algorithms from [19,21]. Finally, we create an ( s , t ) -path P = P 1 P 2 , which forms the longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) . Figure 25c,d demonstrate the construction of such longest ( s , t ) -path. The length of the constructed longest ( s , t ) -path equals L ^ ( R 1 , s , p ) + L ^ ( R 2 , q , t ) = m × n k × l t x + s x + 1 or m × n k × l t y m + s x + 2 .
Case 2: Condition (O3) holds. Using Lemma 9, we can express U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) as max { L ^ ( R 1 , s , t ) , L ^ ( R 2 , s , t ) } , where R 1 and R 2 are two disjoint subgraphs of O ( m , n ; k , l ; a , b , c , d ) (refer to Figure 22c,d). Since R 1 and R 2 are both C-shaped supergrid graphs, we can apply the algorithm from [21] to construct the longest path between s and t in either R 1 or R 2 . The construction of such a path is shown in Figure 25e. The length of the constructed path is equal to L ^ ( R 1 , s , t ) or L ^ ( R 2 , s , t ) , which in turn is equal to U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) by Lemma 9.
Case 3: Condition (F11) holds. Let us examine Figure 23a. According to Lemma 10, if ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) satisfies condition (F11), then U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = , where = max { m × n k × l t x + u x + 1 , m × n k × l v x + t x + 1 } . There are two subcases to consider.
Case 3.1: = m × n k × l v x + t x + 1 . We begin by making two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) to obtain three disjoint supergrid subgraphs, R 1 = L ( m , n ; k + b , c + l ) , R 2 = R ( k 1 , c ) , and R 3 = L ( b + 1 , c + l ; 1 , l ) , as shown in Figure 26a. Let p V ( R 1 ) and q V ( R 2 ) , such that p q , q = ( a + 1 , 1 ) , and p = ( a , 1 ) if s ( a , 1 ) ; otherwise, p = ( a , 2 ) . We consider ( R 1 , s , p ) and note that it does not satisfy conditions (F1)–(F3). Using the algorithms from [19,20], we can construct a Hamiltonian ( s , p ) -path P 1 in R 1 and the longest ( q , t ) -path P 2 in R 2 . We can construct P 1 such that its one edge is placed to face R 3 using the algorithm from [20]. Then, P 12 = P 1 P 2 forms the longest ( s , t ) -path of R 1 R 2 , as depicted in Figure 26b. According to Theorem 2, R 3 contains a Hamiltonian cycle H C 3 . Using the algorithm in [20], we can construct H C 3 such that its one flat face faces R 1 . Then, there exist two edges, e 1 P 12 and e 3 H C 3 , such that e 1 e 3 (see Figure 26c). Using Statement (2) of Proposition 1, we can combine P 12 and H C 3 into the longest ( s , t ) -path P of O ( m , n ; k , l ; a , b , c , d ) . The construction of such longest path is depicted in Figure 26c. The length of the constructed longest ( s , t ) -path is equal to L ^ ( R 1 , s , p ) + L ^ ( R 2 , q , t ) + | V ( R 3 ) | = m × n k × l v x + t x + 1 .
Case 3.2: = m × n k × l t x + u x + 1 . Let us examine the following scenarios.
Case 3.2.1: s x > a . Let ( 1 , 1 ) be the coordinates of the vertex in the upper-right corner of O ( m , n ; k , l ; a , b , c , d ) . Then, we can construct the longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) in a way similar to that in Case 3.1 (as shown in Figure 27a).
Case 3.2.2: s x a . We begin by partitioning O ( m , n ; k , l ; a , b , c , d ) into three non-overlapping subgraphs, R 1 = L ( a + 1 , n ; 1 , n c ) , R 2 = R ( k 1 , c ) , and R 3 = L ( m a , n ; k , c + l ) , using three vertical separations and one horizontal separation (refer to Figure 27b). Let p V ( R 1 ) , q V ( R 2 ) , and w , z V ( R 3 ) such that p w , q z , q = ( a + k , 1 ) , z = ( a + k + 1 , 1 ) , w = ( a + 1 , n ) , and p = ( a , n ) if s ( a , n ) ; otherwise, p = ( a , n 1 ) . We observe that ( R 1 , s , p ) and ( R 3 , w , z ) do not satisfy conditions (F1)–(F3). To construct a Hamiltonian ( s , p ) -path P 1 and a Hamiltonian ( w , z ) -path P 3 of R 1 and R 3 , respectively, we use the algorithm proposed in [20]. Using the algorithm proposed in [19], we construct the longest ( q , t ) -path P 2 in R 2 . Finally, we concatenate P 1 , P 3 , and P 2 to obtain the longest ( s , t ) -path P of O ( m , n ; k , l ; a , b , c , d ) , i.e., P = P 1 P 3 P 2 . The size of the constructed longest ( s , t ) -path is L ^ ( R 1 , s , p ) + L ^ ( R 3 , w , z ) + L ^ ( R 2 , q , t ) = m × n k × l t x u x + 1 . We illustrate the construction of such longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) in Figure 27c.
Case 4: Case 2 of Condition (F13) holds. Let us consider Figure 23b,c. Based on Lemma 10, we have U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) = , where is the maximum of two values: 1 = m × n k × l t x + u x + 1 and 2 = m × n k × l z y m + t x + 1 (or 1 = m × n k × l u x t y + 2 and 2 = m × n k × l v y + t y + 1 , depending on the subcase). We consider the following two subcases.
Case 4.1: = m × n k × l t x + u x + 1 (resp., = m × n k × l m + u x t y + 2 ) . The longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be obtained in a way similar to that in Case 1, by making two vertical separations on O ( m , n ; k , l ; a , b , c , d ) to obtain two disjoint supergrid subgraphs R 1 = C ( m 1 , n ; m 1 a , l ; c , d ) and R 2 = C ( m m 1 , n ; a + k m 1 , l ; c , d ) , where m 1 = a + 1 , q = ( m 1 + 1 , n ) and p = ( m 1 , n ) (see Figure 28a). Using Lemma 10, the size of the constructed longest ( s , t ) -path is L ^ ( R 1 , s , p ) + L ^ ( R 2 , q , t ) = m × n k × l t x + u x + 1 (resp., m × n k × l m + u x t y + 2 ). The construction of such longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) is depicted in Figure 28b.
Case 4.2: = m × n k × l z y m + t x + 1 (resp., = m × n k × l v y + t y + 1 ) . The longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) can be constructed in a way similar to that in Case 3.1. Let R 1 = R ( m 1 , n ) , R 2 = L ( m m 1 , c + l 1 ; k , l 1 ) , R 3 = L ( m m 1 , d + 1 ; k , 1 ) , m 1 = a , q = ( m 1 + 1 , 1 ) , and p = ( m 1 , 1 ) if s ( m 1 , 1 ) ; otherwise, p = ( m 1 , 2 ) (see Figure 28c). The size of the constructed longest ( s , t ) -path is equal to L ^ ( R 1 , s , p ) + L ^ ( R 2 , q , t ) + | V ( R 3 ) | = m × n k × l z y m + t x + 1 (resp., m × n k × l v y + t y + 1 ) . The construction of such longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) is illustrated in Figure 28d.
Case 5: Condition (F13) (cases 1.1 and 3), (F12), or (O4) holds. Using Lemma 10 or 11, we can express U ^ ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) as max { L ^ ( R 1 , s , u ) + L ^ ( R 2 , q , t ) , L ^ ( R 1 , s , v ) + L ^ ( R 2 , z , t ) } . To construct the longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , we consider Figure 23d–g and Figure 24. Since R 1 and R 2 are C-shaped supergrid graphs, we can use the algorithm proposed in [21] to construct the longest ( s , u ) -path P 11 , the longest ( s , v ) -path P 12 in R 1 , the longest ( q , t ) -path P 21 , and the longest ( z , t ) -path P 22 in R 2 . Then, we can form the longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) by concatenating P 11 and P 21 , or P 12 and P 22 .    □
Finally, we conclude with the following theorem.
Theorem 6.
Let O ( m , n ; k , l ; a , b , c , d ) be an O-shaped supergrid graph with vertices s and t. Then, there exists a linear-time algorithm for finding the longest ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) .
Proof. 
The algorithm presented in Algorithm 1 solves the problem in linear time by combining the results of Lemmas 9–12 and Theorem 5. Therefore, the theorem follows.    □
Algorithm 1: The longest ( s , t ) -path algorithm
Input: An O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) and two distinct vertices s and t in it.
Output: The longest ( s , t ) -path.
  • if  s x , t x a  then output  H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) constructed from Lemma 6; // ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy the forbidden conditions (F1) and (F10);
  • if  s x a  and  t x a + 1  then output  H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) constructed from Lemma 7; // ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy the forbidden conditions (F1) and (F10)–(F13);
  • if  s x , t x a + 1  then output  H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t )  constructed from Lemma 8; // ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not satisfy the forbidden conditions (F1) and (F10)–(F13);
  • if  ( O ( m , n ; k , l ; a , b , c , d ) , s , t )  satisfies one of the forbidden conditions (F1)and (F10)–(F13), then output the longest  ( s , t ) -path based on Lemma 12.

6. Conclusions

We provide the necessary conditions for the existence of a Hamiltonian path in O-shaped supergrid graphs between any two given vertices. Moreover, we show that these necessary conditions are sufficient, by presenting a linear-time algorithm for computing the Hamiltonian path between any two vertices, except for five forbidden conditions. Hence, O-shaped supergrid graphs are Hamiltonian-connected, except in the case of the five forbidden conditions. Furthermore, we present a linear-time algorithm for computing the longest ( s , t ) -path of an O-shaped supergrid graph for any two given vertices s and t, provided that the forbidden conditions are satisfied. These algorithms can be regarded as the first attempts to solve the Hamiltonian and longest ( s , t ) -path problems for supergrid graphs with holes, where O-shaped supergrid graphs form a special class of supergrid graphs with holes. Although the Hamiltonian and longest ( s , t ) -path problems are NP-complete for general supergrid graphs, their complexities are still unknown for supergrid graphs with or without holes. We leave them as open problems for interested readers.

Author Contributions

Conceptualization, F.K.-K. and R.-W.H.; methodology, F.K.-K. and R.-W.H.; validation, F.K.-K. and R.-W.H.; formal analysis, R.-W.H.; writing—original draft, R.-W.H.; writing—review and editing, F.K.-K. and R.-W.H. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by National Science and Technology Council, Taiwan, under grant number MOST 110-2221-E-324-007-MY3.

Data Availability Statement

Not applicable.

Acknowledgments

The authors would like to thank the anonymous referees for many useful comments and suggestions, which have improved the presentation and correctness of this paper.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Garey, M.R.; Johnson, D.S. Computers and Intractability: A Guide to the Theory of NP-Completeness; Freeman: San Francisco, CA, USA, 1979. [Google Scholar]
  2. Johnson, D.S. The NP-complete column: An ongoing guide. J. Algorithms 1985, 6, 434–451. [Google Scholar] [CrossRef]
  3. Bertossi, A.A.; Bonuccelli, M.A. Hamiltonian circuits in interval graph generalizations. Inform. Process. Lett. 1986, 23, 195–200. [Google Scholar] [CrossRef]
  4. Damaschke, P. The Hamiltonian circuit problem for circle graphs is NP-complete. Inform. Process. Lett. 1989, 32, 1–2. [Google Scholar] [CrossRef]
  5. Golumbic, M.C. Algorithmic Graph Theory and Perfect Graphs, 2nd ed.; Annals of Discrete Mathematics 57; Elsevier: Amsterdam, The Netherlands, 2004. [Google Scholar]
  6. Gordon, V.S.; Orlovich, Y.L.; Werner, F. Hamiltonian properties of triangular grid graphs. Discrete Math. 2008, 308, 6166–6188. [Google Scholar] [CrossRef] [Green Version]
  7. Hung, R.W.; Yao, C.C.; Chan, S.J. The Hamiltonian properties of supergrid graphs. Theor. Comput. Sci. 2015, 602, 132–148. [Google Scholar] [CrossRef]
  8. Krishnamoorthy, M.S. An NP-hard problem in bipartite graphs. SIGACT News 1976, 7, 26. [Google Scholar] [CrossRef]
  9. Itai, A.; Papadimitriou, C.H.; Szwarcfiter, J.L. Hamiltonian paths in grid graphs. SIAM J. Comput. 1982, 11, 676–686. [Google Scholar] [CrossRef] [Green Version]
  10. Bondy, J.A.; Murty, U.S.R. Graph Theory with Applications; Macmillan: London, UK; Elsevier: New York, NY, USA, 1976. [Google Scholar]
  11. Hung, R.W.; Keshavarz-Kohjerdi, F.; Tseng, Y.M.; Qiu, G.H. Finding longest (s, t)-paths of O-shaped supergrid graphs in linear time. In Proceedings of the 10th IEEE International Conference on Awareness Science and Technology 2019 (iCAST’2019), Morioka, Japan, 23–25 October 2019; pp. 252–259. [Google Scholar]
  12. Hung, R.W.; Keshavarz-Kohjerdi, F. The longest (s, t)-paths of O-shaped supergrid graphs. arXiv 2019, arXiv:1911.08558. [Google Scholar]
  13. Zamfirescu, C.; Zamfirescu, T. Hamiltonian properties of grid graphs. SIAM J. Discret. Math. 1992, 5, 564–570. [Google Scholar] [CrossRef]
  14. Chen, S.D.; Shen, H.; Topor, R. An efficient algorithm for constructing Hamiltonian paths in meshes. Parallel Comput. 2002, 28, 1293–1305. [Google Scholar] [CrossRef]
  15. Lenhart, W.; Umans, C. Hamiltonian cycles in solid grid graphs. In Proceedings of the 38th Annual Symposium on Foundations of Computer Science (FOCS’97), Miami Beach, FL, USA, 20–22 October 1997; pp. 496–505. [Google Scholar]
  16. Keshavarz-Kohjerdi, F.; Bagheri, A. Hamiltonian paths in L-shaped grid graphs. Theor. Comput. Sci. 2016, 621, 37–56. [Google Scholar] [CrossRef]
  17. Nishat, R.I.; Srinivasan, V.; Whitesides, S. 1-complex s, t Hamiltonian paths: Structure and reconfiguration in rectangular grids. J. Graph Algorithms Appl. 2023, 27, 281–327. [Google Scholar] [CrossRef]
  18. Hung, R.W. Hamiltonian cycles in linear-convex supergrid graphs. Discret. Appl. Math. 2016, 211, 99–112. [Google Scholar] [CrossRef] [Green Version]
  19. Hung, R.W.; Li, C.F.; Chen, J.S.; Su, Q.S. The Hamiltonian connectivity of rectangular supergrid graphs. Discret. Optim. 2017, 26, 41–65. [Google Scholar] [CrossRef]
  20. Keshavarz-Kohjerdi, F.; Hung, R.W. The Hamiltonicity, Hamiltonian connectivity, and longest (s, t)-path of L-shaped supergrid graphs. IAENG Int. J. Comput. Sci. 2020, 47, 378–391. [Google Scholar]
  21. Keshavarz-Kohjerdi, F.; Hung, R.W. Finding Hamiltonian and longest (s, t)-paths of C-shaped supergrid graphs in linear time. Algorithms 2022, 15, 61. [Google Scholar] [CrossRef]
Figure 1. The primary elements and operational sequence of a computerized embroidery procedure.
Figure 1. The primary elements and operational sequence of a computerized embroidery procedure.
Mathematics 11 02712 g001
Figure 2. (a) A collection of lattices and (b) the associated supergrid graph of (a), in which each lattice is represented as a vertex with integer coordinates.
Figure 2. (a) A collection of lattices and (b) the associated supergrid graph of (a), in which each lattice is represented as a vertex with integer coordinates.
Mathematics 11 02712 g002
Figure 3. (a) The five layers ( O 1 O 5 ) of a 3D printing model for an O-type object, (b) the computation of the Hamiltonian ( s i , t i ) -path for each layer O i shown in (a), and (c) the final result after completing the 5-layered 3D printing process.
Figure 3. (a) The five layers ( O 1 O 5 ) of a 3D printing model for an O-type object, (b) the computation of the Hamiltonian ( s i , t i ) -path for each layer O i shown in (a), and (c) the final result after completing the 5-layered 3D printing process.
Mathematics 11 02712 g003
Figure 4. The structures of three types of supergrid graphs: (a) L-shaped supergrid graph L ( m , n ; k , l ) , (b) C-shaped supergrid graph C ( m , n ; k , l ; c , d ) , and (c) O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) .
Figure 4. The structures of three types of supergrid graphs: (a) L-shaped supergrid graph L ( m , n ; k , l ) , (b) C-shaped supergrid graph C ( m , n ; k , l ; c , d ) , and (c) O-shaped supergrid graph O ( m , n ; k , l ; a , b , c , d ) .
Mathematics 11 02712 g004
Figure 5. Rectangular supergrid graphs in which there is no Hamiltonian ( s , t ) -path for (a) R ( m , 1 ) and (b) R ( m , 2 ) , where solid lines indicate the longest path between s and t.
Figure 5. Rectangular supergrid graphs in which there is no Hamiltonian ( s , t ) -path for (a) R ( m , 1 ) and (b) R ( m , 2 ) , where solid lines indicate the longest path between s and t.
Mathematics 11 02712 g005
Figure 6. L-shaped supergrid graph L ( m , n ; k , l ) does not contain a Hamiltonian ( s , t ) -path when one of the following conditions are satisfied: (a) s is a cut vertex; (b) { s , t } is a vertex cut; (c) there exists a vertex w such that d e g L ( m , n ; k , l ) ( w ) = 1 , w s , and w t ; (d) m k = 1 , n l = 2 , l = 1 , k 2 , and { s , t } = { ( 1 , 2 ) , ( 2 , 3 ) } .
Figure 6. L-shaped supergrid graph L ( m , n ; k , l ) does not contain a Hamiltonian ( s , t ) -path when one of the following conditions are satisfied: (a) s is a cut vertex; (b) { s , t } is a vertex cut; (c) there exists a vertex w such that d e g L ( m , n ; k , l ) ( w ) = 1 , w s , and w t ; (d) m k = 1 , n l = 2 , l = 1 , k 2 , and { s , t } = { ( 1 , 2 ) , ( 2 , 3 ) } .
Mathematics 11 02712 g006
Figure 7. C-shaped supergrid graphs in which there is no Hamiltonian ( s , t ) -path, when one of the following conditions are satisfied: (a) s is a cut vertex; (b) { s , t } is a vertex cut; (c) there exists a vertex w such that d e g C ( m , n ; k , l ; c , d ) ( w ) = 1 , w s , and w t ; (d) m = 3 , a = m k = 2 , c = 1 , and { s , t } = { ( 1 , 1 ) , ( 2 , 2 ) } ; (eg) condition (F5) holds; (h) a = m k = 1 and s y , t y > c + l .
Figure 7. C-shaped supergrid graphs in which there is no Hamiltonian ( s , t ) -path, when one of the following conditions are satisfied: (a) s is a cut vertex; (b) { s , t } is a vertex cut; (c) there exists a vertex w such that d e g C ( m , n ; k , l ; c , d ) ( w ) = 1 , w s , and w t ; (d) m = 3 , a = m k = 2 , c = 1 , and { s , t } = { ( 1 , 1 ) , ( 2 , 2 ) } ; (eg) condition (F5) holds; (h) a = m k = 1 and s y , t y > c + l .
Mathematics 11 02712 g007
Figure 8. Schematic diagrams of (a) Statement (1), (b) Statement (2), (c) Statement (3), and (d) Statement (4) of Proposition 1, where the cycles or paths are denoted by bold dashed lines, and the symbol ⊗ is used to signify the removal of an edge during their construction.
Figure 8. Schematic diagrams of (a) Statement (1), (b) Statement (2), (c) Statement (3), and (d) Statement (4) of Proposition 1, where the cycles or paths are denoted by bold dashed lines, and the symbol ⊗ is used to signify the removal of an edge during their construction.
Mathematics 11 02712 g008
Figure 9. The subcases for a 2 and c = 1 : (a) b = d = 1 , (b) b = 1 and d 2 , (c) b 2 and d = 1 , and (d) b , d 2 .
Figure 9. The subcases for a 2 and c = 1 : (a) b = d = 1 , (b) b = 1 and d 2 , (c) b 2 and d = 1 , and (d) b , d 2 .
Mathematics 11 02712 g009
Figure 10. (a) One vertical separation on O ( m , n ; k , l ; a , b , c , d ) to obtain R 1 and R 2 , and (b) the constructed Hamiltonian cycle of O ( m , n ; k , l ; a , b , c , d ) , with solid bold lines indicating the cycle.
Figure 10. (a) One vertical separation on O ( m , n ; k , l ; a , b , c , d ) to obtain R 1 and R 2 , and (b) the constructed Hamiltonian cycle of O ( m , n ; k , l ; a , b , c , d ) , with solid bold lines indicating the cycle.
Mathematics 11 02712 g010
Figure 11. H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not exist when (a,b) { s , t } is a vertex cut; (c,d) a = b = c = d = 1 ; and (e) c = 1 , a , b , d 2 , and k 5 .
Figure 11. H P ( O ( m , n ; k , l ; a , b , c , d ) , s , t ) does not exist when (a,b) { s , t } is a vertex cut; (c,d) a = b = c = d = 1 ; and (e) c = 1 , a , b , d 2 , and k 5 .
Mathematics 11 02712 g011
Figure 12. For O-shaped supergrid graphs with a 2 and c = 1 , the forbidden conditions for the existence of a Hamiltonian ( s , t ) -path are as follows: (a) when d = 1 , b 2 , s x a , and t x a + 3 ; (b) when d = 1 , b 2 , a + 1 s x a + k 2 , and t x a + k + 1 ; and (c,d) when b = 1 , s x , t x a + 1 , t = ( m , 1 ) , k 3 , and s x m 3 .
Figure 12. For O-shaped supergrid graphs with a 2 and c = 1 , the forbidden conditions for the existence of a Hamiltonian ( s , t ) -path are as follows: (a) when d = 1 , b 2 , s x a , and t x a + 3 ; (b) when d = 1 , b 2 , a + 1 s x a + k 2 , and t x a + k + 1 ; and (c,d) when b = 1 , s x , t x a + 1 , t = ( m , 1 ) , k 3 , and s x m 3 .
Mathematics 11 02712 g012
Figure 13. O-shaped supergrid graphs with a 2 and c = b = 1 , in which there is no Hamiltonian ( s , t ) -path, where (a) case (1.2) of condition (F13) is satisfied, (b,c) case (1.3) of condition (F13) is satisfied, (df) case (2) of condition (F13) is satisfied, and (g,h) case (3) of condition (F13) is satisfied.
Figure 13. O-shaped supergrid graphs with a 2 and c = b = 1 , in which there is no Hamiltonian ( s , t ) -path, where (a) case (1.2) of condition (F13) is satisfied, (b,c) case (1.3) of condition (F13) is satisfied, (df) case (2) of condition (F13) is satisfied, and (g,h) case (3) of condition (F13) is satisfied.
Mathematics 11 02712 g013
Figure 14. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) is performed with the constraints that s x , t x a , and a = b = c = d = 1 ; (b,c) a horizontal separation is performed on R 1 , where (b) assumes that s and t are adjacent and (c) assumes that s and t are non-adjacent; (d) Hamiltonian paths are constructed for R 11 , R 12 , and R 2 ; and (e) a Hamiltonian ( s , t ) -path is constructed in O ( m , n ; k , l ; a , b , c , d ) , with bold lines representing the constructed path.
Figure 14. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) is performed with the constraints that s x , t x a , and a = b = c = d = 1 ; (b,c) a horizontal separation is performed on R 1 , where (b) assumes that s and t are adjacent and (c) assumes that s and t are non-adjacent; (d) Hamiltonian paths are constructed for R 11 , R 12 , and R 2 ; and (e) a Hamiltonian ( s , t ) -path is constructed in O ( m , n ; k , l ; a , b , c , d ) , with bold lines representing the constructed path.
Mathematics 11 02712 g014
Figure 15. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) , where s x , t x a , a = 2 , and c = 1 , is performed to obtain R 1 and R 2 . (bd,f) Vertical and horizontal separations on R 1 are performed. (e) A horizontal separation on R 1 is performed. Note that bold lines represent the constructed Hamiltonian path.
Figure 15. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) , where s x , t x a , a = 2 , and c = 1 , is performed to obtain R 1 and R 2 . (bd,f) Vertical and horizontal separations on R 1 are performed. (e) A horizontal separation on R 1 is performed. Note that bold lines represent the constructed Hamiltonian path.
Mathematics 11 02712 g015
Figure 16. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) , where s x , t x a and a 3 ; (b) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 ; (c) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) , where { s , t } is not a vertex cut of R 11 ; (d,e) horizontal separation on R 1 and Hamiltonian ( s , t ) -paths of O ( m , n ; k , l ; a , b , c , d ) , where { s , t } is a vertex cut of R 11 and where in (be), s and t are in R 1 , the constructed Hamiltonian ( s , t ) -path is indicated by bold lines, and ⊗ denotes the destruction of an edge during the construction of the Hamiltonian path.
Figure 16. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) , where s x , t x a and a 3 ; (b) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 ; (c) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) , where { s , t } is not a vertex cut of R 11 ; (d,e) horizontal separation on R 1 and Hamiltonian ( s , t ) -paths of O ( m , n ; k , l ; a , b , c , d ) , where { s , t } is a vertex cut of R 11 and where in (be), s and t are in R 1 , the constructed Hamiltonian ( s , t ) -path is indicated by bold lines, and ⊗ denotes the destruction of an edge during the construction of the Hamiltonian path.
Mathematics 11 02712 g016
Figure 17. A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , where a 3 and c = 1 , for (ac) s , t R 2 ; and (d) s R 1 and t R 2 .
Figure 17. A Hamiltonian ( s , t ) -path of O ( m , n ; k , l ; a , b , c , d ) , where a 3 and c = 1 , for (ac) s , t R 2 ; and (d) s R 1 and t R 2 .
Mathematics 11 02712 g017
Figure 18. (a,b) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , and t = ( a + 1 , 1 ) ; (c) a Hamiltonian ( s , p ) -path in R 1 and a Hamiltonian ( q , t ) -path in R 2 for (a); (d) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a); and (e) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) and a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , and t = ( a + 2 , 1 ) , where bold lines indicate the constructed Hamiltonian path.
Figure 18. (a,b) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , and t = ( a + 1 , 1 ) ; (c) a Hamiltonian ( s , p ) -path in R 1 and a Hamiltonian ( q , t ) -path in R 2 for (a); (d) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a); and (e) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) and a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , and t = ( a + 2 , 1 ) , where bold lines indicate the constructed Hamiltonian path.
Mathematics 11 02712 g018
Figure 19. (a) Two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for a , b , d 2 , c = 1 , and t = ( a + k , 1 ) ; (b) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a , b , d 2 , c = 1 , and t = ( a + k 1 , 1 ) ; (c) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 for (b); and (d) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (b), where bold lines represent the constructed Hamiltonian path and ⊗ indicates the destruction of an edge while constructing such a Hamiltonian ( s , t ) -path.
Figure 19. (a) Two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for a , b , d 2 , c = 1 , and t = ( a + k , 1 ) ; (b) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a , b , d 2 , c = 1 , and t = ( a + k 1 , 1 ) ; (c) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 for (b); and (d) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (b), where bold lines represent the constructed Hamiltonian path and ⊗ indicates the destruction of an edge while constructing such a Hamiltonian ( s , t ) -path.
Mathematics 11 02712 g019
Figure 20. (a,b) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , t = ( m , 1 ) , and k 2 ; (c,d) vertical and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , t = ( m , 1 ) , k 3 , and l 2 ; (e) a Hamiltonian ( s , t ) -path in R 1 R 2 and a Hamiltonian cycle in R 3 for (c); and (f) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (c).
Figure 20. (a,b) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , t = ( m , 1 ) , and k 2 ; (c,d) vertical and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , t = ( m , 1 ) , k 3 , and l 2 ; (e) a Hamiltonian ( s , t ) -path in R 1 R 2 and a Hamiltonian cycle in R 3 for (c); and (f) a Hamiltonian ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (c).
Mathematics 11 02712 g020
Figure 21. (ac) Vertical and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , and t = ( m , c + l ) or t = ( m , c + l 1 ) ; (d,e) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a , d 2 and c = 1 ; and (f) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , s y = t y = 1 , and a + 1 s x , t x a + k .
Figure 21. (ac) Vertical and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for a 2 , b = c = 1 , and t = ( m , c + l ) or t = ( m , c + l 1 ) ; (d,e) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a , d 2 and c = 1 ; and (f) a vertical separation on O ( m , n ; k , l ; a , b , c , d ) for a 2 , c = 1 , s y = t y = 1 , and a + 1 s x , t x a + k .
Mathematics 11 02712 g021
Figure 22. The upper bound of the length of the longest ( s , t ) -path, where { s , t } is a vertex cut, when (a) (O1) holds, (b) (O2) holds, and (c,d) (O3) holds. Note that a vertical separation in O ( m , n ; k , l ; a , b , c , d ) is denoted by a bold dashed line.
Figure 22. The upper bound of the length of the longest ( s , t ) -path, where { s , t } is a vertex cut, when (a) (O1) holds, (b) (O2) holds, and (c,d) (O3) holds. Note that a vertical separation in O ( m , n ; k , l ; a , b , c , d ) is denoted by a bold dashed line.
Mathematics 11 02712 g022
Figure 23. The upper bound of the length of the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a) condition (F11); (b) case (2.1) of condition (F13); (c) cases (2.2) and (2.3) of condition (F13); (d,e) condition (F11); and (f,g) cases (1.1), (1.2), and (3) of condition (F13), where the bold dash line indicates vertical or horizontal separation on O ( m , n ; k , l ; a , b , c , d ) .
Figure 23. The upper bound of the length of the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a) condition (F11); (b) case (2.1) of condition (F13); (c) cases (2.2) and (2.3) of condition (F13); (d,e) condition (F11); and (f,g) cases (1.1), (1.2), and (3) of condition (F13), where the bold dash line indicates vertical or horizontal separation on O ( m , n ; k , l ; a , b , c , d ) .
Mathematics 11 02712 g023
Figure 24. The upper bound of the length of the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for condition (O4), where (a,b) d = 1 , t y = n , and s x t x ; and (c) s x = t x , l 3 , and t y 4 .
Figure 24. The upper bound of the length of the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for condition (O4), where (a,b) d = 1 , t y = n , and s x t x ; and (c) s x = t x , l 3 , and t y 4 .
Mathematics 11 02712 g024
Figure 25. (a,b) Vertical separation on O ( m , n ; k , l ; a , b , c , d ) for conditions (O1) and (O2) respectively; (c,d) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a,b), respectively; and (e) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (O3), where bold lines indicate the constructed longest ( s , t ) -path.
Figure 25. (a,b) Vertical separation on O ( m , n ; k , l ; a , b , c , d ) for conditions (O1) and (O2) respectively; (c,d) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a,b), respectively; and (e) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (O3), where bold lines indicate the constructed longest ( s , t ) -path.
Mathematics 11 02712 g025
Figure 26. (a) Two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for (F11), where = m × n k × l v x + t x + 1 ; (b) the longest ( s , t ) -path in R 1 R 2 and a Hamiltonian cycle of R 3 ; and (c) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a), where bold lines indicate the constructed longest ( s , t ) -path and ⊗ represents the destruction of an edge while constructing such an ( s , t ) -path.
Figure 26. (a) Two vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for (F11), where = m × n k × l v x + t x + 1 ; (b) the longest ( s , t ) -path in R 1 R 2 and a Hamiltonian cycle of R 3 ; and (c) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a), where bold lines indicate the constructed longest ( s , t ) -path and ⊗ represents the destruction of an edge while constructing such an ( s , t ) -path.
Mathematics 11 02712 g026
Figure 27. (a) The longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for condition (F11), where = m × n k × l t x + u x + 1 and s x > a ; (b) three vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for (F11), where = m × n k × l t x + u x + 1 and s x a ; and (c) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (b).
Figure 27. (a) The longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for condition (F11), where = m × n k × l t x + u x + 1 and s x > a ; (b) three vertical separations and one horizontal separation on O ( m , n ; k , l ; a , b , c , d ) for (F11), where = m × n k × l t x + u x + 1 and s x a ; and (c) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (b).
Mathematics 11 02712 g027
Figure 28. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for case (2) of condition (F13), where = m × n k × l t x + u x + 1 ; (b) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a); (c) a vertical separation and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for case (2) of condition (F13), where = m × n k × l z y m + t x + 1 ; and (d) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (c).
Figure 28. (a) A vertical separation on O ( m , n ; k , l ; a , b , c , d ) for case (2) of condition (F13), where = m × n k × l t x + u x + 1 ; (b) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (a); (c) a vertical separation and horizontal separations on O ( m , n ; k , l ; a , b , c , d ) for case (2) of condition (F13), where = m × n k × l z y m + t x + 1 ; and (d) the longest ( s , t ) -path in O ( m , n ; k , l ; a , b , c , d ) for (c).
Mathematics 11 02712 g028
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Keshavarz-Kohjerdi, F.; Hung, R.-W. The Longest (s, t)-Path Problem on O-Shaped Supergrid Graphs. Mathematics 2023, 11, 2712. https://doi.org/10.3390/math11122712

AMA Style

Keshavarz-Kohjerdi F, Hung R-W. The Longest (s, t)-Path Problem on O-Shaped Supergrid Graphs. Mathematics. 2023; 11(12):2712. https://doi.org/10.3390/math11122712

Chicago/Turabian Style

Keshavarz-Kohjerdi, Fatemeh, and Ruo-Wei Hung. 2023. "The Longest (s, t)-Path Problem on O-Shaped Supergrid Graphs" Mathematics 11, no. 12: 2712. https://doi.org/10.3390/math11122712

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop