ta10_question

# ta10_question - full binary tree(i.e every internal node...

This preview shows page 1. Sign up to view the full content.

COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 10 1. Recall that in the Huﬀman 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 preﬁx of another. The goal is to ﬁnd 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 Huﬀman’s algorithm, show what items are deleted from the heap and inserted into the heap at each step. (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 for each character? Which code is better? (c) Prove that the optimal preﬁx tree must be a
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: full binary tree (i.e., every internal node must have 2 children). (d) Let x and y be the two characters having the two lowest frequencies. Is it true that x and y are siblings (i.e., children of the same node) in every optimal preﬁx tree? Justify your answer brieﬂy. (e) Consider the optimal preﬁx tree T 1 built by Huﬀman’s algorithm, given n characters with frequencies f 1 ≤ f 2 ≤ ··· ≤ f n . A key idea underlying Huﬀman’s algorithm is that this tree T 1 is related to the optimal preﬁx tree T 2 for a certain set of n-1 characters. Answer the following brieﬂy. (i) What are the frequencies of these n-1 characters? (ii) And what is the relationship of tree T 1 to tree T 2 (i.e., how can you obtain tree T 1 from tree T 2 )? c ± 2006 Chung Kai Lun Peter. Comments are welcomed. Email: [email protected] 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online