Which search is faster, binary search or using prefix tree?

a 夏天 提交于 2019-12-05 18:03:16

Both techniques have their advantages, and their drawbacks:

Suffix tree

  • Advantages:
    • O(N) building complexity
    • O(M) search of a pattern of length M
    • They allow online construction
  • Drawbacks:
    • Space inefficient
    • Really complex construction algorithms

Binary search (with suffix array)

  • Advantages:
    • You can sort the string array in O(N) time
    • Space efficient (five times less memory (at least))
    • Simple and straightforward construction algorithms
  • Drawbacks:
    • They don't support online construction
    • O(M lg N) time to search a pattern of length M among N strings (this can be reduced to O(M+lg N) but this is still a little slower than suffix tree)

Both of these data structures are really powerful. If your application requires fast searching, and the space supplied is enough, then definitely go for suffix trees. But if the space matters, then suffix array(binary search) is the only choice you have...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!