Data Structures and Agorithm: DS 16 Huffman Coding.pptx
RashidFaridChishti
8 views
15 slides
May 18, 2024
Slide 1 of 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
About This Presentation
Data Structures and Agorithm: DS 16 Huffman Coding.pptx
Size: 108.99 KB
Language: en
Added: May 18, 2024
Slides: 15 pages
Slide Content
Data Structures Lecture No. 16 Huffman’s Algorithm Engr . Rashid Farid Chishti http://youtube.com/rfchishti http://sites.google.com/site/chishti International Islamic University H-10, Islamabad, Pakistan Video Lecture
Huffman code is method for the compression for standard text documents. It makes use of a binary tree to develop codes of varying lengths for the letters used in the original message. Huffman code is also part of the JPEG image compression scheme. The algorithm was introduced by David Huffman in 1952 as part of a course assignment at MIT . It’s a variable-length code because each character may be encoded with different numbers of bits It’s a statistical coding scheme Normally Characters don’t occur with the same frequency It’s a lossless data compression algorithm. Huffman Code
Scan text and count the occurrences of all characters S ort characters based on the number of occurrences in text Make each character a leaf node , with its frequency as its weight Pair the two least frequently occurring characters Create a subtree from the pair and the weight is sum of the two Repeat until all subtrees have been paired into a single tree Encode each character as the path from the root, with a left represented as 0, and a right as 1 Algorithm
Example Characters Frequency A 10 E 15 I 12 S 3 T 4 SP 13 X 1 Characters Frequency E 15 SP 13 I 12 A 10 T 4 S 3 X 1 Sort Minimum Priority Queue X, 1 S, 3 E,15 SP,13 I,12 A,10 T, 4 p ush() pop() top() removes an element with min priority gets an element with min priority
root SP,13 I,12 $, 8 T , 4 $,25 $,18 E,15 $,33 $,58 1 1 1 1 A,10 1 S,3 1 X, 1 $, 4 Characters Codes I 00 SP 01 E 10 A 111 T 1100 S 11011 X 11010 Char. Freq. A 10 E 15 I 12 S 3 T 4 SP 13 X 1