Let $(X,d)$ be a compact metric space. Let $f: X \to X$ be such that $d(f(x),f(y)) = d(x,y)$ for all $x,y \in X$. Show that $f $ is onto (surjective). Let $(X,d)$ be a compact metric space. Let $f: X \to X$ be such that $d(f(x),f(y)) = d(x,y)$ for all $x,y \in X$. Show that $f $ is onto (surjective).
If $f$ is not onto then there exist a $p \in X$ such that there does not exist any $y \in X$ such that $f(y) =p$. Then there exist $x \in X$ such that $d(p,f(x)) = d(p,x)$.
I am finding difficulty to do the proof please help!!
Is the result true if $X$ is not compact??
 A: Suppose $f$ is not onto. Pick $x \in X \setminus f[X]$. Then let $\epsilon > 0$ be such that $\epsilon < d(x, f[X])$. $X$ can be covered by finitely many open sets of diameter $< \epsilon$, by compactness. Let $N$ be the smallest size of such a covering, and $\mathcal{U} = \{O_1,\ldots,O_N\}$ a witnessing cover. If $x \in O_i$, then $f[X]$ does not intersect $O_i$, so $f[X]$ is already covered by $\mathcal{U} \setminus \{O_i\}$, which has $N-1$ elements. Then $\{f^{-1}[O_j]: j \neq i \}$ covers $X$, consists of open sets, and the isometry property guarantees that all diameters are $< \epsilon$. This contradicts the minimality of $N$, contradiction.
A: you already got your 1st answer..for your 2nd question the result is not true if X is not compact...for an example define $f: \mathbb{N} -> \mathbb{N}$ s.t $f(n)=n+1$ is not surjective 
A: If $f$ is not onto, take a point $p$ not in the image of $f$. Using sequential compactness, show that there is an open ball $B_\epsilon(p)$ centered at $p$ which is not contained in $f(X)$. Next, show that it cannot be the case that $B(p,\epsilon) \cap f(X) = \emptyset$ for some $\epsilon > 0$. Suppose to the contrary that it does. Then consider the sequence $a_1 = p$, $a_{n+1} = f(a_n)$, $n\ge 1$. Show that by compactness, there are $m$ and $n$, $n > m$, such that $d(a_m,a_n) < \epsilon$. By the isometry property of $f$, $d(f^{n-m}(p), p) < \epsilon$, which contradicts $B_\epsilon(p)\cap f(X) = \emptyset$.
A: Consider a point $p\in X$, and define the sequence $(x_n)_n$ inductively by setting $x_0=p$ and $x_{n+1}=f(x_n)$. Since $X$ is compact there exists a convergent sub-sequence $(x_{n_k})_k$. In particular we have 
$$\lim_{k\to\infty}d(x_{n_{k+1}},x_{n_k})=0$$
That is
$$\lim_{k\to\infty}d(f^{n_{k+1}}(p),f^{n_{k}}(p))=0$$
Or, using the assumption
$$\lim_{k\to\infty}d(f^{n_{k+1}-n_k}(p),p)=0$$
Since $n_{k+1}-n_k\ge1$ the above result is equivalent to
$$\lim_{k\to\infty}d(f(y_k),p)=0\tag{1}$$
where $y_k=f^{n_{k+1}-n_k-1}(p)=x_{n_{k+1}-n_k-1}$. Now we can extract from $(y_k)_k$ a convergent sub-sequence $(y_{k_m})_m$ that converges to some $q\in X$, and $(1)$ then implies, (due to the continuity of $x\mapsto d(f(x),p)$), that
$$\lim_{m\to\infty}d(f(y_{k_m}),p)=d(f(q),p)=0$$
So $p=f(q)\in f(X)$. This proves that $f$ is onto.
Remark. Note that we only need that $d(f(x),f(y))\ge d(x,y)$ for every $ x,y$  in $X$.
