Huffman Trees in Data Structure


Definition

Huffman coding provides codes to characters such that the length of the code depends on the relative frequency or weight of the corresponding character. Huffman codes are of variable-length, and without any prefix (that means no code is a prefix of any other). Any prefix-free binary code can be displayed or visualized as a binary tree with the encoded characters stored at the leaves.

Huffman tree or Huffman coding tree defines as a full binary tree in which each leaf of the tree corresponds to a letter in the given alphabet.

The Huffman tree is treated as the binary tree associated with minimum external path weight that means, the one associated with the minimum sum of weighted path lengths for the given set of leaves. So the goal is to construct a tree with the minimum external path weight.

An example is given below-

Letter frequency table

Letterzkmcudle
Frequency272432374242120

Huffman code

LetterFreqCodeBits
e12001
d421013
l421103
u371003
c3211104
m24111115
k71111016
z21111006

The Huffman tree (for the above example) is given below -

Updated on: 16-Jan-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements