In all of the algorithms below, is the number of edges in the graph and is the number of vertices.
Classic algorithms The first algorithm for finding a minimum spanning tree was developed by Czech scientist
Otakar Borůvka in 1926 (see
Borůvka's algorithm). Its purpose was an efficient electrical coverage of
Moravia. The algorithm proceeds in a sequence of stages. In each stage, called
Boruvka step, it identifies a forest consisting of the minimum-weight edge incident to each vertex in the graph , then forms the graph as the input to the next step. Here denotes the graph derived from by contracting edges in (by the
Cut property, these edges belong to the MST). Each Boruvka step takes linear time. Since the number of vertices is reduced by at least half in each step, Boruvka's algorithm takes time. The fastest non-randomized comparison-based algorithm with known complexity, by
Bernard Chazelle, is based on the
soft heap, an approximate priority queue. Its running time is , where is the classical functional
inverse of the Ackermann function. The function grows extremely slowly, so that for all practical purposes it may be considered a constant no greater than 4; thus Chazelle's algorithm takes very close to linear time.
Linear-time algorithms in special cases Dense graphs If the graph is dense (i.e. , then a deterministic algorithm by Fredman and Tarjan finds the MST in time . The algorithm executes a number of phases. Each phase executes
Prim's algorithm many times, each for a limited number of steps. The run-time of each phase is . If the number of vertices before a phase is , the number of vertices remaining after a phase is at most \tfrac{n'}{2^{m/n'}}. Hence, at most phases are needed, which gives a linear run-time for dense graphs.
Integer weights If the edge weights are integers represented in binary, then deterministic algorithms are known that solve the problem in integer operations. Whether the problem can be solved
deterministically for a
general graph in
linear time by a comparison-based algorithm remains an open question.
Planar graphs Deterministic algorithms are known that solve the problem for planar graphs in linear time. By the
Euler characteristic of planar graphs, , so this is in time .
Decision trees Given graph where the nodes and edges are fixed but the weights are unknown, it is possible to construct a binary
decision tree (DT) for calculating the MST for any permutation of weights. Each internal node of the DT contains a comparison between two edges, e.g. "Is the weight of the edge between and larger than the weight of the edge between and ?". The two children of the node correspond to the two possible answers "yes" or "no". In each leaf of the DT, there is a list of edges from that correspond to an MST. The runtime complexity of a DT is the largest number of queries required to find the MST, which is just the depth of the DT. A DT for a graph is called
optimal if it has the smallest depth of all correct DTs for . For every integer , it is possible to find optimal decision trees for all graphs on vertices by
brute-force search. This search proceeds in two steps.
A. Generating all potential DTs • There are 2^{r \choose 2} different graphs on vertices. • For each graph, an MST can always be found using comparisons, e.g. by
Prim's algorithm. • Hence, the depth of an optimal DT is less than . • Hence, the number of internal nodes in an optimal DT is less than 2^{r^2}. • Every internal node compares two edges. The number of edges is at most so the different number of comparisons is at most . • Hence, the number of potential DTs is less than {(r^4)}^{(2^{r^2})} = r^{2^{(r^2+2)}}.
B. Identifying the correct DTs To check if a DT is correct, it should be checked on all possible permutations of the edge weights. • The number of such permutations is at most . • For each permutation, solve the MST problem on the given graph using any existing algorithm, and compare the result to the answer given by the DT. • The running time of any MST algorithm is at most , so the total time required to check all permutations is at most . Hence, the total time required for finding an optimal DT for
all graphs with vertices is: The following is a simplified description of the algorithm. • Let , where is the number of vertices. Find all optimal decision trees on vertices. This can be done in time (see
Decision trees above). • Partition the graph to components with at most vertices in each component. This partition uses a
soft heap, which "corrupts" a small number of the edges of the graph. • Use the optimal decision trees to find an MST for the uncorrupted subgraph within each component. • Contract each connected component spanned by the MSTs to a single vertex, and apply any algorithm which works on
dense graphs in time to the contraction of the uncorrupted subgraph • Add back the corrupted edges to the resulting forest to form a subgraph guaranteed to contain the minimum spanning tree, and smaller by a constant factor than the starting graph. Apply the optimal algorithm recursively to this graph. The runtime of all steps in the algorithm is ,
except for the step of using the decision trees. The runtime of this step is unknown, but it has been proved that it is optimal - no algorithm can do better than the optimal decision tree. Thus, this algorithm has the peculiar property that it is
optimal although its runtime complexity is
unknown.
Parallel and distributed algorithms Research has also considered
parallel algorithms for the minimum spanning tree problem. With a linear number of processors it is possible to solve the problem in time. The problem can also be approached in a
distributed manner. If each node is considered a computer and no node knows anything except its own connected links, one can still calculate the
distributed minimum spanning tree. ==MST on complete graphs with random weights==