← Years 9–10 Data & Information

Dictionary (substitution) compression

Give each repeated word or phrase a short code, store the code table once, then replace every repeat with its code so the data takes up fewer characters.

Understanding Dictionary (substitution) compression in Years 9–10 Data & Information

What it does: The code table lists each short code with the repeated phrase it stands for, and is stored only once. Each repeat of "the cat" is replaced by 1 in its original position, so the order of the sentence stays the same. One copy of the table is enough to rebuild all the repeats. Storing it again and again would waste the space we are trying to save. Each replacement saves 7 - 1 = 6 characters. 5 x 6 = 30. The table entry costs extra characters, so the real saving is a bit lower.

Common mistakes: Every repeat of "go" must be replaced with its code. The third "go" was left in, so the line should be out ← "1 1 1 home". The code Z replaces "the" in the packed text, so the table must say Z = "the". With "cat" in the table the message would decode wrongly.

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
Which statement describes dictionary compression correctly?
Each repeated phrase gets a short code, and the code table is stored onceEach repeated phrase is deleted and the file just gets smaller
Matches
Table: 1=the cat Text: 1 sat, the cat ran
↓
The second 'the cat' was not replaced with code 1, so a repeat was left in full and no extra space was saved
Applying
Meanings
Term
dictionary compression
Meaning
Give each repeated word or phrase a short code, store the code table once, then replace every repeat with its code so the data takes up fewer characters.
Practice
TABLE
Testing
Gaps
SMALL: " sat, # ran"
Check Answer
Spots
2table: 1 = "go"
3out ← "1 1 go home"

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

The 'Firefly' badge — Night Coder, 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. Which statement describes dictionary compression correctly?
A. Each repeated phrase is deleted and the file just gets smaller
B. Each repeated phrase gets a short code, and the code table is stored once ✓
Dictionary compression does not delete anything. It swaps repeated phrases for short codes and keeps a table so the original can be rebuilt.
2. A text repeats the phrase "good morning" 6 times. What is the best thing to put in the code table?
A. 1 = morning
B. 1 = good morning ✓
The code table should list the whole repeated phrase. Coding the full phrase "good morning" saves more characters than coding just one word.
3. The code table says 1 = the cat. Which is the correct compressed version of "the cat ran. the cat slept."?
A. 1 ran. 1 slept. ✓
B. 1 1 ran. slept.
Each repeat of "the cat" is replaced by 1 in its original position, so the order of the sentence stays the same.
4. Why is the code table stored only once?
A. It lets us decode every code back to its phrase without repeating the phrase ✓
B. It makes every code longer so it is easier to read
One copy of the table is enough to rebuild all the repeats. Storing it again and again would waste the space we are trying to save.
5. The phrase "go team" (7 characters) appears 5 times and is replaced by the code 1 (1 character). How many characters are saved by the replacements alone?
A. 30 characters ✓
B. 35 characters
Each replacement saves 7 - 1 = 6 characters. 5 x 6 = 30. The table entry costs extra characters, so the real saving is a bit lower.

Match the Pairs

1=go to the → A code table entry: the short code 1 stands for the repeated phrase 'go to the'
1 shop, 1 park, 1 beach → The compressed text, where every repeat of the phrase has been replaced by its short code
Build the code table by giving the repeated phrase 'good morning' the short code 2 → 2=good morning
Replace both repeats of 'good morning' in 'good morning Sam, good morning Alex' using code 2 → 2 Sam, 2 Alex
Table: 1=the cat Text: 1 sat, the cat ran → The second 'the cat' was not replaced with code 1, so a repeat was left in full and no extra space was saved
Text: 3 is fun, 3 is easy (no code table stored) → The code table is missing, so nobody can tell that 3 stands for a phrase

Key Term

dictionary compression
Give each repeated word or phrase a short code, store the code table once, then replace every repeat with its code so the data takes up fewer characters.

Fill in the Blanks

1. TABLE: # = "the cat" TEXT: "the cat sat, the cat ran" SMALL: "# sat, # ran"
Hint: Type the short code from the table that replaces the first repeated phrase.
2. original ← 30 compressed ← 12 saved ← original - compressed
Hint: Type the operator that finds how many characters were saved.
3. phrase ← "the cat" code ← "#" saved ← LENGTH(phrase) - LENGTH(code)
Hint: Type the function name that counts the characters in the phrase.
4. text ← "the cat sat, the cat ran" small ← REPLACE(text, "the cat", "#")
Hint: Type the function name that swaps every repeat of a phrase for its code.
5. code ← "#" phrase ← "the cat" table[code] ← phrase
Hint: Type the variable that holds the short code used as the table key.

Spot the Error

Question 1
A s ← "go go go home"
B table: 1 = "go"
C out ← "1 1 go home"
Line C — Every repeat of "go" must be replaced with its code. The third "go" was left in, so the line should be out ← "1 1 1 home".
Question 2
A table: Z = "cat"
B s ← "the cat and the dog"
C out ← "Z cat and Z dog"
Line A — The code Z replaces "the" in the packed text, so the table must say Z = "the". With "cat" in the table the message would decode wrongly.
Question 3
A s ← "I like pie, we like tea"
B table: 1 = "I like"
C out ← "1 pie, 1 tea"
Line A — Dictionary compression only works on a phrase that really repeats. "we like" is not the same as "I like", so the original should be s ← "I like pie, I like tea".
Question 4
A s ← "go go go go"
B table: go = "1"
C out ← "1 1 1 1"
D saved ← 11 - 7
Line B — The table must list the short code first, then the phrase it stands for. It should be table: 1 = "go".
Question 5
A s ← "red red red blue"
B table: R = "red"
C out ← "R R R blue"
D saved ← 10 - 16
Line D — Characters saved = original length minus compressed length. The original is 16 characters and the packed text is 10, so it should be saved ← 16 - 10 (6 saved).

Student with a class code? Join your class →