简体   繁体   English

找到MST的所有关键边缘

[英]Find all critical edges of an MST

I have this question from Robert Sedgewick's book on algorithms. 我有Robert Sedgewick关于算法的书中的这个问题。

Critical edges. 关键边缘。 An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. 从图中删除会导致MST权重增加的MST边缘称为临界边缘。 Show how to find all critical edges in a graph in time proportional to E log E. Note: This question assumes that edge weights are not necessarily distinct (otherwise all edges in the MST are critical). 显示如何在时间上与E log E成比例地查找图中的所有关键边。注意:此问题假定边权重不一定是不同的(否则MST中的所有边都是关键的)。

Please suggest an algorithm that solves this problem. 请建议一种解决此问题的算法。

One approach I can think of does the job in time EV My approach is to run the kruskal's algorithm. 我能想到的一种方法是及时的工作EV我的方法是运行kruskal的算法。

But whenever we encounter an edge whose insertion in the MST creates a cycle and if that cycle already contains an edge with the same edge weight, then, the edge already inserted will not be a critical edge (otherwise all other MST edges are critical edges). 但是每当我们遇到在MST中插入的边创建一个循环并且该循环已经包含具有相同边权重的边时,那么已插入的边将不是临界边(否则所有其他MST边都是临界边) 。

Is this algorithm correct? 这个算法是否正确? How can I extend this algorithm to do the job in time E log E. 如何扩展此算法以及时完成E log E.

The condition you suggest for when an edge is critical is correct I think. 我认为,当边缘严重时你建议的条件是正确的。 But it's not necessary to actually find a cycle and test each of its edges. 但是没有必要实际找到一个循环并测试它的每个边缘。

The Kruskal algorithm adds edges in increasing weight order, so the sequence of edge additions can be broken into blocks of equal-weight edge additions. Kruskal算法以增加的权重顺序添加边缘,因此边缘添加的序列可以被分解为等权重边缘添加的块。 Within each equal-weight block, if there is more than one edge that joins the same two components, then all of these edges are non-critical, because any one of the other edges could be chosen instead. 在每个等权重块内,如果有多个边连接相同的两个分量,则所有这些边都是非关键的,因为可以选择任何一个其他边。 (I say they are all non-critical because we are not actually given a specific MST as part of the input -- if we were then this would identify a particular edge to call non-critical. The edge that Kruskal actually chooses is just an artefact of initial edge ordering or how sorting was implemented.) (我说,他们都是非关键,因为我们实际上并没有给出具体的MST作为输入的一部分-如果我们那么这将确定一个特定的边缘调用非关键的克鲁斯卡真正选择的边缘仅仅是一个初始边缘排序的假象或如何实现排序。)

But this is not quite sufficient: it might be that after adding all edges of weight 4 or less to the MST, we find that there are 3 weight-5 edges, connecting component pairs (1, 2), (2, 3) and (1, 3). 但这还不够:可能是在将所有重量为4或更小的边缘添加到MST之后,我们发现有3个重量为5的边,连接组件对(1,2),(2,3)和(1,3)。 Although no component pair is joined by more than 1 of these 3 edges, we only need (any) 2 of them -- using all 3 would create a cycle. 虽然这3个边中没有超过1个连接组件对,但我们只需要(任意)2个 - 使用全部3将创建一个循环。

For each equal-weight block, having weight say w, what we actually need to do is (conceptually) create a new graph in which each component of the MST so far (ie using edges having weight < w) is a vertex, and there is an edge between 2 vertices whenever there is a weight-w edge between these components. 对于每个等权重块,具有权重w,我们实际需要做的是(概念上)创建一个新图,其中MST的每个组件到目前为止(即使用权重<w的边)是一个顶点,并且那里每当这些组件之间存在权重w边时,它就是2个顶点之间的边。 (This may result in multi-edges.) We then run DFS on each component of this graph to find any cycles, and mark every edge belonging to such a cycle as non-critical. (这可能会导致多边缘。)然后,我们在此图的每个组件上运行DFS以查找任何周期,并将属于此类周期的每个边标记为非关键。 DFS takes O(nEdges) time, so the sum of the DFS times for each block (whose sizes sum to E) will be O(E). DFS需要O(nEdges)时间,因此每个块(其大小总和为E)的DFS时间之和将为O(E)。

Note that Kruskal's algorithm takes time O(Elog E), not O(E) as you seem to imply -- although people like Bernard Chazelle have gotten close to linear-time MST construction, TTBOMK no one has got there yet! 请注意,Kruskal的算法需要时间O(Elog E),而不是O(E),因为你似乎暗示 - 虽然像Bernard Chazelle这样的人已接近线性时间的MST结构,但TTBOMK还没有人到达那里! :) :)

Yes, your algorithm is correct. 是的,你的算法是正确的。 We can prove that by comparing the execution of Kruskal's algorithm to a similar execution where the cost of some MST edge e is changed to infinity. 我们可以证明通过将Kruskal算法的执行与类似的执行进行比较,其中一些MST边e的成本变为无穷大。 Until the first execution considers e, both executions are identical. 在第一次执行考虑e之前,两个执行都是相同的。 After e, the first execution has one fewer connected component than the second. 在e之后,第一次执行的连接组件少于第二次。 This condition persists until an edge e' is considered that, in the second execution, joins the components that e would have. 这种情况持续存在,直到边缘e'被认为在第二次执行中加入e将具有的组件。 Since edge e is the only difference between the forests constructed so far, it must belong to the cycle created by e'. 由于边e是目前构建的森林之间的唯一差异,它必须属于e'创建的循环。 After e', the executions make identical decisions, and the difference in the forests is that the first execution has e, and the second, e'. 在e'之后,执行做出相同的决定,而森林的不同之处在于第一次执行具有e,第二次执行e'。

One way to implement this algorithm is using a dynamic tree, a data structure that represents a labelled forest. 实现此算法的一种方法是使用动态树,即表示标记林的数据结构。 One configuration of this ADT supports the following methods in logarithmic time . 该ADT的一种配置在对数时间内支持以下方法。

  • MakeVertex() - constructs and returns a fresh vertex. MakeVertex() - 构造并返回一个新的顶点。
  • Link(u, c, v) - vertices u and v must not be connected. 链接(u,c,v) - 顶点u和v不得连接。 Creates an unmarked edge from vertex u to vertex v with cost c. 使用cost c创建从顶点u到顶点v的未标记边。
  • Mark(u, v) - vertices u and v must be endpoints of an edge e. Mark(u,v) - 顶点u和v必须是边e的端点。 Marks e. 标记e。
  • Connected(u, v) - indicates whether vertices u and v are connected. 连接(u,v) - 表示顶点u和v是否连接。
  • FindMax(u, v) - vertices u and v must be connected. FindMax(u,v) - 必须连接顶点u和v。 Returns the endpoints of an unmarked edge on the unique path from u to v with maximum cost, together with that cost. 以最大成本和该成本返回从u到v的唯一路径上未标记边的端点。 The endpoints of this edge are given in the order that they appear on the path. 此边的端点按它们出现在路径上的顺序给出。

I make no claim that this is a good algorithm in practice. 我没有声称这是一个很好的算法。 Dynamic trees, like Swiss Army knives, are versatile but complicated and often not the best tool for the job. 动态树木,如瑞士军刀,功能多样但复杂,往往不是最好的工具。 I encourage you to think about how to take advantage of the fact that we can wait until all of the edges are processed to figure out what the critical edges are. 我鼓励你思考如何利用我们可以等到所有边缘都被处理以找出关键边缘的事实。

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

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