# How can I calculate E[∑Xi=1I{Yi≤Yn+1}]\mathrm{E}\!\left[\sum _{i=1}^X I_{\{Y_i\leq Y_{n+1}\}}\right]?

Suppose that $Y_1,\dots,Y_{n+1}$ is a random sample from a continuous distribution function $F$. Let$X\sim\mathrm{Uniform}\{1,\dots,n\}$ be independent of the $Y_i$‘s. How can I compute $\mathrm{E}\!\left[\sum _{i=1}^X I_{\{Y_i\leq Y_{n+1}\}}\right]$?

The third step follows from independence of $Y_i$ and $Y_{n+1}$ from $X$; the fourth step is again an application of the law of iterated expectations; the last step is simply an application of the formula for the expectation of a discrete uniform random variable.
which implies $E[F(Y_{n+1})] = \frac{1}{2}$. Hence: