Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Step: 3

blur-text-image

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago