Graph TheoryD2Phase 2minimum-spanning-treeedgesunion-find

Kruskal MST

Greedy edge selection for MST construction with cycle avoidance feedback.

Easy Explanation

Kruskal builds a minimum spanning tree by taking the cheapest edges that do not create cycles.

Visualizer
O(1)Kruskal MST
Deterministic greedy edge selection sorted by weight, with cycle checks and accepted MST edges.

Nodes / Edges

0 / 0

Accepted

0

Total Weight

0

Result

Processing

Ready

Press Play or Step to start execution.

Progress

considered 0, accepted 0, cycle skips 0

Components

0

MST Edges

n/a

active edgeacceptedrejected (cycle)
No nodes available for visualization.
Kruskal MST Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function kruskalMst(nodeCount, edges):
  sort edges by ascending weight
  parent <- [0..nodeCount-1]
  rank <- array(nodeCount, 0)
  mst <- []
  totalWeight <- 0

  for each edge (u, v, w) in sorted edges:
    rootU <- find(parent, u)
    rootV <- find(parent, v)

    if rootU == rootV:
      continue

    union(parent, rank, rootU, rootV)
    append edge to mst
    totalWeight <- totalWeight + w

    if length(mst) == nodeCount - 1:
      break

  return { mst, totalWeight }
1.00xNo Run