Quant Memo
Core

Expected Distance Between Two Random Points

How to compute the average distance between two points dropped uniformly at random on a line segment or inside a square — a standard building block for geometric-probability interview questions.

Prerequisites: Expected Value, The Uniform Distribution

Drop two points independently and uniformly at random on the segment [0,1][0,1]. What's the expected distance between them? This is a short, clean warm-up for the broader class of "average distance" geometric-probability questions, and it's worth memorizing both the answer and the method, because the same method extends cleanly to two dimensions.

Setting up the expectation

Let XX and YY be independent, each uniform on [0,1][0,1]. You want E[XY]E[|X-Y|]. By symmetry, P(X>Y)=P(Y>X)=12P(X>Y) = P(Y>X) = \tfrac12 (they're equal in distribution, and ties have probability zero), so

E[XY]=2E[(XY)1{X>Y}].E[|X-Y|] = 2\,E[(X-Y)\mathbf{1}\{X>Y\}] .

In plain English: the expected absolute gap is twice the expected value of "how much bigger XX is than YY," restricted to the cases where XX actually is bigger — using the symmetry to avoid handling both orderings separately.

Worked example: computing the integral by hand

E[(XY)1{X>Y}]=010x(xy)dydxE[(X-Y)\mathbf1\{X>Y\}] = \displaystyle\int_0^1\int_0^x (x-y)\,dy\,dx. The inner integral over yy from 00 to xx: 0x(xy)dy=[xyy22]0x=x2x22=x22\displaystyle\int_0^x (x-y)\,dy = \left[xy - \tfrac{y^2}{2}\right]_0^x = x^2 - \tfrac{x^2}{2} = \tfrac{x^2}{2}. Then 01x22dx=[x36]01=16\displaystyle\int_0^1 \tfrac{x^2}{2}\,dx = \left[\tfrac{x^3}{6}\right]_0^1 = \tfrac16. Doubling gives E[XY]=2×16=13E[|X-Y|] = 2 \times \tfrac16 = \tfrac13. The expected distance between two uniform random points on [0,1][0,1] is exactly 13\tfrac13 — smaller than the naive guess of 12\tfrac12 (the average of the maximum possible distance), because points close together are far more common than points near opposite ends.

Worked example: an interview shortcut using order statistics

There's a faster route that avoids the double integral. With n=2n=2 uniform points, the smaller one (the minimum) has expectation E[min]=1n+1=13E[\min] = \tfrac{1}{n+1} = \tfrac13 and the larger (the maximum) has E[max]=nn+1=23E[\max] = \tfrac{n}{n+1} = \tfrac23 — a standard fact about order statistics of uniforms. Since the distance is just maxmin\max - \min, linearity of expectation gives E[distance]=E[max]E[min]=2313=13E[\text{distance}] = E[\max] - E[\min] = \tfrac23 - \tfrac13 = \tfrac13, matching the integral, but in two lines instead of a double integral.

Extending to a unit square

The two-dimensional version — expected distance between two uniform random points inside a unit square — is a well-known but genuinely harder integral, and its closed-form answer is

E[distance]=2+2+5arcsinh(1)150.5214.E[\text{distance}] = \frac{2+\sqrt2+5\,\text{arcsinh}(1)}{15} \approx 0.5214 .

You are not expected to derive this from scratch at a whiteboard — the value worth remembering is that it's a little over half the square's side length, which is a useful sanity-check number, and the method (symmetry to fix an ordering, or order statistics, or a direct double integral) is what interviewers are actually testing on the 1-D version.

Convergence explorer
true meansamples →
after n = 200estimate -0.025error 0.025std error 0.071

Picture running the 1-D experiment many times: each trial drops two random points on [0,1][0,1] and records their distance; the running average of those distances settles toward 130.333\tfrac13\approx0.333 as the number of trials grows, exactly like the running-average behavior this explorer shows for any converging estimator.

What this means in practice

This kind of "average gap between random draws" calculation is the geometric cousin of estimating average time-between-arrivals or average slippage between two randomly timed fills, and the order-statistics shortcut (E[max]E[min]E[\max]-E[\min]) is worth having on hand any time a question can be reduced to the spread between the smallest and largest of a few random draws.

For two independent uniform points on [0,1][0,1], the expected absolute distance between them is 13\tfrac13, derivable either by a direct integral using symmetry, or in two lines via order statistics: E[max]E[min]=2313E[\max]-E[\min] = \tfrac23-\tfrac13.

Related concepts

Practice in interviews

Further reading

  • Wasserman, All of Statistics, ch. 3
ShareTwitterLinkedIn