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.
4 / \ / \ / \ / \ / \ / \ / \ 6 8 / \ / \ / \ / \ / \ / \ / \ / \ 9 12 15 10 / \ / \ / \ / \ 14 23 18 13 |
1. Show the contents of an array that represents the heap.
2. Carry out the following operations in succession, showing what the heap looks like after each operation has been completed. Recall that inserting an element involves adding a new leaf containing that element into the tree (at the next available leaf position) and then sifting up until its parent's key is smaller than or equal to its key. Deleting the minimum involves removing the "last" leaf in the tree, after placing its element into the root, and then sifting down from the root.
(a) insert(11)
(b) insert(2)
(c) deleteMin()
(d) deleteMin()
|
consisting of all bit strings of length three. 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.
(b) Use the Huffman Tree to assign codewords to the "symbols" a through h.
(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.