Click or drag to resize
SuffixArrayX Class

The SuffixArrayX class represents a suffix array of a string of length N. It supports the Selecting the Ith smallest suffix, getting the Index of the Ith smallest suffix, computing the length of the Longest common prefix between the Ith smallest suffix and the I-1st smallest suffix, and determining the Rank of a query string (which is the number of suffixes strictly less than the query string).

This implementation uses 3-way radix quicksort to sort the array of suffixes. For a simpler (but less efficient) implementations of the same API, see . The Index and Length operations takes constant time in the worst case. The Lcp operation takes time proportional to the length of the longest common prefix. The Select operation takes time proportional to the length of the suffix and should be used primarily for debugging.

This implementation uses '\0' as a sentinel and assumes that the charater '\0' does not appear in the text.

In practice, this algorithm runs very fast. However, in the worst-case it can be very poor (e.g., a string consisting of N copies of the same character. We do not shuffle the array of suffixes before sorting because shuffling is relatively expensive and a pathologial input for which the suffixes start out in a bad order (e.g., sorted) is likely to be a bad input for this algorithm with or without the shuffle.

Inheritance Hierarchy
SystemObject
  Algs4NetSuffixArrayX

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class SuffixArrayX

The SuffixArrayX type exposes the following members.

Constructors
  NameDescription
Public methodSuffixArrayX
Initializes a suffix array for the given text string.
Top
Properties
  NameDescription
Public propertyLength
Returns the length of the input string.
Top
Methods
  NameDescription
Public methodIndex
Returns the index into the original string of the Ith smallest suffix. That is, text.substring(sa.index(i)) is the I smallest suffix.
Public methodLcp
Returns the length of the longest common prefix of the Ith smallest suffix and the I-1st smallest suffix.
Public methodStatic memberMainTest
Demo test the SuffixArrayx data type.
Public methodRank
Returns the number of suffixes strictly less than the query string. We note that rank(select(i)) equals i for each i between 0 and N-1.
Public methodSelect
Returns the Ith smallest suffix as a string.
Top
Remarks

For additional documentation, see Section 6.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class SuffixArrayX implementation by the respective authors.

See Also