时间复杂度为如果使用邻接矩阵表示,则Prim的MST算法为O(|V|^2)
。Prim的MST算法在O(| V |^2)
我想实现使用邻接矩阵的Prim算法。我正在使用this 作为参考。
V = {1,2...,n}
U = {1}
T = NULL
while V != U:
/*
Now this implementation means that
I find lowest cost edge in O(n).
How do I do that using adjacency list?
*/
let (u, v) be the lowest cost edge
such that u is in U and v is in V - U;
T = T + {(u,v)}
U = U + {v}
编辑:
- 我明白Prim算法非常好。
- 我知道如何高效地使用堆和优先级队列来实现它。
- 我也知道更好的算法。
- 我想用图的邻接矩阵表示并得到O(| V |^2)的实现。
我想不能有效地实施
这是V^2实现朝向页面末尾http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/GraphAlgor/primAlgor.htm – Ankush 2012-08-22 21:38:55