943,600 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 38029
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 28th, 2004
-1

huffman code

Expand Post »
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
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
apurva agarwal is offline Offline
13 posts
since Aug 2004
Aug 28th, 2004
0

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!
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Aug 28th, 2004
0

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!!!!
Reputation Points: 14
Solved Threads: 0
Newbie Poster
apurva agarwal is offline Offline
13 posts
since Aug 2004
Aug 30th, 2004
0

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!
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Aug 30th, 2004
0

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/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alex Vinokur is offline Offline
3 posts
since Aug 2004
Oct 3rd, 2004
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
devangat20 is offline Offline
1 posts
since Oct 2004
Oct 3rd, 2004
0

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jan 28th, 2005
0

Re: huffman code

Please give me an idea of how to do program the huffman code in C
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nbrmkumaresh is offline Offline
1 posts
since Jan 2005
Jan 28th, 2005
0

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!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Apr 23rd, 2008
0

Re: huffman code

Stop begging for code. Do your own work and read this thread http://www.daniweb.com/forums/announcement8-2.html
Reputation Points: 46
Solved Threads: 24
Posting Whiz in Training
hammerhead is offline Offline
248 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: Bejeweled 2 Algorithm
Next Thread in C++ Forum Timeline: binary '+' : no operator found which takes a right-hand operand





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC