arXiv:2610.18300cs.DSOct 2026

Manuscript Offprint

arXiv:2610.18300

The Complexity of Hamiltonian Cycles and Paths with Prescribed Walk Lengths

Hitendra Kumar, Mathieu Mari, R. B. Sandeep

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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

Hamiltonian Cycles and Paths with Prescribed Walk Lengths

1 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 S-Hamiltonian cycle is a cyclic ordering of all vertices in which every consecutive pair is joined by a walk of length in S. We also consider S-Hamiltonian paths, both with prescribed endpoints and with unrestricted endpoints. For a digraph, every witnessing walk must respect the arc directions. Throughout the paper, S 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 \geq 0 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

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

We call SS normalised when S=cl2(S)S = \mathrm{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.