What is the expected value of |0.5-X| when X is following the beta distribution of the first kind(alpha=2, beta=2)?
The reason why I want to do is to compare the performance between normal quick sort and median-of-three quick sort.
Normal quick sort: pick up the first element as pivot
Median-of-three quick sort: pick up the first, middle and end element and pick up the median of those, then take it as pivot.
memo
Probability Density Function of B(2,2)
$$f(x)=cx^{a-1}(1-x)^{b-1} = 6x(1-x)$$
$$E(X)=\int_{-\infty}^{\infty} xf(x) \,dx$$
$$E(|0.5-X|)=\int_{x=0}^{\frac12} (0.5-x)6x(1-x) \,dx + \int_{x=\frac12}^{1} (x-0.5)6x(1-x) \,dx=0.1875$$
Just integrate the (symmetric) beta distribution between $0$ and $1/2$ (or from $1/2$ to $1$) to find $0.1875$.
$$\frac{\int\limits_{x=0}^{1/2} (x-.5) x (1-x)\ dx}{\int\limits_{x=0}^{1/2} x (1-x)\ dx} = .1875$$