Its a very rare question which one will ask but we should know When to use BST and when hashtable?
To solve this problem, we will discuss the pros and cons of BST over hashTable.
1) BST always gives elements in sorted order by default if we do the inorder traversal of it as compared to hashtable where extra efforts are required to sort the elements.
2) While writing our own custom BST, it is always easy as compared to a hashTable where writing a customized hashtable is difficult as we have to rely on different third party libraries to achieve the same .
3) BST's will guranteed O(logn) for basic operations including search, delete and insert which cannot be the case with hashtable as although hashtable will give O(1) time complexity for such operations but sometimes its not guranteed as these operations can be costly if resizing of hashtable happens.
To solve this problem, we will discuss the pros and cons of BST over hashTable.
1) BST always gives elements in sorted order by default if we do the inorder traversal of it as compared to hashtable where extra efforts are required to sort the elements.
2) While writing our own custom BST, it is always easy as compared to a hashTable where writing a customized hashtable is difficult as we have to rely on different third party libraries to achieve the same .
3) BST's will guranteed O(logn) for basic operations including search, delete and insert which cannot be the case with hashtable as although hashtable will give O(1) time complexity for such operations but sometimes its not guranteed as these operations can be costly if resizing of hashtable happens.