A suffix array is a sorted array of all suffixes of a given string. The definition is similar to Suffix Tree which is compressed trie of all suffixes of the given text. Any suffix tree based algorithm can be replaced with an algorithm that uses a suffix array enhanced with additional information and solves the same problem in the same time complexity.
A suffix array can be constructed from Suffix tree by doing a DFS traversal of the suffix tree. In fact Suffix array and suffix tree both can be constructed from each other in linear time.
Advantages of suffix arrays over suffix trees include improved space requirements, simpler linear time construction algorithms (e.g., compared to Ukkonen’s algorithm) and improved cache locality.
最简单的构建方法就是把所有的后缀取出来再排序,时间复杂度是O(n^2lgn),因为每次比较都要O(n)。有了suffix array之后的查找开销需要O(mlgn),m为pattern长度,用二分查找。
当然,对于构建和查找都有线性的算法。
转自:http://www.geeksforgeeks.org/suffix-array-set-1-introduction/