minWeightTree算法

新手上路,请多包涵

[50 marks] minWeightTree: the object associated with the method is a WeightedEdgeList that has already been sorted by weight. The tasks of sorting by weight and finding the minimum weight tree have been separated so that you can get part marks if one of the two methods works properly but the other one does not.
If the graph is connected, the method returns a WeightedEdgeList that contains the edges in a minimum weight spanning tree. If the graph is not connected, the edges returned give minimum weight spanning trees for each of the components of the graph. The tree edges should be removed from the WeightedEdgeList that is the object associated with the method. This means that when the method returns, the original object contains just the non-tree edges (the chords).

The algorithm you should implement for this question is:

For each of the edges e= (u, v) in the original WeightedEdgeList:

 If u and v are not in the same component
     Remove the node with e from the WeightedEdgeList
     and add it to the end of the list of tree edges.
 endif

end for
You should use the methods in the class UnionFind to maintain information about the connected components.
这个java函数怎么写

阅读 862
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题