9-Path Length and Huffman Codes - Path Length and Huffman...

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

Path Length and Huffman Codes The path length of a binary tree t with nonnegative weights attached to its nodes is W(t) = ∑ w(i) d(i) where node i has weight w(i) and is at depth d(i) in t. All nodes i in t Example: t: 2 / \ 1 0 / \ \ 2 3 5 W(t) = 2x1 + 1x2 + 0x2 + 2x3 + 3x3 + 5x3 = 34 Three ways to compute the path length: 1. Directly from the definition as above. 2. Assign a value to each node equal to the sum of the weights in its subtree and then add up the values 13 / \ 6 5 13 + 6 + 5 + 2 + 3 + 5 = 34 / \ \ 2 3 5 3. Let SW be the sum of all the weights. Then W(t) = Sw + W(tL) + W(tR) = 13 + 11 + 10 = 34 Huffman Codes: Given messages with frequencies or weights w 1 , w 2 , . . . w n find a set of codewords for the messages, each composed of 0’s and 1’a, so the average number of 0’s and 1’s is minimized. That is, the n ∑ w i l(i) is minimized. i=1 where l(i) is the length of codeword i. Also - useful for compression. Discuss example to show the problem and then relate to binary trees. Show connection between the above minimization and minimizing path length. Show that optimal tree must be full. Discuss algorithm involving a search of all trees and then Huffman’s
Image of page 1

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

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '16
  • James Korsh
  • Graph Theory, Tn, Binary heap, path length

{[ 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