This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 10 1. Recall that in the Huffman coding problem, we are given a set of n characters along with their frequencies. We are required to represent each character by a unique codeword using 0’s and 1’s, such that no codeword is a prefix of another. The goal is to find such codewords that achieve maximum compression. (a) Construct the optimal code for the four characters a, b, c, d with frequencies 14, 3, 6, 10, respectively. Assuming the heap implementation of Huffman’s algorithm, show what items are deleted from the heap and inserted into the heap at each step. Character a b c d Frequency 14 3 6 10 Huffman’s tree: In heap order: a b c d n 1 n 2 n 3 Out heap order: b c n 1 d n 2 a n 3 Character Bits a 1 b 000 c 001 d 01 (b) How many bits are needed to encode a string containing 14 a’s, 3 b’s, 6 c’s and 10 d’s using the optimal code found in part (a)? And how may bits would be needed if we used 2 bits forthe optimal code found in part (a)?...
View Full Document