Professional Documents
Culture Documents
Problem Set 9: F (I) C (I) L (I)
Problem Set 9: F (I) C (I) L (I)
Problem Set 9
Use the CS170 drop box in 283 Soda, or hand the solution to Jack Barr, in the CS main
office, 3rd floor of Soda.
Write your name, your student ID number and your section number on your
solution. Write legibly. The description of your proofs and algorithms should be as clear
as possible (which does not mean long – in fact, typically, good clear explanations are also
short.)
Problem 1. We have an alphabet {a, b, c} and frequencies f (a), f (b), f (c). We apply
Huffman’s algorithm, and we get a code for the three alphabet symbols. In each of the
following cases, give an example of possible values for the frequencies that would yield the
specified code, or explain why the specified code is an impossible output for Huffman’s
algorithm (regardless of the value of the frequencies).
Problem 2. The basic intuition behind Huffman’s algorithm (that frequent blocks should
have short encodings and infrequent blocks should have long encodings) is at work in En-
glish, where typical words like I, you, is, and, to, from, and so on are short, and rarely
used words like velociraptor are longer.
However, words like fire!, help!, run! are short not because they are frequent but,
perhaps, because time is precious in situations where these words are used.
To make things theoretical, suppose we have a file composed of “words” numbered 1, . . . , m,
occurring with frequencies f (1), . . . , f (m), and suppose that for each word i, the cost per
bit of encoding of the word is c(i), so that if we find a prefix code where word i has encoding
P
length l(i), the total cost of our encoding will be i f (i) · c(i) · l(i).
Show how to modify Huffman’s algorithm in order to compute the prefix code of minimum
total cost.
Handout PS9: Problem Set 9 2
Problem 3. Give an example of a linear program in two variables whose feasible region
is infinite, but such that there is an optimum solution of bounded cost.
maximize x1 − x2
subject to
x1 + x2 ≤ 2
−2x1 − 2x2 ≤ −10
x 1 , x2 ≥ 0
maximize x1 − x2
subject to
x1 − 2x2 ≤ 2
2x1 − 3x2 ≤ 5
x 1 , x2 ≥ 0