Chapter 16 Answers


Document last modified: 

Greedy Overview

Question 16.1

Example: Huffman codes for optimal data compression

For example, consider the following sentence:

dead beef cafe deeded dad.  dad faced a faded cab.  dad acceded.  dad be bad.
Frequencies for the 77 characters are:
a b c d e f   .
12 4 5 19 12 4 17 4
Question 16.2 - Which characters should we encode in the fewest bits? The characters occurring most frequently should be encoded with the fewest number of bits.

Constructing a Huffman code

Question 16.3 - In above Figure (b), why are codes for a=0 and f=1100? a is left. f is right, right, left, left.

Question 16.4 Where's the greed? Always extract two lowest frequency values from a character frequency min-heap, place (minimum) remaining at lower (longer code) levels of code tree.