Cardinality of Finite Sets
Learning Objectives
-
Define the cardinality of a finite set rigorously
-
Compute the cardinality of a complement and a difference
-
Apply the inclusion–exclusion principle for two and three sets
-
Recognise disjoint sets and use the addition rule for disjoint unions
-
Translate counting problems into the language of sets and operations
From Sets to Counting
In Unit 2 we developed the algebra of sets: union, intersection, complement, difference. These operations told us which elements belong to a combined set. We now ask a different kind of question: how many elements does a set contain?
For a small set listed explicitly — \(A = \{2, 5, 7, 11\}\) — the answer is immediate: count the elements. But sets often arise as the union, intersection, or difference of other sets, and asking how many elements such a combined set has becomes a problem in its own right. The methods of this lesson address it systematically.
Finite Set; Cardinality
A set \(A\) is finite if its elements can be listed without repetition as \(A = \{a_1, a_2, \ldots, a_n\}\) for some natural number \(n \geq 0\). The cardinality of a finite set \(A\), written
\[|A|\]
(or sometimes \(\#A\) or \(\operatorname{card}(A)\)), is the number of elements in \(A\). When \(n = 0\), the listing is empty and \(A = \emptyset\), the empty set; in that case \(|A| = 0\).
A set is infinite if it is not finite. For an infinite set, \(|A|\) is not a natural number; the cardinality of infinite sets is a delicate topic that lies beyond the scope of this lesson. Throughout the rest of the lesson, every set is assumed to be finite.
Cardinality — Examples
\(A = \{2, 4, 6, 8, 10\}\): \(|A| = 5\).
\(B = \{x \in \mathbb{N} \mid 1 \leq x \leq 100\}\): \(|B| = 100\).
\(C = \{n \in \mathbb{N} \mid n \leq 10 \text{ and } n \text{ is prime}\} = \{2, 3, 5, 7\}\): \(|C| = 4\).
\(\emptyset\) (the empty set): \(|\emptyset| = 0\).
\(\{\emptyset\}\) (the set containing the empty set): \(|\{\emptyset\}| = 1\). The single element is \(\emptyset\) itself.
The last two examples deserve attention. The empty set \(\emptyset\) has zero elements. The set \(\{\emptyset\}\) has one element — that element happens to be the empty set, but there is one of it.
Cardinality of a Disjoint Union
Let \(A\) and \(B\) be finite sets with \(A \cap B = \emptyset\). Then:
\[|A \cup B| \;=\; |A| + |B|\]
Two sets satisfying \(A \cap B = \emptyset\) are called disjoint: they share no elements.
Why Disjointness Matters
The condition \(A \cap B = \emptyset\) is essential. If \(A\) and \(B\) share elements, those shared elements belong to both \(A\) and \(B\); summing \(|A| + |B|\) counts each shared element twice, while \(|A \cup B|\) counts it only once. The discrepancy is precisely the number of shared elements — \(|A \cap B|\) — a fact we shall make rigorous in the inclusion–exclusion principle below.
Disjointness is therefore the simplest possible setting for cardinality arithmetic. Whenever we can split a set into disjoint pieces, the total cardinality is the sum of the cardinalities of the pieces.
Disjoint Union — Example
In a class of \(30\) students, \(18\) play a team sport and \(12\) do not. Let \(T\) be the set of students playing a team sport and \(N\) the set of those who do not. Every student is in exactly one of these two categories: \(T\) and \(N\) are disjoint, and together they cover the whole class.
Hence \(|T| + |N| = |T \cup N| = 30\), agreeing with \(18 + 12\).
This example illustrates a frequent pattern: a fixed total is partitioned into disjoint cases, and the addition rule recovers the total.
Cardinality of a Complement
Let \(\mathcal{D}\) be a finite domain and \(A \subseteq \mathcal{D}\). Then:
\[|\complement_\mathcal{D} A| \;=\; |\mathcal{D}| - |A|\]
Proof — Cardinality of a Complement
The sets \(A\) and \(\complement_\mathcal{D} A\) are disjoint by definition (the complement contains exactly those elements of \(\mathcal{D}\) not in \(A\)). Their union is \(\mathcal{D}\). Applying the disjoint union theorem:
\[|\mathcal{D}| \;=\; |A \cup \complement_\mathcal{D} A| \;=\; |A| + |\complement_\mathcal{D} A|\]
Subtracting \(|A|\) from both sides:
\[|\complement_\mathcal{D} A| \;=\; |\mathcal{D}| - |A|\]
as required. \(\blacksquare\)
Inclusion–Exclusion for Two Sets
Let \(A\) and \(B\) be finite sets. Then:
\[|A \cup B| \;=\; |A| + |B| - |A \cap B|\]
This identity is known as the inclusion–exclusion principle (for two sets): elements common to \(A\) and \(B\) are included in both \(|A|\) and \(|B|\), so to count the union correctly we must exclude them once.
Proof — Inclusion–Exclusion for Two Sets
We decompose \(A \cup B\) into disjoint pieces. Consider three sets:
\(A \setminus B\) — elements in \(A\) but not in \(B\)
\(B \setminus A\) — elements in \(B\) but not in \(A\)
\(A \cap B\) — elements in both
These three sets are pairwise disjoint, and their union is \(A \cup B\). By repeated application of the disjoint union theorem:
\[|A \cup B| \;=\; |A \setminus B| + |B \setminus A| + |A \cap B| \qquad (\ast)\]
Now observe that \(A\) decomposes into the disjoint union \(A = (A \setminus B) \cup (A \cap B)\). Hence:
\[|A| \;=\; |A \setminus B| + |A \cap B| \quad\Longrightarrow\quad |A \setminus B| \;=\; |A| - |A \cap B|\]
By the same reasoning, \(|B \setminus A| = |B| - |A \cap B|\). Substituting into \((\ast)\):
\[|A \cup B| \;=\; \big(|A| - |A \cap B|\big) + \big(|B| - |A \cap B|\big) + |A \cap B| \;=\; |A| + |B| - |A \cap B|\]
as required. \(\blacksquare\)
Inclusion–Exclusion — Example
In a class of \(30\) students, \(18\) study French and \(15\) study German. Of these, \(8\) students study both languages. How many students study at least one of the two languages?
Let \(F\) be the set of French students and \(G\) the set of German students. We are given \(|F| = 18\), \(|G| = 15\), and \(|F \cap G| = 8\). The students who study at least one language form the union \(F \cup G\). By inclusion–exclusion:
\[|F \cup G| \;=\; |F| + |G| - |F \cap G| \;=\; 18 + 15 - 8 \;=\; 25\]
Hence \(25\) students study at least one of the two languages, and \(30 - 25 = 5\) students study neither.
Cardinality of a Difference
Let \(A\) and \(B\) be finite sets. Then:
\[|A \setminus B| \;=\; |A| - |A \cap B|\]
The Difference as a Disjoint Decomposition
The proof was already carried out in the proof of inclusion–exclusion above: \(A\) decomposes into the disjoint union \(A = (A \setminus B) \cup (A \cap B)\), from which
\[|A| \;=\; |A \setminus B| + |A \cap B|\]
and the result follows by subtraction. The cardinality of a difference is therefore not an independent identity: it is a direct consequence of the disjoint union theorem applied to the natural decomposition of \(A\).
When \(B \subseteq A\), the formula simplifies: \(A \cap B = B\), and so \(|A \setminus B| = |A| - |B|\). This is the most common case in practice.
Inclusion–Exclusion for Three Sets
Let \(A\), \(B\), and \(C\) be finite sets. Then:
\[|A \cup B \cup C| \;=\; |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|\]
The pattern is: add the cardinalities of the individual sets, subtract the cardinalities of all pairwise intersections, then add back the cardinality of the triple intersection.
Why the Triple Intersection Reappears
Sum \(|A| + |B| + |C|\) counts every element of the triple intersection \(A \cap B \cap C\) three times (once in each of \(|A|\), \(|B|\), \(|C|\)). Subtracting the three pairwise intersections then removes such an element three times (once in each pair). After the subtraction, every triple-intersection element has been counted \(3 - 3 = 0\) times — not the desired single count. Adding back \(|A \cap B \cap C|\) restores it.
Inclusion–Exclusion for Three Sets — Example
Of \(50\) students surveyed about their reading habits in the past month: \(30\) read a novel, \(25\) read a newspaper, \(20\) read a magazine; \(15\) read both a novel and a newspaper, \(10\) read both a novel and a magazine, \(8\) read both a newspaper and a magazine; \(5\) read all three. How many students read at least one of the three?
Let \(N\), \(P\), \(M\) be the sets of novel, newspaper, and magazine readers respectively. By inclusion–exclusion for three sets:
\[|N \cup P \cup M| \;=\; 30 + 25 + 20 - 15 - 10 - 8 + 5 \;=\; 47\]
Hence \(47\) students read at least one type of material, and \(50 - 47 = 3\) read none.
Inclusion–Exclusion in General
The pattern observed for two and three sets continues for any number of sets. For finite sets \(A_1, A_2, \ldots, A_n\):
\[\left|\bigcup_{i=1}^{n} A_i\right| \;=\; \sum_{i} |A_i| \;-\; \sum_{i < j} |A_i \cap A_j| \;+\; \sum_{i < j < k} |A_i \cap A_j \cap A_k| \;-\; \cdots \;+\; (-1)^{n+1}\, \left|\,A_1 \cap A_2 \cap \cdots \cap A_n\right|\]
The pattern is: add the cardinalities of the individual sets, subtract the cardinalities of all pairwise intersections, add the cardinalities of all triple intersections, and so on, alternating signs, until the single term \((-1)^{n+1}\,|A_1 \cap \cdots \cap A_n|\) is reached.
The cases \(n = 2\) and \(n = 3\) studied above are the first two instances of this general formula. The result for general \(n\) can be proved by mathematical induction on \(n\), using the inductive hypothesis at \(n\) together with the two-set formula applied to \(\bigcup_{i=1}^{n} A_i\) and \(A_{n+1}\). The bookkeeping is delicate but the principle is the one already familiar: every element of an intersection is initially overcounted, and the alternating signs correct the count exactly.
Proof — Inclusion–Exclusion in General
We proceed by induction on \(n\), the number of sets.
Base case (\(n = 2\)). The identity \(|A_1 \cup A_2| = |A_1| + |A_2| - |A_1 \cap A_2|\) was established in the two-set case above.
Inductive step. Fix \(n \geq 2\) and assume the formula holds for any \(n\) finite sets. We must prove it for \(n + 1\) sets \(A_1, A_2, \ldots, A_{n+1}\).
Set \(U = \bigcup_{i=1}^{n} A_i\). Applying the two-set formula to \(U\) and \(A_{n+1}\):
\[\left|\bigcup_{i=1}^{n+1} A_i\right| \;=\; |U \cup A_{n+1}| \;=\; |U| + |A_{n+1}| - |U \cap A_{n+1}| \qquad (\ast)\]
By the inductive hypothesis, \(|U|\) is given by the inclusion–exclusion formula for the \(n\) sets \(A_1, \ldots, A_n\). It remains to compute \(|U \cap A_{n+1}|\). Distributing the intersection over the union (Unit 2, Lesson 3):
\[U \cap A_{n+1} \;=\; \left(\bigcup_{i=1}^{n} A_i\right) \cap A_{n+1} \;=\; \bigcup_{i=1}^{n} (A_i \cap A_{n+1})\]
This is a union of \(n\) sets, namely \(B_i = A_i \cap A_{n+1}\) for \(i = 1, \ldots, n\). Applying the inductive hypothesis again:
\[|U \cap A_{n+1}| \;=\; \sum_{i} |B_i| - \sum_{i < j} |B_i \cap B_j| + \cdots + (-1)^{n+1} |B_1 \cap \cdots \cap B_n|\]
Substituting \(B_i = A_i \cap A_{n+1}\), each term \(B_{i_1} \cap \cdots \cap B_{i_k}\) becomes \(A_{i_1} \cap \cdots \cap A_{i_k} \cap A_{n+1}\) — that is, an intersection of \(k\) of the original sets together with \(A_{n+1}\).
Substituting both expansions (the one for \(|U|\) and the one for \(|U \cap A_{n+1}|\)) into \((\ast)\), and combining like terms, every intersection of any \(k\) of the sets \(A_1, \ldots, A_{n+1}\) appears with the sign \((-1)^{k+1}\):
Intersections of \(k\) sets not involving \(A_{n+1}\) come from \(|U|\), with sign \((-1)^{k+1}\).
The single term \(|A_{n+1}|\) appears in \((\ast)\) with sign \(+1 = (-1)^{1+1}\).
Intersections involving \(A_{n+1}\) and \(k - 1\) of the others come from \(-|U \cap A_{n+1}|\) with sign \(-(-1)^{(k-1)+1} = (-1)^{k+1}\).
Hence every \(k\)-fold intersection of the sets \(A_1, \ldots, A_{n+1}\) appears with sign \((-1)^{k+1}\), which is precisely the inclusion–exclusion formula for \(n + 1\) sets.
By the Principle of Mathematical Induction, the formula holds for every \(n \geq 2\). \(\blacksquare\)
Connection to Computer Science
Inclusion–exclusion is one of the standard techniques used by databases to count results when a query asks “how many records satisfy condition A or condition B?”. Without correcting for the records satisfying both conditions, the answer would be too large. The same correction is at work whenever a search engine reports the total number of pages matching one keyword or another.
Exercise 1
For each set, determine the cardinality.
Exercise 2
Apply the inclusion–exclusion principle to count.
Exercise 3
Decide whether each statement is true.