Faster second-best MST algorithm?

前端 未结 2 1979
夕颜
夕颜 2021-02-15 06:38

I am struggling with this.

We can get MST using Kruskal\'s algorithm or Prim\'s algorithm for the MST.

And for \"second-best\" MST, I can:

  1. first g
2条回答
  •  渐次进展
    2021-02-15 07:18

    Let V be the vertex set and E be the edge set.

    Let T be the MST obtained using any of the standard algorithms.

    Let maxEdgeInPath(u,v) be the maximum edge on the unique path in T from vertex u to vertex v.

    For each vertex u perform BFS on T. This gives maxEdgeInPath(u,x) for all x belonging to V-u.

    Find an edge (x,y) which does not belong to T that minimizes w(x,y) - w(maxEdgeInPath(x,y))

    Weight of 2ndMST is W(T) + w(x,y) - maxEdgeInPath(x,y)

    This is based on the algorithm provided in this link. I'm not sure if this is correct and I hope someone would add a proof here.

    Compexity: To compute BST for 1 vertex takes O(V+E) = O(V) as E = V-1 in T Hence overall time complexity is O(V^2)

提交回复
热议问题