{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

08 - Greedy Algorithms (Solution)

# 08 - Greedy Algorithms (Solution) - The Hong Kong...

This preview shows pages 1–3. Sign up to view the full content.

The Hong Kong University of Science & Technology COMP 271: Design and Analysis of Algorithms Fall 2007 Tutorial 8: Greedy Algorithms Below is the suggest solution to the tutorial questions. Question 1 : A file contains only colons, spaces, newlines, commas, and digits in the following frequency: colon (100), space (605), newline (100), comma (705), 0 (431), 1 (242), 2 (176), 3 (59), 4 (185), 5 (250), 6 (174), 7 (199), 8 (205), 9 (217). Construct the Huffman code. Solution: 3 / 59 colon/ 100 n 1 / 159 newline/ 100 6 / 174 2 / 176 n 2 / 259 n 3 / 350 1 / 242 5 / 250 4 / 185 7 / 199 8 / 205 9 / 217 n 7 / 609 space/ 605 n 6 / 492 0 / 431 n 4 / 384 n 5 / 422 n 10 / 1214 n 9 / 923 n 8 / 806 comma/ 705 n 12 / 2137 n 11 / 1511 n 13 / 3648 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
The Huffman code is: character code colon 000001 space 001 newline 00001 comma 11 0 011 1 0100 2 00011 3 000000 4 1000 5 0101 6 00010 7 1001 8 1010 9 1011 2
Question 2 : Show that none of the following greedy algorithms for the chain matrix multiplication problem work. At each step 1. Compute the cheapest multiplication. 2. Compute the most expensive multiplication. 3. Compute the multiplication between two matricies A i and A i +1 such that the number of columns in A i is minimized.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

08 - Greedy Algorithms (Solution) - The Hong Kong...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online