Strings
This chapter covers notes on strings-related algorithms.
In today's world, there's no such thing as a "string." There are ASCII strings and Unicode strings. While we can classify them as a single type "string," that classification isn't very useful β they're different enough that we must treat them separately. Accordingly, whenever we work with "strings," we must always β always β ask: Are working with ASCII strings or Unicode string?
Definitions
alphabet. A non-empty set of symbols is called an alphabet, denoted
For example, the set is an alphabet of two symbols. The set is an alphabet of four symbols.
string. Given an alphabet the finite sequence
with and is called a string over of length Given a symbol we say that is the first symbol, and is the last symbol. We may denote the character o We denote the length of as If then we call the the empty string, and denote it
Note that we will denote strings with double quotes. Thus, the string cookie is denoted The string is denoted Additionally, the empty string may also be denoted with the Greek letter
Because how small subscripts are, we will adopt a few conventions when working with strings. First, given a string we will reference the first character with where is an index. For example, given the string cake, writing returns the string and writing returns the string
kleene closure. Given an alphabet the set of all strings over is called the Kleene closure of denoted
language. Given a Kleene closure and a set of strings if then is a language.
word. Given a language we call each string a word.
character. Given a word of length we call each symbol with a character.
character encoding. Let denote a character set, and denote a finite range of integers . Then the injection
is called a character encoding, whose domain is called the code space and whose image is called the coded character set. For each we call the coded character, and by the code point of
k-Permutation String
Given an alphabet we define a k-permutation string as a permutation of a subset of That is, a string composed entirely of distinct symbols.
k-permutation?
Let be a finite, non-empty string over an alphabet The function returns if, and only if, each with and is distinct.
- while do
- if then return
- else
- return