CMPS 144L Spring 2020
Lab #11 (Week of May 4): Huffman Coding and Prim's Algorithm

The activities in this lab mimic problems that you are likely to see in either the upcoming test or the final exam. You can answer them using pen(cil) and paper, or you could put the answers in a plain text file and submit it.

Activity #1: Huffman Compression

SymbolFrequency
a (000)26%
b (001)2%
c (010)6%
d (011)15%
e (100)28%
f (101)4%
g (110)8%
h (111)11%
 
Suppose that we wish to compress a file and that we are interpreting its contents as being a sequence of 3-bit blocks, which is to say that we are viewing it as being a string "over the alphabet" consisting of all bit strings of length three:

{000, 001, 010, 011, 100, 101, 110, 111}

For the sake of convenience, we will use the names a through h to refer to these eight "symbols", respectively. (Also for the sake of convenience, we will assume that the file's length, in bits, is divisible by three.)

The frequencies with which the symbols occur in the file is given by the table to the left.

(a) Build a Huffman Tree based upon the given frequencies. (You need not include a "picture" in your submission.)

(b) Use the Huffman Tree to determine, for each "symbol" a through h, its codeword. (Your submission should include a table that displays this information.)

(c) Compute the ratio between the lengths of the resulting compressed version of the file and the original file. Of course, this involves computing the average number of bits, per symbol occurrence, that would be used in encoding the file using the codewords. This is the sum, taken over all eight symbols in the alphabet, of the product of the symbol's frequency and the length of its codeword.


Activity #2: Prim's Algorithm

Apply Prim's Algorithm to the graph shown below to produce a minimum spanning tree. Begin by placing vertex I into set S (i.e., as the first vertex to be placed into the tree).

You are not expected to include drawings of the graph in your submission. What you should show are the values of S, Z, E', and the relevant elements of the closest[] array, as they would exist just before the first loop iteration and just after every iteration. In other words, your answer should include the stuff underneath each picture of the graph in the relevant web page. (The link on the CMPS 144 course web page is titled "Prim's Algorithm: Demonstration".)