Text: Step by step write algorithm (Huffman tree)"Disclaimer: Copyright, welcome reprint, please do not use for commercial purposes. Contact mailbox: feixiaoxing @163.com "In the process of data transmission, we always want to use as little bandwidth as possible to transmit more data, Huffman is one of the less bandwidth transmission method. The basic idea of
Original site: http://blog.csdn.net/Quack_quack/article/details/46958413Title: Give n number w[], representing the number of times n letters appear, give K. The K-binary string si is required to replace the letter I, and replaced after the replacement of the article has no ambiguity (the ambiguity here refers to any of the 1≤i,j≤n, I≠j, there are: Si is not the prefix of SJ), to replace the shortest post length (length Len=sigma (w[i]* Strlen (SI))) and the minimum value of the largest SI in thi
1 PackageCom.ietree.basic.datastructure.tree;2 3 ImportJava.util.ArrayDeque;4 Importjava.util.ArrayList;5 Importjava.util.List;6 ImportJava.util.Queue;7 8 /**9 * Created by IetreeTen * 2017/5/1 One */ A Public classHuffmantree { - - Public Static classNode { the E data; - Doubleweight; - Node leftchild; - Node rightchild; + - PublicNode (E data,Doubleweight) { + This. data =data; A This. Weight =weight; at } - - PublicString
The greedy idea is very simple. The key lies in what structure is used to implement the greedy process.
Package section9;Import java. util. Queue;Import java. util. iterator;Import java. util. Collections list;/* Chapter 9 greedy algorithm Huffman encoding */Public class Huffman {/*** @ Param ARGs*/Public static void main (string [] ARGs ){// Todo auto-generated method stubDouble [] P = {0.35, 0.1, 0.2, 0.
This article takes the example form to narrate the C + + Realization Huffman tree simple creation and the traversal method, compares the classical C + + algorithm.
The function of this example is: given n a weighted node, how to construct an n two-fork tree with a given weight of a leaf node, so that its full path length WPL minimum .
The optimal
plus less, the flower of gold is less, from the big to the small arrangement,But the wrong n times, after the game I looked at other people's code, is Huffman tree + priority queue, each take two the smallest number, sticky into a long, every time thisBut I don't know where my code is wrong.#include /* Test instructions: Chop a piece of wood, the current block is how long it takes how many gold coins, to s
Let's start by stating that we usually say Huffman tree is the best binary tree, also known as strict binary tree (note is not a complete binary tree), but Huffman Tree is not limited t
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
As a communicator, he has been in the information theory at the undergraduate level, and the graduate student has continued to work on coding. During the interview, the interviewer said a Hoffman tree, and as a communicator he forgot. Somewhat justified.Theoretical knowledgeThe most fundamental principle of the Huffman algorithm is that the cumulative (the encoded length of the character's statistical chara
Basic concepts:1. A path is a branching sequence from one node to another, and the path length refers to the number of branches that pass from one node to another node.2, in real life, we give each node the actual meaning of the real number, called the real number is the right node . In the tree structure, the path length of the root to a node is called the weighted path length of the node.3. the length of the tree's weighted path is the sum of the le
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
Application of Huffman tree :1. Select an article First2. Then count the number of characters3, the number is not 0 characters to encode4. Output code text5, the decodingOn-Machine code:/*************************************************************************> File Name:huffman tree application. cpp > Author:zzuspy> Mail: [emailprotected] > Created time:2014 Dec
#pragma once#include "Heap.h"//heap implemented using blogsTemplateStructure information of struct huffmannode//node{T _weight;huffmannodehuffmannodehuffmannodeHuffmannode (const t weight): _weight (weight), _parent (NULL), _left (NULL), _right (NULL){}};TemplateImplementation of Class Huffmantree//huffman tree{typedef huffmannodePublicHuffmantree (): _root (NULL){}~huffmantree (){_destroy (_root);_root = N
the 2nd Word, 01 (2) replaces the 3rd Word, and 1 (2) replaces the 4th Word. In this scenario, the shortest length after encoding is:1x3+1x3+2x2+2x1=12The length of the longest string Si is 3. The length of the article is the same as the optimal scheme, but the longest string length is longer.For all data, guarantee 2≤n≤100000,2≤k≤9.Players note that 64-bit integers are used for input, output, storage, and calculation.ExercisesIf you do not think Huffman
) replaces the 3rd Word, and 1 (2) replaces the 4th Word. In this scenario, the shortest length after encoding is:1x3+1x3+2x2+2x1=12The length of the longest string Si is 3. The length of the article is the same as the optimal scheme, but the longest string length is longer.For all data, guarantee 2≤n≤100000,2≤k≤9.Players note that 64-bit integers are used for input, output, storage, and calculation. The following: Because to ensure that SI is not the prefix of SJ. So you can think of
Huffman tree content does not explain here, please search yourself. The following gives the Java implementation of the Huffman tree construction process.
Node class:
1./** 2. * Binary tree Node 3. */4.public class node implements comparable {5.
6. private int value; 7.
Huffman Tree//Xin Yang # include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Data structure---C language Implementation huffman tree and encoding
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.