本文へスキップ

リソース · ガイド・記事

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 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。

対象
ソースにレベルの記載はありません
形式
リファレンス

扱っている内容

  • 辺を一本ずつ加える貪欲な成長の仕方と、非連結グラフに対して返される最小全域森
  • 最小全域木の定義と、一つのグラフに複数の最小全域木がありうることを示す図
  • アニメーションのデモ。そのうち一つはユークリッド距離に基づく

使い方

PrepKit の学習アドバイスであり、ソースの主張ではありません。

辺のソートとunion-findを使ってKruskalを実装し、同じ重みの辺の並び順を変えると、合計の重みは同じで形の異なる木ができることを確認してください。

範囲と制約

大半は定義とアニメーションで、union-findの説明、計算量、文章による解説はありません。

利用方法と形式

MITライセンスのtrekhleb/javascript-algorithmsリポジトリ内のGitHub上のREADMEで、英語で無料で読めます。

PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88

この概要の根拠
  • src/algorithms/graph/kruskal/README.md

この項目を掲載しているページ

PrepKit ニュースレターを受け取る

任意です。PrepKit の利用には必要ありません。

メールアドレスの取り扱いについて