Hash Tables
Map keys to array slots with a hash function for O(1) average lookups.
Intermediate
A hash function turns a key into an index. Two keys landing on the same index is a collision, handled by chaining (a list per slot) or open addressing (probe the next free slot).
Average insert/lookup/delete: ; worst case if many keys collide. When the table fills up past its load factor, it is resized and every key is rehashed. Python dict, Java HashMap and C++ unordered_map are hash tables.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.