Question: In C++ please. Your programs will be tested with the same sample input files as provided in the course website, and some more test cases.
In C++ please.
Your programs will be tested with the same sample input files as provided in the course website, and some more test cases. For each problem, make sure that the running time of your program doesnt not exceed 4 seconds for file input3.txt.
link to sample input files https://drive.google.com/file/d/149ib8QnphFLfqwoM2XBQPhafzajHB3A8/view
Implement Prims algorithm to compute a Minimum Spanning Tree (MST) of a (connected, undirected) graph. For each input graph in the test files, its edges have distinct weights, thus there will be only a unique MST.
Input: The input is a text file containing specification of an undirected graph. Your program will take the file name as an argument. Input Format: The first line contains the number of nodes. Starting from the second line, edges and their weights are given, one edge per line. The two endpoints of an edge, together with the weight, are separated by space.
As mentioned earlier, there are sample test files in the course website. Below is the sizing information of the sample input files. File input1.txt: 5 nodes, 8 edges. File input2.txt: 50 nodes, 1226 edges. File input3.txt: 300 nodes, 44001 edges.
Output: You need to print to stdout information about the MST. The first line will be the total weight of the MST. For the subsequent lines, each line should list information about an edge; the two nodes need to be separated by a space, and between the two nodes, the one of smaller index should appear first. Dont output the weights. The edges must be listed in the ascending order of their weights.
Also please state the command you used to compile the code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
