Download presentation
Presentation is loading. Please wait.
Published byFelicia McDonald Modified over 9 years ago
1
Algorithm Design & Analysis – CS632 Group Project Group Members Bijay Nepal James Hansen-Quartey Winter 2002@UNH
2
INTRODUCTION A Data compression technique Developed by David Huffman, former professor of MIT, in 1952 A statistical method of compression Analyses the input before compression
3
Types of Huffman Algorithm Static Huffman Adaptive Huffman: dynamically changes the code words according to probabilities of the symbols. Extended Huffman: can encode groups of symbols rather than single symbols.
4
Encoding Steps in Huffman encoding Compute the frequency of each characters or symbols Sort them according to the frequency Build the Huffman tree Build the Huffman tree Transverse tree from root to leaf & assign 0 for left node path and 1 for right node path. This gives the code word.
5
Building Huffman Tree 20100503043 7 27 57 abtksSP
6
Building Huffman Tree 10050203043 7 27 57 107
7
Building Huffman Tree 100 50203043 7 27 57 107 207 0 1 1 0 0 0 0 1 1 1 tSPsabk
8
Building Huffman Tree 10050203043 7 27 57 107 207 0 1 1 0 0 0 0 1 1 1 tSPsabk 0 10 11000 11001 1101 111 SP t b a s k Code word
9
Characteristics of Huffman codes No code for a character is the prefix of the code for any other character Huffman coding results in shorter average length of compressed (encoded) message Most frequent characters are assigned to short code words. Characters or symbols are always stored in leaves of Huffman tree. Huffman coding works better when large variation in frequency of letters
10
Decoding Read frequency from frequency table Read encoded characters or symbols. Build the tree and transverse according to the binary codeword. Leaf value is the decoded symbol.
11
Algorithm for building tree C Set of n characters and each character is defined with frequency f[c] Q A priority queue Q, keyed on f Huffman ( C ) Q C For I 1 to n – 1 Do Z ALLCATE-NODE() X LEFT[Z] EXTRACT_MIN(Q) Y RIGHT[Z] EXTRACT_MIN(Q) f[Z] f[X]+f[Y] INSERT(Q, Z) RETURN EXTRACT_MIN ( Q )
12
Time-complexity analysis Q is implemented as heap. Therefore, for a set C of n characters, this can be done in O(n) time. ‘for’ loop in the algorithm is executed exactly n-1 times and each heap operation requires O(log n) time. Therefore, total running time is O(n log n)
13
Implementation Issues Data structures Data structures Sorting Building tree Encoding Decoding
14
Drawbacks This compression algorithm is mainly efficient in compressing text or program files. Static Huffman is not suitable for image compression. For small file, overhead is significant and hence less compression ratio. Not suitable for live data compression as prior data analysis is not available. Scans input data twice.
15
Application Huffman compression is used in programs like pkZIP, gz, zoo and arj. It is also used within JPEG and MPEG compression.
16
Thank You.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.