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:
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)