Minimum Spanning Tree (Kruskal's Algorithm)
Visualize Kruskal's MST algorithm: sort all edges by weight, then greedily add the cheapest edges that don't create a cycle using Union-Find. Demonstrates why a greedy approach guarantees a minimum spanning tree on connected graphs.
Minimum Spanning Tree (Kruskal's Algorithm)
Visualize Kruskal's MST algorithm: sort all edges by weight, then greedily add the cheapest edges that don't create a cycle using Union-Find. Demonstrates why a greedy approach guarantees a minimum spanning tree on connected graphs.
Kruskal's MST: Sort all 7 edges by weight: (1-2,w=1), (1-3,w=2), (0-2,w=3), (0-1,w=4), (2-4,w=5), (3-2,w=6), (3-4,w=7). Use Union-Find to detect cycles.
Kruskal’s algorithm
Order the steps of building a minimum spanning tree.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
Test your knowledge
When is Kruskal preferred over Prim?
The short version
Imagine connecting all houses in a neighborhood with water pipes. You want to use the minimum total pipe length while ensuring every house gets water. MST finds the cheapest way to connect everyone.
In more depth
Two Approaches
Kruskal's Algorithm:
Prim's Algorithm:
When to Use:
Key Gotchas:
When to reach for this
- Connect all nodes with minimum total edge weight
- Network/cable/pipe laying problems
- Keywords: 'minimum cost to connect', 'spanning tree'
- Any graph edge selection with global minimum goal
Interview Questions
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required