954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

apurva agarwal
Newbie Poster
13 posts since Aug 2004
Reputation Points: 14
Solved Threads: 0
 

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!

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

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!!!!

apurva agarwal
Newbie Poster
13 posts since Aug 2004
Reputation Points: 14
Solved Threads: 0
 

Google is your programming friend! Here's what I found with "Huffman algorithm":

http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/huff-op.html

Looks like just what you want!

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 
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/huffman_template_algorithm.html
* http://sourceforge.net/projects/huffman-ta/

Alex Vinokur
Newbie Poster
3 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 
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

devangat20
Newbie Poster
1 post since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Please give me an idea of how to do program the huffman code in C

nbrmkumaresh
Newbie Poster
1 post since Jan 2005
Reputation Points: 10
Solved Threads: 0
 
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!

vegaseat
DaniWeb's Hypocrite
Moderator
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
 

Stop begging for code. Do your own work and read this thread http://www.daniweb.com/forums/announcement8-2.html

hammerhead
Posting Whiz in Training
257 posts since May 2006
Reputation Points: 46
Solved Threads: 24
 

Good advice - 3 years late!

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Sorry Salem, but I deleted a new instance of begging from this morning. hammerhead's post is legit.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

I did not see the date either :)

hammerhead
Posting Whiz in Training
257 posts since May 2006
Reputation Points: 46
Solved Threads: 24
 
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


How do we construct the Hoffman's code in C++

asim88
Newbie Poster
1 post since May 2010
Reputation Points: 5
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You