Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment 6: Huffman Code Generation

Similar presentations


Presentation on theme: "Assignment 6: Huffman Code Generation"— Presentation transcript:

1 Assignment 6: Huffman Code Generation
Andy Wang Data Structures, Algorithms, and Generic Programming

2 Huffman Code Commonly used in compression schemes Idea:
Use variable-length code words Length of the word inversely proportional to the frequency of its occurrences

3 ASCII Encoding TALLAHASSEE ASCII values A 0100 0001 E 0100 0101

4 ASCII Encoding TALLAHASSEE
8*11 = 88 bits

5 Huffman Encoding TALLAHASSEE A 10 E 00 H 010 L 110 S 111 T 011

6 Huffman Encoding TALLAHASSEE 011 10 110 110 10 010 10 111 111 00 00
28 bits

7 Assignment 6 Generate Huffman Code Frequency analysis
Constructing the code tree Printing out the code table

8 Frequency Analysis TALLAHASSEE A 3 E 2 H 1 L 2 S 2 T 1

9 Constructing the Code Tree
Create tree nodes E:2 A:3 H:1 L:2 T:1 S:2

10 Constructing the Code Tree
Build a modified heap H:1 L:2 T:1 A:3 E:2 S:2

11 Constructing the Code Tree
Find two nodes with the smallest counter values T:1 L:2 S:2 A:3 E:2 H:1

12 Constructing the Code Tree
Find two nodes with the smallest counter values E:2 L:2 S:2 A:3 H:1 T:1

13 Constructing the Code Tree
Create a parent node E:2 L:2 S:2 A:3 H:1 T:1 :2

14 Constructing the Code Tree
Insert the parent node back to the heap E:2 L:2 S:2 H:1 T:1 :2 A:3

15 Constructing the Code Tree
Find two nodes with the smallest counter values H:1 T:1 :2 L:2 S:2 A:3 E:2

16 Constructing the Code Tree
Find two nodes with the smallest counter values L:2 A:3 S:2 E:2 H:1 T:1 :2

17 Constructing the Code Tree
Create a parent node L:2 A:3 S:2 E:2 H:1 T:1 :2 :4

18 Constructing the Code Tree
Insert the parent node back to the heap L:2 A:3 E:2 H:1 T:1 :2 :4 S:2

19 Constructing the Code Tree
Find two nodes with the smallest counter values S:2 E:2 H:1 T:1 :2 :4 A:3 L:2

20 Constructing the Code Tree
Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2

21 Constructing the Code Tree
Create a parent node A:3 :4 E:2 :2 :4 H:1 T:1 L:2 S:2

22 Constructing the Code Tree
Insert the parent node back to the heap L:2 S:2 :4 A:3 :4 E:2 :2 H:1 T:1

23 Constructing the Code Tree
Find two nodes with the smallest counter values L:2 S:2 :4 :4 A:3 E:2 :2 H:1 T:1

24 Constructing the Code Tree
Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2 :4

25 Constructing the Code Tree
Create a parent node :7 :4 A:3 L:2 S:2 :4 E:2 :2 H:1 T:1

26 Constructing the Code Tree
Insert the parent node back to the heap A:3 L:2 S:2 :4 :7 E:2 H:1 T:1 :2 :4

27 Constructing the Code Tree
Find two nodes with the smallest counter values E:2 H:1 T:1 :2 :4 A:3 L:2 S:2 :4 :7

28 Constructing the Code Tree
Find two nodes with the smallest counter values :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

29 Constructing the Code Tree
Create a parent node :11 :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

30 Constructing the Code Tree
Insert the parent node back to the heap :11 :4 A:3 L:2 S:2 :4 :7 E:2 :2 H:1 T:1

31 Code Assignment :11 1 :4 A:3 L:2 S:2 :4 :7 1 1 E:2 :2 00 1 10 1 H:1
:4 A:3 L:2 S:2 :4 :7 1 1 E:2 :2 00 1 10 1 H:1 T:1 010 011 110 111

32 Properties of Huffman Code
Higher the frequency, shorter the code The code for one character is not the prefix for another code 00 is not a prefix for 010 00 is a prefix for 001


Download ppt "Assignment 6: Huffman Code Generation"

Similar presentations


Ads by Google