Drop points independently and uniformly on a circle of circumference . They cut the circle into arcs, the gaps, whose average length is exactly . The longest gap is much longer than that. Its expected length is
so with a thousand points the longest gap is, on average, times the average gap, while the shortest gap has expectation exactly , a thousand times shorter than average. The derivation is one change of variables. The exact distribution of the longest gap is a finite alternating sum that Fisher wrote down in 1929 for a problem in time-series analysis. One application is consistent hashing: servers hashed to a ring each own the arc up to their next neighbor, so the busiest server carries about times its fair share of the keys.
The gaps are exchangeable
Rotate the circle so that the first point sits at . The other points are then i.i.d. uniform on , and sorted into they have joint density on the region . The gaps are
and the map from to is linear with determinant . So the gap vector is uniformly distributed on the simplex , the Dirichlet distribution with all parameters equal to . Uniformity on the simplex is symmetric in the coordinates, so the gaps are exchangeable: every permutation of has the same joint law. They are not independent, since they sum to , but any statement about one gap is a statement about every gap. Each has the marginal
the probability that the other points all avoid an arc of length , with mean . This is the same symmetry that produces the German tank estimator: there, observed serial numbers cut a range into exchangeable gaps, and the unobserved gap above the maximum is estimated by the average of the visible ones.
The gap that contains a fixed location on the circle, say the point diametrically opposite the origin, is not a typical gap: long gaps are more likely to contain any given location, in proportion to their length. Its mean is , about twice the average gap. This is the inspection paradox, and it is the reason that, when buses arrive at random times, the interval you land in is longer than the average interval between buses.
Gaps are normalized exponentials
The uniform distribution on the simplex has a second description that makes order statistics easy. Let be i.i.d. exponential random variables with mean and let . The joint density of the is , a function of the sum alone, so conditional on the vector is uniform on the simplex of total ; equivalently, is uniform on the unit simplex and independent of . The gaps have the same law as .
Order statistics of exponentials follow from memorylessness. The minimum of exponentials with mean is exponential with mean ; given the minimum, the excesses of the other variables over it are again i.i.d. exponential with mean , so the second smallest exceeds the smallest by an exponential with mean , and so on up the order. This is Rényi’s representation (1953):
Since is independent of , taking expectations gives , and therefore
In units of the average gap : the smallest gap is of an average gap, the median gap () is average gaps, and the largest is average gaps. The largest gap grows like average gaps and the smallest shrinks like of one. The expected largest gap, in units of the average gap:
| 10 | 100 | 1,000 | ||
|---|---|---|---|---|
| 2.93 | 5.19 | 7.49 | 14.39 |
The exact distribution of the largest gap
All gaps are at most exactly when none exceeds , and inclusion–exclusion over the events needs only one fact: for any specified gaps,
Subtracting from each of the gaps leaves a vector uniform on a simplex of total , and the volume of that simplex relative to the full one is (the simplex has dimension ). Hence
For only the terms survive, and is the probability that all points fit in some semicircle, a classical problem. At the other end, is the single term (every gap exceeds ), so the probability that some two of the points lie within distance of each other is , the continuous form of the birthday problem; in units of the smallest gap is asymptotically exponential.
For the largest gap, put . Then and , so term by term the sum tends to :
the Gumbel distribution, whose mean is Euler’s constant , in agreement with . The largest gap is average gaps plus a Gumbel-distributed number of average gaps: its mean grows with , but its fluctuations stay of the same order as a single average gap. The widget draws a sample on the left and, on the right, the exact density of from the alternating sum, with the Gumbel limit and an adjustable threshold:
Consistent hashing
Karger and coauthors (1997) proposed the following way to spread keys over servers so that adding or removing a server disturbs as little as possible. Hash each server to a point on a ring, hash each key to a point on the same ring, and assign each key to the first server clockwise from it. When a server joins or leaves, only the keys on one arc move. The share of keys a server receives is the length of the arc it owns, which is exactly one of the gaps above. So the busiest server’s share is : on average times the fair share , and the imbalance grows with . With servers the busiest holds times its share on average, and the probability that some server holds more than three times its share is ; with servers the busiest holds times its share.
The remedy in the same paper is to hash each server to points instead of one, the virtual nodes of later systems. A server’s share is then the sum of of the gaps, and by exchangeability that sum has the beta distribution with parameters and : mean as before, and relative standard deviation . A hundred virtual nodes per server bring the typical deviation from the fair share down to about 10%, and the largest of the shares to roughly times the average (a Gaussian approximation to the beta law, with a union bound over the servers), about for a hundred servers with a hundred virtual nodes each. Karger and coauthors prove that points per server suffice to bring the largest share within a constant factor of with high probability, and production systems such as Dynamo assign each server many positions on the ring for this reason.
Related problems
- Fisher’s test for a hidden periodicity. For a time series of Gaussian white noise, the ordinates of the periodogram are i.i.d. exponentials, and normalized by their sum they are exactly uniform spacings. Fisher’s 1929 test rejects white noise when the largest normalized ordinate is too large, and the alternating sum above is the null distribution he derived for it.
- Covering the circle with arcs. Place an arc of length clockwise from each of the points. The arcs cover the circle exactly when no gap exceeds , so the coverage probability is , the formula Stevens (1939) obtained for the covering problem.
- Poisson arrivals. Conditional on a Poisson process having arrivals in a window, the arrival times are i.i.d. uniform in the window, so the longest interval without an arrival is the largest gap, and the exponential representation is the Poisson process itself, before conditioning on the count.
The theory of spacings between order statistics is surveyed in Pyke (1965), the general distribution theory for functions of the gaps goes back to Darling (1953), and Holst (1980) derives the limit laws for the -th longest piece from the exponential representation alone.
References
- Ronald A. Fisher. Tests of significance in harmonic analysis. Proceedings of the Royal Society A, 125(796):54–59, 1929. The exact distribution of the largest normalized periodogram ordinate, which is the largest-gap formula.
- W. L. Stevens. Solution to a geometrical problem in probability. Annals of Eugenics, 9(4):315–320, 1939. Covering the circle by random arcs of equal length.
- Alfréd Rényi. On the theory of order statistics. Acta Mathematica Academiae Scientiarum Hungaricae, 4:191–231, 1953. The representation of exponential order statistics as sums of independent exponentials.
- D. A. Darling. On a class of problems related to the random division of an interval. Annals of Mathematical Statistics, 24(2):239–253, 1953. The characteristic-function method for statistics built from the gaps.
- Ronald Pyke. Spacings. Journal of the Royal Statistical Society, Series B, 27(3):395–436, 1965. The survey of the subject.
- Lars Holst. On the lengths of the pieces of a stick broken at random. Journal of Applied Probability, 17(3):623–634, 1980. Limit laws for the ordered pieces from the exponential representation.
- David Karger, Eric Lehman, Tom Leighton, Rina Panigrahy, Matthew Levine, Daniel Lewin. Consistent hashing and random trees: distributed caching protocols for relieving hot spots on the World Wide Web. Proceedings of the 29th ACM Symposium on Theory of Computing, pages 654–663, 1997. Consistent hashing and the virtual copies.
- Giuseppe DeCandia et al. Dynamo: Amazon’s highly available key-value store. Proceedings of the 21st ACM Symposium on Operating Systems Principles, pages 205–220, 2007. Virtual nodes in a production system.