Building suffix tree ACB when we already have suffix tree AB

97 views Asked by At

I recently encounter a question about suffix tree. Assume we already have a suffix tree for string S=AB, i.e., S is a concatenation of prefix A and suffix B of S. Now we want to build suffix tree U=ACB. What is the most efficient algorithm for this task so far?

A naive way would be to rebuild U all over again, which can be done in O(|U|) time. But it will not utilize any information of suffix tree of S. Can we do better than O(|U|)? Maybe O(|C|), i.e., as good as building a suffix tree of just C?

Thanks very much.

1

There are 1 answers

0
j_random_hacker On

Based on Googling "dynamic suffix tree", I think this is probably an area of active research. I was able to find the paper

Paolo Ferragina and Roberto Grossi, "Fast incremental text editing", Proceedings of the sixth annual ACM-SIAM symposium on Discrete algorithms, pp. 531-540, 1995

This isn't the first (or probably the last) word on the topic, and I only skimmed part of it, but they present several variations on suffix trees that achieve better times when strings are inserted, deleted or changed. After the u-th substring insertion:

  • Data structure 1
    • To find all pocc occurrences of a length-p string: O(p + pocc + u*log(p) + log n)
    • To insert a length-s string: O(s*log(n + s))
  • Data structure 2
    • To find all pocc occurrences of a length-p string: O(p*log(p) + pocc + u*(log(p) + log(n/u)))
    • To insert a length-s string: O(s*log(s) + log u)