Given a function $f: X \to Y$, if $X$ is compact, prove the graph $g = (x, f(x))$ is compact in $X\times Y$ Given a function $f: X \to Y$, and graph of $f, g = \{(x, f(x)): x\in X\}$ in metric space $X\times Y$
(a) Suppose that $X$ is compact. Prove that $f$ is continuous if and only if $g$ is a compact subset of $X\times Y$.
I know that if $f$ is continuous, then $f(X)$ has to be compact, but $g$ is not a union of the set of $x$ and $f(x)$ so I'm not sure how to prove that $g$ is compact. 
(b) If f is continuous, prove g is a closed subset of XxY. 
If f is continuous I know it maps closed subsets to closed subsets, so is that why g is closed?
 A: Initial observation: A function $h: X \rightarrow Y \times Z$ is continuous (in the product topology) iff its coordinates are continuous. 

Note that the graph is the image of the function $Id \times f: X \rightarrow X \times Y $, which is continuous, by the initial observation. Hence, the graph is compact.
Conversely, if the graph is compact, note that $\pi_1|_{g}:X \times Y \rightarrow X$ is a continuous, bijective function. Since $X$ is a metric space, it is Hausdorff. Therefore, $\pi_1|_g$ is a homeomorphism. But its inverse is precisely $Id \times f$. By the initial observation, $f$ is continuous.
A: By Tychonoff's Theorem $X\times f(X)$ is compact. Every closed subspace of a compact space is compact. So we will show $g$ is closed in $X\times f(X)$.
Actually this is obvious. Take $(x,y)\in\overline{g}$, then there exists a sequence $(x_n,f(x_n))\in g$ such that $(x_n,f(x_n))\to (x,y)$. Then $x_n\to x$ and by continuity $f(x_n)\to f(x)=y$. So $(x,y)=(x,f(x))\in g$.
A: Try the following approach:
$g$ is compact if every sequence $(z_n) = (x_n, f(x_n))$ on $g$ has a convergent subsequence  $(z_{n_k})$  that converges in $g$. 
Pick an arbitrary sequence $(z_n) = (x_n, f(x_n))$ on $g$. We know that $X$ is compact, therefore given $(x_n)$, we know there exists subsequence $(x_{n_k})$ on $X$ that converges in $X$. 
We know that the image of a convergent sequence under continuous function is also convergent, hence  $(f(x_{n_k}))$ on $f(X)$ converges in $f(X)$
Thus the sequence $(z_{n_k}) = (x_{n_k}, f(x_{n_k}))$ is a convergent subsequence of $(z_{n}) = (x_{n}, f(x_{n})) $ that converges in $g$. Since  $(z_n)$ is arbitrary, therefore $g$ is compact. 
