Every topological space comes with a natural equivalence relation: iff there is a connected subset such that . The equivalence classes are connected components of .
How do we know if is connected? We must check that there is no way to write it as where and are nonempty, open in , and disjoint. This must be done for every candidate for (actually, we can save time by considering only closed ). So, we run in a nested loop:
for C in [closed sets]: if either x or y are not in C, continue with next C for U in [open sets]: for V in [open sets]: if U and V disconnect C, continue with next C return('equivalent') return('not equivalent')
Perhaps this can be optimized, but it looks like a lot of work to me.
Here is what could be done instead.
for U in [open sets]: if X\U is also in [open sets], add U to [clopen sets] for A in [clopen sets] if x is in A and y is not in A, return('not equivalent') return('equivalent')
There are no nested loops here: the algorithm is linear in the size of the topology. Also, the first loop should run only once for the space, creating a catalog of closed-open subsets in .
Let’s compare these two notions of equivalence, denoting the first one and the second . If , then there exists a closed-open set such that and . Hence, any set containing is disconnected by and . We conclude that . To summarize: .
The converse is not true in general. Here is an example adapted from General Topology by Willard (and made in Sage)
The set lives in the plane and contains of infinitely many concentric squares that converge to the square with endpoints . The vertical sides of the unit square are included in , but the horizontal ones are not. So, the connected components of are: left vertical line (in red), right vertical line (in red), and each of the blue squares. In particular, .
However, . Indeed, let be a closed-open set that contains . Since is open, it intersects (hence, contains) infinitely many blue squares. The union of these squares has as a limit point, and since is closed, .
The equivalence classes of are called quasicomponents. The quasicomponent of is the intersection of all closed-open sets containing . Quasicomponents are closed but not necessarily open; in this they are similar to connected components. Here is another similarity: is connected if and only if it has one quasicomponent.
In compact Hausdorff spaces quasicomponents coincide with components (this is not trivial). If we compactify the example above by adding horizontal sides of the unit square, the points and will be in the same component. Perhaps quasicomponents see the space as it should be, not as it is.