A set is an unordered collection of distinct elements. In computer science, sets underpin formal language theory.
3 ∈ {1,2,3}4 ∉ {1,2,3}{}A ⊆ B means every element of A is in BA = {a, b, c} |A| = 3
B = {} |B| = 0 (empty set)
C = {1,2,3,4} |C| = 4
In formal language theory:
A regular expression (regex) is a compact notation for defining a regular language (the class of languages recognised by FSMs).
| Operator | Symbol | Meaning | Example |
|---|---|---|---|
| Concatenation | ab | a followed by b | ab → {"ab"} |
| Alternation (OR) | a|b | a or b | a|b → {"a","b"} |
| Kleene star | a* | Zero or more a's | a* → {"", "a", "aa", "aaa",...} |
| Kleene plus | a+ | One or more a's | a+ → {"a", "aa", "aaa",...} |
| Optional | a? | Zero or one a | a? → {"", "a"} |
| Grouping | (ab)* | Zero or more "ab" | (ab)* → {"", "ab", "abab",...} |
// All binary strings ending in 1:
(0|1)*1
// Strings of one or more a's followed by one or more b's:
a+b+
// All strings over {a,b}:
(a|b)*
// Binary strings of even length:
((0|1)(0|1))*
// Valid simple email pattern (simplified):
[a-z]+@[a-z]+\.[a-z]+
A regular language is any language that can be:
These three representations are equivalent — they all describe exactly the same class of languages.
| Regular | Non-regular (requires more powerful model) |
|---|---|
| Binary strings ending in 0 | Palindromes |
| Strings containing "ab" | aⁿbⁿ (equal a's and b's) |
| Identifiers in a programming language | Balanced parentheses |
| Even-length binary strings | Context-free languages (require PDA) |
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes