ML0203 Expected |X-Y| for Uniforms

Two random variables X and Y are independent and uniform on [0, 1]. What is the expected value of their difference, and what is the expected value of their absolute difference?

Three-panel whiteboard card. Panel one shows the setup: a caller score X and an agent score Y, each drawn independently from Uniform 0 to 1. Panel two shows the two open questions: the expected signed gap E of X minus Y, and the expected absolute gap E of the absolute value of X minus Y. Panel three lists four whiteboard candidates for the absolute gap, A 0, B one quarter, C one third and D one half, under a constraint of no calculator, no simulation and five minutes

The Problem: In a probability drill reported by candidates from a 2021 Afiniti interview, a caller score X and an agent score Y are independent draws from Uniform[0, 1]. With no calculator and five minutes, you must give the expected signed gap and the expected absolute gap, choosing between the whiteboard candidates 0, 1/4, 1/3 and 1/2.

Answer

The signed difference has expected value zero, because linearity gives E[X - Y] = E[X] - E[Y] = 1/2 - 1/2 = 0 and needs no independence at all. The absolute difference cannot cancel, since |X - Y| folds the negative half of the gap onto the positive half. Integrating |x - y| over the unit square and splitting at the diagonal gives E|X - Y| = 2\int_0^1\int_0^x (x - y)\,dy\,dx = 1/3. The order-statistics shortcut reaches the same number in one line, because |X - Y| = \max(X, Y) - \min(X, Y) with expectations 2/3 and 1/3. Equivalently, the two points cut [0, 1] into three exchangeable spacings of expected length 1/3 each, and the gap is the middle one.

(1) Signed Gap Is Zero: Linearity of expectation needs only finite means, so E[X - Y] = 0 even for dependent pairs. Under independence Z = X - Y has the triangular density 1 - |z| on [-1, 1], symmetric about zero.
(2) Absolute Gap Is 1/3, Not 1/2: Folding the triangle gives f_D(d) = 2(1 - d), which piles probability near zero, so the mean lands at 1/3. The gut answer 1/2 overweights large gaps that are actually rare.
(3) Tail Area Route: The event |X - Y| > d is two corner triangles with legs 1 - d, so P(D > d) = (1 - d)^2 and integrating that tail probability gives 1/3.
(4) Order Statistics Route: P(\max \leq m) = m^2 gives E[\max] = 2/3, and symmetry gives E[\min] = 1/3. Their difference is the gap, so the answer follows with no integration beyond a CDF.
(5) Spread Check: E[D^2] = \mathrm{Var}(X - Y) = 1/6, so \mathrm{Var}(D) = 1/6 - 1/9 = 1/18 and the gap has a standard deviation of about 0.236.

Mathematical Formulation:
E[X - Y] = E[X] - E[Y] = 0
E|X - Y| = \int_0^1 \int_0^1 |x - y| \, dx \, dy
= 2\int_0^1 \int_0^x (x - y) \, dy \, dx
= 2\int_0^1 \frac{x^2}{2} \, dx = \frac{1}{3}
P(D > d) = (1 - d)^2
f_D(d) = 2(1 - d)
E[D] = \int_0^1 P(D > t) \, dt
= \int_0^1 (1 - t)^2 \, dt = \frac{1}{3}
E[D] = E[\max(X, Y)] - E[\min(X, Y)]
= \frac{2}{3} - \frac{1}{3} = \frac{1}{3}

Where:

  • X and Y are independent Uniform[0, 1] variables with mean 1/2 each, so their joint density is 1 on the unit square; D = |X - Y| is the absolute gap.
  • x and y are integration variables; the factor 2 comes from the symmetry of the triangles above and below the diagonal y = x, and the inner integral \int_0^x (x - y)\,dy equals x^2/2.
  • d \in [0, 1] is a gap threshold, P(D > d) is the combined area of two corner triangles, and f_D(d) is its negative derivative, the density of the gap.
  • t is a dummy variable in the tail-integral identity E[D] = \int_0^\infty P(D > t)\,dt, valid for any nonnegative D.
  • \max(X, Y) and \min(X, Y) are the order statistics; E[\max] = 2/3 follows from the density 2m and E[\min] = 1/3 from P(\min > m) = (1 - m)^2.
Three-panel figure. Panel a: the unit square with two shaded corner triangles where the absolute difference exceeds 0.5, each of area one eighth, and the central band of area three quarters. Panel b: the triangular density 1 minus the absolute value of z for the signed difference X minus Y on minus 1 to 1, with a dashed line at its mean 0 and a simulated histogram on top. Panel c: the density 2 times 1 minus d for the absolute difference on 0 to 1, matched by a histogram of 200,000 simulated pairs, with a dashed line at the mean one third and a dotted line at the gut guess one half

Figure 1: (a) The event |X - Y| > 0.5 is two corner triangles of area 1/8 each, so its probability is 1/4. (b) The signed gap has the triangular density 1 - |z|, symmetric with mean 0. (c) Folding gives f_D(d) = 2(1 - d), and 200,000 simulated pairs match it with mean 1/3, well below the gut guess 1/2.

Worked Example:
Replace each uniform by a fair draw from the four midpoints 0.125, 0.375, 0.625 and 0.875, so all 16 ordered pairs are equally likely. Four pairs have gap 0, six have gap 0.25, four have gap 0.5, and two have gap 0.75. The mean absolute gap is (6 \times 0.25 + 4 \times 0.5 + 2 \times 0.75)/16 = 5/16 = 0.3125, while the signed gaps cancel pair by pair to exactly 0. For k midpoints the same count gives (k^2 - 1)/(3k^2), which is 0.25 at k = 2 and 0.33 at k = 10, approaching 1/3 from below. That convergence is a quick sanity check that the continuous answer is 1/3 and not 1/2.

All three derivation routes reach 1/3, but they differ in how fast they fit on a whiteboard and in what they generalize to. The order-statistics route is the fastest under interview pressure, the double integral is the one that survives a change of joint density, and the tail route answers follow-up questions about medians and threshold probabilities for free.

PropertyOrder statisticsDouble integralTail integral
Key stepGap = max – min, with E[max] = 2/3 and E[min] = 1/3Split the unit square at the diagonal y = xP(D > d) = (1 – d)^2 from two corner triangles
Whiteboard lengthTwo linesFour linesThree lines
Generalizes toExpected range of n uniforms, (n – 1)/(n + 1)Any joint density, including dependent pairsMedians, quantiles and threshold probabilities of the gap
Common slipAssuming E[max] of two uniforms is 1Dropping the factor 2 and answering 1/6Counting only one corner triangle, which also gives 1/6

Login to view more content
Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *