Chapter 9: Search Trees I
We study several alternative data structures based on trees for
realizing ordered dictionary. The fundamental operations in an ordered
dictionary ADT are:
-
find(k) -
Return the position of an item with key k, and return a null
position if no such item exists.
- findAll(k) -
Return an iterator of positions for all items with key k, and return a null position
if no such item exists.
- insertItem(k,e)
- Inserts an item with element e
and key k.
- removeElement(k)
- Remove an item with key k.
An error condition occurs if there is no such item.
- removeAllElements(k)
- Remove all items with key equal to k.
9.1 Binary Search Trees
BinarySearchTrees.pdf
5
Inorder traversal visits the keys of its dictionary in nondecreasing
order.
9.1.1 Searching
BinarySearchTrees.pdf
6
Analysis of Binary Tree Searching
Function find(k) on
dictionary D runs O(h)
time, where h is the height
of the binary search tree T
used to implement D.
9.1.2 Update Operations
Insertion
BinarySearchTrees.pdf 7
Removal
BinarySearchTrees.pdf
8, 9
Best-case versus Worst-case
BinarySearchTrees.pdf
10
9.1.3 C++ Implementation
A Binary Search Tree in C++
html-9.2
(Position)
html-9.3 (BST1)
html-9.4 (BST2)
html-9.5 (BST3)
html-9.6 (BST4)
except.h - LBTree.h - BSTree.cpp
9.1.4 Performance