Let $f: X \rightarrow Y$ be a function. The graph of $f$ is the subset of $X \times Y$ given by $G=\{(x, f(x)) \mid x \in X\}$.
(a) In Exercise 4.10 we established that if $f: X \rightarrow Y$ is continuous and $Y$ is Hausdorff, then $G$ is a closed subset of $X \times Y$. Here we prove a converse. Assume that $X$ and $Y$ are topological spaces and $Y$ is compact. Show that if $G$ is a closed subset of $X \times Y$, then $f$ is continuous. (Hint: Given $U$ open in $Y$, and $x \in f^{-1}(U)$, show that the slice $\{x\} \times Y$ is contained in the open set $(X-G) \cup(X \times U)$, and then apply the Tube Lemma.)
(b) Show that the result from part (a) does not hold if we drop the assumption that $Y$ is compact. That is, find an example of a noncompact space $Y$ and a function $f: X \rightarrow Y$ such that the graph of $f$ is a closed subset of $X \times Y$, but $f$ is not continuous.