【问题标题】:Algorithm to find MST in a huge complete graph在巨大的完整图中找到 MST 的算法
【发布时间】:2013-07-01 07:09:25
【问题描述】:

让我们假设一个包含 > 25000 个节点的完整图。每个节点本质上是平面上的一个点。 它有 625M 的边。每条边都有长度,应该存储为浮点数。

我需要一个算法来找到它的 MST(在普通 PC 上)。

如果我采用 Kruskal 算法,它需要先对所有边进行排序,但我什至无法同时将边完全存储在内存中。

如果我选择 Prim 的算法,很难评估同时将多少条边存储在一个堆中,但可能大部分边在算法开始后很快就会存在。

是否有任何内存足够的算法可以让我避免对存储在文件中的边进行排序?

另外,是否有任何已知的 MST 算法利用任何树边缘满足三角形不等式这一事实?

【问题讨论】:

标签: algorithm graph computer-science minimum-spanning-tree


【解决方案1】:

您仍然可以使用 Kruskal 算法。

您实际上不需要对边进行排序,算法所需的只是一种可重复地找到尚未使用的最小权重边的方法。对边缘进行预排序并遍历该列表只是一种非常有效的方法。

你可以做同样的事情,只需重复地找到k个最小的未使用边(其中k是一个可管理的数字,可能至少|V|),然后根据需要对它们进行排序和迭代。这将排序过程分解为更易于管理的部分,尽管存在时间-空间权衡,因为取决于 k 的大小,此过程的时间复杂度可以从 O(E log E) (k = E) 到大约 O (E^2) (k = 1)。

【讨论】:

    【解决方案2】:

    Boruvka's algorithmunsorted 边缘列表上进行对数的遍历。所需内存与节点数量成正比。

    【讨论】:

      【解决方案3】:

      尝试使用这个算法

      1: Append weight w and outgoing vertex v per edge into a list, X.
      2: Divide the edge-list, E, into segments with 1 indicating the start
      of each segment, and 0 otherwise, store this in flag array F.
      3: Perform segmented min scan on X with F indicating segments
      to find minimum outgoing edge-index per vertex, store in NWE.
      4: Find the successor of each vertex and add to successor array, S.
      5: Remove cycle making edges from NWE using S, and identify
      representatives vertices.
      6: Mark remaining edges from NWE as part of output in MST.
      7: Propagate representative vertex ids using pointer doubling.
      8: Append successor array’s entries with its index to form a list, L
      9: Split L, create flag over split output and scan the flag to find
      new ids per vertex, store new ids in C.
      10: Find supervertex ids of u and v for each edge using C.
      11: Remove edge from edge-list if u, v have same supervertex id.
      12: Remove duplicate edges using split over new u, v and w.
      13: Compact and create the new edge-list and weight list .
      14: Build the vertex list from the newly formed edge-list.
      15: Call the MST Algorithm on
      

      作者:

      Vibhav Vineet    
      Pawan Harish    
      Suryakant Patidar    
      P. J. Narayanan
      

      Source

      【讨论】:

      • 也有问题,不是吗? @Fabinout
      • 另外,MST 在法语中代表 STD,所以... 比想象的还要难。 @Jayram
      • 内存复杂度不是O(E)吗?
      【解决方案4】:

      Prim 的 MST 算法和 Dijkstra 的单源最短路径算法之间存在联系,该算法已在 Prim 的 MST 算法的 BOOST Graph Library 实现中使用:

      而在 Dijkstra 算法中,当遍历最近弹出的顶点 $u$ 时,优先级队列中的顶点 $v$ 的成本函数是 $\L(s,u)+|(u,v)|$,它是相同的算法,但是 $|(u,v)|$ 作为产生 MST 而不是最短路径树的成本函数。

      内存占用与顶点数量成线性关系,可以采用 Dijkstra 算法的实现并相应地修改成本函数,或者使用 Prim 的 MST 算法的 BOOST Graph Library 实现。

      【讨论】:

        猜你喜欢
        • 2021-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多