作业帮 > 数学 > 作业

用prim算法和Kruskal算法求最小生成树,不要原代码要过程.

来源:学生作业帮 编辑:大师作文网作业帮 分类:数学作业 时间:2024/11/06 15:38:58
用prim算法和Kruskal算法求最小生成树,不要原代码要过程.
用prim算法和Kruskal算法求最小生成树,不要原代码要过程.
V: {1,2,3,4,5,6,7}
E: {a:(1,2):50, b:(1,3):60,
    c:(2,4):65, d:(2,5):40,
    e:(3,4):52, f:(3,7):45,
    g:(4,5):50, h:(4,6):30, i:(4,7):42,
    j:(5,6):70}kruskal0: V={{1},{2},{3},{4},{5},{6},{7}}, E={},
   pick 1st from {h,d,i,f,a,g,e,b,c,j}
1: V={{1},{2},{3},{4,6},{5},{7}}, E={h},
   pick 1st from {d,i,f,a,g,e,b,c,j}
2: V={{1},{2,5},{3},{4,6},{7}}, E={h,d},
   pick 1st from {i,f,a,g,e,b,c,j}
3: V={{1},{2,5},{3},{4,6,7}}, E={h,d,i},
   pick 1st from {f,a,g,e,b,c,j}
4: V={{1},{2,5},{3,4,6,7}}, E={h,d,i,f},
   pick 1st from {a,g,b,c,j}
5: V={{1,2,5},{3,4,6,7}}, E={h,d,i,f,a},
   pick 1st from {g,b,c,j}
6: V={{1,2,5,3,4,6,7}}, E={h,d,i,f,a,g}, pick 1st from {}
#: final V={1,2,5,3,4,6,7}, E={h,d,i,f,a,g}primVstart = 1
0: V={1}, E={}, pick 1st from {a,b}
1: V={1,2}, E={a}, pick 1st from {d,b,c}
2: V={1,2,5}, E={a,d}, pick 1st from {g,b,c,j}
3: V={1,2,5,4}, E={a,d,g}, pick 1st from {h,i,e,b}
4: V={1,2,5,4,6}, E={a,d,g,h}, pick 1st from {i,e,b}
5: V={1,2,5,4,6,7}, E={a,d,g,h,i}, pick 1st from {e,b}
6: V={1,2,5,4,6,7,3}, E={a,d,g,h,i,e}.