Link to home
Start Free TrialLog in
Avatar of Dragonfyre2825
Dragonfyre2825Flag for United States of America

asked on

Huffman Encoding, Output bits

Last week I had to write a version of the Huffman encoding / Compression Algorithm. I managed to hack it together. It took perhaps 5 pages of printed code. I am wondering is someone has code they would be willing to share that is much more efficient. (NOTE: this is not for a project that I am submitting - rather now for my own edification.) My university has switched to java from c++ and I am having to teach myself a lot since I started in C++; I am having trouble with the various things involved.

I am well versed on the theory behind it and can do it quite well on paper, it is the efficient java form that escapes me. I have found numerous examples of code online, but none that really fit my specific question well enough.

What I am looking for: an efficient method to read a string in from a file, calculate frequency, construct binary tree with values, traverse the tree and create prefix codes. Output (in a new file) the bit values.

What I think I understand: Input and Output is fairly simple as it isn't that much different from other languages I use. I understand the concept of parsing but haven't had any luck implementing (in the program I submitted I created a variable for each expected value and then just incremented it).

Thanks in advance,
NML

(again I understand if people avoid this for suspicion reasons.)
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial