Introduction
Every model in the theory of computation (finite automata, pushdown automata, Turing machines) processes strings built from a fixed finite alphabet. A language is simply a set of strings. This note fixes the notation used throughout the Theory of Computation short notes: alphabets, concatenation, powers, Kleene star, and the elementary language operations (union, intersection, complement, concatenation, star, reverse).
These definitions look elementary, but they are the source of several standard mistakes: confusing with , forgetting that is a string of length 0, or treating infinite languages as if membership tests were automatic.
Prerequisites
- Sets: set notation, union, intersection, complement, power set, countable sets.
Core concepts
Alphabets and symbols
An alphabet is a finite, nonempty set of symbols. Typical alphabets are , , or . The empty set is not used as an alphabet here.
Symbols are atomic: the string ab is two symbols, not one. When a question writes , each digit is one symbol.
Strings
A string (word) over is a finite sequence of symbols from . The empty string is written (some texts use ). It contains no symbols.
- Length. is the number of symbols in . In particular . For , .
- Occurrences. If , the symbol is at position (1-based in prose). The number of times symbol occurs in is written .
- Reverse. is written backwards. , and .
Convention used in all Gate CS Mastery TOC notes. The empty string is ; the empty language (the empty set of strings) is . They are different objects: is a string, is a language, and is a language containing exactly one string.
Concatenation and powers
The concatenation of strings and is the string obtained by writing then . Concatenation is associative: , and is the identity: . It is not commutative in general: .
Integer powers of a string:
So and . Do not confuse string power with language power (below).
Languages
A language over is any subset . Languages may be finite (for example ) or infinite (for example ).
Important special languages:
| Language | Meaning |
|---|---|
| Empty language: no strings | |
| Language containing only the empty string | |
| All strings over of length exactly | |
| All finite strings over , including | |
| All nonempty finite strings: |
If , then . In particular because , and
for . For and : and the number of strings of length at most 3 is .
Operations on languages
For languages :
| Operation | Definition |
|---|---|
| Union | |
| Intersection | |
| Complement | (alphabet must be fixed) |
| Concatenation | |
| Power | , |
| Kleene star | |
| Kleene plus | |
| Reverse |
Star versus plus. . Always . Whether depends on whether (equivalently, whether some for contains ).
Empty language under operations.
- .
- (because for every , including ).
- .
These identities appear in regular-expression simplifications.
How it works
Building languages from operations
Example over . Let and .
- .
- .
- (four strings: each of 2 choices for the left factor times 2 for the right).
- is infinite: it contains , , , , , , , and so on.
Prefixes, suffixes and substrings
For (concatenation of three strings):
- is a prefix of ; if then .
- is a suffix of .
- is a substring (factor) of .
- If , then is a proper prefix.
The language of all prefixes of strings in is written . Regular languages are closed under prefix; that fact is proved later with automata.
Countability
is countably infinite for any finite nonempty : enumerate by increasing length, and lexicographically within each length. Every language over is a subset of a countable set, so languages are at most continuum-many; there are uncountably many languages over , but only countably many finite automata, so some languages are not regular. That counting argument is the cleanest existence proof that non-regular languages exist; concrete examples use the pumping lemma or Myhill-Nerode.
Algorithms and pseudocode
There is no single algorithm in this foundational note. For a fixed language L, membership is a decision problem whose decidability depends on L. An algorithm taking a language description as input needs a finite representation, such as a machine or grammar; the representation matters for that uniform problem.
When a language is finite and listed explicitly, membership is table lookup. When it is given by a pattern such as " has even length", membership is a direct check on .
Mathematical explanation
Monoid of strings
is the free monoid generated by : concatenation is associative with identity , and every string has a unique factorization into symbols of . Language concatenation extends the monoid operation to sets:
The power set of with union and concatenation forms a semiring; regular expressions exploit that algebraic structure (see Regular Expressions).
Proof that
By definition and for every language . Taking gives . For , , so nothing else enters. Hence .
Cardinalities
For finite with :
The set of regular languages is countable (each regular language has a regular expression, and regular expressions over a finite alphabet are a countable set). Therefore most languages are not regular.
Worked examples
Example 1: lengths and powers
Let and .
- , , .
- .
- , length 10.
- Strings in : (four strings).
Example 2: language operations
Let and over .
- .
- .
- So .
- .
- ; .
Example 3: star of a finite language
Let over . Then contains every string that can be tiled by blocks and . Membership examples:
- because .
- : in every string of , each maximal run of 's has even length (the 's arrive two at a time and an separates blocks), and
bbbis a run of length 3. - .
Example 4: complement depends on the alphabet
Let over . Then .
If the same set is viewed over , the complement also contains every string that uses a , so is different. Always fix before taking complements.
Example 5: counting strings, substrings and products
| Quantity | Value | Example |
|---|---|---|
| Prefixes of , (including and ) | abcd: 5 | |
| Proper prefixes | abcd: 4 | |
| Distinct substrings, all symbols distinct | (counting ) | abcd: 11 |
| Distinct substrings of | aaaa: 5 | |
Distinct substrings of abab | 8 | , a, b, ab, ba, aba, bab, abab |
| at most | has 3, not 4 | |
Strings of length over with no 11 | Fibonacci: 1, 2, 3, 5, 8, 13, ... for | : 8 |
| Languages over , , using only strings of length | , : |
The substring count for distinct symbols is the main trap: the formula counts nonempty substrings by position, and it overcounts as soon as symbols repeat. Example 2 is the other trap: holds there only because no two pairs give the same string.
Example 6: order of strings
Shortlex (canonical) order lists strings by length, then lexicographically: . Plain dictionary order is not an enumeration of : never reaches 1. Shortlex order is what makes countable and is the order used to enumerate strings in decidability proofs.
Important properties and observations
- is a string; is a language; .
- , while .
- and .
- , and .
- If then , but the converse fails.
- Finite languages are regular; the converse is false ( is infinite and regular).
- is countable; the set of all languages over is uncountable.
- and ; reversal does not distribute in the same order.
- , but in general : is in neither nor .
- iff .
Common misconceptions.
- " is not a string." It is, of length 0.
- " never contains ." False when .
- " and are the same." They are not.
- "Complement of over is empty." No: every string with a is in the complement.
GATE examination perspective
- EMPTY STRING VERSUS EMPTY LANGUAGE. Questions ask whether , whether , or whether . Read the notation carefully.
- STAR IDENTITIES. Simplifying regular expressions uses , , and .
- CARDINALITY. , including .
- CONCATENATION NON-COMMUTATIVITY. and differ in general; compute both when asked.
- ALPHABET FOR COMPLEMENT. Complement is always relative to a stated .
- COUNTING SUBSTRINGS. holds only when all symbols differ; for repeated symbols list them.
- PRODUCT SIZE. ; check for collisions before multiplying.
Summary
Sources
- J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley: Section 1.5 (the central concepts of automata theory: alphabets, strings, languages, problems).
- M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 0.2 (mathematical notions and terminology; strings and languages).
- P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Section 1.1 (mathematical preliminaries and notation), Section 1.2 (three basic concepts: languages, grammars, automata).