GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 76

Huffman code for dyadic probabilities

Algorithms · Greedy Algorithms · Full GATE CSE 2007 paper

GATE 2007, Q76 2 marks · MCQ
Report issue

Greedy Algorithms

Question 76, GATE 2007: Letters a,b,c,d,e,f occur with probabilities 1/2,1/4,1/8,1/16,1/32,1/32, respectively. Which list, in a,b,c,d,e,f order, is a Huffman code?
Options:
(A) 0,10,110,1110,11110,11111
(B) 11,10,011,010,001,000
(C) 11,10,01,001,0001,0000
(D) 110,100,010,000,001,111
Question 76, GATE 2007: Letters a,b,c,d,e,f occur with probabilities 1/2,1/4,1/8,1/16,1/32,1/32, respectively. Which list, in a,b,c,d,e,f order, is a Huffman code?
Options:
(A) 0,10,110,1110,11110,11111
(B) 11,10,011,010,001,000
(C) 11,10,01,001,0001,0000
(D) 110,100,010,000,001,111
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Approach. Repeatedly merge the two lowest-probability nodes. Code length is leaf depth in the resulting binary tree; high-probability a should get a one-bit word. Prefix-free alone is not enough to guarantee optimality.

2. Derivation and interpretation. Huffman merging combines e and f (1/32 each) into 1/16, merges with d to 1/8, merges with c to 1/4, merges with b to 1/2, then merges with a. The resulting leaf depths for a,b,c,d,e,f are 1,2,3,4,5,5. Option A supplies a prefix code with these depths: 0,10,110,1110,11110,11111. Bit reversal at internal branches can give other equivalent codes, but A is the listed optimal code.

Original paper, page 19