Hash Map
A hash map stores key-value pairs in a bucket array. A hash function maps any key to a bucket index in O(1). Collisions use separate chaining, each bucket is a linked list.
djb2(key): h=5381; for c in key: h = (h×33) XOR ord(c);
index = djb2(key) % capacity
💡Simplification: This shows chains as linked lists. In Java's HashMap, chains automatically convert to a red-black TreeMap once length > 8.
Key
Value
Search
Target
Load Factor0/8 = 0.00
Capacity: 8Entries: 0Used: 0/8Max Chain: 0
[0]
null
[1]
null
[2]
null
[3]
null
[4]
null
[5]
null
[6]
null
[7]
null