Hash tables v self-balancing search trees

后端 未结 6 2098
北恋
北恋 2021-02-05 10:34

I am curious to know what is the reasoning that could overweighs towards using a self-balancing tree technique to store items than using a hash table.

I see that hash

6条回答
  •  爱一瞬间的悲伤
    2021-02-05 11:21

    Here is what I can think of:

    1. There are kinds of data which cannot be hashed (or is too expensive to hash), therefore cannot be stored in hash tables.
    2. Trees keep data in the order you need (sorted), not insertion order. You can't (effectively) do that with hash table, even if you run a linked list through it.
    3. Trees have better worst-case performace

提交回复
热议问题