Theory of computation · A level · AQA 7517 4.4.2.2 · about 20 min
Set notation and comprehension, finite and countably infinite sets, cardinality, Cartesian product, subsets, union, intersection and difference.
[1 mark]A = {3, 5, 7} and B = {a, b, c, d}. What is |A × B|?
[1 mark]A = {1, 2, 3, 4} and B = {3, 4, 5}. List A \ B (the difference), as numbers separated by commas in ascending order.
[1 mark]Which set is {2x | x ∈ ℕ ∧ x < 4}?
[1 mark]Which of these sets are countably infinite?
Tick every answer that is true.
[1 mark]A = {1, 3, 5}. Which statement is false?
[1 mark]What does this program print?
A = {1, 3, 7, 9}
B = {2, 3, 9}
print(sorted(A | B))
print(sorted(A & B))
print(len(A - B), len(B - A))[1, 2, 3, 7, 9] [3, 9] 2 1
Union has every member of either set; intersection only those in both. A - B = {1, 7} and B - A = {2}.
Two robots patrolled the same room and logged the marker ids they saw, with repeats. Let A be the set of ids robot A saw and B the set robot B saw.
- Start from the two lists in the starter. Do not type any of the answers.
- Print exactly these eight lines, in this order. A list of ids is written in ascending order separated by single spaces:
1. A: then the members of A
2. B: then the members of B
3. union: then the members of A ∪ B
4. intersection: then the members of A ∩ B
5. A minus B: then the members of A \ B
6. pairs: then the cardinality of A × B, as a whole number
7. subset: then True or False: whether {7, 9} is a proper subset of A
8. even: then the members of {x | x ∈ A ∪ B ∧ x is even}, built with a set comprehension
For example, if A were {2, 5} the first line would be A: 2 5.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() seen_by_a = [3, 7, 1, 7, 9, 3] seen_by_b = [7, 2, 9, 9, 4]
The hint students can ask for: Turn each list into a set first, so the repeats disappear. Each line is then one set operation or one comparison. To print a set in the required form, put it in order and join the numbers as text. The number of pairs in a Cartesian product is the product of the two cardinalities.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
seen_by_a = [3, 7, 1, 7, 9, 3]
seen_by_b = [7, 2, 9, 9, 4]
def show(s):
return " ".join(str(x) for x in sorted(s))
A = set(seen_by_a)
B = set(seen_by_b)
print("A:", show(A))
print("B:", show(B))
print("union:", show(A | B))
print("intersection:", show(A & B))
print("A minus B:", show(A - B))
print("pairs:", len(A) * len(B))
print("subset:", {7, 9} < A)
print("even:", show({x for x in A | B if x % 2 == 0}))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.