length of a string
Suppose we have a string on alphabet . We can then represent the string as , where for all (), (this means that each must be a “letter” from the alphabet). Then, the length of is . The length of a string is represented as .
For example, if our alphabet is then the length of the string is , since the string breaks down as follows: , , , . So, our is and therefore . Although you may think that is two separate symbols, our chosen alphabet in fact classifies it as a single symbol.
A “special case” occurs when , i.e. it does not have any symbols in it. This string is called the empty string. Instead of saying , we use to represent the empty string: . This is similar to the practice of using to represent a space, even though a space is really blank.
If your alphabet contains as a symbol, then you must use something else to denote the empty string.
Suppose you also have a string on the same alphabet as . We turn into just as before, and similarly . We say is equal to if and only if both , and for every , .
For example, suppose and , both strings on alphabet . These strings are not equal because the second symbols do not match.
Title | length of a string |
---|---|
Canonical name | LengthOfAString |
Date of creation | 2013-03-22 12:29:16 |
Last modified on | 2013-03-22 12:29:16 |
Owner | mathcam (2727) |
Last modified by | mathcam (2727) |
Numerical id | 7 |
Author | mathcam (2727) |
Entry type | Definition |
Classification | msc 03C07 |
Defines | equality of strings |
Defines | empty string |