Technologies K–10 · Years 9–10
Huffman coding by hand: shorter codes for common letters
Computing Technology 7–10 (NSW, 2022); Digital Technologies: Knowledge and understanding, Data representation (ACARA v9)
This site has no interactive model of its own. Where a step or a material names a Concept Studio model, simulation or tool, it has not been built; an external simulation a step names (for example PhET) is not part of this site.
The idea
Giving frequent symbols short codes and rare symbols long ones, with no code the start of another, stores text in fewer bits than a fixed 8 bits per character.
What you need
- Slips of paper for each distinct character of the phrase SHE SELLS SEA SHELLS, with its count
- A3 paper for drawing the code tree
- Computer with Python 3
How to do it
- Count each character in SHE SELLS SEA SHELLS, including spaces.
- Repeatedly join the two slips with the smallest counts into a new slip labelled with their total, drawing the join, until one slip is left.
- Label every left branch 0 and every right branch 1, and read off each character's code from the top.
- Encode the phrase and count the bits.
- Compare with 8-bit ASCII and with a fixed 3-bit code for the 6 distinct characters.
- Decode a partner's bit string and check that no code is the start of another.
What you should see
The counts are S 6, E 4, L 4, space 3, H 2, A 1 (20 characters). Huffman coding gives code lengths of 2 bits for S, E and L, 3 bits for space and 4 bits for H and A, so the phrase takes 49 bits, against 160 bits in 8-bit ASCII and 60 bits with a fixed 3-bit code. Different tie-breaks can give different codes, but every correct Huffman code for these counts gives 49 bits. The learner knows it worked when their total is 49 and their partner decodes the phrase exactly.
What changes
This activity lists no variables to change, measure and keep the same.
Common misconceptions
Each of these ideas is wrong, and the activity is a chance to test it.
- Shorter codes for every letter would be even better (codes must not be the start of another code).
- Huffman coding throws information away (it is lossless).
- The code table is free (it must be stored or agreed, which matters for short texts).
Safety card
Hazards
- None beyond normal classroom activity
Controls
- Not applicable
Note
No chemicals or heat.
Curriculum references
The NSW syllabus outcomes and Australian Curriculum v9 codes this activity supports. They are references, not a verified or complete curriculum alignment.
- Computing Technology 7–10 Syllabus (2022), NESA. Current elective syllabus. Code read from the outcomes page on 2026-09-22.CT5-DAT-01
- Australian Curriculum v9AC9TDI10K03
Sources
The pages the author read to write this activity.