What is a Prim Algorithm Visualizer?
A Prim algorithm visualizer shows how a minimum spanning tree grows from one start node by repeatedly choosing the cheapest frontier edge. It is useful for learning MST algorithms, greedy graph choices, priority queues, and weighted graph interview problems.
This tool lets you paste undirected weighted edges, choose a start node, then step through each frontier edge choice while watching the selected tree expand.
For the full graph and data structure set, browse the Data Structure Visualizers hub.
How to use this Prim visualizer
- Paste one undirected weighted edge per line, such as
A B 4. - Choose the node where Prim should start.
- Click Run Prim to jump to the completed MST or forest component.
- Step forward to see the next cheapest frontier edge.
- Green edges are accepted into the MST, while blue marks the current edge under review.
Prim vs Kruskal
Prim grows one connected tree from a start node. Kruskal sorts every edge globally and accepts edges that connect different components. Both can produce a minimum spanning tree, but they expose different greedy choices.
Compare this page with the Kruskal Algorithm Visualizer to see the global edge-sorting approach. For direct disjoint-set operations, use the Union Find Visualizer.