📜  Boruvka 的最小生成树算法(1)

📅  最后修改于: 2023-12-03 14:39:34.679000             🧑  作者: Mango

Boruvka's Algorithm for Minimum Spanning Tree

Boruvka's algorithm is a greedy algorithm used to find the minimum spanning tree (MST) of a connected, weighted, and undirected graph. It was first described by Otakar Boruvka in 1926.

The algorithm works by initially treating each vertex of the graph as a separate component and finding the minimum edge connecting each component. These edges are added to the MST, and the component groups are updated. The process is repeated until there is only one component left, which is the MST.

Pseudocode
1. Initialize the MST as an empty set.
2. Initialize the components as each vertex of the graph.
3. While there is more than one component:
    a. For each component, find the minimum edge connecting it to another component.
    b. Add these minimum edges to the MST.
    c. Update the components so that each vertex is part of the same component as its nearest neighbor.
4. Return the MST.
Example

Suppose we have the following graph:

          2
   (1)-------(2)
    | \      / |
   6|   \ 7 /   |5
    |     X     |
   (4)---/   \---(3)
         3

The MST can be found using Boruvka's algorithm as follows:

1. Initialize the MST as an empty set: {}
2. Initialize the components as each vertex of the graph: {1},{2},{3},{4}
3. While there is more than one component:
    a. For each component, find the minimum edge connecting it to another component:
        - {1} -> {2} with weight 2
        - {2} -> {1} with weight 2
        - {3} -> {4} with weight 3
        - {4} -> {3} with weight 3
    b. Add these minimum edges to the MST: {(1,2),(3,4)}
    c. Update the components so that each vertex is part of the same component as its nearest neighbor:
        - {1,2}
        - {3,4}
4. Return the MST: {(1,2),(3,4)}
Time Complexity

Boruvka's algorithm has a time complexity of O(ElogV), where E is the number of edges and V is the number of vertices in the graph. This is because each iteration of the algorithm reduces the number of components by at least half, and there are at most log V iterations. Finding the minimum edge for each component takes O(logE) time using a binary heap, giving a total time complexity of O(ElogV).

Conclusion

Boruvka's algorithm is a simple and efficient way to find the MST of a connected, weighted, and undirected graph. It can be easily implemented using a binary heap to find the minimum edges, and has a time complexity of O(ElogV).