Hash table
From WikiTech, the free technology encyclopedia
Data structure that finds items by key very quickly
4 sources from National Institute of Standards and Technology (Dictionary of Algorithms and Data Structures), Princeton University, Python Software Foundation and 1 more. Checked by ByteExplained editors on 5 December 2026. How we check facts
Hash table is the name for a data structure that stores items, such as names with their phone numbers, so that each can be found quickly by its key. Formally, it is a dictionary in which keys are mapped to positions in an array by a hash function.[1]
How it works
A hash table is built on an ordinary array. A hash function turns each key into an array index by doing arithmetic on it. A good hash function is quick to calculate and spreads keys evenly across the array.[2] When the keys of two or more items map to the same position, this is called a collision.[1] There are many ways of handling collisions, but they fall broadly into chaining and open addressing.[1]
In separate chaining, each array position holds a linked list of all the items whose keys hash to it, and a search scans only that short list. In linear probing, a form of open addressing, an item whose position is taken goes into the next free slot. The share of the table that is filled, called the load factor, affects speed; with linear probing it must stay below one, and searches slow down as the table fills.[2]
Because a lookup goes straight to one position rather than checking every item, a hash table can retrieve a key in constant time, written O(1), when stored keys have different hash values.[3]
History
The idea goes back to IBM researcher Hans Peter Luhn. In early 1953 he wrote an internal memo suggesting that information be sorted into "buckets" to speed up searching. His method combined the digits of a value such as a telephone number to produce a bucket label, so a search only had to scan the entries in one bucket rather than the whole list.[4]
Uses
Hash tables are built into many programming languages. In Python (programming language), the dictionary type is implemented as a resizable hash table, chosen because it usually gives faster lookups than B-trees and is simpler to implement.[3]
See also
References
- ^ hash table. National Institute of Standards and Technology (Dictionary of Algorithms and Data Structures). 2022-04-20. xlinux.nist.gov
- ^ Hash Tables (Algorithms, 4th Edition, Section 3.4). Princeton University. algs4.cs.princeton.edu
- ^ Design and History FAQ: How are dictionaries implemented in CPython?. Python Software Foundation. docs.python.org
- ^ Hans Peter Luhn and the Birth of the Hashing Algorithm. IEEE Spectrum. 2018-01-30. spectrum.ieee.org





