Tutorials › Real Analysis › Cardinality

Sets and Functions · Tutorial 77 of 1000

Cardinality

Learn to assign a well-defined size to every finite set and use functions to compare the sizes of finite sets.

Beginner 9 min read

What You'll Learn

  • Define the cardinality of a finite set using bijections with standard finite sets
  • Prove that different distinct listings of the same finite set have the same length
  • Use injections to compare the cardinalities of finite sets
  • Apply the finite pigeonhole principle to functions between finite sets
  • Distinguish equal cardinality from equality of sets

From Finite Listings to Cardinality

The previous tutorial defined a finite set as a set that has a distinct finite listing. A listing gives us a way to exhibit finiteness, but there is a further question: could the same set have distinct listings of different lengths? To speak consistently about the number of elements in a finite set, we first need to show that its listing length is uniquely determined.

A useful way to make “same number of elements” precise is to compare sets by a bijection. A bijection pairs every element of one set with exactly one element of the other, using every element on both sides. We will use bijections with a standard finite set of integers as a measuring tool.

Definition (Cardinality of a Finite Set). For an integer \(n\geq 0\), define
$$ [n]=\{1,2,\ldots,n\}, $$
with \([0]=\varnothing\). A finite set \(A\) has cardinality \(n\) if there is a bijection from \([n]\) to \(A\). When this \(n\) is unique, we write \(|A|=n\).

The set \([n]\) serves as a standard set containing \(n\) integers. In particular, \([0]\) has no elements, \([1]=\{1\}\), and \([3]=\{1,2,3\}\). A distinct listing \(a_1,\ldots,a_n\) of \(A\) gives a bijection from \([n]\) to \(A\) by sending \(i\) to \(a_i\). Conversely, a bijection from \([n]\) to \(A\) lists the elements of \(A\) as the distinct values of that function. So the definition connects cardinality to the distinct listings used to define finite sets.

Why the Number of Entries Is Unique

To justify the notation \(|A|=n\), we must rule out a bijection between two standard finite sets of different sizes. We first prove that an injection from \([m]\) into \([n]\) is possible only when \(m\leq n\). The argument accounts for the empty set as well as nonempty finite sets.

Lemma (Injection Between Standard Finite Sets). If \(m,n\geq 0\) and there is an injection from \([m]\) to \([n]\), then \(m\leq n\).

Proof. We use induction on \(n\), proving the claim for every integer \(m\geq 0\) at each stage. If \(n=0\), then \([n]=\varnothing\). There is no function from a nonempty set \([m]\) into \(\varnothing\), since an element of the domain would need an image. Thus an injection \([m]\to[0]\) requires \(m=0\), and the conclusion holds.

Now suppose the claim holds for \(n\), and consider an injection \(f:[m]\to[n+1]\). If \(m=0\), then \(m\leq n+1\) immediately. Suppose, therefore, that \(m\geq 1\). If \(n+1\) is not an output of \(f\), then every value of \(f\) belongs to \([n]\). We can regard \(f\) as an injection into \([n]\), so the induction hypothesis gives \(m\leq n\), and hence \(m\leq n+1\).

It remains to consider the case in which \(f(i)=n+1\) for some \(i\in[m]\). Since \(f\) is injective, no other input maps to \(n+1\). The remaining \(m-1\) inputs can be reindexed by \([m-1]\): define \(h:[m-1]\to[m]\setminus\{i\}\) by \(h(k)=k\) when \(k<i\), and \(h(k)=k+1\) when \(k\geq i\). This map lists every member of \([m]\setminus\{i\}\) exactly once. Consequently, \(f\circ h\) is an injection from \([m-1]\) into \([n]\). The induction hypothesis gives \(m-1\leq n\), so \(m\leq n+1\). This completes the induction. \(\square\)

Theorem (Well-Defined Cardinality). Every finite set \(A\) has a unique integer \(n\geq 0\) for which there is a bijection from \([n]\) to \(A\). Thus \(|A|\) is well-defined.

Proof. Since \(A\) is finite, it has a distinct listing \(a_1,\ldots,a_m\) for some \(m\geq 0\). Sending \(i\in[m]\) to \(a_i\) gives a bijection from \([m]\) to \(A\). This also holds when \(m=0\): the empty function is a bijection from \([0]=\varnothing\) to \(A=\varnothing\).

For uniqueness, suppose there are bijections \(f:[m]\to A\) and \(g:[n]\to A\). Since a bijection has an inverse, \(g^{-1}\circ f\) is a bijection from \([m]\) to \([n]\), and in particular is an injection. The lemma gives \(m\leq n\). The inverse of this bijection is an injection from \([n]\) to \([m]\), so the lemma also gives \(n\leq m\). Therefore \(m=n\). \(\square\)

The theorem means that the length of a distinct listing is not an accidental feature of how the set was written. Every distinct listing of a given finite set has the same length, and that length is its cardinality.

Worked Example: Finding Cardinality from a Listing

Let \(A=\{\triangle,\square,\circ,\star\}\), where the four symbols represent distinct objects. Define \(f:[4]\to A\) by \(f(1)=\triangle\), \(f(2)=\square\), \(f(3)=\circ\), and \(f(4)=\star\). Each element of \(A\) occurs as exactly one value, so \(f\) is a bijection. Therefore \(|A|=4\).

For example, writing the same set in a different order, \(A=\{\star,\circ,\triangle,\square\}\), does not change its cardinality. The function that sends \(1\) to \(\star\), \(2\) to \(\circ\), \(3\) to \(\triangle\), and \(4\) to \(\square\) is also a bijection from \([4]\) to \(A\). The uniqueness theorem ensures there cannot be a distinct listing of \(A\) with a different number of entries.

Bijections and Injections Compare Sizes

A bijection between two finite sets shows that they have the same cardinality, even if their elements are entirely different. An injection gives a one-sided comparison: every element of its domain can be matched to a different element of its codomain, so the domain cannot be larger.

Theorem (Injections Compare Finite Cardinalities). Let \(A\) and \(B\) be finite sets. If there is an injection \(f:A\to B\), then \(|A|\leq |B|\). In particular, if there is a bijection from \(A\) to \(B\), then \(|A|=|B|\).

Proof. Write \(|A|=m\) and \(|B|=n\). By the definition of cardinality, there are bijections \(u:[m]\to A\) and \(v:[n]\to B\). The composition \(v^{-1}\circ f\circ u\) is an injection from \([m]\) to \([n]\): \(u\) and \(v^{-1}\) are bijections, and composing an injection with bijections preserves injectivity. The Injection Between Standard Finite Sets lemma gives \(m\leq n\). Hence \(|A|\leq |B|\). If \(f\) is a bijection, its inverse also gives an injection from \(B\) to \(A\), so the same result gives \(|B|\leq |A|\). Thus \(|A|=|B|\). \(\square\)

Worked Example: Different Sets with Equal Cardinality

Let \(A=\{2,5,8\}\) and \(B=\{u,v,w\}\), with distinct elements in each set. Define \(f:A\to B\) by \(f(2)=u\), \(f(5)=v\), and \(f(8)=w\). Every element of \(B\) is the output for exactly one input, so \(f\) is a bijection. Thus \(|A|=|B|=3\).

The sets are not equal: for instance, \(2\in A\) and \(2\notin B\). Nevertheless, they have equal cardinality because their elements can be paired bijectively. Cardinality records size, not the identity of the elements.

The Finite Pigeonhole Principle

The injection theorem has a useful contrapositive. If the domain of a function has greater cardinality than its codomain, the function cannot be injective. Therefore, at least two different inputs must have the same output. This is the finite pigeonhole principle: if more objects are assigned to fewer available positions, some position receives at least two objects.

Corollary (Finite Pigeonhole Principle). Let \(A\) and \(B\) be finite sets with \(|A|>|B|\). Every function \(f:A\to B\) takes the same value at two distinct elements of \(A\).

Proof. Suppose instead that \(f(a_1)\ne f(a_2)\) whenever \(a_1\ne a_2\). Then \(f\) is injective. The Injections Compare Finite Cardinalities theorem would give \(|A|\leq |B|\), contradicting \(|A|>|B|\). Hence \(f\) is not injective, which means there are distinct \(a_1,a_2\in A\) such that \(f(a_1)=f(a_2)\). \(\square\)

Worked Example: Two Inputs Must Share an Output

Let \(A=\{a,b,c,d,e\}\) and \(B=\{0,1,2\}\), with all elements distinct within each set. Then \(|A|=5\) and \(|B|=3\). Consider any function \(f:A\to B\). If its five outputs were all different, they would give five distinct elements of \(B\), which has only three elements. Equivalently, \(f\) would be an injection from a set of cardinality \(5\) into one of cardinality \(3\), contradicting the injection theorem because \(5\not\leq3\). Thus two distinct elements of \(A\) must have the same output.

For a concrete function, define \(f(a)=0\), \(f(b)=1\), \(f(c)=2\), \(f(d)=0\), and \(f(e)=1\). In this case \(f(a)=f(d)=0\), and \(f(b)=f(e)=1\). The conclusion concerns at least one repeated output; it does not require every output in \(B\) to occur.

Worked Example: Cardinality of an Empty Set

The empty set \(\varnothing\) is finite, using the listing with no entries. Since \([0]=\varnothing\), the empty function from \([0]\) to \(\varnothing\) is a bijection. It follows that \(|\varnothing|=0\).

No positive integer can also be the cardinality of \(\varnothing\). If there were a bijection from \([n]\) to \(\varnothing\) for some \(n\geq1\), it would in particular be a function from a nonempty set to the empty set. Such a function cannot exist, because the element \(1\in[n]\) would need an output in \(\varnothing\). This agrees with the uniqueness theorem.

What Cardinality Does—and Does Not—Say

For finite sets, cardinality turns the informal idea of “number of elements” into a precise integer. The central step is the well-definedness theorem: once a finite set has one distinct listing, every distinct listing has the same length. A bijection is the appropriate comparison because it matches the elements one-to-one, while an injection only guarantees that the first set can be matched into the second.

Be careful not to confuse equal cardinality with set equality. Sets with different elements can have the same cardinality, as the worked example with \(A\) and \(B\) demonstrates. Conversely, if two finite sets are equal, then they have the same elements and therefore the same cardinality. The cardinality comparison developed here applies to finite sets; later, countable sets will extend the study of how sets can be matched with standard sets.

Key takeaway. A finite set \(A\) has a unique cardinality \(|A|\), the integer \(n\) for which \(A\) is in bijection with \([n]\). A bijection gives equal cardinalities, an injection gives an inequality, and a function from a larger finite set to a smaller one must repeat an output.

Check Your Understanding

Use the definition of cardinality and the results in this tutorial to answer the questions.

  1. How does a distinct listing of a finite set give a bijection from a standard finite set \([n]\)?
  2. Why does a bijection between \([m]\) and \([n]\) imply \(m=n\)?
  3. If \(A\) and \(B\) are finite and there is an injection \(A\to B\), what inequality must their cardinalities satisfy?
  4. Can two unequal finite sets have the same cardinality? Explain how a bijection establishes this.
  5. If \(|A|=7\) and \(|B|=4\), what must be true of any function \(f:A\to B\)?