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 Σ∗\Sigma^* with Σ+\Sigma^+, forgetting that ε\varepsilon 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 Σ\Sigma is a finite, nonempty set of symbols. Typical alphabets are Σ={0,1}\Sigma = \{0,1\}, Σ={a,b}\Sigma = \{a,b\}, or Σ={a,b,c}\Sigma = \{a,b,c\}. 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 Σ={0,1,2,…,9}\Sigma = \{0,1,2,\ldots,9\}, each digit is one symbol.

Strings

A string (word) over Σ\Sigma is a finite sequence of symbols from Σ\Sigma. The empty string is written ε\varepsilon (some texts use λ\lambda). It contains no symbols.

  • Length. ∣w∣|w| is the number of symbols in ww. In particular ∣ε∣=0|\varepsilon| = 0. For w=abbaw = abba, ∣w∣=4|w| = 4.
  • Occurrences. If w=a1a2…anw = a_1 a_2 \ldots a_n, the symbol aia_i is at position ii (1-based in prose). The number of times symbol aa occurs in ww is written ∣w∣a|w|_a.
  • Reverse. wRw^R is ww written backwards. εR=ε\varepsilon^R = \varepsilon, and (uv)R=vRuR(uv)^R = v^R u^R.

Convention used in all Gate CS Mastery TOC notes. The empty string is ε\varepsilon; the empty language (the empty set of strings) is ∅\emptyset. They are different objects: ε\varepsilon is a string, ∅\emptyset is a language, and {ε}\{\varepsilon\} is a language containing exactly one string.

Concatenation and powers

The concatenation of strings uu and vv is the string uvuv obtained by writing uu then vv. Concatenation is associative: (uv)w=u(vw)(uv)w = u(vw), and ε\varepsilon is the identity: uε=εu=uu\varepsilon = \varepsilon u = u. It is not commutative in general: ab≠baab \neq ba.

Integer powers of a string:

w0=ε,wk+1=wkw(k≥0).w^0 = \varepsilon, \qquad w^{k+1} = w^k w \quad (k \ge 0).

So a3=aaaa^3 = aaa and (ab)2=abab(ab)^2 = abab. Do not confuse string power with language power (below).

Languages

A language over Σ\Sigma is any subset L⊆Σ∗L \subseteq \Sigma^*. Languages may be finite (for example {a,ab}\{a, ab\}) or infinite (for example a∗={ε,a,aa,…}a^* = \{\varepsilon, a, aa, \ldots\}).

Important special languages:

LanguageMeaning
∅\emptysetEmpty language: no strings
{ε}\{\varepsilon\}Language containing only the empty string
Σn\Sigma^nAll strings over Σ\Sigma of length exactly nn
Σ∗\Sigma^*All finite strings over Σ\Sigma, including ε\varepsilon
Σ+\Sigma^+All nonempty finite strings: Σ∗∖{ε}\Sigma^* \setminus \{\varepsilon\}

If ∣Σ∣=k|\Sigma| = k, then ∣Σn∣=kn|\Sigma^n| = k^n. In particular ∣Σ0∣=1|\Sigma^0| = 1 because Σ0={ε}\Sigma^0 = \{\varepsilon\}, and

∣Σ≤n∣=∑i=0nki=kn+1−1k−1|\Sigma^{\le n}| = \sum_{i=0}^{n} k^i = \frac{k^{n+1} - 1}{k - 1}

for k>1k > 1. For Σ={0,1}\Sigma = \{0,1\} and n=3n = 3: ∣Σ3∣=8|\Sigma^3| = 8 and the number of strings of length at most 3 is 1+2+4+8=151+2+4+8 = 15.

Operations on languages

For languages L,M⊆Σ∗L, M \subseteq \Sigma^*:

OperationDefinition
UnionL∪M={w∣w∈L or w∈M}L \cup M = \{ w \mid w \in L \text{ or } w \in M \}
IntersectionL∩M={w∣w∈L and w∈M}L \cap M = \{ w \mid w \in L \text{ and } w \in M \}
ComplementL‾=Σ∗∖L\overline{L} = \Sigma^* \setminus L (alphabet must be fixed)
ConcatenationLM={uv∣u∈L,v∈M}LM = \{ uv \mid u \in L, v \in M \}
PowerL0={ε}L^0 = \{\varepsilon\}, Lk+1=LkLL^{k+1} = L^k L
Kleene starL∗=⋃k≥0LkL^* = \bigcup_{k \ge 0} L^k
Kleene plusL+=⋃k≥1Lk=LL∗L^+ = \bigcup_{k \ge 1} L^k = L L^*
ReverseLR={wR∣w∈L}L^R = \{ w^R \mid w \in L \}

Star versus plus. L∗=L+∪{ε}L^* = L^+ \cup \{\varepsilon\}. Always ε∈L∗\varepsilon \in L^*. Whether ε∈L+\varepsilon \in L^+ depends on whether ε∈L\varepsilon \in L (equivalently, whether some LkL^k for k≥1k \ge 1 contains ε\varepsilon).

Empty language under operations.

  • ∅L=L∅=∅\emptyset L = L \emptyset = \emptyset.
  • ∅∗={ε}\emptyset^* = \{\varepsilon\} (because L0={ε}L^0 = \{\varepsilon\} for every LL, including ∅\emptyset).
  • ∅+=∅\emptyset^+ = \emptyset.

These identities appear in regular-expression simplifications.

How it works

Building languages from operations

Example over Σ={a,b}\Sigma = \{a,b\}. Let L1={a,ab}L_1 = \{a, ab\} and L2={b,ba}L_2 = \{b, ba\}.

  • L1∪L2={a,ab,b,ba}L_1 \cup L_2 = \{a, ab, b, ba\}.
  • L1∩L2=∅L_1 \cap L_2 = \emptyset.
  • L1L2={ab,aba,abb,abba}L_1 L_2 = \{ab, aba, abb, abba\} (four strings: each of 2 choices for the left factor times 2 for the right).
  • L1∗L_1^* is infinite: it contains ε\varepsilon, aa, abab, aaaa, aabaab, abaaba, abababab, and so on.

Prefixes, suffixes and substrings

For w=xyzw = xyz (concatenation of three strings):

  • xx is a prefix of ww; if y=z=εy = z = \varepsilon then x=wx = w.
  • zz is a suffix of ww.
  • yy is a substring (factor) of ww.
  • If x≠wx \neq w, then xx is a proper prefix.

The language of all prefixes of strings in LL is written Prefix(L)\mathrm{Prefix}(L). Regular languages are closed under prefix; that fact is proved later with automata.

Countability

Σ∗\Sigma^* is countably infinite for any finite nonempty Σ\Sigma: enumerate by increasing length, and lexicographically within each length. Every language over Σ\Sigma is a subset of a countable set, so languages are at most continuum-many; there are uncountably many languages over {0,1}\{0,1\}, 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 "ww has even length", membership is a direct check on ww.

Mathematical explanation

Monoid of strings

(Σ∗,⋅,ε)(\Sigma^*, \cdot, \varepsilon) is the free monoid generated by Σ\Sigma: concatenation is associative with identity ε\varepsilon, and every string has a unique factorization into symbols of Σ\Sigma. Language concatenation extends the monoid operation to sets:

LM={uv∣u∈L, v∈M}.LM = \{ uv \mid u \in L,\ v \in M \}.

The power set of Σ∗\Sigma^* with union and concatenation forms a semiring; regular expressions exploit that algebraic structure (see Regular Expressions).

Proof that ∅∗={ε}\emptyset^* = \{\varepsilon\}

By definition L∗=⋃k≥0LkL^* = \bigcup_{k \ge 0} L^k and L0={ε}L^0 = \{\varepsilon\} for every language LL. Taking L=∅L = \emptyset gives ε∈∅∗\varepsilon \in \emptyset^*. For k≥1k \ge 1, ∅k=∅\emptyset^k = \emptyset, so nothing else enters. Hence ∅∗={ε}\emptyset^* = \{\varepsilon\}.

Cardinalities

For finite Σ\Sigma with k=∣Σ∣≥1k = |\Sigma| \ge 1:

∣Σ∗∣=ℵ0,∣{L∣L⊆Σ∗}∣=2ℵ0.|\Sigma^*| = \aleph_0, \qquad |\{ L \mid L \subseteq \Sigma^* \}| = 2^{\aleph_0}.

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 Σ={0,1}\Sigma = \{0,1\} and w=01101w = 01101.

  • ∣w∣=5|w| = 5, ∣w∣0=2|w|_0 = 2, ∣w∣1=3|w|_1 = 3.
  • wR=10110w^R = 10110.
  • w2=0110101101w^2 = 0110101101, length 10.
  • Strings in Σ2\Sigma^2: 00,01,10,1100,01,10,11 (four strings).

Example 2: language operations

Let A={00,01}A = \{00, 01\} and B={1,11}B = \{1, 11\} over {0,1}\{0,1\}.

  • AB={001,0011,011,0111}AB = \{001, 0011, 011, 0111\}.
  • BA={100,101,1100,1101}BA = \{100, 101, 1100, 1101\}.
  • So AB≠BAAB \neq BA.
  • A2={0000,0001,0100,0101}A^2 = \{0000, 0001, 0100, 0101\}.
  • A∪B={00,01,1,11}A \cup B = \{00,01,1,11\}; A∩B=∅A \cap B = \emptyset.

Example 3: star of a finite language

Let L={a,bb}L = \{a, bb\} over {a,b}\{a,b\}. Then L∗L^* contains every string that can be tiled by blocks aa and bbbb. Membership examples:

  • abb∈L∗abb \in L^* because a⋅bba \cdot bb.
  • bbb∉L∗bbb \notin L^*: in every string of L∗L^*, each maximal run of bb's has even length (the bb's arrive two at a time and an aa separates blocks), and bbb is a run of length 3.
  • ε∈L∗\varepsilon \in L^*.

Example 4: complement depends on the alphabet

Let L={a}L = \{a\} over Σ={a}\Sigma = \{a\}. Then L‾={ε,aa,aaa,…}=a∗∖{a}\overline{L} = \{\varepsilon, aa, aaa, \ldots\} = a^* \setminus \{a\}.

If the same set L={a}L = \{a\} is viewed over Σ={a,b}\Sigma = \{a,b\}, the complement also contains every string that uses a bb, so L‾\overline{L} is different. Always fix Σ\Sigma before taking complements.

Example 5: counting strings, substrings and products

QuantityValueExample
Prefixes of ww, ∣w∣=n\lvert w\rvert = n (including ε\varepsilon and ww)n+1n + 1abcd: 5
Proper prefixesnnabcd: 4
Distinct substrings, all symbols distinctn(n+1)/2+1n(n+1)/2 + 1 (counting ε\varepsilon)abcd: 11
Distinct substrings of ana^nn+1n + 1aaaa: 5
Distinct substrings of abab8ε\varepsilon, a, b, ab, ba, aba, bab, abab
∣LM∣\lvert LM\rvertat most ∣L∣⋅∣M∣\lvert L\rvert \cdot \lvert M\rvert{a,aa}2={aa,aaa,aaaa}\{a, aa\}^2 = \{aa, aaa, aaaa\} has 3, not 4
Strings of length nn over {0,1}\{0,1\} with no 11Fibonacci: 1, 2, 3, 5, 8, 13, ... for n=0,1,2,…n = 0, 1, 2, \ldotsn=4n = 4: 8
Languages over Σ\Sigma, ∣Σ∣=k\lvert\Sigma\rvert = k, using only strings of length ≤n\le n2∑i=0nki2^{\sum_{i=0}^{n}k^i}k=2k = 2, n=1n = 1: 23=82^3 = 8

The substring count for distinct symbols is the main trap: the formula n(n+1)/2n(n+1)/2 counts nonempty substrings by position, and it overcounts as soon as symbols repeat. Example 2 is the other trap: ∣AB∣=∣A∣ ∣B∣=4\lvert AB\rvert = \lvert A\rvert\,\lvert B\rvert = 4 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: ε,0,1,00,01,10,11,000,…\varepsilon, 0, 1, 00, 01, 10, 11, 000, \ldots. Plain dictionary order is not an enumeration of Σ∗\Sigma^*: ε,0,00,000,…\varepsilon, 0, 00, 000, \ldots never reaches 1. Shortlex order is what makes Σ∗\Sigma^* countable and is the order used to enumerate strings in decidability proofs.

Important properties and observations

  • ε\varepsilon is a string; ∅\emptyset is a language; {ε}≠∅\{\varepsilon\} \neq \emptyset.
  • L{ε}={ε}L=LL\{\varepsilon\} = \{\varepsilon\}L = L, while L∅=∅L=∅L\emptyset = \emptyset L = \emptyset.
  • ∅∗={ε}\emptyset^* = \{\varepsilon\} and {ε}∗={ε}\{\varepsilon\}^* = \{\varepsilon\}.
  • L∗∗=L∗L^{**} = L^*, and L∗L∗=L∗L^* L^* = L^*.
  • If L⊆ML \subseteq M then L∗⊆M∗L^* \subseteq M^*, but the converse fails.
  • Finite languages are regular; the converse is false (a∗a^* is infinite and regular).
  • Σ∗\Sigma^* is countable; the set of all languages over Σ\Sigma is uncountable.
  • (uv)R=vRuR(uv)^R = v^R u^R and (L1L2)R=L2RL1R(L_1 L_2)^R = L_2^R L_1^R; reversal does not distribute in the same order.
  • (L1∪L2)∗=(L1∗L2∗)∗(L_1 \cup L_2)^* = (L_1^* L_2^*)^*, but in general L1∗∪L2∗⊊(L1∪L2)∗L_1^* \cup L_2^* \subsetneq (L_1 \cup L_2)^*: ab∈({a}∪{b})∗ab \in (\{a\} \cup \{b\})^* is in neither a∗a^* nor b∗b^*.
  • L+=L∗L^+ = L^* iff ε∈L\varepsilon \in L.

Common misconceptions.

  • "ε\varepsilon is not a string." It is, of length 0.
  • "L+L^+ never contains ε\varepsilon." False when ε∈L\varepsilon \in L.
  • "∅\emptyset and {ε}\{\varepsilon\} are the same." They are not.
  • "Complement of a∗a^* over {a,b}\{a,b\} is empty." No: every string with a bb is in the complement.

GATE examination perspective

  • EMPTY STRING VERSUS EMPTY LANGUAGE. Questions ask whether ε∈L\varepsilon \in L, whether L=∅L = \emptyset, or whether L={ε}L = \{\varepsilon\}. Read the notation carefully.
  • STAR IDENTITIES. Simplifying regular expressions uses ∅∗={ε}\emptyset^* = \{\varepsilon\}, (L∗)∗=L∗(L^*)^* = L^*, and LL∗=L∗L=L+L L^* = L^* L = L^+.
  • CARDINALITY. ∣Σn∣=∣Σ∣n|\Sigma^n| = |\Sigma|^n, including ∣Σ0∣=1|\Sigma^0| = 1.
  • CONCATENATION NON-COMMUTATIVITY. ABAB and BABA differ in general; compute both when asked.
  • ALPHABET FOR COMPLEMENT. Complement is always relative to a stated Σ∗\Sigma^*.
  • COUNTING SUBSTRINGS. n(n+1)/2+1n(n+1)/2 + 1 holds only when all symbols differ; for repeated symbols list them.
  • PRODUCT SIZE. ∣LM∣≤∣L∣ ∣M∣\lvert LM\rvert \le \lvert L\rvert\,\lvert M\rvert; check for collisions before multiplying.

Summary

Sources

  1. 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).
  2. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 0.2 (mathematical notions and terminology; strings and languages).
  3. 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).

Next steps