A set is a collection of distinct objects. Sets are the base of all discrete mathematics, and they appear in databases, programming and logic.

Basic ideas

A set is written in curly braces: A = {1, 2, 3, 4}. We write 3 ∈ A (3 belongs to A) and 7 ∉ A. The empty set ∅ has no elements. A set can be given by listing, or by a rule: B = {x | x is an even number less than 10}.

  • Subset: A ⊆ B if every element of A is in B. Proper subset: A ⊂ B if also A ≠ B.
  • Universal set (U): the set of everything under discussion.
  • Power set P(A): the set of all subsets of A. If A has n elements, P(A) has 2ⁿ elements. For A = {a, b}: P(A) = {∅, {a}, {b}, {a, b}}.
  • Cardinality |A|: number of elements.

Set operations

Let U = {1, 2, 3, 4, 5, 6}, A = {1, 2, 3, 4} and B = {3, 4, 5}.

Operation Symbol Meaning Result
Union A ∪ B In A or B {1, 2, 3, 4, 5}
Intersection A ∩ B In both {3, 4}
Difference A − B In A, not in B {1, 2}
Complement A′ In U, not in A {5, 6}
Symmetric difference A ⊕ B In exactly one {1, 2, 5}

Two sets are disjoint if A ∩ B = ∅.

Properties of set operations

  • Commutative: A ∪ B = B ∪ A; A ∩ B = B ∩ A.
  • Associative: (A ∪ B) ∪ C = A ∪ (B ∪ C).
  • Distributive: A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
  • Identity: A ∪ ∅ = A; A ∩ U = A.
  • Complement: A ∪ A′ = U; A ∩ A′ = ∅.
  • De Morgan's laws: (A ∪ B)′ = A′ ∩ B′ and (A ∩ B)′ = A′ ∪ B′.
  • Inclusion-exclusion: |A ∪ B| = |A| + |B| − |A ∩ B|. Check: 4 + 3 − 2 = 5 ✓.

Venn diagrams

A Venn diagram draws each set as a circle inside a rectangle for U. The overlap of two circles is A ∩ B. Shading the parts shows what an expression means, which helps check identities such as De Morgan's laws.

Cartesian product

A × B is the set of all ordered pairs (a, b) with a ∈ A and b ∈ B. For A = {1, 2} and B = {x, y}: A × B = {(1, x), (1, y), (2, x), (2, y)}. Here |A × B| = |A| · |B| = 4. Note that A × B ≠ B × A in general.

Worked example

In a class of 60, 35 like Python and 30 like Java, and 10 like both. How many like at least one? |P ∪ J| = 35 + 30 − 10 = 55. So 5 like neither.

Common mistakes

  • Confusing ∈ (element of) with ⊆ (subset). 1 ∈ {1, 2} but {1} ⊆ {1, 2}.
  • Forgetting that the empty set is a subset of every set.

Practice questions

  1. If A = {1, 2, 3} and B = {2, 3, 4}, find A ∪ B, A ∩ B, A − B and A ⊕ B.
  2. How many subsets does a set of 5 elements have?
  3. State De Morgan's laws.
  4. If |A| = 3 and |B| = 4, what is |A × B|?
  5. In a group of 100, 60 drink tea, 50 drink coffee and 20 drink both. How many drink neither?

Answers to the practice questions

  1. {1, 2, 3, 4}; {2, 3}; {1}; {1, 4}.
  2. 2⁵ = 32.
  3. (A ∪ B)′ = A′ ∩ B′ and (A ∩ B)′ = A′ ∪ B′.
  4. 60 + 50 − 20 = 90 drink at least one, so 10 drink neither.

Sources

  • Official BCA syllabus Mathematics Foundations to Computer Science I, course code CC101, Unit I
  • Kolman, Busby and Ross, Discrete Mathematical Structures, 6th edition, Pearson