Описание тега prims-algorithm
Prim's algorithm is a greedy algorithm (a problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum) that efficiently finds the minimum spanning tree for the connected weighted undirected graphs. 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.
Although this algorithm may be modifed to find minimum spanning forest for unconnected graphs, other methods such as Kruskal's algorithm are recommended. Prim's algorithm, in contrast with Kruskal's algorithm, treats the nodes as a single tree and keeps on adding new nodes to the spanning tree from the given graph.
Below image shows the working of Prim's algorithm.
https://stackru.com/images/be83c87eef0f724ea2bb9bdf5d0e132347cbb53b.gif
Image Reference: Wikipedia