Binary Search Tree
We’ve looked at a couple different search strategies so far:
- Linked structures allowed easy insertion/deletion, but the best method for searching a linked list was sequential search
- Binary search was fast, but required contiguous storage, making it expensive to modify the database
Binary trees can be used to solve the problem
- We can use the left/right ordering of subtrees to order our data (as required for binary search in contiguous storage)
- We can use the linked structure to allow efficient updates
Definition (from Aho, Hopcroft, Ullman): a binary search tree is a binary tree in which every node x satisfies the conditions:
- Every node in the left subtree of x has a key < the key of x
- Every node in the right subtree of x has a key > the key of x
- THE DEFINITION IN THE BOOK IS INCORRECT! Here’s a counterexample (not a binary search tree, but it meets book’s definition):