How would you find a maximum spanning tree of an edge-weighted graph? I\'ve read
ID: 3678153 • Letter: H
Question
How would you find a maximum spanning tree of an edge-weighted graph?
I've read that one can simply multiply the weight of each edge by -1 and the rest of the algorithm (Kruskal etc.) will do the job.
Will the following code be sufficient?
public EdgeWeightedGraph(In in) {
this(in.readInt());
int E = in.readInt();
if (E < 0) throw new IllegalArgumentException("Number of edges must be nonnegative");
for (int i = 0; i < E; i++) {
int v = in.readInt();
int w = in.readInt();
double weight = in.readDouble();
Edge e = new Edge(v, w, weight); << change weight to -weight?
addEdge(e);
}
}
Explanation / Answer
yes code written by you is sufficient.
U may check this also:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.