CS Visual Lab
Explore
Learning Paths
5 modules live
Get Started
Minimum Spanning Tree
Module 4.10 — Kruskal's and Prim's algorithms
Graph:
6-Node Graph
Dense Graph
Algorithm:
Kruskal's
Prim's
Step
Reset
Speed:
0.5x
1x
2x
Step 0 / 0
4
2
6
5
10
3
1
8
7
A
B
C
D
E
F
MST Edges (0/5)
Total: 0
Sorted Edges
C—F
1
A—D
2
C—E
3
A—B
4
B—D
5
B—C
6
E—F
7
D—E
8
B—E
10
Comparison
Kruskal's
O(E log E)
Sort + Union-Find
Edge-centric
Prim's
O((V+E) log V)
Priority queue
Vertex-centric
MST Properties
• Connects all V vertices with V-1 edges
• Minimum total edge weight
• No cycles
• May not be unique if equal-weight edges exist