Continuity of $f^{-1}$ So I read this theorem: 

Suppose $f$ is a continuous $1-1$ mapping of a compact metric space $X$ onto a metric space $Y$. Then the inverse mapping $f^{-1}$ defined on $Y$ by $$ f^{-1}(f(x))=x \quad x\in X $$ is a continuous mapping of $Y$ onto $X$.

Can someone please explain why compactness of $X$ is necessary here? I mean why is it not possible for $f^{-1}$ to be continuous without $X$ being compact? 
 A: Let's just prove it, and will be clear where we'll use compactness. Let $F \subseteq X$ be closed. Let's prove that the inverse image $(f^{-1})^{-1}(F)$ of $F$ by $f^{-1}$ is closed. Since $F$ is closed and $X$ is compact, $F$ is also compact. Since $F$ is continuous, $f(F) = (f^{-1})^{-1}(F)$ is compact in $Y$. Since $Y$ is a metric space, it is Hausdorff, and in these spaces, every compact set is closed. As we wanted.
Essential facts:


*

*Direct image of a compact set by a continuous function is compact;

*A closed subset of a compact set is compact itself;

*Every compact subset of a Hausdorff space is closed.

A: Counterexample: $f: [0, 2\pi) \to \mathbb S^1$, $f(t) = e^{it}$ is continuous and bijective, but do not have a continuous inverse. 
To see why the inverse is not continuous, note that 
$$f([0, \pi) = \{ e^{it} | t\in [0, \pi)\}$$
is not open in $\mathbb S^1$. That is, for the open set $[0, \pi)$ in $[0, 2\pi)$, $f^{-1}([0, \pi))$ is not open in $\mathbb S^1$. Thus $f^{-1}$ is not continuous.
A: Let $X=\{0\}\cup (1,2]$.  let $Y=[1,2]$. Let $f(0)=1$. Let $f(x)=x$ for $x\in (1,2]$.Then $f$ is a continuous bijection but the inverse $g=f^{-1}$ is not continuous because $A=(1,2)$ is closed in $X$ but $g^{-1}A=f A=A$ is not closed in $Y$.The key point of the proof of the theorem is that if $X$ were a compact Hausdorff space then any closed $A\subset X$ is compact so its image under $f$ is compact,and therefore closed in $Y$ (because $Y$ is Hausdorff) .Note that we can replace "metric" with the more general "Hausdorff".
