[CS Dept logo]

Computer Science 117
CS117-02, Introduction to Programming III: C++ Spring 1998


Homework #5

Due Wednesday May 27

You may want to consult Bruce Schneier's article on red black trees before starting the assignment.
  • Exercise 1. In the class text on page 280, an example implementation of the Set class is given. The author uses a simple binary tree to do this. As I've discussed in class, a binary tree may become unbalanced and the O(logn) search property may be lost. A way around this is to keep the tree balanced. A red-black tree is one kind of balanced tree that I've presented in class. Implement Set in terms of red-black trees.
  • Exercise 2. Using the hash table implementation given in the book on pages 422--425, implement buckets using red-black trees.
  • Exercise 3. Do Exercise 12 on page 427.
  • Exercise 4. In this exercise, you will compute a word histogram for a text file. That is, given an input file, build a program that computes a table of word frequencies. Using the hash table class that you developed in Exercise 1 or 2, write a program that will prompt the user for an input file name and then compute and print out the word histogram for that file. You may want to change your red-black tree implementation slightly so that node values are pairs (p. 388 in the text), so that word counts can be indexed via word names.
Charles Earl
Last modified: Fri May 22 15:10:19 CDT 1998