Probability

The moment everything joins up

Add edges to a set of points one chance at a time and the graph goes from dust to a single piece — not gradually, but over a window that narrows as the point count grows. The last obstacle is almost always a single point with no edge at all, and that is what fixes where the change happens.
16 min read 6 figures Order out of noiseSmall cases lie

Worth reading first: How long until every one turns up · Sixteen trees on four points.

Take nn points and decide each of the (n2)\binom{n}{2} possible edges independently, each present with probability pp. At p=0p = 0 the result is dust; at p=1p = 1 it is the complete graph. Somewhere in between it stops being in pieces and becomes one thing.

The interesting claim is that “somewhere in between” is much sharper than it sounds. As nn grows, the range of pp over which the graph is sometimes connected and sometimes not shrinks relative to the value of pp itself, so the change looks less like a gradual filling-in and more like a switch.

The chance of being connected, against the chance of an edge. Curves of the exact probability that a random graph on three to six labelled points is connected, plotted against the probability of each individual edge.
Fig. 1 The exact chance of being connected, plotted against the chance of a single edge, for three to six points. Every one of the up to 32,768 graphs on those points was enumerated, so these are polynomials evaluated rather than frequencies measured. The curves move left and steepen — the even-chance point falls from 0.50 to 0.36 while lnn/n\ln n / n falls from 0.37 to 0.30.

Everything in this essay is computed exactly. Nothing is sampled, nothing is estimated, and the drawn graphs later on are illustrations with their seed printed rather than evidence of anything.

Counting the connected graphs

For up to six points every graph can be examined, which is 32,768 of them at n=6n = 6. Sorting them by edge count and keeping the connected ones gives a polynomial:

Pn(p)=mcn,mpm(1p)(n2)m,P_n(p) = \sum_m c_{n,m}\, p^m (1-p)^{\binom{n}{2} - m},

where cn,mc_{n,m} counts connected graphs on nn labelled points with mm edges. Evaluating that polynomial at any pp gives the exact probability.

The enumeration is easy to get wrong in a way that produces a plausible curve, so it is checked against a second computation that shares no code. Split every graph on nn points by the component containing point 1: if that component has kk points, there are (n1k1)\binom{n-1}{k-1} ways to choose the rest of it, ckc_k connected graphs on it, and 2(nk2)2^{\binom{n-k}{2}} arbitrary graphs on what is left. Summing over kk from 1 to n1n-1 and subtracting from 2(n2)2^{\binom{n}{2}} gives cnc_n, the total count of connected graphs.

The recurrence and the enumeration agree at every nn up to six: 1, 1, 4, 38, 728, 26704. A bug in one would have to be matched by the same bug in the other, which is the standing reason this site computes things twice.

The curve is also checked for the one qualitative property it must have: it rises. Adding an edge to a connected graph leaves it connected, so the probability cannot fall as pp grows, and that is asserted at two hundred points along each curve.

What actually goes wrong

A graph can fail to be connected in many ways — two large halves with nothing between them, a piece of three hanging off, a single point left out. The question is which of these is the obstacle in practice.

Connected, against merely having no point left out — 6 points. Two exact probability curves for a random graph on a few labelled points: the chance it is connected and the chance no point is isolated, with the gap between them shaded.
Fig. 2 Two exact curves for six points: the chance of being connected, and the chance of merely having no point left out. They agree at both ends and differ by at most 0.082, at p=0.28p = 0.28. The shaded gap is every disconnection that is not a lone point — every split into two pieces of two or more, every hanging triangle — and it is small.

Being connected implies having no isolated point, so one curve is under the other everywhere; that much is forced. The content is that the gap is narrow, and that it narrows further as nn grows.

The reason is a comparison of counts. For a graph to fail because a single point is isolated costs (1p)n1(1-p)^{n-1} per point, and there are nn points. For it to fail by splitting into a piece of size kk and a piece of size nkn-k with k2k \ge 2 costs (1p)k(nk)(1-p)^{k(n-k)}, and k(nk)k(n-k) is at least 2(n2)2(n-2), which is nearly twice as large an exponent. At the relevant pp the second is negligible against the first.

So the question “when does the graph become connected?” reduces to “when does the last isolated point disappear?” — and that is a question with a clean answer.

Where the threshold is

The expected number of isolated points is n(1p)n1n(1-p)^{n-1}, which is a product of one factor growing and one shrinking. Setting it to 1 and taking logarithms gives plnn/np \approx \ln n / n.

That is the threshold, and its form deserves a moment. The number of edges at that pp is about (n2)lnn/n12nlnn\binom{n}{2} \cdot \ln n / n \approx \tfrac{1}{2} n \ln n — so a random graph needs about 12nlnn\tfrac{1}{2}n\ln n edges to be connected, against the n1n - 1 a tree needs. The factor of lnn\ln n is the price of not being allowed to choose where the edges go.

The lnn\ln n is the same lnn\ln n that appears in how long until every one turns up, and for the same reason: both are asking how long until the last of nn independent-ish waits finishes, and the last of nn waits is a factor of lnn\ln n longer than the typical one. A collector needs nlnnn \ln n draws to see every coupon; a random graph needs 12nlnn\tfrac12 n \ln n edges to give every point at least one. The threshold is a coupon-collector problem wearing a graph.

Erdős and Rényi proved the sharp form in 1959: writing p=(lnn+c)/np = (\ln n + c)/n, the probability of connectedness tends to eece^{-e^{-c}}. So the transition happens over a window of width about 1/n1/n around lnn/n\ln n / n, which is a vanishing fraction of the threshold itself. That is what makes it a threshold rather than a trend.

Connected, against merely having no point left out — 5 points. Two exact probability curves for a random graph on a few labelled points: the chance it is connected and the chance no point is isolated, with the gap between them shaded.
Fig. 3 The same comparison at five points. The gap between connectedness and having no point left out is 0.077, at p=0.31p = 0.31 — barely different from the six-point figure, because at these sizes the asymptotic behaviour has not started. The claim that the gap vanishes is about large nn and cannot be seen here.

What the small cases can and cannot say

The exact curves stop at six points, which is where enumeration stops. Six points is not large, and the honest position is that these figures illustrate a phenomenon whose statement is asymptotic.

What they do establish is real. The curves genuinely steepen; the even-chance crossing genuinely tracks lnn/n\ln n / n from 0.50 down to 0.36 as lnn/n\ln n/n goes from 0.37 to 0.30; the gap between connectedness and no-isolated-point is genuinely small at every pp and every nn computed. Those are facts about the drawn cases.

What they cannot establish is the limit. Four data points of a sequence do not determine its behaviour, and a reader who concluded from the figure that the threshold is exactly where the curve crosses a half would be extrapolating from sizes at which the correction terms are as large as the leading one.

12 points at 3 values of p. Three random graphs on the same points drawn at increasing edge probability, each point coloured by the piece it belongs to and the pieces counted.
Fig. 4 Twelve points at three values of the edge chance, seed 11. Seven pieces, then three, then one. This is a picture of three particular draws and settles nothing — the transition it seems to show is what the exact curves establish, not what these three graphs do.

That distinction is worth being pedantic about. Three drawn graphs looking like dust, fragments and a single piece is an illustration of a claim proved elsewhere; run with a different seed they might have looked otherwise, and nothing in the drawing says how much otherwise.

The other threshold, which is different

Connectivity is not the first thing that happens as pp rises, and the earlier event is more famous.

At pp around 1/n1/n — much smaller than lnn/n\ln n / n — the graph acquires a giant component: a single piece containing a constant fraction of all the points, where before there were only pieces of size O(logn)O(\log n). The change is abrupt in the same technical sense, and it is the event usually meant by “the phase transition in random graphs”.

Between 1/n1/n and lnn/n\ln n / n the graph is in an intermediate state that is easy to picture and easy to get wrong: one enormous piece, plus a scattering of isolated points and tiny fragments. It looks connected if the small pieces are overlooked. The second threshold is the moment those last stragglers are absorbed.

So there are two distinct events with different answers, and both are called phase transitions:

  • p1/np \approx 1/n: a giant piece appears. About n/2n/2 edges.
  • plnn/np \approx \ln n / n: the last isolated point vanishes and the graph becomes connected. About 12nlnn\tfrac12 n \ln n edges.

The ratio between them is lnn\ln n, which is small for any nn anybody draws and unbounded in the limit — a good example of an asymptotic separation that no picture can show.

Every property of this kind has a threshold

Connectivity is not special. A graph property is monotone if adding edges never destroys it — being connected, containing a triangle, having a Hamiltonian cycle, having chromatic number at least 5. Bollobás and Thomason proved in 1987 that every monotone property has a threshold: a function p(n)p^*(n) such that the property holds with probability tending to 0 below it and to 1 above it, whenever the ratio to pp^* tends to 0 or infinity.

That is a strong statement and it says nothing about where. Locating the threshold for a particular property is the work, and the answers are a catalogue rather than a formula:

  • a triangle appears at p1/np \approx 1/n;
  • a giant component at 1/n1/n;
  • every point has an edge, and the graph becomes connected, at lnn/n\ln n/n;
  • a Hamiltonian cycle at lnn/n\ln n/n as well — the same threshold as connectivity, which is a genuinely surprising coincidence and not one anybody guessed;
  • a complete graph on four points at n2/3n^{-2/3}.

The pattern in most of them is the one this essay’s threshold follows: find the expected number of the smallest obstruction, set it to 1, and solve. For a triangle the expected count is (n3)p3\binom{n}{3}p^3, which passes 1 at p1/np \approx 1/n; for an isolated point it is n(1p)n1n(1-p)^{n-1}. The method is called the first moment method and it gives an upper bound honestly and a lower bound only with more work, because an expectation of 1 is consistent with the count being 0 nearly always and enormous occasionally.

16 points at 3 values of p. Three random graphs on the same points drawn at increasing edge probability, each point coloured by the piece it belongs to and the pieces counted.
Fig. 5 Sixteen points at three edge chances, seed 11: eleven pieces, then three, then one. Compared with the twelve-point picture the fragmentation at the low end is worse and the coalescence at the high end is more complete, which is the direction the thresholds predict — and three draws at two sizes is not a measurement of anything.

The other use of the same object

Random graphs began as a proof technique rather than as a subject, and the technique is worth stating because it explains why anybody was counting connected graphs in the first place.

To show that a graph with some property exists, put a probability distribution on graphs and show the property has positive probability. No graph is ever exhibited; the argument is entirely about counting, and the conclusion is existence.

The founding example is a lower bound for Ramsey numbers. Six people at a party shows that six points force a monochromatic triangle. How many points force a monochromatic complete graph on kk points? Erdős’s 1947 argument: colour the edges of the complete graph on nn points at random, and count the expected number of monochromatic complete subgraphs on kk points. It is (nk)21(k2)\binom{n}{k}2^{1-\binom{k}{2}}, and if that is less than 1 then some colouring has none — so nn points do not force one. The bound this gives is exponential in kk, it is essentially the best known eighty years later, and no explicit colouring achieving anything like it has ever been constructed.

That is the pattern the probabilistic method is famous for: it proves objects exist while remaining silent about what they look like. Nobody gets their own hat is a counting argument of the ordinary kind by contrast — it produces a number, and the number is about every permutation rather than about a lucky one.

Where the model came from, and what it is not

Erdős and Rényi introduced the model in 1959, and Gilbert independently in the same year with the pp-per-edge version used here; Erdős and Rényi’s own version fixes the number of edges rather than the probability, and the two agree for most purposes.

The motivation was not to model anything. Erdős had been using random constructions for a decade to prove that graphs with stated properties exist — the probabilistic method, which proves existence by showing the probability is positive and never exhibits the object. The random graph became a subject in its own right when it turned out that its properties appear in a strict order as pp rises, each at its own threshold, with the order itself being the theorem.

What this model is not is a model of any real network. Real networks have degree distributions nothing like the binomial one, and the fact was noticed loudly enough in the 1990s to launch a separate field. The value of the Erdős–Rényi graph is as a null object — the thing a network is compared against — and as the setting in which thresholds were first understood.

The chance of being connected, against the chance of an edge. Curves of the exact probability that a random graph on three to six labelled points is connected, plotted against the probability of each individual edge.
Fig. 6 Four points against six, with everything else stripped away. The four-point curve reaches an even chance at p=0.46p = 0.46 and the six-point curve at 0.36; the six-point curve is steeper through its crossing. Two sizes is enough to see the direction and nowhere near enough to see the rate.

What the pictures cannot show

The enumeration stops at six points because 2152^{15} graphs can be examined and 2212^{21} takes long enough to be a nuisance. Every exact statement here is therefore about n6n \le 6, and every asymptotic statement is quoted rather than computed.

The threshold lnn/n\ln n / n is marked on the isolated-point figure as a vertical line, and at n=6n = 6 that line is at 0.299 while the connectivity curve crosses a half at 0.36. The two do not coincide and there is no reason they should: the threshold is where the expected number of isolated points passes 1, and expectation passing 1 is not the same as probability passing a half except in the limit.

And the drawn graphs use a circular layout, which makes every component look like a chord diagram rather than like a cluster. A drawing that placed connected points near each other would look far more like the intuitive picture of a graph coming together and would be a picture of the layout algorithm as much as of the graph.

The ladder from here

Below: how long until every one turns up, where the same lnn\ln n appears for the same reason, and sixteen trees on four points, which counts labelled graphs of a particular shape. Sideways: the edge that forces a triangle, where the number of edges decides what a graph must contain rather than what it probably does; a bell curve assembled out of coin flips, the concentration that makes thresholds sharp; and how far from the average a thing can be, which is the tool that turns an expectation into a statement about what usually happens. Above: the giant component and its exact size, the second moment method, thresholds for containing a fixed subgraph, and the general theorem that every monotone graph property has one.

What is worth carrying away

A property that a graph either has or does not appears, as the density rises, not gradually but at a place — and finding the place is usually a matter of finding the last obstacle rather than reasoning about the property directly.

For connectivity the last obstacle is a single point with no edges, which is a much simpler object than a disconnection. Once that is noticed, the threshold is an expectation calculation of two lines, and the hard work is only in showing that nothing else matters. The pattern generalises: a threshold is usually located by identifying the cheapest way for the property to fail, and confirmed by showing every other way is cheaper still to avoid.