# 哈密顿路径

一条**哈密顿路径**（Hamiltonian path，亦称 Hamilton path）是图中一条恰好访问每个顶点一次的路径；拥有这种路径的图称为可迹图<sup>[1](https://mathworld.wolfram.com/HamiltonianPath.html)</sup>。当这种路径的两个端点由一条边连接时，路径便闭合成**哈密顿回路**（Hamiltonian cycle，或 Hamilton circuit，亦称哈密顿环），即恰好经过每个顶点一次的回路<sup>[1](https://mathworld.wolfram.com/HamiltonianPath.html)</sup>。判定一个图是否具有哈密顿路径是NP完全的，这使该问题跻身图论与组合优化中经典的计算困难问题之列<sup>[2](https://hardness.mit.edu/drafts/2025-01-29.pdf)</sup>。

| 关键事实 | 细节 |
|---|---|
| 定义 | 一条恰好访问图中每个顶点一次的路径；包含这种路径的图是可迹的<sup>[1](https://mathworld.wolfram.com/HamiltonianPath.html)</sup> |
| 闭合形式 | 如果两个端点相邻，该路径便成为哈密顿回路<sup>[1](https://mathworld.wolfram.com/HamiltonianPath.html)</sup> |
| 起源 | 威廉·罗恩·哈密顿（William Rowan Hamilton）于1856年发明的二十面体游戏，要求找出一条闭合路线，恰好访问正十二面体的每个顶点一次<sup>[3](https://mathworld.wolfram.com/IcosianGame.html)</sup><sup> • </sup><sup>[4](https://openstax.org/books/contemporary-mathematics/pages/12-7-hamilton-cycles)</sup> |
| 复杂度 | NP完全；属于卡普最初的21个问题之一（1972年），有向图和无向图均如此<sup>[2](https://hardness.mit.edu/drafts/2025-01-29.pdf)</sup><sup> • </sup><sup>[5](https://www.cs.toronto.edu/~ashe/ham-path-notes.pdf)</sup> |
| 最佳通用精确算法 | 动态规划，时间复杂度 \( O(n^{2} \cdot 2^{n}) \)（贝尔曼（Bellman）1962；赫尔德（Held）和卡普（Karp）1962）；无向图的蒙特卡洛检测，时间复杂度 \( O(1.657^{n}) \)<sup>[6](https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/IntractabilityIII.pdf)</sup><sup> • </sup><sup>[7](https://arxiv.org/abs/1008.0541)</sup> |
| 与欧拉路径的对比 | 欧拉路径恰好访问每条边一次，可以重复顶点；它可在多项式时间内求解，而哈密顿问题要难得多<sup>[8](https://www.maths.tcd.ie/~stalker/22C00/notes/7.11-hamiltonian-paths-and-circuits.html)</sup> |
| 应用 | 旅行商问题、基因组组装、电子电路设计和作业调度<sup>[9](https://informatica.vu.lt/journal/INFORMATICA/article/1346/read)</sup> |

## 定义与基本性质

形式地说，在具有 \( n \) 个顶点的图 \( G = (V, E) \) 中，哈密顿路径是一条简单路径 \( v_1, v_2, \ldots, v_n \)，它恰好包含每个顶点一次<sup>[10](https://www.eti.uni-siegen.de/ti/lehre/ws2526/komplexitaetstheorie_1/folien-kt1.pdf)</sup>。由于该路径是简单的，没有顶点重复，也没有边被经过两次；因此，具有 \( n \) 个顶点的图中的一条哈密顿路径恰好有 \( n - 1 \) 条边<sup>[11](https://math.libretexts.org/Courses/Florida_SouthWestern_State_College/MGF_1131%3A_Mathematics_in_Context__%28FSW%29/07%3A_Graph_Theory/7.03%3A_Hamiltonian_Circuits_and_the_Traveling_Salesman_Problem)</sup>。

有些结构条件很容易表述。在完全图 \( K_n \) 中，顶点的每一种排序都给出哈密顿路径，因为每一对顶点都由一条边相连；再从最后一个顶点向第一个顶点添加一条边，便得到[哈密顿回路](https://www.edgepedia.org/zh/hamiltonian-cycle)<sup>[8](https://www.maths.tcd.ie/~stalker/22C00/notes/7.11-hamiltonian-paths-and-circuits.html)</sup>。必要条件也可由计数得出：在部集为 \( X \) 和 \( Y \) 的二部图中，任何哈密顿路径都必须在两个部集之间交替，因此 \( \lvert \lvert X \rvert - \lvert Y \rvert \rvert \le 1 \) 是必要条件；若一个连通二部图的两个部集大小相差超过1，则该图不可迹<sup>[1](https://mathworld.wolfram.com/HamiltonianPath.html)</sup>。

与[欧拉路径](https://www.edgepedia.org/zh/eulerian-path)的区别是一个反复出现的比较点。欧拉路径恰好经过每条边一次，并且可以重复经过顶点；其存在性可在多项式时间内检验；而一个图是否具有哈密顿路径或哈密顿回路则难回答得多<sup>[8](https://www.maths.tcd.ie/~stalker/22C00/notes/7.11-hamiltonian-paths-and-circuits.html)</sup>。

## 历史：二十面体游戏

该问题起源于一个谜题，而非一条定理。1856年，威廉·罗恩·哈密顿发明了一种“二十面体演算”（Icosian Calculus），并用它研究正十二面体上恰好访问每个顶点一次的闭合边路径；他在1856年的《哲学杂志》（Philosophical Magazine）和《皇家爱尔兰学院院刊》（Proceedings of the Royal Irish Academy）上发表了关于该演算的短文<sup>[12](https://www.maths.tcd.ie/pub/HistMath/People/Hamilton/Icosian/)</sup>。1857年8月和9月，英国科学促进会（British Association for the Advancement of Science）在都柏林（Dublin）举行第二十七次会议；会上他介绍了该演算以及一种他称为“二十面体游戏”（Icosian）的关联游戏，并分发了一幅石版画，其棋盘是正五边形十二面体的平面投影，顶点处有孔，用于插象牙钉<sup>[12](https://www.maths.tcd.ie/pub/HistMath/People/Hamilton/Icosian/)</sup>。

这种游戏被生产并销售。1859年，哈密顿以25英镑将其卖给伦敦（London）的一家游戏经销商，随后它以多种形式在欧洲销售<sup>[3](https://mathworld.wolfram.com/IcosianGame.html)</sup>。游戏所用的十二面体图有30个哈密顿回路，因此该谜题有30个闭合解<sup>[3](https://mathworld.wolfram.com/IcosianGame.html)</sup>。“二十面体”这个名称指的是正二十面体而非正十二面体：这两种立体各有30条边，且它们的面数与顶点数互换（正二十面体有20个面和12个顶点，正十二面体有12个面和20个顶点），这使哈密顿在研究二十面体对称性时，能把正十二面体的顶点与正二十面体的面联系起来<sup>[4](https://openstax.org/books/contemporary-mathematics/pages/12-7-hamilton-cycles)</sup>。

在哈密顿推出该游戏的两年前，托马斯·柯克曼（Thomas Kirkman）已在提交给皇家学会（Royal Society）的一篇论文中明确提出了基本问题：给定一个多面体的图，是否存在一条经过每个顶点的回路？<sup>[13](https://www.daviddarling.info/encyclopedia/I/Icosian_Game.html)</sup> 可以玩二十面体游戏的图，也就是具有哈密顿回路的图，称为哈密顿图<sup>[3](https://mathworld.wolfram.com/IcosianGame.html)</sup>。

最初的游戏棋盘有一个已知缺陷：可以选出两个顶点，它们之间不存在任何哈密顿路径相连。改进版本会使用哈密顿连通图，其中每一对顶点之间都由一条哈密顿路径相连<sup>[14](https://www.mathematica-journal.com/2010/02/05/the-icosian-game-revisited/)</sup>。

## 计算复杂度

该问题的判定版本 HAM-PATH 问的是：给定图是否包含一条哈密顿路径，通常还指定端点 \( s \) 和 \( t \)。它是NP完全的：有向版本 D-HAM-PATH——判定一个有向图是否存在从 \( s \) 到 \( t \) 的哈密顿路径——是NP完全的，无向版本同样是NP完全的<sup>[5](https://www.cs.toronto.edu/~ashe/ham-path-notes.pdf)</sup>。哈密顿路径是[理查德·M·卡普](https://www.edgepedia.org/zh/richard-m-karp)（Richard M. Karp）1972年论文《组合问题之间的可归约性》（Reducibility Among Combinatorial Problems）中21个问题之一，该文是[NP完全性](https://www.edgepedia.org/zh/np-completeness)理论的奠基性清单之一<sup>[2](https://hardness.mit.edu/drafts/2025-01-29.pdf)</sup>。在NP完全性理论发展期间，这些问题属于最早被证明计算困难的一批问题<sup>[15](https://arxiv.org/abs/2309.09228)</sup>。

即使在很强的限制下，困难性依然存在。对于每个面至少有5条边的平面、三次、三连通图，对于二部图，甚至当图的一条哈密顿路径作为实例的一部分给出时，该问题仍然是NP完全的<sup>[16](https://perso.limos.fr/~palafour/PAPERS/PDF/Garey-Johnson79.pdf)</sup>。判定一个图是否具有*唯一*哈密顿回路或路径，在多项式因子意义下，与布尔公式可满足性的唯一性问题具有相同的复杂度<sup>[17](https://arxiv.org/abs/2205.05782)</sup>。

## 算法

由于对于一般图尚无已知的多项式时间算法，精确算法都是指数时间的，许多工作旨在缩小指数底数。对顶点子集做[动态规划](https://www.edgepedia.org/zh/dynamic-programming)可在 \( O(n^{2} \cdot 2^{n}) \) 时间内解决该问题，这一上界由贝尔曼（1962）得到，赫尔德和卡普（1962）也在处理旅行商问题时独立得到了这一上界<sup>[6](https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/IntractabilityIII.pdf)</sup>。对于无向哈密顿性检测，组合算法研究者安德烈亚斯·比约克隆德（Andreas Björklund）给出了一种运行时间为 \( O(1.657^{n}) \) 的[蒙特卡洛算法](https://www.edgepedia.org/zh/monte-carlo-algorithm)；他称这是自近五十年前确立 \( O^{*}(2^{n}) \) 上界以来，对最坏情况运行时间的首个超多项式改进<sup>[7](https://arxiv.org/abs/1008.0541)</sup>。

[参数化复杂度](https://www.edgepedia.org/zh/parameterized-complexity)通过结构参数而非仅输入规模来衡量困难性。在树深度为 \( d \) 的图上，哈密顿回路、哈密顿路径、长回路、长路径和最小回路覆盖都允许运行时间为 \( 5^{d} \cdot n^{\mathcal{O}(1)} \) 且使用多项式空间的随机蒙特卡洛算法，这解决了早期 Cut&Count 技术工作留下的一个未决问题<sup>[18](https://arxiv.org/abs/2002.04368)</sup>。

**可处理图类。** 一条并行研究路线识别出问题变为多项式时间可解的特殊图类。只要一个有向图的有向树宽、DAG宽度或 Kelly 宽度保持在某个固定常数以内，[哈密顿路径问题](https://www.edgepedia.org/zh/hamiltonian-path-problem)就存在多项式时间算法。<sup>[19](https://doi.org/10.1016/J.DAM.2013.10.038)</sup> 已知区间图、余可比图和其他特殊图类有多项式时间算法<sup>[20](https://www.sciencedirect.com/science/article/pii/S0304397525002397)</sup>，近期工作解决了长期悬而未决的有界独立数图情形，表明哈密顿路径和哈密顿回路在该类图上可在多项式时间内求解<sup>[15](https://arxiv.org/abs/2309.09228)</sup>。相比之下，一般网格图上的哈密顿路径问题是NP完全的<sup>[21](https://epubs.siam.org/doi/pdf/10.1137/0211056)</sup>。

## 与旅行商问题的关系

旅行商问题（Traveling Salesman Problem，TSP）要求在加权图中找到代价最小的哈密顿回路，其核心包含哈密顿结构：一次巡回就是一条哈密顿回路，而TSP的判定版本是NP完全的<sup>[22](https://www.sciencedirect.com/science/article/pii/S0377221710006065)</sup>。其路径变体 \( s \)-\( t \) 路径TSP寻找两个指定节点之间的最短哈密顿路径而非回路；文献中也称其为信使问题、漫游推销员问题或最小哈密顿路径问题<sup>[23](https://link.springer.com/article/10.1007/s10479-025-06641-5)</sup>。对于对称度量代价，Christofides 算法的自然变体为该路径版本给出 \( 5/3 \) 近似，这一上界多年来一直是已知最好的<sup>[24](https://arxiv.org/abs/1110.4604)</sup>。2020年证明了，标准TSP的任何 \( \alpha \) 近似都可转换为相应路径变体的 \( (\alpha + \epsilon) \) 近似，从而弥合了两种情形之间长期存在的差距<sup>[23](https://link.springer.com/article/10.1007/s10479-025-06641-5)</sup>。

## 应用

**基因组组装。** 在从头基因组组装的重叠-布局-共识（overlap-layout-consensus，OLC）范式中，测序读段是重叠图中的节点，布局步骤寻找一条穿过该图、对应于基因组序列的路径；在一般情况下，识别哈密顿路径在计算上是困难的，与组装本身同属NP难问题<sup>[25](https://pmc.ncbi.nlm.nih.gov/articles/PMC2691937/)</sup>。因此，组装器按其底层图是哈密顿图还是欧拉图来分类：在哈密顿表述中，k-mer 是节点，重叠是边；而在欧拉德布鲁因图中，k-mer 是边，共享的 (k−1)-mer 是节点<sup>[26](https://academic.oup.com/bib/article/19/1/23/2339783)</sup>。欧拉德布鲁因图组装器在大基因组上通常比哈密顿方法表现更好，而且欧拉路径可在多项式时间内计算，这是德布鲁因表述在短读长组装中取代哈密顿表述的一个主要原因<sup>[26](https://academic.oup.com/bib/article/19/1/23/2339783)</sup>。

**其他领域。** 该问题被用于电子电路设计、作业调度和DNA链测序中的建模<sup>[9](https://informatica.vu.lt/journal/INFORMATICA/article/1346/read)</sup>。在路由研究中，路线经过所有需求点的循环问题称为哈密顿路由问题，TSP即为一例；而集合覆盖路由问题放宽了这一要求，使一些客户由附近节点覆盖，而不是被直接访问<sup>[27](https://www.sciencedirect.com/science/article/abs/pii/S0360835224008520)</sup>。该问题甚至用非常规硬件处理过：研究人员设计了一种细菌计算机，用来求解哈密顿路径问题的一个小实例；该问题要求在有向图中追踪一条路径，从指定节点出发，到另一节点结束，并且每个节点只经过一次。<sup>[28](https://pmc.ncbi.nlm.nih.gov/articles/PMC2723075/)</sup>

## References

1. [Hamiltonian Path, Wolfram MathWorld](https://mathworld.wolfram.com/HamiltonianPath.html)
2. [Hamiltonian Cycle, Hamiltonian Path, Directed Hamiltonian Cycle, Directed Hamiltonian Path (hardness.mit.edu notes)](https://hardness.mit.edu/drafts/2025-01-29.pdf)
3. [Icosian Game, Wolfram MathWorld](https://mathworld.wolfram.com/IcosianGame.html)
4. [12.7 Hamilton Cycles, Contemporary Mathematics, OpenStax](https://openstax.org/books/contemporary-mathematics/pages/12-7-hamilton-cycles)
5. [Hamiltonian Path is NP-Complete, course notes, University of Toronto](https://www.cs.toronto.edu/~ashe/ham-path-notes.pdf)
6. [Intractability III lecture notes, Princeton University (Bellman 1962; Held–Karp 1962)](https://www.cs.princeton.edu/courses/archive/spring13/cos423/lectures/IntractabilityIII.pdf)
7. [Andreas Björklund, Determinant Sums for Undirected Hamiltonicity, arXiv](https://arxiv.org/abs/1008.0541)
8. [Hamiltonian paths and circuits, Trinity College Dublin course notes](https://www.maths.tcd.ie/~stalker/22C00/notes/7.11-hamiltonian-paths-and-circuits.html)
9. [Beyond Quasi-Adjoint Graphs: On Polynomial-Time Solvable Cases of the Hamiltonian Cycle and Path Problems, Informatica](https://informatica.vu.lt/journal/INFORMATICA/article/1346/read)
10. [Complexity Theory I lecture slides, Universität Siegen](https://www.eti.uni-siegen.de/ti/lehre/ws2526/komplexitaetstheorie_1/folien-kt1.pdf)
11. [7.3 Hamiltonian Circuits and the Traveling Salesman Problem, Mathematics LibreTexts](https://math.libretexts.org/Courses/Florida_SouthWestern_State_College/MGF_1131%3A_Mathematics_in_Context__%28FSW%29/07%3A_Graph_Theory/7.03%3A_Hamiltonian_Circuits_and_the_Traveling_Salesman_Problem)
12. [The 'Icosian Calculus', by William R. Hamilton, Trinity College Dublin](https://www.maths.tcd.ie/pub/HistMath/People/Hamilton/Icosian/)
13. [Icosian Game, The Internet Encyclopedia of Science (David Darling)](https://www.daviddarling.info/encyclopedia/I/Icosian_Game.html)
14. [The Icosian Game, Revisited, The Mathematica Journal](https://www.mathematica-journal.com/2010/02/05/the-icosian-game-revisited/)
15. [Hamiltonian path and Hamiltonian cycle are solvable in polynomial time in graphs of bounded independence number, arXiv](https://arxiv.org/abs/2309.09228)
16. [NP-Complete Problems, A1 Graph Theory (Garey–Johnson compendium excerpt)](https://perso.limos.fr/~palafour/PAPERS/PDF/Garey-Johnson79.pdf)
17. [On the Complexity of Determining Whether there is a Unique Hamiltonian Cycle or Path, arXiv](https://arxiv.org/abs/2205.05782)
18. [Hamiltonian Cycle Parameterized by Treedepth in Single Exponential Time and Polynomial Space, arXiv](https://arxiv.org/abs/2002.04368)
19. [Digraph width measures in parameterized algorithmics, Discrete Applied Mathematics](https://doi.org/10.1016/J.DAM.2013.10.038)
20. [Hamiltonian path in permutation graphs, Theoretical Computer Science](https://www.sciencedirect.com/science/article/pii/S0304397525002397)
21. [Hamilton Paths in Grid Graphs, SIAM Journal on Computing](https://epubs.siam.org/doi/pdf/10.1137/0211056)
22. [Traveling salesman problem heuristics: Leading methods, implementations and latest advances, European Journal of Operational Research](https://www.sciencedirect.com/science/article/pii/S0377221710006065)
23. [A survey on approximability of traveling salesman problems using the TSP-T3CO definition scheme, Annals of Operations Research](https://link.springer.com/article/10.1007/s10479-025-06641-5)
24. [Improving Christofides' Algorithm for the s-t Path TSP, arXiv](https://arxiv.org/abs/1110.4604)
25. [Genome assembly reborn: recent computational challenges, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC2691937/)
26. [The present and future of de novo whole-genome assembly, Briefings in Bioinformatics](https://academic.oup.com/bib/article/19/1/23/2339783)
27. [Set Covering Routing Problems: A review and classification scheme, Computers & Operations Research](https://www.sciencedirect.com/science/article/abs/pii/S0360835224008520)
28. [Solving a Hamiltonian Path Problem with a bacterial computer, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC2723075/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Graph and network algorithms › Hard graph problems and heuristics

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hamiltonian-path

English original: https://www.edgepedia.org/hamiltonian-path
