Homework 19: Huffman Coding II

Building on October’s assignment, your task is to now encode arbitrary text using Huffman Coding.

Your program should take textual input on stdin (or take in a single file argument and read input from that file). It should then build a Huffman tree out of the characters present in the input, encode the input according to the tree, and display on stdout the pre-order traversal of the Huffman tree plus the encoded text as “0” and “1” ASCII characters.

Basically, the output from this month’s program should look like the input from last month’s program.

Example input:

abracadabra!

Example output:

*a**!*dc*rb
0111110010110101001111100100

Bring your solution to our November meeting.

Feel free to discuss the problem or any other topics you are interested in on our mailing list (accessible via our Meetup Group).