Hash Map Insert/Lookup Complexity (Big-O)
A hash map supports expected O(1) insert, lookup, and delete via a hash function; the worst case is O(n) when many keys collide. Space is O(n).
Open the interactive DevRef Hub tool →Key facts
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(n) |
| Space | O(n) |
Frequently asked questions
What is the time complexity of hash map insert?
O(1) expected, O(n) worst case under heavy collisions.
Why is hash map worst case O(n)?
When many keys hash to the same bucket, operations degrade to a linear scan.
Related pages
Big-O of Hash Map Insert is part of DevRef Hub on GOAT Lab — a free reference you can use without signing up, and it works offline. Open the tool above for any custom value.
Part of GOAT Lab — 26 free, browser-based science, engineering and developer tools. No sign-up.