SearchingAnimated
Hash-based Search
Jump straight to a bucket computed from the key.
Time
O(1) avg, O(n) worst
Extra space
O(n)
Use it for
Exact-match lookups with no ordering needs.
How it works
- Store each value in a bucket chosen by a hash function: bucket = value mod m.
- To search, compute the same hash of the target.
- Only look inside that one bucket (values that collide share a bucket).
- With a good hash and enough buckets, lookup takes O(1) on average.
Watch it run
Loading animation…