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
This note was uploaded on 12/09/2010 for the course ENGLISH 1303 taught by Professor May during the Spring '10 term at HKU.
 Spring '10
 may
 English, Ode

Click to edit the document details