Search tree is the key in each node must be greater than all keysstored in the left sub-tree, and smaller than all keys in theright sub-tree.
Difference between BST and hash
So Hash Table seems to beating BST in all common operations.
When should we prefer BST over Hash Tables, what are
advantages. Following are some important points in favor of BSTs.
We can get all keys in sorted order by just doing Inorder Traversal
of BST. This is not a natural operation in Hash Tables and requires
extra efforts.
Doing order statistics, finding closest lower and greater elements,
doing range queries are easy to do with BSTs. Like sorting, these
operations are not a natural operation with Hash Tables.
BSTs are easy to implement compared to hashing, we can easily
implement our own customized BST. To implement Hashing, we
generally rely on libraries provided by programming languages.
With BSTs, all operations are guaranteed to work in O(Log(n) )
time. But with Hashing, ÎÝ(1) is average time and some particular
operations may be costly, especially when table resizing happens.