Consider the following characters and their respective frequency:

e - 4
f - 8
g - 16
k - 32
o - 10
r - 12
s - 18

If Huffman coding is used to encode the message, what will be the encoded message for \”geeksforgeeks\”.

(A) 0100000100001100100000000101101000001000011001
(B) 0100000100001100101000001000011001000000001011
(C) 1111111101001011111011110 011010111110111100110
(D) 1011111011110 011011111111010010111110111100110


Answer: (D)

Explanation: According their given weight/frequency, Huffman coding tree will be,

\"\"

Therefore, their binary codes are:

k = 0
r = 100
g = 101
s = 110
o = 1110
e = 11110
f = 11111 

Hence, Huffman code for geeksforgeeks: 101 11110 11110 0 110 11111 1110 100 101 11110 11110 0 110

So, option (D) is correct.


Quiz of this Question


  • Last Updated : 20 Nov, 2018

Share your thoughts in the comments