An alphabet is a finite set of symbols such as and . A string is a finite sequence of symbols drawn from a given alphabet. For example, ‘aa’, ‘cat’, ‘abracadabra’ are examples of strings over the alphabet of lowercase letters, of length 2, 3, and 11 respectively. The empty string has length 0.
Consider recursive construction of the set of strings of length over alphabet .1 If , the set is , consisting of only the empty string. If , for each symbol , prepend to every string of length , where these strings are generated recursively. Since each of positions can be occupied by possible symbols, there are strings of length in total. For example, for and , there are strings:
000 001 010 011 100 101 110 111
The following program generates such a table of strings in the form of a keyboard. Each symbol is color-coded, being represented by a rectangle whose color distinguishes it from the other symbols. Use base to select the size of the alphabet and n to select the string length. For example, for base=2, red corresponds to 0 and blue to 1; for base=3, red, green, and blue correspond to the symbols 0, 1, and 2 respectively.
- Convention is to use to denote the alphabet. ↩