A hash map stores key โ value pairs and finds any of them almost instantly. The trick is a tiny hash function: it folds a key down to a single number, and modulo the array size turns that number into a bucket index. No scanning โ you compute exactly where a key lives. Below, watch keys drop into buckets, collide, chain, probe, and trigger a resize.
Type a key and a value, then Insert. The key is fed through a small hash function to a big number; we take that mod 8 to pick a bucket, and the pair drops in. To find it again, we re-hash the same key, jump straight to that bucket, and read the value โ that's the O(1) average lookup. No walking the array.
Two different keys can hash to the same bucket โ a collision. There are two classic fixes. Chaining hangs a linked list off the bucket; open addressing probes forward to the next free slot. As the load factor (entries รท buckets) climbs, chains lengthen and probes run longer, dragging lookups toward O(n). Cross a threshold and the table resizes โ doubles its buckets and rehashes everything to spread keys thin again. Hit Add colliding key to force a pile-up.
A hash map trades a little arithmetic for the right to skip searching. Compute the bucket, look there, done.
dict, JS objects, Java HashMap), database
hash indexes, caches (memcached / Redis), deduplication, and
symbol tables in compilers โ all lean on this same key โ bucket trick.