AQA · GCSE · Computer Science · Higher
Huffman versus ASCII savings calculation
Table 1 shows the Huffman codes for the characters used in the string HESELLSSEASHELLASHES.
| Character | Character frequency | Huffman code |
|---|---|---|
| S | 6 | 11 |
| E | 5 | 10 |
| L | 4 | 00 |
| H | 3 | 011 |
| A | 2 | 010 |
| 20 |
Calculate how many bits would be saved if the string HESELLSSEASHELLASHES was encoded using the Huffman codes shown in Table 1, rather than using ASCII.
You should show your working.
Write your answer first. You can study the marking guidance whenever you need it.
Study the marking See what earns credit and compare it with a full-mark answer.
Marking points
- 1 Calculates or clearly attempts the Huffman total from character frequencies and code lengths.
- 2 Calculates or clearly attempts the 7-bit ASCII total for 20 characters.
- 3 Subtracts Huffman bits from ASCII bits to find the saving.
Full-mark answer
Huffman: (6×2) + (5×2) + (4×2) + (3×3) + (2×3) = 45 bits. ASCII: 20×7 = 140 bits. Bits saved = 140−45 = 95 bits.
Why this answer loses marks
I calculated the Huffman total and called it the saving.
A saving is a comparison: calculate the ASCII baseline too, then take the difference between the totals.