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
會比較好?
謝謝!