Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your task for this assignment is to identify a spanning tree in a connected undirected weighted graph using C + + . 1 . Implement
Your task for this assignment is to identify a spanning tree in a connected undirected weighted graph using C
Implement a spanning tree algorithm using C A spanning tree is an acyclic spanning subgraph of a connected undirected weighted graph. Your program will be interactive. Graph edges with respective weights ie v v w are entered at the command line and results are displayed on the console.
Each input transaction represents an undirected edge of a connected weighted graph. The edge consists of two unequal uppercase letters representing graph vertices that the edge connects. Each edge has an assigned weight. The edge weight is a positive integer in the range to The three values on each input transaction are separated by a single space. An input transaction containing the string endoffile signals the end of the graph edge input. After the edge information is read, the spanning tree evaluation process begins. Use an adjacency matrix for recording input edges and show all code used to determine the spanning tree. The input data is assumed to be valid. There is no need to perform data validation on the input data.
Use Prims algorithm to find a minimum spanning tree MST in the input graph. Show all code used to determine the MST After the edges of the MST are determined, the MST edges are displayed on the console, one edge per output line, following the message: Minimum spanning tree: Each output line representing an MST edge contains the two letters of the edge followed by the weight, with one space after each vertex letter. After displaying the edges of the MST the program displays the message: Edge weight total: followed by the sum of the weights from the edges comprising the MST
Sample input transactions are as follows:
A B
C A
A K
E A
B C
B K
B E
C K
C E
K E
endoffile
Sample output expected after processing the above input will be as follows:
Minimum spanning tree:
A B
B E
B C
B K
Edge weight total:
Try to implement the following features:
a input graph edges are read from a text data file using C fstream library;
b output graph edges are written to a text data file using C fstream library;
c input and output file names are provided as command line parameters.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started