6. Control questions and tasks / Контрольні запитання і завдання
Understanding of sets
- Define a set. What two properties distinguish a set from an arbitrary
list, and how does your implementation enforce each of them?
- What is the cardinality of a set? What is ∣∅∣?
- Why do {1,2,2,3} and {1,2,3} denote the same set? Why do
{1,2,3} and {3,2,1}?
- How do you test whether two sets are equal when they are stored as lists
in an arbitrary order?
The operations
- Give the formal definition of A∪B, A∩B, A∖B, and
A.
- Why does the complement require a universal set U, while union,
intersection, and difference do not?
- Express A∖B using intersection and complement. (Hint: relative
to a universe U, A∖B=A∩B.)
- Which of the operations are commutative? Is A∖B=B∖A in general? Give a counterexample.
- State the De Morgan laws for sets: A∪B=? and
A∩B=?
Implementation and complexity
- In your implementation, what is the time complexity of
containsElement? Of
union? How would a hash-based structure change these?
- Why must the set operations work regardless of the element type (integers,
strings, …)? What does your code rely on to compare elements?
- Why should each operation return a new set rather than modify its
arguments?
Tasks by hand
- Let A={1,2,3,4}, B={3,4,5}, U={1,2,3,4,5,6}. Compute
A∪B, A∩B, A∖B, B∖A, and A.
- With A={1,2,3}, B={3,4,5}, C={5,6,7}, evaluate
A intersection B union C step by step and confirm the result
{3,5,6,7} from 4task.md.
- For the same sets, evaluate
A union B difference C left to right. What is
the result?
Laboratory/Laboratory1/6questions.md · 2.0 KB · updated 2026-07-31 21:14