Skip to content
Official PYQ · 1989

GATE CS 1989 Q13a — Algorithm Design: Greedy Techniques

Explain with AI
A language uses an alphabet of six letters, {a,b,c,d,e,f}\left\{a, b, c, d, e, f\right\}. The relative frequency of use of each letter of the alphabet in the language is as given below: LETTERRELATIVE FREQUENCY OF USE a 0.19 b 0.05 c 0.17 d 0.08 e 0.40 f 0.11\begin{array}{|ll|ll|}\hline & \text{LETTER} & \text{RELATIVE FREQUENCY OF USE}\\ \hline &\ a &\ 0.19 \\ &\ b &\ 0.05 \\ &\ c &\ 0.17 \\ &\ d &\ 0.08 \\&\ e &\ 0.40 \\ &\ f &\ 0.11 \\ \hline \end{array}Design a prefix binary code for the language which would minimize the average length of the encoded words of the language.
View worked solution

Answer: 2.33

To minimize the average length of the encoded words, we use Huffman Coding, which generates an optimal prefix binary code.

We start with the given frequencies of the letters:

  • b:0.05b: 0.05
  • d:0.08d: 0.08
  • f:0.11f: 0.11
  • c:0.17c: 0.17
  • a:0.19a: 0.19
  • e:0.40e: 0.40

Step-by-step Huffman Tree Construction:

  1. Combine the two lowest frequencies, b(0.05)b(0.05) and d(0.08)d(0.08), to form a node bd(0.13)bd(0.13).
  2. Combine the next two lowest frequencies, f(0.11)f(0.11) and bd(0.13)bd(0.13), to form a node fbd(0.24)fbd(0.24).
  3. Combine c(0.17)c(0.17) and a(0.19)a(0.19) to form a node ca(0.36)ca(0.36).
  4. Combine fbd(0.24)fbd(0.24) and ca(0.36)ca(0.36) to form a node fbdca(0.60)fbdca(0.60).
  5. Finally, combine e(0.40)e(0.40) and fbdca(0.60)fbdca(0.60) to form the root node (1.00)(1.00).

The resulting tree structure yields the following code word lengths (depths from the root):

  • ee: depth 11 (frequency 0.400.40)
  • cc: depth 33 (frequency 0.170.17)
  • aa: depth 33 (frequency 0.190.19)
  • ff: depth 33 (frequency 0.110.11)
  • bb: depth 44 (frequency 0.050.05)
  • dd: depth 44 (frequency 0.080.08)

Average Code Word Length (LL):

L=(0.40×1)+(0.17×3)+(0.19×3)+(0.11×3)+(0.05×4)+(0.08×4)=0.40+0.51+0.57+0.33+0.20+0.32=2.33 bits per character\begin{align*}L &= (0.40 \times 1) + (0.17 \times 3) + (0.19 \times 3) + (0.11 \times 3) + (0.05 \times 4) + (0.08 \times 4) \\&= 0.40 + 0.51 + 0.57 + 0.33 + 0.20 + 0.32 \\&= 2.33 \text{ bits per character}\end{align*}

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Greedy Techniques questions