Courses / Computer Science I
Discrete Mathematics

Sets and Set Operations

Computer Science I 248 words Free to read

The Foundation of Sets

A set is an unordered collection of distinct objects, its elements. We write x∈Ax \in A for elementhood and x∉Ax \notin A otherwise. Sets have no order ({1,2}={2,1}\{1,2\} = \{2,1\}) and no duplicates.

Relation / SetSymbolMeaningExample
SubsetA⊆BA \subseteq BEvery element of AA is in BB{1}⊆{1,2}\{1\} \subseteq \{1,2\}
Empty Set∅\emptysetHas no elements; subset of all∅⊆A\emptyset \subseteq A
Cardinality∣A∣|A|Number of elements in AA∣{a,b,c}∣=3|\{a,b,c\}| = 3

Set Operations & Logic

Operations combine sets just like boolean logic (Union=OR, Intersection=AND, Complement=NOT).

OperationNotationDefinitionLogic Mirror
UnionA∪BA \cup BIn AA or BB (or both)OR
IntersectionA∩BA \cap BIn both AA and BBAND
DifferenceA∖BA \setminus BIn AA, not in BBA AND NOT B
ComplementA‾\overline{A}In universe, not in AANOT

De Morgan's laws: A∪B‾=A‾∩B‾\overline{A \cup B} = \overline{A} \cap \overline{B} and A∩B‾=A‾∪B‾\overline{A \cap B} = \overline{A} \cup \overline{B}.

Inclusion-exclusion: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. Pitfall: Do not forget to subtract the overlap, or you count it twice.

Sets and Set Operations

Practise this lesson

Try the questions below, free, answers included. The full set, with its interactive scenes, is in the Tryals app.

9practice questions
2interactive scenes

Discrete Mathematics