Prim's Algorithm - Minimum Spanning Tree (MST)

By Jahidul Arafat, Presidential Graduate Research Fellow, CSSE, AU, USA; (ex) Sr. Solution Architect, Oracle

https://www.linkedin.com/in/jahidul-arafat-presidential-fellow-phd-student-791a7490/

Default Graph Demo
Custom Graph Builder

Prim's algorithm finds the minimum spanning tree (MST) of a connected weighted undirected graph. It grows the MST one vertex at a time, always adding the lowest-weight edge that connects a vertex in the MST to a vertex outside the MST.

Starting node: 0

Original Graph

MST Construction (Current Step)

Step: 0

Priority Queue (Edges being considered)

MST Edges Added

Step Edge Weight Reason for Selection

Create your own graph below. Add nodes, then add edges between them with weights. When you're ready, run Prim's algorithm to find the minimum spanning tree.

Graph Editor

Add/Remove Nodes

Add/Remove Edges

Your Custom Graph

Visualization Legend

Node Colors

Node in MST
Newly Added Node
Starting Node
Frontier Node (Connected but not in MST)
Remaining Node (Original Graph)

Edge Colors

Edge in MST
Newly Added Edge
Edge in Priority Queue
Original Graph Edge

Prim's Algorithm Results

Minimum Spanning Tree

MST Edges

From To Weight