Answered step by step
Verified Expert Solution
Link Copied!

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++.
1. 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 (i.e., v1 v2 w) are entered at the command line and results are displayed on the console.
2. 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 1 to 99. The three values on each input transaction are separated by a single space. An input transaction containing the string end-of-file 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.
3. 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 2
C A 4
A K 10
E A 6
B C 3
B K 8
B E 1
C K 55
C E 7
K E 9
end-of-file
Sample output expected after processing the above input will be as follows:
Minimum spanning tree:
A B 2
B E 1
B C 3
B K 8
Edge weight total: 14
4. 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.
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

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Defi ne waste.

Answered: 1 week ago