hashmap
A hashmap is a data structure that stores key-value pairs and retrieves the value for a given key in average constant O(1) time. It implements an associative array, also called a map, so each entry is reached by a meaningful key instead of the numeric position an array uses.
Under the hood, a hashmap is almost always built on a hash table, which runs each key through a hash function to place its value in an array slot. That backing store gives the structure its fast average lookup, and it inherits the hash table’s trade-offs, from the cost of resizing as the map grows to the way many colliding keys can drag a single operation toward O(n).
A hashmap exposes a small, consistent set of operations, each averaging constant time on a well-sized table:
- Insert: Stores a value under a key, replacing any value already held there.
- Lookup: Returns the value bound to a key, or reports that the key is absent.
- Delete: Removes a key and its value from the map.
The names hashmap, hash map, and hash table refer to the same idea in most settings, though some languages reserve map for the key-value abstraction and hash table for the structure beneath it. Concrete examples include Java’s HashMap, C++’s unordered_map, and Python’s built-in dictionary, whose keys must be hashable so the hash function can position them.
Related Resources
Tutorial
Build a Hash Table in Python With TDD
In this step-by-step tutorial, you'll implement the classic hash table data structure using Python. Along the way, you'll learn how to cope with various challenges such as hash code collisions while practicing test-driven development (TDD).
For additional information on related topics, take a look at the following resources:
- Dictionaries in Python (Tutorial)
- How to Iterate Through a Dictionary in Python (Tutorial)
- Sorting a Python Dictionary: Values, Keys, and More (Tutorial)
- Custom Python Dictionaries: Inheriting From dict vs UserDict (Tutorial)
- Python Dictionary Iteration: Advanced Tips & Tricks (Course)
- Build a Hash Table in Python With TDD (Quiz)
- Using Dictionaries in Python (Course)
- Dictionaries in Python (Quiz)
- Python Dictionary Iteration (Quiz)
- Sorting Dictionaries in Python: Keys, Values, and More (Course)
- Sorting a Python Dictionary: Values, Keys, and More (Quiz)
By Martin Breuss • Updated Aug. 11, 2026