Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following variant of the Minimum Spanning Tree ( MST ) problem. We are given an undirected graph G = ( V , E
Consider the following variant of the Minimum Spanning Tree MST problem. We
are given an undirected graph G V E with n vertices numbered from to
n and m edges, a positive not necessarily unique edge cost ce for each edge
in E and a subset of edges A E note that A may contain cycles Suppose that E
represents a set of possible direct fibre links between vertices and A represents the
existing set of direct fibre links between vertices. We would like to find the cheapest
way to connect all the vertices into one connected network.
The abstract problem we are interested in solving is to find a subset X E A
of edges of minimum cost such that V X cup A is connected.
Task: Design an algorithm that solves this problem in Om log n time.
Implement your algorithm in Ed and test it on the following instances: Graph
Graph Graph Each instance is given in a text file as described in Question
Each graph instance is given in a text file using the following format where a is
the number of edges in A:
n
m
vertexId vertexId weight
vertexId vertexId weight
a
vertexId vertexId
vertexId vertexId
For example, the following text describes the instance depicted in Fig. Note
that the vertices are numbered from to n
comp Assignment S
Your program should read input from a text file, and calculate the cost of the
solution generated by your algorithm, that is the cost of the edges in X cup A Your
program does not need to return the actual edges, just print out the total cost
rounded to two decimal places to standard output.
Your code will not be benchmarked or tested for time complexity, but for full
points it must be able to run instances similar to "Graph and each test will
time out after seconds.
Below is the scaffold
# Read in the number of vertices n and edges m
n intinput
m intinput
# Read the edges from stdin.
edges
for in rangem:
edges.appendinputsplit
# Read the A edges. You may want to use a different datastructure.
nA A intinput
for in rangenA:
Aappendinputsplit
mstweight
# Print the weight of the mst to two decimalplaces.
print:fformatmstweight
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