Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

University of California — Berkeley Handout PS9

CS170: Efficient Algorithms and Intractable Problems November 1, 2001


Professor Luca Trevisan

Problem Set 9

This problem set is due on Monday, November 12, before 4:00pm.

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).

(a) the code is {0, 10, 11}


(b) the code is {0, 1, 00}
(c) the code is {10, 01, 00}

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.

Problem 4. [CLRS 29.1-6]


Show that the following linear program is infeasible

maximize x1 − x2
subject to
x1 + x2 ≤ 2
−2x1 − 2x2 ≤ −10
x 1 , x2 ≥ 0

Problem 5. [CLRS 29.1-7]


Show that the following linear program is unbounded

maximize x1 − x2
subject to
x1 − 2x2 ≤ 2
2x1 − 3x2 ≤ 5
x 1 , x2 ≥ 0

You might also like