Skip to content

Commit b0a6a52

Browse files
author
yumengtao
committed
Prim算法
1 parent c3aae55 commit b0a6a52

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/com/zejian/structures/Graph/WeightGraph/LazyPrimMST.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* 利用深度优先搜索算法遍历图,并标记已被访问过的顶点,同时利用最小堆的特性
1313
* 每一次切分,都将新的边的权值加入堆中,并获取从其中获取最小权值的元素,必
1414
* 为最小生成树的一条边的权值
15+
*
16+
* 时间复杂度 E * LogE(deleteMin方法执行的总时间复杂度) + E * LogE(visit方法执行的总时间复杂度) = E*LogE级别
1517
*/
1618
public class LazyPrimMST<Weight extends Number & Comparable<Weight>> {
1719
private boolean visited[]; //标记已被访问过的顶点
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.zejian.structures.Graph.WeightGraph;
2+
3+
public class TestMainForPrim {
4+
5+
}

‎testWG1.txt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
8 16
2+
4 5 .35
3+
4 7 .37
4+
5 7 .28
5+
0 7 .16
6+
1 5 .32
7+
0 4 .38
8+
2 3 .17
9+
1 7 .19
10+
0 2 .26
11+
1 2 .36
12+
1 3 .29
13+
2 7 .34
14+
6 2 .40
15+
3 6 .52
16+
6 0 .58
17+
6 4 .93

0 commit comments

Comments
 (0)