0
7.1kviews
What is huffman coding? Construct the huffman Tree and determine the code for each symbol in the sentence "Engineering"
1 Answer
0
529views
  1. Huffman algorithm or Huffman coding is an entropy encoding algorithm.

  2. It is used widely for data compression (like Winzip Compression-Winzip doesn’t use it but!)

  3. Huffman coding is used in JPEG compression.

  4. The key idea behind Huffman coding is to encode the most common characters using shorter strings of bits than those used for less common source characters.

  5. It works by creating a binary tree stored in an array.

  6. We also need to know the external path length (sum of all paths from root to external node) and internal path length (sum of all paths from root to internal node).

  7. The Huffman Algorithm

    Step 1: Create a leaf node for each character. Add the character and its weight or frequency of occurrence to the priority queue.

    Step 2: Repeat Steps 3 to 5 while the total number of nodes in the queue is greater than 1

    Step 3: Remove two nodes that have the lowest weight (or highest priority)

    Step 4: Create a new internal node by merging these two nodes as children and with weight equal to the sum of the two nodes' weights.

    Step 5: Add the newly created node to the queue.

  8. Example

enter image description here

Please log in to add an answer.