Step 1: Define the Expectation
$$
E[|X-Y|]=\int_0^1 \int_0^1|x-y| f(x, y) d x d y
$$
Since $X$ and $Y$ are independent and uniformly distributed on $[0,1]$,
$f(x, y)=f(x) f(y)=1 \times 1=1$ for all $(x, y) \in[0,1]^2$.
Hence,
$$
E[|X-Y|]=\int_0^1 \int_0^1|x-y| d x d y
$$
Step 2: Split the Integral
The function $|x-y|$ is piecewise-defined and changes form along the line $y=x$, which divides the unit square into two equal triangular regions:
- Region 1$\left(\mathrm{R}_1\right): y>x \Rightarrow|x-y|=y-x$
- Region 2 $\left(\mathrm{R}_2\right): x \geq y \Rightarrow|x-y|=x-y$
So,
$$
E[|X-Y|]=\iint_{R_1}(y-x) d x d y+\iint_{R_2}(x-y) d x d y
$$
By symmetry, both integrals are equal, so we can compute one and multiply by 2 :
$$
E[|X-Y|]=2 \iint_{R_2}(x-y) d x d y
$$
Step 3: Set Up the Integral for Region $\mathrm{R}_2$
Region $R_2: 0 \leq y \leq 1$ and $y \leq x \leq 1$
$$
E[|X-Y|]=2 \int_0^1 \int_y^1(x-y) d x d y
$$
Step 4: Compute the Inner Integral
$$
\int_y^1(x-y) d x=\left[\frac{x^2}{2}-y x\right]_y^1
$$
Substituting limits:
$$
=\left(\frac{1}{2}-y\right)-\left(\frac{y^2}{2}-y^2\right)=\frac{1}{2}-y+\frac{y^2}{2}
$$
Step 5: Compute the Outer Integral
$$
\int_0^1\left(\frac{1}{2}-y+\frac{y^2}{2}\right) d y=\left[\frac{y}{2}-\frac{y^2}{2}+\frac{y^3}{6}\right]_0^1=\frac{1}{2}-\frac{1}{2}+\frac{1}{6}=\frac{1}{6}
$$
Thus, for Region $R_2$,
$$
\iint_{R_2}(x-y) d x d y=\frac{1}{6}
$$
Since there are two symmetric regions:
$$
E[|X-Y|]=2 \times \frac{1}{6}=\frac{1}{3}
$$