algorithm - 使用Prim算法求有向图的MST

标签 algorithm graph minimum-spanning-tree prims-algorithm

alt text

任何人都可以帮助我如何使用 PRIM 算法查找 MST。突出显示 MST 的边缘并写出节点添加到 MST 的顺序。 谢谢

最佳答案

引用The Directed Minimum Spanning Tree Problem :

  1. Discard the arcs entering the root if any; For each node other than the root, select the entering arc with the smallest cost; Let the selected n-1 arcs be the set S.
  2. If no cycle formed, G(N,S) is a MST. Otherwise, continue.
  3. For each cycle formed, contract the nodes in the cycle into a pseudo-node (k), and modify the cost of each arc which enters a node (j) in the cycle from some node (i) outside the cycle according to the following equation.
    c(i,k)=c(i,j)-(c(x(j),j)-min_{j}(c(x(j),j)) here c(x(j),j) is the cost of the arc in the cycle which enters j.
  4. For each pseudo-node, select the entering arc which has the smallest modified cost; Replace the arc which enters the same real node in S by the new selected arc.
  5. Go to step 2 with the contracted graph.

The key idea of the algorithm is to find the replacing arc(s) which has the minimum extra cost to eliminate cycle(s) if any. The given equation exhibits the associated extra cost.

关于algorithm - 使用Prim算法求有向图的MST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4565662/

相关文章:

c - 通过一次只更改一个字母将一个单词转换为另一个单词

java - 在 Java 中构建最小生成树需要使用什么数据结构?

algorithm - 插入新边时更新最小生成树

Java:我的 Prim 看起来怎么样?

c++ - 使用索引项避免重复条目

algorithm - 在 M 天内阅读 N 章书籍的最佳方式

r - 绘制二分加折线图比较

javascript - 对我自己排序的数组进行排序的有效方法

c - 从文件中删除一行,读取和重写是非常低效的……有人能想出更好的算法吗?

asp.net - jQuery flot,来自 SQL Server 的实时绘图