Advantages of Binary Search Trees over Hash Tables

前端 未结 18 1116
醉酒成梦
醉酒成梦 2020-11-29 15:02

What are the advantages of binary search trees over hash tables?

Hash tables can look up any element in Theta(1) time and it is just as easy to add an element....but

18条回答
  •  孤独总比滥情好
    2020-11-29 15:38

    If you want to access the data in a sorted manner, then a sorted list has to be maintained in parallel to the hash table. A good example is Dictionary in .Net. (see http://msdn.microsoft.com/en-us/library/3fcwy8h6.aspx).

    This has the side-effect of not only slowing inserts, but it consumes a larger amount of memory than a b-tree.

    Further, since a b-tree is sorted, it is simple to find ranges of results, or to perform unions or merges.

提交回复
热议问题