Hash tables can look up any element in Theta(1) time and it is just as easy to add an element....but I'm not sure of the advantages going the other way around.
For instance, if a hash function has a range R(h) = 0...100, then you need to allocate an array of 100 (pointers-to) elements, even if you are just hashing 20 elements. If you were to use a binary search tree to store the same information, you would only allocate as much space as you needed, as well as some metadata about links.
Hash tables in general have better cache behavior requiring less memory reads compared to a binary tree. For a hash table you normally only incur a single read before you have access to a reference holding your data. The binary tree, if it is a balanced variant, requires something in the order of K * lg (n) memory reads for some constant k.
树往往是最终的平均数据结构。它们可以作为列表,可以很容易地并行操作拆分,具有快速删除,插入和查找的顺序为 O (lg n)。他们没有做好 尤其是,但他们也没有任何过分恶劣的行为。
Finally, BSTs are much easier to implement in (pure) functional languages compared to hash-tables and they do not require destructive updates to be implemented (the 坚持不懈 argument by Pascal above).
While, how can you do range searches in a hash table? You either need to iterate every bucket space, which is O(n), or you have to look for whether each of 1,2,3,4... up to 5000 exists.
(如果0到5000之间的键是一个无限集合呢? 例如键可以是小数)