Information Theory: Step 3 Huffman Algorithm
Updated: May 6, 2019
Prefix codes (sometimes called "prefix-free codes“) is a type of code system (typically a variable-length code) distinguished by its possession of the "prefix property", which requires that there is no codeword in the system that is a prefix (initial segment) of any other code word in the system.
A prefix code is a uniquely decodable code: a receiver can identify each word without requiring a special marker between words.
Examples of prefix codes:
Country calling codes
In this article we are going to implement our simple version of Huffman Encoding.
In 1951, David A. Huffman and his MIT Information Theory classmates were given the choice of a term paper or a final exam. The professor, Robert M. Fano, assigned a term paper on the problem of finding the most efficient binary code. Huffman, unable to prove any codes were the most efficient, was about to give up and start studying for the final when he hit upon the idea of using a frequency-sorted binary tree and quickly proved this method the most efficient.
In doing so, the student outdid his professor, who had worked with Information Theory inventor Claude Shannon to develop a similar code.
A Huffman code is an optimal code found using the algorithm developed by David A. Huffman while he was a Ph.D. student at MIT, and published in the 1952 paper "A Method for the Construction of Minimum-Redundancy Codes".
Huffman code is one of the optimal codes using for lossless data compression.
The algorithm's output can be viewed as a variable-length code table for encoding a source symbol (such as a character in a file).
Huffman's algorithm derives this table based on the estimated probability or frequency of occurrence (weight) for each possible value of the source symbol.
As in other entropy encoding methods, more common symbols are generally represented using fewer bits than less common symbols.
Characters (or any message to be encoded) of the original alphabet are setted in descending order of probability.
Sum the two minimum probabilities.
Characters of the original alphabet are setted again in descending order of new probabilities.
Repeat the step 2 again and again until there is only 1 symbol with probability = 1.
Construct a binary tree
And our implementation of this algorithm:
And on git hub
Arndt C. Information Measures: Information and its Description in Science and Engineering.
Thomas Cover. Elements Of Information Theory.