【发布时间】:2011-03-26 04:30:08
【问题描述】:
如果使用邻接矩阵表示,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 实现,接近页面末尾personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/GraphAlgor/…
标签: algorithm data-structures language-agnostic implementation prims-algorithm