Another common implementation(besides linked-list) for a hash table is to use a BST as the underlying data structure.
I've searched the web and SO but can't find the answer. How do I implement a Hashtable using a Binary Search Tree? 's answer just like wrapping the BST into a hash table, I don't think that means implementing hash table using a BST.
Please show me the codes for put() and get() method.
The answer is that you simply can't!
The insert/find time in a BST is O(log n) while in HashTable it should be O(1)
UPDATE:
Now after I looked at the book...
Bin you missed what Gayle was referring to - the original question was:
Design and implement a hash table which uses chaining (linked lists) to handle collisions
then at the end of the answer it says
Another common implementation(besides linked-list) for a hash table is to use a BST as the underlying data structure.
It refers to the same thing as the original question: the use of BST is only when collisions occur, which means that the buckets part will be implemented as BST/List not the hash-map itself!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With