ArticleslgStudy

computer science

Suffix array

Suffix array is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Suffix array rather than just read about it. In short: In computer science, a suffix array is a sorted array of all suffixes of a string. It is a data structure used in, among others, full-text indices, data-compression algorithms, and the field of bibliometrics.

Key takeaways

  • Suffix array belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Suffix array to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Suffix array from memory before moving on to harder problems.

Reference excerpt

In computer science, a suffix array is a sorted array of all suffixes of a string. It is a data structure used in, among others, full-text indices, data-compression algorithms, and the field of bibliometrics. Suffix arrays were introduced by Manber & Myers (1990) as a simple, space efficient alternative to suffix trees. They had independently been discovered by Gaston Gonnet in 1987 under the name PAT array (Gonnet, Baeza-Yates & Snider 1992). Li, Li & Huo (2016) gave the first in-place 𝒪(n) time suffix array construction algorithm that is optimal both in time and space, where in-place means that the algorithm only needs 𝒪(1) additional space beyond the input string and the output suffix array. Enhanced suffix arrays (ESAs) are suffix arrays with additional tables that reproduce the full functionality of suffix trees preserving the same time and memory complexity. A sorted array of only some (rather than all) suffixes of a string is called a sparse suffix array.

Definition Let S=S[1]S[2]...S[n] be an n-string and let S[i,j] denote the substring of S ranging from i to j inclusive. The suffix array A of S is now defined to be an array of integers providing the starting positions of suffixes of S in lexicographical order. This means, an entry A[i] contains the starting position of the i-th smallest suffix in S and thus for all 1≤i≤n: S[A[i−1],n]<S[A[i],n]. Each suffix of S shows up in A exactly once. Suffixes are simple strings. These strings are sorted (as in a paper dictionary), before their starting positions (integer indices) are saved in A.

Example Consider the text S=banana$ to be indexed:

The text ends with the special sentinel letter $ that is unique and lexicographically smaller than any other character. The text has the following suffixes:

These suffixes can be sorted in ascending order:

The suffix array A contains the starting positions of these sorted suffixes:

The suffix array with the suffixes written out vertically underneath for clarity:

So for example, A[3] contains the value 4, and therefore refers to the suffix starting at position 4 within S, which is the suffix ana$.

Correspondence to suffix trees Suffix arrays are closely related to suffix trees:

Suffix arrays can be constructed by performing a depth-first traversal of a suffix tree. The suffix array corresponds to the leaf-labels given in the order in which these are visited during the traversal, if edges are visited in the lexicographical order of their first character. A suffix tree can be constructed in linear time by using a combination of suffix array and LCP array. For a description of the algorithm, see the corresponding section in the LCP array article. It has been shown that every suffix tree algorithm can be systematically replaced with an algorithm that uses a suffix array enhanced with additional information (such as the LCP array) and solves the same problem in the same time complexity. 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.

Space efficiency Suffix arrays were introduced by Manber & Myers (1990) in order to improve over the space requirements of suffix trees: Suffix arrays store n integers. Assuming an integer requires 4 bytes, a suffix array requires 4n bytes in total. This is significantly less than the 20n bytes which are required by a careful suffix tree implementation. However, in certain applications, the space requirements of suffix arrays may still be prohibitive. Analyzed in bits, a suffix array requires 𝒪(nlog⁡n) space, whereas the original text over an alphabet of size σ only requires 𝒪(nlog⁡σ) bits. For a human genome with σ=4 and n=3.4×109 the suffix array would therefore occupy about 16 times more memory than the genome itself. Such discrepancies motivated a trend towards compressed suffix arrays and BWT-based compressed full-text indices such as the FM-index. These data structures require only space within the size of the text or even less.

Construction algorithms A suffix tree can be built in 𝒪(n) and can be converted into a suffix array by traversing the tree depth-first also in 𝒪(n), so there exist algorithms that can build a suffix array in 𝒪(n). A naive approach to construct a suffix array is to use a comparison-based sorting algorithm. These algorithms require 𝒪(nlog⁡n) suffix comparisons, but a suffix comparison runs in 𝒪(n) time, so the overall runtime of this approach is 𝒪(n2log⁡n). More advanced algorithms take advantage of the fact that the suffixes to be sorted are not arbitrary strings but related to each other. These algorithms strive to achieve the following goals:

minimal asymptotic complexity Θ(n) lightweight in space, meaning little or no working memory beside the text and the suffix array itself is needed fast in practice One of the first algorithms to achieve all goals is the SA-IS algorithm of Nong, Zhang & Chan (2009). The algorithm is also rather simple (< 100 LOC) and can be enhanced to simultaneously construct the LCP array. The SA-IS algorithm is one of the fastest known suffix array construction algorithms. A careful implementation by Yuta Mori outperforms most other linear or super-linear construction approaches. Beside time and space requirements, suffix array construction algorithms are also differentiated by their supported alphabet: constant alphabets where the alphabet size is bound by a constant, integer alphabets where characters are integers in a range depending on n and general alphabets where only character comparisons are allowed. Most suffix array construction algorithms are based on one of the following approaches:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Suffix array

Start with the simplest possible case. Write down what Suffix array claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Suffix array before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Suffix array ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Suffix array

In research
Suffix array appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Suffix array in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Suffix array is common in secondary-school and first-year university syllabi. It links to neighbouring topics Arrays, Computer science suffixes, String data structures, so understanding it makes those chapters shorter.
In everyday life
Look for Suffix array outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Suffix array” →

How to study Suffix array in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Suffix array means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Suffix array out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Suffix array in simple terms?

In computer science, a suffix array is a sorted array of all suffixes of a string. It is a data structure used in, among others, full-text indices, data-compression algorithms, and the field of bibliometrics.

Why does Suffix array matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Suffix array?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Suffix array.

Tags

  • Arrays
  • Computer science suffixes
  • String data structures
  • Substring indices

Keep exploring