资源 · 指南或文章
Kruskal's Algorithm
介绍 Kruskal 贪心最小生成树算法:不断加入连接两棵不同树的最轻边。
审核日期
打开原站: Kruskal's Algorithm (在新标签页中打开原网站)练习这个主题打开练习面试官,并带上一道关于 图 的题目。
添加到路线图
把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。
来源内容语言:英语
Kruskal's algorithm is a minimum-spanning-tree algorithm which finds an edge of the least possible weight that connects any two trees in the forest. It is a greedy algorithm in graph theory as it finds a minimum spanning tree for a connected weighted graph adding increasing cost arcs at each step. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component). A demo for Kruskal's algorithm based on Euclidean distance. A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges of a connected, edge-weighted (un)directed graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. That is, it is a spanning tree whose sum of edge weights is as small as possible. More generally, any edge-weighted undirected graph (not necessarily connected) has a minimum spanning forest, which is a union of the minimum spanning trees for its connected components.
PrepKit 概览
本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。
- 适合人群
- 来源未说明适用级别
- 形式
- 参考资料
涵盖内容
- Kruskal 逐边贪心扩展的过程,以及对非连通图返回最小生成森林
- 最小生成树的定义,并用一张图说明一个图可以有不止一棵最小生成树
- 动画演示,其中一个基于欧几里得距离
使用建议
这是 PrepKit 的学习建议,并非来源的说法。
用排序后的边和并查集实现 Kruskal,并确认不同的同权边处理顺序会得到权重相同但形状不同的树。
范围与局限
大多是定义和动画:没有讲解并查集,没有复杂度,也没有文字形式的逐步讲解。
获取方式与形式
GitHub 上采用 MIT 许可的 trekhleb/javascript-algorithms 仓库中的免费英文 README。
PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88
本概览的依据
- src/algorithms/graph/kruskal/README.md
收录此条目的页面
订阅 PrepKit 通讯
可选。使用 PrepKit 并不需要订阅。