# Calculating the expectancy

The distance between two numbers will be set as $$\ | i - j |$$ . I pick two numbers without replacement from $$\ 0,1,2, \dots ,n$$ let $$\ X$$ be the distance between the numbers. What is the expectancy of $$\ X$$ ?

there are $$\ {n+1 \choose 2}$$ options. so $$\ {n+1 \choose 2} = \frac{n(n+1)}{2}$$ and the probability will be $$\ P\{X = i\} = \frac{2(n+1-i)}{n(n+1)}$$

Then the expectancy $$\ E[X] = \sum_{i=1}^n x_i \cdot p(x_i) = \sum_{i=1}^n x_i \frac{2(n+1-i)}{n(n+1)}$$

I don't really know how to proceed from here?

• I don't know why you are switching to $x_i \cdot p(x_i)$. Your probability $P\{X = i\}$ is correct and the expectation is $E[X] = \sum_{i = 1}^n i \cdot P\{X = i\}$ – Lee David Chung Lin Dec 2 '18 at 12:12
• I need to somehow get to this answer : $\ \frac{n+2}{3}$ – bm1125 Dec 2 '18 at 13:07
• You have to set $x_i=i$ and then apply the usual techniques to evaluate the sum. – Ingix Dec 2 '18 at 13:53

You are almost there.

$$x_i = i$$ in your formula for the expectation.

$$E[X]=\sum_1^n\frac{2i(n+1-i)}{n(n+1)}$$

Then, use the identities:

$$\sum_1^n i =\frac{n(n+1)}{2}$$

and

$$\sum_1^n i^2 =\frac{n(n+1)(2n+1)}{6}$$

We get

$$E[X]=\frac{2}{n(n+1)}(n+1)\sum i -\frac{2}{n(n+1)}\sum i^2$$

$$E[X]=\frac{2}{n}\frac{n(n+1)}{2} - \frac{2}{n(n+1)}\frac{n(n+1)(2n+1)}{6}$$

Therefore

$$E[X]=n+1-\frac{2n+1}{3}=\frac{n+2}{3}$$