User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 10308 | Replies: 12
Reply
Join Date: Aug 2004
Posts: 13
Reputation: apurva agarwal is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
apurva agarwal apurva agarwal is offline Offline
Newbie Poster

huffman code

  #1  
Aug 28th, 2004
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
TO RISE TO GREAT HEIGHT ONE MUST GO TO GREAT DEPTH
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: huffman code

  #2  
Aug 28th, 2004
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!
Reply With Quote  
Join Date: Aug 2004
Posts: 13
Reputation: apurva agarwal is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
apurva agarwal apurva agarwal is offline Offline
Newbie Poster

Re: huffman code

  #3  
Aug 28th, 2004
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!!!!
TO RISE TO GREAT HEIGHT ONE MUST GO TO GREAT DEPTH
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: huffman code

  #4  
Aug 30th, 2004
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!
Reply With Quote  
Join Date: Aug 2004
Posts: 3
Reputation: Alex Vinokur is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Alex Vinokur Alex Vinokur is offline Offline
Newbie Poster

Re: huffman code

  #5  
Aug 30th, 2004
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/
Reply With Quote  
Join Date: Oct 2004
Posts: 1
Reputation: devangat20 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
devangat20 devangat20 is offline Offline
Newbie Poster

Re: huffman code

  #6  
Oct 3rd, 2004
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
Reply With Quote  
Join Date: Sep 2004
Posts: 6,507
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 487
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: huffman code

  #7  
Oct 3rd, 2004
>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.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Jan 2005
Posts: 1
Reputation: nbrmkumaresh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nbrmkumaresh nbrmkumaresh is offline Offline
Newbie Poster

Re: huffman code

  #8  
Jan 28th, 2005
Please give me an idea of how to do program the huffman code in C
Reply With Quote  
Join Date: Oct 2004
Posts: 2,529
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 177
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Solution Re: huffman code

  #9  
Jan 28th, 2005
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!
May 'the Google' be with you!
Reply With Quote  
Join Date: May 2006
Location: India
Posts: 247
Reputation: hammerhead is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: huffman code

  #10  
Apr 23rd, 2008
Stop begging for code. Do your own work and read this thread http://www.daniweb.com/forums/announcement8-2.html
There are 10 types of people in the world, those who understand binary and those who don't.

All generalizations are wrong. Even this one.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC