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 xAx \in A for elementhood and xAx \notin A otherwise. Sets have no order ({1,2}={2,1}\{1,2\} = \{2,1\}) and no duplicates.

Relation / SetSymbolMeaningExample
SubsetABA \subseteq BEvery element of AA is in BB{1}{1,2}\{1\} \subseteq \{1,2\}
Empty Set\emptysetHas no elements; subset of allA\emptyset \subseteq A
CardinalityA|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
UnionABA \cup BIn AA or BB (or both)OR
IntersectionABA \cap BIn both AA and BBAND
DifferenceABA \setminus BIn AA, not in BBA AND NOT B
ComplementA\overline{A}In universe, not in AANOT

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

Inclusion-exclusion: AB=A+BAB|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

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

9practice questions
2interactive scenes

Discrete Mathematics