Next Article in Journal
Pruning Adapters with Lottery Ticket
Previous Article in Journal
Allocating Small Transporters to Large Jobs
Previous Article in Special Issue
k-Center Clustering with Outliers in Sliding Windows
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Finding Hamiltonian and Longest (s,t)-Paths of C-Shaped Supergrid Graphs in Linear Time

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.
Algorithms 2022, 15(2), 61; https://doi.org/10.3390/a15020061
Submission received: 5 January 2022 / Revised: 8 February 2022 / Accepted: 10 February 2022 / Published: 13 February 2022
(This article belongs to the Special Issue Discrete Optimization Theory, Algorithms, and Applications)

Abstract

:
A graph is called Hamiltonian connected if it contains a Hamiltonian path between any two distinct vertices. In the past, we proved the Hamiltonian path and cycle problems for general supergrid graphs to be NP-complete. However, they are still open for solid supergrid graphs. In this paper, first we will verify the Hamiltonian cycle property of C-shaped supergrid graphs, which are a special case of solid supergrid graphs. Next, we show that C-shaped supergrid graphs are Hamiltonian connected except in a few conditions. For these excluding conditions of Hamiltonian connectivity, we compute their longest paths. Then, we design a linear-time algorithm to solve the longest path problem in these graphs. The Hamiltonian connectivity of C-shaped supergrid graphs can be applied to compute the optimal stitching trace of computer embroidery machines, and construct the minimum printing trace of 3D printers with a C-like component being printed.

Graphical Abstract

1. Introduction

A Hamiltonian path (cycle) in a graph is a spanning path (cycle) of the graph. The Hamiltonian path (cycle) problem involves deciding whether or not a graph contains a Hamiltonian path (cycle). A graph is called Hamiltonian if it contains a Hamiltonian cycle. A graph G is said to be Hamiltonian connected if for each pair of distinct vertices u and v of G, there is a Hamiltonian path between u and v in G. It is well known that the Hamiltonian path and cycle problems are NP-complete for general graphs [1]. In [2], Harary outlined the important motivations and applications for Hamiltonian path problem. In addition, the Hamiltonian problems have been much studied and have numerous applications in different areas, including establishing transport routes, production launching, the on-line optimization of flexible manufacturing systems [3], computing the perceptual boundaries of dot patterns [4], pattern recognition [5,6,7], hypercube properties [8], molecular and physical sciences [9,10], biology science [11], etc. It is worth mentioning that Twarock et al. [11] applied the Hamiltonian path to the analysis of viral genomes, and Balasubramanian [9,10] pointed out that in molecular and physical sciences, the Hamiltonian path problem is related to random walks, enumeration of self-returning walks and ring perception algorithms, and peripherals of fullerenes. The longest path problem, which finds a simple path with the maximum number of vertices in a graph, is one of the most important problems in graph theory. The Hamiltonian path problem is clearly a special case of the longest path problem. Despite the many applications of the problem, it is still open for some classes of graphs, including solid supergrid graphs and supergrid graphs with some holes [12]. There are few classes of graphs in which the longest path problem is polynomial-time solvable [13,14,15]. Because the time complexity of the longest path problem on solid supergrid graphs is still open, it is interesting to study this problem for the subcalsses of solid supergrid graphs. In this paper, we focus on C-shaped supergrid graphs, which form a subclass of solid supergrid graphs. We will give the necessary and sufficient conditions for the Hamiltonicity and Hamiltonian connectivity of C-shaped supergrid graphs. We also present a linear-time algorithm for finding a longest path between any two distinct vertices in a C-shaped supergrid graph.
The two-dimensional integer grid graph  G is an infinite graph whose vertex set consists of all points of the Euclidean plane with integer coordinates and in which two vertices are adjacent if the (Euclidean) distance between them is 1. The two-dimensional supergrid graph S is an infinite graph obtained from G by adding all edges on the lines traced from up-left to down-right and from up-right to down-left. A graph is a grid graph if it is a finite induced subgraph of G . A supergrid graph is a finite vertex-induced subgraph of S . Supergrid graphs came from our industry-university cooperative research project, and can be applied to compute the stitching trace of computerized sewing machines [16]. A solid supergrid graph is a supergrid graph without any hole, and a rectangular supergrid graph is a solid supergrid graph bounded by a axis-parallel rectangle. A L-shaped or C-shaped supergrid graph is a supergrid graph obtained from a rectangular supergrid graph by removing a rectangular supergrid subgraph from it to form a L-like or C-like shape.
The Hamiltonian connectivity and longest path of shaped supergrid graphs can be applied for computing the optimal stitching trace of computer embroidery machines [12,16,17]. For example, consider that a string of letters will be sewed into an object such that the number of crossed paths is minimum. The Hamiltonian connectivity and longest path of these shaped letters play an important role in deciding these sewing traces. In addition, they can be also applied to construct the minimum printing trace of 3D printers. For example, consider a 3D printer with a C-like 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 3D printer. Because 3D printing is performed layer-by-layer (see Figure 1a), each layer can be considered as a C-shaped supergrid graph. Suppose that there are k layers under the above 3D printing. If the Hamiltonian connectivity of C-shaped supergrid graphs holds true, then we can find a Hamiltonian path, starting from s i and ending at t i , of a C-shaped supergrid graph C i , where C 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. For example, Figure 1a shows five layers C 1 C 5 of a 3D printing for a C-type object, Figure 1b depicts the Hamiltonian paths of C i for 1 i 5 , and the result of this 3D printing is shown in Figure 1c.
Some related works in the literature are summarized as follows. Recently, Hamiltonian path (cycle) and Hamiltonian connected problems in grid and supergrid graphs have received much attention. In [18], Itai et al. proved that the Hamiltonian path problem on grid graphs is NP-complete. They also gave necessary and sufficient conditions for a rectangular grid graph having a Hamiltonian path between two given vertices. Note that rectangular grid graphs are not Hamiltonian connected. Zamfirescu et al. [19] gave sufficient conditions for a grid graph having a Hamiltonian cycle, and proved that all grid graphs of positive width have Hamiltonian line graphs. Later, Chen et al. [20] improved the Hamiltonian path algorithm of [18] on rectangular grid graphs and presented a parallel algorithm for the Hamiltonian path problem with two given endpoints in rectangular grid graphs. In addition, there is a polynomial-time algorithm for finding Hamiltonian cycles in solid grid graphs [21]. However, the Hamiltonian problems are still open for solid supergrid graphs. In [22], Salman introduced alphabet grid graphs and determined classes of alphabet grid graphs which contain Hamiltonian cycles. Supergrid graphs first appeared in [16], and the authors proved that the Hamiltonian cycle and path problems on general supergrid graphs are NP-complete, and every rectangular supergrid graph always contains a Hamiltonian cycle. Recently, the Hamiltonian connectivity of L-shaped supergrid graphs has been verified in [17]. Note that C-shaped supergrid graphs contain L-shaped supergrid graphs as their subgraphs. Thus, the results of L-shaped supergrid graphs can not be directly applied to C-shaped supergrid graphs. However, the results in [17] will be used in our method. In this paper, we will consider the Hamiltonian, Hamiltonian connectivity, and longest path of C-shaped supergrid graphs.
The rest of the paper is organized as follows. In Section 2, some notations, observations, known results, and one special Hamiltonian connected property of a special rectangular supergrid graph are given. In Section 3, we give the necessary and sufficient conditions for the Hamiltonian and the Hamiltonian connected C-shaped supergrid graphs. This section shows that C-shaped supergrid graphs are always Hamiltonian and Hamiltonian connected except for a few conditions. In Section 4, we present a linear-time algorithm to compute the longest path between any two distinct vertices in a C-shaped supergrid graph. Finally, a conclusion is given in Section 5.

2. Terminologies and Background Results

In this section, we will introduce some terminologies and symbols. Some observations and previously established results for the Hamiltonicity and Hamiltonian connectivity of rectangular and L-shaped supergrid graphs are also given. In addition, we also prove some Hamiltonian connectivity property of a special class of rectangular supergrid graphs that will be used in proving our result.
Suppose that G is a graph with vertex set V ( G ) and edge set E ( G ) . Let S V ( G ) , and let u , v V ( G ) . We write G [ S ] for the subgraph of G induced by S, and G S for the subgraph G [ V ( G ) S ] . In general, we write G v instead of G { v } . The notation u v (resp., u v ) means that vertices u and v are adjacent (resp., non-adjacent). A vertex wadjoins edge ( u , v ) if w u and w v . For two edges e 1 = ( u 1 , v 1 ) and e 2 = ( u 2 , v 2 ) , if u 1 u 2 and v 1 v 2 then we say that e 1 and e 2 are parallel, denoted this by e 1 e 2 . A neighbor of vertex v is any vertex adjacent to v. We denote by N G ( v ) the set of neighbors of v in G, and let N G [ v ] = N G ( v ) { v } . The degree of vertex v in G, denoted by d e 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 a sequence ( v 1 , v 2 , , v | P | 1 , v | P | ) of vertices such that ( v i , v i + 1 ) E ( G ) for 1 i < | P | , and all vertices except v 1 , v | P | in it 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 will use v i P to denote “P visits vertex v i ” and use ( v i , v i + 1 ) P to denote “P visits edge ( v i , v i + 1 ) ”. A path from v 1 to v k is denoted by ( v 1 , v k ) -path. In addition, we use P to refer to the set of vertices visited by path P if it is understood without ambiguity. 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 of 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, denoted by P 1 P 2 .
For a node (vertex) v in the plane with integer coordinates, let v x and v y represent the x and ycoordinates of node v, respectively, denoted by v = ( v x , v y ) . A grid graph is a finite vertex-induced subgraph of G . Figure 2a shows a grid graph, and it is clear that the maximum degree of all vertices is four. A supergrid graph is a finite vertex-induced subgraph of S . Figure 2b depicts a supergrid graph, it is clear that the maximum degree of all vertices is eight. Thus, supergrid graphs contain grid graphs as subgraphs. Notice that grid graphs are not a subclass of supergrid graphs, and the converse is also true. Obviously, all grid graphs are bipartite [18] but supergrid graphs are not bipartite.
A rectangular supergrid graph, denoted by R ( m , n ) , is a supergrid graph whose vertex set is V ( R ( m , n ) ) = { v = ( v x , v y ) | 1 v x m and 1 v y n } . That is, R ( m , n ) contains m columns and n rows of vertices in S and its shape is a rectangle. The size of R ( m , n ) is defined to be m n , and R ( m , n ) is called n-rectangle. The vertex v is called the upper-left (resp., upper-right, down-left, down-right) corner of R ( m , n ) 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 , w x v x and w y v y ). The edge ( u , v ) is said to be horizontal (resp., vertical) if u y = v y (resp., u x = v x ), and is called crossed if it is neither a horizontal nor a vertical edge. There are four boundaries in a rectangular supergrid graph R ( m , n ) with m , n 2 . The edge in the boundary of R ( m , n ) is called boundary edge. A path is called boundary of R ( m , n ) if it visits all vertices and edges of the same boundary in R ( m , n ) and its length equals to the number of vertices in the visited boundary. For example, Figure 3a shows a rectangular supergrid graph R ( 9 , 8 ) which is called 8-rectangle and contains 2 × ( 8 + 7 ) = 30 boundary edges. Figure 3a also indicates the types of edges and corners. In the figures we will assume that ( 1 , 1 ) are coordinates of the upper-left corner in R ( m , n ) , except when we explicitly change this assumption.
A L-shaped supergrid graph, denoted by L ( m , n ; k , l ) , is a supergrid graph obtained from a rectangular supergrid graph R ( m , n ) by cutting its subgraph R ( k , l ) from the upper-right corner, where m , n > 1 and k , l 1 . A C-shaped supergrid graph C ( m , n ; k , l ; c , d ) is a supergrid graph obtained from a rectangular supergrid graph R ( m , n ) by removing its subgraph R ( k , l ) from its node coordinated as ( m , c + 1 ) while R ( m , n ) and R ( k , l ) have exactly one border side in common, where m 2 , n 3 , k , l 1 , c 1 , d = n l c 1 , and a = m k 1 . The structures of L ( m , n ; k , l ) and C ( m , n ; k , l ; c , d ) are explained in Figure 3b,c, respectively.
In our method, we need to partition a rectangular or C-shaped supergrid graph into η disjoint parts, where η 2 . The partition is defined as follows.
Definition 1.
Assume that G ^ is a rectangular supergrid graph R ( m , n ) or a C-shaped supergrid graph C ( m , n ; k , l ; c , d ) . A separation operation on G ^ is a partition of G ^ into η vertex-disjoint rectangular or L-shaped supergrid subgraphs G ^ 1 , G ^ 2 , ⋯, G ^ η , i.e., V ( G ^ ) = V ( G ^ 1 ) V ( G ^ 2 ) V ( G ^ η ) and V ( G ^ i ) V ( G ^ j ) = for i j and 1 i , j η , where η 2 . A separation is called horizontal if it consists of a set of vertical edges, and is called vertical if it contains a set of horizontal edges. Note that horizontal or vertical separation may be empty in our partition for the presentation of clarity. For example, Figure 3a indicates a horizontal (resp., vertical) separation of R ( 9 , 8 ) which partitions it into R ( 9 , 3 ) and R ( 9 , 5 ) (resp., R ( 4 , 8 ) and R ( 5 , 8 ) ).
Let R ( m , n ) be a rectangular supergrid graph with m n 2 , C be a cycle of R ( m , n ) , and let H be a boundary of R ( m , n ) . The restriction of C to H is denoted by C | H . If | C | H | = 1 , i.e., C | H is a boundary path on H, then C | H is called flat face on H. If | C | H | > 1 and C | H contains at least one boundary edge of H, then C | H is called concave face on H. A Hamiltonian cycle of R ( m , 3 ) is called canonical if it contains three flat faces on two shorter boundaries and one longer boundary, and it contains one concave face on the other boundary, where the shorter boundary consists of three vertices. A Hamiltonian cycle of R ( m , n ) with n = 2 or n 4 is said to be canonical if it contains three flat faces on three boundaries, and it contains one concave face on the other boundary. The following lemma states the result in [16] concerning the Hamiltonicity of rectangular supergrid graphs.
Lemma 1
(See [16]). Assume that R ( m , n ) is a rectangular supergrid graph with m n 2 . Then, the following statements hold true:
(1)
R ( m , 3 ) contains a canonical Hamiltonian cycle;
(2)
R ( m , n ) with n = 2 or n 4 contains four canonical Hamiltonian cycles with concave faces being on different boundaries.
Figure 4 shows canonical Hamiltonian cycles for rectangular supergrid graphs found in Lemma 1. Each Hamiltonian cycle constructed by this lemma contains all the boundary edges on any three sides of the rectangular supergrid graph. This shows that for any rectangular supergrid graph R ( m , n ) with m n 4 , we can construct four canonical Hamiltonian cycles such that their concave faces are placed on different boundaries. For instance, the four distinct canonical Hamiltonian cycles of R ( 5 , 5 ) are shown in Figure 4b–e.
Let ( G , s , t ) denote supergrid graph G with two specified distinct vertices s and t. Without loss of generality, we will assume that s x t x in the rest of the paper. We denote a Hamiltonian path between s and t in G by H P ( G , s , t ) . We say that H P ( G , s , t ) does exist if there is a Hamiltonian ( s , t ) -path in G. From Lemma 1, H P ( R ( m , n ) , s , t ) does exist if m , n 2 and ( s , t ) is an edge in the constructed Hamiltonian cycle of R ( m , n ) .
Definition 2.
Assume that G is a connected supergrid graph and V 1 is a subset of the vertex set V ( G ) . V 1 is called a vertex cut if G V 1 is disconnected. A vertex v V ( G ) is said to be a cut vertex if G { v } is disconnected.
In [12], the authors showed that H P ( R ( m , n ) , s , t ) does not exist if the following condition hold:
( F 1 )
s or t is a cut vertex, or { s , t } is a vertex cut (see Figure 5).
Assume G is any supergrid graph. The following lemma shows that H P ( G , s , t ) does not exist if ( G , s , t ) satisfies condition (F1), and can be verified by the same arguments in [23].
Lemma 2
(See [23]). Assume that G is a supergrid graph with two vertices s and t. If ( G , s , t ) satisfies condition ( F 1 ) , then H P ( G , s , t ) does not exist.
The Hamiltonian ( s , t ) -path of R ( m , n ) constructed in [12] satisfies that it contains at least one boundary edge of each boundary, and is called canonical.
Lemma 3
(See [12]). Assume R ( m , n ) is a rectangular supergrid graph and s , t V ( R ( m , n ) ) . If ( R ( m , n ) , s , t ) does not satisfy condition ( F 1 ) , then there exists a canonical Hamiltonian ( s , t ) -path of R ( m , n ) .
Lemma 4
(See [17]). Assume R ( m , n ) is a rectangular supergrid graph with m 3 and n 2 , and s and t are its two distinct vertices. 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 P of R ( m , n ) such that ( z , f ) P if ( R ( m , n ) , s , t ) does satisfy condition ( F 2 ) ; and ( w , z ) P otherwise, where condition ( F 2 ) is defined as follows:
( F 2 )
n = 2 and { s , t } { { w , z } , { ( 1 , 1 ) , ( 2 , 2 ) } , { ( 2 , 1 ) , ( 1 , 2 ) } } , or n 3 and { s , t } = { w , z } .
We then give some observations on the relations among cycle, path, and vertex. These propositions will be used in proving our results and are given in [12].
Proposition 1
(See [12]). Let G be a graph. Assume C 1 and C 2 are two vertex-disjoint cycles of G, P 1 and P 2 are two vertex-disjoint paths of G, C 1 and P 1 are a cycle and a path, respectively, of G with V ( C 1 ) V ( P 1 ) = , and assume x is a vertex in G V ( C 1 ) or G V ( P 1 ) . Then, 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 6a).
(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 6b).
(3)
If vertex x adjoins one edge ( u 1 , v 1 ) of C 1 (resp., P 1 ), then C 1 (resp., P 1 ) and x can be merged into a cycle (resp., path) of G (see Figure 6c).
(4)
If there exists one edge ( u 1 , v 1 ) P 1 such that u 1 s t a r t ( P 2 ) and v 1 e n d ( P 2 ) , then P 1 and P 2 can be combined into a path of G (see Figure 6d).
Next, we will discover one Hamiltonian connected property of 3-rectangle R ( m , 3 ) with m 3 that will be used in to prove our result. Let z 1 = ( m , 1 ) , z 2 = ( m , 2 ) , and z 3 = ( m , 3 ) be three vertices of R ( m , 3 ) . Assume that R ˜ = R ( m , 3 ) { z 1 , z 2 , z 3 } and edges e 12 = ( z 1 , z 2 ) , e 23 = ( z 2 , z 3 ) . Assume that s , t R ˜ . We will prove that there exists a Hamiltonian ( s , t ) -path P of R ( m , 3 ) such that e 12 , e 23 P . Before giving this property, we first give one result in [12] for 3-rectangle as follows.
Lemma 5
(See [12]). Assume R ( m , 3 ) is a 3-rectangle with m 3 and s , t being its two distinct vertices. Then, R ( m , 3 ) contains a canonical Hamiltonian ( s , t ) -path which contains at least one boundary edge of each boundary in R ( m , 3 ) .
By using the above lemma, we will prove the following lemma.
Lemma 6.
Assume R ( m , 3 ) is a 3-rectangle with m 3 and s , t being its two distinct vertices. Let z 1 = ( m , 1 ) , z 2 = ( m , 2 ) , and z 3 = ( m , 3 ) , which are the three vertices of R ( m , 3 ) , and let edges e 12 = ( z 1 , z 2 ) , e 23 = ( z 2 , z 3 ) . If { s , t } { z 1 , z 2 , z 3 } = , then there exists a Hamiltonian ( s , t ) -path of R ( m , 3 ) containing e 12 and e 23 .
Proof. 
We will prove this lemma by induction on m. Let R ˜ = R ( m , 3 ) { z 1 , z 2 , z 3 } . Then, R ˜ = R ( m 1 , 3 ) , where m 1 2 . Initially, let m = 3 . Then, R ˜ = R ( 2 , 3 ) and s , t R ˜ . By considering every case, we can construct the desired Hamiltonian ( s , t ) -path of R ( 3 , 3 ) , as shown in Figure 7a–o. Assume that the lemma holds true when m = k 3 . Consider that m = k + 1 . Then, R ˜ = R ( k , 3 ) is a subgraph of R ( k + 1 , 3 ) , where z 1 = ( k + 1 , 1 ) , z 2 = ( k + 1 , 2 ) , z 3 = ( k + 1 , 3 ) , and s , t R ˜ = R ( k , 3 ) . Let P ^ = z 1 z 2 z 3 . By Lemma 5, R ˜ contains a Hamiltonian ( s , t ) -path P ˜ such that it contains an edge e ˜ = ( u , v ) locating to face R ( k + 1 , 3 ) R ˜ . Then, s t a r t ( P ^ ) u and e n d ( P ^ ) v . By Statement (4) of Proposition 1, P ˜ and P ^ can be combined into a Hamiltonian ( s , t ) -path of R ( k + 1 , 3 ) . The construction of such a Hamiltonian path is depicted in Figure 7p. Thus, the lemma holds when m = k + 1 . By induction, the lemma holds true.    □
In addition to condition (F1) (see Figure 8a,b), in [17], we showed that H P ( L ( m , n ; k , l ) , s , t ) does not exist whenever one of the following conditions is satisfied.
( F 3 )
assume that G is a supergrid graph, there exists a vertex w G such that d e g ( w ) = 1 , w s , and w t (see Figure 8c).
( F 4 )
m k = 1 , n l = 2 , l = 1 , k 2 , and { s , t } = { ( 1 , 2 ) , ( 2 , 3 ) } or { ( 1 , 3 ) , ( 2 , 2 ) } (see Figure 8d).
Theorem 1
(See [17]). Assume that L ( m , n ; k , l ) is a L-shaped supergrid graph with vertices s and t. Then, H P ( L ( m , n ; k , l ) , s , t ) does exist if and only if ( L ( m , n ; k , l ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , and ( F 4 ) .
The following lemma shows the Hamiltonicity of L-shaped supergrid graphs.
Theorem 2
(See [17]). Assume that L ( m , n ; k , l ) is a L-shaped supergrid graph. Then, L ( m , n ; k , l ) contains a Hamiltonian cycle if and only if it does not satisfy condition ( F 5 ) , where condition ( F 5 ) is defined as follows:
( F 5 )
there exists a vertex win L ( m , n ; k , l ) such that d e g ( w ) = 1 .
Theorem 3
(See [12,17]). Assume that G is R ( m , n ) or L ( m , n ; k , l ) with two distinct vertices s and t. Then, a longest ( s , t ) -path in G can be computed in O ( m n ) -linear time.

3. The Necessary and Sufficient Conditions for the Hamiltonicity and Hamiltonian Connectivity of C-Shaped Supergrid Graphs

In this section, we will give the necessary and sufficient conditions for C-shaped supergrid graphs containing a Hamiltonian cycle and Hamiltonian ( s , t ) -path. First, we will verify the Hamiltonicity of C-shaped supergrid graphs. If m k = 1 or there exists a vertex w V ( C ( m , n ; k , l ; c , d ) ) such that d e g ( w ) = 1 , then C ( m , n ; k , l ; c , d ) contains no Hamiltonian cycle. Therefore, C ( m , n ; k , l ; c , d ) is not Hamiltonian if condition (F6) is satisfied, where condition (F6) is defined as follows:
( F 6 )
a ( = m k ) = 1 or there exists a vertex w V ( C ( m , n ; k , l ; c , d ) ) such that d e g ( w ) = 1 .
Theorem 4.
C ( m , n ; k , l ; c , d ) has a Hamiltonian cycle if and only if it does not satisfy condition  ( F 6 ) .
Proof. 
Only if part ( ) : Assume that C ( m , n ; k , l ; c , d ) satisfies condition (F6), then we will prove that it contains no Hamiltonian cycle. Let v V ( C ( m , n ; k , l ; c , d ) ) such that c + 1 v y c + l if a ( = m k ) = 1 ; otherwise v w . It is obvious that any cycle in C ( m , n ; k , l ; c , d ) must pass through v twice. Therefore, C ( m , n ; k , l ; c , d ) contains no Hamiltonian cycle.
If part ( ) : We will prove this statement by constructing a Hamiltonian cycle of C ( m , n ; k , l ; c , d ) . There are two cases:
Case 1: c = 1 and d = 1 . If k > 1 , then there exists a vertex w V ( C ( m , n ; k , l ; c , d ) ) such that d e g ( w ) = 1 . Thus, k = 1 . We make vertical and horizontal separations on C ( m , n ; k , l ; c , d ) to obtain three disjoint rectangular supergrid subgraphs R 1 = R ( a , n ) , R 2 = R ( k , c ) , and R 3 = R ( k , d ) , as depicted in Figure 9a. Assume that v V ( R 2 ) and u V ( R 3 ) . By Lemma 1, R 1 contains a canonical Hamiltonian cycle H C 1 (see Figure 9b). We can place one flat face of H C 1 to face R 2 and R 3 . Thus, there exists an edge ( w , z ) H C 1 such that v w and v z . By Statement (3) of Proposition 1, v and H C 1 can be combined into a cycle H C 2 . By the same argument, u can be merged into the cycle H C 2 to form a Hamiltonian cycle of C ( m , n ; k , l ; c , d ) , as shown in Figure 9c.
Case 2: c 2 or d 2 . By symmetry, assume that d 2 . We make a horizontal separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 1 = L ( m , c + l ; k , l ) and R 2 = R ( m , d ) , as depicted in Figure 9d,e, where Figure 9d,e respectively, indicate the case of c = 1 and c 2 . By Theorem 2 (resp. Lemma 1), R 1 (resp. R 2 ) contains a Hamiltonian (resp. canonical Hamiltonian) cycle H C 1 (resp. H C 2 ) such that its one flat face is placed to face R 2 (resp. R 1 ). Then, there exist two edges e 1 = ( u 1 , u 2 ) H C 1 and e 2 = ( v 1 , v 2 ) H C 2 such that e 1 e 2 ; as shown in Figure 10a,b. By Statement (1) of Proposition 1, H C 1 and H C 2 can be combined into a Hamiltonian cycle of C ( m , n ; k , l ; c , d ) , as shown in Figure 10c,d.    □
Now, we give the necessary and sufficient conditions for the existence of a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) . In addition to condition (F1) (as depicted in Figure 11a,b) and (F3) (as depicted in Figure 11c), if ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies one of the following conditions, then it contains no Hamiltonian ( s , t ) -path.
( F 7 )
m = 3 , a ( = m k ) = 2 , and [ ( 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 11d).
( F 8 )
n = 3 , k = c = d = 1 , and
(1)
a 2 , s x = t x = m 1 , and | s y t y | = 2 (see Figure 11e); or
(2)
a = 2 , s x = 1 , t x = 2 , and | s y t y | = 2 (see Figure 11f); or
(3)
a > 2 , s x < m 1 , and t = ( m 1 , 2 ) (see Figure 11g).
( F 9 )
a ( = m k ) = 1 , and ( s y , t y c or s y , t y > c + l ) (see Figure 11h).
Lemma 7.
If H P ( C ( m , n ; k , l ; c , d ) , s , t ) exists, then ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , ( F 7 ) , ( F 8 ) , and ( F 9 ) .
Proof. 
Assume that ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies one of the conditions (F1), (F3), (F7), (F8), and (F9), then we show that H P ( C ( m , n ; k , l ; c , d ) , s , t ) does not exist. For conditions (F1) and (F3), it is clear (see Figure 11a–c). For condition (F7), by inspecting all cases of Figure 11d there exists no Hamiltonian ( s , t ) -path. For cases (1)–(2) of condition (F8), consider Figure 11e,f. Let v be a vertex depicted in these figures. Since { s , t , v } is a vertex cut of C ( m , n ; k , l ; c , d ) , then C ( m , n ; k , l ; c , d ) { s , t , v } is disconnected and contains three (or two) components in which two components (or one component) consist of only one vertex. Hence, any path between s and t must pass through s or v twice. Therefore, C ( m , n ; k , l ; c , d ) contains no Hamiltonian ( s , t ) -path. For case (3) of condition (F8), consider Figure 11g. A simple check shows that there is no Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) containing both of vertices u and v. For condition (F9), consider Figure 11h. Let v V ( C ( m , n ; k , l ; c , d ) such that v x = 1 and c + 1 v y c + l . Since a = 1 , v is a cut vertex of C ( m , n ; k , l ; c , d ) . Obviously, any path between s and t must pass through v two times. Therefore, C ( m , n ; k , l ; c , d ) contains no Hamiltonian ( s , t ) -path.    □
In the following, we will show that C ( m , n ; k , l ; c , d ) has a Hamiltonian ( s , t ) -path when ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions (F1), (F3), (F7), (F8), and (F9). We consider the case of a = 1 in Lemma 8 and the case of a 2 in Lemmas 9 and 10.
Lemma 8.
Assume that a ( = m k ) = 1 and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , and ( F 9 ) . Then H P ( C ( m , n ; k , l ; c , d ) , s , t ) does exist.
Proof. 
Notice that, here, ( s y c and t y > c + l ) or ( t y c and s y > c + l ) . If s y , t y c , s y , t y > c + l , or c + 1 s y ( or t y ) c + l , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1) or (F9). Without loss of generality, assume that s y c and t y > c + l . We make a horizontal separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint subgraphs R 1 = R ( m , c ) , R 2 = L ( m , n c ; k , l ) . Let p V ( R 1 ) and q V ( R 2 ) such that p q , q = ( 1 , c + 1 ) , and p = ( 1 , c ) if s ( 1 , c ) ; otherwise p = ( 2 , c ) (see Figure 12a). Consider ( R 1 , s , p ) . Condition (F1) holds, if
(i)
c = 1 , k > 1 , and s x m . Clearly, if this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1), a contradiction.
(ii)
c = 2 and s x = p x 2 . Clearly, in this case, s x = p x = 2 . It contradicts that p = ( 1 , c ) when s ( 1 , c ) .
Therefore, ( R 1 , s , p ) does not satisfy condition (F1). Now, consider ( R 2 , q , t ) . Since q y = c + 1 and t y > c + l , it is enough to show that ( R 2 , q , t ) does not satisfy condition (F1). Condition (F1) holds, if d = 1 , k > 1 , and t x m . Clearly, if this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1), a contradiction. Therefore, ( R 2 , q , t ) does not satisfy conditions (F1), (F3), and (F4). Since ( R 1 , s , p ) and ( R 2 , q , t ) do not satisfy conditions (F1), (F3), and (F4), by Lemma 3 and Theorem 1, there exist Hamiltonian ( s , p ) -path P 1 and Hamiltonian ( q , t ) -path P 2 of R 1 and R 2 , respectively (see Figure 12b). Then, P = P 1 P 2 forms a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) , as depicted in Figure 12c. □
Lemma 9.
Assume c = d = 1 , a ( = m k ) > 1 , and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , ( F 7 ) , and ( F 8 ) . Then H P ( C ( m , n ; k , l ; c , d ) , s , t ) does exist.
Proof. 
Depending on whether n = 3 , we consider the following cases:
Case 1: n = 3 . Notice that, here, if k > 1 , then s x = t x = m . If k > 1 and s x m and t x m , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies (F1) or (F3). Consider the positions of s and t, as there are the following two subcases:
  Case 1.1: s x > a or t x > a . Without loss of generality, assume that t x > a and t y = 1 . We make a vertical and a horizontal separations on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 2 = R ( k , c ) and R 1 = L ( m , n ; k , c + l ) , as depicted in Figure 13a–c. 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 ) (see Figure 13a–c). Here, if | V ( R 2 ) | = 1 (i.e., k = 1 ) , then q = t . Consider ( R 1 , s , p ) . Condition (F1) holds, if a = 2 and s y = p y 2 , or p = ( a , 2 ) and s = ( a , 3 ) . Clearly, in any case, it contradicts that p = ( a , 1 ) when s ( a , 1 ) . Condition (F3) holds, if k > 1 and s x a . If this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F3), a contradiction. Condition (F4) holds, if n = 3 , a = 2 , k = 1 , s = ( 1 , n ) , and p = ( a , 2 ) . It contradicts that p = ( a , 1 ) when s ( a , 1 ) . Thus, ( R 1 , s , p ) does not satisfy conditions (F1), (F3), and (F4). Now, consider ( R 2 , q , t ) . Since q = ( a + 1 , 1 ) and t = ( m , 1 ) , clearly ( R 2 , q , t ) does not satisfy condition (F1). A Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Lemma 8, as shown in Figure 13d.
  Case 1.2: s x , t x a . In this subcase, k = 1 and hence a = m 1 . If k > 1 , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies (F3). Since ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy condition (F8), s x m 1 . There are two subcases:
    Case 1.2.1: s x , t x < m 1 . Let z 1 = ( m 1 , 1 ) , z 2 = ( m 1 , 2 ) , and z 3 = ( m 1 , 3 ) . Let e 1 = ( z 1 , z 2 ) and e 2 = ( z 2 , z 3 ) . We make a vertical and horizontal separations on C ( m , n ; k , l ; c , d ) to obtain three disjoint rectangular supergrid subgraphs R 1 = R ( a , n ) , R 2 = R ( k , c ) , and R 3 = R ( k , d ) ; as depicted in Figure 14a. Assume that v V ( R 2 ) and u V ( R 3 ) . By Lemma 6, where a > 2 , or Lemma 3, where a = 2 , R 1 contains a Hamiltonian ( s , t ) -path P 1 such that e 1 , e 2 P 1 (see Figure 14b). Then, P 1 , u, v can be combined into a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) by Statement (3) of Proposition 1 (see Figure 14c).
    Case 1.2.2: s x < m 1 and t x = m 1 . Since ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions (F1), (F7), and (F8), we have that (1) t = ( m 1 , 1 ) or t = ( m 1 , 3 ) if m 1 > 2 , and (2) s y = t y = 1 or s y = t y = 3 if m 1 = 2 . Thus, t y = 1 or t y = 3 . By symmetry, assume that t = ( m 1 , 1 ) . We make a vertical separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 1 = R ( m 2 , n ) and R 2 = C ( 2 , n ; k , l ; c , d ) , as depicted in Figure 14d,e. Let q V ( R 2 ) and p V ( R 1 ) such that p q , q = ( m 1 , 3 ) , and p = ( m 2 , 3 ) if s ( m 2 , 3 ) ; otherwise p = ( m 2 , 2 ) (see Figure 14d,e).
Notice that, here, if s = ( m 2 , 3 ) , then m 4 . If m = 3 and s = ( m 2 , 3 ) , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F8). Consider ( R 2 , q , t ) . Since a = d = c = 1 , t = ( m 1 , 1 ) , and q = ( m 1 , 3 ) , clearly ( R 2 , q , t ) does not satisfy conditions (F1), (F3), and (F9). Here, ( R 2 , q , t ) lies on Lemma 8. Now, consider ( R 1 , s , p ) . Condition (F1) holds, if
(i)
m 2 = 1 and s = ( m 2 , 2 ) . In this case, ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F7), a contradiction.
(ii)
m 2 = 2 and s y = p y = 2 . Clearly if s y = 2 , then p y = 3 . Hence, s y p y .
Therefore, ( R 1 , s , p ) does not satisfy condition (F1). By Lemmas 3 and 8, R 1 and R 2 contain Hamiltonian ( s , p ) -path P 1 and ( q , p ) -path P 2 , respectively. Then, P = P 1 P 2 forms a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) , as depicted in Figure 14f.
Case 2: n > 3 . Since n > 3 and c = d = 1 , it follows that l > 1 . We make a horizontal separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 1 = L ( m , n n 2 ; k , l 1 ) and R 2 = L ( n 2 , m ; l 2 , k ) , where n 2 = c + l 1 , l 1 = c + l n 2 , and l 2 = l l 1 (see Figure 15a–c). Since n 2 = c + l 1 and d = 1 , clearly n n 2 = 2 . Also since n n 2 = 2 and n > 3 , it follows that n 2 2 . Depending on the positions of s and t, there are the following two subcases:
  Case 2.1: s , t R 1 or s , t R 2 . Without loss of generality, assume that s , t R 2 . Here, k = 1 . If k > 1 , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F3).
    Case 2.1.1: ( n 2 > 2 ) or ( n 2 = 2 and [ ( s x t x ) or ( s x = t x = 1 ) ] ) . Since k = 1 , it is enough to show that ( R 2 , s , t ) does not satisfy conditions (F1) and (F4). Condition (F1) holds, if
(i)
2 s x = t x a . By assumption, this case does not occur.
(ii)
a = 2 and 2 s y = t y n 2 . Clearly if this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1), a contradiction.
Condition (F4) holds, if a = 2 , n 2 > 2 , s x , t x 2 , s y , t y 2 , s x t x , and s y t y . Clearly, if this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F7), a contradiction. Therefore, ( R 2 , s , t ) does not satisfy conditions (F1), (F3), and (F4). Since ( R 2 , s , t ) does not satisfy conditions (F1), (F3), and (F4). By Theorem 1, R 2 contains a Hamiltonian ( s , t ) -path P 2 in which one edge e 2 is placed to face R 1 . By Theorem 2, R 1 contains a Hamiltonian cycle H C 1 such that its one flat face is placed to face R 2 . Then, there exist two edges e 1 H C 1 and e 2 P 2 such that e 1 e 2 (see Figure 15d). By Statement (2) of Proposition 1, P 2 and H C 1 can be combined into a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) . The construction of a such Hamiltonian path is depicted in Figure 15e.
    Case 2.1.2: n 2 = 2 and s x , t x > 1 . In this case, n = 4 , a > 2 , l = 2 , and 2 s x = t x a 1 . If s x = t x = a , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1). Depending on whether a = 3 , we consider the following two subcases:
      Case 2.1.2.1: a = 3 . In this subcase, we can construct a Hamiltonian ( s , t ) -path by the pattern shown in Figure 16a. Consider Figure 16a. Since w = ( 1 , 3 ) and z = ( 3 , 3 ) , clearly ( R 1 , w , z ) does not satisfy conditions (F1), (F3), and (F4). Thus by Theorem 1, R 1 contains a Hamiltonian ( w , z ) -path P 1 . For ( R 2 , s , t ) , we can construct two paths P 21 and P 22 such that P 21 connects s and p, P 22 connects q and t, V ( P 21 ) V ( P 22 ) = , V ( P 21 P 22 ) = V ( R 2 ) , p w , and q z , as shown in Figure 16a. Then, P = P 21 P 1 P 22 forms a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) (see Figure 16a).
      Case 2.1.2.2: a > 3 . We make a vertical separation on R 2 to obtain two disjoint subgraphs R 21 = R ( m , n 2 ) and R 22 = L ( n 2 , m m ; 1 , 1 ) , where m = s x if s x < a 1 ; otherwise m = s x 1 ; as shown in Figure 16b,c. First, let s , t R 21 and consider Figure 16b. Clearly since s x = t x = m , ( R 21 , s , t ) does not satisfy condition (F1). By Lemma 3, R 21 contains a canonical Hamiltonian ( s , t ) -path P 21 . Then, there exists one edge e 21 P 21 that is placed to face R 1 . By Theorem 2, R 22 and R 1 contain Hamiltonian cycle H C 22 and H C 1 , respectively. Using the algorithm of [17], we can construct H C 22 and H C 1 to satisfy that one flat face of H C 1 , which is placed to face R 21 and R 22 , and one flat face of H C 22 , which is placed to face R 1 (see Figure 16d). Then, there exist four edges e 1 , e 2 H C 1 , e 21 P 21 , and e 22 H C 22 such that e 1 e 21 and e 2 e 22 . By Statements (1) and (2) of Proposition 1, P 21 , H C 1 , and H C 22 can be combined into a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) . The construction of a such Hamiltonian path is depicted in Figure 16e. Now, let s , t R 22 and consider Figure 16c. Since s x = t x = 1 and s x , t x < a (in R 22 ), it is clear that ( R 22 , s , t ) does not satisfy conditions (F1), (F3), and (F4). By similar arguments in proving s , t R 21 , a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) can be constructed (see Figure 16f).
  Case 2.2: ( s R 1 and t R 2 ) or ( t R 1 and s R 2 ). Without loss of generality, assume that t R 1 and s R 2 . Let q V ( R 1 ) and p V ( R 2 ) such that p q , where
p = ( 1 , n 2 ) and q = ( 1 , n 2 + 1 ) , if s ( 1 , n 2 ) and t ( 1 , n 2 + 1 ) ; p = ( 2 , n 2 ) and q = ( 2 , n 2 + 1 ) , if s = ( 1 , n 2 ) and t = ( 1 , n 2 + 1 ) ; p = ( 2 , n 2 ) and q = ( 1 , n 2 + 1 ) , if s = ( 1 , n 2 ) and t ( 1 , n 2 + 1 ) ; p = ( 1 , n 2 ) and q = ( 2 , n 2 + 1 ) , otherwise .
Consider ( R 2 , s , p ) and ( R 1 , q , t ) . Condition (F1) holds, if
(i)
( n 2 = 2 and s x = p x = 2 ) or ( n n 2 = 2 and q x = t x = 2 ) . Obviously in this case, s x = p x = 2 and q x = t x = 2 . It contradicts that p x = q x = 1 when s x 1 and t x 1 .
(ii)
k > 1 and a < s x , t x < m . If this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1), a contradiction.
Condition (F3) holds, if k > 1 and s x , t x a . If this case holds, then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F3), a contradiction. Condition (F4) holds, if a = 2 and [ ( n 2 > 2 and s y , p y 2 ) or ( n n 2 > 2 and q y , t y n 1 ) ] . A simple check shows that these cases do not occur. Therefore, ( R 2 , s , p ) and ( R 1 , q , t ) do not satisfy conditions (F1), (F3), and (F4). A Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Lemma 8. Notice that, here, R 1 and R 2 are L-shaped supergrid graphs.    □
Lemma 10.
Assume a ( = m k ) > 1 , ( c > 1 or d > 1 ) , and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , ( F 7 ) , and ( F 8 ) . Then H P ( C ( m , n ; k , l ; c , d ) , s , t ) does exist.
Proof. 
Without loss of generality, assume that d > 1 . Since d > 1 , c 1 , and l 1 , thus n 4 . We make a horizontal separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 2 = L ( n 2 , m ; l , k ) and R 1 = R ( m , n n 2 ) , where n 2 = c + l and n n 2 = d (see Figure 17a,b). Since n 4 , n 2 = c + l , c , l 1 , and d > 1 , it follows that n n 2 , n 2 2 . Depending on the positions of s and t, there are the following three subcases:
Case 1: s , t R 1 . In this case, ( c > 1 ) or ( c = 1 and k = 1 ). If c = 1 and k > 1 , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F3), a contradiction. Depending on the size of n n 2 , we consider the following two subcases:
  Case 1.1: ( n n 2 > 2 ) or ( n n 2 = 2 and [ ( s x t x ) , ( s x = t x = 1 ) , or ( s x = t x = m ) ] ). In this subcase, { s , t } is not a vertex cut of R 1 . Then, ( R 1 , s , t ) does not satisfy condition (F1). By Lemma 3, R 1 contains a canonical Hamiltonian ( s , t ) -path P 1 . Using the algorithm of [12], we can construct a Hamiltonian ( s , t ) -path P 1 of R 1 in which one edge e 1 is placed to face R 2 . By Theorem 2, R 2 contains a Hamiltonian cycle H C 2 . Using the algorithm of [17], we can construct H C 2 such that its one flat face is placed to face R 1 . Then, there exist two edges e 1 P 1 and e 2 H C 2 such that e 1 e 2 (see Figure 17c). By Statement (2) of Proposition 1, P 1 and H C 2 can be combined into a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) . The construction of a such Hamiltonian path is depicted in Figure 17d.
  Case 1.2: n n 2 = 2 and 1 < s x = t x < m . In this subcase, { s , t } is a vertex cut of R 1 . Notice that, here, s x , t x a . If s x , t x > a and k > 1 , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1). Without loss of generality, assume that s y < t y . We make a vertical and a horizontal separations on R 1 to obtain two disjoint supergrid subgraphs R 11 = L ( s x , n n 2 ; 1 , 1 ) and R 12 = R 1 R 11 . Let p V ( R 12 ) , q V ( R 11 ) , and w , z V ( R 2 ) such that p z , q w , q = ( 1 , n 2 + 1 ) , w = ( 1 , n 2 ) , p = ( s x + 1 , n 2 + 1 ) , and z = ( s x , n 2 ) (see Figure 18a,b). A simple check shows that ( R 12 , s , p ) , ( R 2 , z , w ) , and ( R 11 , q , t ) do not satisfy conditions (F1), (F3), and (F4). Thus, by Theorem 1, R 12 , R 2 , and R 11 contain a Hamiltonian ( s , p ) -path P 12 , Hamiltonian ( z , w ) -path P 2 , and Hamiltonian ( q , t ) -path P 11 , respectively. Then, P = P 12 P 2 P 11 forms a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) . The construction of a such Hamiltonian path is depicted in Figure 18c.
Case 2: s , t R 2 . A Hamiltonian ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Case 2.1 of Lemma 9. Notice that, in this case, R 1 is a rectangular supergrid graph.
Case 3: ( s R 1 and t R 2 ) or ( s R 2 and t R 1 ). A Hamiltonian ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Case 2.2 of Lemma 9. Notice that, in this case, R 1 is a rectangular supergrid graphs.    □
It immediately follows from Lemmas 7–10 that the following theorem holds true.
Theorem 5.
H P ( C ( m , n ; k , l ; c , d ) , s , t ) does exist if and only if ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions ( F 1 ) , ( F 3 ) , ( F 7 ) , ( F 8 ) , and ( F 9 ) .

4. The Longest ( s , t ) -Paths in C -Shaped Supergrid Graphs

In this section, first for the cases where H P ( C ( m , n ; k , l ; c , d ) , s , t ) does not exist, we give the upper bounds on the lengths of the longest paths between s and t. Then, we show that these upper bounds are equal to the lengths of the longest path between s and t. Notice that the isomorphic cases are omitted. In the following, we use L ^ ( G , s , t ) to denote the length of the longest ( s , t ) -paths and U ^ ( G , s , t ) to indicate the upper bound on the length of the longest ( s , t ) -paths, where G is a rectangular, L-shaped, or C-shaped supergrid graph. By the length of a path we mean the number of vertices visited by the path. These upper bounds are given in Lemmas 11–13.
We first consider the case of a = 1 , where a = m k . In this case, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F1), (F3), or (F9). We compute the upper bound of the longest ( s , t ) -path in this case as the following lemma.
Lemma 11.
Let a = 1 and w = ( 1 , c + 1 ) . Assume that C ( m , n ; k , l ; c , d ) , s , t ) satisfies one of the conditions ( F 1 ) , ( F 3 ) , and ( F 9 ) . Then, the following conditions hold:
( UB 1 )
If s y , t y > c (resp., s y , t y c ), then the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) , where G 1 = L ( m , n c ; k , l ) (resp., G 1 = L ( c + 1 , m ; 1 , k ) ) (see Figure 19a,b).
( UB 2 )
If ( s y c and t y > c ) or ( t y c and s y > c ) , without loss of generality assume that s y c , then the length of any ( s , t ) -path cannot exceed L ^ ( G 2 , s , z ) + L ^ ( G 1 , w , t ) , where G 2 = R ( m , c ) , G 1 = L ( m , n c ; k , l ) , and z = ( 1 , c ) if s ( 1 , c ) ; otherwise z = ( 2 , c ) (see Figure 19c,d).
Proof. 
The proof is straightforward, see Figure 19.    □
Next, we consider the case of a 2 . In this case, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F1), (F3), (F7), or (F8). Depending on the sizes of c and d, we consider the subcases of (1) c , d 2 and (2) c = 1 or d = 1 . Consider that c , d 2 . Then, ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy conditions (F3), (F7), and (F8). Thus, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy condition (F1) only. We can see that s or t is not a cut vertex when a , c , d 2 . Thus, { s , t } is a vertex cut when ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1). We can see from the structure of C ( m , n ; k , l ; c , d ) that a, c, or d is equal to 2 if { s , t } is a vertex cut. The following lemma shows the upper bound of the longest ( s , t ) -path under that a , c , d 2 and ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F1).
Lemma 12.
Assume that a , c , d 2 and { s , t } is a vertex cut. Then, the following conditions hold:
( UB 3 )
If a = 2 and c + 1 s y = t y c + l , then the length of any ( s , t ) -path cannot exceed max { L ^ ( G 11 , s , t ) , L ^ ( G 12 , s , t ) } , where G 11 = L ( m , n ; k , l ) , G 12 = L ( s y , m ; k , k ) , n = n s y + 1 , l = n d , and k = s y 1 (see Figure 20a,b).
( UB 4 )
If k 2 , a + 1 s x , t x a + k 1 ( = m 1 ) , and [ ( c = 2 and s y , t y c ) or ( d = 2 , and s y , t y c + l ) ] , without loss of generality assume that d = 2 and s y , t y c + l , then the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) + | V ( G 2 ) | = L ^ ( G 1 , s , t ) + k × c , where G 1 = L ( m , n ; k , l + c ) and G 2 = R ( k , c ) (see Figure 20c,d).
Proof. 
Consider Figure 20a,b. Removing s and t clearly disconnects C ( m , n ; k , l ; c , d ) into two components G 1 and G 2 . Thus, a simple path between s and t can only go through one of these components. Therefore, its length cannot exceed the size of the largest component. Notice that, for (UB4), the length of any path between s and t is equal to max { L ^ ( G 1 , s , t ) + | V ( G 2 ) | , 2 × ( m s x + 1 ) } (see Figure 20c,d). Since a , c > 1 , it is obvious that the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) + | V ( G 2 ) | = L ^ ( G 1 , s , t ) + k × c .    □
In the following, we will consider that a 2 , and ( c = 1 or d = 1 ). Without loss of generality, assume that c = 1 . We first make a horizontal and a vertical separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint subgraphs G 1 = L ( m , n ; k , l + c ) and G 2 = R ( m a , c ) , as depicted in Figure 21a, where a 2 , c = 1 , and G 2 is a path graph. Depending the locations of s and t, we consider the following cases:
Case I: s , t G 2 . In this case, k > 1 , s y = t y = 1 , and a + 1 s x , t x m . Then, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F1) or (F3), as depicted in Figure 21b.
Case II: s G 1 and t G 2 . In this case, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F1) or (F3), as depicted in Figure 21c.
Case III: s , t G 1 . In this case, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F1), (F3), (F7), or (F8), as depicted in Figure 21d. If d = 1 , s y = t y = n , and a + 1 s x , t x m , then it is the same as Case I. Depending on whether ( G 1 , s , t ) satisfies condition (F1), there are the following three subcases:
  Case III.1: s or t is a cut vertex of G 1 . In this subcase, d = 1 , and it is the same as Cases I or II.
  Case III.2: { s , t } is a vertex cut of G 1 . Consider the following subcases:
    Case III.2.1: { s , t } = { ( a , 1 ) , ( a , 2 ) } . In this subcase, k = 1 or k > 1 , as shown in Figure 22a,b. If k > 1 , then ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies conditions (F1) and (F3); otherwise it satisfies condition (F1).
    Case III.2.2: a = 2 , s y = t y , and c + 1 s x , t x c + l . In this subcase, it is similar to condition (UB3) in Lemma 12 (see Figure 22c).
    Case III.2.3: d = 2 , k > 1 , a < s x = t x < m , and n 1 s y , t y n . In this subcase, it is similar to condition (UB4) in Lemma 12 (see Figure 22d).
  Case III.3: ( G 1 , s , t ) does not satisfy condition (F1). In this subcase, s and t are not cut vertices and { s , t } is not a vertex cut of G 1 . Then, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F3), (F7), or (F8). Depending on the size of k, we consider the following subcases:
    Case III.3.1: k = 1 . In this subcase, ( C ( m , n ; k , l ; c , d ) , s , t ) may satisfy conditions (F7) and (F8), as follows:
      Case III.3.1.1: ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F7). In this subcase, a = 2 and [ ( 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 23a).
      Case III.3.1.2: ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F8). In this subcase, n = 3 and k = c = d = 1 (see Figure 23c–e).
    Case III.3.2: k > 1 . In this subcase, ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F3) but it does not satisfy condition (F1). There are the following subcases:
      Case III.3.2.1: a = 2 and [ ( 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 ) } ) ] . In this subcase, it is the same as Case III.3.1.1 (see Figure 23b).
      Case III.3.2.2: ( c = 1 and { s , t } { ( 1 , 1 ) , ( 2 , 2 ) } and { ( 1 , 2 ) , ( 2 , 1 ) } ) or ( d = 1 and { s , t } { ( 1 , n ) , ( 2 , n 1 ) } and { ( 1 , n 1 ) , ( 2 , n ) } ) (see Figure 23e,f).
Based on the above cases, we compute the upper bounds of the longest ( s , t ) -paths on ( C ( m , n ; k , l ; c , d ) , s , t ) under that a 2 and c = 1 as the following lemma.
Lemma 13.
Assume that a 2 and c = 1 . Let w = ( a + 1 , 1 ) . Then, the following conditions hold:
( UB 5 )
If k > 1 , a + 1 s x , t x m , and ( s y = t y = 1 or s y = t y = n ), then the length of any ( s , t ) -path cannot exceed t x s x + 1 (see Figure 24a,b, and refer to Case I and Case III.1).
( UB 6 )
If t x > 1 , t y = 1 , and [ ( s x a ) or ( s x > a and s y > c + l ) ] , then the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , z ) + L ^ ( G 2 , w , t ) , where G 1 = L ( m , n ; k , l + c ) , G 2 = R ( k , c ) , and z = ( a , 1 ) if s ( a , 1 ) ; otherwise z = ( a , 2 ) (see Figure 24c,d, and refer to Cases II and III.1).
( UB 7 )
If { s , t } = { ( a , 1 ) , ( a , 2 ) } (resp., d = 1 and { s , t } = { ( a , n 1 ) , ( a , n ) } ), then the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) , where G 1 = L ( m , n ; k , l + c ) (resp., G 1 = L ( n , m ; l + d , k ) ) (see Figure 25a,b, and refer to Case III.2.1).
( UB 8 )
If a = 2 , s y = t y , and c + 1 s y , t y c + l , then the length of any ( s , t ) -path cannot exceed max { L ^ ( G 11 , s , t ) , L ^ ( G 12 , s , t ) } , where G 11 = L ( m , n ; k , l ) , G 12 = L ( s y , m ; k , k ) , n = n s y + 1 , l = n d , and k = s y 1 (see Figure 25c,d, and refer to Case SIII.2.2).
( UB 9 )
If d = 2 , k > 1 , a < s x = t x < m , and n 1 s y , t y n , then the length of any ( s , t ) -path cannot exceed max { L ^ ( G 11 , s , t ) , L ^ ( G 12 , s , t ) } , where G 11 = C ( m , n ; k , l ; c , d ) , G 12 = R ( m m + 1 , d ) , m = s x , and k = m a (see Figure 25e,f, and refer to Case III.2.3).
( UB 10 )
If a = 2 and ( { s , t } = { ( 1 , 1 ) , ( 2 , 2 ) } or { ( 1 , 2 ) , ( 2 , 1 ) } ) (resp., d = 1 and { s , t } = { ( 1 , n ) , ( 2 , n 1 ) } or { ( 1 , n 1 ) , ( 2 , n ) } ), then the length of ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) , where G 1 = L ( m , n ; k , l + c ) (resp., G 1 = L ( n , m ; l + d , k ) ) (see Figure 26a–c, and refer to Case III.3.1.1 and Case III.3.2.1).
( UB 11 )
If ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F8), then the length of ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) , where G 1 = L ( m , n ; k , l + c ) (see Figure 26d–f, and refer to Case III.3.1.2).
( UB 12 )
If ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy condition (F1), k > 1 , and [ ( a > 2 ) or ( a = 2 , { s , t } { ( 1 , 1 ) , ( 2 , 2 ) } and { ( 1 , 2 ) , ( 2 , 1 ) } ) ] (resp., d = 1 and { s , t } { ( 1 , n ) , ( 2 , n 1 ) } and { ( 1 , n 1 ) , ( 2 , n ) } ), then the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , t ) + 1 , where G 1 = L ( m , n ; k , l + c ) (resp., G 1 = L ( n , m ; l + d , k ) ) (see Figure 26g,h, and refer to Case III.3.2.2).
Proof. 
For (UB5), consider Figure 24a,b. There is only one single path between s and t that has the specified. For (UB6), consider Figure 24c,d. Since c = 1 and w is a cut vertex, it is clear that the length of any ( s , t ) -path cannot exceed L ^ ( G 1 , s , z ) + L ^ ( G 2 , w , t ) .
For (UB7), consider Figure 25a,b. In Figure 25a,b, { s , t } is a vertex cut and hence removing s and t clearly disconnects C ( m , n ; k , l ; c , d ) into two components. Thus, a simple path between s and t can only go through one of these components. Therefore, its length cannot exceed the size of the largest component. Since c = 1 , the larger component will be G 1 = L ( m , n ; k , l + c ) . For (UB8) and (UB9), consider Figure 25c–f. The computations of their upper bounds are the same as (UB7), and (UB3) in Lemma 12.
For (UB10), consider Figure 26a–c. A simple check shows that the length of any ( s , t ) -path cannot exceed L ^ ( G a , s , p ) + L ^ ( G b , q , t ) = L ^ ( L ( m , n ; k , l + c ) , s , t ) , where G a , G b , p, q are defined in Figure 26a–c. For (UB11), consider Figure 26d–f. In Figure 26d–f, let r = ( a , 1 ) and z = ( a , 2 ) , where r , z may be one of s and t. Removing r and z clearly disconnects C ( m , n ; k , l ; c , d ) into two components and a simple path between s and t can only go through a component that contains s, t, r, and z. Since the one disjoint component contains only one vertex, the upper bound of the longest ( s , t ) -path will be L ^ ( L ( m , n ; k , l + c ) , s , t ) . For (UB12), consider Figure 26g,h. Since w is a cut vertex, we can easily show that the length of any path between s and t cannot exceed L ^ ( G 1 , s , t ) + 1 , where G 1 = L ( m , n ; k , l + c ) or L ( n , m ; l + d , k ) .    □
Assume that condition (C0) is defined as follows:
( C 0 )
( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy any of conditions (F1), (F3), (F7), (F8), and (F9).
Clearly ( C ( m , n ; k , l ; c , d ) , s , t ) must satisfy one of conditions (C0), (UB1), (UB2), (UB3), (UB4), (UB5), (UB6), (UB7), (UB8), (UB9), (UB10), (UB11), and (UB12). If ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies (C0), then U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = | V ( C ( m , n ; k , l ; c , d ) ) | = m n k l . Otherwise, U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) can be computed using Lemmas 11–13. We summarize them as follows:
U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = L ^ ( G 1 , s , t ) , if ( UB 1 ) , ( UB 7 ) , ( UB 10 ) , or ( UB 11 ) holds ; L ^ ( G 1 , s , z ) + L ^ ( G 2 , w , t ) , if ( UB 2 ) or ( UB 6 ) holds ; max { L ^ ( G 11 , s , t ) , L ^ ( G 12 , s , t ) } , if ( UB 3 ) , ( UB 8 ) , or ( UB 9 ) holds ; L ^ ( G 1 , s , t ) + k × c , if ( UB 4 ) holds ; t x s x + 1 , if ( UB 5 ) holds ; L ^ ( G 1 , s , t ) + 1 , if ( UB 12 ) holds ; m n k l , if ( C 0 ) holds .
In the following, we will show how to obtain a longest ( s , t ) -path for C-shaped supergrid graphs. Notice that if ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (C0), then, by Theorem 5, it contains a Hamiltonian ( s , t ) -path.
Lemma 14.
If ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies one of the conditions ( UB 1 ) ( UB 12 ) , then L ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) .
Proof. 
We prove this lemma by constructing a ( s , t ) -path P such that its length equals to U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) . Consider the following cases:
Case 1: Condition (UB1), (UB7), (UB10), or (UB11) holds. Then, by Lemma 11 (resp. Lemma 13), U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = L ^ ( G 1 , s , t ) , where G 1 = L ( m , n c ; k , l ) or G 1 = L ( c + 1 , m ; 1 , k ) (resp. G 1 = L ( m , n ; k , l + c ) or G 1 = L ( n , m ; l + d , k ) ) (see Figure 19a,b, Figure 25a,b and Figure 26a–f). Since G 1 is a L-shaped supergrid graph, by the algorithm of [17], we can construct a longest ( s , t ) -path in G 1 .
Case 2: Condition (UB2) or (UB6) holds. By Lemma 11 (resp. Lemma 13), U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = L ^ ( G 1 , s , z ) + L ^ ( G 2 , w , t ) (see Figure 19c,d and Figure 24c,d), where G 1 = L ( m , n c ; k , l ) , G 2 = R ( m , c ) (resp. G 1 = L ( m , n ; k , l + c ) and G 2 = R ( k , c ) ), and z w . Then, G 1 and G 2 are L-shaped and rectangular supergrid graphs, respectively. First, by the algorithms [12,17], we can construct a longest ( s , z ) -path P 2 (resp. P 1 ) in G 2 (resp. G 1 ) and a longest ( w , t ) -path P 1 (resp. P 2 ) in G 1 (resp. G 2 ), respectively. Then, P = P 2 P 1 (resp. P 1 P 2 ) forms a longest ( s , t ) -path of C ( m , n ; k , l ; c , d ) . Figure 19c,d and Figure 24c,d show the constructions of such a longest ( s , t ) -path.
Case 3: Conditions (UB3), (UB8), or (UB9) hold. Assume that (UB3) holds. By Lemma 12, U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = max { L ^ ( G 11 , s , t ) , L ^ ( G 12 , s , t ) } , where G 11 = L ( m , n ; k , l ) , G 12 = L ( s y , m ; k , k ) , n = n s y + 1 , l = n d , and k = s y 1 (see Figure 20a,b). Since G 11 and G 12 are L-shaped supergrid graphs, by the algorithm of [17] we can construct a longest path between s and t in G 11 and G 12 . Figure 20a,b depicts such a construction. For conditions (UB8) and (UB9), consider Figure 25c–f. Then, G 12 may be a rectangle. By the algorithm of [12] we can construct a longest ( s , t ) -path in G 12 if it is a rectangle. In addition, G 11 is a C-shaped supergrid graph in (UB9) (see Figure 25e). Then, ( G 11 , s , t ) satisfies condition (UB12). Its longest ( s , t ) -path can be computed by the algorithm in [17]. Its construction is shown in Case 6 and Figure 25e shows such a construction of the longest ( s , t ) -path.
Case 4: Condition (UB4) holds. By Lemma 12, U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = L ^ ( G 1 , s , t ) + | V ( G 2 ) | = L ^ ( G 1 , s , t ) + k × c , where G 1 = L ( m , n ; k , l + c ) and G 2 = R ( k , c ) . Consider Figure 20c,d. Then, G 1 is a L-shaped supergrid graph and G 2 is a rectangle. By the algorithm of [17], we can construct a longest ( s , t ) -path P 1 in G 1 that contains edge e 1 locating to face G 2 . By Lemma 1, G 2 contains a canonical Hamiltonian cycle H C 2 such that its one flat face is placed to face G 1 . Thus, by Statement (2) of Proposition 1, P 1 and H C 2 can be combined into a longest ( s , t ) -path of C ( m , n ; k , l ; c , d ) .
Case 5: Condition (UB5) holds. By Lemma 13, U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = t x s x + 1 . Obviously, the lemma holds for the single possible path between s and t (see Figure 24a,b).
Case 6: Condition (UB12) holds. By Lemma 13, U ^ ( C ( m , n ; k , l ; c , d ) , s , t ) = L ^ ( G 1 , s , t ) + 1 , where G 1 = L ( m , n ; k , l + c ) . We make a vertical and a horizontal separation on C ( m , n ; k , l ; c , d ) to obtain two disjoint supergrid subgraphs R 2 = L ( n 2 , m 2 ; 1 , 1 ) and R 1 = R ( m , n n 2 ) , where n 2 = c + l and m 2 = a + 1 (see Figure 27a). Note that ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy condition (F1) in this case. Depending on the positions of s and t, these are the following three subcases:
  Case 6.1: s , t R 1 . A longest ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Case 1 of Lemma 10 (see Figure 27a,b). Then, we can construct a Hamiltonian ( s , t ) -path of R 1 R 2 . Figure 27a,b depicts such constructions. The size of constructed Hamiltonian ( s , t ) -path equals to L ^ ( L ( m , n ; k , l + c ) ) + 1 = | V ( R 1 R 2 ) | , and hence it is the longest ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) .
  Case 6.2: s , t R 2 . A longest ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Case 2 of Lemma 10 (see Figure 27c,d). Depending on whether { s , t } is a vertex cut of R 2 , we consider Figure 27c,d. Then, we can construct a Hamiltonian ( s , t ) -path of R 1 R 2 , as shown in Figure 27a,b. The size of constructed Hamiltonian ( s , t ) -path equals to L ^ ( L ( m , n ; k , l + c ) ) + 1 = | V ( R 1 R 2 ) | , and hence it is the longest ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) .
  Case 6.3: ( s R 1 and t R 2 ) or ( s R 2 and t R 1 ) . Without loos of generality, assume that s R 1 and t R 2 . A longest ( s , t ) -path of ( C ( m , n ; k , l ; c , d ) can be constructed by similar arguments in proving Case 2.2 of Lemma 9 and Case 3 of Lemma 10.    □
Based on Lemmas 8–10 and Lemmas 11–14, we present Algorithm 1 to solve the longest path problem on C-shaped supergrid graph. Let the input of Algorithm 1 be a C-shaped supergrid C ( m , n ; k , l ; c , d ) and vertices s , t V ( C ( m , n ; k , l ; c , d ) ) . In Algorithm 1, it needs to determine whether ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies conditions (F1), (F3), (F7), (F8), or (F9). Clearly, it can be done in constant time. By Lemmas 8–10, H P ( C ( m , n ; k , l ; c , d ) , s , t ) does exist if ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy any of conditions (F1), (F3), (F7), (F8), and (F9). By the proofs of Lemmas 8–10, H P ( C ( m , n ; k , l ; c , d ) , s , t ) can be constructed in O ( | V ( C ( m , n ; k , l ; c , d ) ) | ) = O ( m n k l ) = O ( m n ) time. Consider that ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies conditions (F1), (F3), (F7), (F8), or (F9). By Theorem 5, H P ( C ( m , n ; k , l ; c , d ) , s , t ) does not exist. By the proofs of Lemmas 11–14, the longest ( s , t ) -path can be constructed in O ( | V ( C ( m , n ; k , l ; c , d ) ) | ) = O ( m n k l ) = O ( m n ) time. Thus, Algorithm 1 runs in O ( m n ) -linear time. We finally conclude the following main result.
Algorithm 1: The longest ( s , t ) -path algorithm.
Input: A C-shaped supergrid graph C ( m , n ; k , l ; c , d ) with m n 2 , and two distinct vertices s and t in C ( m , n ; k , l ; c , d ) .
Output: The longest ( s , t ) -path.
  • if a ( = m k ) = 1 and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy the forbidden conditions (F1), (F3), (F7), (F8), and (F9), then output H P ( C ( m , n ; k , l ; c , d ) , s , t ) constructed from Lemma 8;
  • if a ( = m k ) > 1 , c = d = 1 , and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy the forbidden conditions (F1), (F3), (F7), and (F8), then output H P ( C ( m , n ; k , l ; c , d ) , s , t ) constructed from Lemma 9;
  • if a ( = m k ) > 1 , [ c > 1 or d > 1 ] , and ( C ( m , n ; k , l ; c , d ) , s , t ) does not satisfy the forbidden conditions (F1), (F3), (F7), and (F8), then output H P ( C ( m , n ; k , l ; c , d ) , s , t ) constructed from Lemma 10;
  • if ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies one of the forbidden conditions (F1), (F3), (F7), (F8), and (F9), then output the longest ( s , t ) -path based on Lemma 14.
Theorem 6.
Given a C-shaped supergrid graph C ( m , n ; k , l ; c , d ) and its two distinct vertices s and t, Algorithm 1 computes a longest ( s , t ) -path in O ( m n ) -linear time.
Let G be a graph and let η = | V ( G ) | . The all-pairs longest path problem is to find the longest paths between all pairs of vertices in G. The most obvious solution to the all-pairs longest path problem is to run a longest path algorithm η 2 times since there are η 2 = η ( η 1 ) 2 pairs of vertices. Let G = C ( m , n ; k , l ; c , d ) . Then, η = m n k l = O ( m n ) . By calling Algorithm 1 η 2 times, the all-pairs longest path problem for C ( m , n ; k , l ; c , d ) can be solved. Thus, the following corollary holds true.
Corollary 1.
Given a C-shaped supergrid graph C ( m , n ; k , l ; c , d ) , the all-pairs longest path problem can be solved in O ( m 3 n 3 ) time by calling Algorithm 1 ( m n k l ) 2 times.

5. Conclusions

The Hamiltonian problems can be applied to many fields including computer science, biology, molecular science, etc. However, they are NP-complete for general graphs and supergrid graphs. The Hamiltonian path problem is a special case of the longest path problem, and hence the longest path problem is generally difficult. The time complexities of these problems for solid supergrid graphs are still unknown. In this paper, we study these problems on C-shaped supergrid graphs, which form a subclass of solid supergrid graphs. We first discover some Hamiltonian connected properties of rectangular supergrid graphs. We then prove C-shaped supergrid graphs to be Hamiltonian connected except in a few conditions. Finally, we presented a linear-time algorithm for finding a longest path in C-shaped supergrid graphs between any two given vertices. This result can be applied to find the longest path on C-like objects with a supergrid structure. It is well known that Floyd’s algorithm computes all-pairs shortest paths of a digraph. It is interesting to construct a modification of Floyd’s algorithm for solving the all-pairs longest path problem on C-shaped supergrid graphs in linear time. We will post it as an open problem for interested readers. In addition, Laplacian matrix is a matrix representation of a graph. Together with Kirchhoff’s theorem, it can be used to calculate the number of spanning trees for a given graph. It is interesting to see whether there exists a modification of the above result such that it can compute the number of longest paths between two vertices in C-shaped supergrid graphs efficiently. We would like to post it as an open problem to interested readers.

Author Contributions

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

Funding

This research was funded in part by the Ministry of Science and Technology, Taiwan under grant no. MOST 110-2221-E-324-007-MY3.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Acknowledgments

The authors would like to thank anonymous referees for many useful comments and suggestions which have improved the presentation and correctness of this paper. This work is partly supported by the Ministry of Science and Technology, Taiwan under grant no. MOST 110-2221-E-324-007-MY3.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Garey, M.R.; Johnson, D.S. Computers and Intractability: A Gide to the Theory of NP-Completeness; Freeman: San Francisco, CA, USA, 1979. [Google Scholar]
  2. Harary, F. Graph Theory; Addison-Wesley: Reading, MA, USA, 1967. [Google Scholar]
  3. Ascheuer, N. Hamiltonian Path Problems in the On-Line Optimization of Flexible Manufacturing Systems; Technique Report TR 96-3; Konrad-Zuse-Zentrum für Informationstechnik: Berlin, Germany, 1996. [Google Scholar]
  4. O’Callaghan, J.F. Computing the perceptual boundaries of dot patterns. Comput. Graph. Image Process 1974, 3, 141–162. [Google Scholar] [CrossRef]
  5. Bermond, J.C. Hamiltonian Graphs, in Selected Topics in Graph Theory; Beinke, L.W., Wilson, R.J., Eds.; Academic Press: New York, NY, USA, 1978. [Google Scholar]
  6. Preperata, F.P.; Shamos, M.I. Computational Geometry: An Introduction; Springer: New York, NY, USA, 1985. [Google Scholar]
  7. Toussaint, G.T. Pattern recognition and geometrical complexity. In Proceedings of the 5th International Conference on Pattern Recognition, Miami Beach, FL, USA, 1–4 December 1980; pp. 1324–1347. [Google Scholar]
  8. Harary, F.; Hayes, J.P.; Wu, H.J. A survey of the theory of hypercube graphs. Comput. Math. Appl. 1988, 15, 277–289. [Google Scholar] [CrossRef] [Green Version]
  9. Balasubramanian, K. Computer-assisted enumeration ofwalks and self-returning walks on chemical graphs. Comput. Chem. 1985, 9, 43–52. [Google Scholar] [CrossRef]
  10. Balasubramanian, K. Enumeration of stereo, position andchiral isomers of polysubstituted giant fullerenes: Applications to C180 and C240. Fullerenes Nanotub. Carbon Nanostruct. 2020, 28, 687–696. [Google Scholar] [CrossRef]
  11. Twarock, R.; Leonov, G.; Stockley, P.G. Hamiltonian path analysis of viral genomes. Nat. Commun. 2018, 9, 2021. [Google Scholar] [CrossRef] [PubMed]
  12. Hung, R.W.; Li, C.F.; Chen, J.S.; Su, Q.S. The Hamiltonian connectivity of rectangular supergrid graphs. Discrete Optim. 2017, 26, 41–65. [Google Scholar] [CrossRef]
  13. Bulterman, R.W.; van der Sommen, F.W.; Zwaan, G.; Verhoeff, T.; van Gasteren, A.J.M.; Feijen, W.H.J. On computing a longest path in a tree. Inform. Process. Lett. 2002, 81, 93–96. [Google Scholar] [CrossRef]
  14. Ioannidou, K.; Mertzios, G.B.; Nikolopoulos, S.D. The longest path problem has a polynomial solution on interval graphs. Algorithmica 2011, 61, 320–341. [Google Scholar] [CrossRef] [Green Version]
  15. Mertzios, G.B.; Corneil, D.G. A simple polynomial agorithm for the longest path problem on cocomparability graphs. SIAM J. Discrete Math. 2012, 26, 940–963. [Google Scholar] [CrossRef] [Green Version]
  16. 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]
  17. Keshavarz-Kohjerdi, F.; Hung, R.W. The Hamiltonicity, Hamiltonian connectivity, and longest (s,t)-path of L-shaped supergrid graphs. IAENG Intern. J. Comput. Sci. 2020, 47, 378–391. [Google Scholar]
  18. 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]
  19. Zamfirescu, C.; Zamfirescu, T. Hamiltonian properties of grid graphs. SIAM J Discrete Math. 1992, 5, 564–570. [Google Scholar] [CrossRef]
  20. 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]
  21. 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, 19–22 October 1997; pp. 496–505. [Google Scholar]
  22. Salman, A.N.M. Contributions to Graph Theory. Ph.D. Thesis, University of Twente, Enschede, The Netherlands, 2005. [Google Scholar]
  23. Keshavarz-Kohjerdi, F.; Bagheri, A. Hamiltonian paths in L-shaped grid graphs. Theor. Comput. Sci. 2016, 621, 37–56. [Google Scholar] [CrossRef]
Figure 1. (a) The five layers C 1 C 5 of a 3D printing model while printing a C-type object, (b) the computing Hamiltonian path from s i to t i of each layer C i in (a), and (c) the final result while performing the five-layered 3D printing.
Figure 1. (a) The five layers C 1 C 5 of a 3D printing model while printing a C-type object, (b) the computing Hamiltonian path from s i to t i of each layer C i in (a), and (c) the final result while performing the five-layered 3D printing.
Algorithms 15 00061 g001
Figure 2. (a) A grid graph and (b) a supergrid graph, where the circles represent the vertices and the solid lines indicate the edges in the graphs.
Figure 2. (a) A grid graph and (b) a supergrid graph, where the circles represent the vertices and the solid lines indicate the edges in the graphs.
Algorithms 15 00061 g002
Figure 3. (a) A rectangular supergrid graph R ( 9 , 8 ) , where the bold dashed lines indicate vertical and horizontal separations, (b) the structure of L-shaped supergrid graph L ( 9 , 11 ; 6 , 8 ) , and (c) the structure of C-shaped supergrid graph C ( 8 , 11 ; 4 , 7 ; 2 , 2 ) .
Figure 3. (a) A rectangular supergrid graph R ( 9 , 8 ) , where the bold dashed lines indicate vertical and horizontal separations, (b) the structure of L-shaped supergrid graph L ( 9 , 11 ; 6 , 8 ) , and (c) the structure of C-shaped supergrid graph C ( 8 , 11 ; 4 , 7 ; 2 , 2 ) .
Algorithms 15 00061 g003
Figure 4. A canonical Hamiltonian cycle containing three flat faces and one concave face for (a) R ( 6 , 6 ) , and (be) R ( 5 , 5 ) , where the solid arrow lines indicate the edges in the cycles and R ( 5 , 5 ) contains four distinct canonical Hamiltonian cycles in (be) such that their concave faces are placed on different boundaries.
Figure 4. A canonical Hamiltonian cycle containing three flat faces and one concave face for (a) R ( 6 , 6 ) , and (be) R ( 5 , 5 ) , where the solid arrow lines indicate the edges in the cycles and R ( 5 , 5 ) contains four distinct canonical Hamiltonian cycles in (be) such that their concave faces are placed on different boundaries.
Algorithms 15 00061 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.
Algorithms 15 00061 g005
Figure 6. A schematic diagram for (a) Statement (1), (b) Statement (2), (c) Statement (3), and (d) Statement (4) of Proposition 1, where the bold dashed lines indicate the cycles (paths) and ⊗ represents the destruction of an edge while constructing a cycle or path.
Figure 6. A schematic diagram for (a) Statement (1), (b) Statement (2), (c) Statement (3), and (d) Statement (4) of Proposition 1, where the bold dashed lines indicate the cycles (paths) and ⊗ represents the destruction of an edge while constructing a cycle or path.
Algorithms 15 00061 g006
Figure 7. (ao) The possible Hamiltonian ( s , t ) -paths of R ( 3 , 3 ) when s , t { z 1 , z 2 , z 3 } , and (p) the construction of Hamiltonian ( s , t ) -path of R ( k + 1 , 3 ) for k 3 and s , t R ˜ , where the solid lines indicate the constructed Hamiltonian ( s , t ) -path and ⊗ represents the destruction of an edge while constructing a Hamiltonian ( s , t ) -path of R ( k + 1 , 3 ) .
Figure 7. (ao) The possible Hamiltonian ( s , t ) -paths of R ( 3 , 3 ) when s , t { z 1 , z 2 , z 3 } , and (p) the construction of Hamiltonian ( s , t ) -path of R ( k + 1 , 3 ) for k 3 and s , t R ˜ , where the solid lines indicate the constructed Hamiltonian ( s , t ) -path and ⊗ represents the destruction of an edge while constructing a Hamiltonian ( s , t ) -path of R ( k + 1 , 3 ) .
Algorithms 15 00061 g007
Figure 8. L-shaped supergrid graph in which H P ( L ( m , n ; k , l ) , s , t ) does not exist, where (a,b) satisfy condition (F1), (c) depicts condition (F2), and (d) shows condition (F3).
Figure 8. L-shaped supergrid graph in which H P ( L ( m , n ; k , l ) , s , t ) does not exist, where (a,b) satisfy condition (F1), (c) depicts condition (F2), and (d) shows condition (F3).
Algorithms 15 00061 g008
Figure 9. (a) A vertical and horizontal separation on C ( m , n ; k , l ; c , d ) , (b) a Hamiltonian cycle in R 1 , (c) a Hamiltonian cycle in C ( m , n ; k , l ; c , d ) , and (d,e) a horizontal separation on C ( m , n ; k , l ; c , d ) , where the bold solid lines indicate the constructed Hamiltonian cycle and ⊗ represents the destruction of an edge while constructing a Hamiltonian cycle.
Figure 9. (a) A vertical and horizontal separation on C ( m , n ; k , l ; c , d ) , (b) a Hamiltonian cycle in R 1 , (c) a Hamiltonian cycle in C ( m , n ; k , l ; c , d ) , and (d,e) a horizontal separation on C ( m , n ; k , l ; c , d ) , where the bold solid lines indicate the constructed Hamiltonian cycle and ⊗ represents the destruction of an edge while constructing a Hamiltonian cycle.
Algorithms 15 00061 g009
Figure 10. (a,b) Hamiltonian cycles in R 1 and R 2 , and (c,d) a Hamiltonian cycle in C ( m , n ; k , l ; c , d ) for Figure 9d,e respectively.
Figure 10. (a,b) Hamiltonian cycles in R 1 and R 2 , and (c,d) a Hamiltonian cycle in C ( m , n ; k , l ; c , d ) for Figure 9d,e respectively.
Algorithms 15 00061 g010
Figure 11. Some C-shaped supergrid graphs in which H P ( C ( m , n ; k , l ; c , d ) , s , t ) does not exist, where (a,b) satisfy condition (F1), (c) depicts condition (F3), (d) depicts condition (F7), (eg) depicts condition (F8), and (h) shows condition (F9).
Figure 11. Some C-shaped supergrid graphs in which H P ( C ( m , n ; k , l ; c , d ) , s , t ) does not exist, where (a,b) satisfy condition (F1), (c) depicts condition (F3), (d) depicts condition (F7), (eg) depicts condition (F8), and (h) shows condition (F9).
Algorithms 15 00061 g011
Figure 12. (a) A horizontal separation on C ( m , n ; k , l ; c , d ) , (b) Hamiltonian paths P 1 and P 2 in ( R 1 , s , p ) and ( R 2 , q , t ) , respectively, and (c) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) , where a = 1 and bold lines indicate the constructed Hamiltonian path.
Figure 12. (a) A horizontal separation on C ( m , n ; k , l ; c , d ) , (b) Hamiltonian paths P 1 and P 2 in ( R 1 , s , p ) and ( R 2 , q , t ) , respectively, and (c) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) , where a = 1 and bold lines indicate the constructed Hamiltonian path.
Algorithms 15 00061 g012
Figure 13. (ac) A vertical and a horizontal separation on C ( m , n ; k , l ; c , d ) under that a 2 , c = d = 1 , n = 3 , and t x > a , and (d) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (a), where bold lines indicate the constructed Hamiltonian path.
Figure 13. (ac) A vertical and a horizontal separation on C ( m , n ; k , l ; c , d ) under that a 2 , c = d = 1 , n = 3 , and t x > a , and (d) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (a), where bold lines indicate the constructed Hamiltonian path.
Algorithms 15 00061 g013
Figure 14. (a) A vertical and a horizontal separation on C ( m , n ; k , l ; c , d ) under that s x , t x < m 1 , (b) a Hamiltonian ( s , t ) -path in R 1 for (a), (c) a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) for (a), (d,e) a vertical separation on C ( m , n ; k , l ; c , d ) for s x < m 1 and t x = m 1 , and (f) a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) for (d), where the bold lines indicate the constructed Hamiltonian path and ⊗ represents the destruction of an edge while constructing a Hamiltonian cycle.
Figure 14. (a) A vertical and a horizontal separation on C ( m , n ; k , l ; c , d ) under that s x , t x < m 1 , (b) a Hamiltonian ( s , t ) -path in R 1 for (a), (c) a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) for (a), (d,e) a vertical separation on C ( m , n ; k , l ; c , d ) for s x < m 1 and t x = m 1 , and (f) a Hamiltonian ( s , t ) -path of C ( m , n ; k , l ; c , d ) for (d), where the bold lines indicate the constructed Hamiltonian path and ⊗ represents the destruction of an edge while constructing a Hamiltonian cycle.
Algorithms 15 00061 g014
Figure 15. (ac) A horizontal separation on C ( m , n ; k , l ; c , d ) for n > 3 , (d) a Hamiltonian ( s , t ) -path in R 2 and a Hamiltonian cycle in R 1 , and (e) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) .
Figure 15. (ac) A horizontal separation on C ( m , n ; k , l ; c , d ) for n > 3 , (d) a Hamiltonian ( s , t ) -path in R 2 and a Hamiltonian cycle in R 1 , and (e) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) .
Algorithms 15 00061 g015
Figure 16. (a) A Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) , (b,c) a vertical and horizontal separations on C ( m , n ; k , l ; c , d ) where 2 s x = t x a 1 , (d) a Hamiltonian ( s , t ) -path in R 21 and Hamiltonian cycles in R 1 and R 22 for (b), (e) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (b), and (f) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (c).
Figure 16. (a) A Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) , (b,c) a vertical and horizontal separations on C ( m , n ; k , l ; c , d ) where 2 s x = t x a 1 , (d) a Hamiltonian ( s , t ) -path in R 21 and Hamiltonian cycles in R 1 and R 22 for (b), (e) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (b), and (f) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (c).
Algorithms 15 00061 g016
Figure 17. (a,b) A horizontal separation on C ( m , n ; k , l ; c , d ) under that a > 1 and d > 1 , (c) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 , and (d) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (c).
Figure 17. (a,b) A horizontal separation on C ( m , n ; k , l ; c , d ) under that a > 1 and d > 1 , (c) a Hamiltonian ( s , t ) -path in R 1 and a Hamiltonian cycle in R 2 , and (d) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) for (c).
Algorithms 15 00061 g017
Figure 18. (a,b) A vertical and horizontal separation on R 1 under that s , t R 1 and { s , t } is a vertex cut of R 1 , and (c) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) .
Figure 18. (a,b) A vertical and horizontal separation on R 1 under that s , t R 1 and { s , t } is a vertex cut of R 1 , and (c) a Hamiltonian ( s , t ) -path in C ( m , n ; k , l ; c , d ) .
Algorithms 15 00061 g018
Figure 19. A longest ( s , t ) -path under that a = 1 for (a,b) (UB1) holds, and (c,d) (UB2) holds, where the bold lines indicate the constructed longest ( s , t ) -path and the bold dash lines indicate the separations.
Figure 19. A longest ( s , t ) -path under that a = 1 for (a,b) (UB1) holds, and (c,d) (UB2) holds, where the bold lines indicate the constructed longest ( s , t ) -path and the bold dash lines indicate the separations.
Algorithms 15 00061 g019
Figure 20. A longest ( s , t ) -path under that a 2 and c , d 2 for (a,b) (UB3) holds, and (c,d) (UB4) holds, where the bold lines indicate the constructed longest ( s , t ) -path.
Figure 20. A longest ( s , t ) -path under that a 2 and c , d 2 for (a,b) (UB3) holds, and (c,d) (UB4) holds, where the bold lines indicate the constructed longest ( s , t ) -path.
Algorithms 15 00061 g020
Figure 21. (a) The separations on C ( m , n ; k , l ; c , d ) for a 2 and c = 1 , (b) the case of s , t G 2 , (c) the case of s G 1 and t G 2 , and (d) the case of s , t G 1 .
Figure 21. (a) The separations on C ( m , n ; k , l ; c , d ) for a 2 and c = 1 , (b) the case of s , t G 2 , (c) the case of s G 1 and t G 2 , and (d) the case of s , t G 1 .
Algorithms 15 00061 g021
Figure 22. The cases for s , t G 1 and { s , t } is a vertex cut of G 1 , where (a,b) { s , t } = { ( a , 1 ) , ( a , 2 ) } , (c) a = 2 and s y = t y , and (d) d = 2 , k > 1 , and a < s x = t x < m .
Figure 22. The cases for s , t G 1 and { s , t } is a vertex cut of G 1 , where (a,b) { s , t } = { ( a , 1 ) , ( a , 2 ) } , (c) a = 2 and s y = t y , and (d) d = 2 , k > 1 , and a < s x = t x < m .
Algorithms 15 00061 g022
Figure 23. The cases for s , t G 1 and { s , t } is not a vertex cut of G 1 , where (a,b) a = 2 , s y , t y 2 , s y t y , and s x t x , (ce) ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F8), and (f,g) ( G 1 , s , t ) satisfies condition (F3) but it does not satisfy condition (F1).
Figure 23. The cases for s , t G 1 and { s , t } is not a vertex cut of G 1 , where (a,b) a = 2 , s y , t y 2 , s y t y , and s x t x , (ce) ( C ( m , n ; k , l ; c , d ) , s , t ) satisfies condition (F8), and (f,g) ( G 1 , s , t ) satisfies condition (F3) but it does not satisfy condition (F1).
Algorithms 15 00061 g023
Figure 24. The longest ( s , t ) -path under that a 2 and c = 1 , where (a,b) (UB5) holds and (c,d) (UB6) holds, where the bold lines indicate the constructed longest ( s , t ) -path.
Figure 24. The longest ( s , t ) -path under that a 2 and c = 1 , where (a,b) (UB5) holds and (c,d) (UB6) holds, where the bold lines indicate the constructed longest ( s , t ) -path.
Algorithms 15 00061 g024
Figure 25. The longest ( s , t ) -path under that a 2 and c = 1 , where (a,b) (UB7) holds, (c,d) (UB8) holds, and (e,f) (UB9) holds.
Figure 25. The longest ( s , t ) -path under that a 2 and c = 1 , where (a,b) (UB7) holds, (c,d) (UB8) holds, and (e,f) (UB9) holds.
Algorithms 15 00061 g025
Figure 26. The longest ( s , t ) -path under that a 2 and c = 1 , where (ac) (UB10) holds, (df) (UB11) holds, and (g,h) (UB12) holds.
Figure 26. The longest ( s , t ) -path under that a 2 and c = 1 , where (ac) (UB10) holds, (df) (UB11) holds, and (g,h) (UB12) holds.
Algorithms 15 00061 g026
Figure 27. A longest ( s , t ) -path in C ( m , n ; k , l ; c , d ) when (UB12) holds, where (a,b) s , t R 1 , and (c,d) s , t R 2 .
Figure 27. A longest ( s , t ) -path in C ( m , n ; k , l ; c , d ) when (UB12) holds, where (a,b) s , t R 1 , and (c,d) s , t R 2 .
Algorithms 15 00061 g027
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

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. https://doi.org/10.3390/a15020061

AMA Style

Keshavarz-Kohjerdi F, Hung R-W. Finding Hamiltonian and Longest (s,t)-Paths of C-Shaped Supergrid Graphs in Linear Time. Algorithms. 2022; 15(2):61. https://doi.org/10.3390/a15020061

Chicago/Turabian Style

Keshavarz-Kohjerdi, Fatemeh, and Ruo-Wei Hung. 2022. "Finding Hamiltonian and Longest (s,t)-Paths of C-Shaped Supergrid Graphs in Linear Time" Algorithms 15, no. 2: 61. https://doi.org/10.3390/a15020061

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