Questions about $d(x,A)$ and $\operatorname{diam}(A)$ in a metric space I have 2 questions, one each for $d(x,A)$ and $\operatorname{diam}(A)$, where $A$ is a nonempty subset of a metric space $(X,d)$. Both of them are somewhat related to each other. The first one is about the following statement.

There exists $y\in\bar{A}$ such that $d(x,A)=d(x,y)$.

I figured that this is the case when $X=\mathbb{R}^n$, but my proof relies heavily on the Bolzano-Weierstrass theorem (every bounded sequence has a convergent subsequence) and I can't figure out how I should generalize this to general metric spaces. If this is not true for general metric spaces, how further can we generalize?
The second one is about $\operatorname{diam}(A)$:

If $\operatorname{diam}(A)<\infty$, then there exist $x,y\in\bar{A}$ such that $\operatorname{diam}(A)=d(x,y)$.

Again, my proof relies heavily on the B-W theorem (and the fact that the function $d:X\times X\rightarrow\mathbb{R}$ is continous) and I can't figure out a way to avoid B-W in the argument. Is this not true in general? If so, can someone provide me illustrative counterexamples?
 A: For counterexamples for the general case, consider $A=\{(x_1,x_2)\in\mathbb{Q}^2\,|\,x_1^2+x_2^2=1\}$ and $x=(1,1)$ in $X=\mathbb{Q}^2$ for the first case and $A=(-\sqrt{2},\sqrt{2})\cap\mathbb{Q}$ and $x=2$ in $X=\mathbb{Q}$ for the second case. This means that completeness is something to be assumed.
For counterexamples in the complete case, consider the complete metric space $\ell^2(\mathbb{N})$ whose elements are all infinite sequences $(x_n)$ of real numbers such that $\sum_n\,x_n^2<\infty$ and whose metric is given by
$$d((x_n),(y_n))=\sqrt{\sum_{n=1}^\infty\,(x_n-y_n)^2}\text{.}$$
It is a classic result and/or an interesting exercise that this is effectively a complete metric space. In this space:


*

*Taking $A=\{(1+1/n)e_n\,|\,n\geq 0\}$, where $e_n$ is the sequence with a $1$ in the $n$-th position and $0$ in the rest, and $x=0$, we have that $A$ is closed, $d(x,A)=1$ and $d(x,y)>1$ for all $y\in A$. Thus this is a counterexample for the first statement.

*Taking $A=\{(1-1/n)e_n\,|\,n\geq 1\}$, we have that $A$ is closed, $\mathrm{diam}(A)=2$ and $d(x,y)<2$ for all $x,y\in A$. Therefore this is a counterexample for the second statement.


In conclusion, even in the complete case there are counterexamples for your two statements. This means (up to what I can think) that a compactness assumption (e.g., that every closed ball is compact) is essential, as it has happened to you in the case of $\mathbb{R}^n$.
A: The answer of both of questions is related a theorem which states " Every continuous function defined on a closed(compact) set attains its supremum   and infimum "
By definition we have $d(x,A)=inf\{d(x,a)|a\in A\}$ note that this function attains its  infimum then there exists $a\in A$ such that $d(x,A)=d(x,a).$
