Content deleted Content added
s/wost/worst/ |
Rewrite for clarity; remove "context" tag |
||
Line 1:
In [[computer science]], a '''suffix array''' is an [[array]] giving the [[suffix (computer science)|suffixes]] of a [[string (computer science)|string]] in [[lexicographical order]].
==Details==
Consider the string "abracadabra", of length 11. It has eleven suffixes: "abracadabra", "bracadabra", "racadabra", and so on down to "a". Sorted into lexicographical order, these suffixes are
1 abracadabra▼
2 bracadabra▼
3 racadabra▼
4 acadabra▼
5 cadabra▼
6 adabra▼
7 dabra▼
8 abra▼
10 ra▼
a
bra
If the original string is available, each suffix can be completely specified by the [[zero-based]] or [[one-based]] index of its first character. The suffix array is the array of these indices in lexicographical order. For the string "abracadabra", using one-based indexing, the suffix array is {11,8,1,4,6,9,2,5,7,10,3}, because the suffix "a" begins at the 11th character, "abra" begins at the 8th character, and so forth.
One may also treat the string "abracadabra" as having a twelfth suffix, the empty string (with index 12). But since the empty string will always sort lexicographically before every other suffix, we lose no information by omitting it.
==Algorithms==
The easiest way to construct a suffix array is to use an efficient [[comparison sort]] algorithm. This requires <math>O(n \log n)</math> suffix comparisons, but a suffix comparison requires <math>O(n)</math> time, so the overall runtime of this approach is <math>O(n^2 \log n)</math>. More sophisticated algorithms improve this to <math>O(n \log n)</math> by exploiting the results of partial sorts to avoid redundant comparisons. Several <math>\Theta(n)</math> algorithms are known, but are rarely used in practice because of complexity, high memory requirements, and inefficiency (high constant factors).
==Applications==
The suffix array of a string can be used as an [[index (information technology)|index]] to quickly locate every occurrence of a substring within the string. Finding every occurrence of the substring is equivalent to finding every suffix that begins with the substring. Thanks to the lexicographical ordering, these suffixes will be grouped together in the suffix array, and can be found efficiently with a [[binary search]]. If implemented straightforwardly, this binary search takes <math>O(m \log n)</math> time, where <math>m</math> is the length of the substring. To avoid redoing comparisons, extra data structures giving information about the longest common prefixes (LCPs) of suffixes are constructed, giving <math>O(m + \log n)</math> search time.
Suffix sorting algorithms can be used to perform the [[Burrows-Wheeler transform]] (BWT). Technically the BWT requires sorting [[cyclic permutation]]s of a string, not suffixes. We can fix this by appending to the string a special end-of-string character which sorts lexicographically before every other character. Sorting cyclic permutations is then equivalent to sorting suffixes.
==History==
Suffix arrays were originally developed by [[Gene Myers]] and [[Udi Manber]] to reduce memory consumption compared to a [[suffix tree]]. This began the trend towards compressed suffix arrays and [[BWT]]-based compressed full-text indices.
==References==
|