•
•
•
•
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
![]() |
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
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!
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!
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
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!
http://ciips.ee.uwa.edu.au/~morris/Y...0/huff-op.html
Looks like just what you want!
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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/
•
•
•
•
Originally Posted by nbrmkumaresh
Please give me an idea of how to do program the huffman code in C
http://www.daniweb.com/code/snippet5.html
Test it, improve it, learn from it!
May 'the Google' be with you!
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.
All generalizations are wrong. Even this one.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- huffman code (C)
Other Threads in the C++ Forum
- Previous Thread: Warning on Overloaded stream operators
- Next Thread: files(plz help)



Linear Mode