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. 

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}.$$
