CS 121 › Lesson 1 of 12

Sets, Relations & Functions

Lesson 1 · OKSTEM College · AS Computer Science

Sets, Relations & Functions

A set is an unordered collection of distinct elements. Sets are the foundation of nearly every area of mathematics and computer science.

Set Notation

A = {1, 2, 3, 4, 5} # Roster notation B = {x | x is even, 1≤x≤10} # Set-builder notation ℕ = {0, 1, 2, 3, ...} # Natural numbers ℤ = {..., -2, -1, 0, 1, 2, ...} # Integers

Set Operations

OperationSymbolMeaning
UnionA ∪ BElements in A or B (or both)
IntersectionA ∩ BElements in both A and B
DifferenceA − BElements in A but not B
ComplementAᶜElements NOT in A (relative to universe U)
SubsetA ⊆ BEvery element of A is in B
Power Set𝒫(A)Set of ALL subsets of A

Power set size: If |A| = n, then |𝒫(A)| = 2ⁿ. A set with 3 elements has 8 subsets (including ∅ and A itself).

Functions

A function f: A → B assigns exactly one element of B to each element of A.

Worked Example — Power Set of {a, b, c}

Start: A = {a, b, c}, |A| = 3, so |𝒫(A)| = 2³ = 8
List subsets by size 0: {∅}
Size 1: {a}, {b}, {c}
Size 2: {a,b}, {a,c}, {b,c}
Size 3: {a,b,c}
Total = 1+3+3+1 = 8 ✓

Lab — Venn Diagram Explorer

Knowledge Check

Which set operation gives elements in A OR B (or both)?

If |A| = 4, how many subsets does A have?

A ∩ B contains

A function f: A→B is injective if

A ⊆ B means

Next →