Prove that if $A$ is compact and $B$ is closed and $A\cap B = \emptyset$ then $\text{dist}(A,B) > 0$ Let $X$ be a metric space. For nonempty subsets $A,B\subseteq X$. Define $\text{dist}(A,B) := \inf\{d(x,y) : x\in A, y\in B\}$
a) Prove that if $A$ is compact and $B$ is closed and $A\cap B = \emptyset$ then $\text{dist}(A,B) > 0$
b) Suppose that $X = \mathbb{R}^n$, with the standard metric. Under the same assumptions of (a), prove that $\exists x_0\in A$ and $\exists y_0\in B$ such that dist$(A,B) = ||x_0 - y_0||$.
For a), it seems to me that the crucial point is that $A\cap B = \emptyset$. I can immediately see how this would imply that $\text{dist}(A,B) > 0$. However, I do not understand why it's necessary for $A$ to be compact, and $B$ to be closed. Could you explain why those conditions are necessary? 
 A: a) You need $B$ to be closed so that for any $x\notin B, d(x,B) > 0$. You need $A$ to be compact, so that you can restrict your attention to only finitely many $x$'s as follows :
For every $x \in A, \epsilon_x := d(x,B) > 0$, so there is a $\delta_x > 0$ such that
$$
d(x,y) < \delta_x \Rightarrow d(y,B) > \epsilon_x/2
$$
Now the balls $B(x,\delta_x)$ cover $A$. Take a finite subcover $\{B(x_i,\delta_{x_i})\}$, and choose $\epsilon$ to be the minimum of the corresponding $\epsilon_{x_i}$'s. Now check that
$$
d(A,B) > \epsilon/2 > 0
$$
b) Note that
$$
x \mapsto d(x,B)
$$
is a continuous function on $A$, and so there is $x_0 \in A$, at which the infimum is attained. ie.
$$
d(x_0, B) = \inf\{\|x-y\| : y \in B\} = \inf\{\|x_0 - y\| : y \in B\}
$$
Now there is a sequence $(y_n) \in B$ such that
$$
d(x_0,B) = \lim \|x_0 - y_n\|
$$
Check that $(y_n)$ must be a bouned sequence, and so it must have a convergent subsequence (since you are in $\mathbb{R}^n$). This subsequence must converge to a point $y_0 \in B$. Then
$$
d(A,B) = d(x_0,B) = \|x_0 - y_0\|
$$
A: This does not answer your questions but it's another proof of a).
If $\text{dist}(A,B)=0$, then by definition of this distance there are two sequences $(a_n)$ and $(b_n)$ (with terms in $A$ and $B$ respectively), such that $\lim d(a_n,b_n)=0$.
Since $A$ is compact, you know that there exists a convergent subsequence $(a_{n_k})$ of $(a_n)$ in $A$. 
Let $a\in A$ be its limit. $(d(a_{n_k},b_{n_k}))_{k\geqslant 0}$ is a subsequence of the convergent sequence $(d(a_n,b_n))$, so it has the same limit.
Since : $d(a,b_{n_k})\leqslant d(a,a_{n_k})+d(a_{n_k},b_{n_k})$ for all $k$, you find that $\lim b_{n_k}=a$
But $(b_{n_k})$ is a sequence with terms in the closed set $B$, so its limit $a$ is an element of $B$. 
Remember that we also have $a\in A$. This proves that $A\cap B\neq\emptyset$.
Consequently, if $A\cap B=\emptyset$ with $A$ compact and $B$ closed, then $d(A,B)>0$.
A: For an example of why $B$ is needed to be closed consider in $\mathbb R$:
$$
A = \{0\}, B=(0,1]
$$
clearly $A\cap B=\emptyset$ but $d(A,B)=0$.
The proof of a) and b) is based on the Weierstrass theorem:
every continuous function on a compact set has a minimum. 
Take the function
$$
  f(x) = \inf \{d(x,y)\colon y \in B\}
$$
this is a continuous function hence has a minimum on $A$. So for some $a\in A$ one has 
$$
 d(A,B) = f(a) = d(a,B).
$$
Now notice that $a\not \in B$ and hence $d(a,B) > 0$.
To prove (b) notice that by intersecting $B$ with a bounded closed set you can restrict yourself to the case when also $B$ is compact.
