For this program, you will need to compute the optimal Huffman code for a set of letters. The input will consist of a series of frequencies (and these correspond to the number of A, B, C, ...). There will be at most 26 numbers in the input file.

For example, if you have 5 As, 2 Bs, and 1 C, then the input is

5
2
1

Your program should determine the total number of bits to encode the letters, and then print out the bit patterns used for each code work. In this example, you would have a tree with A on one side (requiring 1 bit), and then B and C on the other side (requiring 2 bits each). The total number of bits is 11 (5 bits, one for each A, then 4 bits for the Bs, and 2 more bits for the C). The output would look like

11
A 0
B 10
C 11

There are many different possible bit patterns that would work -- you just need to print out one of them.

 

 

 

You should use a heap data structure for the letters; extract two from the heap (using the extract min function), add their frequencies together, and then insert it back into the heap as a "new letter." You keep going, until there's only one thing extracted from the heap.