Sub topic 1
Alphabets, Strings, and Languages
Prerequisites
Assume you know basic set operations such as union, intersection, and complement. You should also be comfortable with sequences, functions, and simple proofs by induction or contradiction.
Alphabets and Strings
An alphabet is a finite, nonempty set of symbols. It is usually written as Σ. For example:
- Σ = {0, 1} is a binary alphabet.
- Σ = {a, b, c} is an alphabet of three letters.
- Σ = {x, y} is an alphabet whose symbols are
xandy.
A string is a finite sequence of symbols from an alphabet. If Σ = {0, 1}, then 0101 is a string over Σ. The symbols in a string may repeat.
The empty string, written ε, contains no symbols. It is a string over every alphabet. Its length is zero. For a string w, its length is written |w|. Therefore, |0101| = 4 and |ε| = 0.
The set of all finite strings over Σ is written Σ*. It includes the empty string. The set of all nonempty strings is written Σ+, so:
- Σ* = {ε} ∪ Σ+
- Σ+ = Σ* − {ε}
For Σ = {a, b}, both abba and ε belong to Σ. A string such as abc does not belong to Σ because c is not in the alphabet.
Operations on Strings
If u and v are strings, their concatenation is the string formed by placing v after u. It is written uv. For example:
- If u =
aband v =ba, then uv =abba. - εu = uε = u.
Concatenation is associative, so (uv)w = u(vw). It is generally not commutative: uv may differ from vu.
The reversal of w, written wᴿ, lists its symbols in reverse order. If w = abc, then wᴿ = cba. The empty string reverses to itself.
A string x is a prefix of w if w = xy for some string y. Similarly, x is a suffix of w if w = yx. The empty string is both a prefix and a suffix of every string.
Languages and Language Operations
A language over Σ is any set of strings in Σ*. A language may be finite or infinite. For example:
L = {w ∈ {0, 1}* : w ends with 1}
This language contains 1, 01, and 1101, but not ε or 100.
For languages A and B, common operations include:
| Operation | Definition |
|---|---|
| Union | A ∪ B = strings in A or B |
| Intersection | A ∩ B = strings in both A and B |
| Concatenation | AB = {xy : x ∈ A and y ∈ B} |
| Kleene star | A* = zero or more concatenations of strings from A |
| Complement | Σ* − A, when the reference alphabet is Σ |
The Kleene star always includes ε because zero repetitions are allowed. If A = {ab}, then A = {ε, ab, abab, ababab, ...}. If A = {a, b}, then A = {a, b}*, all finite strings over {a, b}.
A useful implementation reflects the definition directly:
def ends_with_one(w):
return len(w) > 0 and w[-1] == "1"
for word in ["", "1", "01", "100"]:
print(word, ends_with_one(word))The function checks membership in the language of nonempty binary strings ending in 1.
Exercise
Let A = {a, ab} and B = {b}. List every string in AB and decide whether ε belongs to AB.
Show answer
AB = {ab, abb}. The empty string does not belong to AB because neither A nor B contains ε.