ORIGIN

Haffman Coding

Data Structure 1 mins203 words

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

img

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.

    img
  2. Do the same as 1

    img
  3. Same to 1

img
  1. Same to 1
img
  1. Same to 1

    img
  2. Same to 1

    img
  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.

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

    img

TOP
COMMENT
  • ABOUT
  • |
o_oyao
  The Jigsaw puzzle is incomplete with even one missing piece. And I want to be the last piece to make the puzzle complete.
Like my post?
Default QR Code
made with ❤️ by o_oyao
©o_oyao 2019-2024

|