Directi Interview Question
Software Engineer / DevelopersQ: Colliston detection techniques for HashTable
1. Open Addressing :
- Linear Probing
- Quadratic Probing
- Double Hashing
2. Separate Chaining using Linked List
Q : When should a Hash table be used and when should a BST?
Use Hashtable when you have to do single value look up like what is the phone number for person ABC (Assuming your hastable stored name as key and numbers as value pair)
Use BST when you need to work over range of data like show names of employees whose salary is above $10,000 (assuming you have BST sorted by employee salary)
Implement a dictionary ADT efficiently.
- Anonymous February 16, 2010Since all hash functions are not perfect hashes, there will few inputs which are mapped to same hash values. This is Collision.
2 ways - Open Hashing & Closed Hashing. Open Hashing - create a bucket list for every collision entry. Closed hashing finds the next free spot in the Hash table.
If you want operations involving any ordering among elements - min, max, predecessor or successor, you would use a BST. If not we can go for hash. Hashtable can also help in reducing memory as we will be avoiding the use of pointers(assuming limited collisions).
No. Hash tables have avg O(1) complexity.