Confusion over the differences between hashmap and hashtable

I have a confusion:

I read in many posts that Hash-maps are implemented as binary search trees, which makes the logarithmic complexity difficult for various operations.

Hashtables , on the other hand, provide a constant sampling of time.

But, as I read in this one , no difference was provided in terms of the complexity of searching / searching for elements in two data structures.

So here is my question -

Since hashtables guarantee constant search complexity, their implementation must be different from the implementation of hash maps. So, why does anyone ever use hash maps if they do not provide a constant time search. Also, why are they primarily implemented as binary search trees?

I know that hash cards store keys in sorted form and provide iteration through the map. But the same could also be included in the hash table.

+4
source share
1 answer

Your confusion stems from the following:

Hash maps are implemented as binary search trees

This is not true. No reasonable naming convention will use the term "hashmap" to describe a tree-based structure.

For example, in Java, HashMap based on a hash table and TreeMap based on a tree.

C ++ uses neither a "hash" nor a "tree" in the name of its standard containers. Two containers that are oiled correspond to HashMap and TreeMap , std::unordered_map and std::map .

+7
source

Source: https://habr.com/ru/post/1481496/


All Articles