The Container Every Other Structure Sits In
A set is the most basic collection in mathematics: “a collection of different things,” where “the things are called elements or members of the set.” Two properties define it. Elements are distinct, so is just , and order does not matter, so . Membership is the one primitive question, written .
Sets are the substrate under nearly everything else in CS. A type is a set of values. A relation is a set of pairs. A hash set is this abstraction made concrete, and the map built on it inherits the no-duplicate-keys rule directly from the definition of a set.
Note
The payload: the boolean connectives and the set operations are the same algebra wearing two costumes. Intersection is AND, union is OR, complement is NOT. An element is in exactly when it is in AND in . Learn the truth tables and you already know the set identities, De Morgan’s laws included.
Membership, Subsets, and the Empty Set
is a subset of , written , when “every element of A is also an element of B.” If also has elements lacks, is a proper subset (). The empty set is “a set with no elements,” written or , and it is a subset of every set vacuously, since it has no element that could fail the condition.
Do not confuse membership with containment. (an element), but (a subset). The single-element set is a different object from the element .
The Operations
Given sets over some universe :
- Union : elements in , in , or in both.
- Intersection : “those elements that belong to both A and B.”
- Difference : elements in but not in .
- Complement or : everything in the universe not in , that is .
These pair off with the logical connectives one-for-one, which is why a Venn diagram (overlapping regions for each set, shaded to show an operation’s result) and a truth table encode the same information. Union shades the OR region, intersection the AND overlap, complement the outside.
Power Set and Cardinality
The cardinality of a set is “the number of its members,” written . For , .
The power set is “the set that contains all subsets of a given set,” “including the empty set and S itself.” Its size is fixed by a counting argument: each element is either in or out of a given subset, two independent choices per element, so a set of elements has exactly subsets. Wikipedia states it directly: if “then the number of all the subsets of S is .”
That is not a curiosity. It is the size of the search space every subset-enumeration algorithm walks, the reason brute-force over all feature combinations is exponential, and the same that bounds a truth table over variables. Subsets of an -set and truth assignments to booleans are the same objects counted twice.
Example
Power set of . List every subset by asking include-or-not for each element: Four subsets, matching . The empty set and the full set are always both present.
Warning
Naive set theory, taking “any definable collection is a set,” is inconsistent: Russell’s paradox asks whether the set of all sets that do not contain themselves contains itself, and either answer contradicts. The working fix is axiomatic set theory (ZFC), which restricts how sets are formed. For everyday CS the naive operations above are safe; the paradox is why “the set of everything” is not allowed.
Related Notes
- Propositional Logic - the boolean algebra that set operations mirror exactly
- Combinatorics - counting subsets, unions, and intersections (inclusion-exclusion)
- Discrete Probability - events are subsets of a sample set, and probability rules follow set rules
- Graph Theory - a graph is a set of vertices plus a set of edges
Sources
- Set (mathematics) (Wikipedia) - definitions of set, element, subset, empty set, intersection, and cardinality.
- Power set (Wikipedia) - the power set as all subsets and its cardinality of 2