Connectedness and continuity

The following is a theorem from my book, but i don't think that i follow the proof given:

Theorem:

Every continuous image of a connected metric space is connected.

Proof:

Suppose X and Y are metric spaces and g : X -> Y is continuous.

Suppose g(X) is not a connected space.

Then there exists a continuous function f from g(X) onto {0,1}. (i don't think i follow this)

This yields (fog)(X) = f(g(X)) = {0,1}, and since fog is continuous,

X does not satisfy the continuity criterion for connectedness and therefore is not connected. (I don't understand how this happens ? why is it not satisfying the continuity criterion ?)

Any help will be appreciated.

Re: Connectedness and continuity

Suppose $\displaystyle g(X)$ is not connected. Then, $\displaystyle g(X) = U \cup V$ where $\displaystyle U\cap V = \emptyset$, and both $\displaystyle U$ and $\displaystyle V$ are open and nonempty. Define $\displaystyle f:g(X) \to \{0,1\}$ by $\displaystyle f(x) = \begin{cases}0 & \text{if }x \in U \\ 1 & \text{if }x \in V\end{cases}$. Now, $\displaystyle f$ is continuous if the preimage of open sets are open. So, let's look at the open sets of $\displaystyle \{0,1\}$. They are $\displaystyle \{\emptyset, \{0\}, \{1\}, \{0,1\}\}$. The preimage of the empty set is the empty set, which is open in $\displaystyle g(X)$. The preimage of $\displaystyle \{0\}$ is $\displaystyle U$, which is open in $\displaystyle g(X)$. The preimage of $\displaystyle \{1\}$ is $\displaystyle V$, which is open in $\displaystyle g(X)$, and the preimage of $\displaystyle \{0,1\}$ is $\displaystyle g(X)$, which is obviously open in $\displaystyle g(X)$. So, $\displaystyle f$ is continuous. You have already seen the proof that the composition of continuous functions is continuous. So, $\displaystyle (f\circ g):X \to \{0,1\}$ must be a continuous function. Hence, $\displaystyle (f\circ g)^{-1}(\{0\}), (f\circ g)^{-1}(\{1\})$ must be disjoint, nonempty, open subsets of $\displaystyle X$ whose union is $\displaystyle X$. This implies $\displaystyle X$ is not connected.

Edit: Disjoint comes from the definition of a function. If they were not disjoint, then let $\displaystyle x \in (f\circ g)^{-1}(\{0\}) \cap (f\circ g)^{-1}(\{1\})$. Then $\displaystyle (f\circ g)(x) = 0$ and $\displaystyle (f\circ g)(x) = 1$ implying $\displaystyle (f\circ g)$ is not even a function.

Nonempty comes from the fact that $\displaystyle U,V$ are nonempty subsets of $\displaystyle g(X)$, so $\displaystyle g^{-1}(U)$ and $\displaystyle g^{-1}(V)$ must be nonempty subsets of $\displaystyle X$.

Open comes from continuity of $\displaystyle (f\circ g)$.

The union $\displaystyle (f\circ g)^{-1}(\{0\}) \cup (f\circ g)^{-1}(\{1\}) = (f\circ g)^{-1}(\{0,1\}) = X$ because the preimage of the entire image of a function is the entire domain.