Minimum Spanning Tree
Minimum Spanning Tree
Only used for undirected graph
1. Kruskal's Algorithm
1.1 Description
1.2 Procedure
Suppose:
- \(G\) : Graph
- \(|N|\) : Node set of \(G\)
- \(|A|\) : Edge set of \(G\)
Step 0 : Initialization.
Create a forest \(T_0\) (a set of trees), where each node in the graph \(G\) is a separate tree, (i.e, \(T_0\) only contain all nodes of the graph \(G\) )
Create a edge set \(E_0\) containing all the edges in the graph \(G\)
Step 1: Stopping criterion. If \(A_{k} \neq \varnothing\) and \(T_{k}\) is not yet spanning (i.e., the edge number of \(T_{k}\) is less than the node number minus 1), continue to Step 2, otherwise stop.
Step 2: Select the edge \(e_k\) with minimum weight from \(A_k\)
-
(1) Remove \(e_k\) from \(A_k\):
\[A_{k+1} = A_k - \{e_k\} \] -
(2) If \(e_k\) connects two different trees, which can combining two trees into a single tree, then add it to the forest \(T_k\)
\[T_{k+1} = T_k \ \text{ add a edge } \ \{e_k \} \]Otherwise, that is, add \(e_k\) will create a loop for a tree, do nothing.
Then set \(k = k+1\), go to Step 1.
At the termination of the algorithm, the forest forms a minimum spanning forest of the graph. If the graph is connected, the forest has a single component and forms a minimum spanning tree.
1.3 Algorithm
2. Prim's Algorithm
2.1 Description
2.2 Procedure
Suppose
- \(N = \{ 1,2,\cdots, n\}\) : the set of nodes of the network
- \(C_k\) : set of nodes that have been permanently connected at iteration \(k\),
- \(\bar{C}_k\) : set of nodes as yet to be connected permanently after iteration \(k\).
The following steps describe the minimal spanning tree algorithm :
Step 0: Initiation. Set \(C_0 = \varnothing\), \(\bar{C}_0=N\), \(k=0\)
Start with any node \(i\) in the unconnected set \(\bar{C}_0\) and set
Step 1: Check the stopping criterion. If \(\bar{C}_k=\varnothing\), stop. Otherwise, go to Step 2.
Step 2: During each loop \(k\), perform the following two sub-steps:
Step 2.1: Select a node \(j^*\) from the unconnected set \(\bar{C}_k\) that yields the shortest link to someone node in the connected set \(C_n\)
Step 2.2: Adding node \(j^*\) to set \(C_n\) will not contain a cycle:
2.3 Algorithm
Suppose:
- \(\mathbf{D}\) : distance matrix, if there are not edge between two node, the distance will be set as positive infinite.
- \(\mathbf{T}\) : Output, the distance matrix of minimal spanning tree
- \(t_{i^*j^*}, \, t_{j^*i^*}\) : the distance between node \(i^*\) and \(j^*\) of \(\mathbf{T}\).
2.4 Implement by Python
2.4.1 Using network structure
2.4.2 Using constructed functions in NetworkX
# return: type of Graph
MT = nx.minimum_spanning_tree(G, weight='weight', algorithm='kruskal', ignore_nan=False)
# return: edges of MT, type of iterator
edges = nx.minimum_spanning_edges(G, algorithm='kruskal', weight='weight', keys=True, data=True, ignore_nan=False)
- Parameters:
algorithm:{'kruskal', 'prim', 'boruvka'}
3. Boruvka's Algorithm
References
[1] H. A. Taha, "Section 6.2 Minimal Spanning Tree Algorithm" in Operations research: an introduction, Tenth edition, Global edition. Harlow, England London New York Boston Amsterdam Munich: Pearson Education, 2017, p.p. 250-255.
[2] Mathematical Programming, website.
[3] Kruskal's algorithm, Wikipedia, website.

浙公网安备 33010602011771号