Data Interview Question

Expectation of Absolute Difference

bugfree Icon

Hello, I am bugfree Assistant. Feel free to ask me for any question related to this problem

Solution & Explanation

To determine the expected value of the absolute difference xy|x-y| where xU(0,1)x\sim U(0,1) and yU(0,2)y\sim U(0,2), we need to consider the joint distribution of xx and yy and evaluate the expectation over the defined support.

Step-by-Step Solution

1. Define the Probability Density Functions (PDFs):

  • xU(0,1)x\sim U(0,1) implies the PDF of xx is f(x)=1f(x) = 1 for 0x10 \leq x \leq 1.
  • yU(0,2)y\sim U(0,2) implies the PDF of yy is f(y)=12f(y) = \frac{1}{2} for 0y20 \leq y \leq 2.

2. Joint PDF:

  • Since xx and yy are independent, the joint PDF is: f(x,y)=f(x)f(y)=112=12f(x,y) = f(x) \cdot f(y) = 1 \cdot \frac{1}{2} = \frac{1}{2}

3. Expected Value of xy|x-y|:

  • The expected value can be calculated by integrating over the entire region where xx and yy are defined: E[xy]=0201xy12 dx dyE[|x-y|] = \int_{0}^{2} \int_{0}^{1} |x-y| \cdot \frac{1}{2} \ dx \ dy

4. Split the Integral into Two Cases:

  • Case 1: x>yx > y E[xy]=020y(yx)12 dx dyE[|x-y|] = \int_{0}^{2} \int_{0}^{y} (y-x) \cdot \frac{1}{2} \ dx \ dy
  • Case 2: x<yx < y E[xy]=02y1(xy)12 dx dyE[|x-y|] = \int_{0}^{2} \int_{y}^{1} (x-y) \cdot \frac{1}{2} \ dx \ dy

5. Evaluate the Integrals:

  • For Case 1: 020y(yx)12 dx dy=02[y22yx2]0y dy=02y22 dy=812\int_{0}^{2} \int_{0}^{y} (y-x) \cdot \frac{1}{2} \ dx \ dy = \int_{0}^{2} \left[\frac{y^2}{2} - \frac{yx}{2} \right]_{0}^{y} \ dy = \int_{0}^{2} \frac{y^2}{2} \ dy = \frac{8}{12}
  • For Case 2: 02y1(xy)12 dx dy=02[x22xy2]y1 dy=02(12y2y22)dy=412\int_{0}^{2} \int_{y}^{1} (x-y) \cdot \frac{1}{2} \ dx \ dy = \int_{0}^{2} \left[\frac{x^2}{2} - \frac{xy}{2} \right]_{y}^{1} \ dy = \int_{0}^{2} \left(\frac{1}{2} - \frac{y}{2} - \frac{y^2}{2} \right) dy = \frac{4}{12}

6. Combine the Results:

  • Add the results from both cases: E[xy]=812+412=1212=23E[|x-y|] = \frac{8}{12} + \frac{4}{12} = \frac{12}{12} = \frac{2}{3}

Conclusion

The expected value of the absolute difference xy|x-y| is 23\frac{2}{3}. This result is consistent with both analytical methods and simulation approaches, confirming the accuracy of the calculation.