Abstract
This paper presents an algorithm for effectively maintaining the minimum spanning tree in dynamic weighted undirected graphs. The algorithm efficiently updates the minimum spanning tree when the underlying graph structure changes. By identifying the portion of the original tree that can be preserved in the updated tree, our algorithm avoids recalculating the minimum spanning tree from scratch. We provide proof of correctness for the proposed algorithm and analyze its time complexity. In general scenarios, the time complexity of our algorithm is comparable to that of Kruskal’s algorithm. However, the experimental results demonstrate that our algorithm outperforms the approach of recomputing the minimum spanning tree by using Kruskal’s algorithm, especially in medium- and large-scale dynamic graphs where the graph undergoes iterative changes.
MSC:
05C85
1. Introduction
Given a weighted undirected connected graph, the minimum spanning tree (MST) problem involves finding a subgraph spanning all vertices in the graph without ring structures and with the minimized sum of edge weights. This problem was first introduced by Brouvka in 1926. Nesetril and Nesetrilova [1] have provided a detailed overview of the origin and development of the MST problem. MST has widespread applications in real-life scenarios, including transportation problems, communication network design, and many other combinatorial optimization problems. For example, MST is commonly employed in clustering (see [2,3,4]). It is a common method to study relationships in financial markets by constructing an MST from correlation matrices (see [5,6,7]). MST is also used for analyzing brain networks (see [8,9,10]). The MST problem is also common in various production and life applications, such as power grid configuration [11], dynamic power distribution reconfiguration [12], optimal configuration problem [13], etc.
Real-world problems requiring solutions to the MST problem often involve graphs of immense scale and dynamic changes. Although polynomial-time algorithms exist for the MST problem, the real-time computation for large-scale graphs remains challenging. Moreover, real-world scenarios typically involve modifications to only a small portion of the original graph. Recalculating the entire graph using MST algorithms for the new graph results in significant redundant computations. This underscores the need for effective maintenance of the MST in dynamic graphs. Solutions designed for static problems are generally inadequate to meet the requirements of dynamic graphs [14]. In the context of the Internet of Things (IoT) domain, Wireless Ad Hoc Networks are commonly used and often employ a minimum dominating tree (MDT) structure as the backbone for network traffic management [15]. MDT is a spanning tree that encompasses a specific dominating set within the network. Given the dynamic nature of Ad Hoc Networks, they frequently change over time, necessitating corresponding adjustments in their backbone structure. To ensure efficient maintenance of the backbone, an effective solution to the dynamic minimum spanning tree (MST) problem is necessary. Moreover, the algorithm for dynamic MST can also be employed as a sub-procedure in the MDT algorithm to enhance convergence [16].
This paper studies the problem of updating the original MST of a graph when its structure changes. Given a weighted undirected graph and its MST, the problem queries a new MST based on the original one if the graph changes its structure, i.e., if edges and vertices are added or removed.
Existing algorithms for maintaining the minimum spanning tree in dynamic graphs are usually designed for various scenarios. Frederickson et al. [17] proposed a top-tree-based algorithm, which is specifically designed for graphs where the maximum degree of vertices is three. Amato et al. [18] conducted the first experimental study on dynamic minimum spanning tree algorithms. They implemented different versions of Frederickson’s algorithm using partitioning and top-trees. Additionally, to achieve the fastest random input, Henzinger and King [19] introduced a fully dynamic minimum spanning tree algorithm. Holm et al. [20] improved the algorithm proposed by Henzinger and King. They were the first to introduce a fully dynamic minimum spanning tree algorithm with logarithmic-time complexity. Cattaneo et al. [21] further optimized several algorithms for this problem. Eppstein et al. [22] introduced sparsification techniques on top of Frederickson’s algorithm, reducing the time complexity to . Based on Eppstein’s work, Kopelowitz et al. [23] proposed the algorithm with the best-known results, achieving a time complexity of per update for each vertex, but only allowing single-edge updates. Tarjan and Wereck [24] conducted experiments on two variants of dynamic tree data structures (self-adjusting and worst-case) and compared their advantages and disadvantages. Chen et al. [25] proposed the LDP-MST algorithm, which calculates density based on the results of the natural neighbor search algorithm, identifies local density peaks, and then constructs the minimum spanning tree. Junior et al. [26] proposed an algorithm for solving the variant of the fully dynamic minimum spanning tree problem, addressing the incremental minimum spanning tree problem through complete backtracking. Anderson et al. [22] proposed a parallel batch-processing dynamic algorithm for incremental minimum spanning trees. They introduced a parallel data structure for batch-processing incremental MSF problems, achieving polynomial time for each edge insertion, which is more efficient than the fastest sequential single-update data structure for sufficiently large batches. Tseng et al. [27] implemented parallelization based on Holm et al.’s work and proposed a parallel batch algorithm to maintain MSF.
After reviewing the current state of research, it is apparent that the majority of the existing studies have predominantly concentrated on scenarios involving single changes. In this paper, our objective is to explore a specific scenario where a portion of the graph undergoes alteration. Furthermore, we propose a method that is well suited for preserving MST in situations where the graph undergoes iterative structural modifications, with only a small segment of the graph being altered in each iteration.
The following of the paper is organized as follows: Section 2 describes the problem studied by this paper in detail; Section 3 introduces the proposed MST maintenance algorithm; Section 4 includes theoretical proofs and an analysis of the time complexity of the proposed algorithm; Section 5 presents the experiments conducted and evaluates the proposed algorithm; finally, Section 6 concludes the paper and outlines prospects for future work.
2. Problem Description
Given a weighted undirected graph , where V is the set of vertices and E is the set of edges, and its minimum spanning tree, this paper investigates a rapid updating and generation algorithm for the new minimum spanning tree when partial structural changes occur in graph G. If the updated graph becomes a non-connected graph, the algorithm should provide a minimum spanning forest. This section describes two specific scenarios of graph changes and generalizes the common variations in the graph accordingly.
2.1. Minimum Spanning Tree of the Subgraph in the Original Graph
If the changes to the graph only involve the removal from the original graph, the updated graph is a subgraph of the original. The problem then becomes finding the minimum spanning tree of a subgraph of the original graph. This is defined as follows: Given a weighted undirected graph and its spanning tree T, the task is to find the minimum spanning tree of graph , where .
The MST of a subgraph may differ from or be identical to the MST of the original graph. Figure 1 illustrates an example of the subgraph MST problem. Given the original graph shown in Figure 1a, where solid lines represent edges in the MST (following schematic figures), a subgraph is formed by removing edge , as depicted in Figure 1b. It can be observed that the MST of this subgraph is different from that of the original graph. If the removed edge is not part of the original MST, the MST of the subgraph is identical to the original MST, as shown in Figure 1c.
Figure 1.
Illustration of subgraph minimum spanning tree problem. (a) The original graph and its MST; (b) Removing changes the MST; (c) Removing does not change the MST. (Numbers on edges represent the edge weights. The following figures are the same).
Removing a vertex from the original graph can be reduced to removing multiple edges. The new minimum spanning tree obtained after removing a vertex from the original graph has the same weight as the minimum spanning forest obtained by removing all edges connected to this vertex, after which this vertex becomes an isolated vertex, and its presence or absence does not affect the weight of the minimum spanning tree. For example, in the original graph shown in Figure 2a, after deleting vertex B, the subgraph and its minimum spanning tree are shown in Figure 2b. After deleting all edges connected to vertex B, the subgraph and its minimum spanning forest are shown in Figure 2c. Deleting a vertex from the original graph changes the minimum spanning tree.
Figure 2.
Deleting vertex B provides the same MST as deleting all edges related to B. (a) The original graph; (b) Deleting vertex B; (c) Deleting all edges connected to vertex B.
2.2. Minimum Spanning Tree of the Supergraph in the Original Graph
If the modifications to the graph only involve additions to the original graph, then the updated graph becomes a supergraph of the original. The problem becomes finding the minimum spanning tree (MST) of a certain supergraph of the original graph. The definition is as follows: Given a weighted undirected graph and its spanning tree T, the objective is to find the minimum spanning tree of graph , where .
Figure 3 illustrates an example of the supergraph minimum spanning tree problem. Given the original graph and its spanning tree shown in Figure 3a, the supergraph with the added edge and its minimum spanning tree are depicted in Figure 3b. It can be observed that in this example, the spanning tree of the supergraph differs from that of the original graph. Through analysis, it can be deduced that when the weight of the added edge is less than the weight of a certain edge forming a cycle in the original MST, the new MST changes. For example, in this instance, adding creates a cycle in the original MST: — — ; the weight of is less than the weight of in the cycle. If the weight of the added edge is greater than the weights of all other edges in the cycle, then the MST of the supergraph remains the same as that of the original graph, as shown in Figure 3c.
Figure 3.
Example of a supergraph minimum spanning tree. (a) The original graph and its MST; (b) Adding edge with weight 4 changes the MST; (c) Adding edge with weight 15 does not change the MST.
From the original graph, the addition of a vertex can be reduced to adding multiple edges. Consider the vertex to be added firstly as an isolated vertex in the original graph, and then add the edges associated with it to the original graph. For example, considering the original graph and its spanning tree shown in Figure 4 (left), after adding vertex Q along with edges and , the resulting supergraph and its minimum spanning tree are illustrated in Figure 4 (right). Adding a non-isolated vertex to the original graph inevitably alters the minimum spanning tree.
Figure 4.
Example of a supergraph with added vertex Q.
2.3. Minimum Spanning Tree after Modifications to Original Graph
When the modified graph is not a subgraph or supergraph of the original graph, the transformation can be broken down into two distinct sub-processes: removing edges and adding new edges. This leads to the transformation of the original problem into two processes, solving a subgraph minimum spanning tree and a supergraph minimum spanning tree.
Let the original graph be denoted by and the changed graph by . First, we determine the set of edges removed in compared with G as and the set of edges added in compared with G as . Subsequently, we calculate the minimum spanning tree of subgraph . Then, we calculate the minimum spanning tree of supergraph , where is equivalent to .
For example, as depicted in Figure 5a, the original graph transforms into the new graph shown in Figure 5c (by deleting and adding ). To find the minimum spanning tree of the resulting graph, one can first determine the minimum spanning tree of the subgraph (by deleting ), as shown in Figure 5b, and then compute the minimum spanning tree of the supergraph (by adding ), which is equivalent to the graph in Figure 5c.
Figure 5.
Schematic diagram of the splitting operation to solve the minimum spanning tree of the new graph after the change. (a) The original graph and its MST; (b) Removing ; (c) Removing and adding .
3. Fast Updating and Maintenance Algorithm for Minimum Spanning Trees
This section describes an algorithm for efficiently updating and maintaining the minimum spanning tree in a dynamic graph. To facilitate the subsequent algorithm descriptions, we first define the following symbols:
- : ordered set of edges in graph E, where the edges are sorted in ascending order of weight.
- : set of edges added in the new graph compared with the original graph.
- : set of edges removed in the new graph compared with the original graph.
- D: array representing the disjoint-set data structure. If , it signifies that vertex i is a non-representative vertex, and denotes the representative vertex number of the connected component containing vertex i. If , it indicates that vertex i is the representative vertex of its connected component, and the absolute value of is the number of vertices in the current connected component. This data structure is globally visible throughout the algorithm.
- V: visitation array used as an auxiliary data structure for reconstructing the disjoint set during sub-processes. indicates that vertex i has been visited; otherwise, . This data structure is globally visible throughout the algorithm.
- T: set of edges for the current spanning tree.
- : set of edges for the updated spanning tree.
3.1. Framework of the Algorithm
The overall framework of the algorithm is described in Algorithm 1. The input to the algorithm consists of the given graph G, the ordered edge set of G, the minimum spanning tree T of G, the set of edges to be added , and the set of edges to be removed . The algorithm first calculates the minimum spanning tree of the subgraph obtained by removing the edges in from the original graph (Line 7). Subsequently, it computes the minimum spanning tree of the new graph obtained by adding the edges in to this subgraph and its spanning tree (Line 11).
It is worth noting that the algorithm requires information about the sorted edges of the current graph based on edge weights (ordered edge set ) to enhance computational speed. Upon completion of the algorithm, the ordered edge set of the new graph will be returned for subsequent updates and maintenance of the minimum spanning tree when further changes occur. The updating algorithm for the minimum spanning tree of the subgraph in Algorithm 1, as well as the updating algorithm for the supergraph, will be specifically described in the following sections.
| Algorithm 1 MST updating: dynamic graph MST fast updating and maintenance algorithm |
|
3.2. Updating and Maintenance of Minimum Spanning Trees for Subgraphs
This section describes the updating algorithm for the minimum spanning tree of the subgraph, as depicted in Algorithm 2.
| Algorithm 2 MST updating subgraph: dynamic graph MST fast updating and maintenance algorithm |
|
The algorithm takes as input the current graph G, the minimum spanning tree T before the graph changes, the set of deleted edges , and the ordered set of edges from the original graph. The algorithm first removes from the original minimum spanning tree T to obtain the pruned subgraph (Line 4). Subsequently, the algorithm reconstructs and returns the disjoint set data structure D based on by using a depth-first traversal process, along with the count (n) of connected components in .
If equals T or forms a connected structure (), then it is the updated minimum spanning tree (Lines 6–8). Otherwise, the algorithm iteratively examines the edges in set that do not belong to or , and if an edge connects two different connected components in , it is added to until has edges. At this point, becomes the updated minimum spanning tree (Lines 9–16).
The latter part of the algorithm (Lines 9–16) is essentially similar to Kruskal’s algorithm. The key distinction lies in the fact that Kruskal’s algorithm starts building the minimum spanning tree from scratch, while Algorithm 2 maximizes the utilization of the original graph’s minimum spanning tree. It begins constructing the new graph’s minimum spanning tree from the substructure derived from the original graph’s minimum spanning tree. To facilitate the continuation of Kruskal’s algorithm based on substructure , a disjoint set structure D matching the current is required. Algorithms 3 and 4 describe the logical steps for obtaining the corresponding disjoint set D based on input .
| Algorithm 3 Rebuilding disjoint set and returning current component count |
|
| Algorithm 4 Recursive sub-procedure for rebuilding the disjoint set |
|
Algorithm 3 initializes D and V. It starts by searching for an unvisited vertex in after initialization (Line 6), marks it as visited, and performs a depth-first traversal starting from it (Line 11). If there are no unvisited vertices after this depth-first traversal, the algorithm terminates; otherwise, it starts over from another unvisited vertex. The sub procedure find_unvisited in Algorithm 3 traverses the vertices in and returns the index of the first vertex corresponding to a FALSE V value. If all vertices have TRUE V values, find_unvisited returns −1. The detailed logic of the depth-first traversal process count_recur is described in Algorithm 4.
Algorithm 4 is an iterative depth-first traversal operation for a subgraph to rebuild the disjoint set, with the representative vertex and the current vertex v. If , the value represents the representative of vertex v; if , it indicates that v is a root representative representing all the other vertices in this connected component, and its absolute value represents the number of vertices in the connected component.
Algorithm 5 checks whether the two endpoints of edge e are connected to the two connected components in the current subgraph T. If true, it adds edge e to the current subgraph T, updates the corresponding D values, and returns the updated subgraph . The process of Algorithm 5 is identical to the corresponding steps in Kruskal’s algorithm.
| Algorithm 5 Checking if edge e belongs to minimum spanning tree |
|
This algorithm differs from Kruskal’s algorithm in that it does not compute the spanning tree from scratch but utilizes the original minimum spanning tree of the graph and reconstructs its corresponding disjoint set. The depth-first traversal operation has linear-time complexity, whereas obtaining the same disjoint-set structure using Kruskal’s algorithm involves polynomial-time complexity.
3.3. Updating and Maintenance of Minimum Spanning Trees for Supergraphs
This subsection describes the minimum spanning tree updating algorithm for supergraphs. The algorithmic logic is shown in Algorithm 6. The input of Algorithm 6 includes the current graph G, the minimum spanning tree T before the graph changes, the set of added edges , the set of deleted edges , and the ordered set of edges in the original graph. Algorithm 6 first obtains the union of T and , denoted by ; then it executes Kruskal’s algorithm with elements only from ; finally, it generates the ordered edge set for the current graph G based on , , and , which will be used for the subsequent iterations to update the minimum spanning tree. Although a supergraph does not contain any deleted edges compared with the original graph, the deleted edges here are the ones from the previous subgraph procedure and are used to generate the ordered edge set for the next iteration.
| Algorithm 6 Supergraph minimum spanning tree fast updating and maintenance algorithm |
|
Algorithm 7 describes how to generate the ordered edge set for the current graph G. The logic involves a one-time merge–sort operation on two ordered setsone-time merge sort of two ordered sets: the ordered set of elements from and the ordered set , excluding elements belonging to . It is important to note that when scanning elements from one by one, elements belonging to should be skipped.
| Algorithm 7 Updating ordered edge set |
|
This algorithm differs from Kruskal’s algorithm in that it does not use the complete current graph edge set but only the edge set , where is the union of the edge set of the original minimum spanning tree and the added edge set. For large sparse graphs with a relatively small added edge set, the size of is much smaller than the complete edge set E. Consequently, the number of instruction operations in this algorithm is lower than that of the operations required for performing the complete Kruskal’s algorithm on the current graph.
4. Theoretical Analysis
This section provides the theoretical proof of optimality for the proposed algorithm in this paper. Specifically, given the original graph and its minimum spanning tree, the results provided by the algorithm presented in this paper are proven to be a correct minimum spanning tree for the updated graph. Additionally, this section includes an analysis of the time complexity of the proposed algorithm.
4.1. Correctness Analysis
As described in Section 3.2, the main approach of the algorithm proposed in this paper for computing the minimum spanning tree of a subgraph is to inherit edges from the original minimum spanning tree. The goal is to achieve a fast computation of the minimum spanning tree for the subgraph. Theorem 1 establishes that the results obtained using this approach are guaranteed to be a correct minimum spanning tree for the subgraph.
Theorem 1.
Given a weighted connected undirected graph , where is an edge in its minimum spanning tree T (i.e., ), if e also exists in the connected subgraph of graph G, i.e., , then for this subgraph of G, it is guaranteed that a minimum spanning tree containing edge e can be found.
Proof.
Let us assume there exists a subgraph containing e while all its minimum spanning trees do not contain e.
Due to being an edge in some minimum spanning tree T of graph G, we can infer two situations (denoted as verdict A) as follows:
- A
- 1: There is no simple path in graph G connecting x and y without e;2: There exists a simple path P in graph G connecting x and y without e, and in P, there must be an edge with a weight greater than or equal to e.
From the assumption, we can infer verdict B as follows:
- B
- In , there exists a simple path connecting x and y without e, and all edges in have weights smaller than e.
Since is a subgraph of G, must also be a path in G. Verdicts A and B contradict each other. Therefore, the assumption is false, i.e., if the spanning tree edge of the original graph appears in a subgraph, it must be included in some minimum spanning tree of the subgraph. This completes the proof. □
The algorithm described in Section 3.3 aims to efficiently compute the minimum spanning tree of a supergraph. The main idea is to exclude edges that cannot appear in the minimum spanning tree of the supergraph. Theorem 2 establishes that the results obtained using this approach are guaranteed to be a correct minimum spanning tree for the supergraph.
Theorem 2.
Given an undirected weighted connected graph and T as one of its minimum spanning trees, if there exists an edge such that and , then there exists a minimum spanning tree for some supergraph that does not include edge e.
Proof.
Let us assume that the minimum spanning tree of supergraph must include edge .
Due to the minimum spanning tree T of graph G not containing , we can infer verdict A as follows:
- A
- There must be a simple path P in graph G connecting x and y without e, satisfying that all edges in P have weights smaller than or equal to e.
Let be some path in that connects x and y including e. From the assumption, we can infer verdict B as follows:
- B
- The weight of e is less than the weight of the maximum-weight edge in .
Since is a supergraph of G, must also be a path in . Therefore, P should satisfy verdict B, i.e., there exists an edge in P with a weight greater than the weight of e. This conclusion contradicts verdict A. Thus, the assumption is false, and a minimum spanning tree without e can certainly be found for supergraph . This completes the proof. □
Due to the algorithm decomposing the general case of graph updates into the solutions of minimum spanning trees for subgraphs and supergraphs, it is known from the above two theorems that the algorithm proposed in this paper can provide a correct minimum spanning tree for the updated graph.
4.2. Complexity Analysis
In this section, we conduct an analysis of the time complexity of the algorithm based on the pseudo-code in Section 3. We analyze the upper bound of the worst case and the lower bound of the best case of the proposed algorithm.
4.2.1. Worst-Case Analysis
For Algorithm 7, the main operations include two parts: the sorting of in Line 4, with a time complexity of , and the subsequent merge operation of ordered element columns, with a time complexity of . By combining these, the time complexity of Algorithm 7 is .
For Algorithm 6, the main operations are divided into two parts: from Line 5 to Line 13, we have Kruskal’s algorithm for a specific substructure, with a time complexity of , and Line 14 is as described in Algorithm 7. Overall, the time complexity of Algorithm 6 is . Since , this expression can be simplified to . When the number of added edges is sufficiently small, this expression can be further simplified to . For dense graph scenarios, this expression can be further simplified to .
The essence of Algorithm 3 is the depth-first traversal operation for a given substructure T. If the graph is stored using an adjacency list structure, its time complexity is . Since , this expression can be simplified to .
Algorithm 2 has three main operations.
Line 4: Deleting edges from in the original spanning tree T. If is stored using a hash table structure, the time complexity is .
Line 5: Algorithm 3.
The following steps of Algorithm 2 involve a Kruskal’s algorithm-like operation for elements in , with a time complexity of .
Overall, the time complexity of Algorithm 2 is . Since , this expression can be simplified to . When the number of removed edges is sufficiently small, this expression can be further simplified to . For dense graphs, this expression can be further simplified to .
In summary, the time complexity of the proposed algorithm in general is
When the amount of changes to the graph is sufficiently small, the algorithm’s time complexity expression can be simplified to
When the amount of changes to the graph is sufficiently small and the graph is dense, the algorithm’s time complexity expression can be further simplified to
The time complexity of this algorithm is the same as the standard Kruskal’s algorithm. This implies that the proposed algorithm is theoretically equivalent to performing a complete recalculation of the minimum spanning tree by using the standard Kruskal’s algorithm. However, in practical runtime, the proposed algorithm effectively reduces the actual search space, making it more efficient for multiple iterations of updates on large-scale graphs. The subsequent sections will provide comparative data between the proposed algorithm and Kruskal’s algorithm in actual runtime.
4.2.2. Best-Case Analysis
When the new graph is a subgraph, the best case occurs when the removed edges do not belong to the original tree or their removal does not disconnect the tree. Algorithm 2 can be terminated before Line 10. If the removed edges do not belong to the original tree, the time complexity of Algorithm 2 is exactly the one of the sub-procedure remove_e_from_tree, i.e., . Let us suppose that some of the removed edges belong to the original tree but their removal does not disconnect it. In that case, the time complexity of Algorithm 2 depends on Algorithm 3, i.e., . The other sub-procedures do not execute when the updated graph is a subgraph. Therefore, the lower-bound time complexity of the subgraph best case is . If the removal is small compared with the graph, it can be simplified to .
When the new graph is a supergraph, the best case occurs when all the added edges have a greater cost than the ones in the original tree. However, the proposed algorithm does not explicitly check this situation; it proceeds to calculate the spanning tree using the reduced edge set. But, in this case, the updated three edges will be exactly the first ones in the edge set, which means that the algorithm terminates when it has traversed elements in the edge set. Algorithm 7 does not execute, since is empty. Therefore, the lower-bound time complexity of the supergraph best case is .
Since , when a spanning tree is successfully found, the overall lower bound of the time complexity of the best case for the proposed algorithm is .
5. Experimental Analysis
This section presents an experimental analysis of the efficiency of the proposed algorithm. The dynamic graph minimum spanning tree updating and maintenance algorithm proposed in this paper was tested in the following three scenarios.
(1) Given the original graph and its spanning tree, solve the minimum spanning tree of the original graph’s supergraph. (2) Given the original graph and its spanning tree, solve the minimum spanning tree of the original graph’s subgraph. (3) Solve the minimum spanning tree of the new graph after changes to the original graph.
Additionally, a comparison of the runtime between the proposed algorithm and Kruskal’s algorithm, which recalculates the new graph, was conducted.
5.1. Experimental Data
The algorithms used in the experiments were implemented in Java. The experimental platform consisted of a computer with a six-core processor (Intel Core i7 2.6 GHz) and 16 GB of memory, running on the Windows 11 operating system. The timing for all algorithms in the experiments was measured in milliseconds.
The test instances were obtained from a common set of instances for the minimum dominating tree problem [28]. Each instance represents a weighted undirected graph , where V is the set of vertices and E is the set of edges. The instances were generated as follows: vertices were randomly deployed in a area, and edges connected vertices if the straight-line distance between them was less than a certain distance. The edge weights were assigned as the distances between the vertices. The instance set was divided into three groups based on the maximum vertex connection distance, namely, Range_100, Range_125, and Range_150 (the number indicates the maximum vertex connection distance, and a larger number indicates a denser graph). Each group contained 12 instances with a specified number of nodes . All instances can be obtained from the author or online (https://github.com/xavierwoo/Dynamic-MST, accessed on 25 March 2024).
To evaluate the algorithm’s performance in large-scale scenarios, we generated multiple clustered graph instances of massive scale. The generation process followed these steps: (1) Vertices were organized into clusters using a matrix layout. (2) Within each cluster, vertices were randomly placed within a square and connected with random probability, where the edge cost was determined by the distance. (3) Adjacent clusters were interconnected by introducing edges between two randomly selected vertices from each, with the distance representing the edge cost. These generated instances, as well as the generator used, are available from the author.
5.2. Experimental Evaluation of Supergraph Minimum Spanning Tree Maintenance Algorithm
This section presents the experimental results for the proposed algorithm applied to the updating and maintenance of the minimum spanning tree (MST) for the original graph’s supergraph.
5.2.1. Experimental Methodology for Supergraph
To evaluate the performance of the proposed algorithm for maintaining the minimum spanning tree of a supergraph, the following testing procedure was employed:
- Start with a test graph . Randomly remove k edges to obtain a graph , using G as the input for the algorithm.
- Use the ordered set of edges in E as the algorithm input parameter .
- Use the minimum spanning tree of G as the algorithm input parameter T.
- Use the set as the algorithm input parameter .
- Set as an empty set.
At this point, the test graph is a supergraph of graph G. The experiments were conducted for different values of k (). The total running time of the algorithm was recorded and compared with the time taken by Kruskal’s algorithm to find the minimum spanning tree of .
Since the algorithm’s single run time is very short, each test case was independently repeated 1000 times, and the total running time was recorded. To improve the accuracy of the experiments, each set of data was calculated 100 times, and the average running time was reported in seconds.
In all comparative experiments presented in this paper, the timing of the proposed algorithm and Kruskal’s algorithm were conducted independently. The experiments used the same random seed to generate random sets, ensuring that each algorithm calculated on the same graph for every experiment.
5.2.2. Analysis of Experimental Results for Supergraph
The experimental results of the supergraph minimum spanning tree maintenance algorithm are shown in Table 1. The first column of Table 1 represents the group name of the test case, the second column is the name of the test case, and the next six columns compare the time consumption of the maintenance algorithm (MT) and Kruskal’s algorithm (Kru) under different conditions. The last column describes the number of vertices and edges in the current test case. We define a time consumption evaluation index, where ( represents the runtime of Kruskal’s algorithm, and T represents the runtime of the maintenance algorithm). indicates the performance difference between the maintenance algorithm and Kruskal’s algorithm. The larger is, the better the performance of the maintenance algorithm is. Boldfaced in the table indicates that the corresponding algorithm’s runtime is smaller than that of the comparison algorithm. The formats and meanings of the subsequent tables are the same as those of Table 1.
Table 1.
Experimental results of supergraph minimum spanning tree maintenance algorithm.
From Table 1, we can conclude that the proposed algorithm for maintaining the minimum spanning tree in supergraphs is significantly superior to Kruskal’s algorithm for a complete recalculation of the MST in the new graph. When comparing Kruskal’s algorithm for different numbers of added edges in the same test case, we observe a relatively smooth fluctuation in its runtime. The fewer edges the maintenance algorithm adds, the larger the value of is, indicating a greater advantage of the supergraph maintenance algorithm. Additionally, it is evident that for graphs with the same number of vertices and a similar number of graph changes, the value is larger for denser graphs. This suggests that the updating algorithm performs better in calculating the MST of supergraphs, particularly on denser graphs compared with sparse ones.
5.3. Experimental Design for Subgraph
This section tests the updating and maintenance algorithm for the original graph’s subgraph.
5.3.1. Experimental Methodology for Subgraph
We tested the maintenance algorithm for the minimum spanning tree of the subgraph by using the following approach:
- Let the example graph be denoted by , and use graph G as the input to the algorithm. Randomly remove k edges from G to obtain the subgraph .
- Let the ordered set of edges from the edge set of the graph G be the algorithm input parameter .
- Let the minimum spanning tree of graph G be the algorithm input parameter T.
- Set as an empty set for the algorithm input parameter.
- Let be the set .
At this point, the example graph is a subgraph of graph G. The experiment tested the cases where , recorded the total runtime of the entire algorithm, and compared it with the runtime taken by Kruskal’s algorithm to solve the minimum spanning tree for graph .
The experiment protocol is the same as the one used in the supergraph test.
5.3.2. Analysis of Experimental Results for Subgraph
Through Table 2, we can conclude that for the solution of the minimum spanning tree in the subgraph, the proposed subgraph minimum spanning tree maintenance algorithm in this paper is significantly better than Kruskal’s algorithm, which recomputes from the scratch. By comparing the runtime of Kruskal’s algorithm when deleting different numbers of edges in the same test case, it was observed that the runtime fluctuation of Kruskal’s algorithm is relatively small. The fewer edges the maintenance algorithm deletes, the larger the value is, indicating a greater advantage of the subgraph minimum spanning tree maintenance algorithm. It was also observed that for graphs with the same number of vertices and a similar number of graph changes, denser graphs yield larger values. This suggests that the updating algorithm performs better on dense graphs compared with sparse graphs when computing the minimum spanning tree of the subgraph.
Table 2.
Experimental results of subgraph minimum spanning tree maintenance algorithm.
5.4. Experimental Evaluation of Dynamic Graph Minimum Spanning Tree Maintenance Algorithm
This section tests the proposed dynamic graph minimum spanning tree maintenance algorithm in this paper in general scenarios.
5.4.1. Experimental Design for Dynamic Graph Minimum Spanning Tree Maintenance Algorithm
As presented in this section, we tested the dynamic graph minimum spanning tree maintenance algorithm through continuous multiple iterations.
The initial iteration’s algorithm parameters were set as follows:
- Let the example graph be . Randomly delete k edges from it to obtain the graph G, which serves as the input original graph for the algorithm.
- Denote the ordered set of edges from graph G by , and let it be the algorithm input parameter. Denote the minimum spanning tree of graph G by T, and let it be the algorithm input parameter.
- Let be the set and be a randomly selected subset of size k from set E.
For each subsequent iteration, the algorithm parameters were generated based on the results of the previous iteration, as follows:
- Remove all edges in from graph G, and add all edges in to obtain the graph .
- Set , and let be a randomly selected subset of size k from set .
- is the minimum spanning tree of graph , as given by the previous iteration.
- is the ordered set of edges from set , as given by the previous iteration.
These parameters ( and are used as the input for the new iteration.
The experiment protocol is the same as the previous ones.
5.4.2. Analysis of Maintenance Algorithm Results for Dynamic Graph
From Table 3, we can conclude that for solving the minimum spanning tree problem in general dynamic graphs, the proposed dynamic graph minimum spanning tree maintenance algorithm is significantly better than Kruskal’s algorithm, which recomputes from scratch. By comparing different numbers of modified edges (additions and deletions) within the same test case, it was observed that the more edges are modified, the smaller the value of is, indicating that the advantage of the dynamic graph minimum spanning tree maintenance algorithm diminishes. Additionally, it was observed that for the same number of vertices and a similar graph modification number, higher-density graphs yield larger values. This implies that the updating algorithm performs better on dense graphs than on sparse ones.
Table 3.
Experimental results of dynamic graph minimum spanning tree maintenance algorithm.
5.5. Analysis for Massive Cluster Graphs
In this subsection, we evaluate the performance of our proposed algorithm on massive cluster graphs. We compared our algorithm with Kruskal’s (Kru) and Prim’s (Pri) algorithms. Due to the larger size of the instances used in this experiment compared with those in the previous sections, each test was conducted over 50 iterations, with 50 edges being modified in each iteration. The results are presented in Table 4. The columns and represent the performance differences between our maintenance algorithm and Kruskal’s and Prim’s algorithms, respectively. The instances’ names follow the format cluster-nxn-g-p-s, where nxn denotes the matrix layout of the entire graph, g represents the number of vertices in a single cluster, p represents the connection probability, and s denotes the random seed used to generate the instance.
Table 4.
Experimental results on cluster graphs.
Based on the results presented in Table 4, it is evident that the maintenance algorithm outperforms Kruskal’s and Prim’s algorithms on cluster graphs. Specifically, Prim’s algorithm demonstrated better performance compared with Kruskal’s algorithm in this experiment. This observation aligns with the fact that Prim’s algorithm tends to be more efficient than Kruskal’s algorithm when dealing with dense graphs, which was the case for all instances used in this experiment. However, despite this advantage, Prim’s algorithm is still 5 to 8 times slower compared with the proposed maintenance algorithm.
5.6. Analysis of Algorithm Performance with Graph Changes
We conducted experiments on the dynamic graph minimum spanning tree maintenance algorithm iteratively, with the same experimental protocol as the dynamic graph minimum spanning tree maintenance algorithm experiments described above. We wanted to determine the specific point at which computing from scratch becomes more advantageous than maintaining the existing version.
We selected six test cases with different densities and various vertex numbers for experimentation. For each test case, we gradually increased the number of modified edges and recorded the algorithm’s running time. To enhance experimental accuracy, each set of data underwent 100 calculations. We also tested using Kruskal’s algorithm to compute from scratch and compared the results. Note that when edge sets and exceeded half of the total number of edges in the graph, the new graph became entirely different from the original, rendering the algorithm results meaningless.
The results are shown in Figure 6. The x-axis in the figures represents the increasing number of added and deleted edges, while the y-axis represents the algorithm’s running time. Through the comparison of the running time results of the six test cases, it was observed that the maintenance algorithm had a significant advantage when the number of modified edges was small. As the number of modified edges increased, the gap between the two algorithms gradually narrowed. When the number of modified edges approached half of the total edges in the test case, the running times of the two algorithms became close. By comparing the figures, we found that with fewer modified edges, an decrease in the graph density led to a greater advantage for the maintenance algorithm.

Figure 6.
The relationship between algorithm time consumption and graph changes. (a) Range_150_500_1; (b) Range_150_500_3; (c) Range_125_500_3; (d) Range_100_500_3; (e) Range_125_300_1; (f) Range_100_300_1.
6. Conclusions
This paper introduces a dynamic graph minimum spanning tree maintenance algorithm. In the scenario where the original graph and its spanning tree are known, the algorithm quickly solves the minimum spanning tree of a new graph with partial modifications to the original graph. The algorithm also provides an ordered set of the new graph’s edge set to expedite subsequent dynamic minimum spanning tree computations. The paper proves that given the original graph and its spanning tree, the maintenance algorithm yields a correct minimum spanning tree for the new graph. Compared with the traditional Kruskal’s algorithm, the time complexity of the maintenance algorithm is the same as that of Kruskal’s algorithm. This implies that theoretically, the proposed algorithm is on par with the standard Kruskal’s algorithm, which completely recalculates the new graph. In practical execution, the maintenance algorithm efficiently reduces the actual search space, making it more effective for multiple iterations of updates in large-scale graph scenarios. As for future work, we aim to optimize the algorithm’s pruning strategies, for example, maintaining the disjoint-set structure by updating it rather than rebuilding it and using path compression for faster searching. We also hope that the maintenance algorithm proposed in this paper can be extended to more problem domains.
Author Contributions
Conceptualization, X.W.; Investigation, H.Q.; Methodology, M.L.; Project administration, C.X.; Software, H.Q. and X.W.; Writing—original draft, M.L.; Writing—review and editing, D.X. and Y.K. All authors have read and agreed to the published version of the manuscript.
Funding
This research was funded by the National Natural Science Foundation of China (grant Nos. 62201203 and 62002105) and the Science and Technology Research Program of Hubei Province (2021BLB171).
Data Availability Statement
The instances and code used in this paper can be found at https://github.com/xavierwoo/Dynamic-MST (accessed on 25 March 2024).
Conflicts of Interest
The authors declare no conflicts of interest.
References
- Nesetril, J.; Nesetrilová, H. The origins of minimal spanning tree algorithms—Boruvka and Jarník. Doc. Math. 2012, 17, 127–141. [Google Scholar]
- Lv, X.; Ma, Y.; He, X.; Huang, H.; Yang, J. CciMST: A clustering algorithm based on minimum spanning tree and cluster centers. Math. Probl. Eng. 2018, 2018, 1–14. [Google Scholar] [CrossRef]
- Peter, S.J. Discovering local outliers using dynamic minimum spanning tree with self-detection of best number of clusters. Int. J. Comput. Appl. 2010, 9, 36–42. [Google Scholar] [CrossRef]
- La Grassa, R.; Gallo, I.; Landro, N. OCmst: One-class novelty detection using convolutional neural network and minimum spanning trees. Pattern Recognit. Lett. 2022, 155, 114–120. [Google Scholar] [CrossRef]
- Millington, T.; Niranjan, M. Construction of minimum spanning trees from financial returns using rank correlation. Phys. A Stat. Mech. Its Appl. 2021, 566, 125605. [Google Scholar] [CrossRef]
- Danylchuk, H.; Kibalnyk, L.; Serdiuk, O.; Ivanylova, O.; Kovtun, O.; Melnyk, T.; Zaselskiy, V. Modelling of trade relations between EU countries by the method of minimum spanning trees using different measures of similarity. In Proceedings of the CEUR Workshop Proceedings 2020, Copenhagen, Denmark, 30 March 2020; pp. 167–186. [Google Scholar]
- Xingguo, Y.; Chi, X. The Study of Fund Market Complex Complex Network Based on Cosine Similarity and MST Method. Theory Pract. Financ. Econ. 2020, 41, 55–61. [Google Scholar]
- van Dellen, E.; Sommer, I.E.; Bohlken, M.M.; Tewarie, P.; Draaisma, L.; Zalesky, A.; Di Biase, M.; Brown, J.A.; Douw, L.; Otte, W.M.; et al. Minimum spanning tree analysis of the human connectome. Hum. Brain Mapp. 2018, 39, 2455–2471. [Google Scholar] [CrossRef] [PubMed]
- Chen, J.; Wang, H.; Hua, C.; Wang, Q.; Liu, C. Graph analysis of functional brain network topology using minimum spanning tree in driver drowsiness. Cogn. Neurodyn. 2018, 12, 569–581. [Google Scholar] [CrossRef] [PubMed]
- Jonak, K.; Krukow, P.; Karakuła-Juchnowicz, H.; Rahnama-Hezavah, M.; Jonak, K.E.; Stępniewski, A.; Niedziałek, A.; Toborek, M.; Podkowiński, A.; Symms, M.; et al. Aberrant structural network architecture in Leber’s hereditary optic neuropathy. Minimum spanning tree graph analysis application into diffusion 7T MRI. Neuroscience 2021, 455, 128–140. [Google Scholar] [CrossRef] [PubMed]
- Chreang, S.; Kumhom, P. A Method of Selecting Cable Configuration for Microgrid Using Minimum Spanning Tree. In Proceedings of the 2018 15th International Conference on Electrical Engineering/Electronics, Computer, Telecommunications and Information Technology (ECTI-CON), Chiang Rai, Thailand, 18–21 July 2018; pp. 489–492. [Google Scholar]
- Mosbah, M.; Arif, S.; Mohammedi, R.D.; Hellal, A. Optimum dynamic distribution network reconfiguration using minimum spanning tree algorithm. In Proceedings of the 2017 5th International Conference on Electrical Engineering-Boumerdes (ICEE-B), Boumerdes, Algeria, 29–31 October 2017; pp. 1–6. [Google Scholar]
- Kebir, N.; Ahsan, A.; McCulloch, M.; Rogers, D.J. Modified Minimum Spanning Tree for Optimised DC Microgrid Cabling Design. IEEE Trans. Smart Grid 2022, 13, 2523–2532. [Google Scholar] [CrossRef]
- Ramalingam, G.; Reps, T. On the computational complexity of dynamic graph problems. Theor. Comput. Sci. 1996, 158, 233–277. [Google Scholar] [CrossRef]
- Adasme, P.; de Andrade, R.C. Minimum weight clustered dominating tree problem. Eur. J. Oper. Res. 2023, 306, 535–548. [Google Scholar] [CrossRef]
- Xiong, C.; Liu, H.; Wu, X.; Deng, N. A two-level meta-heuristic approach for the minimum dominating tree problem. Front. Comput. Sci. 2022, 17, 171406. [Google Scholar] [CrossRef]
- Frederickson, G.N. Data structures for on-line updating of minimum spanning trees. In Proceedings of the 15th Annual ACM symposium on Theory of Computing, Boston, MA, USA, 25–27 April 1983; pp. 252–257. [Google Scholar]
- Ribeiro, C.C.; Toso, R.F. Experimental analysis of algorithms for updating minimum spanning trees on graphs subject to changes on edge weights. In Proceedings of the Experimental Algorithms: 6th International Workshop, WEA 2007, Rome, Italy, 6–8 June 2007; Springer: Berlin/Heidelberg, Germany, 2007; pp. 393–405. [Google Scholar]
- Henzinger, M.R.; King, V. Maintaining minimum spanning trees in dynamic graphs. In Proceedings of the Automata, Languages and Programming: 24th International Colloquium, ICALP’97, Bologna, Italy, 7–11 July 1997; Springer: Berlin/Heidelberg, Germany, 1997; pp. 594–604. [Google Scholar]
- Holm, J.; De Lichtenberg, K.; Thorup, M. Poly-logarithmic deterministic fully-dynamic algorithms for connectivity, minimum spanning tree, 2-edge, and biconnectivity. J. ACM (JACM) 2001, 48, 723–760. [Google Scholar] [CrossRef]
- Cattaneo, G.; Faruolo, P.; Petrillo, U.F.; Italiano, G.F. Maintaining dynamic minimum spanning trees: An experimental study. Discret. Appl. Math. 2010, 158, 404–425. [Google Scholar] [CrossRef]
- Eppstein, D.; Galil, Z.; Italiano, G.F.; Nissenzweig, A. Sparsification—a technique for speeding up dynamic graph algorithms. J. ACM (JACM) 1997, 44, 669–696. [Google Scholar] [CrossRef]
- Kopelowitz, T.; Porat, E.; Rosenmutter, Y. Improved worst-case deterministic parallel dynamic minimum spanning forest. In Proceedings of the 30th on Symposium on Parallelism in Algorithms and Architectures, Vienna, Austria, 16–18 July 2018; pp. 333–341. [Google Scholar]
- Tarjan, R.E.; Werneck, R.F. Dynamic trees in practice. J. Exp. Algorithmics (JEA) 2010, 14, 4–5. [Google Scholar]
- Wulff-Nilsen, C. Fully-dynamic minimum spanning forest with improved worst-case update time. In Proceedings of the 49th Annual ACM SIGACT Symposium on Theory of Computing, Montreal, QC, Canada, 19–23 June 2017; pp. 1130–1143. [Google Scholar]
- de Andrade Júnior, J.W.; Duarte Seabra, R. Fully retroactive minimum spanning tree problem. Comput. J. 2022, 65, 973–982. [Google Scholar] [CrossRef]
- Tseng, T.; Dhulipala, L.; Shun, J. Parallel batch-dynamic minimum spanning forest and the efficiency of dynamic agglomerative graph clustering. In Proceedings of the 34th ACM Symposium on Parallelism in Algorithms and Architectures, Philadelphia, PA, USA, 11–14 July 2022; pp. 233–245. [Google Scholar]
- Sundar, S.; Singh, A. New heuristic approaches for the dominating tree problem. Appl. Soft Comput. 2013, 13, 4695–4703. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).






