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 prefix doubling, which takes \(O(n\log n)\)
  • 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.
  • 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.