Definition
Character Set
A character set is a set equipped with a total order, which means that any two distinct elements and in can be compared: either or . The elements of the character set are called characters.
String
A string is a sequence formed by arranging characters in order. is called the length of , denoted by .
If string indices start at , the -th character of is denoted by ;
if string indices start at , the -th character of is denoted by .
Substring
The substring of string denotes the segment from to in , namely the string formed by arranging in order.
Sometimes , , is also used to denote the empty string.
Subsequence
A subsequence of string is a sequence formed by extracting some elements from without changing their relative positions, namely , where .
Suffix
A suffix is a special substring that starts at some position and ends at the end of the entire string. The suffix of string starting at is denoted by , namely .
A proper suffix is a suffix of other than itself.
For example, all suffixes of the string abcabcd are {d, cd, bcd, abcd, cabcd, bcabcd, abcabcd}, and its proper suffixes are {d, cd, bcd, abcd, cabcd, bcabcd}.
Prefix
A prefix is a special substring that starts at the beginning of the string and ends at some position . The prefix of ending at is denoted by , namely .
A proper prefix is a prefix of other than itself.
For example, all prefixes of the string abcabcd are {a, ab, abc, abca, abcab, abcabc, abcabcd}, and its proper prefixes are {a, ab, abc, abca, abcab, abcabc}.
Lexicographic Order
Compare strings by using the -th character as the -th keyword. An empty character is smaller than every character in the character set (that is, ).
Palindrome
A palindrome is a string that is the same when written forwards and backwards, that is, an satisfying .
Hamming Distance
The Hamming distance is the distance between two strings of equal length; it is the number of positions at which the corresponding characters of the two strings differ.
It can be simply understood as the number of bits obtained by XORing the two strings.
String Storage
- Store strings in a
chararray, using the null character\0to mark the end of the string (a C-style string). - Use the
stringclass provided by the C++ standard library. - String constants can be represented by string literals (strings enclosed in double quotation marks).