Here is the question from Pugh's Real Mathematical Analysis:

My answer to $b)$ is that for a closed square, points on corner has density $1/4$, while on the sides the density is $1/2$. But how to understand that "almost every point has density 1" by Lebesgue's density theorem? Is it because side of a square in $R^2$ has lower dimension and thus has zero measure (i.e. line in a plane has zero measure)?
For $c)$, I want to use set of natural numbers (denote as $N$), which has measure $0$. So $m(B \cap N)=0$, while $mB$ is the length of interval. So this imply that density of any natural number is $0$? I find a little bit confused because the denominator (length of interval) also tends to $0$. Still can someone show the density of points in the cantor set? By Lebesgue's density theorem, almost every point should have density of 1, but how to compute that, and are there points in cantor set with other values of density?
What's more, the textbook does not require the ball $B$ to be centered at $x$, while many other materials require the ball to be centered at $x$ (and if B's centre is x, the textbook calls such density the balanced density as the picture shows). So what's the difference between those 2 versions of "density"? Are they eventually the same definition? It is confused to compare limits where one come from balls centred at a point (balanced density), while others only require ball contain a point (density in this textbook).
Thanks!
Remember that 'almost everywhere' is shorthand for 'everywhere except a set of measure zero'. Thus, the sides and corners of the square don't count for the square to have balanced density 1 almost everywhere, since they are of measure zero. Furthermore, any statement is true almost anywhere on a set of measure zero, like the natural numbers or the Cantor set, which have density zero everywhere. (The denominator does tend to zero, yes, but the limit of $0/x$ is 0 as $x$ approaches $0$.)
Your intuition works well for $\mathbb{R}^2$, but you are missing some pieces of the question. Note that you are asked to find a set $E$ and point $x$ of balanced density $\alpha$ for any $\alpha\in [0,1]$, and the square only works for $\alpha \in \{1/4, 1/2, 1\}$. In two dimensions this can be fixed by choosing something along the line of circular sectors with varying central angle. However, the question also asks you to do this in one dimension, which is less intuitive.
There's definitely a difference between parts b) and c), because the balanced density might exist whereas the more general form of density might not. An example would be the point $\{0\}$ in the set $[0,1]$. The balanced density is clearly $1/2$, but you have small neighborhoods of the form $(-2^{-n}, 1/n)$ and $(-1/n, 2^{-n})$ demonstrating that once you remove the centering assumption you cannot force the limit to exist merely by reducing the radius of your balls. However, if the more general limit exists then it forces the balanced limit to exist as well.
Hopefully this helps clarify the situation.