Hashtable vs associative array


Hashtable vs associative array,are they similar,different,how ??


The term “hash table” is talking about the implementation: a specific way to organize your data in memory.

The term “associative array” is talking about the interface: the concept that you use objects as array indices. (This is sometimes called an abstract data structure.)

There are multiple ways to implement an associative array. A hash table is one of them – in fact, it is by far the most common one.


The difference between an associative array and a hash table is that an associative array is a data type, while a hash table is a data implementation. Obviously the associative array type is very important in many current programming languages: Perl, Python, PHP, etc. A hash table is the main way to implement an associative array, but not quite the only way. And associative arrays are the main use of hash tables, but not quite the only use. So it’s not that they are the same, but if you already have associative arrays, then you usually shouldn’t worry about the difference.

For performance reasons, it can be important to know that your associative arrays in your favorite language are implemented as hashes. And it can be important to have some idea of the overhead cost of that implementation. Hash tables are slower and use more memory than linear arrays as you see them in C.