A suffix array is an index structure for locating substrings in a larger string. It is an array of indexes giving the lexicographical order of the suffixes. A suffix array for a string S of length n can be built in Θ(n) time, and lets you find all occ occurrences of a pattern P of length m in S in O(m + log n + occ) time. Suffix arrays were originally developed by Gene Myers and Udi Manber to reduce memory consum 141o141b ption compared to a suffix tree. This began the trend towards compressed suffix arrays and BWT-based compressed full-text indices.
The kth suffix of a string S is S with the first k-1 characters removed, for some starting position k. A string of n characters has n suffixes, denoted by their starting positions 1..n. For instance, the string "abracadabra" has the following suffixes:
abracadabraThe first step in building a suffix array is to sort the suffixes lexicographically, giving:
11 aTo find where a given pattern P is a substring of S, two binary searches are used to find the range of suffixes prefixed by P. The output of the search is the list of starting positions in this range. A search for "br" in the given example would give a left border 6 and a right border 7, giving suffixes 9 and 2. This means that "br" is a substring of "abracadabra" both at position 2 and 9. If implemented straightforward, this binary search takes O(m log n) time, as most of the pattern P is compared at every step in the binary search in the worst case. To avoid redoing comparisons, extra data structures giving information about the longest common prefixes (LCP's) of suffixes are constructed, giving O(m + log n) search time.
The key insight of the suffix array is to denote each suffix by its starting position only (the second column above). The resulting array of numbers, combined with the original string, is a compact representation of the sorted suffix list, consuming one character and one integer for each character in the string.
There are many suffix array construction algorithms, with different properties. Some O(n2) construction algorithms are faster than the Θ(n) algorithms in practise.
[edit]
Retrieved from "https://en.wikipedia.org/wiki/Suffix_array"
|