Consider the characters and their frequency counts. Frequencies: a = 24 b = 16…

2017

Consider the characters and their frequency counts.

image.png

Frequencies:

  • a = 24

  • b = 16

  • c = 12

  • d = 20

  • e = 8

  • f = 4

Using Huffman coding, which of the following is a valid code for character c?

  1. A.

    11111

  2. B.

    1110

  3. C.

    11110

  4. D.

    110

Attempted by 132 students.

Show answer & explanation

Correct answer: D

Concept: Huffman coding builds an optimal prefix-free code by a greedy bottom-up merge: repeatedly take the two nodes with the smallest weights, merge them into a parent whose weight is their sum, and repeat until one root remains. A leaf's code length equals its depth in this tree, so a more frequent symbol generally ends up nearer the root (shorter code) and a rarer symbol ends up deeper (longer code).

Application (build the tree for f=4, e=8, c=12, b=16, d=20, a=24):

  1. Merge the two smallest, f(4) and e(8), into (f,e)=12.

  2. Smallest weights now are c(12) and (f,e)=12; merge them into (c,(f,e))=24. This places c one level above e and f.

  3. Merge b(16) and d(20) into (b,d)=36.

  4. Merge a(24) with the (c,(f,e))=24 node into 48.

  5. Merge the last two, (b,d)=36 and 48, into the root 84.

Tracing the path to c: root -> the weight-48 node -> the weight-24 node -> c. So c sits at depth 3, giving it a code of length 3; e and f sit at depth 4 (length-4 codes).

Cross-check: a consistent prefix-free assignment for the whole tree is a=10, b=00, d=01, c=110, f=1110, e=1111 (the e/f branches may swap with the opposite left/right convention, but c stays at depth 3). The depth-3 path for c yields the 3-bit code 110, which is the valid code for c among the given options.

Explore the full course: Coal India Management Trainee