Start New Discussion within our Software Development Community

Hi basically I've exhausted my mind looking for resources and help on the Huffman Tree Coding. This is my problem, there are 2 parts to what I have to do, the first done:

1. Given a text file, determine the frequency of each character in the text (map of
character and frequency)

Next comes the optimal Huffman tree:

2. Build an optimal huffman tree to represent these characters with these
frequencies (maintain a priority queue of trees, removing and joining trees until
only one tree remains – the final Huffman tree required) Hint: each Hoffman
Tree might have a weight data member, as wellas a pointer to its root node.

I've literally no idea how to go about implmenting this, I understand trees and the Huffman tree, but when it comes to implmenting it I'm lost!! Could anyone help?

You should start by defining the problem itself.

First aff all assume you will only be using ascii symbol.
This way you will only be needing to keep track of 128 diffent kind of charachters.
Make an int array 128 long, initilaize to zero for entire entries

Make a good filereader function,
that reads the file char by char until end of file.
For each char get the ascii value and increment the
intarray[asciival of char] ++;

the int array will then contain a table of occurences of the different chars.
The sum of elements should equal the number of chars read from file.

You say you want the frequenzy, then you just need to divide with the total sum.
But for creating the huffmancode, you dont need the frequnzies just an ordered list.

This should get you started

good luck

This question has already been answered. Start a new discussion instead.