ta10_sol - COMP 271H Design and Analysis of Algorithms 2006...

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

View Full Document Right Arrow Icon
COMP 271H Design and Analysis of Algorithms 2006 Fall Semester Tutorial 10 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. Character a b c d Frequency 14 3 6 10 Huffman’s tree: In heap order: a b c d n 1 n 2 n 3 Out heap order: b c n 1 d n 2 a n 3 Character Bits a 1 b 000 c 001 d 01 (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 would be needed if we used 2 bits for each character? Which code is better?
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern