Introduction to Sets
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn what a set is, the two ways to describe one, how membership and subset relationships differ, how to count the elements of a set, and how to build the power set.
This lesson brings a lot of notation at once. Nothing here is hard, but it’s worth knowing the names:
The Concept
Section titled “The Concept”A set is an unordered collection of distinct objects. The objects are called elements or members.
Two rules define everything about sets:
- Order doesn’t matter. and are the same set.
- Duplicates don’t count. is the same set as .
If order matters, you want a sequence or tuple, not a set. If repetition matters, you want a multiset.
Two ways to describe a set
Section titled “Two ways to describe a set”Roster notation lists the elements:
Set-builder notation describes them with a predicate:
The vertical bar reads “such that.” Some books use a colon instead: .
Set-builder is essential for infinite sets, where you can’t list everything:
Membership
Section titled “Membership”means “is an element of.” means “is not an element of.”
Special sets
Section titled “Special sets”The empty set has no elements:
Watch out: and are different. The first is empty. The second is a set containing one thing, which happens to be the empty set. Like an empty box versus a box containing an empty box.
Standard number sets have reserved symbols:
| Symbol | Set | Examples |
|---|---|---|
| Natural numbers | ||
| Integers | ||
| Rationals | ||
| Real numbers | ||
| Complex numbers |
(Some sources include 0 in and some don’t. Check the convention wherever you’re reading.)
The universal set is the set of all elements under consideration in a given problem. It’s context-dependent, and you need it to make sense of complements.
Subsets
Section titled “Subsets”is a subset of , written , if every element of is also in . In quantifier notation:
is a proper subset, written , if and .
Two facts that follow immediately:
- for every set . (Vacuously true: there’s no element of that could fail the condition.)
- for every set .
Set equality means mutual containment:
That’s how you prove two sets are equal: show each contains the other. It’s the set-theory version of proving a biconditional.
Element versus subset
Section titled “Element versus subset”This distinction causes more errors than anything else in this lesson. Let .
- . True, 1 is listed.
- . True, the set containing 1 is a subset.
- . False. is not one of the three listed elements.
- . True, it is literally one of the elements.
- . False. 3 is inside an element of , but is not itself an element of .
compares an object to a set. compares a set to a set.
Cardinality
Section titled “Cardinality”The cardinality of , written , is the number of elements it contains.
For , the cardinality is 3, not 4. The nested set counts as one element.
The power set
Section titled “The power set”The power set of , written , is the set of all subsets of .
For :
Note that and itself are always included.
The size follows a clean rule:
Why ? To build a subset, walk through the elements and make an independent yes-or-no decision about each one. That’s choices, times, so total. Every subset corresponds to exactly one pattern of decisions.
That’s a counting argument, and it’s your first taste of combinatorics.
For a 3-element set those decisions have a shape you already know. Each element is one axis, so the 8 subsets are the 8 corners of a cube, and walking along any edge adds or removes exactly one element:
Cartesian product
Section titled “Cartesian product”The Cartesian product is the set of all ordered pairs with the first entry from and the second from :
If and :
Size: .
Order matters here, so in general. And is exactly the coordinate plane you’ve been using since pre-algebra.
Worked Examples
Section titled “Worked Examples”Example 1: Convert between notations.
Write in roster notation.
Solution. Integers from up to but not including 3:
Cardinality 6. The asymmetric endpoints are deliberate, so read the inequalities carefully.
Example 2: Classify each statement as true or false.
Let .
Solution.
- True.
- False. The element is 3, not .
- True. Every element of (namely 3) is in .
- False. 6 is not in , so containment fails.
- True. The empty set is a subset of everything.
- True.
Example 3: Build a power set.
Find .
Solution. Organize by size, which prevents you from missing any.
- Size 0:
- Size 1:
- Size 2:
- Size 3:
That’s 8 subsets, and . Checks out. Notice the counts by size are 1, 3, 3, 1, which is a row of Pascal’s triangle. That’s not a coincidence, and you’ll see why in the combinations lesson.
Example 4: Prove set equality.
Let and . Show .
Solution. Prove containment in both directions.
: Let , so . Write . Since is even, has the form with even. So .
: Let , so with even. Then for some integer , so . So .
Both containments hold, therefore . ∎
Both sets are the multiples of 4.
Example 5: Cartesian product.
If and , what are and ?
Solution.
Power sets grow fast. That’s a real constraint in computing, where “check every subset” is usually not a viable algorithm.
Real-World Applications
Section titled “Real-World Applications”Sets are the data model underneath relational databases. A table is a set of rows, a SELECT is a filter, and a JOIN operates on a Cartesian product. The DISTINCT keyword exists precisely because sets don’t allow duplicates.
Most programming languages ship a set type (Set in JavaScript and Python, HashSet in Java and Rust) with fast membership testing. Whenever you need “have I seen this before?” a set is the right tool.
Search filters on shopping sites are set operations. Selecting two brands and one price range asks for the intersection of a union.
In practical terms, cardinality is what powers permission systems and tagging. And the power set explains why feature-flag combinations get out of hand: 10 independent flags produce 1,024 possible configurations, which is why nobody tests them all.
Retrying will remove your ✅ checkmark until you pass again.