Madivalappagouda Patil Huffman coding Madivalappagouda Patil
Introduction used for compressing the data uses the table of frequencies of occurrence of characters each character is represented by a binary string Two ways Fixed length code Variable length code
Take the characters and their frequencies, and sort this list by increasing frequency All the characters are vertices of the tree Take the first 2 vertices from the list and make them children of a vertex having the sum of their frequencies Insert the new vertex into the sorted list of vertices If there are at least 2 vertices in the list, fallow the above steps. Read the Huffman code from the tree
The (Real) Basic Algorithm An Introduction to Huffman Coding March 21, 2000 The (Real) Basic Algorithm 1. Scan text to be compressed and tally occurrence of all characters. 2.Sort or prioritize characters based on number of occurrences in text. 3.Build Huffman code tree based on prioritized list. 4. Perform a traversal of tree to determine all code words. 5. Scan text again and create new file using the Huffman codes. CS 102 Mike Scott
n=|C| Q=C for i=1 to n-1 Z=new tree node left=(z)=Extract Min(Q) Right=(z)= Extract Min(Q) frequency(z)=frequency(x)+frequency(y) Insert(Q,z) Return Extract Min(Q)
Example
Summary Huffman coding is a technique used to compress files for transmission Uses statistical coding more frequently used symbols have shorter code words Works well for text and fax transmissions An application that uses several data structures CS 102
Thank you