• edited by
5,572 views
0 0 votes

Consider the following message:

The number of bits required for huffman encoding of the above message are __________?

My Strategy:- 

But the answer given is 52bits i used standard Algorithem 

Made Easy Solution :- 

1 Answer

1 1 vote

Steps to build Huffman Tree
 

1. Create a leaf node for each unique character and build a min heap of all leaf nodes (Min Heap is used as a priority queue. The value of frequency field is used to compare two nodes in min heap. Initially, the least frequent character is at root)

2. Extract two nodes with the minimum frequency from the min heap.

3. Create a new internal node with the frequency equal to the sum of the two nodes frequencies. Make the first extracted node as its left child and the other extracted node as its right child. Add this node to the min heap.

4. Repeat steps#2 and #3 until the heap contains only one node. The remaining node is the root node and the tree is complete.

     Character      Frequency
         p         7
         q         9
          r          5
          s          5

Extract two minimum frequency nodes . Add a new internal node with frequency 5 + 5 = 10.

    

      character      frequency
        p          7
        q         9
         rs         10

Extract two minimum frequency nodes . Add a new internal node with frequency 7 + 9 = 16.

     character  frequency
        pq      16
        rs       10

   Character      bits
         p         10(2 bits)
         q         11 ( 2 bits)
          r         00 ( 2 bits )
          s          01 ( 2 bits )

The number of bits required for Huffman encoding: $( 7 + 9 + 5 + 5 ) * 2 = 52 \  bits$

Position:
Show:

Related questions

0 0 votes
1 1 answer
1.5k
1.5k views
Na462 asked Apr 30, 2018
1,465 views
Consider the following graph:If the edge weight of minimum spanning tree are given and edge weight of each edge is distinct, then the minimum value of sum (a, b, c, d, e,...
2 2 votes
2 answers 2 answers
3.7k
3.7k views
Prasanna asked Jan 29, 2016
3,738 views
There are n white dots and n black dots. Equally spaced in a line. You want to connect each white dot with some block dot in one to one fashion with a minimum total lengt...
2 2 votes
4 4 answers
5.8k
5.8k views
Pankaj Joshi asked Jan 22, 2017
5,780 views
The optimal time required in merging the list of size 11, 21, 33, 34,45,54,60 ismy answer (11+21)*4+ 33*3 +(34+45)*3 + (54+60)*2but the provided answer is 269 to 282I don...
6 6 votes
3 3 answers
28.6k
28.6k views
Akash Kanase asked Dec 1, 2015
28,579 views
What is the time complexity of job sequencing with deadline using greedy algorithm?O(n)O(log n)O(n log n)O(n2)Made EasyFull Syllabus Test-6 : Basic Level : Practice Test-...