Prim's Algorithm Visualizer

Algorithm Status
Current Step: -
Visited Nodes: -
Edges in MST: 0
Total Weight: 0
Welcome to Prim's Algorithm Visualizer
Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
Step Current Node Available Edges Chosen Edge MST So Far
How to Use This Visualizer
Step 1: Create Your Graph

Start by specifying the number of nodes (between 2 and 15) and click "Generate Nodes". Then add edges by specifying the "From" node, "To" node, and the weight of the edge.

Step 2: Run Prim's Algorithm

Click "Run Prim's Algorithm" to start the visualization. The algorithm will find the Minimum Spanning Tree (MST) step by step.

Step 3: Follow Along

Use the "Next Step" and "Previous Step" buttons to navigate through the algorithm. The explanation panel will describe what's happening at each step.

Understanding Prim's Algorithm

Prim's algorithm works by starting at an arbitrary node and repeatedly adding the cheapest edge that connects a node in the MST to a node outside the MST until all nodes are included.