11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 5.8 Exercises 1915.23 Wh<strong>at</strong> are the minimum <strong>and</strong> maximum number of elements in a heap ofheight h?5.24 Where in a max-heap might the smallest element reside?5.25 Show the max-heap th<strong>at</strong> results from running buildHeap on the followingvalues stored in an array:10 5 12 3 2 1 8 7 9 45.26 (a) Show the heap th<strong>at</strong> results from deleting the maximum value from themax-heap of Figure 5.20b.(b) Show the heap th<strong>at</strong> results from deleting the element with value 5 fromthe max-heap of Figure 5.20b.5.27 Revise the heap definition of Figure 5.19 to implement a min-heap. Themember function removemax should be replaced by a new function calledremovemin.5.28 Build the Huffman coding tree <strong>and</strong> determine the codes for the following setof letters <strong>and</strong> weights:Letter A B C D E F G H I J K LFrequency 2 3 5 7 11 13 17 19 23 31 37 41Wh<strong>at</strong> is the expected length in bits of a message containing n characters forthis frequency distribution?5.29 Wh<strong>at</strong> will the Huffman coding tree look like for a set of sixteen characters allwith equal weight? Wh<strong>at</strong> is the average code length for a letter in this case?How does this differ from the smallest possible fixed length code for sixteencharacters?5.30 A set of characters with varying weights is assigned Huffman codes. If oneof the characters is assigned code 001, then,(a) Describe all codes th<strong>at</strong> cannot have been assigned.(b) Describe all codes th<strong>at</strong> must have been assigned.5.31 Assume th<strong>at</strong> a sample alphabet has the following weights:Letter Q Z F M T S O EFrequency 2 3 10 10 10 15 20 30(a) For this alphabet, wh<strong>at</strong> is the worst-case number of bits required by theHuffman code for a string of n letters? Wh<strong>at</strong> string(s) have the worstcaseperformance?(b) For this alphabet, wh<strong>at</strong> is the best-case number of bits required by theHuffman code for a string of n letters? Wh<strong>at</strong> string(s) have the bestcaseperformance?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!