Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
,
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions