Can hash maps use a data structure other than an array to implement?

Question

In the context of this lesson, can hash maps use a data structure other than an array to implement?

Answer

Yes, you can absolutely use a different data structure other than an array to implement a hash map. However, using another data structure may decrease the performance of the hash map.

Using a different data structure can be disadvantageous, mainly because of the usefulness of arrays. Arrays let us obtain and assign values instantly, which most other data structures do not provide. For a hash map, it is important that it can instantly jump to the specific index and bucket location for getting and setting key-values.

For instance, if we used a linked list instead of an array to store all the indexes and buckets, lookups will take a bit longer because it must go through all the linked list nodes from the beginning each time.

In summary, it is best to use an array when implementing a hash map, unless it is absolutely necessary to use another data structure.