Question: 1. [10] Write a C++ program to implement Prim's algorithm for finding a minimum spanning tree from a weighted, connected, undirected graph. Use the graph

 1. [10] Write a C++ program to implement Prim's algorithm for

1. [10] Write a C++ program to implement Prim's algorithm for finding a minimum spanning tree from a weighted, connected, undirected graph. Use the graph indicated by the following weighted adjacency matrix, $\boldsymbol{M}$ : \begin{tabular}{|CCCCCCCCC} \hline & $\mathbf{A}$ & $\mathbf {B}$ & $\mathbf {C}$ & $\mathbf{D}$ & $\mathbf{E}$ & $\mathbf{F}$ & $\mathbf{G}$ & $\mathbf{H}$ \hline $\mathbf{A} $ & 0 & 1 & 6 & 2 & 0& O&O & O \hline $\mathbf{B}$ & 1 & 0& 0 & 9 & 4 & 6 & 0 &0 \hline $\mathbf{C}$ & 6 & 0 & 0 & 2 & 0 & 9 & 0&O \hline $\mathbf{D} $ & 2 & 9 & 2 & 0 & 5 & 0& 7 & 0 \hline $\mathbf{E} $ & 0& 4 & 0 & 5 & 0 & 5 & 3 & 0 \hline $\mathbf {F} $ & 0 & 6 & 0 & 0 & 5 & 0 & 6 & 2 \hline $\mathbf{G}$ & 0 & 0 & 0& 7 & 3 & 6 & 0 & 0 \hline $\mathbf{H}$ & 0 & 0 & 9 & 0& 0 & 2 & 0& O \hline \end{tabular) If $\boldsymbol{M} (\mathrm{i}, \mathrm{j})=0$, no edge exists between vertices $\mathrm{i}$ and $\mathrm{j}$. Otherwise, the number is the weight (or cost) associated with the edge between vertices $i$ and $j$. You may hardcode this matrix in your program. Solutions should start with vertex A and your final output should be a list of the selected edges, in the order they were selected. Edges should be named by the vertices they connect in alphabetical order (e.g., edge $\mathbf {P Q}$ would connect vertex $\mathbf{P}$ and vertex $\mathbf{Q}$ ). The final total cost for the tree should also be displayed. CS.VS.1122||

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!