I have the following problem: Let $X$ be a compact metric space, $Y$ any metric space, and suppose $f: X \rightarrow Y$ is continuous. Let $ G \subset X \times Y, G = \{(x,f(x)) : x \in X\}$. If $G$ is compact, prove it. Otherwise show why $G$ is not compact.
This is what I have so far: We know that the continuous image of a compact metric space is compact, so therefore $ f(X) \in Y$ is compact. Also note that because of the way $G$ is defined, $ G \subset X \times f(X)$. Given a sequence $\{(x_n,f(x_n))\} \in G$, by the compactness of $X$ and $f(X)$, we know that any sequences $\{x_n\}$ and $\{f(x_n)\}$ will have convergent subsequences, so therefore $\{(x_n,f(x_n))\}$ will have a convergent subsequence.
Does this logic actually work? The main thing I'm iffy on is if the sequence would be defined as $\{(x_n,f(x_n))\}$, or if it would be something like $\{(x_n,f(x_k))\}$ instead. Also, I was initially planning on showing that $G$ was closed, because I know that the closed subset of a compact set is compact, but this method seemed slightly less cumbersome.
If you take that approach, you need to work a little harder to get the convergent sequence. First, $\langle x_n:n\in\Bbb N\rangle$ is a sequence in the compact space $X$, so it has a convergent subsequence $\langle x_{n_k}:k\in\Bbb N\rangle$. Then the sequence $\langle f(x_{n_k}):k\in\Bbb N\rangle$ in the compact space $f[X]$ has a convergent subsequence $\langle f(x_{n_{k_\ell}}):\ell\in\Bbb N\rangle$, so the sequence $\big\langle\langle x_{n_{k_\ell}},f(x_{n_{k_\ell}})\rangle:\ell\in\Bbb N\big\rangle$ converges in $X\times f[X]$. However, you’re not done at this point: you still have to show that the limit is in $G$. That’s where you’ll need the continuity of $f$, which you might note that you haven’t used yet.
Your initial idea is a bit easier, and the one that I would have used. It’s a standard result (and not hard to prove) that if $f:X\to Y$ is continuous, and $Y$ is Hausdorff, then the graph of $f$ is closed in $X\times Y$. If you’ve not seen the result and get stuck proving it, you’ll find a proof here.