Huffman tree (Homan tree, and optimal binary tree)

Source: Internet
Author: User

Huffman tree (Homan tree, and optimal binary tree)

Huffman tree (Homan tree, and optimal binary tree)

Flyfish 2015-8-1

The Huffman tree has different translations, so there are other names:
Define reference from Yan Weimin Data Structure
Path
The branches from one node in the tree to another constitute the path between two nodes.

Path Length
The number of branches on the path is called the path length.

Tree path length
The tree path length is the sum of the path lengths from the root node to each node.

Length of the weighted path of a node
The length of the weighted path of a node is the product of the path length from the node to the root node and the permission on the node.

Length of the tree's weighted path
The length of a tree's weighted path is the sum of the length of the weighted path of all leaf nodes in the tree. It is generally recorded as WPL.

Huffman tree
Assume there are n weights { W1, w2 ,... Wn }, Construct a binary tree with n leaf nodes, with each leaf node having the right Wi The binary tree with the minimum length of WPL is called the Huffman tree.

Assume that there is a character string, and each character appears as follows:
A: 5
B: 15
C: 40
D: 30
E: 10
Sort characters in ascending order to form an ordered sequence.

Bottom-up creation process
Step 1

Step 2

Step 3

Step 4

Constructed <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxzdHJvbmc + uMXE7rK5s + Q8L3N0cm9uZz48L3A + DQo8cD48aW1nIGFsdD0 = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/150803/04203L0Q-5.png" title = "/>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.