CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 0 · Foundations

Lesson 0.2.1 · Item 2 of 91

Sets

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. What does it mean for a machine to accept an input?
    Stuck? Peek at 0.1.1 What “computation” means
    • Machine: reads a finite input symbol by symbol, changes mode, ends with yes (accept) / no (reject) — or may never end.
    • Decision problem: a question whose answer is yes or no for every input.
    • Machines differ by memory: finite modes → pile of plates → endless notebook → beyond all machines.
    • Finite memory works iff the fact you must carry stays bounded (even/odd, remainder, “seen x?”). Unbounded counts/comparisons break it.

    Read lesson 0.1.1

  2. Why can’t a fixed-mode machine check whether an input has equally many a’s and b’s?
    Stuck? Peek at 0.1.1 What “computation” means
    • Machine: reads a finite input symbol by symbol, changes mode, ends with yes (accept) / no (reject) — or may never end.
    • Decision problem: a question whose answer is yes or no for every input.
    • Machines differ by memory: finite modes → pile of plates → endless notebook → beyond all machines.
    • Finite memory works iff the fact you must carry stays bounded (even/odd, remainder, “seen x?”). Unbounded counts/comparisons break it.

    Read lesson 0.1.1

  3. What is a decision problem?
    Stuck? Peek at 0.1.1 What “computation” means
    • Machine: reads a finite input symbol by symbol, changes mode, ends with yes (accept) / no (reject) — or may never end.
    • Decision problem: a question whose answer is yes or no for every input.
    • Machines differ by memory: finite modes → pile of plates → endless notebook → beyond all machines.
    • Finite memory works iff the fact you must carry stays bounded (even/odd, remainder, “seen x?”). Unbounded counts/comparisons break it.

    Read lesson 0.1.1

The Hook

A spam filter keeps a list of blocked email addresses. Your phone keeps a list of contacts. A machine that “says yes” keeps — in effect — a collection of all the inputs it says yes to. Before we can talk about all inputs a machine accepts, we need the language of collections. That language is sets, and every later definition in TOC is written in it.

Predict First

A set has 3 elements, say {red, green, blue}. How many different sub-collections can you pick from it — counting “pick nothing” and “pick everything”?

Core Concept

Prediction check

Answer: 8. For each of the 3 elements you decide independently “in” or “out”: 2 × 2 × 2 = 2³ = 8. The list: {}, {red}, {green}, {blue}, {red,green}, {red,blue}, {green,blue}, {red,green,blue}. This 2ⁿ count will come back many times (for example, when a machine with n modes is converted into a machine whose modes are groups of the old modes).

red
in or out: 2
×
green
in or out: 2
×
blue
in or out: 2
=
subsets
2 × 2 × 2 = 8
One independent in/out switch per element.

Set and membership

Set: an unordered collection of distinct objects, called its elements.
  • Write elements in braces: A = {1, 2, 3}.
  • Order doesn’t matter: {1,2,3} = {3,1,2}.
  • Repeats don’t count: {1,1,2} = {1,2}.
  • Membership: x ∈ A means “x is an element of A”; x ∉ A means it isn’t. 2 ∈ {1,2,3}, 5 ∉ {1,2,3}.
  • Set-builder form: {x | x is even and 0 ≤ x ≤ 6} = {0, 2, 4, 6}. Read “|” as “such that”.
2 ∈ {1,2,3}
2 is an element
5 ∉ {1,2,3}
not an element
{1,2,3} = {3,1,2}
order does not matter
{1,1,2} = {1,2}
repeats do not count
Membership is about single elements.

The empty set

The set with no elements is the empty set, written ∅ or {}. Careful: {∅} is not empty — it is a set containing one element, and that element happens to be the empty set. Think of an empty box (∅) versus a box containing an empty box ({∅}).

∅ = { }
an empty box — 0 elements
{∅}
a box holding an empty box — 1 element
The most common one-mark trap in this whole subject.

Subset

A ⊆ B (A is a subset of B): every element of A is also in B.
  • {1,2} ⊆ {1,2,3}. Also {1,2,3} ⊆ {1,2,3} (every set is a subset of itself).
  • ∅ ⊆ every set (there is nothing in ∅ that could fail to be in B).
  • Proper subset A ⊂ B: A ⊆ B and A ≠ B. {1,2} ⊂ {1,2,3}, but {1,2,3} is not a proper subset of itself.
  • Equality: A = B exactly when A ⊆ B and B ⊆ A. This “prove both directions” idea is how you prove two sets equal.
B = {1,2,3}
A = {1,2} A ⊆ B, and A ⊂ B (proper)
∅ inside every set
Subset = a box drawn inside another box.

Union, intersection, difference

  • Union A ∪ B = everything in A or B (or both).
  • Intersection A ∩ B = everything in both.
  • Difference A − B (also written A \ B) = in A but not in B.

With A = {1,2,3,4}, B = {3,4,5}: A ∪ B = {1,2,3,4,5}; A ∩ B = {3,4}; A − B = {1,2}; B − A = {5}. Note A − B ≠ B − A in general.

Two sets are disjoint if A ∩ B = ∅.

Tap each operation to see which region it shades. U = {1,…,6}.
Tap each operation to see which region it shades. U = {1,…,6}.

Universe and complement

Usually all sets in a discussion live inside one big set, the universe U. The complement of A, written A̅ (or Aᶜ, or A′), is U − A: everything in the universe that is not in A.

If U = {1,…,6} and A = {2,4,6}, then A̅ = {1,3,5}. Complement always depends on the universe — this matters a lot later, when “the universe” will be all possible inputs.

De Morgan’s laws: (A ∪ B)̅ = A̅ ∩ B̅ and (A ∩ B)̅ = A̅ ∪ B̅. Also A − B = A ∩ B̅. Memorize this last one: it turns difference into intersection + complement.

Complement shades everything outside — including region U. De Morgan: the two middle buttons shade the same region.
Complement shades everything outside — including region U. De Morgan: the two middle buttons shade the same region.

Cardinality and counting

The cardinality |A| is the number of elements. |{a,b,c}| = 3, |∅| = 0, |{∅}| = 1.

Inclusion–exclusion: |A ∪ B| = |A| + |B| − |A ∩ B|. (You subtract the overlap because you counted it twice.)

Sets can also be infinite, like the set of all natural numbers ℕ = {0, 1, 2, …}.

Inclusion–exclusion: the overlap was counted twice, so subtract it once.
Inclusion–exclusion: the overlap was counted twice, so subtract it once.

Power set

Power set P(A) (also written 2^A): the set of all subsets of A. If |A| = n then |P(A)| = 2ⁿ.

P({1,2}) = {∅, {1}, {2}, {1,2}} — four elements. P(∅) = {∅}, which has 1 element (2⁰ = 1), not 0.

The power set of {r, g, b} is literally a cube. Drag to rotate it.
The power set of {r, g, b} is literally a cube. Drag to rotate it.

Ordered pairs and the Cartesian product

Sometimes order matters. An ordered pair (x, y) has a first and second entry: (1,2) ≠ (2,1). The Cartesian product A × B is the set of all pairs (a, b) with a ∈ A and b ∈ B.

{p,q} × {0,1} = {(p,0), (p,1), (q,0), (q,1)}. In general |A × B| = |A| · |B|. We will use this to describe a machine’s rules: “in mode p, reading symbol 0, go to …” is a rule for the pair (p, 0).

×01
p(p, 0)(p, 1)
q(q, 0)(q, 1)
{p,q} × {0,1}: every row paired with every column — 2 × 2 = 4 ordered pairs.

Putting it together

  • ∈ is about one element, ⊆ about a whole set; ∅ ⊆ every set; ∅ ≠ {∅}.
  • Union, intersection, difference and complement are just shaded regions; A − B = A ∩ B̅ and De Morgan swaps ∪ and ∩ under complement.
  • |P(A)| = 2^|A| (a switch per element), |A × B| = |A|·|B|, |A ∪ B| = |A| + |B| − |A ∩ B|.

Visual

U = {1,2,3,4,5,6}      A = {1,2,3,4}      B = {3,4,5}
 ┌──────────────────────────────────────────────┐ U
 │     ┌───────────────┐                        │
 │     │ A    1  2  ┌──┼──────────┐             │
 │     │            │ 3│ 4        │             │
 │     │            │  │   A∩B    │  5    B     │
 │     └────────────┼──┘          │             │
 │                  └─────────────┘        6    │  ← 6 is in neither
 └──────────────────────────────────────────────┘
 A∪B = {1,2,3,4,5}   A∩B = {3,4}   A−B = {1,2}   B−A = {5}
 Ā = {5,6}           B̄ = {1,2,6}   (A∪B)̄ = {6} = Ā ∩ B̄ ✓ De Morgan

Power set of {a,b,c} by the “in/out” switches:

a b c   subset          a b c   subset
0 0 0   ∅               1 0 0   {a}
0 0 1   {c}             1 0 1   {a,c}
0 1 0   {b}             1 1 0   {a,b}
0 1 1   {b,c}           1 1 1   {a,b,c}      → 2³ = 8 subsets

Worked Examples

Easy

Let A = {a, b, c}. Is ∅ ∈ A? Is ∅ ⊆ A? Is {a} ∈ A? Is {a} ⊆ A?

Show the full solution

∅ ∈ A: no (A’s elements are a, b, c; the empty set is not one of them). ∅ ⊆ A: yes (always). {a} ∈ A: no ({a} is a set; A contains the letter a, not the set {a}). {a} ⊆ A: yes. The ∈ vs ⊆ distinction is the most common slip.

Medium

In a class of 60, 35 study TOC, 28 study OS, and 10 study both. How many study neither?

Show the full solution

|TOC ∪ OS| = 35 + 28 − 10 = 53. Neither = 60 − 53 = 7. That is |(TOC ∪ OS)̅| with universe = the class.

GATE-level

Let A = {1, 2}. Find |P(P(A))| and |P(A × A)|.

Show the full solution

|A| = 2 so |P(A)| = 2² = 4, so |P(P(A))| = 2⁴ = 16. |A × A| = 2·2 = 4 so |P(A × A)| = 2⁴ = 16. Both 16 — and if |A| = 3: |P(P(A))| = 2⁸ = 256 while |P(A×A)| = 2⁹ = 512. Always compute the inner cardinality first.

GATE Traps

  • ∅ vs {∅}: |∅| = 0 but |{∅}| = 1. P(∅) = {∅} has one element.
  • ∈ vs ⊆: “x ∈ A” is about one element; “X ⊆ A” is about a whole set. {a} ⊆ {a,b} but {a} ∉ {a,b}.
  • Complement depends on the universe. When later the universe is “all possible inputs”, the complement includes very long and very short inputs you might forget.
  • A − B ≠ B − A. And A − B = A ∩ B̅.

Memory Hook

Power set = a row of light switches, one per element: n switches → 2ⁿ patterns.

Connect the Dots

Sets let us name “all the inputs a machine accepts” as one object. Next we need a way to describe rules: “given this mode and this symbol, go to that mode”. That is what a function is, and grouping modes that “behave the same” needs equivalence relations.

Self-Test

  1. MCQ

    Which statement is FALSE?

    1. ∅ ⊆ {1,2}
    2. ∅ ∈ {∅, 1}
    3. |{∅}| = 0
    4. {1} ⊆ {1,2}
  2. NAT

    If |A| = 4, how many subsets of A contain at least one element?

    Write your answer before opening the key.

  3. MSQ

    Let U = {1,…,8}, A = {1,2,3,4}, B = {3,4,5,6}. Which are correct?

    1. A − B = {1,2}
    2. A̅ ∩ B̅ = {7,8}
    3. A ∩ B̅ = {1,2}
    4. |A ∪ B| = 8
  4. NAT

    If |A| = 3 and |B| = 2, what is |P(A × B)|?

    Write your answer before opening the key.

  5. MCQ

    Which is equal to A − B for every A, B inside universe U?

    1. A ∪ B̅
    2. A ∩ B̅
    3. A̅ ∩ B
    4. (A ∩ B)̅

Rule Card

  • x ∈ A (element) vs X ⊆ A (subset). ∅ ⊆ every set. A = B ⇔ A ⊆ B and B ⊆ A.
  • A ∪ B, A ∩ B, A − B = A ∩ B̅, A̅ = U − A. De Morgan: (A∪B)̅ = A̅∩B̅, (A∩B)̅ = A̅∪B̅.
  • |A ∪ B| = |A| + |B| − |A ∩ B|. |A × B| = |A|·|B|. |P(A)| = 2^|A|.
  • |∅| = 0, |{∅}| = 1, P(∅) = {∅}.

Concept Ledger

  • set, element, ∈, ∉
  • empty set ∅
  • subset ⊆, proper subset ⊂
  • union ∪, intersection ∩, difference −
  • universe U, complement A̅
  • De Morgan’s laws
  • cardinality |A|
  • power set P(A) = 2^A
  • ordered pair, Cartesian product A × B
  • finite / infinite set
  • disjoint sets

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. The machine finishes and says yes.
  2. It must remember the difference #a − #b, which is unbounded; a fixed list of modes cannot hold every value.
  3. A question about inputs whose answer is always yes or no.

Self-test answers

  1. C — {∅} contains exactly one element (the empty set), so its cardinality is 1.
    • A: True — the empty set is a subset of every set.
    • B: True — ∅ is listed as an element.
    • D: True — 1 is in {1,2}.
  2. 15 — All subsets: 2⁴ = 16. Remove the empty set: 15.
  3. ABC — A∪B = {1..6} so its complement {7,8} = A̅ ∩ B̅ (De Morgan). A ∩ B̅ = A − B = {1,2}.
    • D: |A ∪ B| = 4 + 4 − 2 = 6.
  4. 64 — |A × B| = 6, so the power set has 2⁶ = 64 elements.
  5. B — Elements in A and not in B = A ∩ B̅.
    • A: A ∪ B̅ also contains things outside A.
    • C: That is B − A.
    • D: That contains everything outside A ∩ B, including things not in A.

Flashcards

  1. |P(A)| when |A| = n?
    Reveal answer2ⁿ
  2. ∅ vs {∅} — cardinalities?
    Reveal answer|∅| = 0, |{∅}| = 1
  3. Write A − B using ∩ and complement.
    Reveal answerA ∩ B̅
  4. De Morgan’s laws for sets
    Reveal answer(A∪B)̅ = A̅ ∩ B̅ and (A∩B)̅ = A̅ ∪ B̅
  5. |A ∪ B| = ?
    Reveal answer|A| + |B| − |A ∩ B|
  6. |A × B| = ?
    Reveal answer|A| · |B|

Exam shortcuts

  • Nested power sets: compute from the inside out. |P(P(P(∅)))| = 2^(2^(2^0)) = 2^(2^1) = 2² = 4.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.