Hello everyone,
Is there an algorithm to build Suffix Array in complexity O(n)?
Thanks in advance!
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 170 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
5 | -is-this-fft- | 158 |
7 | adamant | 154 |
7 | Dominater069 | 154 |
9 | awoo | 153 |
10 | luogu_official | 152 |
Hello everyone,
Is there an algorithm to build Suffix Array in complexity O(n)?
Thanks in advance!
Name |
---|
I don't know how to build it in O(n) but, Yes there are algorithms to build Suffix Arrays in O(n).
Li, Li & Huo (2016) gave the first in-place O(n) time suffix array construction algorithm that is optimal both in time and space, where in-place means that the algorithm only needs O(1) additional space beyond the input string and the output suffix array.
Li, Zhize; Li, Jian; Huo, Hongwei (2016). Optimal In-Place Suffix Sorting. Proceedings of the 25th International Symposium on String Processing and Information Retrieval (SPIRE). Lecture Notes in Computer Science. 11147. Springer. pp. 268–284. arXiv:1610.08305. doi:10.1007/978-3-030-00479-8_22. ISBN 978-3-030-00478-1.
source: https://en.wikipedia.org/wiki/Suffix_array
You can try to search dc3 algorithm (becareful that there are many wrong implementations)
You can build suffix trie in linear time by building SAM on the reversed string so I presume something similar should work for suffix array.
Note that SAM works in $$$O(26N)$$$ time, or more generally $$$O(\Sigma N)$$$ time where $$$\Sigma$$$ is the size of the alphabet. There are algorithms which run in $$$O(N)$$$ time even when $$$\Sigma = \Theta(N)$$$, such as DC3 and SAIS.