Graph Algorithms & TraversalsAdvanced LevelStudy Time: 28 mins

Kruskal's MST Algorithm

Kruskal's Algorithm finds the Minimum Spanning Tree (MST) of a connected weighted graph by sorting all edges by weight and adding them using Union-Find cycle detection.

Loading visualizer workspace...

Real-world analogy: Connecting Power Grids

Union-Find (DSU)
Hover over items for details

Connect 10 towns with electric cables. Sort all possible cable costs and lay down the cheapest cables first, skipping any cable that creates an electrical loop.

  • Union-Find (DSU)= Detects graph cycles in near-O(1) time using path compression.

Complexity analysis

Scenario Simulator: Dataset Size (N = 500)
Presets:
N = 10N = 10,000
Complexity Curve MapKruskal's MST: O((V + E) log V) Time
Time (t)Size N (500)N = 500O(N²)O(N log N)O(N)O(log N)O(1)Kruskal's MST Gr
Time Steps (N=500)

~4,483 steps (Linearithmic)

O((V + E) log V) Time

Space Footprint

O(V + E) Graph Memory

Memory growth rate as N expands.

Performance Rank
Moderate Tier

Relative efficiency rating for large N.

OperationTime ComplexitySpace Complexity
Kruskal MST TimeO(E log E)O(V + E)

Code implementations

function kruskal(numVertices, edges) {
  edges.sort((a, b) => a.weight - b.weight);
  const dsu = new DisjointSet(numVertices);
  const mst = [];
  for (const edge of edges) {
    if (dsu.union(edge.u, edge.v)) mst.push(edge);
  }
  return mst;
}

Real-world applications

Case 01

Telecommunication Networks

Lays fiber-optic cables connecting cities at minimal infrastructure cost.

Interview questions

Topic Knowledge Test & Assessment

10 Questions Assessment

Kruskal Knowledge & Skill Test

Validate your conceptual understanding, operation mechanics, and core concepts of Kruskal.