DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   huffman code (http://www.daniweb.com/forums/thread9966.html)

apurva agarwal Aug 28th, 2004 10:00 am
huffman code
 
hi!!
i want to know about the huffman algoriyhm and its implementation.
how the huffman code works and its use, a code in c/c++ language

Chainsaw Aug 28th, 2004 2:29 pm
Re: huffman code
 
Huffman was a guy who realized that letters do not occur statisticly randomly; 'e' is used a lot more than 'j'. He figured you could build a balanced tree of letters (or anything else that occurs non-randomly, like words) and using that tree, represent letters in a minimal number of bits.

The original Huffman went like this:
1) count the occurances of the letters in your text to be compressed
2) build a binary tree such that the shortest paths in the tree go to the most referred-to letters
3) encode the tree as bits, where a 0 means go LEFT on the tree and 1 means go RIGHT.

Later variants allowed the tree to be built dynamically as you see the charactors, as in processing a stream of bytes.

Huffman is used as the post-processing in many compressors, like gzip (which first removes blocks of common letters and then Huffmanizes the result) and jpeg (which converts pixels into cosine values and Huffmanizes the resulting (nearly the same) values).

Google will get you to some sample code easily. Now that you know the basics, the code should be pretty readable.

Good luck!

apurva agarwal Aug 28th, 2004 11:05 pm
Re: huffman code
 
thanks a lot !!!!
but i have a problem with the code i have counted the frequency but i am not able to build the heap which i have to build to finally make a tree.
help me here!!!!

Chainsaw Aug 30th, 2004 2:11 am
Re: huffman code
 
Google is your programming friend! Here's what I found with "Huffman algorithm":

http://ciips.ee.uwa.edu.au/~morris/Y...0/huff-op.html

Looks like just what you want!

Alex Vinokur Aug 30th, 2004 4:36 am
Re: huffman code
 
Quote:

Originally Posted by apurva agarwal
hi!!
i want to know about the huffman algoriyhm and its implementation.
how the huffman code works and its use, a code in c/c++ language

Look at n-ary Huffman Template Algorithm
* http://alexvn.freeservers.com/s1/huf...algorithm.html
* http://sourceforge.net/projects/huffman-ta/

devangat20 Oct 3rd, 2004 2:48 pm
Re: huffman code
 
Quote:

Originally Posted by apurva agarwal
hi!!
i want to know about the huffman algoriyhm and its implementation.
how the huffman code works and its use, a code in c/c++ language

I would be highly grateful if u give me the code

Narue Oct 3rd, 2004 4:18 pm
Re: huffman code
 
>I would be highly grateful if u give me the code
I'm sure you would. Do your own work, it's much more rewarding.

nbrmkumaresh Jan 28th, 2005 11:58 am
Re: huffman code
 
Please give me an idea of how to do program the huffman code in C

vegaseat Jan 28th, 2005 12:26 pm
Re: huffman code
 
Quote:

Originally Posted by nbrmkumaresh
Please give me an idea of how to do program the huffman code in C

Check the C code snippet right here on DaniWeb:
http://www.daniweb.com/code/snippet5.html

Test it, improve it, learn from it!

hammerhead Apr 23rd, 2008 5:45 am
Re: huffman code
 
Stop begging for code. Do your own work and read this thread http://www.daniweb.com/forums/announcement8-2.html


All times are GMT -4. The time now is 4:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC