Condition for which $ \text{dist}(x,A) = d(x,y_0)$ If $(X,d)$ is metric space, $x\in X$ and $A \subset X$. Let's mark $$\text{dist}(x,A) = \text{inf}\; \Big\{ d(x,y) : y \in A \Big\}$$


Does there always exists $y_0 \in A$ that $ \text{dist}(x,A) = d(x,y_0)$ ? Will the answer change, if set $A$ is closed? 
Can someone help to solve this exercise?
First Consider a finite dimensional vector space like $\mathbb R$. Take for $x$ the origin.

An example of a bounded subset for which distance is not attained below:


   $A = (1,2]$


If $A$ is compact, then the distance is always attained. For the proof consider a sequence $(x_n)$ such that $d(x_n ,A) \to d(x,A)$ and extract a converging sub-sequence.

If $A$ is closed, then the distance is also always attained. For the proof, consider a point $a \in A$. Then $\overline A = \{y \in A \colon d(x,y) \le d(x,a)\}$ is compact and you can use point above.

Second. Case of an infinite dimensional vector space.

In that case, the distance may not be attained even if $A$ is closed. Look here for a counterexample.
First Consider a finite dimensional vector space like $\mathbb R$. Take for $x$ the origin.

An example of a bounded subset for which distance is not attained below:


   $A = (1,2]$


If $A$ is compact, then the distance is always attained. For the proof consider a sequence $(x_n)$ such that $d(x_n ,A) \to d(x,A)$ and extract a converging sub-sequence.

If $A$ is closed, then the distance is also always attained. For the proof, consider a point $a \in A$. Then $\overline A = \{y \in A \colon d(x,y) \le d(x,a)\}$ is compact and you can use point above.

Second. Case of an infinite dimensional vector space.

In that case, the distance may not be attained even if $A$ is closed. Look here for a counterexample.