02-greedy

02-greedy

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: tters Character Frequency a e 15 i 12 s 3 t 4 (space) 13 (newline) 1 Total 68 10 58 Compression step 1 (b) Build a min-heap Character Sorted by frequency Frequency a e 69 10: i (space) 13: sp 13 1 Total 12: i 4 (newline) 15: e 3 t 3: s 12 s 4: t 15 i 1: nl 10 58 Compression step 2 Build the tree Start with a “forest” of trees: Repeat Take the two trees that have the lowest frequency The next two removals from the heap Make them children of a new node Keep track of the total frequency of that node 70 And stick that tree back into the heap 71 72 The final Huffman coding tree Character Code a 001 e 01 i 10 s 00000 t 0001 (space) (newline) 73 11 00001 Resulting encoding table Character Code Frequency Total bits a 001 10 30 e 01 15 30 i 10 12 24 s 00000 3 15 t 0001 4 16 11 13 26 00001 1 5 58 146 (space) (newline) Total Total encoding is 146 bits 74 Is Huffman encoding optimal? First define what optimal means: The Huffman code for a given alphabet achieves the minimum average number of bits per letter of any prefix code To prove this, we must first two things: Optimal sub-structure Greedy choice property We’ll show the second one first 75 Step 1 • Lemma 16.2: Let C be an alphabet in which each character c C has frequency c.freq. Let x and y be two characters in C having the lowest frequencies. Then there exists an optimal prefix code for C in which the codewords for x and y have the same len...
View Full Document

This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.

Ask a homework question - tutors are online