betaFeedback

WorksComputer Science

The Complexity of Hamiltonian Cycles and Paths with Prescribed Walk Lengths

Abstract

Fix a set SS of positive integers. An SS-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 SS. 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 SS and admit linear-time algorithms when SS is cofinite. For other fixed infinite sets SS, we establish NP-complete and undecidable cases, with undecidability occurring even when SS is recursive.

2012 ACM Subject Classification Theory of computation →\to Problems, reductions and completeness; Mathematics of computing →\to 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 S⊆N>0S \subseteq\mathbb{N}_{>0}. An SS-Hamiltonian cycle is a cyclic ordering of all vertices in which every consecutive pair is joined by a walk of length in SS. We also consider SS-Hamiltonian paths, both with prescribed endpoints and with unrestricted endpoints. For a digraph, every witnessing walk must respect the arc directions. Throughout the paper, SS 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 tt can be extended to length t+2it+2i for every integer i≥0i \ge0 by inserting back-and-forth traversals of an edge. Hence the undirected problems for SS are identical to those for its normalisation, the parity-preserving downward closure

cl⁡2(S)={r∈N>0:∃ℓ∈S, r≤ℓ, r≡ℓ(mod2)}.\operatorname{cl}_{2}(S) = \{r \in\mathbb{N}_{>0} : \exists\ell\in S,\ r \le\ell,\ r \equiv\ell\pmod{2}\}.

We call SS normalised when S=cl⁡2(S)S = \operatorname{cl}_{2}(S). Such a set is a union of an odd prefix and an even prefix: write Ok={1,3,…,k}O_k = \{1, 3, \ldots, k\} for odd kk, Eh={2,4,…,h}E_h = \{2, 4, \ldots, h\} for even hh, and O∞,E∞O_\infty, E_\infty for the entire positive odd and even classes. Either prefix may also be empty.

Context and previous work.

Amarilli, Lombardo, and Monet introduced the SS-Hamiltonian variant of Hamiltonicity and studied its complexity on undirected graphs [1, 2]. For normalised sets, their cycle classification gives NP-completeness for {1}\{1\}, {1,2}\{1, 2\}, and {2}\{2\}, and NP-hardness under Cook reductions for {2,4}\{2, 4\}. The remaining classified cases are linear-time solvable: even prefixes containing {2,4,6}\{2, 4, 6\}, mixed sets containing {1,2,3}\{1, 2, 3\} or {1,2,4}\{1, 2, 4\}, and O∞O_\infty (with the empty set trivial). The first two classical cases follow from ordinary Hamiltonicity and graph squares [9, 11]; the tractability of sets containing {1,2,3}\{1, 2, 3\} follows from the Hamiltonian-connectedness of graph cubes [8].

The finite odd-only prefixes OkO_k with k≥3k \ge3 were the sole remaining family in their cycle classification. For paths, they additionally left open {2,4}\{2, 4\} with unrestricted endpoints and {2,4,6}\{2, 4, 6\} with prescribed endpoints. Their {2,4}\{2, 4\} 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 {2,4}\{2, 4\}, establish NP-completeness under many-one reductions for all three variants. For prescribed-endpoint paths with {2,4,6}\{2, 4, 6\}, 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 SS gives NP-completeness, even on oriented graphs. For infinite sets, cofinite SS 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 restrictionAll three problems
S=∅S = \varnothingTrivial
Finite nonempty SS, oriented graphsNP-complete (Thm. 12)
Cofinite SSLinear time (Thm. 14)
S0={2}∪O∞S_0 = \{2\} \cup O_\infty, strongly connected bipartite oriented graphsNP-complete (Thm. 16)
A recursive infinite S∗S^*, strongly connected oriented graphsUndecidable (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 GSG_S, 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 V(G)V(G) for the vertex set, and E(G)E(G) or A(G)A(G) for the edge or arc set. A walk of length ℓ\ell has ℓ\ell edges or arcs, counted with multiplicity. Its vertices need not be distinct. A path has no repeated vertices. Write G[U]G[U] for the subgraph induced by UU, and NG(v)N_G(v), NG[v]N_G[v] for the open and closed neighbourhoods of vv. In digraphs, NG+(v)N_G^+(v), NG−(v)N_G^-(v) and dG+(v)d_G^+(v), dG−(v)d_G^-(v) 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 GrG^r of an undirected graph joins distinct vertices whose distance in GG is at most rr.

Fix S⊆N>0S \subseteq\mathbb{N}_{>0}. The SS-Hamiltonian Path problem asks whether V(G)V(G) has an ordering v1,…,vnv_1,\ldots,v_n such that each viv_i is joined to vi+1v_{i+1} by a walk of length in SS. The prescribed-endpoint variant additionally requires v1=sv_1=s and vn=tv_n=t, for two given distinct vertices. The SS-Hamiltonian Cycle problem requires n≥3n \ge3 and also a permitted walk from vnv_n to v1v_1. 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 SS is part of an input.

Definition 1 (Compatibility graph or digraph). For an undirected graph GG, let GSG_S be the simple graph on V(G)V(G) in which distinct x,yx,y are adjacent precisely when an xx–yy walk in GG has a length in SS. For a digraph GG, define the loopless digraph GSG_S analogously, using directed walks from xx to yy.

Each SS-Hamiltonian problem on GG is exactly its ordinary Hamiltonian counterpart on GSG_S. For every fixed undirected SS, this graph can be constructed in polynomial time: breadth-first search in the parity lift V(G)×{0,1}V(G) \times\{0,1\}, with edges (u,i)(v,1−i)(u,i)(v,1-i) for uv∈E(G)uv \in E(G), finds the shortest walks of each parity; their lengths are compared with the fixed prefixes of cl⁡2(S)\operatorname{cl}_2(S). For finite directed SS, exact-length reachability up to max⁡S\max S likewise constructs GSG_S in polynomial time (the empty set gives no arcs). Consequently, all three problems belong to NP for every fixed undirected SS and every fixed finite directed SS: a certificate is an ordering of V(G)V(G), checked in GSG_S. Below, NP-hardness therefore suffices to establish NP-completeness in these cases. For infinite directed sets, constructing GSG_S need not be decidable.

Undirected Graphs: NP-Completeness

We prove NP-completeness for finite odd prefixes and many-one NP-completeness for {2,4}\{2,4\}, 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 k≥1k \ge1, all three OkO_k-Hamiltonian problems are NP-complete. The cycle problem remains NP-complete on connected bipartite graphs of maximum degree at most 2(k+1)2(k+1); both path variants remain NP-complete on connected bipartite graphs of maximum degree at most 2(k+1)+12(k+1)+1.

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 QQ on a path or cycle WW is a maximal consecutive segment of WW contained in QQ. If WW is directed, its runs are the connected components of the subgraph induced by Q∩V(W)Q \cap V(W) in the underlying undirected graph of WW; 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).

A block Q visited in three runs by a spanning path W

Figure 1. One block QQ visited in three runs by a spanning path WW. The block is the fixed set of coloured vertices, whereas each outlined run is a maximal consecutive segment of WW contained in that set. The reductions use the counting lemma to force a single run per block.

Lemma 3. Let WW be a Hamiltonian path or cycle in a graph or digraph HH, and let Q=M∪˙DQ = M \mathbin{\dot\cup} D be a nonempty proper subset of V(H)V(H). Suppose that DD is independent and all neighbours of vertices in DD belong to MM; in the directed case this includes both in- and out-neighbours. Let eDe_D be the number of endpoints of WW in DD (zero for a cycle), and let zz count the edges or arcs of WW with both ends in MM. Then the number rr of QQ-runs is

r=∣M∣−∣D∣+eD−z.(1)r = |M| - |D| + e_D - z. \tag*{(1)}

In particular, if ∣D∣=∣M∣−1|D| = |M| - 1 and eD=0e_D = 0, then QQ is one run. If MM is also independent, then z=0z = 0.

Proof. Since QQ is proper, the edges of WW induced by QQ form a linear forest with rr components. Every edge of WW incident with DD stays in QQ, so this forest has exactly 2∣D∣−eD+z2|D| - e_D + z edges. Consequently, r=∣Q∣−(2∣D∣−eD+z)r = |Q| - (2|D| - e_D + z), proving (1). In the stated special case, 1≤r=1−z≤11 \le r = 1 - z \le1.

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 FF be the source graph. For cycles, assume that FF is connected, has at least three vertices, and has minimum degree at least two. For paths, let s≠ts \ne t be the prescribed endpoints, and assume that FF 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 OkO_k. Recall that grid graphs are bipartite and have maximum degree four.

Construction.

Put λ=(k+1)/2\lambda=(k+1)/2. For every source edge e=uve=uv, introduce a private path PeP_e of length kk with terminals tu,et_{u,e} and tv,et_{v,e}. For each endpoint vv of ee, let Bv,eB_{v,e} consist of the vertices at even distance from tv,et_{v,e} along PeP_e. Thus ∣Bv,e∣=λ|B_{v,e}|=\lambda, and Bu,e,Bv,eB_{u,e},B_{v,e} partition V(Pe)V(P_e). Define

Mv=⋃e∋vBv,e,mv=∣Mv∣=λdeg⁡F(v).M_v=\bigcup_{e\ni v}B_{v,e},\qquad m_v=|M_v|=\lambda\deg_F(v).

Choose Z=∅Z=\varnothing for the cycle reduction and Z={s,t}Z=\{s,t\} for the path reductions. Add a set DvD_v of mv−1+1v∈Zm_v-1+1_{v\in Z} vertices, each adjacent to every terminal tv,et_{v,e} with e∋ve\ni v. Set Qv=Mv∪˙DvQ_v=M_v\mathbin{\dot\cup}D_v, and call the resulting graph GZG_Z. For prescribed paths choose α∈Ds\alpha\in D_s and β∈Dt\beta\in D_t. All sets DvD_v are nonempty by the assumptions on the source.

The sets QvQ_v partition V(GZ)V(G_Z), and the construction has linear size for fixed kk. A bipartition of FF extends by placing MvM_v on the side of vv and DvD_v on the opposite side. The graph is connected. A terminal has degree mv+1v∈Zm_v+1_{v\in Z}, a vertex in DvD_v has degree deg⁡F(v)\deg_F(v), 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 k=3k=3.

Figure 2. The undirected odd-prefix reduction for k=3k=3, around a source vertex uu of degree four. Each source edge is replaced by a private length-three corridor. Red vertices form MuM_u: the even positions Bu,eB_{u,e} on each incident corridor. The seven green vertices form DuD_u in the cycle construction and are each joined to all four terminals tu,et_{u,e}. For the path construction, an endpoint gadget has one additional vertex in DuD_u.

Let H=GZOkH=G_Z^{O_k}.

Claim 4. For every source vertex vv and every d∈Dvd\in D_v, NH(d)=MvN_H(d)=M_v, and both DvD_v and MvM_v are independent in HH. Moreover, an edge of HH between different blocks Qu,QvQ_u,Q_v has its ends in Mu,MvM_u,M_v and satisfies uv∈E(F)uv\in E(F). For every source edge e=uve=uv, the terminals tu,e,tv,et_{u,e},t_{v,e} are adjacent in HH.

Proof. Every vertex of MvM_v is reachable from dd by an odd walk of length at most kk: move to the appropriate terminal and then an even number of steps along its corridor. Conversely, a walk of length at most kk starting in DvD_v cannot traverse an entire incident corridor and reach its far terminal: that requires at least k+1k+1 steps. It remains within DvD_v and the incident corridors on the vv side of their far terminals. Among these vertices, precisely those in MvM_v have the opposite bipartition colour from dd. Thus an odd walk of length at most kk can end only in MvM_v. Each of DvD_v and MvM_v is monochromatic, and hence independent in HH.

It remains to exclude compatibility between MuM_u and MvM_v when uvuv is not a source edge. If u,vu,v lie on the same side of the bipartition of FF, their MM-sets have the same colour and no odd walk joins them. Suppose therefore that u,vu,v lie on opposite sides and are nonadjacent. Identify all vertices of each DwD_w into a single vertex cwc_w. This preserves distances between corridor vertices: a passage through cwc_w can be lifted through any vertex of DwD_w. The quotient is the uniform subdivision of FF in which each source edge has length L=k+2L=k+2.

Take x∈Bu,uax\in B_{u,ua} and y∈Bv,vby\in B_{v,vb}. The distances from xx to the two ends cu,cac_u,c_a of its subdivided source edge are at least 1,21,2, respectively; the analogous lower bounds for yy and cv,cbc_v,c_b are 1,21,2. Bipartiteness and the nonadjacency of u,vu,v give

dist⁡F(u,v)≥3,dist⁡F(u,b)≥2,dist⁡F(a,v)≥2,dist⁡F(a,b)≥1.\operatorname{dist}_F(u,v)\ge3,\qquad\operatorname{dist}_F(u,b)\ge2,\qquad\operatorname{dist}_F(a,v)\ge2,\qquad\operatorname{dist}_F(a,b)\ge1.

Any xx–yy path must leave the first subdivided edge and enter the second through their ends. Its length is therefore at least the minimum of 2+3L2+3L, 3+2L3+2L, 3+2L3+2L, and 4+L4+L, which exceeds kk. Thus no odd walk of length at most kk joins xx to yy. Finally, PeP_e itself witnesses the asserted terminal edge. ◀

Cycle correctness.

For Z=∅Z=\varnothing, every block induces Kmv,mv−1K_{m_v,m_v-1} in HH. A Hamiltonian cycle of FF can be expanded at each vv into a spanning alternating path of H[Qv]H[Q_v] between the two terminals used by that cycle. The terminal edges from Claim 4 join these block paths into a Hamiltonian cycle of HH. Conversely, Lemma 3 makes every QvQ_v a single run on any Hamiltonian cycle of HH. Contracting the runs gives a Hamiltonian cycle of FF, because every inter-block edge follows a source edge.

Path correctness.

For Z={s,t}Z=\{s,t\}, the two endpoint blocks induce Kmv,mvK_{m_v,m_v}, whereas all other blocks induce Kmv,mv−1K_{m_v,m_v-1}. A Hamiltonian ss–tt path of FF expands into a Hamiltonian α\alpha–β\beta path of HH: use an alternating path from α\alpha to the required terminal in QsQ_s, an alternating path from the required terminal to β\beta in QtQ_t, and terminal-to-terminal alternating paths in the remaining blocks.

For the reverse direction, let WW be any Hamiltonian path of HH. For each endpoint block, equation (1) gives r=eDv≥1r=e_{D_v}\ge1, since its two parts have equal size and MvM_v is independent. Hence WW has one endpoint in DsD_s and the other in DtD_t. Both endpoint blocks are single runs by the same lemma. Contracting the runs gives a Hamiltonian ss–tt path of FF. This proves both path reductions, including the unrestricted variant.

The length set {2,4}\{2,4\}

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 {2,4}\{2,4\}-Hamiltonian problems are NPNP-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 FF be a graph of order at least three, and obtain JJ by adding, for each v∈V(F)v \in V(F), new vertices av,bva_v,b_v and edges vav,avbvva_v,a_vb_v. Then FF is Hamiltonian if and only if J2J^2 is Hamiltonian. Moreover, every Hamiltonian cycle of J2J^2 contains every edge avbva_vb_v.

Proof. In J2J^2, the vertex bvb_v has precisely the neighbours av,va_v,v. A Hamiltonian cycle must therefore use both incident edges. It cannot also use vavva_v, because these three edges would form a proper cycle. The other cycle neighbour of ava_v consequently belongs to NF(v)N_F(v). There is one such choice for each source vertex, and each original vertex has only one remaining cycle incidence after its edge to bvb_v. These choices therefore use all remaining incidences at original vertices. Hence all cycle edges outside the paths av,bv,va_v,b_v,v join ava_v to a neighbour of vv in FF. Contracting these paths gives a Hamiltonian cycle of FF. Conversely, expand every vertex vv of a Hamiltonian cycle of FF into v,bv,avv,b_v,a_v, oriented in the cycle order. The connecting edge from ava_v to the next original vertex exists in J2J^2.

For a graph JJ and an edge xy∈E(J)xy \in E(J), construct B=B(J,xy)B = B(J,xy) as follows. Start with the incidence graph of JJ: replace each vertex uu by a node u′u', each edge uvuv by a vertex euve_{uv}, and add u′euv,v′euvu'e_{uv},v'e_{uv}. Write N={u′:u∈V(J)}N = \{u' : u \in V(J)\}. Add seven vertices d1,…,d7d_1,\ldots,d_7 and the edges

d1d3, d2d3, d3d4, d4d5, d5d6, d5d7, d6d7,x′d1, y′d2.(2)d_1d_3,\ d_2d_3,\ d_3d_4,\ d_4d_5,\ d_5d_6,\ d_5d_7,\ d_6d_7,\qquad x'd_1,\ y'd_2. \tag*{(2)}

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 JJ. The incidence edges are omitted. The cycle reduction uses one copy. The path reductions use three copies, joined by edges between their d6d_6 vertices.

Lemma 7 (Incidence gadget). Let H=B{2,4}H = B_{\{2,4\}}. Then (i) H[N]H[N] is naturally isomorphic to J2J^2; (ii) every neighbour of NN outside NN belongs to {d3,d5}\{d_3,d_5\}; (iii) NH(d5)∩N={x′,y′}N_H(d_5) \cap N = \{x',y'\} and NH(d3)∩N={u′:u∈NJ[x]∪NJ[y]}N_H(d_3) \cap N = \{u' : u \in N_J[x] \cup N_J[y]\}. If J2J^2 has a Hamiltonian cycle containing xyxy, then HH has a Hamiltonian cycle containing d6d7d_6d_7.

Proof. For the three structural assertions, an even walk of length at most four starting at a node cannot reach d6d_6 or d7d_7; each is at distance at least five from NN. In the remaining bipartite graph, the vertices on the node side are exactly N∪{d3,d5}N \cup\{d_3,d_5\}. Length-two and length-four walks through the incidence graph encode adjacency in J2J^2. The only additional node-to-node route of length at most four is x′,d1,d3,d2,y′x', d_1, d_3, d_2, y', which adds no new pair because xy∈E(J)xy \in E(J). The same inspection gives the two displayed neighbourhoods.

For completeness, we record why the forward construction can retain d6d7d_6d_7. Under the forward hypothesis, JJ is connected. Add a vertex ww adjacent to x,yx,y in JJ, and a new leaf zz adjacent to ww, obtaining J+J^+. Its incidence graph is the subgraph of BB on all vertices except d6,d7d_6,d_7, with w,zw,z represented by d3,d5d_3,d_5 and the edges wx,wy,wzwx,wy,wz by d1,d2,d4d_1,d_2,d_4. 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 wz,wywz,wy, using the intermediate edge wxwx. Deleting the resulting closing edge gives a path WW in HH from d4d_4 to d2d_2 spanning all incidence-edge vertices, including d1,d2,d4d_1,d_2,d_4.

Write the given node cycle as (x,y,v1,…,vt)(x,y,v_1,\ldots,v_t). Then

(x′,d5,W,d6,d7,d3,y′,v1′,…,vt′)(x',d_5,W,d_6,d_7,d_3,y',v'_1,\ldots,v'_t)

is a Hamiltonian cycle in HH. Here WW includes both its endpoints. The new transitions are witnessed, respectively, by

x′d1d3d4d5,d5d6d7d5d4,d2d3d4d5d6,x'd_1d_3d_4d_5,\quad d_5d_6d_7d_5d_4,\quad d_2d_3d_4d_5d_6,
d6d5d7,d7d6d5d4d3,d3d2y′.d_6d_5d_7,\quad d_7d_6d_5d_4d_3,\quad d_3d_2y'.

All have length two or four. The second witness deliberately repeats d5d_5, 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 FF be such a source instance and construct JJ as in Lemma 6. Choose any r∈V(F)r \in V(F) and set x=arx=a_r, y=bry=b_r. Construct B=B(J,xy)B=B(J,xy).

The graph JJ 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 x′,exy,y′x',e_{xy},y'. The attachments increase the node degrees at x′x' and y′y' to three and two, respectively; the other node degrees are at most four, and all added vertices have degree at most three. Thus BB is planar of maximum degree four. An embedding can be chosen with d6d_6 on the outer face.

Claim 8. Let WW be a Hamiltonian cycle in B2,4B_{2,4}, or a Hamiltonian path with neither endpoint in NN. Then NN is a single run on WW, and its two external neighbours are d3,d5d_3,d_5. Consequently, J2J^2 has a Hamiltonian cycle.

Proof. Every NN-run needs two edges to the interface I={d3,d5}I=\{d_3,d_5\}. 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; W[N∪I]W[N \cup I] would then contain a cycle. This is impossible for a path, and for a Hamiltonian cycle it would omit other vertices of BB. 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 J2J^2 with one endpoint in {x,y}\{x,y\} and the other in NJ[x]∪NJ[y]N_J[x] \cup N_J[y]. The endpoints are distinct and at distance at most two in JJ, since xy∈E(J)xy \in E(J). Joining them closes a Hamiltonian cycle of J2J^2. ◀

The cycle reduction now follows. A Hamiltonian cycle of FF gives one in J2J^2 containing xyxy, and Lemma 7 lifts it to BB. Conversely, Claim 8 and Lemma 6 recover a Hamiltonian cycle of FF.

For the path variants, take three disjoint copies B1B_1, B2B_2, B3B_3 of BB and add d61d62d_6^1d_6^2 and d62d63d_6^2d_6^3. Denote the result by GG and, for the prescribed-endpoint variant, choose α=d61\alpha=d_6^1 and β=d63\beta=d_6^3. The graph is planar, and its maximum degree is still four: only d62d_6^2 receives two extra edges, increasing its degree from two to four.

Every node of BiB_i is at distance at least five from d6id_6^i. 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 NiN_i in G{2,4}G_{\{2,4\}}.

If FF is Hamiltonian, choose in each copy the Hamiltonian cycle containing d6id7id_6^id_7^i supplied by the lifting lemma. Delete that edge to obtain a spanning path from d6id_6^i to d7id_7^i. Concatenate the three paths using the length-two walks d7id_7^i, d6id_6^i, d6i+1d_6^{i+1}, for i=1,2i=1,2. This gives an α\alpha–β\beta 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 NiN_i. Claim 8 for that copy gives a Hamiltonian cycle of J2J^2, and hence of FF. 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 setCyclePrescribed-endpoint pathUnrestricted path
O1={1}O_1 = \{1\}NP-complete [9]NP-complete [7]NP-complete [7]
OkO_k, finite odd k≥3k \ge3NP-complete (Thm. 2)NP-complete (Thm. 2)NP-complete (Thm. 2)
{2}\{2\}NP-complete [1, 2]NP-complete [1, 2]NP-complete [1, 2]
{2,4}\{2,4\}NP-complete (Thm. 5)NP-complete (Thm. 5)NP-complete (Thm. 5)
{1,2}\{1,2\}NP-complete [11]NP-complete [2]NP-complete [2]
EhE_h, h≥6h \ge6 or h=∞h = \inftyLinear time [1, 2]Linear time (Thm. 9)Linear time [1, 2]
{1}∪Eh\{1\} \cup E_h, h≥4h \ge4 or h=∞h = \inftyTrivial [1, 2]Linear time [1, 2]Trivial [2]
{1,2,3}⊆cl⁡2(S)\{1,2,3\} \subseteq\operatorname{cl}_2(S)Trivial [8]Trivial [8]Trivial [8]
O∞O_\inftyLinear time [1, 2]Linear time [1, 2]†Linear time [1, 2]†
∅\varnothingTrivialTrivialTrivial

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 {2,4,6}\{2,4,6\} prescribed-endpoint case left open in [1]. The key observation is that the E6E_6-compatibility graph is the cube of the common-neighbour graph G{2}G_{\{2\}}, which is connected exactly when GG is connected and non-bipartite. Karaganis’s theorem then gives Hamiltonian-connectedness, yielding all three variants.

Theorem 9. Suppose that cl⁡2(S)=Eh\operatorname{cl}_2(S)=E_h for even h≥6h\ge6, or for h=∞h=\infty. For each of the three undirected SS-Hamiltonian problems, an input GG is a yes-instance if and only if it is connected and non-bipartite. These tests take linear time.

Lemma 10. For every integer r≥1r\ge1, GE2r=G{2}rG_{E_{2r}}=G_{\{2\}}^r. Moreover, if ∣V(G)∣≥2|V(G)|\ge2, then G{2}G_{\{2\}} is connected if and only if GG is connected and non-bipartite.

Proof. An even walk of length 2j≤2r2j\le2r in GG yields a sequence of every second vertex. Consecutive distinct vertices in that sequence are adjacent in G{2}G_{\{2\}}; deleting consecutive repetitions gives a walk of length at most jj. Conversely, each edge of a path in G{2}G_{\{2\}} can be replaced by a length-two walk in GG. This proves the equality.

If GG is disconnected, so is G{2}G_{\{2\}}. If GG is connected and bipartite, no edge of G{2}G_{\{2\}} joins its two nonempty parts. If GG 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 G{2}G_{\{2\}}.

Proposition 11 (Karaganis [8]). For every connected graph GG with at least three vertices, G3G^3 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, GG admits all three {1,2,3}\{1,2,3\}-Hamiltonian variants.

Proof of Theorem 9. If GG is connected and non-bipartite, Lemma 10 and Proposition 11 show that GE6=G{2}3G_{E_6}=G_{\{2\}}^3 is Hamiltonian-connected. The same holds for its supergraph GSG_S. 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 O(∣V(G)∣+∣E(G)∣)O(|V(G)|+|E(G)|) 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 cl⁡2(S)\operatorname{cl}_2(S), as explained in the introduction. The finite odd-prefix cases follow from Theorem 2, and the {2,4}\{2,4\} cases from Theorem 5. For {2}\{2\}, 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 {1,2}\{1,2\} 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 OkO_k for finite odd kk or O∞O_\infty. An even-only nonempty normalised set is E2E_2, E4E_4, or contains E6E_6. A mixed normalised set either equals {1,2}\{1,2\}, contains {1,2,3}\{1,2,3\}, or has the form {1}∪Eh\{1\}\cup E_h with h≥4h\ge4, 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 SS 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 SS gives NP-completeness for all three directed problems, even without loops or antiparallel arcs.

Theorem 12. For every fixed finite nonempty S⊆N>0S\subseteq\mathbb{N}_{>0}, all three directed SS-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 vv by v−→v0→v+v^{-}\mathbin{\to}v^{0}\mathbin{\to}v^{+} and each arc uvuv by u+v−u^{+}v^{-}. Every Hamiltonian cycle traverses each triple consecutively, so contraction and expansion prove equivalence. For paths, split a vertex rr of an oriented cycle instance into a source ss and a sink zz: replace rvrv by svsv and urur by uzuz. Cutting and closing at rr proves NP-hardness of Hamiltonian ss-zz Path on oriented graphs satisfying d−(s)=d+(z)=0d^{-}(s)=d^{+}(z)=0. Every Hamiltonian path of such a graph necessarily starts at ss and ends at zz.

Put t=max⁡St=\max S. The case t=1t=1 is settled by these source reductions, so assume t≥2t\ge2. Let FF be the appropriate oriented source instance.

Construction.

For each v∈V(F)v \in V(F), introduce tt layers Lv,i={xv,i0,xv,i1,xv,i2}L_{v,i} = \{x_{v,i}^{0}, x_{v,i}^{1}, x_{v,i}^{2}\}, for 0≤i<t0 \le i < t. Orient each layer as a directed triangle, and add all arcs from every layer to the next. Put Mv=⋃iLv,iM_v = \bigcup_i L_{v,i}, so ∣Mv∣=3t|M_v| = 3t. Add a set DvD_v of 3t−13t - 1 vertices, all arcs from DvD_v to Lv,0L_{v,0}, and all arcs from Lv,t−1L_{v,t-1} to DvD_v. Write

Qv=Mv∪˙Dv,av=xv,00,bv=xv,01,τv=xv,t−10.Q_v = M_v \mathbin{\dot\cup} D_v,\qquad a_v = x_{v,0}^{0},\quad b_v = x_{v,0}^{1},\quad\tau_v = x_{v,t-1}^{0}.

For each source arc uvuv, add τuav\tau_u a_v. There are no other arcs. Call the result GG. 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 SS. For the prescribed-endpoint variant choose α=as\alpha= a_s, β=bz\beta= b_z; the unrestricted-endpoint variant uses the same GG.

Figure 4 shows one vertex gadget and an outgoing arc corresponding to a source arc.

The directed vertex gadget, illustrated for $t=3

Figure 4. The directed vertex gadget, illustrated for t=3t = 3. Each layer is a directed triangle. Each thick arrow represents all arcs between the indicated sets: DvD_v to the first layer, each layer to the next, and the last layer to DvD_v; connections to both displayed vertices of DvD_v are shown, and the same connections apply to every omitted vertex. The thin outgoing arc is τvaw\tau_v a_w.

Let H=GSH = G_S.

Claim 13. For every d∈Dvd \in D_v, NH+(d)=NH−(d)=MvN_H^{+}(d) = N_H^{-}(d) = M_v. Every inter-block arc of HH goes from MuM_u to MvM_v for some uv∈A(F)uv \in A(F), and every such source arc gives buav∈A(H)b_u a_v \in A(H). Finally, for any distinct a,b∈Mva,b \in M_v, H[Qv]H[Q_v] has a spanning directed aa–bb path.

Proof. Fix y∈Lv,jy \in L_{v,j}. To walk from dd to yy in exactly tt steps, enter the first layer, take t−j−1t-j-1 steps around its triangle, and cross jj layer boundaries. The entry vertex can be chosen freely, and complete forward adjacency allows the prescribed final vertex. For a walk from yy to dd, cross the remaining t−1−jt-1-j boundaries, take jj steps around the last triangle, and move to dd. Both walks have length t∈St \in S.

A walk from DvD_v to a vertex outside MvM_v, or from outside MvM_v to DvD_v, needs at least t+1t+1 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 tt cannot use two inter-block arcs, since between them it must cross t−1t-1 layer boundaries. Every inter-block compatibility arc therefore follows one source arc. Conversely, walking from bub_u through the layers to τu\tau_u and then to ava_v takes exactly tt steps when uv∈A(F)uv \in A(F). Finally, the complete adjacency in both directions between DvD_v and MvM_v, with ∣Dv∣=∣Mv∣−1|D_v| = |M_v| - 1, gives the required spanning alternating path between any two distinct vertices of MvM_v.

Cycle correctness.

A Hamiltonian cycle of FF expands into one of HH by replacing each vv with a spanning ava_v–bvb_v path in its block and using the arcs buavb_u a_v between consecutive blocks. Conversely, in any Hamiltonian cycle of HH, Lemma 3 makes every block a single run. This use of the lemma does not require MvM_v to be independent. Contracting the runs gives a Hamiltonian cycle of FF by Claim 13.

Path correctness.

A Hamiltonian ss–zz path of FF expands in exactly the same way to a Hamiltonian α\alpha–β\beta path of HH. Conversely, consider any Hamiltonian path of HH. No inter-block arc enters QsQ_s, and none leaves QzQ_z. Thus the path traverses all of QsQ_s as its initial segment and all of QzQ_z 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 ss–zz path of FF. 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 S⊆N>0S \subseteq\mathbb{N}_{>0} 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 SS, and let GG be a digraph.

(i) For ∣V(G)∣≥3|V(G)| \ge3, GG has an SS-Hamiltonian cycle if and only if it is strongly connected.

(ii) For ∣V(G)∣≥2|V(G)| \ge2, take any topological ordering C1,…,CkC_1,\ldots,C_k of its strongly connected components. An unrestricted SS-Hamiltonian path exists if and only if, for every i<ki < k, the condensation has the arc CiCi+1C_iC_{i+1} and, whenever both components consist of a single vertex without a loop, 1∈S1 \in S.

(iii) A path with distinct prescribed endpoints a,ba,b exists if and only if the conditions in (ii) hold and a∈C1a \in C_1, b∈Ckb \in C_k.

All three problems have linear-time decision algorithms.

Lemma 15 (Cofinite padding). Let SS be cofinite. If a directed walk from xx to yy can pass through a directed cycle, then a directed xx–yy walk has length in SS.

Proof. Insert arbitrarily many traversals of that cycle. The resulting walk lengths are unbounded, so some lie beyond the threshold of SS. ◀

Proof of Theorem 14. For (i), concatenating the witnessing walks of an SS-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, GSG_S is the complete loopless digraph, proving the assertion.

For the necessity in (ii), let WW be an SS-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 {u}\{u\} and {v}\{v\} without loops, the only possible uu–vv 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 1∈S1 \in S is necessary. The first and last components must contain a,ba,b 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 1∈S1 \in S. Concatenating these orders gives the required path. In (iii), start the first component at aa and end the last at bb; when k=1k = 1, 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 O(∣V(G)∣+∣A(G)∣)O(\lvert V(G)\rvert+ \lvert A(G)\rvert) time. No transitive closure or enumeration of endpoint pairs is needed.

An Infinite Length Set Giving NP-Completeness

The fixed infinite set S0={2}∪O∞S_0 = \{2\} \cup O_\infty gives NP-completeness for all three directed problems, even on strongly connected bipartite oriented graphs.

Theorem 16. For the fixed infinite set S0={2}∪O∞S_0 = \{2\} \cup O_\infty, all three directed S0S_0-Hamiltonian problems are NP-complete, even on strongly connected bipartite oriented graphs.

Proof. To test for an odd-length directed walk from xx to yy, replace each vertex vv by (v,0),(v,1)(v,0),(v,1) and each arc uvuv by the arcs (u,0)(v,1)(u,0)(v,1) and (u,1)(v,0)(u,1)(v,0). Every step flips the second coordinate, so such a walk exists exactly when (y,1)(y,1) is reachable from (x,0)(x,0). Ordinary graph search tests this in polynomial time. Length-two walks are tested by checking for an intermediate vertex. Together these tests construct GS0G_{S_0} in polynomial time, proving membership in NP on arbitrary digraphs.

We reduce from Hamiltonian Path on connected undirected graphs [4]. Let FF 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 pc⁡(D)\operatorname{pc}(D) be the minimum number of paths in such a cover of DD. The source is a yes-instance precisely when pc⁡(F)=1\operatorname{pc}(F) = 1.

Construction.

Fix r∈V(F)r \in V(F) and an integer h≥2h \ge2, to be chosen below. Subdivide every arc uv∈A(F)uv \in A(F) by a distinct vertex yuvy_{uv}, giving u→yuv→vu \to y_{uv} \to v. Add vertices a,b,c,p,sa,b,c,p,s and ℓ1,…,ℓh\ell_1,\ldots,\ell_h, and add exactly the following further arcs:

ℓia, bℓi (1≤i≤h),ac, cb, cp, pr, rs, sc.\ell_i a,\ b\ell_i\ (1 \le i \le h),\qquad ac,\ cb,\ cp,\ pr,\ rs,\ sc.

Call the resulting digraph GhG_h. 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

Xh=V(F)∪{c,ℓ1,…,ℓh},Y={yuv:uv∈A(F)}∪{a,b,p,s}.X_h = V(F) \cup\{c,\ell_1,\ldots,\ell_h\}, \qquad Y = \{y_{uv}: uv \in A(F)\} \cup\{a,b,p,s\}.

It is strongly connected: the subdivided copy of FF is strongly connected, it reaches cc through r,sr,s, cc reaches it through p,rp,r, and each added leaf vertex is linked to cc through a,ba,b. Put q=∣Y∣=∣A(F)∣+4q = |Y| = |A(F)| + 4.

Figure 5 illustrates the construction around rr when r,u,vr,u,v form a triangle in the source graph.

The construction around r when r, u, v form a triangle in the source graph

Figure 5. The construction for the infinite directed set S0S_0, with a source triangle on r,u,vr,u,v. Blue vertices belong to XhX_h and orange vertices to YY. Each source edge gives two opposing arcs, each subdivided by its own orange vertex. The gadget attaches to the source only at rr; every ℓi\ell_i has arcs to and from bb. Only ℓ1,ℓh\ell_1,\ell_h are drawn.

In (Gh)S0(G_h)_{S_0}, all arcs in both directions between XhX_h and YY are present: strong connectivity gives walks between every ordered pair, and bipartiteness makes every such cross-part walk odd. Within XhX_h, the only permitted length is two. Inspection of the construction shows that Jh=(Gh)S0[Xh]J_h = (G_h)_{S_0}[X_h] consists precisely of FF, the bidirected edges cℓic\ell_i for 1≤i≤h1 \le i \le h, and the bidirected edge crcr.

Claim 17. pc⁡(Jh)=h−1+pc⁡(F)\operatorname{pc}(J_h) = h - 1 + \operatorname{pc}(F).

Proof. For the upper bound, use the path ℓ1,c,ℓ2\ell_1,c,\ell_2, the other h−2h-2 leaves as singleton paths, and a minimum path cover of FF. For the lower bound, consider the unique cover path containing cc. If it avoids FF, it contains at most two leaves. Together with the other singleton leaves, this gives at least h−1h-1 paths disjoint from FF. If it meets FF, it contains at most one leaf: reaching FF uses one incidence at cc through rr. At least h−1h-1 leaves then remain singleton paths. In either case, a cover path meeting FF contains a single contiguous segment of FF, because the only attachment is at rr and a path cannot repeat rr. Restricting the paths that meet FF therefore gives a path cover of FF, and at least pc⁡(F)\operatorname{pc}(F) such paths are needed. Adding the disjoint paths proves the lower bound.

The three variants

Choose the value of hh as follows:

Target varianthhMaximum number of XhX_h-runs
Cycleqqqq
Path prescribed from aa to bbq−1q-1q−1q-1
Unrestricted-endpoint pathq+1q+1q+1q+1

Table 1 (PDF p. 15).

Indeed, qq vertices outside XhX_h separate at most qq cyclic runs, at most q−1q-1 runs of a path with both endpoints in YY, and at most q+1q+1 runs of an arbitrary path. These runs form a path cover of JhJ_h. Thus a yes-instance of the chosen target variant implies pc⁡(Jh)≤h\operatorname{pc}(J_h) \le h, and Claim 17 yields pc⁡(F)≤1\operatorname{pc}(F) \le1.

Conversely, if pc⁡(F)=1\operatorname{pc}(F) = 1, then pc⁡(Jh)=h\operatorname{pc}(J_h) = h. Let P1,…,PhP_1,\ldots,P_h be a cover of this size. Every transition between an XhX_h-path and a vertex of YY is available in both directions. For cycles, alternate the qq paths with all qq vertices of YY. For prescribed paths, start at aa, alternate the q−1q-1 paths with the q−2q-2 vertices of Y∖{a,b}Y \setminus\{a,b\}, and end at bb. For unrestricted paths, alternate the q+1q+1 paths with the qq vertices of YY, 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 S⋆⊆N>0S^\star\subseteq\mathbb{N}_{>0} for which all three directed S⋆S^\star-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 L≥2L \ge2, and construct BL,kB_{L,k} from an independent set D={d1,…,dk}D = \{d_1,\ldots,d_k\} and vertices p1,…,pL−1p_1,\ldots,p_{L-1} by adding all arcs dip1d_i p_1, all arcs pL−1dip_{L-1}d_i, and the directed path p1→⋯→pL−1p_1 \to\cdots\to p_{L-1}. For any fixed SS containing 11, the following are equivalent:

(i) SS contains a positive multiple of LL;

(ii) BL,LB_{L,L} has an SS-Hamiltonian cycle;

(iii) BL,LB_{L,L} has an SS-Hamiltonian path from d1d_1 to pL−1p_{L-1};

(iv) BL,L+1B_{L,L+1} has an unrestricted SS-Hamiltonian path.

Each gadget is strongly connected and loopless, and has O(L)O(L) vertices and arcs for the two stated values of kk.

Proof. Every positive-length walk from one vertex of DD to another has length a positive multiple of LL, since it must traverse the entire pp-path between successive visits to DD. Conversely, every positive multiple of LL occurs between every ordered pair in DD.

If (i) holds, all transitions between distinct vertices of DD are allowed. Consider the ordering

d1,…,dk,p1,…,pL−1.d_1,\ldots,d_k,p_1,\ldots,p_{L-1}.

The transitions inside DD use an allowed multiple of LL, and the remaining transitions use length one. For k=Lk = L, the ordering gives the path in (iii), and closing at d1d_1 gives the cycle in (ii). For k=L+1k = L+1, it gives (iv).

If (i) fails, DD is independent in the compatibility digraph. In a cycle with k=Lk = L, all LL vertices of DD need distinct successors among only L−1L-1 vertices outside DD, which is impossible. The same count applies to a path ending at pL−1p_{L-1}, since no vertex of DD is the final vertex. For an unrestricted path with k=L+1k = L+1, at most one vertex of DD can be final, leaving at least LL vertices that again need distinct successors among L−1L-1 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 T1,T2,…T_1,T_2,\ldots of Turing machines run on empty input, and let qnq_n be the nnth odd prime. Define

S⋆={1}∪{2r:r≥1}∪{2qnt:n,t≥1 and Tn halts within t steps}.(3)S^\star= \{1\} \cup\{2^r : r \ge1\} \cup\{2q_n^t : n,t \ge1 \text{ and } T_n \text{ halts within } t \text{ steps}\}. \tag*{(3)}

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 2pt2p^t with pp an odd prime and t≥1t \ge1. Compute the index nn of pp among the odd primes and simulate TnT_n for tt steps. This is a terminating membership test; no polynomial-time bound is asserted or needed.

Unique prime factorisation gives

S⋆∩qnN>0≠∅⟺Tn halts.(4)S^\star\cap q_n\mathbb{N}_{>0} \ne\varnothing\quad\Longleftrightarrow\quad T_n \text{ halts}. \tag*{(4)}

Indeed, among the integers in (3), only numbers of the form 2qnt2q_n^t are divisible by qnq_n, and such a number is included exactly when a sufficiently long finite simulation witnesses halting. Given nn, compute qnq_n and apply Lemma 19 with L=qnL=q_n. Equation (4) reduces the halting problem to the cycle and prescribed-endpoint problems on Bqn,qnB_{q_n,q_n}, and to the unrestricted-endpoint problem on Bqn,qn+1B_{q_n,q_{n+1}}. Since L=qn≥3L=q_n \ge3, the vertices p1p_1 and pL−1p_{L-1} 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. [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. [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. [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. [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. [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. [6]Ronald J. Gould. Advances on the Hamiltonian problem—a survey. Graphs and Combinatorics, 19(1):7–52, 2003.DOI
  7. [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. [8]Jerome J. Karaganis. On the cube of a graph. Canadian Mathematical Bulletin, 11(2):295–296, 1968.DOI
  9. [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. [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. [11]P. Underground. On graphs with Hamiltonian squares. Discrete Mathematics, 21(3):323, 1978.DOI

Paper details

vlnc:W_4a4d7sr3
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 3

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

GPT 6 Pro

View statement
Looking for related papers…
Contents