Tutorials › Real Analysis › Countable Sets

Sets and Functions · Tutorial 78 of 1000

Countable Sets

Learn how to recognize countable sets through injections into the natural numbers and construct enumerations of familiar infinite sets.

Beginner 10 min read

What You'll Learn

  • Distinguish countable sets from countably infinite sets
  • Prove that a set is countable exactly when it injects into the natural numbers
  • Enumerate the integers and pairs of natural numbers
  • Use an injection to prove that the rational numbers are countable
  • Recognize why an infinite subset of the natural numbers can be listed

From Finite Cardinality to Countable Sets

The previous tutorial measured finite sets by matching them with standard finite sets \([n]\). We now extend the idea of comparing sets by bijections to infinite sets. The basic infinite reference set will be the natural numbers \(\mathbb N=\{1,2,3,\ldots\}\). A set matched bijectively with \(\mathbb N\) can be listed in a sequence: its first element, its second element, and so on.

There is a small convention to settle. Some authors use “countable” to mean “countably infinite,” while others include finite sets as countable. Here we use the inclusive convention. This makes finite sets part of the same general category, while the phrase “countably infinite” identifies sets that can be matched bijectively with all of \(\mathbb N\).

Definition (Countable Set). A set \(A\) is countably infinite if there is a bijection from \(\mathbb N\) to \(A\). A set \(A\) is countable if it is finite or countably infinite.

A bijection \(f:\mathbb N\to A\) is an enumeration of \(A\): the terms \(f(1),f(2),f(3),\ldots\) are all distinct and include every element of \(A\). In contrast, an injection into \(\mathbb N\) only assigns distinct natural-number labels to the elements of \(A\). It need not use every natural number. We will show that, for countability, having such labels is enough.

An Injection Criterion for Countability

To establish the criterion, first consider a subset \(S\) of \(\mathbb N\). If \(S\) is infinite, its elements can be listed in increasing order by repeatedly choosing the least element not yet chosen. The least-element property of the natural numbers ensures each choice is possible. The resulting list must include every element of \(S\): if \(m\in S\) were never chosen, then every chosen element would be less than \(m\), even though there are only finitely many natural numbers less than \(m\).

Theorem (An Infinite Subset of \(\mathbb N\) Is Countably Infinite). If \(S\subseteq\mathbb N\) is infinite, then there is a bijection from \(\mathbb N\) to \(S\).

Proof. Define \(s_1\) to be the least element of \(S\). Once \(s_1,\ldots,s_k\) have been chosen, define \(s_{k+1}\) to be the least element of \(S\setminus\{s_1,\ldots,s_k\}\). This set is nonempty: if it were empty, \(S\) would equal the finite set \(\{s_1,\ldots,s_k\}\), contradicting that \(S\) is infinite. Thus the construction continues for every positive integer \(k\).

The terms are distinct, since each new term is chosen outside the set of earlier terms. They are strictly increasing, since \(s_{k+1}\) is the least element remaining after \(s_1,\ldots,s_k\) have been selected. Define \(e:\mathbb N\to S\) by \(e(k)=s_k\). Distinct terms show that \(e\) is injective.

It remains to show that \(e\) is surjective. Let \(m\in S\). Suppose, for contradiction, that \(m\) is never selected. At every stage \(k\), \(m\) remains among the available elements. Since \(s_k\) is the least available element, \(s_k\leq m\); and because \(m\) is never selected, \(s_k\ne m\), so \(s_k<m\). In particular, all the terms \(s_1,\ldots,s_m\) would be distinct natural numbers less than \(m\). There are only \(m-1\) such numbers, which is impossible. Therefore \(m=s_k\) for some \(k\), and \(e\) is surjective. Hence \(e\) is a bijection from \(\mathbb N\) to \(S\). \(\square\)

Theorem (Injection Criterion for Countability). A set \(A\) is countable if and only if there is an injection from \(A\) into \(\mathbb N\).

Proof. First suppose \(A\) is countable. If \(A\) is finite, its distinct listing gives an injection into \(\mathbb N\): send the first listed element to \(1\), the second to \(2\), and so on. If \(A\) is countably infinite, a bijection from \(\mathbb N\) to \(A\) has an inverse, which is an injection from \(A\) into \(\mathbb N\). Thus either way there is such an injection.

Conversely, suppose \(f:A\to\mathbb N\) is injective, and let \(S=f[A]\), the range of \(f\). Then \(S\subseteq\mathbb N\). The function \(f\), regarded as a map from \(A\) onto \(S\), is a bijection: it is injective by assumption and surjective onto its range by definition. Therefore \(f^{-1}:S\to A\) is also a bijection. If \(S\) is finite, a distinct listing \(s_1,\ldots,s_k\) of \(S\) pulls back through \(f^{-1}\) to the distinct listing \(f^{-1}(s_1),\ldots,f^{-1}(s_k)\) of \(A\), which includes every element of \(A\) because \(f^{-1}\) is onto \(A\). So \(A\) is finite. If \(S\) is infinite, the theorem just proved gives a bijection \(e:\mathbb N\to S\), and \(f^{-1}\circ e:\mathbb N\to A\) is a bijection. In this case \(A\) is countably infinite. Both cases show that \(A\) is countable. \(\square\)

This theorem is useful because it replaces the task of constructing a complete listing with the often simpler task of assigning distinct natural-number labels. For an infinite set, an injection into \(\mathbb N\) may leave some labels unused; the proof shows that this still gives a bijection with \(\mathbb N\).

Worked Example: The Even Natural Numbers

Let \(E=\{2,4,6,\ldots\}\). Define \(f:E\to\mathbb N\) by \(f(2k)=k\) for \(k\in\mathbb N\). Every element of \(E\) has the form \(2k\) for exactly one \(k\in\mathbb N\), so \(f\) is a bijection. Its inverse sends \(k\) to \(2k\). Thus \(E\) is countably infinite, with enumeration \(2,4,6,8,\ldots\).

The inclusion \(E\subseteq\mathbb N\) alone would also give an injection, namely \(n\mapsto n\) for \(n\in E\). The explicit bijection above gives more: it shows directly how the elements of \(E\) correspond to every natural number.

Worked Example: A Finite Set Is Countable

Let \(A=\{\heartsuit,\diamondsuit,\clubsuit\}\), where the three symbols represent distinct objects. The assignment \(\heartsuit\mapsto1\), \(\diamondsuit\mapsto2\), and \(\clubsuit\mapsto3\) defines an injection from \(A\) into \(\mathbb N\). By the injection criterion, \(A\) is countable. It is not countably infinite: it is finite, and a finite set cannot be in bijection with \(\mathbb N\), since \(\mathbb N\) has no finite listing: for any finite list \(n_1,\ldots,n_k\) of natural numbers, the number \(\max\{n_1,\ldots,n_k\}+1\) is missing from it.

Listing Integers and Pairs

The integers \(\mathbb Z\) are not a subset of the positive natural numbers, but they can still be assigned distinct natural-number labels. One possible ordering begins \(0,1,-1,2,-2,3,-3,\ldots\). The alternating signs prevent the negative integers from being left out.

Worked Example: An Enumeration of the Integers

Define \(g:\mathbb N\to\mathbb Z\) by \(g(1)=0\), and for \(k\geq1\) set \(g(2k)=k\) and \(g(2k+1)=-k\). The first values are \(g(1)=0\), \(g(2)=1\), \(g(3)=-1\), \(g(4)=2\), and \(g(5)=-2\), in agreement with the displayed ordering.

The values are distinct: \(0\) occurs only at input \(1\); positive integers occur only at even inputs; and negative integers occur only at odd inputs greater than \(1\). Every integer is a value, since \(0=g(1)\), each positive integer \(k\) equals \(g(2k)\), and each negative integer \(-k\), for \(k\geq1\), equals \(g(2k+1)\). Thus \(g\) is a bijection, and \(\mathbb Z\) is countably infinite.

A less immediate example is the set \(\mathbb N\times\mathbb N\) of ordered pairs of natural numbers. It may seem that an infinite grid has too many entries to list. The key is to list pairs along diagonals of constant sum. Each diagonal contains only finitely many pairs.

Theorem (The Set of Pairs of Natural Numbers Is Countable). There is a bijection from \(\mathbb N\) to \(\mathbb N\times\mathbb N\).

Proof. For each integer \(r\geq2\), list the pairs whose coordinates sum to \(r\), in this order: \((1,r-1),(2,r-2),\ldots,(r-1,1)\). Concatenate these finite lists in order of increasing \(r\). The beginning of the resulting list is \((1,1),(1,2),(2,1),(1,3),(2,2),(3,1),\ldots\).

Every listed pair occurs exactly once. Indeed, a pair \((a,b)\) belongs to the list for the unique sum \(r=a+b\), and within that list it occurs at the unique position determined by its first coordinate \(a\). Thus no pair is repeated. Conversely, every \((a,b)\in\mathbb N\times\mathbb N\) has a sum \(r=a+b\geq2\), so it appears on that diagonal. Hence the concatenated list contains every pair exactly once. Assigning the first pair to \(1\), the second to \(2\), and so forth gives a bijection from \(\mathbb N\) to \(\mathbb N\times\mathbb N\). \(\square\)

The diagonal method works because each diagonal is finite, and the diagonals can be arranged in a sequence. Merely arranging entries row by row would not work: after finishing the first row one would never reach the second, because each row has infinitely many entries. The diagonal ordering makes progress through both coordinates.

The Rational Numbers Are Countable

The rational numbers \(\mathbb Q\) can be represented by fractions, but many fractions represent the same rational number: for example, \(1/2=2/4\). To use pairs as labels without duplication, represent each rational number in its reduced form \(p/r\), where \(p\in\mathbb Z\), \(r\in\mathbb N\), and \(p\) and \(r\) have no common factor greater than \(1\). This representation is unique when the denominator is required to be positive.

Worked Example: Labeling the Rational Numbers

First encode each integer as a natural number using \(c:\mathbb Z\to\mathbb N\), where \(c(p)=2p+1\) if \(p\geq0\), and \(c(p)=-2p\) if \(p<0\). For instance, \(c(0)=1\), \(c(3)=7\), and \(c(-3)=6\). Nonnegative integers receive odd labels and negative integers receive even labels, so distinct integers have distinct labels.

For \(q\in\mathbb Q\), write its unique reduced representation as \(q=p/r\), and assign to it the pair \((c(p),r)\in\mathbb N\times\mathbb N\). This assignment is injective. If two rationals receive the same pair, their denominators are equal and their integer numerators have equal \(c\)-labels. Since \(c\) is injective, the numerators are equal too, so the rationals are equal.

By the diagonal theorem, there is a bijection \(g:\mathbb N\to\mathbb N\times\mathbb N\), and its inverse \(g^{-1}:\mathbb N\times\mathbb N\to\mathbb N\) is also a bijection. Composing the injection \(\mathbb Q\to\mathbb N\times\mathbb N\) just constructed with \(g^{-1}\) gives an injection from \(\mathbb Q\) into \(\mathbb N\). The injection criterion therefore shows that \(\mathbb Q\) is countable. It is infinite, since it contains all natural numbers, so in fact it is countably infinite.

What Countability Tells Us

Countability does not mean that a set is small in the sense of being finite. The even natural numbers, the integers, and the rational numbers are all infinite, yet each can be placed in bijection with \(\mathbb N\). For these sets, the important feature is not that their elements are arranged in an obvious order, but that a complete sequence can be constructed.

A common pitfall is to assume that an infinite set cannot be counted because its listing never ends. A countable enumeration does continue indefinitely; what matters is that each element occurs at a particular finite position. Conversely, an attempted list that misses even one element is not an enumeration. The injection criterion is often the more efficient tool: it proves countability by assigning distinct natural-number labels, without requiring those labels to be used in order.

Key takeaway. A set is countable exactly when its elements can be assigned distinct natural-number labels. For an infinite set, this is equivalent to having a bijective enumeration by \(\mathbb N\). Diagonal listing shows how even sets of pairs—and, through reduced fractions, the rational numbers—can be enumerated.

Check Your Understanding

Use the definitions and results in this tutorial to answer the questions.

  1. Under the convention used here, what is the difference between “countable” and “countably infinite”?
  2. Why does an infinite subset of \(\mathbb N\) have a least element available at every stage of the increasing-list construction?
  3. How does an injection from a set \(A\) into \(\mathbb N\) help establish that \(A\) is countable?
  4. Why does listing \(\mathbb N\times\mathbb N\) one entire row at a time fail, and how do diagonals avoid that problem?
  5. Why is it important to use reduced fractions when assigning pairs of natural-number labels to rational numbers?