Find $E\subseteq\mathbb{R}$ such that $\liminf_{\delta\to 0}\frac{m(E\cap(-\delta,\delta))}{2\delta}=\alpha$

Problem: Let $\alpha$ and $\beta$ be such that $0\leq\alpha\leq\beta\leq 1$. Find a measurable set $E\subseteq\mathbb{R}$ such that $$\liminf_{\delta\to 0}\frac{m(E\cap(-\delta,\delta))}{2\delta}=\alpha\quad\text{and}\quad\limsup_{\delta\to 0}\frac{m(E\cap(-\delta,\delta))}{2\delta}=\beta,$$ where $m$ is the Lebesgue measure. (Taken from Rudin's Real and Complex Analysis, Chapter 7, Exercise 2.)

I tried many things, but every attempt fails. All I can get is a set $E$ corresponding to $\alpha=0$ and $\beta=1$. But when $0<\alpha\leq\beta<1$, I don't know how to get $E$.

I'd actually say that the $0<\alpha<\beta<1$ case is a little easier, in that you can actually realise the limits infinitely often.

Lets start at $\delta = 1$, and we'll specify that $x\in E$ iff $-x\in E$, so we only have to work with $$f(\delta) = \frac{m(E\cap (0, \delta))}{\delta}.$$ Furthermore, assume $f(1) = \alpha$. Now, we want this to be a minima for $f$ near $0$, so we want some $x_1$ such that $E\cap(x_1, 1) = \emptyset$, and we may as well also try to ensure that $f(x_1) = \beta$. Now, $m(E\cap(0, 1)) = \alpha$, and we want $f(x) = m(E\cap(0, x_1))/x_1 = \alpha/x_1 = \beta$, and clearly $x_1 = \frac{\alpha}{\beta}$ satisfies that equation.

And we want $f(x_1)$ to be a maxima, and the easiest way to ensure that is with a $y_1$ such that $(y_1, x_1) \subseteq E$ and we can also assume that $f(y_1) = \alpha.$ Now, $$f(y_1) = \frac{m(E\cap (0, y_1)}{y_1} = \frac{\alpha - \alpha/\beta + y_1}{y_1} = \alpha$$ and therefore $$y_1 = \frac{\alpha(1-\beta)}{\beta(1-\alpha)}.$$

And then we want an interval such that $(x_2, y_1)\cap E = \emptyset$ and $f(x_2) = \beta$. I claim that if we let $x_2 = \frac{\alpha}{\beta} y_1$ then we have the right value.

More generally, if we let $$E\cap(0, 1) = \bigcup_{n\in \mathbb{N}} \left( \frac{\alpha^n(1-\beta)^n}{\beta^n(1-\alpha)^n}, \frac{\alpha^n(1-\beta)^{n-1}}{\beta^n(1-\alpha)^{n-1}} \right).$$

then $f(x)$ will have a minima of $\alpha$, a maxima of $\beta$, and each value will be achieved an infinite number of times, one after the other, as $x\to 0$.

This still leaves the cases where $0 = \alpha < \beta < 1$, $0 < \alpha < \beta = 1$ and $0 \leq \alpha = \beta \leq 1$. The first two of these are pretty straightforward, and one is the complement of the other (ie take complements of $E$ to solve the other case). The last is a bit tricky. You can use a set very much like the one I have described here, but you need the max and min to start to converge to one another, whilst your $x_n$ and $y_n$ are varying enough to eventually go to $0$. If you have difficulties, leave a comment and I'll show you how to do it.

I expect that this is all discussed in the context of Lebesgue's density theorem, but if not, you should familiarise yourself with it, just so you know how freakish the relationship between $0$ and $E$ is here.

http://en.wikipedia.org/wiki/Lebesgue%27s_density_theorem