CS502

CS502 – Design and Analysis of Algorithms
Assignment No. 02
Spring 2026
Due Date: 29-06-2026

Question

Given the message string “aaddbbeess”, use the Huffman Encoding algorithm to:

  1. Calculate the frequency of each character.
  2. Determine the probability of each character.
  3. Construct the Huffman codes (codewords) for each character.

Solution

Step 1: Calculate Frequency

Message String = aaddbbeess

Total Characters = 10

CharacterFrequency
a2
b2
d2
e2
s2

Step 2: Calculate Probability

Probability = Frequency / Total Characters

CharacterProbability
a2/10 = 0.20
b2/10 = 0.20
d2/10 = 0.20
e2/10 = 0.20
s2/10 = 0.20

Step 3: Assign Huffman Codewords

CharacterCodeword
a00
b01
d100
e101
s11

Final Answer

Characterabdes
Frequency22222
Probability0.200.200.200.200.20
Codeword000110010111

Submitted By: zaniklawnak
Student ID: bc100201010

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top