Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
GeneralRe: datagrid check box Pin
totig23-Jul-03 13:26
totig23-Jul-03 13:26 
GeneralRe: datagrid check box Pin
Radoslav Bielik24-Jul-03 5:04
Radoslav Bielik24-Jul-03 5:04 
GeneralAccess Denied Pin
Alexandru Serban23-Jul-03 11:38
professionalAlexandru Serban23-Jul-03 11:38 
GeneralRe: Access Denied Pin
Julian Bucknall [MSFT]23-Jul-03 13:59
Julian Bucknall [MSFT]23-Jul-03 13:59 
GeneralRe: Access Denied Pin
Alexandru Serban23-Jul-03 19:55
professionalAlexandru Serban23-Jul-03 19:55 
Generalhuffman tree algorithm Pin
jtmtv1823-Jul-03 11:23
jtmtv1823-Jul-03 11:23 
GeneralRe: huffman tree algorithm Pin
totig23-Jul-03 13:27
totig23-Jul-03 13:27 
GeneralRe: huffman tree algorithm Pin
Julian Bucknall [MSFT]23-Jul-03 13:41
Julian Bucknall [MSFT]23-Jul-03 13:41 
I'm kind of puzzled: java and C# are very similar. If you've found a java example of creating a huffman tree than it should be easy to convert it into C#.

To build a huffman tree you'll need two basic classes: the tree and a priority queue. (You need the latter to easily get the nodes or partial trees with the smallest weights every time.)

A huffman tree consists of node objects. Each node object will have a left child node and a right child node, and will have a weight value (the weight being the count of characters in the node and its children). You'll also store the byte value in the node.

So, first do it without regard to performance. Create an array of nodes, one for each possible byte in the input stream (i.e. 256 of them). Read through the input stream, for each byte you update the weight in the relevant node object.

Push all the nodes with non-zero weights in the priority queue.

Pop the top two off. Create a new parent node with weight equal to the sum of the two nodes' weights. The children of this parent are the two nodes popped off.

Push the parent node into the priority queue.

Perform the previous two steps until there is only one node in the queue. This is the huffman tree.


Cheers, Julian
Program Manager, C#

This posting is provided "AS IS" with no warranties, and confers no rights.
GeneralRe: huffman tree algorithm Pin
jtmtv1823-Jul-03 14:46
jtmtv1823-Jul-03 14:46 
GeneralRe: huffman tree algorithm Pin
Frank Olorin Rizzi24-Jul-03 4:11
Frank Olorin Rizzi24-Jul-03 4:11 
GeneralRe: huffman tree algorithm Pin
Julian Bucknall [MSFT]24-Jul-03 8:48
Julian Bucknall [MSFT]24-Jul-03 8:48 
GeneralRe: huffman tree algorithm Pin
Frank Olorin Rizzi24-Jul-03 4:07
Frank Olorin Rizzi24-Jul-03 4:07 
GeneralRe: huffman tree algorithm Pin
jtmtv1824-Jul-03 7:52
jtmtv1824-Jul-03 7:52 
GeneralRe: huffman tree algorithm Pin
Julian Bucknall [MSFT]24-Jul-03 8:50
Julian Bucknall [MSFT]24-Jul-03 8:50 
GeneralRe: huffman tree algorithm Pin
Frank Olorin Rizzi24-Jul-03 16:39
Frank Olorin Rizzi24-Jul-03 16:39 
GeneralMultithreaded application design question. Pin
GriffonRL23-Jul-03 11:11
GriffonRL23-Jul-03 11:11 
GeneralRe: Multithreaded application design question. Pin
wightman_michael22-Dec-09 15:40
wightman_michael22-Dec-09 15:40 
QuestionMethodInfo Invoke, bad performance? Pin
STW23-Jul-03 9:15
STW23-Jul-03 9:15 
AnswerRe: MethodInfo Invoke, bad performance? Pin
Eric Gunnerson (msft)23-Jul-03 10:02
Eric Gunnerson (msft)23-Jul-03 10:02 
GeneralRe: MethodInfo Invoke, bad performance? Pin
STW26-Jul-03 23:37
STW26-Jul-03 23:37 
GeneralRe: MethodInfo Invoke, bad performance? Pin
Eric Gunnerson (msft)27-Jul-03 5:23
Eric Gunnerson (msft)27-Jul-03 5:23 
GeneralRe: MethodInfo Invoke, bad performance? Pin
STW27-Jul-03 8:48
STW27-Jul-03 8:48 
AnswerRe: MethodInfo Invoke, bad performance? Pin
Daniel Turini23-Jul-03 11:31
Daniel Turini23-Jul-03 11:31 
GeneralRe: MethodInfo Invoke, bad performance? Pin
STW26-Jul-03 23:41
STW26-Jul-03 23:41 
GeneralAccessing Functions Pin
ppathan23-Jul-03 6:08
ppathan23-Jul-03 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.