A hash table is an effective data structure for implementing dictionaries. The average time to search is 

A hash table generalizs the simpler notion of an ordinary array.

Direct-address Table

→ we can take advantage of it when we can afford to allocate an array that has one position for every possible key

Suppose that we need a dynamic set in which each element has a key drawn from the universe , where  is not too large.
To represent the dynamic set we use a direct-address table (i.e. array), in which each slot corresponds to a key in 

slot  points to an element in the set with key 

In some applications rather than storing the key and the data in an external object, we can store the object in the slot itself.

Hash Tables

→ direct-address tables can’t be used for large universes

Hash table requires much less storage when the set  of keys stored in a dictionary is much smaller than the universe .
Memory → 
Searching requires  time

We use a hash function  to compute the slot number from the key . The hash function maps the universe of keys into the slot of a hash table .
The hash function reduces the range of array indices, instead of a size of , the array can have size .

See also