Question: Write C + + code of this algorithm Prim's Algorithm: Prim's algorithm works differently from Kruskal ' s . It builds a minimum spanning tree

Write C++ code of this algorithm
Prim's Algorithm: Prim's algorithm works differently from Kruskal 's. It builds a minimum spanning
tree T by expanding outward in connected links from some vertex. One edge and one vertex are
added at each stage. The edge added is the one of least weight that connects the vertices already in T
with those not in T, and the vertex is the endpoint of this edge that is not already in T.
This algorithm involves the following steps.
(i) Choose any vertex v1 of G.
(ii) Choose an edge e1=v1v2 of G such that v2=v1 and e1 has the smallest weight among
the edges of G incident with v1.
(iii) If edges e1,e2,dots,ei have been chosen involving end points v1,v2,dots,vi+1, choose an edge
ei+1=vjvk with vjin{v1,dots,vi+1} and vkin{?v1,dots,vi+1} such that ei+1 has the smallest
(iv) Stop after n-1 edges have been chosen. Otherwise, repeat Step-3.
A step by step illustration of Prim's Algorithm to find a minimal spanning tree of the graph given
Example 11.3(Figure 12) is given below.
,
 Write C++ code of this algorithm Prim's Algorithm: Prim's algorithm works

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!