Read this lesson as text
Introduction to Set Theory
Math for CS · Axiom Academy
Why sets are the foundation of computer science Set theory is not just abstract mathematics — it is the bedrock of computer science . Nearly every data structure, algorithm, and formal system you encounter is built on the language of sets. Databases store sets of records; SQL operations (UNION, INTERSECT, EXCEPT) are set operations Type systems define types as sets of allowed values Networking uses sets of IP addresses, port ranges, and routing rules Machine learning operates on sets of features, labels, and training examples A set is the simplest possible collection: a group of objects with no duplicates and no particular order. This simplicity is exactly what makes it powerful. When you write if x in my_set in Python or check Set.has(x) in JavaScript, you are performing a membership query — the fundamental operation of set theory. A relational database table is essentially a set of tuples (rows). SQL was designed with set theory baked in: Understanding set theory means understanding what your database queries actually do . In typed languages, each type defines a set of possible values : char = the set of Unicode code points Many data structures are direct implementations of mathematical sets: HashSet / set — unordered collection with O(1) membership test TreeSet — sorted set with O(log n) operations BitSet — sets of integers using bit vectors (extremely compact) Bloom filters — probabilistic set membership ("maybe in set" or "definitely not")
This is the written version of the interactive lesson above. See the full Math for CS course.