Big O Gym › Problem

Big O Quiz: Hashmap Lookup Worst

What is the worst-case time complexity of looking up a key in a hashmap?

Concept: hashmap collision worst case

In the pathological case where every key hashes to the same bucket, the bucket becomes a linear list of `n` entries and lookup walks all of them - **O(n)**. Average case is O(1) (see the related problem); production hashmaps use techniques like tree-bucketed chaining (Java HashMap) or robin-hood probing to keep this from biting in practice, but the asymptotic worst case stands.

More Big O practice problems · Today's daily problem