The population mean and median of a uniform distribution on $[0,1]$ are both $\frac12$ as it is symmetric about $\frac12$.
Let's write $\bar X$ for $\frac1n \sum X_i$. We can say:
- $\mathbb E\left[|X_i-\frac12|\right]=\frac14$ so $\mathbb E\left[\frac1n\sum|X_i-\frac12|\right]=\frac14$ and $\mathbb E\left[\sum|X_i-\frac12|\right]=\frac n4$.
- For $n=1$, $X_1=\bar X$ so $\mathbb E\left[|X_1-\bar X|\right]=0$ and $\mathbb E\left[\sum|X_i-\frac12|\right] - \mathbb E\left[\sum|X_i-\bar X|\right] =\mathbb E\left[|X_1-\frac12|\right] - \mathbb E\left[|X_1-\bar X|\right] =\frac14$.
- For $n>1$, $\mathbb E\left[|X_i-\bar X|\right]=\mathbb E\left[\frac1n\sum|X_i-\bar X|\right]= \frac14\left(1-\frac{2}{3n}\right)$ for $n>1$
- so $\mathbb E\left[\sum|X_i-\bar X|\right]= \frac n4-\frac{1}{6}$
- and thus $\mathbb E\left[\sum|X_i-\frac12|\right] - \mathbb E\left[\sum|X_i-\bar X|\right] =\frac16$ for $n>1$, much as you found.
In another question, ashpool stated in comments that the $\left(1-\frac{2}{3n}\right)$ term can be proved at least for $n=2,3,4$. As an illustration, see the following simulation in R (the average absolute deviation from the sample mean is in black and from the population mean in grey, with the simulations as points and $\frac14\left(1-\frac{2}{3n}\right)$ and $\frac14$ as lines):
avabsdevunif <- function(n, low=0, high=1){
X <- runif(n, low, high)
meanX <- mean(X)
return(c(mean(abs(X-meanX)), mean(abs(X-(high-low)/2))))
}
set.seed(2023)
cases <- 10^5
avabsdev <- matrix(nrow=2, ncol=10)
for (n in 1:10){
simunif <- replicate(cases, avabsdevunif(n))
avabsdev[,n] <- c(mean(simunif[1,]), mean(simunif[2,]))
}
plot(1:10, avabsdev[1,], ylim=c(0,0.26))
curve((1-2/(3*x))/4, from=1, to=10, add=TRUE)
points(1:10, avabsdev[2,], pch=15, col="lightgrey")
abline(h=1/4, col="lightgrey")
A normal distribution $N(\mu, \sigma^2)$ would show a different result,
- with $\mathbb E\left[\frac1n\sum|X_i-\frac12|\right]=\sqrt{\frac{2}{\pi}} \sigma$
- and $\mathbb E\left[\frac1n\sum|X_i-\bar X|\right]=\sqrt{\frac{n-1}{n}} \sqrt{\frac{2}{\pi}} \sigma$,
- so $\mathbb E\left[\sum|X_i-\mu|\right] - \mathbb E\left[\sum|X_i-\bar X|\right] = (n-\sqrt{n(n-1)})\sqrt{\frac{2}{\pi}} \sigma$
- which gradually reduces towards $\frac{\sigma}{\sqrt{2\pi}} $ as $n$ increases.