Track progress, take quizzes and save notes on this lesson.

Free forever · no card needed

Start free
Intermediate

Sets and Formal Languages

4.4.2.2 Maths for regular expressions

Aligned to the AQA 7517 specification

Level
Intermediate
Reading time
5 min
Published
13 June 2026
Updated
1 July 2026
On this page
  1. 1.Sets and Set Notation
  2. 2.Set Operations
  3. 3.Cartesian Product
  4. 4.Formal Languages: Alphabets and Strings
  5. 5.Countable and Uncountable Sets
  6. 6.Common Exam Mistakes

Key takeaways

  • A set is an unordered collection of distinct elements, so {1, 2, 2, 3} is the same as {1, 2, 3} and cannot contain duplicates.
  • Union A ∪ B contains elements in A, B or both; intersection A ∩ B contains elements in both; complement A̅ contains all elements of the universal set U not in A.
  • The Cartesian product A × B is the set of all ordered pairs (a, b) with a ∈ A and b ∈ B, and |A × B| = |A| × |B|.
  • An alphabet Σ is a finite non-empty set of symbols, a string is a finite sequence of those symbols, and Σ* is the infinite set of all strings over Σ including the empty string ε.
  • Σ* is countable but the set of all languages over Σ is uncountable, so there are more problems than programs and most problems cannot be solved by any program.

Sets and Set Notation

A set is an unordered collection of distinct elements. Sets are fundamental to the mathematics of formal languages and computation.

Defining a set:

A = {1, 2, 3, 4, 5}          // List notation (roster notation)
B = {x | x is an even integer, 0 ≤ x ≤ 10}  // Set-builder notation
  = {0, 2, 4, 6, 8, 10}

Key set notation:

| Symbol | Meaning | Example | | --------------------- | ---------------------------------------------- | ------------------------------ | -------------------------------------------- | --- | ----------- | ---- | | | is a member of set | is True | | | is not a member of | is True | | or | Empty set — contains no elements | | | | Natural numbers | | | | Integers | | | | Cardinality (size/number of elements) of | |

Sets do not have duplicate elements: .

Set Operations

Three fundamental operations on sets:

Union () — elements in , , or both:

Intersection () — elements in both and :

Complement ( or ) — all elements NOT in (relative to the universal set ):

If and , then .

Universal set () — the set of all elements under consideration in a given context. Every other set in that context is a subset of .

Cartesian Product

The Cartesian product of two sets and is the set of all ordered pairs where and :

Example:

.

Why it matters in computing: the Cartesian product defines transition tables for finite state machines. A transition function maps (state, input symbol) pairs to new states — is a Cartesian product.

Formal Languages: Alphabets and Strings

A formal language is a set of strings defined over an alphabet.

Alphabet () — a finite, non-empty set of symbols. Examples:

  • Binary alphabet:
  • Lowercase letters:
  • DNA bases:

String — a finite sequence of symbols from . Examples over :

  • a, b, aa, ab, ba, bb, aab, …

Empty string () — the string with zero symbols. .

— the set of all possible strings over , including . This is an infinite set even when is finite.

Language () — any subset of . Examples:

  • — a finite language
  • — strings of a's followed by b's (infinite language)
  • The set of all valid Python programs over the ASCII alphabet

How much of this have you taken in?

Quiz yourself on this section, free, no card needed.

Test myself

Countable and Uncountable Sets

AQA requires awareness of the following distinction:

Countable set — a set whose elements can be listed in a sequence (put into one-to-one correspondence with ).

  • Examples: , , (rationals), the set of all strings over any finite alphabet ()

Uncountable set — a set too large to be listed in any sequence; cannot be put into one-to-one correspondence with .

  • Examples: (real numbers), the set of all possible languages over an alphabet

Significance for computing:

  • is countable — there are countably many possible programs
  • The set of all languages over is uncountable — there are uncountably many possible problems
  • Therefore, most problems cannot be solved by any program — there are more problems than programs

(Extra context — not required beyond AQA 7517 awareness level) This is formalized by Cantor's diagonal argument — the same technique that proves the set of real numbers is uncountable and underpins the proof that the halting problem is unsolvable.

Common Exam Mistakes

1. Including duplicates in a set

Sets cannot contain duplicate elements. is the same as . Listing duplicates in a set answer shows a misunderstanding of what a set is.

2. Confusing and

is the empty set — it contains no elements; . is a set containing one element (the empty set); . These are different.

3. Confusing union and intersection symbols

(union) looks like a "U" — Union. (intersection) looks like an inverted U — the elements in common. Getting these backwards is a common notation error.

4. Treating ε as a character in the alphabet

is not a symbol in — it represents the absence of any symbol. The string has length 0. Adding it to a string leaves the string unchanged: .

5. Forgetting ε in

includes the empty string . If the question asks for all strings of length 0 or more over , the empty string must be included.

Key terms

Set
An unordered collection of distinct elements containing no duplicates.
Union (∪)
The set of all elements that are in A, in B, or in both.
Intersection (∩)
The set of all elements that are in both A and B.
Complement (A̅)
The set of all elements of the universal set U that are not in A.
Universal set (U)
The set of all elements under consideration in a given context, of which every other set is a subset.
Cardinality
The size of a set, that is the number of elements it contains.
Cartesian product (A × B)
The set of all ordered pairs (a, b) where a ∈ A and b ∈ B.
Alphabet (Σ)
A finite, non-empty set of symbols over which strings are formed.
String
A finite sequence of symbols drawn from an alphabet Σ.
Empty string (ε)
The string with zero symbols, so |ε| = 0; it is not itself a symbol in Σ.
Σ*
The set of all possible strings over Σ including ε; infinite even when Σ is finite.
Countable set
A set whose elements can be listed in a sequence, that is put into one-to-one correspondence with ℕ.

Frequently asked questions

∅ is the empty set, which contains no elements, so |∅| = 0. {∅} is a set containing one element, the empty set itself, so |{∅}| = 1. They are different.

Σ* is the set of all possible strings over the alphabet Σ, including the empty string ε. It is an infinite set even when Σ is finite. A language is any subset of Σ*.

Because Σ* is countable, meaning there are countably many possible programs, but the set of all languages over Σ is uncountable, meaning there are uncountably many possible problems. There are therefore more problems than programs, so most problems cannot be solved by any program.

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Prev

Finite State Machines

Next

Regular Expressions

Related lessons

9 min

8 min

Lesson

Regular Expressions

A-Level Computer Science · AQA 7517

1 month ago

6 min

Top students don’t revise more. They revise what counts.

Start revising free

Free to start. No card needed.