Recent from talks
Nothing was collected or created yet.
Hamiltonian path problem
View on WikipediaThe Hamiltonian path problem is a topic discussed in the fields of complexity theory and graph theory. It decides if a directed or undirected graph, G, contains a Hamiltonian path, a path that visits every vertex in the graph exactly once. The problem may specify the start and end of the path, in which case the starting vertex s and ending vertex t must be identified.[1]
The Hamiltonian cycle problem is similar to the Hamiltonian path problem, except it asks if a given graph contains a Hamiltonian cycle. This problem may also specify the start of the cycle. The Hamiltonian cycle problem is a special case of the travelling salesman problem, obtained by setting the distance between two cities to one if they are adjacent and two otherwise, and verifying that the total distance travelled is equal to n. If so, the route is a Hamiltonian cycle.
The Hamiltonian path problem and the Hamiltonian cycle problem belong to the class of NP-complete problems, as shown in Michael Garey and David S. Johnson's book Computers and Intractability: A Guide to the Theory of NP-Completeness and Richard Karp's list of 21 NP-complete problems.[2][3]
Reductions
[edit]Reduction from the path problem to the cycle problem
[edit]The problems of finding a Hamiltonian path and a Hamiltonian cycle can be related as follows:
- In one direction, the Hamiltonian path problem for graph G can be related to the Hamiltonian cycle problem in a graph H obtained from G by adding a new universal vertex x, connecting x to all vertices of G. Thus, finding a Hamiltonian path cannot be significantly slower (in the worst case, as a function of the number of vertices) than finding a Hamiltonian cycle.
- In the other direction, the Hamiltonian cycle problem for a graph G is equivalent to the Hamiltonian path problem in the graph H obtained by adding terminal (degree-one) vertices s and t attached respectively to a vertex v of G and to v', a cleaved copy of v which gives v' the same neighbourhood as v. The Hamiltonian path in H running through vertices corresponds to the Hamiltonian cycle in G running through .[4]
Algorithms
[edit]Brute force
[edit]To decide if a graph has a Hamiltonian path, one would have to check each possible path in the input graph G. There are n! different sequences of vertices that might be Hamiltonian paths in a given n-vertex graph (and are, in a complete graph), so a brute force search algorithm that tests all possible sequences would be very slow.
Partial paths
[edit]An early exact algorithm for finding a Hamiltonian cycle on a directed graph was the enumerative algorithm of Martello.[3] A search procedure by Frank Rubin[5] divides the edges of the graph into three classes: those that must be in the path, those that cannot be in the path, and undecided. As the search proceeds, a set of decision rules classifies the undecided edges, and determines whether to halt or continue the search. Edges that cannot be in the path can be eliminated, so the search gets continually smaller. The algorithm also divides the graph into components that can be solved separately, greatly reducing the search size. In practice, this algorithm is still the fastest.
Dynamic programming
[edit]Also, a dynamic programming algorithm of Bellman, Held, and Karp can be used to solve the problem in time O(n2 2n). In this method, one determines, for each set S of vertices and each vertex v in S, whether there is a path that covers exactly the vertices in S and ends at v. For each choice of S and v, a path exists for (S,v) if and only if v has a neighbor w such that a path exists for (S − v,w), which can be looked up from already-computed information in the dynamic program.[6][7]
Monte Carlo
[edit]Andreas Björklund provided an alternative approach using the inclusion–exclusion principle to reduce the problem of counting the number of Hamiltonian cycles to a simpler counting problem, of counting cycle covers, which can be solved by computing certain matrix determinants. Using this method, he showed how to solve the Hamiltonian cycle problem in arbitrary n-vertex graphs by a Monte Carlo algorithm in time O(1.657n); for bipartite graphs this algorithm can be further improved to time O(1.415n).[8]
Backtracking
[edit]For graphs of maximum degree three, a careful backtracking search can find a Hamiltonian cycle (if one exists) in time O(1.251n).[9]
Boolean satisfiability
[edit]Hamiltonian paths can be found using a SAT solver. The Hamiltonian path is NP-Complete meaning it can be mapping reduced to the 3-SAT problem. As a result, finding a solution to the Hamiltonian Path problem is equivalent to finding a solution for 3-SAT.
Unconventional methods
[edit]Because of the difficulty of solving the Hamiltonian path and cycle problems on conventional computers, they have also been studied in unconventional models of computing. For instance, Leonard Adleman showed that the Hamiltonian path problem may be solved using a DNA computer. Exploiting the parallelism inherent in chemical reactions, the problem may be solved using a number of chemical reaction steps linear in the number of vertices of the graph; however, it requires a factorial number of DNA molecules to participate in the reaction.[10]
An optical solution to the Hamiltonian problem has been proposed as well.[11] The idea is to create a graph-like structure made from optical cables and beam splitters which are traversed by light in order to construct a solution for the problem. The weak point of this approach is the required amount of energy which is exponential in the number of nodes.
Complexity
[edit]The problem of finding a Hamiltonian cycle or path is in FNP; the analogous decision problem is to test whether a Hamiltonian cycle or path exists. The directed and undirected Hamiltonian cycle problems were two of Karp's 21 NP-complete problems. They remain NP-complete even for special kinds of graphs, such as:
- bipartite graphs,[12]
- undirected planar graphs of maximum degree three,[13]
- directed planar graphs with indegree and outdegree at most two,[14]
- bridgeless undirected planar 3-regular bipartite graphs,
- 3-connected 3-regular bipartite graphs,[15]
- subgraphs of the square grid graph,[16]
- cubic subgraphs of the square grid graph.[17]
However, for some special classes of graphs, the problem can be solved in polynomial time:
- 4-connected planar graphs are always Hamiltonian by a result due to Tutte, and the computational task of finding a Hamiltonian cycle in these graphs can be carried out in linear time[18] by computing a so-called Tutte path.
- Tutte proved this result by showing that every 2-connected planar graph contains a Tutte path. Tutte paths in turn can be computed in quadratic time even for 2-connected planar graphs,[19] which may be used to find Hamiltonian cycles and long cycles in generalizations of planar graphs.
Putting all of these conditions together, it remains open whether 3-connected 3-regular bipartite planar graphs must always contain a Hamiltonian cycle, in which case the problem restricted to those graphs could not be NP-complete; see Barnette's conjecture.
In graphs in which all vertices have odd degree, an argument related to the handshaking lemma shows that the number of Hamiltonian cycles through any fixed edge is always even, so if one Hamiltonian cycle is given, then a second one must also exist.[20] However, finding this second cycle does not seem to be an easy computational task. Papadimitriou defined the complexity class PPA to encapsulate problems such as this one.[21]
Polynomial time verifier
[edit]
The Hamiltonian path problem is NP-Complete meaning a proposed solution can be verified in polynomial time.[1]
A verifier algorithm for Hamiltonian path will take as input a graph G, starting vertex s, and ending vertex t. Additionally, verifiers require a potential solution known as a certificate, c. For the Hamiltonian Path problem, c would consist of a string of vertices where the first vertex is the start of the proposed path and the last is the end.[22] The algorithm will determine if c is a valid Hamiltonian Path in G and if so, accept.
To decide this, the algorithm first verifies that all of the vertices in G appear exactly once in c. If this check passes, next, the algorithm will ensure that the first vertex in c is equal to s and the last vertex is equal to t. Lastly, to verify that c is a valid path, the algorithm must check that every edge between vertices in c is indeed an edge in G. If any of these checks fail, the algorithm will reject. Otherwise, it will accept.[22][23]
The algorithm can check in polynomial time if the vertices in G appear once in c. Additionally, it takes polynomial time to check the start and end vertices, as well as the edges between vertices. Therefore, the algorithm is a polynomial time verifier for the Hamiltonian path problem.[22]
Applications
[edit]Networks on chip
[edit]Networks on chip (NoC) are used in computer systems and processors serving as communication for on-chip components.[24] The performance of NoC is determined by the method it uses to move packets of data across a network.[25] The Hamiltonian Path problem can be implemented as a path-based method in multicast routing. Path-based multicast algorithms will determine if there is a Hamiltonian path from the start node to each end node and send packets across the corresponding path. Utilizing this strategy guarantees deadlock and livelock free routing, increasing the efficiency of the NoC.[26]
Computer graphics
[edit]Rendering engines are a form of software used in computer graphics to generate images or models from input data.[27] In three dimensional graphics rendering, a common input to the engine is a polygon mesh. The time it takes to render the object is dependent on the rate at which the input is received, meaning the larger the input the longer the rendering time. For triangle meshes, however, the rendering time can be decreased by up to a factor of three. This is done through "ordering the triangles so that consecutive triangles share a face."[28] That way, only one vertex changes between each consecutive triangle. This ordering exists if the dual graph of the triangular mesh contains a Hamiltonian path.
References
[edit]
Media related to Hamiltonian path problem at Wikimedia Commons
- ^ a b Sipser, Michael (2013). Introduction to the Theory of Computation (3rd ed.). Cengage Learning. pp. 292–314.
- ^ Garey, Michael R; Johnson, David S. (1979). Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman and Company. p. 60.
- ^ a b Held, M.; Karp, R. M. (1965). "The construction of discrete dynamic programming algorithms". IBM Systems Journal. 4 (2): 136–147. doi:10.1147/sj.42.0136. ISSN 0018-8670.
- ^ Reduction from Hamiltonian cycle to Hamiltonian path
- ^ Rubin, Frank (1974), "A Search Procedure for Hamilton Paths and Circuits", Journal of the ACM, 21 (4): 576–80, doi:10.1145/321850.321854, S2CID 7132716
- ^ Bellman, Richard (January 1962). "Dynamic Programming Treatment of the Travelling Salesman Problem". Journal of the ACM. 9 (1): 61–63. doi:10.1145/321105.321111. ISSN 0004-5411. S2CID 15649582.
- ^ Held, Michael; Karp, Richard M. (March 1962). "A Dynamic Programming Approach to Sequencing Problems". Journal of the Society for Industrial and Applied Mathematics. 10 (1): 196–210. doi:10.1137/0110015. ISSN 0368-4245.
- ^ Bjorklund, Andreas (October 2010). "Determinant Sums for Undirected Hamiltonicity". 2010 IEEE 51st Annual Symposium on Foundations of Computer Science. IEEE. pp. 173–182. arXiv:1008.0541. doi:10.1109/focs.2010.24. ISBN 978-1-4244-8525-3.
- ^ Iwama, Kazuo; Nakashima, Takuya (2007), Lin, Guohui (ed.), "An Improved Exact Algorithm for Cubic Graph TSP", Computing and Combinatorics, Lecture Notes in Computer Science, vol. 4598, Berlin, Heidelberg: Springer Berlin Heidelberg, pp. 108–117, doi:10.1007/978-3-540-73545-8_13, ISBN 978-3-540-73544-1, retrieved 2023-10-07
- ^ Adleman, Leonard (November 1994), "Molecular computation of solutions to combinatorial problems", Science, 266 (5187): 1021–1024, Bibcode:1994Sci...266.1021A, CiteSeerX 10.1.1.54.2565, doi:10.1126/science.7973651, JSTOR 2885489, PMID 7973651.
- ^ Mihai Oltean (2006). A light-based device for solving the Hamiltonian path problem. Unconventional Computing. Springer LNCS 4135. pp. 217–227. arXiv:0708.1496. doi:10.1007/11839132_18.
- ^ "Proof that the existence of a Hamilton Path in a bipartite graph is NP-complete". Computer Science Stack Exchange. Retrieved 2019-03-18.
- ^ Garey, M. R.; Johnson, D. S.; Stockmeyer, L. (1974), "Some simplified NP-complete problems", Proc. 6th ACM Symposium on Theory of Computing (STOC '74), pp. 47–63, doi:10.1145/800119.803884, S2CID 207693360.
- ^ Plesńik, J. (1979), "The NP-completeness of the Hamiltonian cycle problem in planar digraphs with degree bound two" (PDF), Information Processing Letters, 8 (4): 199–201, doi:10.1016/0020-0190(79)90023-1.
- ^ Akiyama, Takanori; Nishizeki, Takao; Saito, Nobuji (1980–1981), "NP-completeness of the Hamiltonian cycle problem for bipartite graphs", Journal of Information Processing, 3 (2): 73–76, MR 0596313.
- ^ Itai, Alon; Papadimitriou, Christos; Szwarcfiter, Jayme (1982), "Hamilton Paths in Grid Graphs", SIAM Journal on Computing, 4 (11): 676–686, CiteSeerX 10.1.1.383.1078, doi:10.1137/0211056.
- ^ Buro, Michael (2001), "Simple Amazons endgames and their connection to Hamilton circuits in cubic subgrid graphs" (PDF), Computers and Games, Lecture Notes in Computer Science, vol. 2063, pp. 250–261, CiteSeerX 10.1.1.40.9731, doi:10.1007/3-540-45579-5_17, ISBN 978-3-540-43080-3.
- ^ Chiba, Norishige; Nishizeki, Takao (1989), "The Hamiltonian cycle problem is linear-time solvable for 4-connected planar graphs", Journal of Algorithms, 10 (2): 187–211, doi:10.1016/0196-6774(89)90012-6
- ^ Schmid, Andreas; Schmidt, Jens M. (2018), "Computing Tutte Paths", Proceedings of the 45th International Colloquium on Automata, Languages and Programming (ICALP'18), to appear.
- ^ Thomason, A. G. (1978), "Hamiltonian cycles and uniquely edge colourable graphs", Advances in Graph Theory (Cambridge Combinatorial Conf., Trinity College, Cambridge, 1977), Annals of Discrete Mathematics, vol. 3, pp. 259–268, doi:10.1016/S0167-5060(08)70511-9, ISBN 9780720408430, MR 0499124.
- ^ Papadimitriou, Christos H. (1994), "On the complexity of the parity argument and other inefficient proofs of existence", Journal of Computer and System Sciences, 48 (3): 498–532, CiteSeerX 10.1.1.321.7008, doi:10.1016/S0022-0000(05)80063-7, MR 1279412.
- ^ a b c Bun, Mark (November 2022). "Boston University Theory of Computation" (PDF).
- ^ Bretscher, A (February 5, 2021). "University of Toronto CSCC63 Week 7 Lecture Notes" (PDF).
- ^ Bahn, Jun Ho. "Overview of Network-on-Chip". University Of California Irvine.
- ^ Satish, E. G. (2022). "Comparative Performance Analysis of Routing Topology for NoC Architecture". Emerging Research in Computing, Information, Communication and Applications. Lecture Notes in Electrical Engineering. Vol. 790. pp. 431–440. doi:10.1007/978-981-16-1342-5_34. ISBN 978-981-16-1341-8 – via Springer.
- ^ Bahrebar, P.; Stroobandt, D. (2014). "Improving hamiltonian-based routing methods for on-chip networks: A turn model approach". 2014 Design, Automation & Test in Europe Conference & Exhibition: 1–4 – via IEEE.
- ^ Garsiel, Tali; Irish, Paul (August 5, 2011). "How Browsers Work".
- ^ Arkin, Esther M.; Mitchell, Joseph S. B.; Held, Martin; Skiena, Steven S. "Hamiltonian Triangulations for Fast Rendering" (PDF). Department of Computer Science Stony Brook University.
Hamiltonian path problem
View on GrokipediaDefinition and Background
Formal Statement
The Hamiltonian path problem is a fundamental decision problem in graph theory, asking whether a given undirected or directed graph contains a path that visits every vertex exactly once. Formally, given an undirected graph with vertex set of size and edge set , the problem determines if there exists a sequence of distinct vertices such that for all . For directed graphs, edges are ordered pairs, and the condition applies accordingly.[7][8] The input to the problem consists of the graph , typically encoded via an adjacency list (listing neighbors for each vertex) or an adjacency matrix (a boolean matrix indicating edge presence between vertices), along with the number of vertices . The output is a binary decision: "yes" if a Hamiltonian path exists, and "no" otherwise. This formulation treats the problem strictly as one of existence, without requiring the explicit construction or identification of the path itself.[9] For illustration, consider the complete graph on three vertices connected by all possible edges, forming a triangle. This graph admits Hamiltonian paths, such as the sequence traversing vertices 1-2-3, since every pair is adjacent and all vertices are visited exactly once.[7] The Hamiltonian path problem is distinct from the related Hamiltonian cycle problem, which seeks a closed path visiting each vertex exactly once and returning to the starting vertex.[9]Relation to Hamiltonian Cycle
The Hamiltonian cycle in a graph is defined as a closed path that visits each vertex exactly once before returning to the starting vertex.[10] This differs from a Hamiltonian path, which does not require closure, but the two problems are intimately connected through simple structural modifications. A standard polynomial-time reduction from the Hamiltonian path problem to the Hamiltonian cycle problem involves augmenting the original undirected graph with a new vertex adjacent to every vertex in . The resulting graph has a Hamiltonian cycle if and only if has a Hamiltonian path: if contains a path visiting all vertices from some to , then admits the cycle ; conversely, any Hamiltonian cycle in induces a Hamiltonian path in by removing and its incident edges.[11] The reverse reduction, from Hamiltonian cycle to path, can be achieved for undirected graphs by selecting an arbitrary edge in (assuming is connected and has edges), removing it to form , and determining if has a Hamiltonian path from to : has a Hamiltonian cycle if and only if such a path exists in .[9] Both the Hamiltonian path and cycle problems are NP-complete, as established in Karp's seminal work demonstrating their equivalence under polynomial-time reductions from known NP-complete problems like 3-SAT.[12] The mutual reducibility implies that the problems share the same computational complexity, with the path variant directly transformable to the cycle variant (and vice versa) in linear time. This close relationship extends to algorithmic approaches: solvers designed for Hamiltonian cycles can be adapted to find paths via these O(1) graph modifications, preserving asymptotic performance while enabling bidirectional applicability in exact and heuristic methods.[13]History and Origins
Early Developments
The concept of traversing graphs in a specific manner traces its early roots to the 18th century, particularly through Leonhard Euler's foundational work on what would later be known as Eulerian paths. In 1735, Euler presented a paper to the St. Petersburg Academy addressing the Seven Bridges of Königsberg problem, which involved finding a path that crosses each bridge exactly once without repetition, though it did not require visiting every landmass (vertex) precisely once. This work, published in 1736, laid groundwork for graph traversal problems but focused on edges rather than vertices, distinguishing it from later Hamiltonian formulations.[14] Parallel to Euler's contributions, combinatorial puzzles involving vertex traversals emerged in the context of chess problems, notably the knight's tour, which requires a knight to visit every square on a chessboard exactly once. The earliest documented discussions of the knight's tour appear in Arabic manuscripts from around 840 AD, attributed to the scholar al-Adli ar-Rumi, who explored open and closed tours on smaller boards. By the 18th century, Euler extended this in 1759 by demonstrating a closed knight's tour on an 8x8 board, treating the problem as a vertex-covering path in the knight's graph, though solutions remained manual and puzzle-oriented rather than algorithmic. These early efforts highlighted the challenge of complete vertex traversals but predated formal graph-theoretic framing.[15][16] The Hamiltonian path problem derives its name from the 19th-century work of Irish mathematician William Rowan Hamilton, who in 1856 began exploring systematic traversals of polyhedral graphs, particularly the dodecahedron. Hamilton's investigations extended Eulerian ideas to vertex-focused paths and cycles, culminating in the Icosian game, a puzzle he invented in 1857 that challenges players to find a cycle visiting each of the 20 vertices of a dodecahedron exactly once, with the vertices labeled with the names of cities. While the game emphasized cycles, Hamilton's underlying "Icosian calculus" implicitly addressed path constructions as precursors, published in papers in the Philosophical Magazine and Proceedings of the Royal Irish Academy in 1856.[17][18] Initially, Hamilton's contributions centered on recreational mathematics and polyhedral symmetries rather than computational or complexity aspects, with the Icosian game commercialized in 1859 by a London firm for £25, promoting it as an intellectual diversion. This era's focus on puzzles like the knight's tour and Icosian game underscored the problem's combinatorial allure, influencing later graph theory without immediate recognition of its decision-theoretic implications.[18]Key Milestones
The Hamiltonian path problem gained formal recognition in computer science during the 1950s, as graph-theoretic problems began intersecting with emerging computational paradigms and optimization techniques. This period marked the transition of combinatorial challenges from pure mathematics to algorithmic study, with early explorations in network flows and pathfinding laying groundwork for analyzing traversal problems in discrete structures.[19] A pivotal theoretical advancement occurred in 1960 when Øystein Ore established sufficient degree conditions guaranteeing the existence of a Hamiltonian path. Ore's theorem states that a connected graph on vertices has a Hamiltonian path if, for every pair of non-adjacent vertices and , . This condition extended earlier Dirac-like criteria and provided a practical tool for verifying Hamiltonicity in denser graphs, influencing subsequent sufficiency theorems in graph theory.[20] In 1972, Richard Karp solidified the problem's status in computational complexity by including the Hamiltonian path among his 21 NP-complete problems in the seminal paper "Reducibility Among Combinatorial Problems." Karp demonstrated reductions from other hard problems, such as the vertex cover, establishing that deciding the existence of a Hamiltonian path is NP-complete for directed and undirected graphs, which spurred decades of research into exact and approximate solutions.[9] The 1980s and 1990s saw substantial progress in heuristic and approximation methods, often leveraging connections to the traveling salesman problem (TSP). Nicos Christofides' 1976 algorithm for the metric TSP, yielding a 3/2-approximation ratio for finding near-optimal tours, was extended in this era to the s-t Hamiltonian path variant, enabling efficient heuristics for metric instances by constructing minimum spanning trees and Eulerian paths followed by shortcutting. These developments, including branch-and-bound techniques and genetic algorithms tailored for sparse graphs, improved practical solvability for large instances despite inapproximability results under standard assumptions.[21][22] In the 2010s and beyond, quantum computing introduced novel approaches for approximate solving. The Harrow-Hassidim-Lloyd (HHL) algorithm (2009), which solves linear systems exponentially faster than classical methods under certain conditions, inspired hybrid quantum-classical frameworks for optimization problems like Hamiltonian path, particularly in quantum approximate optimization algorithms (QAOA). For instance, a 2022 QAOA variant specifically targets the Hamiltonian path by encoding the problem into a quantum Ising model, demonstrating potential speedups for small-scale instances on near-term quantum hardware.[23] Recent advancements up to 2023 have focused on parameterized complexity, especially for restricted graph classes like grid graphs. A 2023 study showed that finding long directed cycles—and by extension, Hamiltonian paths—in graphs with small directed feedback vertex sets remains W[24]-hard, even for grid-like structures, highlighting persistent challenges in fixed-parameter tractability while identifying polynomial-time solvable subclasses such as O-shaped supergrids. These results refine the boundaries of efficient algorithms for geometric and lattice-based instances.[25][26]Complexity Analysis
NP-Completeness Proof
The Hamiltonian path problem belongs to the class NP because a nondeterministic Turing machine can guess a sequence of distinct vertices and verify it forms a path in polynomial time. Specifically, the certificate consists of an ordered list of vertices , where the verifier checks two conditions: (1) each pair is an edge in the graph, requiring adjacency checks, and (2) all vertices are unique, which can be confirmed in time by pairwise comparison or using a hash set in practice. The overall verification time complexity is thus .[27] To establish NP-hardness, a polynomial-time many-one reduction from the NP-complete 3-SAT problem to the Hamiltonian path problem is constructed, as originally demonstrated by Karp in 1972. This proof shows that solving Hamiltonian path would allow solving 3-SAT in polynomial time if a polynomial-time algorithm existed for the former, thereby proving NP-completeness. Karp's seminal work included this among 21 combinatorial problems reduced from SAT, highlighting that intractability is pervasive in optimization and sequencing tasks, forming a cornerstone of computational complexity theory by linking logical satisfiability to graph traversal.[5] The reduction builds a directed graph from a 3-SAT formula with variables and clauses such that has a Hamiltonian path from a source vertex to a sink vertex if and only if is satisfiable. For each variable , a variable gadget is created: a chain of vertices with bidirectional edges along the chain, allowing traversal in either direction (left-to-right for true, right-to-left for false). These chains are connected end-to-end across variables, ensuring the path must traverse all variable gadgets while choosing a consistent direction for each. For each clause , a clause gadget vertex is added, with incoming edges from the literals in the clause (e.g., from position or in the relevant variable chain depending on positive or negative polarity) and outgoing edges to the next positions, allowing the path to detour through only if at least one literal is true under the assignment defined by the directions. The source connects to the start of the first chain, and the sink to the end of the last, forcing a full traversal. This construction ensures every clause gadget is visited exactly once via a true literal, corresponding to a satisfying assignment, and runs in time. The undirected version follows analogously by symmetrizing edges, preserving the NP-completeness.[27][5]Related Hardness Results
The Hamiltonian path problem demonstrates significant inapproximability properties. Specifically, there is no polynomial-time approximation algorithm that can approximate the length of the longest path within a factor of for any constant , unless P = NP. This result is derived from the corresponding inapproximability for the Hamiltonian cycle problem, to which the path variant reduces in polynomial time. In parameterized complexity theory, the directed variant of the Hamiltonian path problem is W[24]-hard when parameterized by directed treewidth. This hardness holds even for finding cycles of length at least a constant fraction of the number of vertices. In contrast, the undirected Hamiltonian path admits fixed-parameter tractable algorithms parameterized by (undirected) pathwidth, leveraging dynamic programming on path decompositions.[28][29] The directed Hamiltonian path problem is NP-complete, distinct from the undirected case. Its NP-completeness is established via a polynomial-time reduction from 3-SAT, where variable and clause gadgets are constructed to ensure that a satisfying assignment corresponds to a Hamiltonian path traversing all vertices exactly once. This reduction differs from the undirected version, which uses vertex cover or vertex disjoint paths reductions. The longest path problem, which seeks a simple path of maximum length in a graph, is NP-hard. This hardness persists even when restricting to optimization variants without a guaranteed Hamiltonian path, and it implies challenges in approximating the maximum path length beyond constant factors.[30] Recent results have explored average-case hardness for the Hamiltonian path problem under distributions like random graphs. Assuming the exponential time hypothesis (ETH), there is no polynomial-time algorithm for solving Hamiltonian path on average over certain input distributions derived from worst-case hard instances, including sparse random graphs near the connectivity threshold. This establishes that average-case instances can be as hard as worst-case ones for subexponential time solvers.Algorithms for Solving
Exact Methods
The brute force method for determining whether a Hamiltonian path exists in a graph involves enumerating all possible permutations of the n vertices and checking for each whether consecutive vertices in the permutation are connected by edges in the graph. This requires generating and validating n! permutations, with each validation taking O(n) time to check the n-1 edges, resulting in an overall time complexity of O(n! · n).[6] A more efficient exact algorithm employs dynamic programming in the style of the Held-Karp approach, originally proposed for sequencing problems including those related to Hamiltonian paths.[31] This method uses states defined by a subset S ⊆ V of vertices and an endpoint v ∈ S, where dp[S] represents the minimum cost (or existence for the decision version) of a path that visits exactly the vertices in S and ends at v. The recurrence relation is: if there is an edge from u to v with weight w(u, v); otherwise, it is infinite (or false for existence). Base cases are dp[{k}] = 0 for all vertices k. A Hamiltonian path exists if there is some v such that dp[V] is finite (or true). Computing all states requires O(2^n · n^2) time, as there are 2^n subsets and for each, O(n^2) transitions are considered.[31] Backtracking provides another exact strategy through a depth-first search that incrementally builds candidate paths, adding vertices one by one while ensuring no repeats and pruning subtrees when a partial path cannot be extended to cover all vertices without violating graph edges. Historical and modern implementations of backtracking for the Hamiltonian path problem, such as those surveyed in comparative studies, demonstrate effectiveness on small to moderate graph sizes by exploiting early detection of infeasible branches.[32] The dynamic programming method achieves exponential but subfactorial time complexity, outperforming brute force for instances up to n ≈ 20, beyond which its 2^n scaling becomes impractical on standard hardware.[33]Heuristic and Approximation Approaches
Heuristic and approximation approaches for the Hamiltonian path problem aim to identify viable paths in large or dense graphs where exact methods are computationally prohibitive, emphasizing computational efficiency and practical success rates over theoretical guarantees. These techniques often draw inspiration from related optimization problems like the traveling salesman problem (TSP), adapting greedy, randomized, and evolutionary strategies to construct long paths that may or may not be Hamiltonian. While they provide no worst-case performance bounds due to the NP-completeness of the problem, they succeed frequently on random or structured graphs, enabling applications in network design and optimization. Monte Carlo methods employ randomized sampling to explore the space of possible paths, offering probabilistic guarantees of detection in certain graph classes. A representative approach involves generating random walks or permutations and verifying if they form a Hamiltonian path, with acceptance based on path coverage; this can be tuned with acceptance probabilities derived from graph density to favor complete paths. For instance, in graphs with bounded treewidth, randomized algorithms related to the Cut&Count technique can solve the Hamiltonian cycle problem in time with high probability, where is the treewidth; similar approaches apply to paths.[34] These methods are particularly effective in sparse or random graphs, where the probability of sampling a valid path increases with edge density, though they may require multiple trials for low-density instances. Partial path heuristics construct solutions incrementally by extending short subpaths with greedy or rule-based choices, pruning branches that lead to dead ends. In this framework, a partial path is tested for extendability by analyzing the connectivity of the remaining subgraph, classifying edges as forbidden (if they would disconnect components) or mandatory (if required for coverage), and backtracking only when necessary. A classic implementation starts with an initial subpath and greedily adds vertices that preserve the graph's bipartition balance or degree constraints in the induced subgraph on unvisited vertices. The HybridHAM algorithm, primarily designed for cycles, initiates with a greedy depth-first search from the highest-degree vertex to form an initial partial path, then iteratively extends it via swaps or insertions; tests on benchmark instances show it finds solutions in about 30% of cases for graphs up to 250 vertices.[35] This approach reduces search space exponentially through early pruning, making it suitable for graphs up to several hundred vertices. The nearest neighbor heuristic, borrowed from TSP approximations, builds a path by starting at an arbitrary vertex and iteratively appending the unvisited vertex with the smallest "distance," interpreted as edge weight in metric graphs or simply an adjacent unvisited neighbor in unweighted ones. It operates in time by maintaining a priority queue of candidates and updating distances after each addition, producing a spanning path that is often near-optimal in complete or dense graphs but can get stuck in sparse structures without backtracking. Although lacking a constant-factor approximation ratio for the general case, it serves as a baseline for path construction, with variants incorporating look-ahead to avoid premature termination. Genetic algorithms model path candidates as sequences (chromosomes) and evolve populations through selection, crossover (e.g., order crossover to preserve path validity), and mutation (e.g., swapping adjacent vertices) to maximize a fitness function based on path length or edge coverage. These algorithms have been applied to structured graphs, such as directed layered graphs, to optimize path orderings. More recent hybrids integrate local search operators, such as 2-opt improvements, to refine solutions, demonstrating high success rates on random directed graphs with 100 vertices. In the 2020s, machine learning techniques, particularly graph neural networks (GNNs), have been explored for related problems like predicting Hamiltonian cycles by learning patterns from labeled graph datasets. For example, a compact message-passing GNN with about 22,000 parameters, trained on Erdős-Rényi random graphs of size 25, can predict cycles with success rates of 75% for n=25, 55% for n=150, and 48% for n=200, outperforming some traditional heuristics. Similar data-driven approaches hold potential for Hamiltonian paths.[36]Reductions to Other Problems
One common polynomial-time reduction transforms an instance of the Hamiltonian path problem into an instance of the Hamiltonian cycle problem. Given an undirected graph with , construct a new graph by adding a universal vertex adjacent to every vertex in . This adds new edges and can be done in time. The graph has a Hamiltonian path if and only if has a Hamiltonian cycle, as any cycle in must pass through and connect two vertices in via paths that cover all vertices exactly once, yielding a Hamiltonian path upon removal of . The Hamiltonian path problem also reduces in polynomial time to the 3-SAT problem via a direct encoding that models the path as a permutation of vertices. For a graph with vertices labeled to , introduce Boolean variables for , where is true if vertex occupies position in the path. The CNF formula includes clauses ensuring: (1) each position has exactly one vertex ( and for ); (2) each vertex appears exactly once ( and for ); and (3) consecutive positions and are adjacent in ( for all non-edges ). This formula has variables and clauses, is 3-CNF after standard conversion if needed, and is satisfiable if and only if has a Hamiltonian path.[37] This SAT reduction facilitates solving Hamiltonian path instances using modern SAT solvers. For example, encodings tested with solvers like Kissat solve instances up to vertices in dense graphs within reasonable time, though performance varies by graph structure and encoding optimizations such as vertex elimination.[38] A polynomial-time reduction exists from the vertex cover problem to the Hamiltonian path problem (and similarly to Hamiltonian cycle), enabling the use of Hamiltonian path solvers for vertex cover instances. Given a graph and integer , construct a new graph with "cover" vertices corresponding to potential cover elements, plus gadgets for each edge in . Each edge gadget consists of paths that can only be traversed if at least one endpoint is "selected" via routing through the corresponding ; uncovered edges block all Hamiltonian paths by forcing dead ends in the gadget. The full construction connects these in a linear arrangement, ensuring a Hamiltonian path in exists if and only if has a vertex cover of size at most . This gadget-based approach runs in polynomial time relative to . Unconventional reductions include formulations as integer linear programs (ILPs), where binary variables indicate if vertex follows vertex in the path, subject to constraints for in/out-degrees (exactly 1 for intermediate vertices, adjusted for endpoints) and subtour elimination via MTZ inequalities like for positions . Feasibility of this ILP (with variables and constraints) corresponds to a Hamiltonian path, solvable via ILP solvers like CPLEX for moderate .[39] Reductions to quantum frameworks, such as encoding into quantum approximate optimization algorithm (QAOA) instances for variational quantum solvers, map the path constraints to quadratic unconstrained binary optimization (QUBO) forms, though practical utility remains limited by current quantum hardware scale.[40]Verification and Decision
Polynomial-Time Verifier
The polynomial-time verifier for the Hamiltonian path problem operates on an input graph with vertices and edges, along with a certificate consisting of an ordered sequence of vertices . The algorithm first confirms that the sequence contains each vertex exactly once by marking vertices in a set or array, which requires time. It then checks, for each to , whether the edge exists in ; using an adjacency list representation, this verification takes time overall, as each edge check scans the relevant adjacency list entries.[2][41] The total running time of this verifier is , which is polynomial in the input size, as both and are at most . This efficient verification procedure demonstrates that the Hamiltonian path problem belongs to the complexity class NP, where "yes" instances have short certificates that can be checked quickly, in contrast to the apparent hardness of constructing such a path from scratch.[42][43] For weighted graphs, where the decision problem asks if there exists a Hamiltonian path of total weight at most , the verifier extends the above by computing the sum of the weights of the edges and checking if it is , adding only time to the process.[9]Counting Variants
The counting variant of the Hamiltonian path problem seeks to determine the exact number of distinct Hamiltonian paths in a given graph, distinguishing it from the decision version by requiring enumeration rather than mere existence. This problem belongs to the complexity class #P, which captures the computational difficulty of counting the accepting paths of a nondeterministic polynomial-time Turing machine. Specifically, counting Hamiltonian paths is #P-complete, even for directed and undirected graphs, as proven by Valiant through parsimonious reductions that preserve the number of solutions from other #P-complete problems like #SAT. This completeness implies that no polynomial-time algorithm exists unless #P = P, and it underscores the inherent hardness beyond the NP-complete decision problem.[44] A notable reduction establishing this #P-hardness originates from the problem of computing the permanent of a 0-1 matrix, which Valiant also showed to be #P-complete. The construction yields a directed bipartite graph with n row vertices and n column vertices . Edges exist from to if the matrix entry , and from every to for . The number of Hamiltonian paths starting at precisely equals the permanent of the matrix, given by where is the set of permutations of . This bijection demonstrates that counting Hamiltonian paths is #P-hard even when restricted to bipartite graphs, as the reduction is polynomial-time and preserves counts exactly. Exact algorithms for counting Hamiltonian paths rely on dynamic programming, extending the framework originally developed by Held and Karp for the traveling salesman problem. Define as the number of paths that visit exactly the vertices in subset and end at vertex . The recurrence is , with base case for each . Computing this for all subsets and vertices yields the total count by summing over all possible ending vertices for , achieving time complexity and space . This approach, while exponential, provides the fastest known exact method for moderate . Applications of counting Hamiltonian paths appear in probabilistic graph theory, particularly for analyzing random graphs. For instance, the expected number of Hamiltonian paths in a random graph with edge probability can be computed using linearity of expectation over all possible vertex orderings, where each potential path contributes . If this expectation exceeds 1, the probabilistic method guarantees the existence of at least one such path with positive probability, aiding thresholds for Hamiltonicity in models like Erdős–Rényi graphs. Such counts thus inform asymptotic properties and phase transitions in graph ensembles.Applications and Extensions
Hardware and Network Design
In networks on chip (NoC), Hamiltonian paths play a crucial role in routing data between processing cores in multi-core processors, enabling adaptive communication schemes that minimize latency and avoid deadlocks. These paths are particularly effective in mesh topologies, where they provide a systematic ordering of nodes to facilitate wormhole routing, allowing packets to traverse alternative routes without congestion. For instance, Hamiltonian-based odd-even turn models have been developed to maximize adaptivity in 2D mesh NoCs, outperforming deterministic methods by distributing traffic more evenly across the interconnect.[45] This approach ensures efficient resource utilization in high-performance computing systems, where latency reduction is critical for overall chip performance.[46] In very-large-scale integration (VLSI) design, the Hamiltonian path problem addresses wire routing challenges by determining non-overlapping paths for interconnects, such as power and ground lines, to prevent short circuits and signal interference. A seminal method uses a Hamiltonian cycle to partition the chip surface into distinct regions—one for power (VDD) and one for ground (GND)—allowing trees of wires to be routed within each region without crossings. This technique, applied during the power-routing phase, simplifies layout verification and reduces design complexity in single-layer metal routing.[47] By guaranteeing a cycle that visits all modules exactly once, it ensures complete coverage while maintaining electrical integrity.[48] Research from the 2000s, published in IEEE proceedings, highlighted NoC topologies like torus graphs that inherently guarantee Hamiltonian paths, supporting scalable and fault-tolerant routing in emerging multi-core architectures. Torus structures, with their wrap-around connections, facilitate cycle-based embeddings that enable efficient broadcasting and multicast operations without virtual channels. For example, algorithms for torus-embedded hypercubes were proposed to enhance interconnect performance in parallel systems.[49] These findings laid the groundwork for deadlock-free protocols in wormhole-routed networks.[50] Advancements as of 2025 include hybrid quantum graph algorithms for approximating Hamiltonian paths using quantum array search techniques, with applications to path discovery in noisy intermediate-scale quantum (NISQ) environments.[51] Separately, artificial intelligence is being integrated into quantum chip design to optimize layouts and connectivity, combining machine learning with nanotechnology and semiconductors.[52]Computational Geometry and Graphics
In computer graphics, variants of the traveling salesman problem (TSP), which seek approximate Hamiltonian paths or cycles, are employed to generate efficient tours for rendering and modeling tasks. For instance, in 3D object reconstruction, view planning algorithms use the shortest Hamiltonian path to sequence camera positions that maximize coverage while minimizing motion, enabling complete and fast scanning of unknown objects with minimal redundancy.[53] This approach is particularly useful in autonomous systems where computational resources limit exhaustive searches, providing a near-optimal traversal of viewpoints derived from surface normals or feature points. Additionally, Hamiltonian paths facilitate triangle stripification in mesh rendering, where the dual graph of a triangulated surface is traversed to produce continuous strips of triangles, reducing vertex processing overhead and improving GPU efficiency in real-time graphics pipelines. Seminal work established that Hamiltonian triangulations exist for certain planar graphs, allowing strips that visit each triangle exactly once without redundant vertex submissions.[54] In printed circuit board (PCB) layout, Hamiltonian paths optimize feeder rack assignments during automated assembly, modeling component placements as graph vertices to find short paths that sequence pick-and-place operations across multiple machines. By computing Hamiltonian paths for pairs of feeder locations using TSP heuristics like farthest insertion, the method prioritizes component types based on path lengths, minimizing table movements and assembly time for diverse board types.[55] This geometric routing ensures collision-free traversals in the layout plane, aligning with computational geometry principles for planar graphs. The art gallery problem in computational geometry relates to Hamiltonian paths through visibility graphs, where vertices represent polygon corners and edges indicate mutual visibility. Visibility graphs of simple polygons always contain a Hamiltonian cycle formed by the boundary edges. Under certain conditions, such as when endpoints form disjoint segments, a Hamiltonian path can connect all points via visible edges, aiding in guarding or patrolling tasks. Open questions include the complexity of finding Hamiltonian paths between specific vertices or recognizing visibility graphs in general.[56][57] Hamiltonian paths appear in robot motion planning for collision-free traversals, particularly in constrained environments like polygonal obstacles. For snake-like robots, which must maneuver without self-intersection, the problem reduces to finding a Hamiltonian path in a configuration graph of joint positions, proven PSPACE-complete on grids but fixed-parameter tractable for small robot sizes using color-coding techniques. This ensures a sequence of configurations that visits all required states while avoiding obstacles, scalable for real-world deployments in tight spaces.[58] Recent applications in virtual reality (VR) and augmented reality (AR) leverage Hamiltonian path-inspired sequencing for path-based animations, such as generating smooth, non-repeating trajectories for immersive tours or object manipulations in 3D scenes. In VR environments, these paths optimize animation flows to visit key viewpoints or interactive elements exactly once, enhancing user engagement in educational or exploratory simulations without redundant motion.[53]Biological and Optimization Contexts
The Hamiltonian path problem finds significant application in bioinformatics, particularly in genome assembly, where reconstructing a DNA sequence from short, overlapping reads is formulated as identifying a Hamiltonian path in an overlap graph. In this model, each read represents a vertex, and edges connect vertices based on the overlap between reads; a Hamiltonian path through all vertices corresponds to the original sequence by aligning the overlaps without repetition. This approach, central to the overlap-layout-consensus (OLC) paradigm, was highlighted in foundational work on computational molecular biology, though practical implementations often approximate the NP-hard path due to graph complexity.[59][60] In protein folding, Hamiltonian path models provide a framework for predicting secondary structures by representing the polypeptide chain as a path on a lattice graph, where vertices denote amino acid positions and edges reflect possible backbone conformations that minimize energy. This abstraction captures the sequential connectivity of the protein chain while optimizing for non-local interactions, such as hydrogen bonds in alpha-helices or beta-sheets, to form stable secondary elements. Reverse Hamiltonian path approaches have been explored to reverse-engineer folding trajectories from known structures, aiding in the design of proteins with desired folds.[61][62] Hamiltonian paths also appear in DNA self-assembly models, such as tile assembly, where paths represent the sequential binding of DNA tiles to form complex nanostructures, enabling algorithmic self-assembly for computations.[63] Beyond biology, the Hamiltonian path problem underpins optimization in scheduling, where job sequencing on machines is modeled as finding a minimum-cost path visiting each job exactly once to minimize completion time or setup costs. For instance, in flexible manufacturing systems, the sequence of operations forms a path in a graph of jobs and resources, with edge weights representing transition times; solving this aids in just-in-time production planning. Heuristic methods, such as branch-and-bound variants, are commonly applied for large-scale instances due to the problem's intractability.[64][65] In logistics, approximations to the Hamiltonian path appear in vehicle routing problems (VRP), particularly open variants where routes start from a depot and end at a customer without returning, effectively seeking a path covering all demand points with capacity constraints. Clustered routing formulations use Hamiltonian paths to order visits within customer groups, reducing total travel distance; approximation algorithms achieve ratios near 3/2 for such cases, enabling scalable solutions for fleet management. These models extend to heterogeneous fleets, where vehicle types influence path feasibility.[66][67]References
- A Hamiltonian path, also called a Hamilton path, is a graph path between two vertices of a graph that visits each vertex exactly once.
