12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

202 Chap. 5 Binary Trees5.29 What will the Huffman coding tree look like for a set of sixteen characters allwith equal weight? What 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 that cannot have been assigned.(b) Describe all codes that must have been assigned.5.31 Assume that 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, what is the worst-case number of bits required by theHuffman code for a string of n letters? What string(s) have the worstcaseperformance?(b) For this alphabet, what is the best-case number of bits required by theHuffman code for a string of n letters? What string(s) have the bestcaseperformance?(c) What is the average number of bits required by a character using theHuffman code for this alphabet?5.32 You must keep track of some data. Your options are:(1) A linked-list maintained in sorted order.(2) A linked-list of unsorted records.(3) A binary search tree.(4) An array-based list maintained in sorted order.(5) An array-based list of unsorted records.For each of the following scenarios, which of these choices would be best?Explain your answer.(a) The records are guaranteed <strong>to</strong> arrive already sorted from lowest <strong>to</strong> highest(i.e., whenever a record is inserted, its key value will always begreater than that of the last record inserted). A <strong>to</strong>tal of 1000 inserts willbe interspersed with 1000 searches.(b) The records arrive with values having a uniform r<strong>and</strong>om distribution(so the BST is likely <strong>to</strong> be well balanced). 1,000,000 insertions areperformed, followed by 10 searches.(c) The records arrive with values having a uniform r<strong>and</strong>om distribution (sothe BST is likely <strong>to</strong> be well balanced). 1000 insertions are interspersedwith 1000 searches.

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

Saved successfully!

Ooh no, something went wrong!