Computer Science C63 Winter 2025
Scarborough Campus University of Toronto
On countable and uncountable sets
Vassos Hadzilacos
A set A is countable or enumerable if it is finite or there is a bijection f : N → A (i.e., A can be placed
in a one-to-one correspondence with the natural numbers). A set is uncountable if it is not countable.
From the definition of countable set it follows immediately that A is countable if and only if there is a
finite or infinite sequence S = a0 , a1 , a2 , . . . such that every element of A appears once and only once in S.
We call such a sequence an enumeration of the set A.
In lecture we saw examples of countable and uncountable sets. In particular, we saw two proof tech-
niques, both due to Cantor: Dovetailing (merging countably many infinite sequences into a single infinite
sequence), which can be used to prove that a set is countable; and diagonalization, which can be used
to prove that a set is not countable.
Following is a list of the results of this nature that we have proved using these techniques.
Theorem 1.1: Z is countable.
Theorem 1.2: N × N is countable.
Theorem 1.3: For every positive integer k, Nk = |N × N ×
{z· · · × N} is countable.
k times
N∗ Nk
S
Theorem 1.4: = k∈N (the set of finite sequences of natural numbers) is countable.
Theorem 1.5: The set of infinite sequences over {0, 1} is uncountable.
Theorem 1.6: The set of functions from N to N is uncountable.
Theorem 1.7: The set of strings over an alphabet is countable.1
We can leverage the fact that we know that certain sets are countable (or uncountable) to show that
other sets have this property.
For example, consider the set of “step functions” from N to N. A function f : N → N is called a step
function if there is some nf ∈ N and a, b ∈ N such that for all n, 0 ≤ n ≤ nf , f (n) = a and for all n > nf ,
f (n) = b. Is the set of step functions from N to N countable or uncountable?
Notice that a step function f : N → N can be uniquely and fully described by a triple of natural
numbers (nf , a, b). Sometimes we say that this triple encodes the function f : Given a step function there
is a unique triple that corresponds to it; and conversely, given a triple, there is a unique step function
defined by it. Since triples of natural numbers can be encoded by (correspond one-to-one to) natural
numbers (see Theorem 1.3), we conclude that
Theorem 1.8: The set of step functions from N to N is countable.
The preceding argument exemplifies a useful way to prove that a set is countable: Show that every
element of the set can be encoded by (i.e., placed into a one-to-one correspondence with) the elements of
a set we have already proved is countable. Now, we can use Theorem 1.8 to show:
Theorem 1.9: The set of non-step functions from N to N is uncountable.
1
Recall that an alphabet Σ is a finite set of symbols; and a string over Σ is a finite sequence of symbols from Σ. The set
of all strings over Σ, denoted Σ∗ is infinite since strings can be arbitrarily long, even though each individual string has finite
length.
1
Proof. Suppose, for contradiction, that the set of non-step N → N functions is countable, and let
f0 , f1 , f2 , . . . be an enumeration of this set. By Theorem 1.8, the set of N → N step functions is countable,
so let g0 , g1 , g2 , . . . be an enumeration of this set. Then we can enumerate the set of all N → N functions
by dovetailing as f0 , g0 , f1 , g1 , f2 , g2 , . . ., contradicting Theorem 1.6.
As an exercise, try to prove Theorem 1.9 using diagonalization.
Following are some useful facts about countable sets:
Theorem 1.10:
(a) If f : N → A is an onto (surjective) function, then A is countable.
(b) If A ⊆ B and B is countable, then A is countable.
(c) If A and B are countable, then A ∪ B is countable.
S
(d) If for each i ∈ N the set Ai is countable then the set i∈N Ai is countable. (That is, the union of
countably many countable sets is countable!).
(e) If f : A → B is a bijection, then A is countable if and only if B is countable.
Proof. Part (a) is left as an exercise. (See Question 1(a) in Assignment 1!) It implies that if a0 , a1 , a2 , . . .
is a sequence of elements of A such that every element of A appears at least once (i.e., this sequence is a
listing of all THE elements of A but possibly with duplicates) then A is countable. This is useful because
it is sometimes simpler to describe a listing of a set that may contain duplicates. (Note that the sequence
a0 , a1 , a2 , . . . is not an enumeration of A, which is a sequence in which every element of A must appear
exactly once.)
Part (b) follows from (a): Intuitively, given an enumeration of B we can write an enumeration of A with
possible duplicates by replacing elements in the enumeration of B that are not in A by some element of A.
(If A is empty, then it is by definition countable since the empty set is finite.)
For part (c), let a0 , a1 , a2 , . . . be an enumeration of A and b0 , b1 , b2 , . . . be an enumeration of B. By
dovetailing these two sequences
a0 , b0 , a1 , b1 , a2 , b2 , . . .
we get an enumeration (with possible repetition) of A ∪ B. By part (a), A ∪ B is countable.
For part (d) we can assume, without loss of generality, that every Ai is non-empty. (If A is countable
then A ∪ ∅ = A is also countable.) Let ai0 , ai1 , ai2 , . . . be an enumeration of Ai ; if Ai is finite, we pad
the enumeration by repeating some element of Ai an infinite number of times (we can do this because we
assume that Ai is non-empty). So, every element of ∪i∈N Ai appears (at least once) in the following table:
a00 a01 a02 a03 ···
a10 a11 a12 a13 ···
a20 a21 a22 a23 ···
a30 a31 a32 a33 ···
.. .. .. .. ..
. . . . .
By
S dovetailing we can enumerate (possibly with repetition) all elements of all Ai ’s. Thus, by part (a),
i∈N Ai is countable.
For part (e), let f : A → B be a bijection. For the “only if” part we reason as follows: First consider the
case where A is countable and finite. Then B has exactly the same number of elements as A (if it had
more f would not be onto; and if it had fewer, by the Pigeonhole Principle, f would not be one-to-one).
2
So B is also finite and countable. Now consider the case where A is countably infinite. For the “only if”
part we reason as follows: Since A is countably infinite, there is a bijection g: N → A. It is easy to show
that the composition of two bijections is a bijection, and so g ◦ f : N → B is a bijection, proving that B is
countably infinite. The “if” part follows from the “only if” part by noting that, because f is a bijection,
f −1 : B → A is also a bijection.
If we encode the elements of a set A by the elements of a set B that is countable (respectively uncount-
able), then part (e) immediately implies that B is also countable (respectively uncountable). We silently
made use of this fact in the proof of Theorem 1.8.
How many infinities?
So far, we have seen that there are at least two kinds of infinite sets: countable, and uncountable. All
countable sets are clearly equinumerous. Are all uncountable sets equinumerous? The answer is no — by
a long shot! — as shown by the following result, known as Cantor’s Theorem. Recall that the powerset
P(A) of a set A, is the set of subsets of A.
Theorem 1.11: For any set A, A is not equinumerous to P(A).
Proof. It suffices to prove that there is no surjective function from A to B. Consider any function
f : A → P(A). Let D = {x ∈ A: x ∈ / f (x)}. D is a subset of A, so D ∈ P(A), but D is not the image of any
x ∈ A under f , because it differs from f (x) on (at least) whether it contains x: by definition, x ∈ f (x) if
and only if x ∈/ D. So f is not surjective.
Theorem 1.11 implies that N, P(N), P P(N) , P P P(N) , . . . is an infinite sequence of sets of ever-
larger cardinalities. (We say that set B has larger cardinality than set A, written |B| > |A|, if there is
an injective function from A to B, but no surjective function from A to B.) So, there is no largest infinity!
In fact, there are many more cardinalities than the ones of the sets in the above sequence, but this is a
topic beyond the scope of this course.