简体   繁体   English

使用Prim算法找到有向图的MST

[英]Finding MST of directed graph using Prim's algorithm

替代文字

can any one plz help me how to Find the MST using the PRIM algorithm. 谁能帮助我如何使用PRIM算法查找MST。 Highlight the edges of the MST and write the sequence in which the nodes are added to the MST.. thanks 突出显示MST的边缘并写下将节点添加到MST的顺序。

Quoting 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. 令选定的n-1个弧为集合S。
  2. If no cycle formed, G(N,S) is a MST. 如果未形成任何循环,则G(N,S)为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. 对于每个形成的循环,将循环中的节点收缩为伪节点(k),并根据以下内容修改从循环外的某个节点(i)进入循环中的节点(j)的每条弧线的成本方程。
    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. c(i,k)= c(i,j)-(c(x(j),j)-min_ {j}(c(x(j),j))在这里c(x(j),j)是进入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. 用新选择的圆弧替换在S中输入相同实节点的圆弧。
  5. Go to step 2 with the contracted graph. 使用收缩图转到步骤2。

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. 给定的方程式显示了相关的额外成本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM