Enrico M. Malatesta

Could be worse - Random topics in statistical physics, spin glasses, optimization and average case hardness

The random minimum spanning tree problem

23 November 2026 | E. Malatesta

← All blog posts

Consider the complete graph KNK_N and assign an independent random variable weight LeL_e to every edge ee.

Let ENE_N be the total length of its minimum spanning tree (MST)

EN=∑e∈MSTLe. E_N=\sum_{e\in\mathrm{MST}}L_e.

From a statistical-physics point of view, ENE_N is the ground-state energy of the spanning-tree problem. A beautiful result proved by Frieze [Frieze (1985)] states that, if the lengths LeL_e are uniform on [0,1][0,1], then

lim⁡N→∞E[EN]=ζ(3)=∑k=1∞1k3≃1.2020569. \lim_{N\to\infty}\mathbb E[E_N] = \zeta(3) = \sum_{k=1}^{\infty}\frac{1}{k^3} \simeq 1.2020569.

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 t/Nt/N, this threshold graph is the sparse Erdős–Rényi graph G(N,t/N)G(N,t/N). Its connected-component density can be written compactly in terms of the fraction u(t)u(t) of vertices outside the giant component. Finally, expanding the same density by the size of its finite trees produces one term 1/k31/k^3 for each tree size kk.

Contents
  1. Kruskal's algorithm
  2. The integral representation of the optimal cost
  3. The Erdős–Rényi random graph
    1. Locally tree-like property
    2. The equation for the giant component
    3. The graph outside the giant component
    4. Counting the number of trees
  4. The algebra leading to ζ(3)\zeta(3)

Kruskal's algorithm

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 N−1N-1 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 N−1N-1 successful mergers only one component remains.

The standard implementation sorts the MM edges in O(Mlog⁡M)O(M\log M) time and maintains the components with a disjoint-set, or union–find, data structure. The union–find operations take O(Mα(N))O(M\alpha(N)) time, where α\alpha is the inverse Ackermann function, so sorting dominates. For the complete graph, M=(N2)M=\binom N2, and the total running time is

O(Mlog⁡M)=O(N2log⁡N). O(M\log M)=O(N^2\log N).

We show below a visual implementation of Kruskal's algorithm, for N=28N=28 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.

Kruskal's algorithm on a Euclidean complete graph
Figure 1: Kruskal's algorithm on a complete graph with Euclidean edge weights.

The integral representation of the optimal cost

For ℓ≥0\ell\geq0, let G(N,ℓ)=([N],{e:Le≤ℓ})\mathcal{G}(N, \ell) = \bigl([N],\{e:L_e\leq\ell\}\bigr) be the graph with NN vertices containing all edges with length at most ℓ\ell, and denote its number of connected components by CN(ℓ)\mathcal{C}_N(\ell). Note that since every edge belongs to G(N,ℓ)\mathcal{G}(N, \ell) independently with probability P(Le≤ℓ)=ℓ\mathbb P(L_e\leq \ell)=\ell, G(N,ℓ)\mathcal{G}(N, \ell) is exactly an Erdős–Rényi random graph.

Let w1,…,wN−1w_1,\ldots,w_{N-1} denote the lengths of the N−1N-1 edges in the minimum spanning tree of the complete graph KNK_N, for a given realization of the random variables LeL_e. Using the identity x=∫0∞dℓ Θ(x−ℓ)x=\int_0^\infty d\ell\,\Theta(x-\ell) where Θ(∙)\Theta(\bullet) is the Heaviside function, we can write

EN=∑i=1N−1wi=∫0∞dℓ N(ℓ) E_N = \sum_{i=1}^{N-1}w_i = \int_0^\infty d\ell\, \mathcal{N}(\ell)

where N(ℓ)=∑iΘ(wi−ℓ)\mathcal{N}(\ell) = \sum_i \Theta(w_i-\ell) is the number of weights in the minimum spanning tree larger than the threshold ℓ\ell.

The quantity in the integrand has a direct interpretation in terms of Kruskal's algorithm. When we reach level ℓ\ell, Kruskal's algorithm has built a spanning tree inside every component of G(N,ℓ)\mathcal{G}(N, \ell). If those components have sizes n1,…,nCn_1,\ldots,n_{\mathcal{C}}, the number of edges already accepted is

∑a=1C(na−1)=N−CN(ℓ). \sum_{a=1}^{\mathcal{C}}(n_a-1) = N-\mathcal{C}_N(\ell).

Since the MST contains N−1N-1 edges, the number of selected edges still missing at level ℓ\ell, i.e. N(ℓ)\mathcal{N}(\ell), is

N(ℓ)=(N−1)−(N−CN(ℓ))=CN(ℓ)−1. \mathcal{N}(\ell) = (N-1)-\bigl(N-\mathcal{C}_N(\ell)\bigr) = \mathcal{C}_N(\ell)-1.

so that the energy for a realization of the weights

EN=∫0∞dℓ [CN(ℓ)−1]. \boxed{ E_N = \int_0^\infty d\ell\, \bigl[\mathcal{C}_N(\ell)-1\bigr]. }

Making the change of variables ℓ=p/N\ell=p/N, taking the expectation, and sending N→∞N\to \infty we therefore get

lim⁡N→∞E[EN]=∫0∞dp κ(p). \boxed{ \lim_{N\to \infty} \mathbb{E} [E_N] = \int_0^\infty dp\, \kappa(p). }

where we have defined

κ(p)=lim⁡N→∞1NE[CN ⁣(pN)−1] \kappa(p) = \lim_{N\to\infty}\frac{1}{N}\mathbb{E} \left[\mathcal{C}_N\!\left(\frac{p}{N} \right)-1\right]

The Erdős–Rényi random graph

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 ℓ=pN\ell = \frac{p}{N}. To do that, it is useful to recall some properties of the Erdős–Rényi random graph ensemble G(N,p/N)\mathcal{G}(N,p/N).

Note that the scaling ℓ=pN\ell = \frac{p}{N} makes the probability of a vertex ii to have degree degi\mathrm{deg}_i equal to kk Poissonian distributed in the large NN limit. Indeed

P[degi=k]=(N−1k)(pN)k(1−pN)N−1−k →N→∞ e−ppkk!. P[\mathrm{deg}_i=k] = \binom{N-1}{k} \left(\frac{p}{N}\right)^k \left(1-\frac{p}{N}\right)^{N-1-k} \; \xrightarrow{N \to \infty} \; e^{-p}\frac{p^k}{k!}.

Note that therefore pp represents the mean degree when NN is large: p=E[degi]p = \mathbb{E}[\mathrm{deg}_i].

Locally tree-like property

What does an Erdős–Rényi graph look like locally? In order to answer this question, we take a vertex ii at random, and we ask what is the probability that ii is belongs to a cycle ωs\omega_s of length s? To answer, let's start from ii; I have N−1N-1 possibilities to connect with another node i1i_1 and this happens with probability p/Np/N. Then from i1i_1 I can choose another vertex i2i_2 in N−2N-2 ways with probability p/Np/N. I iterate this procedure until I get to node is−1i_{s-1} after which I have to come back to vertex ii. We therefore have

P[i∈ωs]=12(N−1)pN(N−2)pN…(N−s+1)pN⋅pN≃ps2N \begin{aligned} P[i \in \omega_s] &= \frac{1}{2} (N-1) \frac{p}{N} (N-2) \frac{p}{N} \dots (N-s+1) \frac{p}{N} \cdot \frac{p}{N} \simeq \frac{p^s}{2N} \end{aligned}

where the factor 1/21/2 is added to avoid double counting (since the loop can be travelled starting from ii in two possible directions). This probability goes to zero in the limit of large NN. This means that if one takes a random node ii and looks to a finite neighborhood ss 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 ss

E[Ls]≃ps2NNs=ps2s \mathbb{E} [\mathcal{L}_s] \simeq \frac{p^s}{2N} \frac{N}{s} = \frac{p^s}{2s}

is of order 1 and does not scale with NN. The factor N/sN/s has a simple origin. Multiplying by NN sums over the possible choices of a marked vertex ii. In this way, however, every cycle of length ss is counted ss times, once for each of its vertices. We must therefore divide by ss. For p<1p<1, equation (12) shows that E[Ls]\mathbb E[\mathcal L_s] decreases exponentially with ss, 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 ii, on average it has pp neighbors; each of them has, on average, pp neighbours. For p<1p<1 one therefore gets

E[∣C(i)∣]≃∑s=0∞ps=11−p, \mathbb E[|\mathcal C(i)|]\simeq\sum_{s=0}^{\infty} p^s = \frac{1}{1-p},

so a typical vertex belongs to a finite component of size O(1)O(1), which is a tree with high probability. For p>1p>1, the exploration may instead continue growing as prp^r. When p>1p>1 instead, the size of the connected component scales as psp^s; when this quantity becomes of order NN loops can appear. The typical length of a loop when p>1p>1 is therefore

s≃ln⁡Nln⁡p s \simeq \frac{\ln N}{\ln p}

The equation for the giant component

The exploration argument above suggests a qualitative change at p=1p=1. For p<1p<1, the number of newly discovered vertices decreases on average and the exploration eventually stops, producing a finite component. For p>1p>1, it grows on average and has a positive probability of reaching an extensive number of nodes of the graph. In the large-NN limit, this produces a unique component containing order-NN vertices, known as the giant component. We now determine the fraction of vertices belonging to it.

Let us denote by u(p)u(p) the fraction of vertices not belonging to the giant component. For a vertex ii 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 j≠ij\ne i, one of the following must occur:

The total probability that ii does not belong to the giant component is therefore 1−pN+pNu1- \frac{p}{N} + \frac{p}{N} u. For ii to be disconnected from the giant component this must be true for all the N−1N-1 possible choices of jj, so that[1]

u=(1−p(1−u)N)N−1 →N→∞ u=e−p(1−u). u = \left(1 - \frac{p(1-u)}{N}\right)^{N-1} \; \xrightarrow{N\to\infty} \; u = e^{-p(1-u)}.

The emergence of the giant component is illustrated in Figure 2, where the fraction 1−u1-u of vertices belonging to it is plotted as a function of the mean degree pp.

Fraction of vertices in the giant component
Figure 2: Fraction 1−u1-u of vertices belonging to the giant component as a function of the mean degree pp. For p≤1p\leq1, the physical solution is u=1u=1 and no giant component is present. For p>1p>1, a nonzero giant component emerges continuously, with uu determined by u=e−p(1−u)u=e^{-p(1-u)}.

The graph outside the giant component

In the previous section we have found how the giant component emerges. However, this does not count in the number of connected components CN(ℓ)\mathcal{C}_N(\ell) when NN 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 ii not belonging to the giant component i∉gci \notin \mathrm{gc}. We would like to compute what is the probability that it has degree kk. For ii to remain outside the giant component, given it has degree kk, it must be that none of its kk neighbouring branches reaches the giant component. Each branch is not in the giant component with probability uu, and therefore

P[i∉gc∣degi=k]=uk. P[i \notin \mathrm{gc} \mid \mathrm{deg}_i=k]=u^k.

Using Bayes' rule, we obtain

P[degi=k∣i∉gc]=P[i∉gc∣degi=k]P[degi=k]P[gc]=ukue−ppkk!. \begin{aligned} P[\mathrm{deg}_i=k \mid i \notin \mathrm{gc}] &= \frac{ P[i \notin \mathrm{gc} \mid \mathrm{deg}_i=k] P[\mathrm{deg}_i=k] }{ P[\mathrm{gc}] }\\ &= \frac{u^k}{u} e^{-p}\frac{p^k}{k!}. \end{aligned}

The self-consistency equation (15) implies

e−pu=e−pu. \frac{e^{-p}}{u}=e^{-pu}.

Hence when we condition on a random vertex ii not belonging to the giant component the probability it has degree equal to kk

P[degi=k∣i∉gc]=e−pu(pu)kk!. P[\mathrm{deg}_i=k \mid i \notin \mathrm{gc}] = e^{-pu}\frac{(pu)^k}{k!}.

is still Poissonian but with a mean degree pupu. Crucially, this effective mean is smaller than one. Taking the logarithm of the equation (15) gives

p=−log⁡u1−u ⟹ pu=−ulog⁡u1−u. p=\frac{-\log u}{1-u} \implies pu=\frac{-u\log u}{1-u}.

For 0<u<10 < u < 1,

−ulog⁡u=∫u1ux dx<∫u1dx=1−u. -u\log u = \int_u^1\frac{u}{x}\,dx < \int_u^1 dx = 1-u.

from which it follows that pu<1pu <1.

Thus, although the original graph is in the supercritical phase p>1p>1, the graph outside the giant component (composed by uNuN vertices) behaves asymptotically as an Erdős–Rényi random graph in the subcritical q<1q<1 phase:

G(uN,pN)=G(uN,quN),q≡pu<1. \mathcal{G}\left(uN,\frac{p}{N}\right) = \mathcal{G}\left(uN,\frac{q}{uN}\right), \qquad q\equiv pu<1.

This property is known as the duality principle.

We can summarize the evolution of G(N,p/N)\mathcal{G}(N,p/N) as pp increases as follows:

Counting the number of trees

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 TN,kT_{N,k} be the number of tree components containing exactly kk vertices in G(N,pN)\mathcal{G}\left(N,\frac{p}{N}\right). We can count the expected value of TN,kT_{N,k} by the following reasoning.

Therefore, putting all the mentioned factors together, we have

E[TN,k]=(Nk)kk−2(pN)k−1(1−pN)k(N−k)+(k2)−(k−1). \mathbb E[T_{N, k}] = \binom Nk k^{k-2} \left(\frac{p}{N}\right)^{k-1} \left(1-\frac{p}{N}\right)^{ k(N-k)+\binom{k}{2}-(k-1) }.

For fixed kk and large NN, we obtain

E[TN,k]≃Nkk!kk−2(pN)k−1e−kp=Nkk−2k!pk−1e−kp \begin{aligned} \mathbb E[T_{N, k}] &\simeq \frac{N^k}{k!} k^{k-2} \left(\frac{p}{N}\right)^{k-1} e^{-k p} \\ &=N \frac{k^{k-2}}{k!} p^{k-1} e^{-k p} \end{aligned}

Summing over kk and dividing by NN we finally get

κ(p)=∑k≥1kk−2k!pk−1e−kp. \boxed{ \kappa(p) = \sum_{k\ge1} \frac{k^{k-2}}{k!} p^{k-1}e^{-kp}. }

The algebra leading to ζ(3)\zeta(3)

Substituting equation (25) into equation (8) gives

lim⁡N→∞E[EN]=∑k≥1kk−2k!∫0∞dp pk−1e−kp , \lim_{N\to\infty}\mathbb E[E_N] = \sum_{k\geq1} \frac{k^{k-2}}{k!} \int_0^\infty dp\,p^{k-1}e^{-kp}\,,

where Tonelli’s theorem allows us to exchange the sum and the integral because all terms are nonnegative. With x=kpx=k p,

∫0∞dp pk−1e−kp=1kk∫0∞dx xk−1e−x=Γ(k)kk=(k−1)!kk. \begin{split} \int_0^\infty dp\,p^{k-1}e^{-kp} &= \frac{1}{k^k} \int_0^\infty dx\,x^{k-1}e^{-x}\\ &= \frac{\Gamma(k)}{k^k} = \frac{(k-1)!}{k^k}. \end{split}

Therefore we find

lim⁡N→∞E[EN]=∑k=1∞kk−2k!(k−1)!kk=∑k=1∞1k3=ζ(3). \lim_{N\to\infty}\mathbb E[E_N] = \sum_{k=1}^{\infty} \frac{k^{k-2}}{k!} \frac{(k-1)!}{k^k} = \sum_{k=1}^{\infty}\frac{1}{k^3} = \zeta(3).

[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 kk neighbours of vertex ii independently fails to belong to the giant component with probability uu, the probability that none of them belongs to it is uku^k. We have

u=∑k=0∞P[degi=k]uk=e−p∑k=0∞(pu)kk!=e−p(1−u)u = \sum_{k=0}^{\infty} P[\mathrm{deg}_i = k] u^k = e^{-p} \sum_{k=0}^{\infty} \frac{(pu)^k}{k!} = e^{-p(1-u)}

which is (15).

References

[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).

© Enrico M. Malatesta. Last modified: November 23, 2026. Built with Franklin.jl.