Skip to content
Related Articles

Related Articles

Algorithms | Greedy Algorithms | Question 3
  • Last Updated : 27 Feb, 2013
GeeksforGeeks - Summer Carnival Banner

A networking company uses a compression technique to encode the message before transmitting over the network. Suppose the message contains the following characters with their frequency:

character   Frequency
    a           5
    b           9
    c           12
    d           13
    e           16
    f           45

Note : Each character in input message takes 1 byte.

If the compression technique used is Huffman Coding, how many bits will be saved in the message?
(A) 224
(B) 800
(C) 576
(D) 324

Answer: (C)


Total number of characters in the message = 100. 
Each character takes 1 byte. So total number of bits needed = 800.

After Huffman Coding, the characters can be represented with:
f: 0
c: 100
d: 101
a: 1100
b: 1101
e: 111
Total number of bits needed = 224
Hence, number of bits saved = 800 - 224 = 576
See here for complete explanation and algorithm.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :