Reverse-delete algorithm
From Wikipedia, the free encyclopedia
The reverse-delete algorithm is an algorithm in graph theory used to obtain a minimum spanning tree from a given connected, edge-weighed graph. If the graph is disconnected, this algorithm will find a minimum spanning tree for each disconnected part of the graph. The set of these minimum spanning trees is called a minimum spanning forest, which consists of every vertex in the graph.
This algorithm is a greedy algorithm, choosing the best choice given any situation. It is the reverse of Kruskal's algorithm, which is another greedy algorithm to find a minimum spanning tree. Kruskal’s algorithm starts with an empty graph and adds edges while the Reverse-Delete algorithm starts with the original graph and deletes edges from it. The algorithm works as follows:
- Start with graph G, which contains a list of edges E.
- Go through E in decreasing order of edge weights.
- Check if deleting current edge will further disconnect graph.
- If G is not further disconnected, delete the edge.
Contents |
[edit] Proof of correctness
The Reverse-Delete algorithm ensures connectivity in the graph or graph parts before deletion. Since the algorithm only deletes edges when it does not disconnect the graph, any edge removed by the algorithm at the time of deletion was in a cycle. Since the algorithm starts from the heaviest weighted edge and continues in decreasing order, the edge removed from any cycle is the maximum edge in that cycle. Therefore, according to the definition of a minimum spanning tree, the edges removed by the algorithm are not in any minimum spanning tree.
[edit] Pseudocode
1 function ReverseDelete(edges[] E) 2 sort E in decreasing order 3 Define an index i ← 0 4 while i < size(E) 5 Define edge temp ← E[i] 6 delete E[i] 7 if temp.v1 is not connected to temp.v2 8 E[i] ← temp 9 i ← i + 1 10 return edges[] E
In the above the graph is the set of edges E with each edge containing a weight and connected vertices v1 and v2.
[edit] Example
In the followng example green edges are those being evaluated by the algorithm and red edges are those which have been deleted.
[edit] Running time
The algorithm can be shown to run in O(E log E) time, where E is the number of edges and V is the number of vertices. This bound is achieved as follows:
- sorting the edges by weight using a comparison sort in O(E log E) time
- E iterations of loop
- deleting in O(1) time
- connectivity checked in O(logV) time
[edit] See also
[edit] References
- Kleinberg, Jon, and Eva Tardos. Algorithm Design. New York: Pearson Education, Inc., 2006.