Sub topic 1
Alphabets, Strings, and Languages
Prerequisites
Assume you know basic set notation, finite automata, and regular expressions. You should also know that a language is a set of strings and that a finite automaton reads one input symbol at a time.
Alphabets and strings
An alphabet is a finite, nonempty set of symbols. We usually write an alphabet as \( \Sigma \). For example:
- \( \Sigma = \{a,b\} \)
- \( \Sigma = \{0,1\} \)
- \( \Sigma = \{(,)\} \)
A string is a finite sequence of symbols from an alphabet. The string abba belongs to \( \{a,b\}^ \), where \( \Sigma^ \) means all finite strings over \( \Sigma \), including the empty string.
The empty string is written \( \varepsilon \). Its length is zero. The length of abba is four, written \( |abba| = 4 \).
The set \( \Sigma^+ \) contains all nonempty strings over \( \Sigma \). Therefore, \( \Sigma^* = \Sigma^+ \cup \{\varepsilon\} \).
A substring is a consecutive part of a string. For example, bb is a substring of abba, but aa is not. A prefix starts at the first symbol, and a suffix ends at the last symbol. The string ab is a prefix of abba; ba is a suffix.
Languages as sets of strings
A language over \( \Sigma \) is any subset of \( \Sigma^* \). It may be finite or infinite. For example:
\[ L = \{a^n b^n \mid n \geq 1\} \]
contains ab, aabb, aaabbb, and so on. It does not contain abab, because all a symbols must come before all b symbols and their counts must match.
The notation \( a^n \) means \( n \) consecutive copies of a. Language operations include union, concatenation, and Kleene star.
| Operation | Meaning | Example |
|---|---|---|
| Union \(L_1 \cup L_2\) | In either language | `{a} ∪ {b} = {a,b}` |
| Concatenation \(L_1L_2\) | Join strings in order | `{a}{b} = {ab}` |
| Kleene star \(L^*\) | Zero or more repetitions | `{ab}^* = {ε, ab, abab, ...}` |
Why this matters for context-free languages
Regular languages can describe many patterns, but finite automata have no unbounded memory. They cannot compare two arbitrary counts, such as the number of a symbols and b symbols in \(a^n b^n\).
A context-free grammar adds recursive structure for such patterns. Later, a pushdown automaton will represent this extra memory with a stack.
Exercise
Let Σ = {0,1}. Is the string 0010 in the language L = {0^n1^n | n ≥ 1}? Explain briefly.
Show answer
No. Although it contains two 0s, it contains only one 1, so the required counts are unequal.