Alphabets and Strings
Alphabets
Definition
An alphabet is a finite set whose elements are called symbols.
Examples
- : binary alphabet
- : lowercase English letters
- : decimal digits
- ASCII character set (finite)
- : the empty alphabet
Non-examples
- : infinite, not an alphabet
- : infinite, not an alphabet
Strings
Definition
A string (or word) over alphabet is a finite sequence of symbols from .
- Strings are written without punctuation: ,
- The length of string is written
- The empty string (length 0) is written or
Formal Definition
A string of length is a function , where .
The empty string is the unique function .
Examples
Over :
- : empty string,
- : length 1
- : length 4
- : length 4
The Set of All Strings
Definition
is the set of all strings over , including .
where is the set of length- strings.
Special Cases
- If : (only the empty string)
- If :
Distinguishing Notation
| Symbol | Meaning |
|---|---|
| The empty set | |
| The set containing the empty string | |
| The empty string itself |
These are three distinct objects!
Concatenation
Definition
The concatenation of strings and , written , is the string formed by appending to .
Properties
- Identity:
- Associativity:
Concatenation is NOT commutative: in general .
Examples
If and :
Powers
For a string and :
By convention, .
Strings Form a Monoid
Algebraic Structure
is a monoid:
- Binary operation: concatenation
- Identity element:
- Associative:
Not a Group
Strings do not generally have inverses under concatenation.
If , then .
Free Monoid
is the free monoid on : every monoid generated by is a quotient of .
Substrings and Prefixes
Substring
is a substring of if for some strings .
Prefix
is a prefix of if for some string .
Suffix
is a suffix of if for some string .
Examples
For :
- Prefixes:
- Suffixes:
- Substrings include: , , ,
Summary
- An alphabet is a finite set of symbols
- is the set of all finite strings over
- Concatenation is associative with identity
- forms a monoid
- , , and are distinct