Tuesday, April 3, 2012


http://www2.research.att.com/~bs/whitespace98.pdf

HW:
step 1)
find the freq table

2) charfreq class, comparable

3) revisit your generic binarytree class, where binarytrees should also be comparable. based on the value stored at the root.

4) Take your freq table, create a forest of trees, where each tree contains a charFreq.

Revisit your priorityqueuue. make sure it is generic.

5) Algorithm for creating a Huffman Tree:
a)  Take your freq table, create a forest of trees, where each tree contains a charFreq.
b) As you create each tree in your forest, insert it into the PQ.

c) While PQ.size() != 1
Tree T1 = PQ.dequeue();
Tree T2 = PQ.dequeue();
Tree T3 = join(T1, T2); // where root node's charfreq's freq is the sum of the freq of roots of T1 and T2
PQ.enqueue(T3);

outside of while loop:
d) Tree Huffman = PQ.dequeue();

6) Use the Huffman tree to encode a text file. (You may encode it as a string first.)
Do a visit of each node. If go to left, append a '0', else append a '1'.
Write to a table what string corresponds to a given letter.

Then, loop thru your file, creating an appropriate text string.

Using bitshifting, << >> | &, generate byte array. Write to a file.

7) Open a file, use your existing Huffman Tree, convert bit pattern (or string) to original text.