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:
- Calculate the frequency of each character.
- Determine the probability of each character.
- Construct the Huffman codes (codewords) for each character.
Solution
Step 1: Calculate Frequency
Message String = aaddbbeess
Total Characters = 10
| Character | Frequency |
|---|---|
| a | 2 |
| b | 2 |
| d | 2 |
| e | 2 |
| s | 2 |
Step 2: Calculate Probability
Probability = Frequency / Total Characters
| Character | Probability |
|---|---|
| a | 2/10 = 0.20 |
| b | 2/10 = 0.20 |
| d | 2/10 = 0.20 |
| e | 2/10 = 0.20 |
| s | 2/10 = 0.20 |
Step 3: Assign Huffman Codewords
| Character | Codeword |
|---|---|
| a | 00 |
| b | 01 |
| d | 100 |
| e | 101 |
| s | 11 |
Final Answer
| Character | a | b | d | e | s |
|---|---|---|---|---|---|
| Frequency | 2 | 2 | 2 | 2 | 2 |
| Probability | 0.20 | 0.20 | 0.20 | 0.20 | 0.20 |
| Codeword | 00 | 01 | 100 | 101 | 11 |
Submitted By: zaniklawnak
Student ID: bc100201010
