Example of metric space that has more than two sets that are both closed and open?

Metric spaces that aren't connected can give such examples. For example, $(0, 1) \cup (2, 3)$ is a metric space (equipped with the usual Euclidean metric) and both $(0, 1)$ and $(2, 3)$ are open and closed in the topology induced by the metric.

Of course, as usual $\emptyset$ and the entire space are two more examples, for a total of four.


Let $X$ be any set. For any two elements $x, y\in X$ let $d(x, y)=\begin{cases} 1 & \text{if } x\neq y\\ 0 & \text{if }x=y\end{cases}$.

This is called the discrete metric. In the metric space $(X, d)$, $\textit{every}$ set is both open and closed.


You already know several such subspaces of $\Bbb R$ with the usual metric.

  1. $\Bbb Z$: Clearly $\left(n-\frac12,n+\frac12\right)\cap\Bbb Z=\{n\}$ for any $n\in\Bbb Z$, so $\{n\}$ is an open subset of $\Bbb Z$ for each $n\in\Bbb Z$. Since $A=\bigcup_{n\in A}\{n\}$ for any $A\subseteq\Bbb Z$, each subset of $\Bbb Z$ is open in the relative topology of $\Bbb Z$. This immediately implies that each $A\subseteq\Bbb Z$ is closed in $\Bbb Z$: if $U=\Bbb Z\setminus A$, then $U$ is open, and therefore $A=\Bbb Z\setminus U$ is closed. That is, every subset of $\Bbb Z$ is clopen (open and closed) in the $\Bbb Z$ with the usual metric.

  2. $\Bbb Q$: Let $q\in\Bbb Q$, and let $\alpha$ be any positive irrational; then $B(q,\alpha)=\{p\in\Bbb Q:|p-q|<\alpha\}$ is a clopen subset of $\Bbb Q$ with the usual metric. $B(q,\alpha)$ is certainly open in $\Bbb Q$. To see that it’s also closed, we’ll show that $\Bbb Q\setminus B(q,\alpha)$ is open. Suppose that $p\in\Bbb Q\setminus B(q,\alpha)$; then $p\ge q+\alpha$ or $p\le q-\alpha$. Suppose that $p\ge q+\alpha$. Since $p$ is rational, $p\ne q+\alpha$, and therefore $p>q+\alpha$. Let $\beta=(q+\alpha)-p>0$; then $$q-\alpha<q<q+\alpha=p-\beta<p<p+\beta\;,$$ so $B(p,\beta)\cap B(q,\alpha)=\varnothing$, where $B(p,\beta)=\{r\in\Bbb Q:|r-p|<\beta\}$. In other words, $B(p,\beta)$ is an open ball about $p$ such that $B(p,\beta)\subseteq\Bbb Q\setminus B(q,\alpha)$. If $p\le q-\alpha$, take $\beta=(q-\alpha)-p$ and argue similarly to show that $B(p,\beta)\subseteq\Bbb Q\setminus B(q,\alpha)$, and conclude that $\Bbb Q\setminus B(q,\alpha)$ is open and hence that $B(q,\alpha)$ is closed and therefore clopen. The open balls with irrational radius are not the only clopen subsets of $\Bbb Q$, but they’re easy to describe, and they clearly show that $\Bbb Q$ with the usual metric has infinitely many clopen subsets.

  3. $\Bbb R\setminus\Bbb Q$: If $x$ is irrational and $r>0$ is irrational, then $B(x,r)=\{y\in\Bbb R\setminus\Bbb Q:|y-x|<r\}$ is clopen in $\Bbb R\setminus\Bbb Q$ with the usual metric; the proof is very similar to the previous one.

  4. The middle-thirds Cantor set $C$: If $\alpha,\beta\in\Bbb R\setminus C$, and $\alpha<\beta$, then $U=(\alpha,\beta)\cap C$ is a clopen subset of $C$ with the usual Euclidean metric. Clearly $U$ is open in $C$, since it’s the intersection with $C$ of an open set in $\Bbb R$. On the other hand, $\alpha,\beta\notin C$, so $U=[\alpha,\beta]\cap C$; $[\alpha,\beta]$ is a closed set in $\Bbb R$, so its intersection with $C$ is a closed set in $C$, and $U$ is therefore closed as well as open.