Huffman coding is applied to the encoding of data files and image compression. Its compression rate is usually between 20%~90%, in the case of long-distance communication, it is often necessary to convert the text to be transferred into a string consisting of binary characters, and the total length of the message to be transmitted as short as possible. It is obvious that the total length of the message to b
data structure exercises--huffman Coding
time limit (normal/java): 1000ms/10000ms Run memory limit: 65536KByte
Description
Previously, when there was no phone, the main means of fast long-distance communication was the Telegraph, which converted the text needed to be transferred into a string of binary characters. For example, suppose that the message to be t
Java applet's Huffman tree and file compression and decompression (i) Huffman Tree Construction Chapter
Before we get to know Huffman tree, let's look at the relevant knowledge of the tree first.
I. Knowledge of tree in data structureThe data structure is the way that the computer stores and organizes it. Data stru
Huffman codeHuffman coding is simple, but it is a very important coding method, it solves a very important problem of data storage: Compression! Its coding is optimal, lossless, especially in the image used very much. Here's how it works.Encoding methodHuffman coding is base
SOURCE Coding algorithm
Fenaux Encoding Fano Coding
Huffman Code Huffman Coding
Fenaux Encoding Step
The source symbols are arranged from large to small according to their probability size;
Divide this set of source symbols into probabilities and as close a
bottom-up process):Eventually we'll get a binary tree like this:At this point, we put the left branch of the tree encoded as 0, the right branch code of 1, so that we can traverse the tree to get the character encoding, such as: ' B ' encoding is XX, ' P ' encoding is 101, ' R ' encoding is 1000. we can see that the more the frequency will be in the upper layer, the shorter the coding, the less the frequency of the lower, the more the code is longer
character case while (que.size ()!=) {a =que.top (); Que.pop (); B=que.top (); Que.pop (); Ans+=a +b; Que.push (a +b); } while (!que. Empty () que.pop (); } The process in the while is exactly as follows, the steps mentioned above toIf you add input AAAABBBCCD, you will get such a tree according to the above stepsThis is coded out toa:0 1bitB:10 2bitc:110 3bitd:111 3bitSo the number of digits in the encoding is the number of occurrences x encoded bit1x4+2x3+3
A Huffman tree is generated based on the number of characters in a string as the weight of the character.Then according to the generated Huffman code, the arbitrary string Implementation code, the arbitrary binary string implementation decoding.Program Run Result:1. Program Main interface:2. Create Huffman tree and encodings based on the string:3. The resulting e
Introduced
This article describes the simplest and fastest Huffman coding that can be found on the Internet. This method does not use any extended dynamic libraries, such as STL or component. Use simple C functions, such as: Memset,memmove,qsort,malloc,realloc and memcpy.
As a result, everyone will find it easy to understand or even modify the code.
Background
Huf
,decode by bit, for example, if we have such a bitset "1011110111″ then it is" Pepe "after decoding. So, we need to build our Huffman encoded and decoded dictionary tables through this binary tree.One thing to note here is that our Huffman does not conflict with the encoding of individual characters, that is, there is no prefix for another encoding, otherwise it would be a big problem. Because the encoding
For details, please refer to the previous blog: Optimal Huffman coding based on binary tree and doubly linked list for limiting lengthThere is a significant difference in efficiency between array-based and linked-list-based implementations:Encode 256 symbols with a symbol weight of 1 ... 256, limit the length to 16, loop encode 1w times, release mode. Based on the time of the linked list is 8972ms, the arra
The greatest gain in learning Huffman coding is to learn the use of priority queues in STL and the issues to be aware of when using them: when using custom data types, priority queues overload their comparison operators. About Huffman tree How to explain, see the introduction of the algorithm, the principle is really simple, but to write the complete code is the
Huffman Coding Tree
View Submit Statistics Questions
Total time limit: 1000ms memory limit: 65535kB
Describe
Constructs an extended binary tree with n external nodes, each outer node Ki has a WI counterpart, as the right of the external node. The sum of the weighted external path length of the leaf node of this extended binary tree is minimal:
Min (W1 * L1 + W2 * L2 + W3 * L3 + ... + Wn * Ln)
Wi: Th
1 Build Huffman tree.(using the data structure of the queue, continuously get the smallest two, exit the queue and make it the left and right subtree of the new node.) Then insert the new node into the queue. So loop ... )Counts the occurrences of each character, based on the string entered by the user. Set weights. Build the queue. The node in the queue is a two-tree node (with a left pointer, and a right pointer).Build a new node, and the left and r
Huffman coding is the use of greedy algorithm for text compression algorithm, the algorithm idea is the number of characters in the first statistical file, save to the array, and then the characters in ascending order of the number of times, the smallest selection of two elements to join the formation of a subtree, the number of sub-tree is equal to two nodes of the sum of the number of Then delete the two
requires determining that as many containers as possible are loaded into the ship without the loading volume being limited.Solution: Each time the weight of the lightest person.Huffman Code:For shorter characters with high frequency, the characters with lower frequency appear with longer encoding. A 0,1 string is specified for each character as its code, and the code that requires either character is not prefixed with any other character code. This encoding is called a prefix code.The above fou
the last character of the document, reading the nn char cc; Ffile.get (cc); int xx = cc-' 0 '; Get the number of extra charactor//turn into digital ffile.seekg (0L, Ios::beg); Goto file begin //Navigate to the beginning of the document to read the compressed character while (Getline (Ffile, foo)) { int len = Foo.size (); for (int i=0; iSo we get the 01 coded string before the compression fstr~~~The above is in the writing course design to le
Objective
I want to learn the data structure of the small partners must know Huffman, the great God invented the famous "Best binary Tree", in order to commemorate him, we call it "Huffman tree." Huffman tree can be used for Huffman coding,
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.