跳到主要内容

资源 · 指南或文章

Travelling Salesman Problem

陈述旅行商问题,即找出经过每座城市的最短往返路线,并展示如何把它建模为带权无向图。

审核日期

打开原站: Travelling Salesman Problem (在新标签页中打开原网站)

练习这个主题打开练习面试官,并带上一道关于 图 的题目。

添加到路线图

把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。

来源内容语言:英语

The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?" Solution of a travelling salesman problem: the black line shows the shortest possible loop that connects every red dot. TSP can be modelled as an undirected weighted graph, such that cities are the graph's vertices, paths are the graph's edges, and a path's distance is the edge's weight. It is a minimization problem starting and finishing at a specified vertex after having visited each other vertex exactly once. Often, the model is a complete graph (i.e. each pair of vertices is connected by an edge). If no path exists between two cities, adding an arbitrarily long edge will complete the graph without affecting the optimal tour.

PrepKit 概览

本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。

适合人群
来源未说明适用级别
形式
参考资料

涵盖内容

  • 图模型:城市为顶点,道路为带权边,路线需恰好访问其他每个顶点一次
  • 两座城市之间没有直达路径时,用一条任意长的边补全图

使用建议

这是 PrepKit 的学习建议,并非来源的说法。

用两种方法求解小规模实例:先尝试所有排列,再用位掩码动态规划,并在你自己设计的四城市示例上确认两者返回相同的路线长度。

范围与局限

只有问题陈述。没有算法、启发式方法、复杂度讨论或代码讲解,唯一的参考资料是维基百科。

获取方式与形式

GitHub 上采用 MIT 许可的 trekhleb/javascript-algorithms 仓库中的免费英文 README。

PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88

本概览的依据
  • src/algorithms/graph/travelling-salesman/README.md

收录此条目的页面

订阅 PrepKit 通讯

可选。使用 PrepKit 并不需要订阅。

我们如何处理你的邮箱