next up previous
Next: About this document ... Up: Assignment 10: Huffman Codes Previous: Build the Frequency table

Build the Huffman tree

1.
Go to http://rocky.colby.edu/cs231/code/Huffman2/ and pick up a copy of the stripped version of HuffTree.java and the complete versions of Heap.java and Comparable.java.

NOTE: You should not have to make any changes to Heap.java or Comparable.java--that's the nice thing about ADTs!

NOTE: This directory also contains solutions to part one of the assignment.

2.
Look over HuffTree.java; it indicates which methods you have to fill in.

3.
In Huffman.java, fill in the methods buildHuffTree and decode. To debug your program you may want to use the methods I provide for printing a tree. Keep in mind that you might not get exactly the same tree as in the book, but it should be similar in the sense that each letter should have the same code length as in the book, even if the code is not identical.



Allen B. Downey
1998-12-07