Such as string: abcdef
Suffix not sorted:
1 adcefd
2 dcefd
3 cefd
4 EFD
5 FD
6 d
Save the suffix SA after sorting
1 adcefd
2 cefd
3 D
4 dcefd
5 EFD
6 FD
Rank array:
The subscript of the rank array corresponds to the subscript of the original string (the first letter of each suffix, the suffix of the original string)
The saved content corresponds to the subscript of the suffix string starting with the current subscript in the SA array (the row number in SA)
A D C E F D
1 2 3 4 5 6 // position of the first letter of each Suffix in the original string
Sa [5] = 4 // The EFD is saved in SA [5], and the initial suffix is E,
// The position of E in the original string a d c e f d is 4
Rank [4] = 5 // In the SA array, the first character of the suffix string is 4, that is, in the original string a D C E F D
// The suffix of the 4-character E string e f d is saved in the SA array at 5,
// Obviously SA [5] = E F D
Sort the suffix array SA: