Raw

6. Control questions and tasks / Контрольні запитання і завдання

Ordered pairs and the Cartesian product

  1. What is an ordered pair? State the condition under which (a,b)=(c,d)(a,b) = (c,d), and explain why (1,2)(2,1)(1,2) \neq (2,1) while {1,2}={2,1}\{1,2\} = \{2,1\}.
  2. Define the Cartesian product A×BA \times B. What is A×B|A \times B| in terms of A|A| and B|B|?
  3. Is A×B=B×AA \times B = B \times A in general? When are they equal?
  4. What is A×A \times \varnothing? Justify your answer from the definition.

Relations

  1. Define a binary relation from AA to BB. What does it mean for a relation to be a relation on a set AA?
  2. Exactly what does isRelationValid(relation, A, B) verify? Phrase your answer using the words subset and A×BA \times B.
  3. How many distinct relations exist from AA to BB? Why? (Hint: a relation is any subset of A×BA \times B.)
  4. What does it mean to define a relation by a predicate P(a,b)P(a,b)? Write the set-builder form of such a relation.

Implementation and complexity

  1. 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?
  2. What is the time complexity of cartesianProduct? Why can it not be faster than O(AB)O(|A|\cdot|B|)?
  3. What is the cost of isRelationValid with a list-based membership test, and how would a hash-based test change it?
  4. In findRelations, who decides whether the pair (a,a)(a,a) is included — the algorithm or the predicate? Explain.

Tasks by hand

  1. Compute A×BA \times B for A={1,2}A = \{1,2\} and B={x,y}B = \{x, y\}. How many pairs do you get?
  2. List the relation “a<ba < bon the set A={1,2,3}A = \{1,2,3\} (pairs (a,b)(a,b) with a,bAa,b \in A and a<ba < b). How many pairs are there?
  3. Let A={2,3}A = \{2, 3\} and B={6,8,9}B = \{6, 8, 9\}. Using the predicate “aa divides bb”, list the pairs of A×BA \times B that satisfy it.

Laboratory/Laboratory2/6questions.md · 1.9 KB · updated 2026-07-31 21:14