Continuous extension of a uniformly continuous function from a dense subset. I'm trying to understand an alternative proof of the idea that if $E$ is a dense subset of a metric space $X$, and $f\colon E\to\mathbb{R}$ is uniformly continuous, then $f$ has a uniform continuous extension to $X$.
I think I know how to do this using Cauchy sequences, but there is this suggested alternative. For each $p\in X$, let $V_n(p)$ be the set of $q\in E$ such that $d(p,q)<\frac{1}{n}$. Then prove that the intersections of the closures
$$
A=\bigcap_{n=1}^\infty\overline{f(V_n(p))}
$$
consists of a single point, $g(p)$, and so $g$ is the desired continuous extension of $f$. Why is this intersection a single point, and why is $g$ continuous?

This is what I did so far. Since $f$ is uniformly continuous, for given $\epsilon>0$, there is $\delta>0$ such that $\text{diam }f(V)<\epsilon$ whenever $\text{diam }V<\delta$. Since $V_n(p)$ has diameter at most $\frac{2}{n}$, taking $n>2/\delta$ would imply 
$$
\text{diam }f(V_n(p))=\text{diam }\overline{f(V_n(p))}<\epsilon
$$
So I think $\lim_{n\to\infty}\text{diam }\overline{f(V_n(p))}=0$, which would imply $A$ consists of at most one point. I noticed that the closures form a descending sequence of closed sets, but I couldn't tell if they are bounded since $X$ is an arbitrary metric space, in order to conclude that the intersection is nonempty, and hence a single point.
Lastly, why is $g$ continuous at points $p\in X\setminus E$? I was trying to think of an argument with sequences converging to $p$ since $p$ is a limit point of $E$, but got stumping on how to show $g$ is actually continuous. Thanks.
 A: I had a lot of help on this question in chat from users Srivatsan and t.b. the other day. I tried my best to write up what was said as an answer here.

Notice that the sets $\overline{f(V_n(p))}\supseteq\overline{f(V_{n+1}(p))}\supseteq\cdots$ form a nested sequence of closed sets. Moreover, let $\epsilon>0$ be given. Since $f$ is uniformly continuous, there exists $\delta>0$ such that $d(p,q) < \delta$ implies $d(f(p),f(q))<\epsilon$ for $p,q\in E$. Taking $n$ large enough so that $\frac{2}{n}<\delta$, then for $q,r\in V_n(p)$,
$$
d(q,r)<d(q,p)+d(p,r)<\frac{2}{n}<\delta
$$
so $d(f(q),f(r))<\epsilon$. Thus $f(V_n(p))$ is bounded in $\mathbb{R}$, so $\overline{f(V_n(p))}$ is bounded as well. Hence for large enough $n$ the sets form a compact nested sequence. Since $V_n(p)$ has diameter at most $\frac{2}{n}$, taking $n>2/\delta$ would imply 
$$
\operatorname{diam } f(V_n(p))=\operatorname{diam }\overline{f(V_n(p))}<\epsilon
$$
So $\lim_{n\to\infty}\operatorname{diam }\overline{f(V_n(p))}=0$, and thus their intersection consists of a single point. Also, since $\operatorname{diam }f(V_n(p))\to 0$ as $n\to\infty$, and so by choosing points arbitrarily close to $p$, their images under $g$ are arbitrarily close to $g(p)$. (To be more explicit, letting $\delta$ be small enough such that for $x,y\in E$, then $d(x,y)<2\delta$ implies $d(f(x),f(y))<\epsilon/3$, choose $n$ large enough that $\frac{1}{n}<\delta$, and thus for any $x,y\in V_n(p)$, $d(x,y)<2/n<2\delta$, so $\operatorname{diam }f(V_n(p))<2\epsilon/3$, so $d(f(x),g(p))<2\epsilon/3$. Note also that this can be done for any $p$.)
I contend that $g$ is uniformly continuous. Let $\epsilon>0$ be given. Since $f$ is uniformly continuous, there exists $\delta>0$ such that $d(r,s)<\delta$ implies $d(f(r),f(s))<\epsilon/3$. Now let $p,q\in X$ be any points such that $d(p,q)<\delta/3$. By the above reasoning, choose $n$ large enough so that $n>\frac{3}{\delta}$, and both $d(g(r),g(p))<\epsilon/3$ and $d(g(s),g(q))<\epsilon/3$ for $r\in V_n(p)$ and $s\in V_n(q)$. Also, 
$$
d(r,s)<d(r,p)+d(p,q)+d(q,s)<\delta
$$
so $d(f(r),f(s))=d(g(r),g(s))<\epsilon/3$. By the triangle inequality, $d(g(p),g(q))<\epsilon$, so $g$ is uniformly continuous, and thus continuous on $X$, and of course $g|_E=f$.
A: As Srivatsan notes, any set with a finite diameter is bounded. You have shown that for a fixed $\varepsilon$, ${\rm diam} \overline {f(V_n(p))} < \varepsilon$, starting from some $n$. So starting from some $n$, $\overline {f(V_n(p))}$ are all bounded and hence compact. Furthermore the image of a real uniformly continuous function on the bounded set is bounded. This is Exercise 4.8 in Rudin.
For continuity on $p \in X$ you do the following. For $\varepsilon > 0$ you essentially want a $\delta = {1 \over n}$ so small that ${\rm diam} \overline {f(V_n(p))} < \varepsilon$. Now if $q \in X$ is such that $d(p, q) < {1 \over n}$, then you can pick $m$ so large that $V_m(q) \subseteq V_n(p)$. Then $\overline {f(V_m(q))} \subseteq \overline {f(V_n(p))}$ and so $g(p), g(q) \in \overline {f(V_n(p))}$. This implies that $d(g(p), g(q)) < \varepsilon$. By uniform continuity of $f$ you can pick $\delta$ independent of $p$ and this gives you uniform continuity.
A: Here is a perhaps an alternative way of looking at what happens before you take the infinite intersection. We know that $\textrm{diam} V_n(p) < \frac{2}{n}$. So by uniform continuity of $f$, for all $\epsilon > 0$ there exists $\delta > 0$ (and hence an $n\in \Bbb{N}$ such that $0 < \frac{1}{2n} < \delta$ by the Archimedean property) such that 
$$\textrm{diam} f(V_n(p)) < \epsilon.$$
In other words we have that $\textrm{diam} f(V_n(p)) \rightarrow 0$. Now Theorem 3.10(a) of Rudin tells you that for any subset $E$ of a metric space $X$, $\textrm{diam} E = \textrm{diam} \overline{E}$. Applying it here we have $\textrm{diam} \overline{f(V_n(p))} \rightarrow 0$. Now we have a nested sequence of closed sets
$$\overline{f(V_1(p))} \supset \overline{f(V_2(p))} \supset \ldots $$
Instead of using compactness, you can pick for each $n$ an $x_n \in \overline{f(V_n(p))}$. It is easy to see that $x_n$ is a cauchy sequence so by completeness of $\Bbb{R}$ must convergence to some $x$. This $x$ is easily seen to be in the infinite intersection and the diameter going to zero means that this is the only element left in it.
A: Let, $p\in X$, we define $V_n(p)=\big\{q\in E: d(p,q)<\frac{1}{n}\big\}$
We have that, $V_n(p)\neq\phi\,\forall\,n\in\Bbb N$ (Since, $\overline E=X$)
Also note that,
\begin{equation}\tag{1}
\lim_{n\to\infty}{\mbox{diam}} (V_n(p))=0
\end{equation}
Now, $f:E\to Y$ is uniformly continuous.
Hence, $\forall\,\epsilon>0\,\exists\,\delta>0$, such that whenever $F\subset E$ and diam$(F)<\delta$ then diam$(f(F))<\epsilon$
Due to (1), we have $k\in\Bbb N$ such that diam$(V_k(p))<\delta\implies$ diam$(f(V_k(p)))<\epsilon$
$\implies$ diam$(f(V_n(p)))<\epsilon\,\forall\,n\geq k$ (Since, $V_1(p)\supset V_2(p)\supset V_3(p)\dots$)
$$\implies \lim_{n\to\infty}{\mbox{diam$(f(V_n(p)))=0$}}$$
\begin{equation}\tag{2}
\implies \lim_{n\to\infty}{\mbox{diam$\overline{(f(V_n(p)))}=0$}}
\end{equation}
$Y$ is complete, $\overline{f(V_n(p))}\neq\phi\,\forall\,n\in\Bbb N$ and forms the sequence of nested closed sets (by (2)), hence by Cantor's intersection theorem we have:$$\bigcap_{n=1}^\infty\overline{f(V_n(p))}=\{y\}$$
Now, we define $g:X\to Y$ as:
\begin{equation}\tag{3}
g(x)=
\begin{cases}
f(x) &x\in E\
\bigcap_{n=1}^\infty\overline{f(V_n(x))} &x\in X\backslash E\
\end{cases}
\end{equation}
Now, we let $x\in X\backslash E$. 
From (2) we have, $\forall\,\epsilon>0\,\exists\,k_1\in\Bbb N$ such that, diam$\overline{(f(V_{k_1}(x))}<\epsilon$
$\implies$ diam$(g(\overline{V_{k_1}(x)}))<$ diam$\overline{(g(V_{k_1}(x)))}<\epsilon\implies d'(g(a),g(x))<\epsilon\,\forall\,a\in\overline{V_{k_1}(x)}$
Now, we easily can verify that, $B_{\frac{1}{k_1}}(x)\subseteq\overline{V_{k_1}(x)}$
Hence, $g$ is continuous at $x$.
Now, if $x\in E$, then also $g$ is continuous at $x$ (By continuity of $f$).
Therefore, $g:X\to Y$ is continuous extension of $f$. $\qquad\qquad\qquad\square$
