What is the average-case and worst-case complexity of a hash table lookup?
- A.Average O(1), worst case O(1)
- B.Average O(1), worst case O(n)
- C.Average O(log n), worst case O(n)
- D.Average O(n), worst case O(n log n)
Answer: B
Average O(1), worst case O(n). A good hash function spreads keys evenly so each bucket holds only a few elements. When many keys collide into the same bucket, the operation degenerates into a linear scan of that bucket's list.
References