Minimum Spanning Tree Visualizer
Explore Kruskal's and Prim's algorithms with interactive weighted graph visualization
Graph Setup
Add Node:
Add Node
From:
Select node
To:
Select node
Weight:
Add Edge
Generate Small Graph
Generate Large Graph
Clear Graph
Algorithm Controls
Algorithm:
Kruskal's Algorithm
Prim's Algorithm
Start Node:
Select start node
Speed:
Slow
Medium
Fast
Very Fast
Start Algorithm
Step
Reset
Graph Visualization
Nodes
0
Edges
0
MST Edges
0
Total MST Weight
0
MST Edges
No MST computed yet. Select an algorithm and click "Start Algorithm".
Help
What is a Minimum Spanning Tree?
Minimum Spanning Tree (MST):
A subset of edges that connects all nodes with minimum total weight
Contains exactly (V-1) edges for V nodes
No cycles - forms a tree structure
Minimizes the sum of all edge weights
Used in network design, clustering, and optimization problems
Algorithms
Kruskal's Algorithm:
Sorts edges by weight and adds them if they don't create a cycle
Uses Union-Find data structure for cycle detection
Time complexity: O(E log E) where E is the number of edges
Works on the entire graph at once
Prim's Algorithm:
Grows the MST from a starting node
Always adds the minimum weight edge connecting MST to a new node
Time complexity: O(E log V) with binary heap
Requires selecting a start node
How to Use
Add nodes by entering labels (A, B, C, etc.)
Connect nodes by selecting two nodes, entering a weight, and clicking Add Edge
All edges are undirected (bidirectional)
Select Kruskal's (works on all edges) or Prim's (needs a start node)
Use Start to animate or Step to advance manually
MST edges are highlighted in green with thicker lines
Current edge being considered is shown in yellow
Generate sample graphs to see the algorithms in action
Visualization Colors
Gray:
Unprocessed edges
Yellow:
Current edge being evaluated
Green:
Edges included in the MST
Red:
Edges rejected (would create a cycle in Kruskal's)
Light Blue:
Nodes in the MST (Prim's algorithm)