Reverse Delete algorithm is closely related to Kruskal’s algorithm. In Kruskal’s algorithm what we do is : Sort edges by increasing order of their weights. After sorting, we one by one pick edges in increasing order. We include current picked edge if by including this in spanning tree not form any cycle until there are V-1 edges in spanning tree, where V = number of vertices.
In Reverse Delete algorithm, we sort all edges in decreasing order of their weights. After sorting, we one by one pick edges in decreasing order. We include current picked edge if excluding current edge causes disconnection in current graph. The main idea is delete edge if its deletion does not lead to disconnection of graph.
1) Sort all edges of graph in non-increasing order of edge weights. 2) Initialize MST as original graph and remove extra edges using step 3. 3) Pick highest weight edge from remaining edges and check if deleting the edge disconnects the graph or not. If disconnects, then we don't delete the edge. Else we delete the edge and continue.
If we delete highest weight edge of weight 14, graph doesn’t become disconnected, so we remove it.
Next we delete 11 as deleting it doesn’t disconnect the graph.
Next we delete 10 as deleting it doesn’t disconnect the graph.
Next is 9. We cannot delete 9 as deleting it causes disconnection.
We continue this way and following edges remain in final MST.
Edges in MST (3, 4) (0, 7) (2, 3) (2, 5) (0, 1) (5, 6) (2, 8) (6, 7)
Note : In case of same weight edges, we can pick any edge of the same weight edges.
Below is C++ implementation of above steps.
Edges in MST (3, 4) (0, 7) (2, 3) (2, 5) (0, 1) (5, 6) (2, 8) (6, 7) Total weight of MST is 37
- The above implementation is a simple/naive implementation of Reverse Delete algorithm and can be optimized to O(E log V (log log V)3) [Source : Wiki]. But this optimized time complexity is still less than Prim and Kruskal Algorithms for MST.
- The above implementation modifies the original graph. We can create a copy of the graph if original graph must be retained.
This article is contributed by Antra Purohit. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Boruvka's algorithm for Minimum Spanning Tree
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Spanning Tree With Maximum Degree (Using Kruskal's Algorithm)
- Applications of Minimum Spanning Tree Problem
- Kruskal's Minimum Spanning Tree using STL in C++
- Minimum Product Spanning Tree
- Minimum spanning tree cost of given Graphs
- Find the weight of the minimum spanning tree
- Find the minimum spanning tree with alternating colored edges
- Minimum Spanning Tree using Priority Queue and Array List
- Minimum Bottleneck Spanning Tree(MBST)
- Prim’s Minimum Spanning Tree (MST) | Greedy Algo-5
- Types of Spanning Tree Protocol (STP)
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Problem Solving for Minimum Spanning Trees (Kruskal’s and Prim’s)
- Total number of Spanning Trees in a Graph
- Total number of Spanning trees in a Cycle Graph
- Number of spanning trees of a weighted complete Graph
- Minimum number of operations required to delete all elements of the array
- Minimum cost to convert one given string to another using swap, insert or delete operations
Improved By : sanjeev2552