Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b43e2e

Browse files
Oleksandr Kulkovadamant-pwn
authored andcommitted
the alphabet contribution to the complexity
1 parent 0d54cff commit 4b43e2e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/string/suffix-array.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,9 @@ We use temporary arrays $pn[]$ and $cn[]$ to store the permutation by the second
200200
return p;
201201
}
202202
```
203-
The algorithm requires $O(n \log n)$ time and $O(n)$ memory.
204-
However if we take the size of the alphabet $k$ into account, then it uses $O(n \log n + k)$ time and $O(n + k)$ memory. The first counting sort takes $O(k)$ time, but all following counting sorts are bounded by the number of equivalence classes, and take $O(n)$ time.
203+
The algorithm requires $O(n \log n)$ time and $O(n)$ memory. For simplicity we used the complete ASCII range as alphabet.
205204
206-
For simplicity we used the complete ASCII range as alphabet.
207-
If we know that the string only contains a subset of characters, e.g. only lowercase letters, then this implementation can obviously be optimized.
208-
However not by much, since the alphabet size affects the runtime of only a single counting sort.
205+
If it is known that the string only contains a subset of characters, e.g. only lowercase letters, then the implementation can be optimized, but the optimization factor would likely be insignificant, as the size of the alphabet only matters on the first iteration. Every other iteration depends on the number of equivalence classes, which may quickly reach $O(n)$ even if initially it was a string over the alphabet of size $2$.
209206
210207
Also note, that this algorithm only sorts the cycle shifts.
211208
As mentioned at the beginning of this section we can generate the sorted order of the suffixes by appending a character that is smaller than all other characters of the string, and sorting this resulting string by cycle shifts, e.g. by sorting the cycle shifts of $s + $\$.

0 commit comments

Comments
 (0)