Prove that there exists $b \in B$ such that $d(a, b) = d(a, B)$. I am currently taking an introductory real analysis course which corresponds roughly to the first half of Rudin.
The following problems have me absolutely stumped:


*

*Let $B \in \mathbb{R}^k$ be nonempty and compact with $a \in B^C$. Prove that there exists $b \in B$ such that $d(a, b) = d(a, B$).

*Let $B \in \mathbb{R}^k$ be nonempty and closed with $a \in B^C$. Prove that there exists $b \in B$ such that $d(a, b) = d(a, B$).

*In this part, we consider the metric space $\mathbb{Q}$ (usual metric). I want to find a nonempty closed subset $B \in \mathbb{Q}$ and a rational number $a \in B^C$. such that there is no $b \in B$ for which $d(a, b) = d(a, B$.
On notation: By $d(a, B)$ we mean the smallest distance from $a$ to any point in $B$. That is, $d(a, B) = \inf \{d(a, b) \mid b \in B \}$.
My thoughts on the problem:
In parts (a) and (b), we are working in $\mathbb{R}^k$ and as such receive some nice properties. For example, since $B \subset \mathbb{R}^k$ is compact, it is evident that $B$ is closed and bounded. Thus part (a) follows directly from part (b).
However, I feel that this is the wrong approach since (a) is asked before (b). Furthermore, I have not made any nontrivial progress on part (b).
In part (c), we are showing that the statements in (a) and (b) do not hold in a general metric space. In particular, (b) does not hold in the metric space $X=\mathbb{Q}$ with the usual metric. This leads me to believe that I need to choose a $B$ that has rational endpoints. My first instinct is to guess $B=(\sqrt 2, \sqrt{3}) \cap \mathbb{Q}$ which is nonempty and closed. My intuition tells me that we cannot find a number outside this interval with minimal distance to $B$ because if there was such a number, we could find another rational in between (by the density of real numbers). However, I have yet to be able to formalize this idea rigourously.
Note that I chose to include all 3 subparts in this one question as I feel that they are extremely related.
 A: If we can show that $d(a,B)$=inf$\{d(a,b): b\in B \}$ is a limit point of B then the fact that $B$ is closed means that the inf is in $B$.
Let $r = d(a, B)$
Construct a sphere of radius $r$ around $a$. Since $r$ is the greatest lower bound of distances from $a$ to points in $B$ we know that no points of $B$ lie in the interior of our sphere. Given $\epsilon\gt 0$, Construct a sphere of radius $r+\epsilon$ around $a$. Since $r$ is the greatest lower bound, there must be at least one point of $B$ in the interior of this sphere. Since we chose $\epsilon$ with no other properties than it being positive, this is true for all $\epsilon\gt 0$. 
Therefore, we can construct a sequence of points $\{b_n\}$ such that $b_i\in B$ and $d(a,b_i)\lt r+\frac{1}{i}$. This sequence has a subsequence that converges to a point $b\in B$ and $d(a,b)\le r$. But we also know that $d(a,b)\ge r$ so $d(a,b)=r$.
For part 3, let $B=\{q\in\mathbb Q: 0\le q^2\le 2\}$ and let $a=2$. You should be able to see that no element of $B$ is going to have the desired property because $\sqrt{2}$ is not rational.
