1 Procedure SortSuffix takes one sequence X = <x_1, x_2, …, x_L> as input.
2
3 GenerateSuffix(X)
4 L ← X.length
5 S ← create L sequences = <s_1, s_2, …, s_L>
6
7 // note that each si is a sequence = <s_i1, s_i2, …, s_in>
8 // s_ij means j-th element of sequence s_i
9 // s_i.length = L - i + 1
10
11 for i ← 1 to L
12 for j ← 1 to L - i
13 s_ij ← x_(i + j)
14
15 // add dummy space; make sure each (s_i).length = L
16
17 for j ← L - i + 1 to L
18 do s_ij ← ’ ’ // this is a space
19 return S
关于这题,我觉得在第 12、13 行和第 17、18 行的 index 上面有点怪怪的
以 taiwan 为例(^ 表示空格)
s_1 = aiwan
^
s_2 = iwan
^^
s_3 = wan
^^^
s_4 = an
^^^^
s_5 = n
^^^^^
s_6 =
^^^^^^
每一个 suffix 都会少掉头一个字母。
想请问是不是说那几行改成
12 for j ← 1 to L - i + 1
13 s_ij ← x_(i + j - 1)
17 for j ← L - i + 2 to L
18 do s_ij ← ’ ’ // this is a space
会比较好?
谢谢!