【发布时间】:2025-12-03 19:10:01
【问题描述】:
算法:
输入:图G
输出: MST 集 T
开始
T=空; E=G.边;
对于 G 中的所有顶点, 创建具有单个顶点 b 的树 t
将 t 添加到 T
结束
repeat
Find an edge e ∈ E having minimum weight
such that one end belongs to t ∈ T and the other
end does not belongs to any of the trees in T
Add e to t
until e = NULL
我卡在突出显示块的逻辑上。 我对顶点、边和树使用了简单的对象。对于他们的集合,使用了对象数组。
我有代码:
Tree[] findMSF(){
T=new Tree[numofMST];
E=new Edge[C.v.length];
for(int i=0;i<E.length;i++){
E[i]=C.e[i];//E ← C.Edges
}
for(int i=0;i<B.length;i++){
t=new Tree(B[i].v);//Create a tree t having single vertex b
T[i]=t;// T ← T U t
}
do{
e=find_e(E);
}while(e!=null);
return T;
}
我需要 find_e(E) 的实现;
【问题讨论】:
标签: java algorithm graph-algorithm