Discussion
In a hash table with 'n' slots using chaining for collision resolution, what is the average time complexity for search in the worst case ?
Answer: C
In the worst case a search takes O(n) time.
With separate chaining each slot holds a linked list of the keys that hash to it. If the hash function sends all n keys to the same slot, one chain holds every key, and a search has to walk that whole list, which is linear time.
O(1) is the average case with a good hash function and a bounded load factor, not the worst case. O(log n) applies only if each chain is replaced by a balanced tree. \(O(n^{2})\) is too large, since a search visits each key at most once.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development