(Latest Revision: 04/14/2003)
Why Use A Binary Search Tree for A Keyed List (Table)?
- Implementing a keyed list as an array (maintained in key-order):
- Advantages:
- Fast, O(log(Size)) worst case, binary search (faster than in
a BST)
- Fast, O(Size) worst case, in-order traversal (faster than in
a BST)
- Disadvantages:
- Slow, O(Size) on average, insertion and deletion operations
(moves required).
- Static Memory Allocation -- size limits -- wasted space.
- Implementing a keyed list as a linked list (maintained in key-order):
- Advantages:
- Dynamic memory allocation -- uses only the memory needed
(some extra for pointers).
- Fast, O(Size) worst case, in-order traversal (faster than in
a BST).
- Disadvantages:
- Slow, O(Size) on average, linear search. (Binary search is
not an option.)
- Slow, O(Size) average, insertion and deletion (linear search
required).
- Implementing a keyed list as a BST with nodes and links:
- Advantages:
- Average O(log(Size)) binary search
- Average O(log(Size)) insertion and deletion (find
position with binary search -- no moves required).
- Dynamic memory allocation -- uses only the memory needed
(some extra for pointers).
- Worst case O(Size), in-order, pre-order, and post-order
traversals.
- Disadvantages:
- The worst case of search, insertion, and deletion is O(Size)
-- (This happens when the tree has near-maximum height.)
Summary: Binary search tree's are "uniformly not bad" at performing all the
major operations expected for a keyed list.