Hashing Visualizer
Hash Tables
Watch keys map into buckets with modulo hashing, collisions, chain traversal, and live average versus worst-case complexity.
Average O(1), worst O(n)
bucket = abs(key) % 7active key: 18
Bucket 0
key7
key14
key21
Bucket 1
empty
Bucket 2
empty
Bucket 3
empty
Bucket 4
key18
key25
key32
Bucket 5
empty
Bucket 6
empty
Time
Average O(1), worst O(n)
Space
O(n)
Step Note
Hash table is built with 6 keys and 7 buckets.
function search(table: Bucket[], target: number) {
const bucket = Math.abs(target) % table.length
for (const entry of table[bucket]) {
if (entry.key === target) {
return entry
}
}
return null
}