Now that the Hoffman tree has been constructed, how can it get the code for each leaf?

Updated on home 2024-05-07
7 answers
  1. Anonymous users2024-02-09

    You can make the left subtree 0 and the right subtree 1, so that you get a string from the root to the leaf that looks like a 011101, which is the leaf code.

  2. Anonymous users2024-02-08

    First make up the Huffman tree, the Huffman tree construction rules:

    Assuming n weights, the constructed Huffman tree has n leaf nodes. The n weights are set to w1, w2, 、..., wn, then the construction rules of the Huffman tree are:

    1) 、... W1 and W2, wn is seen as a forest with n trees (each tree has only one node);

    2) The tree with the smallest weights of two root nodes was selected and merged in the forest as the left and right subtrees of a new tree, and the root node weights of the new tree were the sum of the weights of the root nodes of the left and right subtrees;

    3) remove the two selected trees from the forest and add new trees to the forest;

    4) Repeat steps (2) and (3) until there is only one tree left in the forest.

    After the construction is completed, starting from this root node, the default left subtree is 0 and the right subtree is 1, until the leaf node is reached, and the encoding of the leaf node is the required encoding.

    For example, the weights of the characters a, b, c, d, e, f, are 8, 12, 5, 20, 4, 11

    The Huffman tree is:

    f(11) b(12) 17 d(20)

    a(8) 9

    e(4) c(5)

    The encoding is A:100, B:01, C:1011, D: 11, E:1010 ,F:00

  3. Anonymous users2024-02-07

    The specific method of Heuffman encoding is to queue according to the probability of occurrence, add the two lowest probabilities to re-queue as the new probability and the remaining probability, and then add the two smallest probabilities, and then re-queue until it finally becomes 1. Each time the addition of "0" and "1" is assigned to the two probabilities of addition, the reading starts from the symbol to the last "1", and the "0" and "1" encountered on the route are arranged in the order of the lowest to the highest position, which is the Hefmann code of the symbol.

    For example, A7 is from left to right, from you to U, and its code word is 1000;

    A6 arranges the "0" and "1" encountered according to the route in order from the lowest digit to the highest digit, and its code word is 1001....

    The average bit rate obtained by Herfman encoding is: the probability of occurrence of code size call.

    The example above is: bit

    The source entropy of this example can be calculated, and the two are already very close.

    The compression ratio of Huffman encoding is calculated based on the average code length, and the compression ratio is relatively low. For example, the average length of the isometric DAO code encoded with a three-digit two-roll progression is 3, while the average code length based on the Huffman tree code is:

    Its average code length is 87% of the same length code, so the average compression rate is 13%.

  4. Anonymous users2024-02-06

    Summary. The Huffman tree can be drawn by first ordering the weights from small to large, then linking the first two weights as nodes from left to right, using the sum of the two weights as the parent node, and then inserting the parent node into the existing sequence of weights (still in order from small to large after insertion) until the weights in the sequence are used up.

    Thought right to plant the leaf nodes of the Huffman tree how to draw.

    and find the weighted path length of the binary tree.

    WPL Huffman tree can first arrange the weights from small to large, then link the first two weights as nodes from left to right, then use the sum of the two weights as the parent node, and then insert the parent node into the existing weight sequence (after insertion, it is still in order from small to large), until the weights in the sequence are used up.

    WPL can be obtained by adding the nodes of the Huffman tree except the root node.

    Can you draw a diagram?

    Is that so? For example, the two numbers are written out as nodes, and the sum you want to add is used as the parent node and inserted into the ordered weight sequence, and the two numbers on the far left of the sequence are written out as coarse and pure nodes to add, and the above steps are repeated.

    I'm a novice, just learned.

    You are wrong about this, first of all, although there is 13 in the original sequence you gave, the 13 generated when you create the tree should also be put into the sequence, and secondly, for example, the third number 11 and, it is smaller than the parent node we just waited for, so it is written on the left side of the parent node 13. But when the next number in our sequence is larger than the parent node of the tree I told them to construct, we need to write this number to the right of the parent node.

    Sorry I forgot to tell you, every time you construct you have to pick the two nodes with the lowest weight to start building the Huffman tree, and follow the small one on the left and the big one on the right.

  5. Anonymous users2024-02-05

    First make up the Huffman tree, the Huffman tree construction rules:

    Assuming that there are n weights, then the Huffman tree constructed by Shen Shengsheng has n leaf nodes. The n weights are set to w1, w2, 、..., wn, then the construction rules of the Huffman tree are:

    1) 、... W1 and W2, wn is seen as a forest with n trees (each tree has only one node);

    2) The tree with the smallest weights of two root nodes was selected and merged in the forest as the left and right subtrees of a new tree, and the root node weights of the new tree were the sum of the weights of the root nodes of the left and right subtrees;

    3) remove the two selected trees from the forest and add new trees to the forest;

    4) Repeat steps (2) and (3) until there is only one tree left in the forest.

    After the construction is completed, starting from this root node, the default left subtree is 0, and the width of the right subtree is 1, until the leaf node, the encoding of the leaf node is the required encoding.

    Example. The weight of the character a, b, c, d, e f, is 8, 12, 5, 20, 4, 11

    The Huffman tree is:

    f(11) b(12) 17 d(20)

    a(8) 9

    e(4) c(5)

    The encoding is A:100, B:01, C:1011, D: 11, E:1010 ,F:00

  6. Anonymous users2024-02-04

    The total length of the code is calculated separately for each case. Let's start with the total length of the Hoffman code. Draw its coding tree according to the frequency, and then calculate the weighted sum of the coding length according to the occurrence frequency of each node as 90.

    Then calculate the total length of the encoding in the uncompressed state, because there are 5 colors, the encoding length of each color in the isometric encoding is 3 binary bits, and the total length is 120. The specific calculation method and process are shown in the figure.

  7. Anonymous users2024-02-03

    Yes, oh, I just took a look, and I helped you find this resource, you can click on my profile to see it...

Related questions
5 answers2024-05-07

Suddenly, like a night of spring breeze, thousands of trees and pear blossoms bloom. >>>More

13 answers2024-05-07

The tree has a long flowering time, and the ripe fruit can give off a fragrance, and it also has medicinal value.

8 answers2024-05-07

The roots of the yellow horn tree can be soaked in wine with chicken blood vine to cure rheumatism.

9 answers2024-05-07

Saponaria tree, official name: honey locust, isLegumes >>>More

8 answers2024-05-07

First, the plant type is different.

The palm tree is a tall tree, belonging to the mountain palm family, palm trees, the height is very high, about 3-10 meters, can be higher, the trunk is cylindrical, about 10-15 cm DBH. >>>More