Reputation: 699
For what number range of elements is a hash map suited for?
I understand that everything is constant time and that the only problem caused will be a large memory consumption, but I would be interested to know to what extent is too much?
Upvotes: 1
Views: 70
Reputation: 55589
Any number range.
The only problem is most certainly not memory consumption. Memory consumption is generally linear in the number of elements, which isn't particularly bad.
If there are plenty of hash collisions (elements hashing to the same value), this would be a major problem, as you'd have to search all elements with that hash value to find the correct one. A popular method of storing elements that have the same hash value (called 'separate chaining') is using a linked-list, and searching in a linked-list is slow.
Whether or not a hash table would perform well depends on:
Upvotes: 1