Data Structures & AlgorithmsEasyIBM · Deloitte pattern

With a good hash function and a bounded load factor, what is the average time to search for a key in a hash table?

  1. A. O(n log n)
  2. B. O(1)
  3. C. O(n)
  4. D. O(log n)

Correct answer: B. O(1)

With keys spread evenly and the load factor kept constant, each bucket holds O(1) keys on average, so search is O(1) on average. The worst case, when all keys collide, is still O(n).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic