WorksComputer Science
The Complexity of Hamiltonian Cycles and Paths with Prescribed Walk Lengths
Abstract
Fix a set of positive integers. An -Hamiltonian cycle is a cyclic ordering of all vertices of a graph such that each consecutive pair is joined by a walk whose length belongs to . We study the complexity of deciding whether an input graph admits such an ordering, together with the corresponding path variants with prescribed or unrestricted endpoints. We complete the complexity classification for undirected graphs. In particular, we prove NP-completeness for every finite nonempty set of odd lengths, resolving an open problem posed by Amarilli, Lombardo, and Monet (WG 2026). For digraphs, all three problems are NP-complete for every fixed finite nonempty and admit linear-time algorithms when is cofinite. For other fixed infinite sets , we establish NP-complete and undecidable cases, with undecidability occurring even when is recursive.
2012 ACM Subject Classification Theory of computation Problems, reductions and completeness; Mathematics of computing Graph algorithms
Keywords and phrases Hamiltonian cycle, Hamiltonian path, walk length, graph powers, complexity dichotomy, directed graphs
Funding R. B. Sandeep: R. B. Sandeep thanks the IWOCA 2026 organizing team and gratefully acknowledges financial support from LIRMM, Montpellier, France, through the IWOCA 2026 Extended Stay Support Scheme for his research visit to LIRMM.
Introduction
The Hamiltonian Cycle and Hamiltonian Path problems ask whether a given graph contains a cycle or a path, respectively, that visits every vertex exactly once. These are fundamental problems in graph theory and theoretical computer science [6], closely connected to routing and sequencing applications through the travelling salesman problem [3]. As classical NP-complete problems, they also play a central role in the study of computational complexity and the design of algorithms [9, 4]. In both problems, consecutive vertices must be adjacent. A natural generalisation, studied by Amarilli, Lombardo, and Monet [1], relaxes this requirement by allowing consecutive vertices to be joined by a walk whose length belongs to a fixed set of positive integers. Every vertex must still appear exactly once in the cyclic or linear ordering, but the walks witnessing these transitions may repeat vertices and pass through vertices appearing elsewhere in the ordering.
Formally, fix . An -Hamiltonian cycle is a cyclic ordering of all vertices in which every consecutive pair is joined by a walk of length in . We also consider -Hamiltonian paths, both with prescribed endpoints and with unrestricted endpoints. For a digraph, every witnessing walk must respect the arc directions. Throughout the paper, is fixed rather than supplied as part of the input. Crucially, these are conditions on walk lengths, not on shortest-path distances. For example, an edge of an undirected graph can be traversed back and forth to give a walk of any positive odd length between its endpoints.
More generally, a walk of positive length can be extended to length for every integer by inserting back-and-forth traversals of an edge. Hence the undirected problems for are identical to those for its normalisation, the parity-preserving downward closure
We call normalised when . Such a set is a union of an odd prefix and an even prefix: write for odd , for even , and for the entire positive odd and even classes. Either prefix may also be empty.
Context and previous work.
Amarilli, Lombardo, and Monet introduced the -Hamiltonian variant of Hamiltonicity and studied its complexity on undirected graphs [1, 2]. For normalised sets, their cycle classification gives NP-completeness for , , and , and NP-hardness under Cook reductions for . The remaining classified cases are linear-time solvable: even prefixes containing , mixed sets containing or , and (with the empty set trivial). The first two classical cases follow from ordinary Hamiltonicity and graph squares [9, 11]; the tractability of sets containing follows from the Hamiltonian-connectedness of graph cubes [8].
The finite odd-only prefixes with were the sole remaining family in their cycle classification. For paths, they additionally left open with unrestricted endpoints and with prescribed endpoints. Their hardness proofs for cycles and prescribed endpoints used Cook reductions, leaving many-one hardness unresolved. They also proposed studying directed graphs as an open direction.
Our contributions.
We resolve all these undirected open cases. Our main result, Theorem 2, proves NP-completeness for every finite odd prefix, completing the cycle classification. For , establish NP-completeness under many-one reductions for all three variants. For prescribed-endpoint paths with , we give a linear-time algorithm. Table 1 gives the complete classification, with our new results in bold.
For directed graphs, we answer the finite-set question: every fixed finite nonempty gives NP-completeness, even on oriented graphs. For infinite sets, cofinite gives linear-time algorithms, whereas we exhibit both a fixed infinite NP-complete case and a fixed recursive infinite undecidable case, even on strongly connected oriented graphs. Table 2 summarises these results; a complete classification of infinite directed sets remains open.
| Fixed set and input restriction | All three problems |
| Trivial | |
| Finite nonempty , oriented graphs | NP-complete (Thm. 12) |
| Cofinite | Linear time (Thm. 14) |
| , strongly connected bipartite oriented graphs | NP-complete (Thm. 16) |
| A recursive infinite , strongly connected oriented graphs | Undecidable (Thm. 18) |
Table 2. Directed results; bold entries are our contributions. “Trivial” means no on inputs of at least two vertices; a single vertex is a path. NP-completeness uses many-one reductions. These rows do not classify all infinite sets.
Organisation.
Section 2 establishes the common framework. Sections 3 and 4 prove the undirected results. Sections 5 and 6 treat finite and infinite directed length sets, respectively.
Preliminaries
We relate the three problems to ordinary Hamiltonicity in the compatibility graph , giving polynomial-time construction and NP membership for fixed undirected sets and finite directed sets. All graphs are finite. Undirected graphs are simple. Digraphs have no parallel arcs and may have loops unless a restriction is stated; an oriented graph has neither loops nor antiparallel arcs. Write for the vertex set, and or for the edge or arc set. A walk of length has edges or arcs, counted with multiplicity. Its vertices need not be distinct. A path has no repeated vertices. Write for the subgraph induced by , and , for the open and closed neighbourhoods of . In digraphs, , and , denote out- and in-neighbourhoods and degrees. A digraph is bipartite when its underlying undirected graph is bipartite. The line graph of an undirected graph has one vertex for each edge, with adjacency when the corresponding edges share an endpoint. A graph or digraph is Hamiltonian-connected if it has a Hamiltonian path between every pair of distinct vertices (in the specified order for a digraph). The power of an undirected graph joins distinct vertices whose distance in is at most .
Fix . The -Hamiltonian Path problem asks whether has an ordering such that each is joined to by a walk of length in . The prescribed-endpoint variant additionally requires and , for two given distinct vertices. The -Hamiltonian Cycle problem requires and also a permitted walk from to . For digraphs, walks must respect arc directions. Witnessing walks are independent and may repeat vertices or pass through any vertex of the ordering. A single vertex is a Hamiltonian path; empty inputs and other bounded-order cases are handled directly. Unless stated otherwise, paths have at least two vertices and cycles at least three. Directed cycles used to pad walks may have length one or two.
All NP-hardness reductions below are polynomial-time many-one (Karp) reductions. Undecidability uses computable many-one reductions. No representation of the fixed set is part of an input.
Definition 1 (Compatibility graph or digraph). For an undirected graph , let be the simple graph on in which distinct are adjacent precisely when an – walk in has a length in . For a digraph , define the loopless digraph analogously, using directed walks from to .
Each -Hamiltonian problem on is exactly its ordinary Hamiltonian counterpart on . For every fixed undirected , this graph can be constructed in polynomial time: breadth-first search in the parity lift , with edges for , finds the shortest walks of each parity; their lengths are compared with the fixed prefixes of . For finite directed , exact-length reachability up to likewise constructs in polynomial time (the empty set gives no arcs). Consequently, all three problems belong to NP for every fixed undirected and every fixed finite directed : a certificate is an ordering of , checked in . Below, NP-hardness therefore suffices to establish NP-completeness in these cases. For infinite directed sets, constructing need not be decidable.
Undirected Graphs: NP-Completeness
We prove NP-completeness for finite odd prefixes and many-one NP-completeness for , settling the outstanding undirected hardness cases [1].
Finite odd prefixes
We settle the sole remaining family in the cycle classification of [1]: every finite nonempty odd prefix gives NP-completeness for cycles and both path variants.
Theorem 2 (Finite odd prefixes). For every fixed finite odd , all three -Hamiltonian problems are NP-complete. The cycle problem remains NP-complete on connected bipartite graphs of maximum degree at most ; both path variants remain NP-complete on connected bipartite graphs of maximum degree at most .
The reduction forces each vertex gadget to be traversed consecutively. The following elementary count will also be used in the directed reduction.
A run of a vertex set on a path or cycle is a maximal consecutive segment of contained in . If is directed, its runs are the connected components of the subgraph induced by in the underlying undirected graph of ; all traversals must still respect the arc directions.
A block is a designated set of vertices of the reduction; it need not be consecutive in an arbitrary ordering. Its runs are the consecutive pieces in which the ordering visits it (Figure 1).

Figure 1. One block visited in three runs by a spanning path . The block is the fixed set of coloured vertices, whereas each outlined run is a maximal consecutive segment of contained in that set. The reductions use the counting lemma to force a single run per block.
Lemma 3. Let be a Hamiltonian path or cycle in a graph or digraph , and let be a nonempty proper subset of . Suppose that is independent and all neighbours of vertices in belong to ; in the directed case this includes both in- and out-neighbours. Let be the number of endpoints of in (zero for a cycle), and let count the edges or arcs of with both ends in . Then the number of -runs is
In particular, if and , then is one run. If is also independent, then .
Proof. Since is proper, the edges of induced by form a linear forest with components. Every edge of incident with stays in , so this forest has exactly edges. Consequently, , proving (1). In the stated special case, .
Proof. We reduce from Hamiltonian Cycle on grid graphs, and from Hamiltonian Path with prescribed endpoints on grid graphs; both source problems are NP-complete [7]. Let be the source graph. For cycles, assume that is connected, has at least three vertices, and has minimum degree at least two. For paths, let be the prescribed endpoints, and assume that is connected, every non-endpoint has degree at least two, and both endpoints have positive degree. Inputs violating these necessary conditions are mapped to fixed no-instances. The path on three vertices is such a cycle no-instance, and the claw is such a path no-instance, for every . Recall that grid graphs are bipartite and have maximum degree four.
Construction.
Put . For every source edge , introduce a private path of length with terminals and . For each endpoint of , let consist of the vertices at even distance from along . Thus , and partition . Define
Choose for the cycle reduction and for the path reductions. Add a set of vertices, each adjacent to every terminal with . Set , and call the resulting graph . For prescribed paths choose and . All sets are nonempty by the assumptions on the source.
The sets partition , and the construction has linear size for fixed . A bipartition of extends by placing on the side of and on the opposite side. The graph is connected. A terminal has degree , a vertex in has degree , and other vertices have degree two. These observations give the asserted degree bounds.
Figure 2 illustrates the replacement of a source vertex and its incident edges for .
Figure 2. The undirected odd-prefix reduction for , around a source vertex of degree four. Each source edge is replaced by a private length-three corridor. Red vertices form : the even positions on each incident corridor. The seven green vertices form in the cycle construction and are each joined to all four terminals . For the path construction, an endpoint gadget has one additional vertex in .
Let .
Claim 4. For every source vertex and every , , and both and are independent in . Moreover, an edge of between different blocks has its ends in and satisfies . For every source edge , the terminals are adjacent in .
Proof. Every vertex of is reachable from by an odd walk of length at most : move to the appropriate terminal and then an even number of steps along its corridor. Conversely, a walk of length at most starting in cannot traverse an entire incident corridor and reach its far terminal: that requires at least steps. It remains within and the incident corridors on the side of their far terminals. Among these vertices, precisely those in have the opposite bipartition colour from . Thus an odd walk of length at most can end only in . Each of and is monochromatic, and hence independent in .
It remains to exclude compatibility between and when is not a source edge. If lie on the same side of the bipartition of , their -sets have the same colour and no odd walk joins them. Suppose therefore that lie on opposite sides and are nonadjacent. Identify all vertices of each into a single vertex . This preserves distances between corridor vertices: a passage through can be lifted through any vertex of . The quotient is the uniform subdivision of in which each source edge has length .
Take and . The distances from to the two ends of its subdivided source edge are at least , respectively; the analogous lower bounds for and are . Bipartiteness and the nonadjacency of give
Any – path must leave the first subdivided edge and enter the second through their ends. Its length is therefore at least the minimum of , , , and , which exceeds . Thus no odd walk of length at most joins to . Finally, itself witnesses the asserted terminal edge. ◀
Cycle correctness.
For , every block induces in . A Hamiltonian cycle of can be expanded at each into a spanning alternating path of between the two terminals used by that cycle. The terminal edges from Claim 4 join these block paths into a Hamiltonian cycle of . Conversely, Lemma 3 makes every a single run on any Hamiltonian cycle of . Contracting the runs gives a Hamiltonian cycle of , because every inter-block edge follows a source edge.
Path correctness.
For , the two endpoint blocks induce , whereas all other blocks induce . A Hamiltonian – path of expands into a Hamiltonian – path of : use an alternating path from to the required terminal in , an alternating path from the required terminal to in , and terminal-to-terminal alternating paths in the remaining blocks.
For the reverse direction, let be any Hamiltonian path of . For each endpoint block, equation (1) gives , since its two parts have equal size and is independent. Hence has one endpoint in and the other in . Both endpoint blocks are single runs by the same lemma. Contracting the runs gives a Hamiltonian – path of . This proves both path reductions, including the unrestricted variant.
The length set
Here we give polynomial-time many-one reductions, strengthening the Cook hardness result of [1] for cycles and prescribed endpoints. The construction also establishes hardness with unrestricted endpoints.
Theorem 5. All three -Hamiltonian problems are -complete on planar graphs of maximum degree four.
We first isolate the two ingredients of the reduction. The first is the pendant-path construction underlying the classical hardness of Hamiltonicity in graph squares [11].
Lemma 6. Let be a graph of order at least three, and obtain by adding, for each , new vertices and edges . Then is Hamiltonian if and only if is Hamiltonian. Moreover, every Hamiltonian cycle of contains every edge .
Proof. In , the vertex has precisely the neighbours . A Hamiltonian cycle must therefore use both incident edges. It cannot also use , because these three edges would form a proper cycle. The other cycle neighbour of consequently belongs to . There is one such choice for each source vertex, and each original vertex has only one remaining cycle incidence after its edge to . These choices therefore use all remaining incidences at original vertices. Hence all cycle edges outside the paths join to a neighbour of in . Contracting these paths gives a Hamiltonian cycle of . Conversely, expand every vertex of a Hamiltonian cycle of into , oriented in the cycle order. The connecting edge from to the next original vertex exists in .
For a graph and an edge , construct as follows. Start with the incidence graph of : replace each vertex by a node , each edge by a vertex , and add . Write . Add seven vertices and the edges
This is the incidence gadget of Amarilli, Lombardo, and Monet [1 Proposition 4.2]; see Figure 3.
Figure 3. The gadget attached to the incidence graph of . The incidence edges are omitted. The cycle reduction uses one copy. The path reductions use three copies, joined by edges between their vertices.
Lemma 7 (Incidence gadget). Let . Then (i) is naturally isomorphic to ; (ii) every neighbour of outside belongs to ; (iii) and . If has a Hamiltonian cycle containing , then has a Hamiltonian cycle containing .
Proof. For the three structural assertions, an even walk of length at most four starting at a node cannot reach or ; each is at distance at least five from . In the remaining bipartite graph, the vertices on the node side are exactly . Length-two and length-four walks through the incidence graph encode adjacency in . The only additional node-to-node route of length at most four is , which adds no new pair because . The same inspection gives the two displayed neighbourhoods.
For completeness, we record why the forward construction can retain . Under the forward hypothesis, is connected. Add a vertex adjacent to in , and a new leaf adjacent to , obtaining . Its incidence graph is the subgraph of on all vertices except , with represented by and the edges by . The line-graph square lemma of [1 Lemma 4.3] states that, in a connected graph with at least three edges, the square of its line graph has a Hamiltonian cycle containing any specified pair of distinct edges joined by a length-two walk in the line graph. Apply it to , using the intermediate edge . Deleting the resulting closing edge gives a path in from to spanning all incidence-edge vertices, including .
Write the given node cycle as . Then
is a Hamiltonian cycle in . Here includes both its endpoints. The new transitions are witnessed, respectively, by
All have length two or four. The second witness deliberately repeats , as the definition permits walks rather than paths. ◀
Proof of Theorem 5. We reduce from Hamiltonian Cycle on planar cubic graphs, which is NP-complete [5]. Let be such a source instance and construct as in Lemma 6. Choose any and set , . Construct .
The graph is planar and has maximum degree four. Its incidence graph is planar, and the additional gadget can be embedded in a face incident with the pendant incidence path . The attachments increase the node degrees at and to three and two, respectively; the other node degrees are at most four, and all added vertices have degree at most three. Thus is planar of maximum degree four. An embedding can be chosen with on the outer face.
Claim 8. Let be a Hamiltonian cycle in , or a Hamiltonian path with neither endpoint in . Then is a single run on , and its two external neighbours are . Consequently, has a Hamiltonian cycle.
Proof. Every -run needs two edges to the interface . There are at most four such edges. If there were two runs, all cycle or path incidences of both interface vertices would be used by these runs; would then contain a cycle. This is impossible for a path, and for a Hamiltonian cycle it would omit other vertices of . There is therefore one run. Its two external neighbours are distinct, since attaching both ends to one interface vertex would again form a proper cycle.
By Lemma 7, the node run is a Hamiltonian path of with one endpoint in and the other in . The endpoints are distinct and at distance at most two in , since . Joining them closes a Hamiltonian cycle of . ◀
The cycle reduction now follows. A Hamiltonian cycle of gives one in containing , and Lemma 7 lifts it to . Conversely, Claim 8 and Lemma 6 recover a Hamiltonian cycle of .
For the path variants, take three disjoint copies , , of and add and . Denote the result by and, for the prescribed-endpoint variant, choose and . The graph is planar, and its maximum degree is still four: only receives two extra edges, increasing its degree from two to four.
Every node of is at distance at least five from . Hence an even walk of length at most four starting at a node cannot use an added edge. The three structural assertions of Lemma 7, and Claim 8, therefore remain valid for each node set in .
If is Hamiltonian, choose in each copy the Hamiltonian cycle containing supplied by the lifting lemma. Delete that edge to obtain a spanning path from to . Concatenate the three paths using the length-two walks , , , for . This gives an – Hamiltonian path in the compatibility graph. Conversely, any Hamiltonian path, regardless of its endpoints, has neither endpoint in at least one of the three sets . Claim 8 for that copy gives a Hamiltonian cycle of , and hence of . All constructions have linear size.
Undirected Graphs: Algorithms and Classification
We give linear-time tests for all remaining undirected cases and complete the classification in Table 1.
| Normalised set | Cycle | Prescribed-endpoint path | Unrestricted path |
| NP-complete [9] | NP-complete [7] | NP-complete [7] | |
| , finite odd | NP-complete (Thm. 2) | NP-complete (Thm. 2) | NP-complete (Thm. 2) |
| NP-complete [1, 2] | NP-complete [1, 2] | NP-complete [1, 2] | |
| NP-complete (Thm. 5) | NP-complete (Thm. 5) | NP-complete (Thm. 5) | |
| NP-complete [11] | NP-complete [2] | NP-complete [2] | |
| , or | Linear time [1, 2] | Linear time (Thm. 9) | Linear time [1, 2] |
| , or | Trivial [1, 2] | Linear time [1, 2] | Trivial [2] |
| Trivial [8] | Trivial [8] | Trivial [8] | |
| Linear time [1, 2] | Linear time [1, 2]† | Linear time [1, 2]† | |
| Trivial | Trivial | Trivial |
Table 1. The complete undirected classification. Entries marked † follow by adapting the proof of Theorem 7.1 in [2]. NP-completeness uses many-one reductions. “Trivial” means a constant answer on connected inputs of the relevant minimum order (yes for the mixed rows, no for the empty set); checking connectedness takes linear time. For the empty set, the unrestricted path problem accepts exactly the one-vertex inputs, whereas the prescribed-endpoint problem has no yes-instances.
An allowed walk cannot join different connected components. Thus every nontrivial spanning instance first requires connectedness. In this section, graphs have at least three vertices; smaller instances are handled directly.
Even prefixes containing six
We show that connectedness and non-bipartiteness characterise all three problems for even prefixes containing six, resolving the prescribed-endpoint case left open in [1]. The key observation is that the -compatibility graph is the cube of the common-neighbour graph , which is connected exactly when is connected and non-bipartite. Karaganis’s theorem then gives Hamiltonian-connectedness, yielding all three variants.
Theorem 9. Suppose that for even , or for . For each of the three undirected -Hamiltonian problems, an input is a yes-instance if and only if it is connected and non-bipartite. These tests take linear time.
Lemma 10. For every integer , . Moreover, if , then is connected if and only if is connected and non-bipartite.
Proof. An even walk of length in yields a sequence of every second vertex. Consecutive distinct vertices in that sequence are adjacent in ; deleting consecutive repetitions gives a walk of length at most . Conversely, each edge of a path in can be replaced by a length-two walk in . This proves the equality.
If is disconnected, so is . If is connected and bipartite, no edge of joins its two nonempty parts. If is connected and non-bipartite, every pair of vertices has an even walk: take any walk between them, and, if necessary, insert a detour through an odd cycle to change its parity. Taking every second vertex then joins the pair in .
Proposition 11 (Karaganis [8]). For every connected graph with at least three vertices, has a Hamiltonian path between any prescribed pair of distinct vertices. It therefore also has an unrestricted Hamiltonian path and a Hamiltonian cycle: choose adjacent endpoints and close the spanning path with their edge. Equivalently, admits all three -Hamiltonian variants.
Proof of Theorem 9. If is connected and non-bipartite, Lemma 10 and Proposition 11 show that is Hamiltonian-connected. The same holds for its supergraph . This gives both path variants. Choosing adjacent endpoints of a Hamiltonian path and closing it gives a Hamiltonian cycle. Conversely, disconnectedness prevents a spanning ordering, and in a bipartite graph every even walk stays within one part. Connectedness and bipartiteness can be tested in time; there is no need to construct the possibly dense compatibility graph.
Completing the classification
Combining the preceding results with the inherited hardness cases gives the complete dichotomy in Table 1: all three problems are NP-complete in its hard rows and linear-time solvable otherwise. It suffices to classify , as explained in the introduction. The finite odd-prefix cases follow from Theorem 2, and the cases from Theorem 5. For , the cycle and prescribed-endpoint hardness results are established in [1 Theorems 3.5 and 4.1], and the unrestricted path result in [2 Theorem E.2]. The cycle result is classical [11]; both path variants are covered in [2 Appendix E.2]. These are many-one hardness results.
For exhaustiveness, an odd-only nonempty normalised set is for finite odd or . An even-only nonempty normalised set is , , or contains . A mixed normalised set either equals , contains , or has the form with , including infinity. The remaining cases are therefore covered by Theorem 9 and the known odd-only and mixed-parity tractability results [1, 2]. The empty set permits no transition between distinct vertices and is trivial. All tractable tests are linear-time. An infinite has an infinite parity prefix and cannot belong to the hard rows of Table 1.
Directed Graphs: Finite Length Sets
We answer the finite directed-set question raised in [1]: every nonempty finite set gives NP-completeness.
Hardness on oriented graphs
Every fixed finite nonempty set gives NP-completeness for all three directed problems, even without loops or antiparallel arcs.
Theorem 12. For every fixed finite nonempty , all three directed -Hamiltonian problems are NP-complete on oriented graphs.
Proof. We first specify the source problems. Directed Hamiltonian Cycle is NP-complete [9], even after restricting the source to oriented graphs: replace each vertex by and each arc by . Every Hamiltonian cycle traverses each triple consecutively, so contraction and expansion prove equivalence. For paths, split a vertex of an oriented cycle instance into a source and a sink : replace by and by . Cutting and closing at proves NP-hardness of Hamiltonian - Path on oriented graphs satisfying . Every Hamiltonian path of such a graph necessarily starts at and ends at .
Put . The case is settled by these source reductions, so assume . Let be the appropriate oriented source instance.
Construction.
For each , introduce layers , for . Orient each layer as a directed triangle, and add all arcs from every layer to the next. Put , so . Add a set of vertices, all arcs from to , and all arcs from to . Write
For each source arc , add . There are no other arcs. Call the result . It is oriented: first and last layers are distinct, all inter-layer arcs point forward, and no added inter-block arc has its reverse. Its size is linear in the source size for fixed . For the prescribed-endpoint variant choose , ; the unrestricted-endpoint variant uses the same .
Figure 4 shows one vertex gadget and an outgoing arc corresponding to a source arc.

Figure 4. The directed vertex gadget, illustrated for . Each layer is a directed triangle. Each thick arrow represents all arcs between the indicated sets: to the first layer, each layer to the next, and the last layer to ; connections to both displayed vertices of are shown, and the same connections apply to every omitted vertex. The thin outgoing arc is .
Let .
Claim 13. For every , . Every inter-block arc of goes from to for some , and every such source arc gives . Finally, for any distinct , has a spanning directed – path.
Proof. Fix . To walk from to in exactly steps, enter the first layer, take steps around its triangle, and cross layer boundaries. The entry vertex can be chosen freely, and complete forward adjacency allows the prescribed final vertex. For a walk from to , cross the remaining boundaries, take steps around the last triangle, and move to . Both walks have length .
A walk from to a vertex outside , or from outside to , needs at least steps: it must pass through the entire sequence of layers and use an additional incident arc. Thus the stated neighbourhoods are exact. A walk of length at most cannot use two inter-block arcs, since between them it must cross layer boundaries. Every inter-block compatibility arc therefore follows one source arc. Conversely, walking from through the layers to and then to takes exactly steps when . Finally, the complete adjacency in both directions between and , with , gives the required spanning alternating path between any two distinct vertices of .
Cycle correctness.
A Hamiltonian cycle of expands into one of by replacing each with a spanning – path in its block and using the arcs between consecutive blocks. Conversely, in any Hamiltonian cycle of , Lemma 3 makes every block a single run. This use of the lemma does not require to be independent. Contracting the runs gives a Hamiltonian cycle of by Claim 13.
Path correctness.
A Hamiltonian – path of expands in exactly the same way to a Hamiltonian – path of . Conversely, consider any Hamiltonian path of . No inter-block arc enters , and none leaves . Thus the path traverses all of as its initial segment and all of as its final segment. Neither global endpoint lies in any other block, so Lemma 3 makes every remaining block a single run. Contraction gives a Hamiltonian – path of . This proves the reverse implication even without prescribed target endpoints. ◀
Directed Graphs: Infinite Length Sets
Infinite directed sets admit linear-time solvability, NP-completeness, or undecidability, as the three constructions below show.
Cofinite sets: linear-time characterisations
For cofinite sets, strong connectivity characterises cycles, and a condition on the condensation characterises paths, giving linear-time algorithms for all three problems.
A set is cofinite if it contains every sufficiently large integer. The condensation is the acyclic digraph obtained by contracting each strongly connected component and deleting loops.
Theorem 14. Fix a cofinite set , and let be a digraph.
(i) For , has an -Hamiltonian cycle if and only if it is strongly connected.
(ii) For , take any topological ordering of its strongly connected components. An unrestricted -Hamiltonian path exists if and only if, for every , the condensation has the arc and, whenever both components consist of a single vertex without a loop, .
(iii) A path with distinct prescribed endpoints exists if and only if the conditions in (ii) hold and , .
All three problems have linear-time decision algorithms.
Lemma 15 (Cofinite padding). Let be cofinite. If a directed walk from to can pass through a directed cycle, then a directed – walk has length in .
Proof. Insert arbitrarily many traversals of that cycle. The resulting walk lengths are unbounded, so some lie beyond the threshold of . ◀
Proof of Theorem 14. For (i), concatenating the witnessing walks of an -Hamiltonian cycle shows that every vertex can reach every other. Conversely, in a strongly connected digraph of order at least two, every ordered pair can be joined through a directed cycle. By Lemma 15, is the complete loopless digraph, proving the assertion.
For the necessity in (ii), let be an -Hamiltonian path. Once its ordering leaves a strongly connected component, it cannot return: the two relevant witnessing walks would put the intervening vertices in that component. Thus the components occur as consecutive blocks. Concatenating witnesses shows that each earlier component reaches every later one. Consequently the condensation has a unique topological ordering, namely the block order. Consecutive components in this order must have a direct arc, since no intermediate component can lie between them. If two consecutive components are single vertices and without loops, the only possible – walk is the single arc: a longer walk would either traverse an intermediate component or create a cycle in one of the two singleton components. Hence is necessary. The first and last components must contain in the prescribed case.
Conversely, suppose the stated conditions hold. List the components in the given order. Within every component containing at least two vertices, any pair of distinct vertices is compatible by Lemma 15, so its vertices can be ordered arbitrarily. Between consecutive components, any chosen last and first vertices can be joined by a directed walk using the condensation arc. If either component contains at least two vertices or a loop, this walk can pass through a directed cycle and can be padded to an allowed length. Otherwise both components are single vertices without loops and the transition is a single arc, allowed by . Concatenating these orders gives the required path. In (iii), start the first component at and end the last at ; when , choose both ends of that component accordingly.
Compute the strongly connected components, record their sizes and any loops, and topologically sort the condensation. A scan of the arcs marks every pair of consecutive components that is joined by an arc. Checking these marks, the component sizes and loops, and the endpoints takes time. No transitive closure or enumeration of endpoint pairs is needed.
An Infinite Length Set Giving NP-Completeness
The fixed infinite set gives NP-completeness for all three directed problems, even on strongly connected bipartite oriented graphs.
Theorem 16. For the fixed infinite set , all three directed -Hamiltonian problems are NP-complete, even on strongly connected bipartite oriented graphs.
Proof. To test for an odd-length directed walk from to , replace each vertex by and each arc by the arcs and . Every step flips the second coordinate, so such a walk exists exactly when is reachable from . Ordinary graph search tests this in polynomial time. Length-two walks are tested by checking for an intermediate vertex. Together these tests construct in polynomial time, proving membership in NP on arbitrary digraphs.
We reduce from Hamiltonian Path on connected undirected graphs [4]. Let be the symmetric orientation of a connected source graph: each edge gives both opposing arcs. A directed path cover partitions the vertices into directed paths, where singleton paths are allowed; let be the minimum number of paths in such a cover of . The source is a yes-instance precisely when .
Construction.
Fix and an integer , to be chosen below. Subdivide every arc by a distinct vertex , giving . Add vertices and , and add exactly the following further arcs:
Call the resulting digraph . It is oriented: opposite source arcs use distinct subdivision vertices, and none of the added gadget arcs has its reverse. It is bipartite, with parts
It is strongly connected: the subdivided copy of is strongly connected, it reaches through , reaches it through , and each added leaf vertex is linked to through . Put .
Figure 5 illustrates the construction around when form a triangle in the source graph.

Figure 5. The construction for the infinite directed set , with a source triangle on . Blue vertices belong to and orange vertices to . Each source edge gives two opposing arcs, each subdivided by its own orange vertex. The gadget attaches to the source only at ; every has arcs to and from . Only are drawn.
In , all arcs in both directions between and are present: strong connectivity gives walks between every ordered pair, and bipartiteness makes every such cross-part walk odd. Within , the only permitted length is two. Inspection of the construction shows that consists precisely of , the bidirected edges for , and the bidirected edge .
Claim 17. .
Proof. For the upper bound, use the path , the other leaves as singleton paths, and a minimum path cover of . For the lower bound, consider the unique cover path containing . If it avoids , it contains at most two leaves. Together with the other singleton leaves, this gives at least paths disjoint from . If it meets , it contains at most one leaf: reaching uses one incidence at through . At least leaves then remain singleton paths. In either case, a cover path meeting contains a single contiguous segment of , because the only attachment is at and a path cannot repeat . Restricting the paths that meet therefore gives a path cover of , and at least such paths are needed. Adding the disjoint paths proves the lower bound.
The three variants
Choose the value of as follows:
| Target variant | Maximum number of -runs | |
| Cycle | ||
| Path prescribed from to | ||
| Unrestricted-endpoint path |
Table 1 (PDF p. 15).
Indeed, vertices outside separate at most cyclic runs, at most runs of a path with both endpoints in , and at most runs of an arbitrary path. These runs form a path cover of . Thus a yes-instance of the chosen target variant implies , and Claim 17 yields .
Conversely, if , then . Let be a cover of this size. Every transition between an -path and a vertex of is available in both directions. For cycles, alternate the paths with all vertices of . For prescribed paths, start at , alternate the paths with the vertices of , and end at . For unrestricted paths, alternate the paths with the vertices of , beginning and ending with a path. This proves the forward implications. Each construction has linear size, establishing all three many-one reductions.
Undecidability for a Recursive Length Set
We construct a fixed recursive infinite set for which all three directed problems are undecidable, even on strongly connected oriented graphs.
Theorem 18. There is a fixed recursive infinite set for which all three directed -Hamiltonian problems are undecidable, even on strongly connected oriented graphs.
The last construction separates membership in a length set from the ability to determine whether that set contains a feasible walk length.
Lemma 19 (Divisibility gadget). Let , and construct from an independent set and vertices by adding all arcs , all arcs , and the directed path . For any fixed containing , the following are equivalent:
(i) contains a positive multiple of ;
(ii) has an -Hamiltonian cycle;
(iii) has an -Hamiltonian path from to ;
(iv) has an unrestricted -Hamiltonian path.
Each gadget is strongly connected and loopless, and has vertices and arcs for the two stated values of .
Proof. Every positive-length walk from one vertex of to another has length a positive multiple of , since it must traverse the entire -path between successive visits to . Conversely, every positive multiple of occurs between every ordered pair in .
If (i) holds, all transitions between distinct vertices of are allowed. Consider the ordering
The transitions inside use an allowed multiple of , and the remaining transitions use length one. For , the ordering gives the path in (iii), and closing at gives the cycle in (ii). For , it gives (iv).
If (i) fails, is independent in the compatibility digraph. In a cycle with , all vertices of need distinct successors among only vertices outside , which is impossible. The same count applies to a path ending at , since no vertex of is the final vertex. For an unrestricted path with , at most one vertex of can be final, leaving at least vertices that again need distinct successors among vertices. This excludes (ii)–(iv). Strong connectivity, looplessness, and the size bounds are immediate from the construction.
Proof of Theorem 18. Fix an effective enumeration of Turing machines run on empty input, and let be the th odd prime. Define
This set is infinite because it contains all positive powers of two. It is recursive: test whether an input is 1 or a power of two; otherwise factor it. The only remaining possible form is with an odd prime and . Compute the index of among the odd primes and simulate for steps. This is a terminating membership test; no polynomial-time bound is asserted or needed.
Unique prime factorisation gives
Indeed, among the integers in (3), only numbers of the form are divisible by , and such a number is included exactly when a sufficiently long finite simulation witnesses halting. Given , compute and apply Lemma 19 with . Equation (4) reduces the halting problem to the cycle and prescribed-endpoint problems on , and to the unrestricted-endpoint problem on . Since , the vertices and are distinct, and the gadgets contain no antiparallel arcs. These are therefore computable many-one reductions to finite strongly connected oriented graphs. The undecidability of halting [10] proves the theorem.
Declaration of AI use
A preliminary version of Theorem 12 was obtained manually using a construction with loops. GPT 6 Pro was used to extend this result to oriented graphs and to obtain all other new results in this paper. The authors take full responsibility for the content of the paper.
References
- [1]Antoine Amarilli, Arthur Lombardo, and Mikaël Monet. The S-hamiltonian cycle problem. In Jan Goedgebeur and Pawel Rzążewski, editors, 52nd International Workshop on Graph-Theoretic Concepts in Computer Science (WG 2026), volume 376 of Leibniz International Proceedings in Informatics (LIPIcs), pages 51–:15, Dagstuhl, Germany, 2026. Schloss Dagstuhl – Leibniz-Zentrum für Informatik.
- [2]Antoine Amarilli, Arthur Lombardo, and Mikaël Monet. The S-hamiltonian cycle problem. arXiv:2602.16532v2, May 2026. Full version, version 2.arxiv.org/abs/2602.16532
- [3]David L. Applegate, Robert E. Bixby, Vašek Chvátal, and William J. Cook. The Traveling Salesman Problem: A Computational Study. Princeton Series in Applied Mathematics. Princeton University Press, 2006.
- [4]Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman, San Francisco, 1979.
- [5]Michael R. Garey, David S. Johnson, and Robert Endre Tarjan. The planar Hamiltonian circuit problem is NP-complete. SIAM Journal on Computing, 5(4):704–714, 1976.DOI
- [6]Ronald J. Gould. Advances on the Hamiltonian problem—a survey. Graphs and Combinatorics, 19(1):7–52, 2003.DOI
- [7]Alon Itai, Christos H. Papadimitriou, and Jayme Luiz Szwarcfiter. Hamilton paths in grid graphs. SIAM Journal on Computing, 11(4):676–686, 1982.DOI
- [8]Jerome J. Karaganis. On the cube of a graph. Canadian Mathematical Bulletin, 11(2):295–296, 1968.DOI
- [9]Richard M. Karp. Reducibility among combinatorial problems. In Raymond E. Miller, James W. Thatcher, and Jean D. Bohlinger, editors, Complexity of Computer Computations, pages 85–103. Plenum Press, New York, 1972.
- [10]Alan M. Turing. On computable numbers, with an application to the Entscheidungsproblem. Proceedings of the London Mathematical Society, s2-42(1):230–265, 1937.
- [11]P. Underground. On graphs with Hamiltonian squares. Discrete Mathematics, 21(3):323, 1978.DOI

