4. Huffman Encoding #

Created Sunday 08 March 2020

This is a technique for text compression. Remember that this compression(text) has to be lossless.

Algorithm(Compression)

  1. Count the frequencies and update in a 26 or 256 sized array
  2. We need two minimum nodes at each iteration for forming the tree, so use a Min Priority Queue for this. Just pop 2 and push the sum. Keep doing until no letter is left.
  3. Make the tree: Make a start node.
  4. Save the codes in a hashmap. key is the letter and value is teh binary code. We use this to avoid
  5. Traverse the message and generate the compressed text.

Send the decomp tree and the compressed text;

Algorithm(Decompression)

  1. Make the hashmap for the tree. Keys are compressed texts values are letters.
  2. Traverse the compressed text and generate the original text.

This can be done as a project in school.