TITLE: $X$ is Hausdorff if and only if the diagonal of $X\times X$ is closed
QUESTION [88 upvotes]: Let $X$ be a topological space. The diagonal of $X \times X$ is the subset $$D = \{(x,x)\in X\times X\mid x \in X\}.$$
  Show that $X$ is Hausdorff if and only if $D$ is closed in $X \times X$.

First, I tried to show that $X \times X \setminus D$ is open using the fact that $X \times X$ is Hausdorff (because $X$ is Hausdorff), but I couldn't find an open set that contains a point outside $D$ and is disjoint to it...

REPLY [18 votes]: There is a related problem:

Let $f,g:A\to B$ be two continuous maps, $B$ is a Hausdorff space and $A$ is an arbitrary space. Then the set $C(f,g)=\{x\in A| f(x)=g(x)\}$ is the coincidence set of $f$ and $g$. Prove $C(f,g)$ is closed.

to proof this, for every point $x_0$ not in $C(f,g)$,  $y_f=f(x_0)$ and $y_g=g(x_0)$ are two distinguished point in $B$, because $B$ is Hausdorff, you get two disjoint open neighborhood $U(y_f)$ and $U(y_g)$, because $f,g$ is continuous, $O=f^{-1}(U(y_f))\cap g^{-1}(U(y_g))$ is open in $A$. You can verify that $O$ is a neighborhood of $x_0$ disjoint of $C(f,g)$, for if $c\in C(f,g)$ and $c\in O$, then $c\in f^{-1}(U(y_f))$ and $c\in g^{-1}(U(y_g))$, this is equal to say $f(c)=g(c)$ is in both $U(y_f)$ and $U(y_g)$, which is impossible because the two neighborhood is disjoint.
Set $A=X\times X$, $B=X$, $f=\pi_1$, $g=\pi_2$ be the projection map, you get the desired result.
Hope this can illustrate the problem you ask.