Suffix tree and Tries. What is the difference?

前端 未结 4 1044
广开言路
广开言路 2020-12-12 12:03

I am reading about Tries commonly known as Prefix trees and Suffix Trees.
Although I have found code for a Trie I can not find an

4条回答
  •  粉色の甜心
    2020-12-12 12:24

    If you imagine a Trie in which you put some word's suffixes, you would be able to query it for the string's substrings very easily. This is the main idea behind suffix tree, it's basically a "suffix trie".

    But using this naive approach, constructing this tree for a string of size n would be O(n^2) and take a lot of memory.

    Since all the entries of this tree are suffixes of the same string, they share a lot of information, so there are optimized algorithms that allows you to create them more efficiently. Ukkonen's algorithm, for example, allows you to create a suffix tree online in O(n) time complexity.

提交回复
热议问题