If $X$ is a compact set, when does $f'(0)$ exist? Let $X$ be a compact set in $\mathbb R$ and for $t\geq 0$ define $f(t)$ as $$f(t) = m(\{x\in \mathbb R| \exists y \in X : |x-y| \leq t\})$$ Under what conditions for $X$ does $f'(0)$ exist? ($m$ is the Lebesgue measure)
If $X$ is finite, then $f'(0)$ exist. Also, if $X$ contains an interval, f'(0) does not exist. I also showed that if $X=\{\frac{1}{2^n}, n\in \mathbb N\} \cup \{0\}$, then $f'(0)$ does not exist. If I am correct, this seems very strange to me, because $X$ has measure $0$ and I would think that for the derivative at zero to exist, the nominator $f(t)-f(0) = f(t)-m(X)$ has to go to $0$ faster than the denominator $t$ and the fastest way for this to happen would be if $X$ had measure $0$, so that $f$ doesn't "measure" a lot of points. 
So, now I am at a loss and can't find what other properties $X$ must have. Thanks for any help and I hope I am clear enough in my explanation!

UPDATE: With the help of the comments from Niels Diepeveen, I managed to do some work on this, but I am still stuck on a point. My work: 
Let $\cal{C}$ be the collection of the connected components of $X$. The claim is that $f'(0)$ exists if and only if $\cal{C}$ is finite.
$(\Leftarrow$) If $\cal{C}$ is finite, then $\cal{C}$ $= \{X_1, X_2,..., X_k\}$. Each $X_i$ is closed and they are pairwise disjoint, therefore there is a $t_0$ such that $$\forall x \text{ with }  d(x,X_i) \leq t_0 \Rightarrow d(x, X_j) > t_o, \forall j \neq i$$
Additionaly each $X_i$ is measurable as a closed and bounded set. Hence, for $t \leq t_o$, $f(t) = \sum_{i=1}^{k} m(X_i) + 2kt$ which means that $f'(0) = 2k$.
$(\Rightarrow)$ Suppose that $f'(0)$ exists but $\cal{C}$ is infinite. Let $M$ be given. Then there is a $k \in \mathbb{N}$ such that $2k>M$. Then, as before, we find a $t_0$ for $k$ of the sets in $\cal{C}$, let them be $\{X_1,...X_k\}$ such that $$\forall x \text{ with }  d(x,X_i) \leq t_0 \Rightarrow d(x, X_j) > t_o, \forall j \neq i, i,j \in \{0,...,k\}$$
Now the problem is, that if I take $t \leq t_o$ I would like to have $$\frac{f(t)-f(0)}{t-0} \geq \frac{f(t_0) - m(X)}{t_0} \geq \frac{m(X) + 2kt_0 -m(X)}{t_0} = 2k > M$$ and then the problem would be solved. But I don't see how I can prove that first inequality (the others are easy). It actually means that the function $\frac{f(t)}{t}$ is decrasing, which seems logical to me, but I can't prove it.
 A: For every compact set $X\in\mathbb R$ define $$d(X)=\liminf_{t\to 0^+}\, t^{-1}\left( m(\{x\in \mathbb R  \, |\, \exists y \in X : |x-y| \leq t\})-m(X)\right)$$
(this quantity is always defined, though may  be $+\infty$). Then


*

*$d(X)\ge 2$ for every nonempty $X$, because you get two intervals of length $t$ next to $\min X$ and $\max X$.

*$d(X\cup Y)\ge d(X)+d(Y)$ when $X$ and $Y$ are disjoint. Indeed, when $2t<\operatorname{dist}(X,Y)$, the $t$-neighborhoods are disjoint. So the  measures add up, and $\liminf $ of a sum is at least the sum of $\liminf$s.


Now suppose that $X$ has infinitely many connected components. Since it's not connected, there is $a\in \mathbb R\setminus X$ such that $\min X<a<\max X$. The sets $X_1=X\cap (-\infty,a]$ and $X_2=X\cap  [a,\infty)$ are nonempty and compact. By 2, $d(X)\ge d(X_1)+d(X_2)$. But at least one of $X_1$ and $X_2$ has infinitely many components, say $X_1$. So, $d(X_1)\ge d(X_{11})+d(X_{12})$, and this can continue indefinitely. Thus, $d(X)=\infty$. 
A: The following suggestion should be a comment, but I think it is better to use the whole space here.
Define $X_{\delta}=\cup_{x\in X}B(x,\delta)$, since $X$ is bounded then $X_{\delta}$ has finitely many components; fill in details. For $X_{\delta}$ define $f_{\delta}$ as you did for $f$. Note that $f_{\delta}(t)=f(t+\delta)$ and $f(0)\le f_{\delta}(0)$, therefore
$$
\frac{f(t)-f(0)}{t}\ge\frac{f_{\delta}(t-\delta)-f_{\delta}(0)}{t-\delta}\frac{t-\delta}{t},
$$
the derivative $f_{\delta}'(0)$ should tend to the number of components ($\infty$) and $(f_{\delta}(t)-f_{\delta}(0))/t=f_{\delta}'(0)$ for $t\le\epsilon_\delta$. Somehow, you may be able to prove that there exists a sequence $r_n\to 0$ such that $\epsilon_{r_n}=r_n$; this concludes the problem.
Honestly, I'm not happy with my advice, I hope there is something much better out there.
