Study guide: Set Theory
Overview
A set is a collection of distinct objects where order and repetition do not matter: {1, 2, 2, 3} is the same set as {3, 2, 1}. Sets are the common language of discrete mathematics. Relations, functions, probability events and database tables are all built from them.
Set theory also teaches precision. A complement means nothing until a universal set is fixed, and “element of” and “subset of” are different relationships that are easy to confuse.
Key ideas explained
The basic operations
Union A ∪ B collects everything in either set. Intersection A ∩ B keeps what is in both. Difference A − B keeps what is in A but not B. Symmetric difference A ⊕ B keeps what is in exactly one of them. The complement A′ is everything in the universal set U that is not in A, and A − B = A ∩ B′.
Subsets and the power set
A ⊆ B means every element of A is in B. The power set P(A) is the set of all subsets of A, including ∅ and A itself, and it has 2^|A| members.
Cartesian products
A × B is the set of ordered pairs (a, b) with a in A and b in B, so |A × B| = |A|·|B|. Order matters: (1, 2) ≠ (2, 1), and A × B is generally different from B × A.
Inclusion–exclusion
|A ∪ B| = |A| + |B| − |A ∩ B|, because adding the sizes counts the overlap twice. For three sets: |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|.
Worked examples
All the basic operations on two sets
Problem. Let U = {1,…,8}, A = {1,2,3,4,5} and B = {4,5,6,7}. Find A ∪ B, A ∩ B, A − B, B − A, A ⊕ B and A′.
- Union: everything in either set gives {1,2,3,4,5,6,7}.
- Intersection: the shared elements are {4,5}.
- A − B = {1,2,3} and B − A = {6,7}.
- Symmetric difference: A − B together with B − A gives {1,2,3,6,7}.
- Complement of A in U is {6,7,8}.
- Check: |A ∪ B| = 5 + 4 − 2 = 7.
Answer. A ∪ B = {1,…,7}, A ∩ B = {4,5}, A − B = {1,2,3}, B − A = {6,7}, A ⊕ B = {1,2,3,6,7}, A′ = {6,7,8}.
Listing a power set
Problem. Find P({a, b, c}).
- The set has 3 elements, so expect 2³ = 8 subsets.
- By size: one empty set; three singletons; three pairs; one full set (1 + 3 + 3 + 1 = 8).
Answer. ∅, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}.
Enter these same values in the calculator above and compare each step with the working shown here.
Common mistakes to avoid
- Confusing ∈ with ⊆: 2 ∈ {1,2,3} and {2} ⊆ {1,2,3}, but {2} ∈ {1,2,3} is false.
- Leaving ∅ or the set itself out of the power set.
- Taking a complement without a universal set.
- Counting duplicates: {1, 1, 2} has two elements, not three.
- Assuming A × B = B × A.
Where this shows up in computer science
- SQL's UNION, INTERSECT and EXCEPT operate on result sets, and a cross join is a Cartesian product.
- In probability, events are subsets of a sample space, and P(A ∪ B) = P(A) + P(B) − P(A ∩ B) is inclusion–exclusion.
- Programming: Python's
set, permission flags and de-duplication all rely on set operations.
Test yourself
Try each question before opening the answer.
If |A| = 6, |B| = 4 and |A ∩ B| = 2, what is |A ∪ B|?
6 + 4 − 2 = 8.
How many subsets, and how many proper subsets, does a 7-element set have?
2⁷ = 128 subsets and 127 proper subsets (all except the set itself).
Is {∅} equal to ∅?
No. ∅ has no elements, while {∅} has exactly one element, namely the empty set.