ELEMENTARY SYMBOL TABLES AND BINARY SEARCH TREES
Elementary implementations.
Ordered array and linked list. Understand the performance of each.
Comparable vs. equals.
Keys must either be comparable or have an equals method which takes into account the semantics of the object. The default
equals method only checks reference equality.
API for Symbol Table and Ordered Symbol Table.
Know the operations that go with symbol tables and ordered symbol tables. You don't have to be able to list them, but you
should understand what they mean.
BST basics.
Know the definition of a BST and how to search and insert.
Recursive BST code.
You should be able to read recursive BST code. You will not be required to write recursive BST code, since you won't have
practice until the kd-tree assignment.
In-order traversal.
Understand how to perform an inorder traversal.
Treesort.
Understand how to use a BST to sort items. Insert all the items, then perform an inorder traversal.
This algorithm is similar to quicksort, where each node corresponding to a partitioning item
that subdivides its descendants into smaller keys and larger keys.
Deletion and Hibbard deletion.
Understand how to delete an item with 1 or 0 children. Understand how to delete an item with 2 children, a.k.a. Hibbard
deletion.
Symbol table performance.
Understand the performance of our elementary implementations. Understand the performance of a BST based symbol table in the
best, worst, and average (shuffled) case, with an emphasis on the fact that the height of a tree is the key factor.
Understand what Hibbard deletions do to tree height. You do not need to know why Hibbard deletes result in sqrt(n) height.
Recommended Problems
C level
- What is the best case BST height? Worst case?
- If shuffling guarantees log N tree height (probabilistically),
why don't we simply shuffle our input data before building our BST based symbol table to avoid worst case behavior?
- Textbook 3.2.3, but give only two orderings.
- Textbook 3.2.4
- Fall 2015 Midterm #3a and #3b
B level
- In our elementary implementations, we considered ordered arrays and linked lists. We did not consider ordered linked lists.
Why not?
- Give an example of something that you might like to store as a key in a symbol table for which there is no natural compare
method.
- Do there exist any objects for which it is impossible to define a total order? In other words,
can we always write a compare method if we're willing to do the work, or are some data types
fundamentally impossible to compare other than for equality?
- Stable 2-way partitioning is a partitioning procedure in which items that are smaller
than the pivot are kept in the same relative order after partitioning, and likewise with larger items.
For example, if we stably partition GADFLY on G, we'd get ADFGLY. Perform an entire
quicksort using stable partitioning on the array [5, 3, 2, 1, 9, 7, 6],
and record the compares you make along the way. Build the BST for this array.
Observe that the same exact compares were made.
What are the advantages and disadvantages of this stable 2-way partitioning algorithm
compared to the version we discussed in the Quicksort lecture?
- Textbook 3.2.22 (pretty easy, but good to do)
- Textbook 3.2.23
- Textbook 3.2.24 (so easy it might seem hard)
- Fall 2015 Midterm #3c
A level
- None available.