⚠️ Please use a computer for the best experience

Minimum Spanning Tree Algorithms

Interactive visualization of Kruskal's and Prim's algorithms

Controls

Graph Visualization

Step: 0 / 0

All Edges

MST Edges (0)

Kruskal's Algorithm

Greedy approach: Sort all edges by weight and add them one by one to the MST.

Union-Find: Use disjoint set data structure to detect cycles.

Time Complexity: O(E log E) where E is the number of edges.

  1. Sort all edges in ascending order by weight
  2. For each edge, check if it creates a cycle using Union-Find
  3. If no cycle, add edge to MST
  4. If cycle detected, skip the edge
  5. Continue until MST has V-1 edges