Haffman Coding

See the ariticle on my own blog https://dyingdown.github.io/2019/10/20/Haffman-Code/.

Assume that we have a bunch of points, each point has a number means the occurrence times of the point.

Haffman Coding

If we want to label these points with a unique code for each, what do we do?

Well, there are many ways, but I’m just going to show the Haffman coding method.

What is Haffman Coding

In computer science and information theory, a Huffman code is a particular type of optimal prefix code that is commonly used for lossless data compression. The process of finding or using such a code proceeds by means of Huffman coding, an algorithm developed by David A. Huffman while he was a Sc.D. student at MIT, and published in the 1952 paper “A Method for the Construction of Minimum-Redundancy Codes”.[1] ——From Wikipedia

Illustration

  1. First we pick up two smallest points and make it one point.

    Haffman Coding

  2. Do the same as 1

    Haffman Coding

  3. Same to 1

Haffman Coding

  1. Same to 1

Haffman Coding

  1. Same to 1

    Haffman Coding

  2. Same to 1

    Haffman Coding

  3. Finally we start label the nodes. From the root to the bottom, the code add one digit when the layer is also one deeper. The left is 0 and right is 1.

    Haffman Coding

  4. So we got the haffman code of all the nodes.

    Haffman Coding Haffman Coding Haffman Coding Haffman Coding Haffman Coding Haffman Coding Haffman Coding
    100 101010 11 10100 1011 101011 0