Homework 2
Search Trees and Hash Tables
Due: Friday, Oct 31, beginning of class
This assignment is designed to give you practice with various
implementations of the search and dictionary ADTs we have seen. Given
the timing of this assignment and the upcoming midterm, it may not
give you enough practice with the underlying concepts. You are
encouraged to work on some more problems from the textbook on your own
and verify your solutions with the course staff.
Note: Please review the collaboration policy on the
course web page. You must mention the names of fellow students
who you worked with on this assignment.
Total: 80 points. 20 points for each problem.
- [Search Trees] Show the result of inserting 10, 15, 12, 3,
1, 13, 4, 17 and 8 into the following initially empty search tree data
structures. It's fine to turn in only the final result. However, if
your final answer in incorrect, intermediate steps may allow partial
credit.
- Binary search tree (unbalanced)
- AVL tree
- Splay tree
- B-tree with M=3, L=2
- B-tree with M=3, L=3
- [Hash Tables] Do the same as you did in the above
problem, but now for the following hash table implementations.
Indicate if and when no more keys can be inserted into the table.
- Hash table of size 11 with separate chaining
- Hash table of size 11 with open addressing and linear probing
- Hash table of size 11 with open addressing and quadratic probing
- Hash table of size 11 with open addressing and double hashing,
where
hash2(x) = 5 - (x mod 5)
- Hash table of size 11 with open addressing, quadratic probing and
rehashing when the table is half full
- [Range Search] Give an algorithm (pseudocode) that takes
a binary search tree as input along with two keys
x
and
y
, with x
less than or equal to
y
, and prints out all keys z
in the tree
that lie between (and including) x
and y
.
- What is the worst-case running time of your algorithm? Give
a bound in terms of the tree size
N
, the tree depth
D
, and the number M
of keys output.
- What would be the worst-case running time if instead of a
binary search tree, you were given a hash table with
tableSize S
and N
elements?
- [Open Addressing] Problem 5.6, page 178.