-
-
Notifications
You must be signed in to change notification settings - Fork 48.6k
Description
Feature description
Algorithm Name
Prim's Algorithm
Programming Language
C++
Category
Greedy Algorithms
Difficulty Level
Easy (Beginner friendly)
Algorithm Description
Prim's algorithm builds a Minimum Spanning Tree by starting with a single vertex and "growing" the tree outwards one edge at a time. It begins at an arbitrary starting node and, at each step, adds the cheapest possible edge that connects a vertex already in the tree to a vertex outside of it. This process is repeated until all vertices in the graph have been included in the tree. Imagine you're building a road network to connect several towns; Prim's is like starting in one town, then always building the shortest possible road that leads to a new, previously unconnected town, continuing this process until all towns are linked by the cheapest possible network of roads.