If $X$ is compact and $Y$ is closed. Show that there exists $x_0 \in X$, and $y_0 \in Y$ such that $|x_0-y_0| \leq |x-y|$ for all $x \in X$, $y \in Y$ Let $X$, $Y$ be subsets of $\Bbb{R}$, with $X$ compact and $Y$ closed. Show that there exists $x_0 \in X$, and $y_0 \in Y$ such that $|x_0-y_0| \leq |x-y|$ for all $x \in X$, $y \in Y$.
If $Z = \{|x-y| : x\in X, y\in Y\}$, then $0$ is a lower bound of $Z$ so there exists $\alpha = \inf Z$. So there is a sequence of elements in $Z$ such that it converges to $\alpha$, this means that there are sequences $(x_n)$ in $X$ and $(y_n)$ in $Y$ such that $\lim |x_n-y_n| = \alpha$. Now, because $X$ is compact, then there is a convergent subsequence of $(x_n)$, $(x_{n_k})$ and it could converge to an $x_0$ in $X$ (because $X$ is closed). But I am stuck here, I think what I need is $(x_n)$ to be convergent but that does not necessarily happen here.
 A: A slightly different solution which avoids sequences altogether:
Define $d(\cdot, Y) : X \to \mathbb{R}$ as $d(x,Y) = \inf_{y \in Y} |x-y|$ for all $x \in X$.
$d(\cdot, Y)$ is continuous on $X$. Indeed, for $x, x' \in X$ and $y \in Y$ we have
$$|x-y| \le |x-x'| + |x'-y|$$
$$|x'-y| \le |x-x'| + |x-y|$$
Taking the infimum over $y \in Y$ yields
$$d(x,Y) \le |x-x'| + d(x', Y)$$
$$d(x',Y) \le |x-x'| + d(x, Y)$$
so $$|d(x',Y) - d(x,Y)| \le |x-x'|$$
so we can conclude that $d(\cdot, Y)$ is continuous on $X$. Since $X$ is compact, there exists $x_0 \in X$ such that $d(x_0, Y) \le d(x,Y)$ for all $x \in X$.
There exists $r > 0$ such that $$d(x_0, Y) = d(x_0, Y \cap B(x_0, r)) = \inf_{y \in Y \cap B(x_0, r)} |x_0 - y|$$ $Y \cap B(x_0, r)$ is now a compact set and the function $y \mapsto |x_0 - y| $ is continuous on $Y \cap B(x_0, r)$ so there exists $y_0 \in Y \cap B(x_0, r)$ such that $|x_0 - y_0| \le |x_0 - y|$ for all $y \in Y \cap B(x_0, r)$.
In particular, $|x_0 - y_0| \le d(x_0, Y \cap B(x_0, r)) = d(x_0, Y)$ so we in fact conclude $|x_0 - y_0| = d(x_0, Y)$.
Therefore, $$|x_0 - y_0| \le |x-y|, \forall x\in X, y \in Y$$
A: $|y_{n_k} - x_{n_k}| \to \alpha$ and $x_{n_k} \to x_0$ as $k \to \infty$, so the possible limit points of $(y_{n_k})_k$ are $x_0 \pm \alpha$.  One of them must contain infinitely many points of the sequence $(y_{n_k})_k$ (by "Pigeon-Hole Principle"), and name this point $y_0 \in Y$.  ($Y$ is closed.)
We claim that $x_0 \in X$ and $y_0 \in Y$ minimises $|x-y|$: suppose there exists $x_1 \in X$ and $y_1 \in Y$ such that $|x_1-y_1| < |x_0-y_0|$, then $|x_1 - y_1| \in Z$, so that $\alpha \le |x_1 - y_1|$.  However, $|x_0 - y_0| = \alpha$ by construction, so $|x_0 - y_0| \le |x_1 - y_1|$, which contradicts the assumption on $x_1$ and $y_1$.
A: Since $X$ is compact, the sequence $(x_n)_{n\in \Bbb N}$ has a convergent sub-sequence $(x_{f(n)})_{n\in \Bbb N}$ for some strictly increasing $f:\Bbb N\to \Bbb N.$ Let $x'_n=x_{f(n)}.$ Let $x_0=\lim_{n\to \infty}x'_n.$ And let $y'_n=y_{f(n)}.$
Now $x_0 \in X$ because $X$ is closed because $X$ is compact.
The sequence $(|x'_n-y'_n|)_{n\in \Bbb N}$ is a sub-sequence of $(|x_n-y_n|)_{n\in \Bbb N}$ so it converges to the same limit $\alpha.$
The set $S=\{|x'_n-y'_n|:n\in \Bbb N\}$ is bounded because $(|x'_n-y'_n|)_{n\in \Bbb N}$ is a convergent sequence. Let $M_S=\sup S.$ The set $X$ is bounded because $X$ is compact. Let  $M_A=\sup \{|x|:x\in X\}.$ Therefore the set $T= \{y'_n:n\in \Bbb N\}$ is bounded because $$\forall n\in \Bbb N\;(  |y'_n|=|(y'_n-x'_n)+x'_n|\leq |y'_n-x'_n|+|x'_n|\leq M_S+M_X).$$
Since $T$ is bounded there is a strictly increasing $g:\Bbb N\to \Bbb N$ such that $(y'_{g(n)})_{n\in \Bbb N}$ converges. Let $y''_n=y'_{g(n)}.$ Let $y_0=\lim_{n\to \infty}y''_n. $ And let $x''_n=x'_{g(n)}.$
Now $y_0\in Y$ because $Y$ is closed.
The sequence  $(|x''_n-y''_n|)_{n\in \Bbb N}$ is a sub-sequence of $(|x'_n-y'_n|)_{n\in \Bbb N}$  so it converges to the same limit $\alpha.$ And $(x''_n)_{n\in \Bbb n}$ is a sub-sequence of $(x'_n)_{n\in \Bbb N}$ so it converges to the same limit $x_0.$
Now $x_0=\lim_{n\to \infty}x''_n\in X$ and $ y_0=\lim_{n\to \infty}y''_n\in Y.$ 
And $|x_0-y_0|=\lim_{n\to \infty}|x''_n-y''_n|=\alpha.$
REMARKS. (1) It should say in your hypothesis that $X, Y$ are not empty. (2). The Q can be answered quickly and easily using some general results about metric spaces but I dk  how much of that is familiar to you.
