Could be worse - Random topics in statistical physics, spin glasses, optimization and average case hardness
23 November 2026 | E. Malatesta
Consider the complete graph and assign an independent random variable weight to every edge .
Let be the total length of its minimum spanning tree (MST)
From a statistical-physics point of view, is the ground-state energy of the spanning-tree problem. A beautiful result proved by Frieze [Frieze (1985)] states that, if the lengths are uniform on , then
In this post I want to derive the result by translating Kruskal's algorithm into the language of the Erdős–Rényi random-graph process [Erdős and Rényi (1960)]. The logic is the following. Kruskal's algorithm first turns the optimal cost into an integral over the number of connected components of a threshold graph. At edge-length scale , this threshold graph is the sparse Erdős–Rényi graph . Its connected-component density can be written compactly in terms of the fraction of vertices outside the giant component. Finally, expanding the same density by the size of its finite trees produces one term for each tree size .
Kruskal's algorithm [Kruskal (1956)] constructs an MST by sorting all the edges in increasing order of weight and then inspecting them one at a time. An edge is accepted if and only if its endpoints currently belong to two different connected components. If they are already connected, the edge is rejected because it would create a cycle. The algorithm stops after edges have been accepted.
The evolving set of accepted edges is therefore always a forest. Every accepted edge merges two of its connected components, and after successful mergers only one component remains.
The standard implementation sorts the edges in time and maintains the components with a disjoint-set, or union–find, data structure. The union–find operations take time, where is the inverse Ackermann function, so sorting dominates. For the complete graph, , and the total running time is
We show below a visual implementation of Kruskal's algorithm, for and vertices drawn uniformly on the unit square. The weight of each edge is given by the Euclidean distance between the endpoints of the edge. This problem is usually called the Euclidean MST problem.

For , let be the graph with vertices containing all edges with length at most , and denote its number of connected components by . Note that since every edge belongs to independently with probability , is exactly an Erdős–Rényi random graph.
Let denote the lengths of the edges in the minimum spanning tree of the complete graph , for a given realization of the random variables . Using the identity where is the Heaviside function, we can write
where is the number of weights in the minimum spanning tree larger than the threshold .
The quantity in the integrand has a direct interpretation in terms of Kruskal's algorithm. When we reach level , Kruskal's algorithm has built a spanning tree inside every component of . If those components have sizes , the number of edges already accepted is
Since the MST contains edges, the number of selected edges still missing at level , i.e. , is
so that the energy for a realization of the weights
Making the change of variables , taking the expectation, and sending we therefore get
where we have defined
We would like now to determine the expected number of connected components of an Erdős–Rényi random graph with edge probability scaling as . To do that, it is useful to recall some properties of the Erdős–Rényi random graph ensemble .
Note that the scaling makes the probability of a vertex to have degree equal to Poissonian distributed in the large limit. Indeed
Note that therefore represents the mean degree when is large: .
What does an Erdős–Rényi graph look like locally? In order to answer this question, we take a vertex at random, and we ask what is the probability that is belongs to a cycle of length s? To answer, let's start from ; I have possibilities to connect with another node and this happens with probability . Then from I can choose another vertex in ways with probability . I iterate this procedure until I get to node after which I have to come back to vertex . We therefore have
where the factor is added to avoid double counting (since the loop can be travelled starting from in two possible directions). This probability goes to zero in the limit of large . This means that if one takes a random node and looks to a finite neighborhood with high probability we will not see any loop. This property is called tree-like property of the Erdős–Rényi random graph. From this also follows that the expected number of loops of length
is of order 1 and does not scale with . The factor has a simple origin. Multiplying by sums over the possible choices of a marked vertex . In this way, however, every cycle of length is counted times, once for each of its vertices. We must therefore divide by . For , equation (12) shows that decreases exponentially with , so cycles are rare and a vertex chosen uniformly at random does not belong to any loop.
A similar argument also determines the typical component size. Starting from vertex , on average it has neighbors; each of them has, on average, neighbours. For one therefore gets
so a typical vertex belongs to a finite component of size , which is a tree with high probability. For , the exploration may instead continue growing as . When instead, the size of the connected component scales as ; when this quantity becomes of order loops can appear. The typical length of a loop when is therefore
The exploration argument above suggests a qualitative change at . For , the number of newly discovered vertices decreases on average and the exploration eventually stops, producing a finite component. For , it grows on average and has a positive probability of reaching an extensive number of nodes of the graph. In the large- limit, this produces a unique component containing order- vertices, known as the giant component. We now determine the fraction of vertices belonging to it.
Let us denote by the fraction of vertices not belonging to the giant component. For a vertex not to belong to the giant component, it must not be connected to any other vertex that belongs to the giant component. For every vertex , one of the following must occur:
vertex does not belong to the neighborhood of node , i.e. . This event happens with probability ;
, but is not in the giant component; this event has probability .
The total probability that does not belong to the giant component is therefore . For to be disconnected from the giant component this must be true for all the possible choices of , so that[1]
The emergence of the giant component is illustrated in Figure 2, where the fraction of vertices belonging to it is plotted as a function of the mean degree .

In the previous section we have found how the giant component emerges. However, this does not count in the number of connected components when is large (recall equation (9)). We therefore need to examine how typically an Erdős–Rényi random graph looks like for vertices not belonging to the giant component.
Choose uniformly at random a vertex not belonging to the giant component . We would like to compute what is the probability that it has degree . For to remain outside the giant component, given it has degree , it must be that none of its neighbouring branches reaches the giant component. Each branch is not in the giant component with probability , and therefore
Using Bayes' rule, we obtain
The self-consistency equation (15) implies
Hence when we condition on a random vertex not belonging to the giant component the probability it has degree equal to
is still Poissonian but with a mean degree . Crucially, this effective mean is smaller than one. Taking the logarithm of the equation (15) gives
For ,
from which it follows that .
Thus, although the original graph is in the supercritical phase , the graph outside the giant component (composed by vertices) behaves asymptotically as an Erdős–Rényi random graph in the subcritical phase:
This property is known as the duality principle.
We can summarize the evolution of as increases as follows:
for , a vertex chosen at random is located in a tree with high probability; it is possible to show that the largest components have size ;
at , it is possible to show that the largest components have size ;
for , a unique giant component of size appears, while the graph outside the giant is effectively subcritical, with mean degree . Therefore a uniformly chosen vertex, conditioned on lying outside the giant component, belongs to a tree component with high probability;
when is of order the graph becomes connected.
From the analysis of the previous section we found that the number of connected components of an Erdős–Rényi random graph is dominated by trees. Now we will compute explicitly the number of tree components. Let be the number of tree components containing exactly vertices in . We can count the expected value of by the following reasoning.
Choose vertices out of the available; there are possibilities;
From those vertices Cayley's formula tells us that we can construct spanning trees;
Then we have to require that the edges of out vertex tree are present. This happens with probability ;
Next we have to assure that no other edges are present between our vertices: this event has probability ;
Finally we have to impose that there are no edges between these vertices and the remaining : this gives an additional factor
Therefore, putting all the mentioned factors together, we have
For fixed and large , we obtain
Summing over and dividing by we finally get
Substituting equation (25) into equation (8) gives
where Tonelli’s theorem allows us to exchange the sum and the integral because all terms are nonnegative. With ,
Therefore we find
| [1] | Another way of deriving this result is to use the Poissonian degree distribution of the vertices derived in equation (10). Since each of the neighbours of vertex independently fails to belong to the giant component with probability , the probability that none of them belongs to it is . We have which is (15). |
[1] A. M. Frieze, "On the Value of a Random Minimum Spanning Tree Problem", Discrete Applied Mathematics 10, 47–56 (1985). doi:10.1016/0166-218X(85)90058-7.
[2] P. Erdős and A. Rényi, "On the Evolution of Random Graphs", Publication of the Mathematical Institute of the Hungarian Academy of Sciences 5, 17–61 (1960).
[3] J. B. Kruskal, "On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem", Proceedings of the American Mathematical Society 7, 48–50 (1956).