EECS70 Note 5
EECS70 Note 5
1 Bijections
Two finite sets have the same size if and only if their elements can be paired up, so that each element of one
set has a unique partner in the other set, and vice versa. We formalize this through the concept of a bijection.
Consider a function (or mapping) f that maps elements of a set A (called the domain of f ) to elements of
set B (called the range of f ). Since f is a function, it must specify, for each element x ∈ A (“input”), exactly
one element f (x) ∈ B (“output”). Recall that we write this as f : A → B. We say that f is a bijection if
every element a ∈ A has a unique image b = f (a) ∈ B, and every element b ∈ B has a unique pre-image
a ∈ A : f (a) = b.
f is a one-to-one function (or an injection) if f maps distinct inputs to distinct outputs. More rigorously, f
is one-to-one if the following holds: x ̸= y =⇒ f (x) ̸= f (y).
f is onto (or surjective) if it “hits” every element in the range (i.e., each element in the range has at least one
pre-image). More precisely, a function f is onto if the following holds: (∀y ∃x)( f (x) = y).
Here are some simple examples to help visualize one-to-one and onto functions, and bijections:
1 a 1 a 1 a
b 2 2 b
2 b
c 3 3 c
3 d 4 c 4 d
A B A B A B
Note that, according to the above definitions, f is a bijection if and only if it is both one-to-one and onto.
Exercise. Let f : A → B be a bijection. Show that f has an inverse f −1 : B → A that satisfies f −1 ( f (a)) = a
for all a ∈ A, and that f −1 is also a bijection.
N 0 1 2 3 4 5 ...
f
Z+ 1 2 3 4 5 6 ...
Why is this mapping a bijection? Clearly, the function f : N → Z+ is onto because every positive integer
is hit. And it is also one-to-one because no two natural numbers have the same image. (The image of n is
f (n) = n + 1, so if f (n) = f (m) then we must have n = m.) Since we have shown a bijection between N and
Z+ , this tells us that there are as many natural numbers as there are positive integers! (Very) informally, we
have proved that “∞ + 1 = ∞."
What about the set of even natural numbers 2N = {0, 2, 4, 6, . . .}? In the previous example the difference
was just one element. But in this example, there seem to be twice as many natural numbers as there are even
natural numbers. Surely, the cardinality of N must be larger than that of 2N since N contains all of the odd
natural numbers as well? Though it might seem to be a more difficult task, let us attempt to find a bijection
between the two sets using the following mapping:
N 0 1 2 3 4 5 ...
f
2N 0 2 4 6 8 10 ...
The mapping in this example is also a bijection. f is clearly one-to-one, since distinct natural numbers get
mapped to distinct even natural numbers (because f (n) = 2n). f is also onto, since every n in the range is
hit: its pre-image is n2 . Since we have found a bijection between these two sets, this tells us that in fact N
and 2N have the same cardinality!
What about the set of all integers, Z? At first glance, it may seem obvious that the set of integers is larger
than the set of natural numbers, since it includes infinitely many negative numbers. However, as it turns out,
it is possible to find a bijection between the two sets, meaning that the two sets have the same size! Consider
the following mapping f :
0 −1 1 −2 2 ... 62 ...
We will prove that this function f : N → Z is a bijection, by first showing that it is one-to-one and then
showing that it is onto.
Proof (one-to-one): Suppose f (x) = f (y). Then they both must have the same sign. Therefore either
f (x) = 2x and f (y) = 2y , or f (x) = − x+1 y+1
2 and f (y) = − 2 . In the first case,
x y
f (x) = f (y) =⇒ = =⇒ x = y.
2 2
Hence x = y. In the second case,
x+1 y+1
f (x) = f (y) =⇒ − =− =⇒ x = y.
2 2
So in both cases f (x) = f (y) =⇒ x = y, so f is injective.
Proof (onto): If y ∈ Z is non-negative, then f (2y) = y. Therefore, y has a pre-image. If y is negative, then
f (−(2y + 1)) = y. Therefore, y has a pre-image. Thus every y ∈ Z has a preimage, so f is onto.
Since f is a bijection, this tells us that N and Z have the same size.
Now for an important definition. We say that a set S is countable if there is a bijection between S and N
or some subset of N. Thus any finite set S is countable (since there is a bijection between S and the subset
{0, 1, 2, . . . , m − 1}, where m = |S| is the size of S). And we have already seen three examples of countable
infinite sets: Z+ and 2N are obviously countable since they are themselves subsets of N; and Z is countable
because we have just seen a bijection between it and N.
What about the set of all rational numbers? Recall that Q = { xy | x, y ∈ Z, y ̸= 0}. Surely there are more
rational numbers than natural numbers? After all, there are infinitely many rational numbers between any
two natural numbers. Surprisingly, the two sets have the same cardinality! To see this, let us introduce a
slightly different way of comparing the cardinality of two sets.
If there is a one-to-one function f : A → B, then the cardinality of A is less than or equal to that of B. Now to
show that the cardinality of A and B are the same we can show that |A| ≤ |B| and |B| ≤ |A|. This corresponds
to showing that there is a one-to-one function f : A → B and a one-to-one function g : B → A. The existence
of these two one-to-one functions implies that there is a bijection h : A → B, thus showing that A and B have
the same cardinality. The proof of this fact, which is called the Cantor-Bernstein theorem, is actually quite
hard, and we will skip it here.
Back to comparing the natural numbers and the integers. First it is obvious that |N| ≤ |Q| because N ⊆ Q.
So our goal now is to prove that also |Q| ≤ |N|. To do this, we must exhibit an injection f : Q → N. The
following picture of a spiral conveys the idea of this injection:
−3 −2 −1 1 2 3
−1
−2
−3
Each rational number ab (written in its lowest terms, so that gcd(a, b) = 1) is represented by the point (a, b)
in the infinite two-dimensional grid shown (which corresponds to Z × Z, the set of all pairs of integers).
Note that not all points on the grid are valid representations of rationals: e.g., all points on the x-axis have
b = 0 so none are valid (except for (0, 0), which we take to represent the rational number 0); and points
such as (2, 8) and (−1, −4) are not valid either as the rational number 41 is represented by (1, 4). But Z × Z
certainly contains all rationals under this representation, so if we come up with an injection from Z × Z to N
then this will also be an injection from Q to N (why?).
The idea is to map each pair (a, b) to its position along the spiral, starting at the origin. (Thus, e.g.,(0, 0) → 0,
(1, 0) → 1, (1, 1) → 2, (0, 1) → 3, and so on.) It should be clear that this mapping maps every pair of integers
injectively to a natural number, because each pair occupies a unique position along the spiral.
This tells us that |Q| ≤ |N|. Since also |N| ≤ |Q|, as we observed earlier, by the Cantor-Bernstein Theorem
N and Q have the same cardinality.
Exercise. Show that the set N × N of all ordered pairs of natural numbers is countable.
Our next example concerns the set of all binary strings (of any finite length), denoted {0, 1}∗ . Despite the
fact that this set contains strings of unbounded length, it turns out to have the same cardinality as N. To see
this, we set up a direct bijection f : {0, 1}∗ → N as follows. Note that it suffices to enumerate the elements
of {0, 1}∗ in such a way that each string appears exactly once in the list. We then get our bijection by setting
f (n) to be the nth string in the list. How do we enumerate the strings in {0, 1}∗ ? Well, it’s natural to list them
in increasing order of length, and then (say) in lexicographic order (or, equivalently, numerically increasing
order when viewed as binary numbers) within the strings of each length. This means that the list would look
like
ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101, 110, 111, 1000, . . . ,
where ε denotes the empty string (the only string of length 0). It should be clear that this list contains each
binary string once and only once, so we get a bijection with N as desired.
Our final countable example is the set of all polynomials with natural number coefficients, which we denote
N(x). To see that this set is countable, we will make use of (a variant of) the previous example. Note first
that, by essentially the same argument as for {0, 1}∗ , we can see that the set of all ternary strings {0, 1, 2}∗
(that is, strings over the alphabet {0, 1, 2}) is countable. To see that N(x) is countable, it therefore suffices to
exhibit an injection f : N(x) → {0, 1, 2}∗ , which in turn will give an injection from N(x) to N. (It is obvious
that there exists an injection from N to N(x), since each natural number n is itself trivially a polynomial,
1012102111221002110
It is easy to check that this is an injection, since the original polynomial can be uniquely recovered from this
ternary string by simply reading off the coefficients between each successive pair of 2’s. (Notice that this
mapping f : N(x) → {0, 1, 2}∗ is not onto (and hence not a bijection) since many ternary strings will not be
the image of any polynomials; this will be the case, for example, for any ternary strings that contain binary
subsequences with leading zeros.)
Hence we have an injection from N(x) to N, so N(x) is countable.
3 Cantor’s Diagonalization
We have established that N, Z, Q all have the same cardinality. What about R, the set of real numbers?
Surely they are countable too? After all, the rational numbers, like the real numbers, are dense (i.e., between
any two rational numbers a, b there is a rational number, namely a+b 2 ). In fact, between any two real
numbers there is always a rational number. It is really surprising, then, that there are more real numbers than
rationals. That is, there is no bijection between the rationals (or the natural numbers) and the reals. We shall
now prove this, using a beautiful argument due to Cantor that is known as diagonalization. In fact, we will
show something even stronger: the real numbers in the interval [0, 1] are uncountable!
Exercise. Show how to find a rational number between any two (distinct) real numbers.
In preparation for the proof, recall that any real number can be written out uniquely as an infinite decimal
with no trailing zeros. In particular, a real number in the interval [0, 1] can be written as 0.d1 d2 d3 . . .. In
this representation, we write for example 1 as 0.999 . . .1 , and 0.5 as 0.4999 . . .. (Thus rational numbers will
always be represented as recurring decimals, while irrational ones will be represented as non-recurring ones.
Importantly for us, all of these expressions will be infinitely long and unique.)
Theorem: The real interval R[0, 1] (and hence also the set of real numbers R) is uncountable.
Proof: Suppose towards a contradiction that there is a bijection f : N → R[0, 1]. Then, we can enumerate
the real numbers in an infinite list f (0), f (1), f (2), . . . as follows:
1 To see this, write x = .999 . . .. Then 10x = 9.999 . . ., so 9x = 9, and thus x = 1.
The number circled in the diagonal can be viewed as some real number r = 0.5479 . . ., since it is an infinite
decimal expansion. Now consider the real number s obtained by modifying every digit of r, say by replacing
each digit d with d + 2 (mod 10); thus in our example above, s = 0.7691 . . .. We claim that s does not occur
in our infinite list of real numbers. Suppose for contradiction that it did, and that it was the nth number in
the list, f (n). But by construction s differs from f (n) in the (n + 1)th digit, so these two numbers cannot be
equal! So we have constructed a real number s that is not in the range of f . But this contradicts the assertion
that f is a bijection. Thus the real numbers are not countable.
Let us remark that the reason that we modified each digit by adding 2 (mod 10) as opposed to adding 1 is
that the same real number can have two decimal expansions; for example 0.999 . . . = 1.000 . . .. But if two
real numbers differ by more than 1 in any digit they cannot be equal. Thus we are completely safe in our
assertion. (An alternative way of avoiding this potential pitfall is to replace each digit by some different
digit chosen from the range {1, 2, . . . , 8}.)
With Cantor’s diagonalization method, we proved that R is uncountable. What happens if we apply the same
method to Q, in a (futile) attempt to show the rationals are uncountable? Well, suppose for contradiction
that our bijective function f : N → Q[0, 1] produces the following mapping:
f (0) = 0 . 1 4 0 0 0 . . .
f (1) = 0 . 5 9 2 4 5 . . .
f (2) = 0 . 2 1 4 2 1 . . .
.. ..
. .
This time, let us consider the number q obtained by modifying every digit of the diagonal, say by replacing
each digit d with d + 2 (mod 10). Then in the above example q = 0.316..., and we want to try to show that
it does not occur in our infinite list of rational numbers. However, we do not know that q is rational (in fact,
it is extremely unlikely for the decimal expansion of q to be periodic). This is why the method fails when
applied to the rationals. When dealing with the reals, the modified diagonal number was guaranteed to be a
real number.
1)
2)
3)
The Cantor set contains all points that have not been removed: C = {x : x not removed}. How much of
the original unit interval is left after this process is repeated infinitely? Well, we start with an interval of
length 1, and after the first iteration we remove 31 of it, leaving us with 23 . For the second iteration, we keep
2 2
3 × 3 of the original interval. As we repeat these iterations infinitely often, we are left with:
n
2 2 2 2 2 2 2
1 −→ −→ × −→ × × −→ · · · −→ lim =0
3 3 3 3 3 3 n→∞ 3
According to the calculations, we have removed everything from the original interval! Does this mean that
the Cantor set is empty? No, it doesn’t. What it means is that the measure of the Cantor set is zero; the
Cantor set consists of isolated points and does not contain any non-trivial intervals. In fact, not only is the
Cantor set non-empty, it is uncountable!2
To see why, let us first make a few observations about ternary strings. In ternary notation, all strings consist
of digits (called “trits”) from the set {0, 1, 2}. All real numbers in the interval [0, 1] can be written in
ternary notation. (E.g., 31 can be written as 0.1, or equivalently as 0.0222 . . ., and 23 can be written as 0.2
or as 0.1222 . . ..) Thus, in the first iteration, the middle third removed contains all ternary numbers of the
form 0.1xxxxx. The ternary numbers left after the first removal can all be expressed either in the form
0.0xxxxx. . . or 0.2xxxxx. . . (We have to be a little careful here with the endpoints of the intervals; but we
can handle them by writing 13 as 0.02222 . . . and 23 as 0.2.) The second iteration removes ternary numbers
of the form 0.01xxxxx and 0.21xxxxx (i.e., any number with 1 in the second position). The third iteration
removes 1’s in the third position, and so on. Therefore, what remains is all ternary numbers with only 0’s
and 2’s. Thus we have shown that
C = {x ∈ [0, 1] : x has a ternary representation consisting only of 0’s and 2’s}.
Finally, using this characterization, we can set up an onto map f from C to [0, 1]. Since we already know that
[0, 1] is uncountable, this implies that C is uncountable also. The map f is defined as follows: for x ∈ C, f (x)
is defined as the binary decimal obtained by dividing each digit of the ternary representation of x by 2. Thus,
for example, if x = 0.0220 (in ternary), then f (x) is the binary decimal 0.0110. But the set of all binary
decimals 0.xxxxx. . . is in 1-1 correspondence with the real interval [0, 1], and the map f is onto because
every binary decimal is the image of some ternary string under f (obtained by doubling every binary digit).3
This completes the proof that C is uncountable.
respectively, which denote the same real number. Thus f is not a bijection. However, the current proof shows that the cardinality
of C is at least that of [0, 1], while it is obvious that the cardinality of C is at most that of [0, 1] since C ⊂ [0, 1]. Hence C has the
same cardinality as [0, 1] (and as R).
0 1 2 3 4 5 ...
0 1 0 0 0 0 0 ...
1 0 0 0 0 0 0 ...
2 1 0 1 0 0 0 ...
..
.
In this example, we have assigned the following mapping: 0 → {0}, 1 → {}, 2 → {0, 2}, . . . (i.e., the nth
row describes the nth subset as follows: if there is a 1 in the kth column, then k is in this subset, else it is
not.) Using a similar diagonalization argument to the earlier one, flip each bit along the diagonal: 1 → 0,
0 → 1, and let b denote the resulting binary string. First, we must show that the new element is a subset
of N. Clearly it is, since b is an infinite binary string which corresponds to a subset of N. Now suppose b
were the nth binary string. This cannot be the case though, since the nth bit of b differs from the nth bit of
the diagonal (the bits are flipped). So it’s not on our list, but it should be, since we assumed that the list
enumerated all possible subsets of N. Thus we have a contradiction, implying that P(N) is uncountable.
Thus we have seen that the cardinality of P(N) (the power set of the natural numbers) is strictly larger
than the cardinality of N itself. The cardinality of N is denoted ℵ0 (pronounced “aleph null"), while that of
P(N) is denoted 2ℵ0 . It turns out that in fact P(N) has the same cardinality as R (the real numbers), and
indeed as the real numbers in [0, 1]. This cardinality is known as c, the “cardinality of the continuum." So
we know that 2ℵ0 = c > ℵ0 . Even larger infinite cardinalities (or “orders of infinity”), denoted ℵ1 , ℵ2 , . . .,
can be defined using the machinery of set theory; these obey (to the uninitiated somewhat bizarre) rules of
arithmetic. Several fundamental questions in modern mathematics concern these objects. For example, the
famous “continuum hypothesis” asserts that c = ℵ1 (which is equivalent to saying that there are no sets with
cardinality between that of the natural numbers and that of the real numbers).