Suffix array

Invented by Udi Manber, Gene Myers (1990)
Idea:
  • sort all \(n\) suffixes of the text and store their starting positions in lexicographic order
  • suffixes that start with the same pattern land next to each other, so the answer to a search is always one block of rows — found by binary search
  • the companion LCP array stores, for each row, how many leading characters it shares with the row above; with it the array carries the same information as a suffix tree
Advantages:
  • several times smaller than a suffix tree over the same text: the array is just one integer per character, with no pointers and no per-node overhead
  • independent of the alphabet size: only comparisons of symbols are needed, where a suffix tree needs a child lookup per node
Variations:
  • there are many suffix array construction algorithms, from the trivial \(O(n^2\log n)\) to optimal \(O(n)\); this visualization shows seven:
    • Manber–Myers prefix doubling, \(O(n\log n)\)
    • Larsson–Sadakane, the same doubling that sorts only the suffixes that still tie and skips the finished ones, also \(O(n\log n)\) but much faster in practice
    • Kärkkäinen–Sanders (DC3), \(O(n)\), which sorts the suffixes at positions not divisible by 3 recursively, as the suffixes of a text of triple names about two thirds as long, sorts the rest by one radix sort with their help, and merges the two
    • Seward's copy, the suffix sorting of bzip2, which groups the suffixes by their first two characters, sorts a few of the groups directly and copies the order of every finished bucket into the groups it determines, fast in practice but \(O(n^2\log n)\) in the worst case
    • Itoh–Tanaka, which sorts only the suffixes whose first character is at most the second, by plain comparison, and induces the rest from them in one pass, fast in practice but \(O(n^2\log n)\) in the worst case
    • Ko–Aluru, \(O(n)\), which sorts only the suffixes of the less common type, ↘ or ↗, and induces the rest from them in one pass
    • SA-IS, its successor, also \(O(n)\), which sorts only the suffixes starting in valleys, at most half of them, and induces the order of all the others from them
  • the array can be used with or without the LCP array; the trade-off is more space against faster operations
Disadvantages:
  • the search is a binary search, not a walk down a trie, so it costs a \(\log n\) factor a suffix tree does not pay; matching statistics and other suffix-link algorithms need the LCP array plus extra structure to imitate the tree

References

  • U. Manber, G. Myers. Suffix arrays: a new method for on-line string searches. SIAM Journal on Computing, 22(5):935-948, 1993. (First published at SODA 1990, 319-327.)
  • T. Kasai, G. Lee, H. Arimura, S. Arikawa, K. Park. Linear-time longest-common-prefix computation in suffix arrays and its applications. Proceedings of the 12th annual symposium on Combinatorial Pattern Matching (CPM), 181-192, 2001.
  • M.I. Abouelhoda, S. Kurtz, E. Ohlebusch. Replacing suffix trees with enhanced suffix arrays. Journal of Discrete Algorithms, 2(1):53-86, 2004.
  • N. J. Larsson, K. Sadakane. Faster suffix sorting. Theoretical Computer Science, 387(3):258-272, 2007.
  • J. Kärkkäinen, P. Sanders. Simple linear work suffix array construction. Proceedings of the 30th International Colloquium on Automata, Languages and Programming (ICALP), LNCS 2719, 943-955, 2003.
  • J. Seward. On the performance of BWT sorting algorithms. Proceedings of the Data Compression Conference (DCC), 173-182, 2000.
  • H. Itoh, H. Tanaka. An efficient method for in memory construction of suffix arrays. Proceedings of the 6th International Symposium on String Processing and Information Retrieval (SPIRE), 81-88, 1999.
  • P. Ko, S. Aluru. Space efficient linear time construction of suffix arrays. Journal of Discrete Algorithms, 3(2-4):143-156, 2005.
  • G. Nong, S. Zhang, W.H. Chan. Linear suffix array construction by almost pure induced-sorting. Proceedings of the Data Compression Conference (DCC), 193-202, 2009.
  • G. Nong, S. Zhang, W.H. Chan. Two efficient algorithms for linear time suffix array construction. IEEE Transactions on Computers, 60(10):1471-1484, 2011.