Abstract
Recently, the problem of counting Hamiltonian cycles in 2-tiled graphs was resolved by Vegi Kalamar, Bokal, and Žerak. In this paper, we continue our research on generalized tiled graphs. We extend algorithms on counting traversing Hamiltonian cycles from 2-tiled graphs to generalized tiled graphs. We further show that, similarly as for 2-tiled graphs, for a fixed finite set of tiles, counting traversing Hamiltonian cycles can be performed in linear time with respect to the size of such graph, implying that counting traversing Hamiltonian cycles in tiled graphs is fixed-parameter tractable.
MSC:
05C30; 05C38
1. Introduction
Interest in the enumeration and generation of Hamiltonian cycles in various families of graphs can be found in different domains of science. In chemistry, theoretical physics, and biophysics, the research is connected to the modeling of polymers [], polymer melting, protein folding [], and the study of magnetic systems with symmetry []. In the theory of algorithms, it is one of the most studied counting problems coming from the mathematical nanosciences []. It has applications in coding theory according to [,,]. In engineering and bioinformatics, the research is connected to security and intellectual property protection [] and path planning problems for robots and machine tools [].
Studies on the topic of counting Hamiltonian cycles in different families of graphs and the use of similar (matrix) approaches are not negligible. In 1990, a characterization of Hamiltonian cycles of the Cartesian product was established []. In 1994, Kwong and Rogers developed a matrix method for counting Hamiltonian cycles in , obtaining exact results for []. Their method was extended to arbitrarily large grids by Bodroža-Pantić et al. [] and by Stoyan and Strehl []. Later, Bodroža-Pantić et al. gave some explicit generating functions for the number of Hamiltonian cycles in graphs , and [,,]. Recently, Đokić et al. presented two algorithms for determination of the number of (all spanning unions of cycles) 2-factors in three classes of grid graphs: the thin cylinder , torus , and Klein bottle , all of which had a width of m []. On the other hand, Vegi Kalamar et al. characterized all Hamiltonian cycles in 2-tiled graphs and efficiently counted them for a fixed family of tiles []. Others have recently tackled other (less related) families of graphs: Fernandes et al. on the Matroid Basis Graph [], Liu et al. on planar triangulations [] and Ferber et al. on Dirac Hypergraphs [].
In the present contribution, we build on the results of []. The introduced k-traversing Hamiltonian cycles in tiled graphs are a generalization of zigzagging (1-traversing) and traversing (2-traversing) Hamiltonian cycles from 2-tiled graphs. We extend the results to counting traversing Hamiltonian cycles in an arbitrary family of tiled graphs.
We organize the remainder of the paper as follows. In Section 2, we define tiled graphs as a generalization of 2-tiled graphs, define traversing Hamiltonian cycles in tiled graphs, and prove their possible existence. In Section 3, we present an algorithm to count this type of Hamiltonian cycles and represent its value in a closed formula. In Section 4, we propose open problems for further research.
2. Tiled Graphs and Traversing Hamiltonian Cycles
In this section, we introduce the concept of a tile as presented in [] and extend it to a definition of a tiled graph. We define the concept of k-traversing Hamiltonian cycles in tiled graphs and prove their possible existence for certain values of k.
Definition 1.
A tile is a triple , consisting of a connected graph G and two sequences (left wall) and (right wall) of distinct vertices of G, with no vertex of G appearing in both x and y. We call T a -tile.
Example 1
(A tile). Same graph represented as a (2,3)-tile with one internal vertex and as a (3,3)-tile without an internal vertex.

Definition 2.
- 1.
- The tiles and are compatible whenever
- 2.
- A sequence of tiles is compatible if, for each , is compatible with .
- 3.
- The join of compatible tiles and is the tile for which the graph is obtained from disjoint union of G and by identifying the sequence y term by term with the sequence .
- 4.
- The join of a compatible sequence of tiles is defined as .
- 5.
- A tile T is cyclically compatible if T is compatible with itself.
- 6.
- For a cyclically compatible tile , the cyclization of T is the graph obtained by identifying the respective vertices of x with y.
- 7.
- A cyclization of a cyclically compatible sequence of tiles is defined as .
- 8.
- A tiled graph is a cyclization of a sequence of at least 3 tiles.
Example 2
(Join of tiles). Result of a join of tiles from the left side is a (2,2)-tile on the right side.

Example 3
(Cyclization of a tile). Cyclization of the left side tile results in a graph where the vertices of the left wall are identified with the vertices of the right wall.

The following lemma is crucial in understanding of a structure of Hamiltonian cycles in tiled graphs. It is an extension of claims 1–3 of Lemma 1 from [] to tiled graphs.
Lemma 1.
Let C be a Hamiltonian cycle in a tiled graph . Then, we have the following:
- 1.
- .
- 2.
- is a union of paths and isolated vertices.
- 3.
- Let v be a vertex of a component of . Then, v has degree 2 in or v is a wall vertex.
Proof.
- 1.
- 2.
- Let K be a component of . As C is a cycle, K is a connected subgraph of C. Then, K is either equal to C, a path, or a vertex. If , then contains all the vertices of G, a contradiction to (in at least one tile, C does not contain all the vertices). The claim follows.
- 3.
- Let v be a vertex of of degree different from 2. As the maximum degree of vertex in C is 2, v has degree 1 or 0. If v is an internal vertex of , its degree in is equal to its degree in . This contradicts C being a cycle and the claim follows.
□
Definition 3.
Let be a tiled graph and the set of all isolated vertices in . For , Hamiltonian cycle C is k-traversing, if , is a set of k paths that start in a vertex of left wall and end in a vertex of right wall that cover all internal vertices of .
Definition 4.
Let be a tiled graph, where is a -tile. The minimum wall size of a tiled graphs G is defined as .
The following result (using claim 4 of Lemma 1 from [] as a basis) directly follows from claims of Lemma 1.
Corollary 1.
Let be a tiled graph, where is a -tile. If a k-traversing Hamiltonian cycle exists in G, then .
Proof.
By Claim 3 in Lemma 1, paths start and end in a wall vertex. Each traversing path is a distinct non-degenerate path and has at least two unique wall vertices, one from the left wall and one from the right wall. For a tile , the number of such paths is at most and the claim for the whole graph follows from the fact that . □
3. Counting Traversing Hamiltonian Cycles in Tiled Graphs
In this section, we introduce structures that enable us to describe an algorithm for counting traversing Hamiltonian cycles and prove its correctness. We further show that, in the case of a fixed set of tiles, this algorithm is efficient.
According to Definition 3, k-traversing Hamiltonian cycles can be obtained by “gluing” k disjoint paths covering all internal nodes of a tile between neighboring tiles. We must pay attention to the following things:
- 1.
- Each of the k paths in a tile has to be “glued together” with exactly one of the k paths in the neighboring tile.
- 2.
- When we “glue” all k paths in neighboring tiles, on a shared wall each node must belong to exactly on of the k paths.
- 3.
- When “gluing together” k paths in the entire tiled graph, we must make sure that this is conducted in such a way that these “glued” k paths result in a single cycle.
In the following, we present the structures that will help us solve the presented challenges. To facilitate brevity, we have prepared Table A1 with a summary of frequently used notations. It is located in Appendix A.
Let be a tiled graph, where , is a -tile. For a tile , let . Let be a set of strings of left endvertices of length k (out of options) and be a set of strings of right endvertices of length k (out of options), both ordered lexicographically from smallest to largest. Then, and . Those sets will be used to model left-to-right transition modes. Let denote an empty string. Additionally, let be a set of all binary strings of length (for remaining left wall vertices) and a set of all binary strings of length (for remaining left wall vertices),
both ordered lexicographically from largest to smallest. Then, and . Those sets will be used to model the coverage of wall vertices with paths within the current (bit value 1) or a neighboring tile (bit value 0). For element x from sets and , let denote a string where all bits are flipped and .
Let be a block matrix
where, , (p-th element in ) and , (r-th element in ), is a matrix of form
where, , (u-th element in ), and , (v-th element in ), represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices and ordered right wall endvertices (defining paths ), describing if remaining left wall vertices are/are not part of any k paths and describing if remaining right wall vertices are/are not part of any k paths.
Example 4.
Let T be a (2,3)-tiled graph with no internal (non-wall) vertex. Then, there may exist 1-traversing and 2-traversing paths:
- 1-traversing: In this case, the sets are the following:ThenwhereFor example, denotes the number of possible combinations in T for one path covering all internal vertices, starting in , ending in , where the first remaining left wall vertex () is part of the path and the first remaining right wall vertex () is part of the path, but the second one () is not. See Figure 1.
Figure 1. Possible combinations for . - 2-traversing: In this case, the sets are the following:Thenwhere ,For example, denotes the number of possible combinations in T for two distinct paths covering all internal vertices, the first starting in and ending in , and second one starting in and ending in , where there is no remaining left wall vertex and the first remaining right wall vertex () is part of one of the paths. See Figure 2.
Figure 2. Possible combinations for .
Let be a block matrix
where, , (p-th element in ) and , (r-th element in ), is a matrix of form
Example 5.
Using tile from Example 4, we check the matrices:
- 1-traversing:where
- 2-traversing:where
Definition 5.
Let be a -tile and a -tile that are compatible (). For , let be a matrix that belongs to and a matrix that belongs to . For a tile , we define a matrix as
where · represents the block matrix multiplication
Lemma 2.
Matrix is a block matrix of form
where, , (p-th element in ) and , (r-th element in ), is a matrix of form
where, , (u-th element in ), and , (v-th element in ), represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices and ordered right wall endvertices (defining paths ), describing if remaining left wall vertices are/are not part of any k paths and describing if remaining right wall vertices are/are not part of any k paths.
Remark 1.
Lemma 2 presents the counting of ways of “gluing” k paths in adjacent tiles.
Proof.
Because tiles and are compatible, and . Since is a block matrix of dimension and is a block matrix of dimension , by definition of block matrix multiplication, is a block matrix of dimension . Since each block in is of dimension and each block in of dimension , by definition of block matrix multiplication, each block in is of dimension .
By definition of block matrix multiplication, element of block is calculated as
We have to show that ,
generates described paths in .
Let and . Then, represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices and ordered right wall endvertices x (defining paths ), describing if remaining left wall vertices are/are not part of any k paths and y describing if remaining right wall vertices are/are not part of any k paths. On the other side, represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices x and ordered right wall endvertices (defining paths ), describing if remaining left wall vertices are/are not part of any k paths and describing if remaining right wall vertices are/are not part of any k paths.
It is clear that, if we identify those k paths by endvertices x (defining paths ), we cover all internal vertices in and , but also remaining vertices on shared wall (paths in cover remaining right wall vertices in , for which the bit value in y is 1, and paths in cover remaining left wall vertices in , for which the bit value in is 1) and the result follows. □
Example 6.
We check out the product , where is a tile from Example 4 and the tile that we obtain if we switch walls in (those tiles are compatible).
- 1-traversing:where
- 2-traversing:where
Definition 6.
For , we define
Definition 7.
For and , let
be the z-shift of b.
Theorem 1.
Let be a tiled graph and let . The number of distinct k-traversing Hamiltonian cycles in G is equal to
Proof.
Let be a matrix that belongs to . Then, it is a block matrix of form
where , (p-th element in ), , (r-th element in ), is a matrix of form
Since graph G is a result of identifications of left and right wall vertices in tile , and so and . We obtain that matrix is a block matrix of form
where , (p-th and r-th element in ), is a matrix of form
where, , (u-th and v-th element in ), represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices and ordered right wall endvertices (defining paths ), describing remaining left wall vertices are/are not part of any k paths and describing remaining right wall vertices are/are not part of any k paths.
To obtain the number from the matrix , we need to take into account only block matrices for which mapping of consecutive elements of into consecutive elements of () is a permutation of a set that can be decomposed into one disjoint cycle. Otherwise each sequence of paths identified by a disjoint cycle in the decomposition can generate a separate cycle. For , , is the desired permutation, and, for , it is easy to see, that , mappings , where , are the desired permutations.
From such block matrices , only entries add to the number , since they cover all remaining vertices on the shared wall between tiles and exactly once. Because of the introduced lexicographic order on sets ,
Hence, if , ,
and, if ,
are values that contribute to .
However, since there are block matrices that calculate same cycles (ones that generate permutations over the same set), the total sum must be divided by . □
Remark 2.
- 1.
- If , for , setforms an anti-diagonal of block matrix .
- 2.
- If , for and , setforms an anti-diagonal of block matrix .
Using the above algorithm, some results from [] can be recreated. In it, 2-tiled graphs are investigated.
Example 7
(Counting traversing Hamiltonian cycles in 2-tiled graphs). For 2-tiled graphs, 1-traversing (denoted as zigzagging in []) and 2-traversing (denoted as traversing in []) Hamiltonian cycles may exist:
- 1-traversing: The matrix is a block matrix, where each block is of dimension :Then
- 2-traversing: The matrix is a block matrix, where each block is of dimension :Then
Corollary 2.
Let be a finite family of tiles, and let be a family of cyclizations of finite sequence of such tiles. There exists and algorithm that yields, for each graph , the number . For a fixed set , the running time of the algorithm is linear in the number of tiles (and hence vertices) of G.
Proof.
For a fixed family of tiles, we precalculate matrices (and so ). The time complexity to compute the matrix is and additional is needed to obtain the searched sum from it. □
4. Conclusions and Further Research
In this paper, we presented a solution to count traversing Hamiltonian cycles in tiled graphs. We accomplished it by introducing an extended matrix method from [], where the crucial part was the identification of matrices . Similarly as in [] for 2-tiled graphs, in Corollary 2, we used the fact that, in a finite set of tiles, the generation of these matrices can be thought of as a constant problem, which resulted in that our algorithm’s running time is linear in the number of tiles (and hence vertices). In general, this is not true, so we now propose the following open problem:
Open problem.
Find an (efficient) algorithm to generate block matrices .
By definition, traversing Hamiltonian cycles are such that their intersection with the tile results in paths that start in one wall and end in another wall of the tile. Obviously, however, there are also types of Hamiltonian cycles such that their intersection with a tile also allows paths that start and end in the same wall of the tile (flanking Hamiltonian cycles as an example in 2-tiled graphs []). Therefore, we additionally propose the following open problems:
Open problem.
Identify other types of Hamiltonian cycles in tiled graphs.
Open problem.
Count other types of Hamiltonian cycles in tiled graphs.
Funding
This research was funded by Slovenian Research Agency (research project J1-2452).
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
Not applicable.
Acknowledgments
I am grateful to Drago Bokal for his critical comments that encouraged me to improve the presentation of the paper.
Conflicts of Interest
The author declares no conflict of interest.
Appendix A
Table A1.
Glossary of frequently used symbols.
Table A1.
Glossary of frequently used symbols.
| Notation | Description |
|---|---|
| Set of strings of left endvertices of length k (out of options), ordered lexicographically from smallest to largest. Used to model left-to-right transition modes. It is clear that . | |
| Set of strings of right endvertices of length k (out of options), ordered lexicographically from smallest to largest. Used to model left-to-right transition modes. It is clear that . | |
| An empty string. | |
| Set of all binary strings of length (for remaining left wall vertices), ordered lexicographically from largest to smallest. | |
| Set of all binary strings of length (for remaining left wall vertices), ordered lexicographically from largest to smallest.
| |
| Denotes a bit string where all bits in x are flipped. | |
| A block matrix of form | |
| For , it is a matrix of form | |
| For and , it represents the number of possible combinations in for k distinct paths covering all internal vertices that have ordered left wall endvertices and ordered right wall endvertices (defining paths ), describing if remaining left wall vertices are/are not part of any k paths and describing if remaining right wall vertices are/are not part of any k paths. | |
| A block matrix of form | |
| For , it is a matrix of form
|
References
- des Cloizeaux, J.; Jannik, G. Polymers in Solution: Their Modelling and Structure; Clarendon Press: Oxford, MS, USA, 1990. [Google Scholar]
- Kloczkowski, A.; Jernigan, R.L. Transfer matrix method for enumeration and generation of compact self-avoiding walks. I. Square lattices. J. Chem. Phys. 1998, 109, 5134–5146. [Google Scholar] [CrossRef]
- Jacobsen, J.L. Exact enumeration of Hamiltonian circuits, walks and chains in two and three dimensions. J. Phys. A Math. Theor. 2007, 40, 14667–14678. [Google Scholar] [CrossRef]
- Montoya, J.A. On the Counting Complexity of Mathematical Nanosciences. MATCH Commun. Math. Comput. Chem. 2021, 86, 453–488. [Google Scholar]
- Alahmadi, A.; Aldred, R.E.L.; de la Cruz, R.; Solé, P.; Thomassen, C. The maximum number of minimal codewords in long codes. Discret. Appl. Math. 2013, 161, 424–429. [Google Scholar] [CrossRef]
- Alahmadi, A.; Aldred, R.E.L.; de la Cruz, R.; Solé, P.; Thomassen, C. The maximum number of minimal codewords in an [n,k]-code. Discret. Math. 2013, 313, 1569–1674. [Google Scholar] [CrossRef]
- Alahmadi, A.; Aldred, R.E.L.; de la Cruz, R.; Ok, S.; Solé, P.; Thomassen, C. The minimum number of minimal codewords in an [n,k]-code and in graphic codes. Discret. Appl. Math. 2015, 184, 32–39. [Google Scholar] [CrossRef]
- Nishat, R.I.; Whitesides, S. Reconfiguring Hamiltonian Cycles in L-Shaped Grid Graphs. Graph-Theor. Concepts Comput. Sci. 2019, 21, 325–337. [Google Scholar]
- Liang, T.C.; Chakrabarty, K.; Karri, R. Programmable daisychaining of microelectrodes to secure bioassay IP in MEDA biochips. IEEE Trans. Very Large Scale Integr. (VLSI) Syst. 2020, 25, 1269–1282. [Google Scholar] [CrossRef]
- Tošić, R.; Bodroža-Pantić, O.; Kwong, Y.H.H.; Straight, H.J. On the number of Hamiltonian cycles of P4 × Pn. Indian J. Pure Appl. Math. 1990, 21, 403–409. [Google Scholar]
- Kwong, Y.H.H.; Rogers, D.G. A matrix method for counting Hamiltonian cycles on grid graphs. Eur. J. Comb. 1994, 15, 277–283. [Google Scholar] [CrossRef]
- Bodroža-Pantić, O.; Tošič, R. On the number of 2-factors in rectangular lattice graphs. Publ. L’Institut Math. 1994, 56, 23–33. [Google Scholar]
- Stoyan, R.; Strehl, V. Enumeration of Hamiltonian circuits in rectangular grids. J. Comb. Math. Comb. Comput. 1996, 21, 109–127. [Google Scholar]
- Bodroža-Pantić, O.; Pantić, B.; Pantić, I.; Bodroža-Solarov, M. Enumeration of Hamiltonian cycles in some grid graphs. MATCH Commun. Math. Comput. Chem. 2013, 70, 181–204. [Google Scholar]
- Bodroža-Pantić, O.; Kwong, H.; Doroslovački, R.; Pantić, M. Enumeration of Hamiltonian cycles on a thick grid cylinder—Part I: Non-contractible Hamiltonian cycles. Appl. Anal. Discret. Math. 2019, 13, 28–60. [Google Scholar] [CrossRef]
- Bodroža-Pantić, O.; Kwong, H.; Dokić, J.; Doroslovački, R.; Pantić, M. Enumeration of Hamiltonian cycles on a thick grid cylinder—Part II: Contractible Hamiltonian cycles. Appl. Anal. Discret. Math. 2022, 16, 246–287. [Google Scholar] [CrossRef]
- Đokić, J.; Doroslovački, K.; Bodroža-Pantić, O. A Spanning Union of Cycles in Thin Cylinder, Torus and Klein Bottle Grid Graphs. Mathematics 2023, 11, 846. [Google Scholar] [CrossRef]
- Vegi Kalamar, A.; Žerak, T.; Bokal, D. Counting Hamiltonian Cycles in 2-Tiled Graphs. Mathematics 2021, 9, 693. [Google Scholar] [CrossRef]
- Fernandes, C.G.; Hernández-Vélez, C.; de Pina, J.C.; Ramírez Alfonsín, J.L. Counting Hamiltonian Cycles in the Matroid Basis Graph. Graphs Comb. 2019, 35, 539–550. [Google Scholar] [CrossRef]
- Liu, X.; Wang, Z.; Yu, X. Counting Hamiltonian cycles in planar triangulations. J. Comb. Theory Ser. 2022, 155, 256–277. [Google Scholar] [CrossRef]
- Ferber, A.; Hardiman, L.; Mond, A. Counting Hamilton Cycles in Dirac Hypergraphs. Combinatorica 2023, 1–16. [Google Scholar] [CrossRef]
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. |
© 2023 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).