Skip to content

Resource · Guide or article

Kruskal's Algorithm

Introduces Kruskal's greedy minimum spanning tree algorithm, which keeps adding the lightest edge joining two separate trees.

Reviewed

Open the original: Kruskal's Algorithm (opens the original site in a new tab)

Practice this topicOpens the practice interviewer with a question on Graphs.

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

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 overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Kruskal's edge-by-edge greedy growth, and the minimum spanning forest it returns for a disconnected graph
  • Definition of a minimum spanning tree, with a figure showing that a graph can have more than one
  • Animated demos, one based on Euclidean distance

How to use it

PrepKit study advice, not a claim made by the source.

Implement Kruskal with sorted edges and union-find, and confirm that different tie orders give different trees of equal weight.

Scope and limitations

Mostly definitions and animations: no union-find explanation, complexity or text walkthrough.

Access and format

Free English README on GitHub in the MIT-licensed trekhleb/javascript-algorithms repository.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/graph/kruskal/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email