Home > Net >  How can I find an MST from all trees containing a given edge?
How can I find an MST from all trees containing a given edge?

Time:03-03

In a weighted undirected graph, I need to modify Kruskal's algorithm to find the MST conditional to the fact that it includes a given edge 'e' in O(m log n) time. How can I do that?

CodePudding user response:

Consider kruskal's algorithm:

sort all edges in increasing order of edge weight
for every edge from u->v with weight w in the list:
    if u and v are not connected, take this edge

This algorithm at any step does not consider the graph to be "individual" nodes; rather, they are all components that can be connected by any arbitrary node within the component. Thus, if we want to force some edges to be taken in the MST, we can simply connect them before running kruskal's, and remove the edge(s) forced from the edge list provided to kruskal's.

  • Related