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 . 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 and be independent, each uniform on . You want . By symmetry, (they're equal in distribution, and ties have probability zero), so
In plain English: the expected absolute gap is twice the expected value of "how much bigger is than ," restricted to the cases where actually is bigger — using the symmetry to avoid handling both orderings separately.
Worked example: computing the integral by hand
. The inner integral over from to : . Then . Doubling gives . The expected distance between two uniform random points on is exactly — smaller than the naive guess of (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 uniform points, the smaller one (the minimum) has expectation and the larger (the maximum) has — a standard fact about order statistics of uniforms. Since the distance is just , linearity of expectation gives , 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
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.
Picture running the 1-D experiment many times: each trial drops two random points on and records their distance; the running average of those distances settles toward 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 () 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 , the expected absolute distance between them is , derivable either by a direct integral using symmetry, or in two lines via order statistics: .
Related concepts
Practice in interviews
Further reading
- Wasserman, All of Statistics, ch. 3