Sets, relations & functions: practice problems with step-by-step solutions

Also called: set theory · Venn diagrams · inclusion–exclusion principle

Free Sets, relations & functions practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: Venn diagrams and subsets, inclusion–exclusion and relations, functions and counting.

Free practice problemEasy

Let A = {b, e} and B = {1, 2}. Find |A × B|.

A = {b, e}B = {1, 2}

Exact answer: a whole number, no rounding.

Next problem →

What you practise

  1. EasyVenn diagrams and subsets
  2. Mediuminclusion–exclusion and relations
  3. Hardfunctions and counting

How to solve Sets, relations & functions problems

  1. Draw a Venn diagram and decide region by region what belongs to the set expression.
  2. For counting problems, fill in the regions from the centre outwards: all sets, then pairs, then single sets, then the outside.
  3. Use inclusion–exclusion as a check: |A ∪ B| = |A| + |B| − |A ∩ B|.
  4. For a relation, test each property on every pair and give one counterexample when it fails.
  5. For a function, count the arrows arriving at each element of B: at most one means injective, at least one surjective.

Common mistakes

  • Adding |A| and |B| without subtracting the overlap.
  • Forgetting to add back the centre for three sets.
  • Swapping the exponent in the number of functions: nᵐ for m elements into n.
  • Applying g ∘ f in the wrong order: f acts first.
  • Forgetting the pairs (x, x) when counting the pairs of an equivalence relation.

Key formulas

Two sets
|A ∪ B| = |A| + |B| − |A ∩ B|
Three sets
|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|
Difference and complement
A − B = A ∩ B′, |A′| = |U| − |A|
Power set and product
|𝒫(A)| = 2|A|, |A × B| = |A|·|B|
Subsets of size k
C(n, k) = n!/(k!(n − k)!)
Functions A → B
nᵐ; injective n!/(n − m)!; surjective Σ (−1)ᵏ C(n, k)(n − k)ᵐ
Relations on n elements
2n²; reflexive 2n² − n; symmetric 2n(n+1)/2
Composition
(g ∘ f)(x) = g(f(x))

Learn Sets, relations & functions from scratch

Before this: Propositional logic & proofs

1Sets and set operations

A set is a collection of distinct elements: A = {1, 2, 3}. Order and repetition do not matter. |A| is the number of elements, and U is the universal set that contains everything under discussion.

  • A ∪ B (union): the elements in A or B or both.
  • A ∩ B (intersection): the elements in both.
  • A − B (difference): the elements of A that are not in B.
  • A′ (complement): the elements of U that are not in A.

In a Venn diagram two circles split U into four regions: only A, both, only B, and neither. Every set expression is a union of some of these regions, so you can always count it region by region.

UAB125815

Here |A| = 12 + 5 = 17, |A ∩ B| = 5, |A ∪ B| = 12 + 5 + 8 = 25 and |(A ∪ B)′| = 15.

Self-check In the diagram above, how many elements does A − B have?
  1. 12
  2. 17
  3. 25
  4. 5

Answer: 12. A − B keeps the part of A outside B: only the region with 12. The 5 in the overlap are in B as well, and 17 is all of A.

2Counting with inclusion–exclusion

Adding |A| and |B| counts the overlap twice, so subtract it once:

|A ∪ B| = |A| + |B| − |A ∩ B|

For three sets the pairwise overlaps are subtracted, but then the centre has been removed three times, so it is added back:

|A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|

In word problems it is usually safer to fill in a Venn diagram from the centre outwards: first the elements in all three sets, then each pair minus the centre, then each single set minus what is already placed.

Two other counts come up often: a set with n elements has 2ⁿ subsets (its power set 𝒫(A)), and |A × B| = |A|·|B| ordered pairs.

Self-check Of 40 students, 25 study French, 18 study German and 9 study both. How many study neither?
  1. 15
  2. 34
  3. 3
  4. 6

Answer: 6. |F ∪ G| = 25 + 18 − 9 = 34, so 40 − 34 = 6 study neither. Forgetting to subtract the 9 gives 43, which is more than the whole group.

3A worked example

Follow every step. Try to predict the next one before you open it.

Worked example

Of 60 students, 30 passed Mathematics (M), 25 Physics (P) and 20 Chemistry (C). 10 passed M and P, 8 passed M and C, 6 passed P and C, and 3 passed all three. How many passed none?

1

Centre

3 passed all three.

2

Pairs only

M and P only: 10 − 3 = 7. M and C only: 8 − 3 = 5. P and C only: 6 − 3 = 3.

3

Singles only

M only: 30 − 7 − 5 − 3 = 15. P only: 25 − 7 − 3 − 3 = 12. C only: 20 − 5 − 3 − 3 = 9.

4

Union and complement

|M ∪ P ∪ C| = 15 + 12 + 9 + 7 + 5 + 3 + 3 = 54

The formula gives the same: 30 + 25 + 20 − 10 − 8 − 6 + 3 = 54.

Answer

60 − 54 = 6 students passed none of the three.

4Relations

A relation R on a set X is a set of ordered pairs (x, y) with x and y in X. Drawn as a directed graph, each pair is an arrow and (x, x) is a loop.

  • Reflexive: (x, x) ∈ R for every x: a loop at every vertex.
  • Symmetric: (x, y) ∈ R always comes with (y, x) ∈ R.
  • Antisymmetric: (x, y) and (y, x) are both in R only when x = y.
  • Transitive: (x, y) and (y, z) in R force (x, z) ∈ R.

A relation that is reflexive, symmetric and transitive is an equivalence relation. It splits X into disjoint classes, such as the remainders 0, 1 and 2 for “x ≡ y (mod 3)”. A class with s elements contributes s² ordered pairs.

To disprove a property, one counterexample is enough; to prove it, check every pair.

Self-check R = {(1, 2), (2, 3)} on {1, 2, 3}. Which pair must be added to make R transitive?
  1. (1, 1)
  2. (1, 3)
  3. (2, 1)
  4. (3, 1)

Answer: (1, 3). (1, 2) and (2, 3) are in R, so transitivity requires (1, 3). (2, 1) would be needed for symmetry and (1, 1) for reflexivity.

5Functions

A function f: A → B gives every element of A exactly one image in B.

AB123abcd
  • Injective (one-to-one): different elements have different images; no element of B receives two arrows.
  • Surjective (onto): every element of B receives at least one arrow.
  • Bijective: both. Only then does f have an inverse f⁻¹.

The function in the figure is injective but not surjective: d receives no arrow. An injection needs |A| ≤ |B| and a surjection |A| ≥ |B|.

With |A| = m and |B| = n there are nᵐ functions and n!/(n − m)! injective ones. The composition (g ∘ f)(x) = g(f(x)) applies f first.

Self-check How many functions are there from a set with 3 elements to a set with 4 elements?
  1. 12
  2. 24
  3. 64
  4. 81

Answer: 64. Each of the 3 elements chooses one of 4 images: 4³ = 64. 3⁴ = 81 swaps the roles, 24 = 4·3·2 counts only the injective functions, and 12 = 3·4 is the size of A × B.

6Common mistakes

  • Adding |A| + |B| without subtracting the overlap.
  • Forgetting to add back the centre in three-set inclusion–exclusion.
  • Writing mⁿ instead of nᵐ for the number of functions from m elements to n elements.
  • Thinking a relation cannot be both symmetric and antisymmetric: the relation {(1, 1)} is both.
  • Applying g ∘ f in the wrong order: f acts first.

7How exam questions look

  • Easy: Venn diagrams and subsets. You count a set expression from a Venn diagram, click the region of an expression, or find the size of a power set, a Cartesian product or a family of subsets.
  • Medium: inclusion–exclusion and relations. You solve two- and three-set counting problems, count expressions from region totals, decide which property a relation has, or count the pairs needed for a closure.
  • Hard: functions and counting. You classify a function as injective, surjective or bijective, count functions, injections and surjections, evaluate compositions and inverses, and count pairs in equivalence relations.

Learn it step by step in the appLearn it step by step in the app

Worked examples

Example 1Easy

Let A = {a, b, c, x, y} and B = {1, 2, 3, 4}. Find |𝒫(A)|.

A = {a, b, c, x, y}B = {1, 2, 3, 4}

Find |𝒫(A)|

Show hints
  1. A set with k elements has 2ᵏ subsets: each element is either in a subset or not.
  2. |A| = 5, |B| = 4.
  3. |𝒫(A)| = 2|A|.
Show the answer and the step-by-step solution

Functions and counting: a function f: A → B gives every element of A exactly one image in B. f is injective (one-to-one) when different elements have different images, surjective (onto) when every element of B is an image, and bijective when both hold. With |A| = m and |B| = n there are nᵐ functions, n!/(n − m)! injective ones (m ≤ n), and by inclusion–exclusion Σ (−1)ᵏ·C(n, k)·(n − k)ᵐ surjective ones. |𝒫(A)| = 2ᵐ and |A × B| = m·n.

Sizes

|A| = 5
|B| = 4

Count

|𝒫(A)| = 25 = 32

Answer

|𝒫(A)| = 32
Example 2Medium
UMPC

Of 53 first-year students, 35 passed Mathematics (M), 28 passed Physics (P) and 29 passed Chemistry (C). 20 passed M and P, 18 passed M and C, 10 passed P and C, and 6 passed all three. How many are in none of the three sets?

|U| = 53

Find |(M ∪ P ∪ C)′|

Show hints
  1. Fill in the Venn diagram from the centre outwards: first all three, then the pairs, then the single sets.
  2. Only M and P (not C): 20 − 6 = 14. Only M: 35 − 14 − 12 − 6 = 3.
  3. At least one set: 35 + 28 + 29 − 20 − 18 − 10 + 6 = 50.
Show the answer and the step-by-step solution

Sets and Venn diagrams: A ∪ B holds the elements in A or B (or both), A ∩ B the elements in both, A − B the elements of A that are not in B, and the complement A′ everything in U that is not in A. In a Venn diagram every set expression is a union of regions, so count it region by region. Inclusion–exclusion: |A ∪ B| = |A| + |B| − |A ∩ B|, and |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|.

Centre and pairs

M ∩ P ∩ C: 6
M ∩ P only: 20 − 6 = 14
M ∩ C only: 18 − 6 = 12
P ∩ C only: 10 − 6 = 4

Single sets

M only: 35 − 14 − 12 − 6 = 3
P only: 28 − 14 − 4 − 6 = 4
C only: 29 − 12 − 4 − 6 = 7

Answer

|M ∪ P ∪ C| = 50
|(M ∪ P ∪ C)′| = 53 − 50 = 3

Answer

|(M ∪ P ∪ C)′| = 3
Example 3Hard
x12345f(x)13234g(x)51541

The functions f and g on {1, 2, 3, 4, 5} are given by their tables. Find (f ∘ g)(5).

f: 1 ↦ 1, 2 ↦ 3, 3 ↦ 2, 4 ↦ 3, 5 ↦ 4g: 1 ↦ 5, 2 ↦ 1, 3 ↦ 5, 4 ↦ 4, 5 ↦ 1

Find (f ∘ g)(5)

Show hints
  1. (f ∘ g)(x) means f(g(x)): first g, then f.
  2. The inner value is g(5) = 1.
  3. Now apply the outer function to 1.
Show the answer and the step-by-step solution

Functions and counting: a function f: A → B gives every element of A exactly one image in B. f is injective (one-to-one) when different elements have different images, surjective (onto) when every element of B is an image, and bijective when both hold. With |A| = m and |B| = n there are nᵐ functions, n!/(n − m)! injective ones (m ≤ n), and by inclusion–exclusion Σ (−1)ᵏ·C(n, k)·(n − k)ᵐ surjective ones. |𝒫(A)| = 2ᵐ and |A × B| = m·n.

Inner function

g(5) = 1

Outer function

f(1) = 1
(f ∘ g)(5) = 1

Answer

(f ∘ g)(5) = 1

Questions and answers

What is Sets, relations & functions?

A set is a collection of distinct elements: A = {1, 2, 3}. Order and repetition do not matter. |A| is the number of elements, and U is the universal set that contains everything under discussion.

In a Venn diagram two circles split U into four regions: only A, both, only B, and neither. Every set expression is a union of some of these regions, so you can always count it region by region.

How do I solve Sets, relations & functions problems step by step?
  1. Draw a Venn diagram and decide region by region what belongs to the set expression.
  2. For counting problems, fill in the regions from the centre outwards: all sets, then pairs, then single sets, then the outside.
  3. Use inclusion–exclusion as a check: |A ∪ B| = |A| + |B| − |A ∩ B|.
  4. For a relation, test each property on every pair and give one counterexample when it fails.
  5. For a function, count the arrows arriving at each element of B: at most one means injective, at least one surjective.
What are common mistakes in Sets, relations & functions?
  • Adding |A| and |B| without subtracting the overlap.
  • Forgetting to add back the centre for three sets.
  • Swapping the exponent in the number of functions: nᵐ for m elements into n.
  • Applying g ∘ f in the wrong order: f acts first.
  • Forgetting the pairs (x, x) when counting the pairs of an equivalence relation.
What do the Sets, relations & functions exercises cover?
  • Easy: Venn diagrams and subsets
  • Medium: inclusion–exclusion and relations
  • Hard: functions and counting

Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.

How practising works

  • Every problem has new values, so you learn the method instead of an answer.
  • Stuck? Open a small hint first, and the full explanation only when you need it.
  • Your progress, mistakes and saved problems are kept, so you can review before the exam.

Topics before and after this one

Learn first

Continue with

Courses with this topic

More topics in Mathematics & statistics

Printable worksheet