GateAI
Algorithm Design Techniques

GATE CSE 2017 Set 2 · Q50

NAT2 marksMedium

Time

A message is made up entirely of characters from the set X={P,Q,R,S,T}X = \{P, Q, R, S, T\}. The table of probabilities for each of the characters is shown below: If a message of 100 characters over XX is encoded using Huffman coding, then the expected length of the encoded message in bits is ________.

GATE CSE 2017 Set 2 Q50 diagram

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 225 (±0)

Algorithm Design Techniques

To find the expected length using Huffman coding, we construct the Huffman tree for the given probabilities:

Sorted initial frequencies:

  • T:0.08T: 0.08

  • R:0.17R: 0.17

  • S:0.19S: 0.19

  • P:0.22P: 0.22

  • Q:0.34Q: 0.34

Step 1: Combine the two lowest probabilities T(0.08)T (0.08) and R(0.17)R (0.17) into a new node N1N_1 with probability 0.08+0.17=0.250.08 + 0.17 = 0.25.

  • Remaining: $S(0.19), P(0.22), N_1(0.25), Q(0.34)$

Step 2: Combine the next two lowest probabilities S(0.19)S (0.19) and P(0.22)P (0.22) into node N2N_2 with probability 0.19+0.22=0.410.19 + 0.22 = 0.41.

  • Remaining: $N_1(0.25), Q(0.34), N_2(0.41)$

Step 3: Combine N1(0.25)N_1 (0.25) and Q(0.34)Q (0.34) into node N3N_3 with probability 0.25+0.34=0.590.25 + 0.34 = 0.59.

  • Remaining: $N_2(0.41), N_3(0.59)$

Step 4: Combine N2(0.41)N_2 (0.41) and N3(0.59)N_3 (0.59) to form the root with probability 1.001.00.

Codeword lengths:

  • Length of SS: 2 bits (depth in tree)

  • Length of PP: 2 bits

  • Length of QQ: 2 bits

  • Length of TT: 3 bits

  • Length of RR: 3 bits

Expected length per character (LL):

L=∑P(x)⋅l(x)L = \sum P(x) \cdot l(x)
L=(0.22×2)+(0.34×2)+(0.17×3)+(0.19×2)+(0.08×3)L = (0.22 \times 2) + (0.34 \times 2) + (0.17 \times 3) + (0.19 \times 2) + (0.08 \times 3)
L=0.44+0.68+0.51+0.38+0.24=2.25 bits/characterL = 0.44 + 0.68 + 0.51 + 0.38 + 0.24 = 2.25\text{ bits/character}

For a message of 100 characters, the expected total length is:

Total length=100×2.25=225 bits\text{Total length} = 100 \times 2.25 = 225\text{ bits}

Hence, the correct answer is 225.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Algorithm Design Techniques previous year question is Q50 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Algorithm Design Techniques in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Algorithm Design Techniques PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Algorithm Design Techniques in GATE CSE

Algorithm Design Techniques has 6 GATE CSE PYQs across 6 papers from 2011 to 2017. 3 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2017 Set 2.

How GATE tests Algorithm Design Techniques

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q50 · NAT

A message is made up entirely of characters from the set X = {P, Q, R, S, T}. The table of probabilities for each of the characters is shown below: If a message of 100 characters over X is encoded using Huffman coding, then the expected length of the encoded message in bits is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.