What is a suffix array?

Searching Algorithms Questions Medium



24 Short 58 Medium 71 Long Answer Questions Question Index

What is a suffix array?

A suffix array is a data structure that stores all the suffixes of a given string in lexicographically sorted order. It is commonly used in string processing and pattern matching algorithms.

To construct a suffix array, we first create an array of all the suffixes of the given string. Then, we sort this array in lexicographical order. The resulting sorted array is the suffix array.

The main advantage of using a suffix array is that it allows for efficient pattern matching operations. By using binary search or other search algorithms on the suffix array, we can quickly find the occurrences of a pattern within the original string.

Additionally, suffix arrays can be used to solve various string-related problems, such as finding the longest common substring between two strings, finding the longest repeated substring, and constructing the Burrows-Wheeler Transform.

Compared to other string matching data structures like tries or suffix trees, suffix arrays require less memory and are relatively easier to implement. However, they lack some of the additional functionalities provided by those data structures.

In summary, a suffix array is a sorted array of all the suffixes of a given string, which enables efficient pattern matching and other string-related operations.