QB4 - Greedy &amp; NPC

QB4 - Greedy &amp;amp; NPC - COMP 271 Design and Analysis...

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COMP 271 Design and Analysis of Algorithms 2004 Fall Semester Question Bank 4 Solving these questions will give you good practice for the final exam. Some of these questions (or similar ones) will definitely appear on your exam! Note that you do not have to submit answers to these questions for grading. Your TAs will discuss answers to selected questions in the tutorials. 1 Greedy Algorithms 1. Recall that in the Huffman coding problem, we are given a set of n characters along with their frequencies. We are required to represent each character by a unique codeword using 0’s and 1’s, such that no codeword is a prefix of another. The goal is to find such codewords that achieve maximum compression. (a) Construct the optimal code for the four characters a, b, c, d with frequencies 14, 3, 6, 10, respectively. Assuming the heap implementation of Huffman’s algorithm, show what items are deleted from the heap and inserted into the heap at each step. (b) How many bits are needed to encode a string containing 14 a’s, 3 b’s, 6 c’s and 10 d’s using the optimal code found in part (a)? And how may bits wouldand 10 d’s using the optimal code found in part (a)?...
View Full Document

This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.

Page1 / 3

QB4 - Greedy &amp;amp; NPC - COMP 271 Design and Analysis...

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

View Full Document
Ask a homework question - tutors are online