sec minimum-cost spanning trees figure graph and its mst all edges appear in the original graph those edges drawn with heavy lines indicate the subset making up the mst note that edge (cfcould be replaced with edge (dfto form different mst with equal cost ( it connects them together)and it has minimum cost figure shows the mst for an example graph prim' algorithm the first of our two algorithms for finding msts is commonly referred to as prim' algorithm prim' algorithm is very simple start with any vertex in the graphsetting the mst to be initially pick the least-cost edge connected to this edge connects to another vertexcall this add vertex and edge (nmto the mst nextpick the least-cost edge coming from either or to any other vertex in the graph add this edge and the new vertex it reaches to the mst this process continuesat each step expanding the mst by selecting the least-cost edge from vertex currently in the mst to vertex not currently in the mst prim' algorithm is quite similar to dijkstra' algorithm for finding the singlesource shortest paths the primary difference is that we are seeking not the next closest vertex to the start vertexbut rather the next closest vertex to any vertex currently in the mst thus we replace the lines if ( [ ( [vg->weight(vw)) [wd[vg->weight(vw)in djikstra' algorithm with the lines if ( [wg->weight(vw) [wg->weight(vw)in prim' algorithm