Kruskal Algorithm Visualizer

Paste undirected weighted edges, sort them by weight, then step through Kruskal's accept-or-reject cycle checks.

Nodes
6
Edges
10
Selected
0
Weight
0

Weighted graph input

Use one undirected edge per line: node A, node B, weight.

Step controls

Sort 10 edge(s) by weight from smallest to largest.

Minimum spanning tree graph

Green edges are selected. Blue is the edge under review. Red is rejected.

Accepted Checking Root
Kruskal MST graph diagramUndirected weighted graph with 6 nodes and 10 edges.4231546237Aroot=ABroot=BCroot=CDroot=DEroot=EFroot=F

Sorted edges

EdgeWeightStatus
B-C1pending
A-F2pending
D-E2pending
A-C3pending
E-F3pending
A-B4pending
C-D4pending
B-D5pending
C-E6pending
D-F7pending

MST output

selected = 0
total_weight = 0
components = 6
No MST edges selected yet.

What is a Kruskal Algorithm Visualizer?

A Kruskal algorithm visualizer shows how a minimum spanning tree is built by sorting weighted edges and accepting only the edges that connect different components. It is useful for learning MST algorithms, cycle detection, union find, and graph interview problems.

This tool lets you paste undirected weighted edges, then step through each accepted or rejected edge while watching the disjoint-set parent table.

For the full graph and data structure set, browse the Data Structure Visualizers hub.

How to use this Kruskal visualizer

  • Paste one undirected weighted edge per line, such as A B 4.
  • Click Run Kruskal to jump to the completed MST or forest.
  • Step through the sorted edge list to see which edge is considered next.
  • Green edges are accepted into the MST.
  • Red edges are rejected because they would create a cycle.

Kruskal and union find

Kruskal uses union find to track which nodes already belong to the same connected component. When an edge connects two different roots, it is safe to accept. When both endpoints already share a root, accepting the edge would form a cycle.

Compare this page with the Prim Algorithm Visualizer to see the frontier-growing MST approach. Use the Union Find Visualizer to inspect the disjoint-set operations directly. For an all-pairs shortest path matrix instead of an MST, use the Floyd Warshall Visualizer.

Frequently Asked Questions

What input format does this Kruskal visualizer use?
Paste one undirected weighted edge per line with two endpoints and a weight, such as A B 4.
What does Kruskal's algorithm find?
Kruskal finds a minimum spanning tree for a connected undirected weighted graph, or a minimum spanning forest if the graph is disconnected.
Why does Kruskal use union find?
Union find quickly checks whether an edge connects two different components or would create a cycle.
Can MST edges have negative weights?
Yes. Minimum spanning tree algorithms can handle negative edge weights because they only compare edge weights and avoid cycles.

Related tools