Lect34 Huffman Coding
Lect34 Huffman Coding
• Its value and the previously calculated sum of the tree are used to form the
new node which in turn becomes their parent.
6/29/21 Huffman 2
Algorithm
Introduction
character frequencies
E 10 ① 8 bit Ascii coding –
T 7
Number of bits required (nb)
O 5
A 3 nb= 10x8+7x8+5x8+3x8 = 200bits
6/29/21 Huffman 3
Algorithm
Character frequencies
A 3
O 5
T 7
* 8
E 10
* 15
6/29/21 Huffman 4
Algorithm
Character frequencies code
A 3 110
O 5 111
T 7 10
E 10 0
6/29/21 Huffman 6
Algorithm
A B B C D B C C D A A B B E E E B E A B
Character frequency Code
20 D 2 100
0
1
C 3 101
8 12 E 4 00
0 1 0 1 A 4 01
4 4 5 7 B 7 11
E A 0 1 B
Nb= (2x3 + 3x3 + 4x2 + 4x2 + 7x2)
2 3 = 6+9+8+8+14
D C = 45 bits
Transmitted code –
011111101100111011011000101……………………….
****** No code is prefix of other
6/29/21 Huffman 7
Algorithm
Huffman Algorithm
Assignment 1
Value Frequencies
1 5
2 7
3 10
4 15
5 20
6 45
6/29/21 Huffman 8
Algorithm
Huffman Algorithm
Assignment2
Value C D E K L M U Z
Frequency 32 42 120 7 42 24 37 2
6/29/21 Huffman 9
Algorithm
Huffman Algorithm
• Find code for
• DEED
• MUCK
6/29/21 Huffman 10
Algorithm
Assignments
• Slides at myblog
http://www.ashimlamichhane.com.np/2016/07/tree-slide-for-data-
structure-and-algorithm/
• Assignments at github
https://github.com/ashim888/dataStructureAndAlgorithm/tree/dev/As
signments/assignment_7
6/29/21 Huffman 11
Algorithm
Reference
• https://www.siggraph.org/education/materials/HyperGraph/video/mp
eg/mpegfaq/huffman_tutorial.html
• https://en.wikipedia.org/wiki/Binary_search_tree
• https://www.cs.swarthmore.edu/~newhall/unixhelp/Java_bst.pdf
• https://www.cs.usfca.edu/~galles/visualization/BST.html
• https://www.cs.rochester.edu/~gildea/csc282/slides/C12-bst.pdf
• http://www.tutorialspoint.com/data_structures_algorithms/tree_data
_structure.htm
6/29/21 Huffman 12
Algorithm
Doubts???
6/29/21 Huffman 13
Algorithm