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

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

View Full Document Right Arrow Icon
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. (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 prefix tree must be a
Background image of page 1
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 prefix tree? Justify your answer briefly. (e) Consider the optimal prefix tree T 1 built by Huffman’s algorithm, given n characters with frequencies f 1 ≤ f 2 ≤ ··· ≤ f n . A key idea underlying Huffman’s algorithm is that this tree T 1 is related to the optimal prefix tree T 2 for a certain set of n-1 characters. Answer the following briefly. (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