6. Control questions and tasks / Контрольні запитання і завдання
Ordered pairs and the Cartesian product
- What is an ordered pair? State the condition under which (a,b)=(c,d),
and explain why (1,2)=(2,1) while {1,2}={2,1}.
- Define the Cartesian product A×B. What is ∣A×B∣ in terms
of ∣A∣ and ∣B∣?
- Is A×B=B×A in general? When are they equal?
- What is A×∅? Justify your answer from the definition.
Relations
- Define a binary relation from A to B. What does it mean for a relation
to be a relation on a set A?
- Exactly what does
isRelationValid(relation, A, B) verify? Phrase your answer
using the words subset and A×B.
- How many distinct relations exist from A to B? Why? (Hint: a relation is
any subset of A×B.)
- What does it mean to define a relation by a predicate P(a,b)? Write the
set-builder form of such a relation.
Implementation and complexity
- How do you represent an ordered pair and a whole relation without using a
built-in tuple/set type? How are two pairs compared for equality?
- What is the time complexity of
cartesianProduct? Why can it not be faster
than O(∣A∣⋅∣B∣)?
- What is the cost of
isRelationValid with a list-based membership test, and
how would a hash-based test change it?
- In
findRelations, who decides whether the pair (a,a) is included — the
algorithm or the predicate? Explain.
Tasks by hand
- Compute A×B for A={1,2} and B={x,y}. How many pairs do
you get?
- List the relation “a<b” on the set A={1,2,3} (pairs (a,b)
with a,b∈A and a<b). How many pairs are there?
- Let A={2,3} and B={6,8,9}. Using the predicate “a divides
b”, list the pairs of A×B that satisfy it.
Laboratory/Laboratory2/6questions.md · 1.9 KB · updated 2026-07-31 21:14