Show that $\int_0^1|x-\mu|f(x)dx\le \frac{1}{2}, \text { where } \mu=\int_0^1xf(x)dx.$ 
Question: Let $f:[0,1]\to(0,\infty)$ be a function satisfying $$\int_0^1f(x)dx=1.$$ Show that the integral $$\int_0^1(x-a)^2f(x)dx\text{ is minimized when } a=\int_0^1xf(x)dx.$$ Hence or otherwise show that $$\int_0^1|x-\mu|f(x)dx\le \frac{1}{2}, \text { where } \mu=\int_0^1xf(x)dx.$$

My approach: Let $g:\mathbb{R}\to\mathbb{R}$ be such that $$g(a)=\int_0^1(x-a)^2f(x)dx, \forall a\in\mathbb{R}.$$
Thus $$g(a)=\int_0^1 x^2f(x)dx-2a\int_0^1xf(x)dx+a^2\int_0^1f(x)dx\\=\int_0^1 x^2f(x)dx-2a\int_0^1xf(x)dx+a^2, \forall a\in\mathbb{R}.$$ 
Observe that $g$ is differentiable $\forall a\in\mathbb{R}$. 
Now $$g'(a)=-2\int_0^1xf(x)dx+2a, \forall a\in\mathbb{R}.$$ 
Thus $$g'(a)=0\iff -2\int_0^1xf(x)dx+2a=0\iff a=\int_0^1xf(x)dx.$$
Again observe that $g'$ is differentiable $\forall a\in\mathbb{R}$ and $$g''(a)=2, \forall a\in\mathbb{R}.$$ 
This implies that $$g''\left(\int_0^1xf(x)dx\right)=2>0.$$ 
Hence by the double derivative test we can conclude that $g$ has a local minimum at $a=\int_0^1xf(x)dx$. 
Now observe that $$\lim_{a\to+\infty}g(a)=+\infty\text{ and }\lim_{a\to-\infty}g(a)=+\infty.$$ 
Thus we can conclude that $g$ attain it's global minimum at $$a=\int_0^1 xf(x)dx.$$
Hence, we are done with the first part of the question. 
For the second part I was trying to solve using the Cauchy-Schwarz inequality for integrals, but haven't found anything meaningful yet. Someone please help me in proceeding. 
 A: Let $A = \int_0^\mu |x-\mu| f(x) dx$ and $B = \int_\mu^1 |x-\mu| f(x)dx$. The integral at hand equals to
$$I \stackrel{def}{=} \int_0^1 |x-\mu|f(x) dx = A + B$$
Since $$B - A = \int_\mu^1 (x-\mu) f(x) dx - \int_0^\mu (\mu - x) f(x)dx
= \int_0^1 (x - \mu) f(x) dx = 0$$
we have $A = B \implies I = 2A = 2B$.
Notice 
$$\left[\int_0^\mu f(x) dx - (1-\mu)\right] + \left[\int_\mu^1 f(x) dx - \mu \right] = \int_0^1 f(x) dx - 1 = 0$$
At least one of the square brackets on LHS is negative.
Let's say $\int_0^\mu f(x)dx \le 1 - \mu$, we will have
$$A = \int_0^\mu |x-\mu| f(x) dx \le \mu \int_0^\mu f(x) dx \le \mu(1-\mu)$$
Otherwise, $\int_\mu^1 f(x) dx < \mu$ and
$$B = \int_\mu^1 |x-\mu| f(x) dx \le (1-\mu)\int_\mu^1 f(x) dx \le (1-\mu)\mu$$
In both cases, we find $I \le 2\mu(1-\mu)$. It is easy to see $\mu \in [0,1]$, this leads to
$$\int_0^1 |x-\mu|f(x) dx \le \sup_{\mu \in [0,1]} 2\mu(1-\mu) = \frac12$$
As an alternate approach, we can use the fact $f(x)$ is non-negative and integrate to $1$. This allow us to treat $f(x)$ as a probability density for a random variable $X$ takings values in $[0,1]$ with mean $\mu$. Let $\sigma^2$ be the variance of $X$.
By a variant of Cauchy Schwarz inequality, we have
$$I^2 = \verb/E/\bigg[|X-\mu|\cdot 1\bigg]^2 \le \verb/E/\left[(X - \mu)^2\right]\verb/E/\bigg[1^2\bigg] = \sigma^2$$
By Popoviciu's inequality on variances, we get
$$\sigma^2 \le \frac14(1 - 0)^2 = \frac14
\quad\implies\quad \int_0^1 |x-\mu|f(x) dx \le \sigma \le \frac12
$$
A: How about a one-line proof ?

$
\int_0^1|x-\mu|f(x)dx = E[|X-\mu|] = E\sqrt{(X-\mu)^2} \le \sqrt{E(X-\mu)^2} =: \sqrt{\text{Var}(X)} \le \sqrt{1/4} = 1/2,
$
where the first inequality is by Jensen's inequality (since the function $\varphi: [0, \infty) \rightarrow [0,\infty)$, defined by $\varphi(t) = \sqrt{t}$ is concave) and the second is Popoviciu's inequality, namely

If $X$ is a random variable such that $a \le X \le b$ a.s, then $\text{Var}(X) \le (b-a)^2/4$.

A: By Cauchy-Schwarz inequality we have $$\left|\int_0^1|x-\mu|f(x)dx\right|=\int_0^1|x-\mu|f(x)dx=\int_0^1\left(|x-\mu|\sqrt{f(x)}\right)\left(\sqrt{f(x)}\right)dx\\\le \sqrt{\int_0^1|x-\mu|^2f(x)dx \int_0^1f(x)dx}\\= \sqrt{\int_0^1|x-\mu|^2f(x)dx}\\=\sqrt{\int_0^1(x-\mu)^2f(x)dx}\\=\sqrt{\int_0^1x^2f(x)dx-\mu^2}.$$
Now we have $$\left(\mu-\frac{1}{2}\right)^2\ge 0 \implies \mu^2-\mu+\frac{1}{4}\ge 0\implies -\mu^2\le -\mu+\frac{1}{4}.$$ 
Thus we have $$\int_0^1x^2f(x)dx-\mu^2\le \int_0^1x^2f(x)dx-\mu+\frac{1}{4}\\=\int_0^1x^2f(x)dx-\int_0^1xf(x)dx+\frac{1}{4}\int_0^1f(x)dx\\=\int_0^1\left(x^2-x+\frac{1}{4}\right)f(x)dx\\=\int_0^1\left(x-\frac{1}{2}\right)^2f(x)dx.$$
Now since $$0\le x\le 1 \implies -\frac{1}{2}\le x-\frac{1}{2}\le \frac{1}{2}\implies \left|x-\frac{1}{2}\right|\le \frac{1}{2}\\\implies \left|x-\frac{1}{2}\right|^2=\left(x-\frac{1}{2}\right)^2\le \frac{1}{4}.$$
Thus $\forall x\in[0,1]$, we have $$\left(x-\frac{1}{2}\right)^2f(x)\le \frac{1}{4}f(x)\\\implies \int_0^1\left(x-\frac{1}{2}\right)^2f(x)dx\le \frac{1}{4}\int_0^1f(x)dx=\frac{1}{4}.$$
Hence we have $$\int_0^1x^2f(x)dx-\mu^2\le \frac{1}{4}\\\implies \sqrt{\int_0^1x^2f(x)dx-\mu^2}\le \frac{1}{2}.$$ 
This in turn implies that $$\int_0^1|x-\mu|f(x)dx\le \sqrt{\int_0^1x^2f(x)dx-\mu^2}\le \frac{1}{2}\\\implies \int_0^1|x-\mu|f(x)dx\le \frac{1}{2}.$$
