Chapter 16 Answers

powered by FreeFind

Modified: 

Greedy Overview

Question

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 - 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: In above Figure (b), why are codes for a=0 and f=1100? a is left. f is right, right, left, left.

Question: 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.