Skip to content
Part IA Michaelmas, Lent Term

Alphabets and Strings

Alphabets

Definition

An alphabet is a finite set Σ\Sigma whose elements are called symbols.

Examples

  • {0,1}\{0, 1\}: binary alphabet
  • {a,b,c,,z}\{a, b, c, \ldots, z\}: lowercase English letters
  • {0,1,2,,9}\{0, 1, 2, \ldots, 9\}: decimal digits
  • ASCII character set (finite)
  • {}=\{\} = \emptyset: the empty alphabet

Non-examples

  • N\mathbb{N}: infinite, not an alphabet
  • R\mathbb{R}: infinite, not an alphabet

Strings

Definition

A string (or word) over alphabet Σ\Sigma is a finite sequence of symbols from Σ\Sigma.

  • Strings are written without punctuation: abbaabba, 00110011
  • The length of string ww is written w|w|
  • The empty string (length 0) is written ε\varepsilon or λ\lambda

Formal Definition

A string of length nn is a function w:[n]Σw : [n] \to \Sigma, where [n]={0,1,,n1}[n] = \{0, 1, \ldots, n-1\}.

The empty string is the unique function [0]Σ[0] \to \Sigma.

Examples

Over Σ={a,b}\Sigma = \{a, b\}:

  • ε\varepsilon: empty string, ε=0|\varepsilon| = 0
  • aa: length 1
  • abbaabba: length 4
  • aaaaaaaa: length 4

The Set of All Strings

Definition

Σ\Sigma^* is the set of all strings over Σ\Sigma, including ε\varepsilon.

Σ={w:w is a string over Σ}=n0Σn\Sigma^* = \{w : w \text{ is a string over } \Sigma\} = \bigcup_{n \geq 0} \Sigma^n

where Σn={w:w=n}\Sigma^n = \{w : |w| = n\} is the set of length-nn strings.

Special Cases

  • If Σ=\Sigma = \emptyset: Σ={ε}\Sigma^* = \{\varepsilon\} (only the empty string)
  • If Σ={a}\Sigma = \{a\}: Σ={ε,a,aa,aaa,}\Sigma^* = \{\varepsilon, a, aa, aaa, \ldots\}

Distinguishing Notation

SymbolMeaning
\emptysetThe empty set
{ε}\{\varepsilon\}The set containing the empty string
ε\varepsilonThe empty string itself

These are three distinct objects!

Concatenation

Definition

The concatenation of strings uu and vv, written uvuv, is the string formed by appending vv to uu.

uv=u+v|uv| = |u| + |v|

Properties

  • Identity: uε=u=εuu\varepsilon = u = \varepsilon u
  • Associativity: (uv)w=u(vw)(uv)w = u(vw)

Concatenation is NOT commutative: in general uvvuuv \neq vu.

Examples

If u=abu = ab and v=bav = ba:

  • uv=abbauv = abba
  • vu=baabvu = baab
  • uu=ababuu = abab
  • u3=abababu^3 = ababab

Powers

For a string uu and n0n \geq 0:

un=uuun timesu^n = \underbrace{uu\cdots u}_{n \text{ times}}

By convention, u0=εu^0 = \varepsilon.

Strings Form a Monoid

Algebraic Structure

(Σ,,ε)(\Sigma^*, \cdot, \varepsilon) is a monoid:

  • Binary operation: concatenation
  • Identity element: ε\varepsilon
  • Associative: (uv)w=u(vw)(uv)w = u(vw)

Not a Group

Strings do not generally have inverses under concatenation.

If uv=εuv = \varepsilon, then u=v=εu = v = \varepsilon.

Free Monoid

Σ\Sigma^* is the free monoid on Σ\Sigma: every monoid generated by Σ\Sigma is a quotient of Σ\Sigma^*.

Substrings and Prefixes

Substring

uu is a substring of ww if w=xuyw = xuy for some strings x,yx, y.

Prefix

uu is a prefix of ww if w=uvw = uv for some string vv.

Suffix

uu is a suffix of ww if w=vuw = vu for some string vv.

Examples

For w=abcdw = abcd:

  • Prefixes: ε,a,ab,abc,abcd\varepsilon, a, ab, abc, abcd
  • Suffixes: ε,d,cd,bcd,abcd\varepsilon, d, cd, bcd, abcd
  • Substrings include: bcbc, bb, ε\varepsilon, abcdabcd

Summary

  • An alphabet Σ\Sigma is a finite set of symbols
  • Σ\Sigma^* is the set of all finite strings over Σ\Sigma
  • Concatenation is associative with identity ε\varepsilon
  • (Σ,,ε)(\Sigma^*, \cdot, \varepsilon) forms a monoid
  • \emptyset, {ε}\{\varepsilon\}, and ε\varepsilon are distinct