In computing, a hash table (also hash map) is a data structure used to implement an associative array, a structure that can map Unique key|keys to Value (computer science)|values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found.
Ideally, the hash function should assign each possible key to a unique bucket, but this ideal situation is rarely achievable in practice (unless the hash keys are fixed; i.e. new entries are never added to the table after it is created). Instead, most hash table designs assume that Collision (computer science)|hash collisions—different keys that are assigned by the hash function to the same bucket—will occur and must be accommodated in some way.
In a well-dimensioned hash table, the average cost (number of instruction (computer science)|instructions) for each lookup is independent of the number of elements stored in the table. Many hash table designs also allow arbitrary insertions and deletions of key-value pairs, at constant average (indeed, amortized analysis|amortized) cost per operation.
In many situations, hash tables turn out to be more efficient than search trees or any other table (computing)|table lookup structure. For this reason, they are widely used in many kinds of computer software, particularly for associative arrays, database indexing, cache (computing)|caches, and set data structure|sets.
In computing, a hash table (also hash map) is a data structure used to implement an associative array, a structure that can map Unique key|keys to Value (computer science)|values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found.
Ideally, the hash function should assign each possible key to a unique bucket, but this ideal situation is rarely achievable in practice (unless the hash keys are fixed; i.e. new entries are never added to the table after it is created). Instead, most hash table designs assume that Collision (computer science)|hash collisions—different keys that are assigned by the hash function to the same bucket—will occur and must be accommodated in some way.
In a well-dimensioned hash table, the average cost (number of instruction (computer science)|instructions) for each lookup is independent of the number of elements stored in the table. Many hash table designs also allow arbitrary ins...