If f(x) is a density function, then its integral over the entire real line should be 1:
[tex]\displaystyle\int_{-\infty}^\infty f(x)\,\mathrm dx=\int_0^2(1-0.5x)\,\mathrm dx=(x-0.25x^2)\bigg|_0^2=2-1=1[/tex]
so yes, f(x) is indeed a density function.