$\mathbf{Question}:$Let $(X,d_1)$ and $(Y,d_2)$ be two metric spaces and $f,g: X \mapsto Y$ be two continuous functions. Then prove that $\{x \in X: f(x) =g(x)\}$ is closed in $X$.
Approach: We consider the function $h: X \mapsto \mathbb{R^+}\cup \{0\}$ defined by $h(x)=d_2(f(x),g(x))$
Lemma 1: $h(x)$ is continuous on $X$.
Proof: We have $d_2(f(x),g(x))+d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(c),g(c))\implies d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(c),g(c))-d_2(f(x),g(x))$.
Symmetry gives us $d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(x),g(x))-d_2(f(c),g(c))$
Now, for any $\epsilon>0$, $\exists$ $\delta>0$ such that $d_2(g(x),g(c))< \epsilon/2$ and $d_2(f(x),f(c))<\epsilon/2$ whenever $d_1(x,c)<\delta$.
Hence, we conclude $\forall \epsilon>0, \ \exists \delta>0$ such that $|h(x)-h(c)|<\epsilon$ whenever $d_1(x,c)<\delta$, which establishes the lemma.
Now, $h(x)=0$, iff $f(x)=g(x)$.
We know that $\{0\}$ is a closed set in $\mathbb{R^+}\cup \{0\}$ and that the inverse image set of a closed set under a continuous mapping is a closed set.
Hence $\{x \in X: h(x)=0\} \equiv \{x \in X: f(x)=g(x)\}$ is a closed set in $X$.
$\mathbf{Follow-up \ question}:$ If $A \subseteq X$ is dense in $X$ and $f(x)=g(x), \forall x \in A$, then $f=g$ on $X$.
Attempt: By the previous theorem, $D=\{x \in X: f(x)=g(x)\}$ is closed in $X$. Now, suppose, for some $k \in X \setminus A$, $f(k) \neq g(k)$. But, $A\subset D \implies A' \subset D'$ (derived set) $\implies k \in D'$ but $k \notin D$ which contradicts the fact that $D$ is closed.
Is this correct? Please verify.