The problem with the coding of the Harman tree and the Harman tree
Today, I saw a question about the coding of the user. Given a string named abcdabaa, I asked the user what the total length of the binary string after the encoding is. The answer is 14.
I don't know much about the Harman tree at all. So after a look-up, I summarized the following knowledge points
Harman tree, Harman
I am not talking about the basic definition of the Harman tree. I have not written many features about this tree. It is a job in our reference books. There are two functions, one is the expression of the child's parent and parent, and the most binary tree is shown. The other is gone. In addition, during my debugging today, I found that there a
Build and codec of The Harman tree, and build codec of The Harman tree
/*
* Implementation process: the user first constructs the User-Defined tree using the HuffmanTree () function, and then * starts from the bottom up (that is, starting from the node where the array serial number is zero) in the main () function) it is determined from the above layer. If it is on the left side of * parent node, it is set
This program is a course assignment for the last semester. At that time, I only had a little C language and data structure foundation for cross-professionals. For this reason, I checked a lot of information and added my own thoughts and analysis. After implementation, I continuously debugged, tested, and improved, it took about one week to complete the process on February 19. Although this is a very small program, it is the first program I completed.
Source code is hosted on GitHub: Click here t
Huffman. h
# Ifndef _ huffman_h_fe
# DEFINE _ huffman_h_fe // The node Structure of the Harman tree
Typedef struct _ huff_node ...{
Float weight; // node weight
Int lchild; // left child of the node
Int rchild; // The right child of the node
Int parent; // The parent node of the node.
} Huff_node, * phuff_node; // the User-Defined tree
Typedef struct _ huff_tree ...{
Int leaf_num; // The number of nodes to be encoded in the middle of the tree.
Int nod
Withidzaki will not be deprecated II (Harman encoding, priority queue), fumanDescription
You are excited to summon an alien creature and think that you can transform into a super person with powerful power to defeat all monsters. However, you are stunned at the face of a tall alien creature, because, do you understand M78 Xingyun? However, don't worry, because the hacker is very witty, he gave a key note: "To be honest, Japanese is a universal languag
DefinitionA type of tree with the shortest length of a weight path, also known as the optimal tree, is a type of tree with the shortest length.
The length of the weighted path of all leaf nodes in the tree. It is usually recorded as WPL = W1 * L1 + W2 * L2 +... + Wn * Ln.
For example:
Nodes ABCDE have the following weights: 1, 2, 4, 5, and 6. For Figure 1, WPL = 4*3 + 2*3 + 1*3 + 5*3 + 6*1 = 42. For Figure 2, WPL = 1*3 + 2*3 + 4*2 + 5*2 + 6*2 = 39. The above nodes can also list other trees and
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1053
Analysis: this topic is a typical problem of the user tree. In a word, the main function of the user tree is to solve the problem of compression encoding, I believe that all students who have studied discrete mathematics should have learned this magical data structure.
(1) create a structure of a node in the Harman tree
TypedefStructHuffman_trie {IntDeep;//DepthIntFreq;//Frequenc
The principle and structure of the Harman tree (reprinted)
This is the process of constructing the Harman tree.
1. Create an initial set
{W1, W2, W3 ,..., wi ,..., wn} is the initial set of n Binary Trees. F = {T1, T2, T3 ,..., ti ,..., tn}, where each binary tree Ti has only one root node with the weight of Wi, and its left and right subtree are empty. (To facilitate Algorithm Implementation on the compute
weight is not unique in the form of the nearest optimal binary tree from the root. The wpl minimum construction of the optimal binary tree Harman algorithm is based on the given n weights w1, w2 ,..., wn: Forest F = {T1, T2 ,.., tn}, where each binary tree Ti has only one root node with the weight of wi, and its left and right subtree are empty. In forest F, select the two trees with the smallest root node weight (when there are more than two trees,
Tags: HTTP Io OS AR for SP Div art code
This is the process of constructing the Harman tree.
1. Create an initial set
{W1, W2, W3 ,..., WI ,..., wn} is the initial set of N Binary Trees. f = {T1, T2, T3 ,..., ti ,..., tn}, where each binary tree TI has only one root node with the weight of Wi, and its left and right subtree are empty. (To facilitate Algorithm Implementation on the computer, it is generally required to sort the weights in ascendi
Data Structure --- implementation of the Harman tree and coding in c language --- c fuman
// Harman tree // Yang Xin # include
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
I think every computer major student is more or less exposed to the old problems in the data structure. Generally, it is to give some characters, and the occurrence frequency of these characters, so that you can design a binary encoding for these characters, requiring the minimum encoding of the characters with the highest frequency. The solution is to construct a user-defined tree (Binary Tree). The basic idea is to pick out two of these characters with the lowest frequency and construct a new
The coding of a user is dependent on the user tree.
The character string to be compressed uses the frequency of occurrence of each word as the basis to construct a user-defined tree. The more frequently the word is, the closer it is to the root node of the tree. Therefore, the shorter the encoding. Therefore, characters with high frequencies use short codes, and those with low frequencies use long codes. You can compress strings based on such a code table.
This program uses C.
Basically, it d
/*
* Implementation process: the user first constructs the User-Defined tree using the huffmantree () function, and then * starts from the bottom up (that is, starting from the node where the array serial number is zero) in the main () function) it is determined from the above layer. If it is on the left side of * parent node, it is set to 0. If it is on the right side, it is set to 1. Finally, the generated encoding is output. * ------------------------------------------------------------------
I recently learned the Harman tree (the optimal binary tree) in the data structure. It means that the given number of leaves has different weights, minimum the weighted paths from the root to the leaves.
I have learned some basic applications, such as data encoding: Assume that 26 letters and 9 numbers appear in a document, only 6-10 characters in a letter have a high probability (the weight is relatively large). How can we minimize the total length
Construction of the javascript Harman tree
Function Node (data) {this. data = data; this. left = null; this. right = null;} Array. prototype. createHufuTree = function () {var nodes = [];/* initialize node */for (var I = 0; I
Construction and coding and decoding of the Harman tree
/*
* Implementation process: the user first constructs the User-Defined tree using the HuffmanTree () function, and then * starts from the bottom up (that is, starting from the node where the array serial number is zero) in the main () function) it is determined from the above layer. If it is on the left side of * parent node, it is set to 0. If it is on the right side, it is set to 1. Finally,
The question is very long and I don't know what's going on, but I understand it very well. It means to give you a string and let you output the digits occupied by common ASCII encoding and huffman encoding respectively, then output the compression ratio;
The first time I wrote the Harman encoding, I wrote it for half a day, and finally wa it several times. The output format of this compression ratio is too painful. He said that I should keep a decimal
This is probably the case when files are compressed (original) using the Harman encoding.
Compression Process: Read files, statistical characters: In my program, the data type is BYTE rather than char, which can compress files other than text files. Then create a user-defined tree. The total number of bytes of the original file that I first saved when saving the compressed file, 4 bytes are used for storage. The reason for this is that after the text
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.