← Years 9–10 Data & Information

Shorter codes for frequent characters

Gives common characters short bit codes and rare ones longer codes, so a whole message uses fewer bits than if every character used the same fixed number of bits.

Understanding Shorter codes for frequent characters in Years 9–10 Data & Information

What it does: The tally shows A appears 6 times, B twice and C once, so A should get the shortest code. Multiplying each letter's count by its code length and adding them gives 12 bits, which is less than the 18 bits needed with fixed-length codes. You need the character frequencies first so you know which characters should get the short codes.

Common mistakes: The message has 9 characters and each uses 2 bits, so the fixed-length total is 9 * 2 = 18 bits, not 16. B appears only once in AABAACAD, so the count should be 1. Counting frequencies correctly is the first step in giving the common characters shorter codes.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 6–16) and word search (Modules 6–132).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
In variable-length coding, which character gets the shortest bit code?
The rarest characterThe most frequent character
Matches
A=10, B=0, C=11 (A appears 6 times, B twice)
↓
The shortest code (0) was given to B, which is rarer. The most frequent letter A should get the 1-bit code, so A=0 and B=10.
Applying
Meanings
Term
variable-length coding
Meaning
Gives common characters short bit codes and rare ones longer codes, so a whole message uses fewer bits than if every character used the same fixed number of bits.
Practice
Message: AAAAAABBC
Testing
Gaps
Count of A =
Check Answer
Spots
2fixed code = 2 bits each
3fixed total = 9 * 2 = 16 bits

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Penguin' badge — List Waddler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. In variable-length coding, which character gets the shortest bit code?
A. The most frequent character ✓
B. The rarest character
Frequent characters appear many times, so giving them short codes saves the most bits overall.
2. A message uses 4 different characters. A fixed-length code needs 2 bits per character. How many bits does a 100-character message take?
A. 400 bits
B. 200 bits ✓
100 characters x 2 bits = 200 bits. Fixed-length means every character uses the same number of bits.
3. Which step comes first when building a variable-length code?
A. Count how often each character appears ✓
B. Give every character a 1-bit code
You need the character frequencies first so you know which characters should get the short codes.
4. In the message AAAAAAAB, which code assignment saves more bits?
A. A = 0, B = 10 ✓
B. A = 10, B = 0
A appears 7 times, so A should get the shorter code. A = 0 and B = 10 gives 7 + 2 = 9 bits, but swapping them gives 14 + 1 = 15 bits.
5. Message: AAAAAAAB. With A = 0 and B = 10, the total is 9 bits. A fixed 2-bit code would use 16 bits. What does this show?
A. Fixed-length coding used fewer bits
B. Variable-length coding used fewer bits ✓
9 bits is less than 16 bits, so giving the common letter a short code made the message smaller.

Match the Pairs

A=0, B=10, C=11 → A variable-length code: the most common letter A gets a 1-bit code, and the rarer letters B and C get 2-bit codes.
9 letters x 2 bits = 18 bits → The total bits for a 9-letter message when a fixed-length code uses 2 bits for every character.
Counting character frequencies in AAAAAABBC shows which letter is most common and should get the shortest code. → A:6, B:2, C:1
Comparing total bits shows the variable-length code (A=0, B=10, C=11) uses fewer bits than a 2-bit fixed code for AAAAAABBC. → 6x1 + 2x2 + 1x2 = 12 bits (fixed: 18 bits)
A=10, B=0, C=11 (A appears 6 times, B twice) → The shortest code (0) was given to B, which is rarer. The most frequent letter A should get the 1-bit code, so A=0 and B=10.
12 bits vs 18 bits, so the fixed-length code is smaller → 12 is less than 18, so the variable-length code is smaller. The fixed-length code is the larger one.

Key Term

variable-length coding
Gives common characters short bit codes and rare ones longer codes, so a whole message uses fewer bits than if every character used the same fixed number of bits.

Fill in the Blanks

1. Message: AAAABBC Count of A = 4
Hint: Count how many times the letter A appears in the message
2. Fixed: 7 characters x 2 bits = 14 bits
Hint: Multiply the number of characters by the bits per character
3. Most common letter gets the shortest code
Hint: Type the word describing the code length a frequent character receives
4. A: 4 x 1 = 4 B: 2 x 2 = 4 C: 1 x 2 = 2
Hint: Multiply the count of C by the bits in its code
5. 10 bits < 14 bits, so variable saves space
Hint: Type the operator that shows variable-length uses fewer bits than fixed-length

Spot the Error

Question 1
A message = AAAAAABBC
B fixed code = 2 bits each
C fixed total = 9 * 2 = 16 bits
Line C — The message has 9 characters and each uses 2 bits, so the fixed-length total is 9 * 2 = 18 bits, not 16.
Question 2
A message = AABAACAD
B count A = 5
C count B = 2
D count C = 1
Line C — B appears only once in AABAACAD, so the count should be 1. Counting frequencies correctly is the first step in giving the common characters shorter codes.
Question 3
A A = 00 (most common)
B B = 10
C C = 11 (rare)
Line A — The most common character should get the shortest code. A should be 0 (1 bit), not 00 (2 bits), which is no shorter than the codes for the rare characters.
Question 4
A A: 5 times, code 0 (1 bit)
B B: 1 time, code 10 (2 bits)
C C: 1 time, code 11 (2 bits)
D total = 5*1 + 1*2 + 1*2 = 8
Line D — Multiply each count by its code length and add: 5 + 2 + 2 = 9 bits, not 8.
Question 5
A Fixed: 1 bit for 4 letters
B Message has 10 characters
C Total = 10 * 2 = 20 bits
Line A — One bit only gives 2 patterns (0 and 1). To give 4 different letters their own fixed-length code you need 2 bits each, which is what the total of 10 * 2 = 20 uses.

Student with a class code? Join your class →