Will Serialization Help in Storing a Huffman Tree To A File

532 views Asked by At

I am creating Huffman compression program for my class assignment. I know how to implement it but since decoder has to either use a conversion table stored by the encoder or create the Huffman tree from scratch, I wanted to store the complete Huffman tree as it it by the encoder so decoder doesn't need to reconstruct it. I came to know that saving a thing with pointers is not same so I saw that Serialization might help. My Main questions are:

1- Will Serialization be able to store the tree as it is ? 2- Does storing the tree will take more space then storing a conversion table and reconstructing it ?

I want to minimize the tree data to be stored in the encoded file. I'm talking plain text compression here. - Thanks

1

There are 1 answers

2
Mark Adler On BEST ANSWER

You don't need to transfer the tree. Once you have the code lengths for each symbol, discard the tree. You can then construct a canonical code from the lengths and an ordering of the symbols. You would then transmit only the lengths to the decoder, and the decoder would construct the same canonical code from just the lengths.