Skip to main content

What is the complexity of removing an element from a hash table?

The average time complexity of removing an element from a hash table is O(1).

Why:

  1. The hash function computes the slot index in constant time.
  2. The table accesses the right bucket directly.
  3. The element is removed directly, without traversing the whole structure.

But in the worst case: If a bucket has many collisions (for example, it holds a long list), all elements in that bucket must be walked, and then removal takes O(n).

Summary:

  • Average complexity: O(1)
  • Worst case: O(n)
  • Under normal load (load factor < 0.75) and with a good hash function: removal is almost always instant.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.