I just started working with suffix trees, so I might be wrong, but it seems that inserting or deleting can change the tree in quite radical ways.
"abcdef" is a really trivial suffix tree:
abcdef ├a..$ ├b..$ ├c..$ ├d..$ ├e..$ └f$
Adding “g” to the end or removing “a” at the beginning is incredibly simple.
But let's say we run another 'a' in the middle:
abcadef ├a │├b..$ │└d..$ ├b ├c ├...
We have to go back and check each letter from the very beginning to see if we need to insert a node based on this. Same thing if we have a character from the end:
abafef ├a │├bafef$ │└fef$ ├bafef$ ├f │├ef$ │└$ └ef$
If you inserted something like "ef" to the end, you have to go through and add new nodes everywhere!
Inserting a character looks like it will include a re-view of each character in the string, i.e. linear time. Since Ukkonen's algorithm already takes linear time, you should not use any dynamic insertion algorithm, you should just regenerate the tree from scratch every time with the confidence that it is still pretty good.
If you care about the space, you can always cache every step of the tree generation algorithm, and then when it comes time to insert or delete at point x, just load the tree as constructed to point x.
Brownbat
source share