Courses / Computer Science I
Discrete Mathematics

Sets and Set Operations

Computer Science I 340 words Free to read

The Foundation of Everything Discrete

A set is an unordered collection of distinct objects, its elements. We write xAx \in A for "xx is in AA" and xAx \notin A for "xx is not in AA." Sets are the bedrock of discrete mathematics — numbers, relations, functions, and even logic are all defined in terms of sets. Two features matter: a set has no order ({1,2}={2,1}\{1,2\} = \{2,1\}) and no duplicates (listing an element twice changes nothing).

Key relationships and special sets:

The operations combine sets into new sets:

These mirror boolean logic exactly: union is OR, intersection is AND, complement is NOT. So De Morgan's laws hold for sets too: AB=AB\overline{A \cup B} = \overline{A} \cap \overline{B} and AB=AB\overline{A \cap B} = \overline{A} \cup \overline{B}. A crucial counting rule is inclusion-exclusion: AB=A+BAB|A \cup B| = |A| + |B| - |A \cap B| — you add the sizes and subtract the overlap counted twice.

Common pitfall: confusing union with intersection, or forgetting the overlap in inclusion-exclusion. Union collects everything in either set; intersection keeps only what is in both. And AB|A \cup B| is not simply A+B|A| + |B| — that double-counts the shared elements, so you must subtract AB|A \cap B|.

Two overlapping set circles A and B; the lens overlap flashes in accent as it is subtracted once, illustrating |A ∪ B| = |A| + |B| − |A ∩ B|.

AB=A+BAB|A \cup B| = |A| + |B| - |A \cap B|

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
Start Computer Science I free

Discrete Mathematics