Saturday, August 19th
Special Edges in a Minimum Cost Spanning Tree
Given a graph represented as a weighted edgeless, find critical and pseudo-critical edges in the Minimum Cost Spanning Tree (MST) of a graph. A critical edge is an edge whose deletion would increase the cost of the MST, while a pseudo-critical edge is an edge that may appear in some MSTs.
The Tokyo subway network courtesy of Yveltal via Wikipedia. Distributed under the Creative Commons Attribution-Share Alike 4.0 International license. Not exactly a minimum cost spanning tree, but illustrates related network problemsWe assume the reader is familiar with graph theory, including the Minimum Cost Spanning Tree.
Since we are dealing with questions of connectivity, Kruskal's algorithm for MST seems like a good approach. In order to properly use it, we convert the graph to a Union-Find Data Structure
We keep a global variable vector of parents, and initiate it by setting the size equal to the number of nodes in the graph
Next, we implement the find method, which recursively calls itself until the condition is met that a node is its own parent in the data structure.
The last method for the Union-Find data structure, merge(), is implemented by finding the parents of 2 disconnected subgraphs and combining them into the same parent
With the Union-Find data structure ready, we take a look at Kruskal's and try to see how we can use it to solve the problem
Vanilla Kruskal's is below. Since the problem here deals with MST weights, we have Kruskal's only returning the weight of the MST, not the edges of the MST
The algorithm works by first sorting the edges according to weight, then beginning with the smallest-weighted edge, iterating through the edgelist while selecting edges that connect new nodes.
To test for that connection, we use the find function for the Union-Find data structure, and if the nodes of an edge reside in different components, then we call merge.
At the end, if the structure contains n-1 edges, we know we have an MST.
We modify Kruskal's in 2 ways to help solve the problem. In 1 version, we take an additional input parameter j, which identifies the index of an edge. Then add the following line of code inside the for loop that creates the vector of weighted edges:
The addition of the edge parameter allows us to create an MST without the edge in question. To find an MST without edge of index 2, we call
We can use the same function to perform ordinary Kruskal's by including the index of an edge that doesn't exist
The above function, for finding a MST weight while omitting an edge, will be used for testing whether an edge is critical or not. If k1() is called with a given edge omitted, if the the MST weight increases, then we know the edge in question is critical.
A second modification allows us to look for pseudo critical edges
In addition to including the exclusion line like in k1(), we add a line forcing the MST to use a given edge. Below, while an inputted edge is omitted in the for loop, it is forced into the MST by explicitly merging the endpoints
Forcing an edge to be in the MST helps finding the pseudo-critical edges. By forcing an edge into an MST, we can compare MST weights. If the weight with a given edge is equal to the vanilla MST, then we can say an edge is pseudo-critical.
Finally, we craft our main program to incorporate the k1() and k2() functions to answer the problem
First we initialize our Union-Find data structure, then compute the base MST weight
Then we create our solution vectors: a vector to hold the critical edges, a vector for psuedo-critical edges, and the answer vector to hold both edge vectors
Next we iterate through the edgeless.
For each edge, we compute the MST when it is omitted. If the MST increases in weight, then we have a critical edge
For each edge, we also compute when the MST is forced to include the edge. If the MST weight remains the same, we have a pseudo edge
Finally, combine both vectors into the final solution vector and return it
Definitely a hard problem, but knowing the Union-Find data structure and having a comfortable knowledge of Kruskal's, the problem isn't too complicated
Thanks to CHIIKUU for the very sensible implementation
Comments
Post a Comment