The concept Huffman trees and Huffman coding

A. Huffman

  1. Given n weights as a leaf node n, a binary tree configuration, if the weighted path length of the tree reaches a minimum, such a binary tree is called optimal binary tree, also known as Huffman tree (Huffman Tree) . Huffman tree is the shortest path length weighted tree, the larger the weight from the root node closer.
  2. Ado, directly on the map:

    obtaining weighted path length three binary tree WPL, WPL wherein (C) the shortest, c is the Huffman tree.
  3. So how to construct a Huffman tree? Huffman given Huffman algorithm :
    ① set F n weight values according to a predetermined configuration as the n binary trees, where each of them is only a binary Ti wi is the weighted root node, the left and right child. trees are empty.
    ②. Select two minimum weight tree root node configured as the left and right subtrees of a new binary tree in F, and set the new binary tree root weight is about right subtree of the root node and value.
    ③. Delete these two left and right subtrees in F, and the newly acquired F is added in a binary tree.
    ④. Repeat steps ② and ③ until Step F with only up a tree, the tree is the Huffman tree.
    The process corresponding to the FIG:
    /

Applied Second Huffman tree - Huffman coding

  1. The main means of remote communication is quick telegram, in the process of transmission, the need to transfer the text string into binary characters, for example "ABACCD A", which only four characters, which are encoded as 00 if , and 11., the above message will be converted to "00010010101100", length 14, when receiving the other, according to a two decoded.
  2. We hope that when the total length of the transmission message as short as possible, if each character design of unequal length coding, such as 0,00,1,01, the above message will be converted to "000 011 010", the total length of nine, its shortened length, but when there will be a variety of coding translation. We therefore to design different length encoding, it must be either a character encoding is not a prefix of another character encoding, this encoding is called a prefix code.
  3. We can use a binary tree design binary prefix code, set 4 is the leaf nodes A, B, C, D four characters, and the left branch represents conventions character 0, character 1 denotes the right branch, the binary tree as shown below:
    /
  4. Thus obtained will be encoded as a prefix code, but how to make the total length of the shortest message? This problem has transitioned to solve the problem of the Huffman tree, and the number of messages we will see in the characters that appear to the right value, according to Huffman algorithm to construct out of the Huffman tree, the right path with the shortest length WPL, That is the total length of the shortest message.
  5. Thus, the design of the message total length of the shortest binary prefix code is the character appearing at a frequency of n as the weight, design a problem Huffman tree, thereby obtaining a binary prefix code will be called Huffman coding.
  6. Huffman understood from the characteristics, there is no degree of Huffman tree node 1 (also known as such a strict tree or regular binary tree), with n is a leaf node of the Huffman tree Total 2n-1 nodes.
    Since: ∵N = N0 + N1 + N2;
       ∴N = N0 + N2;
       and ∵n0 = n2 + 1 (an important characteristic of the binary tree);
       ∴N-= 2N. 1;
Published 77 original articles · won praise 19 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_42932834/article/details/94402791