← Text Compression (You Can Say That Again!)
Grades 6–8 reading level
Text Compression (You Can Say That Again!)
Adapted with AI from the original open resource by CS Unplugged. Nothing is invented — only the reading level changes.
Activity 3: You Can Say That Again! — Text Compression
Summary
Computers only have a limited amount of space to store information, so they need to represent that information as efficiently as possible. This process is called compression. By coding (rewriting) data before it is stored, and then decoding it (turning it back to normal) when it is needed again, a computer can store more data — or send it faster over the Internet.
Curriculum Links
- English: Recognizing patterns in words and text.
- Technology: Understanding how computers work.
Skills
- Copying written text
Ages
- 9 and up
Materials
- An overhead transparency: You Can Say That Again!
- Worksheet: You Can Say That Again!
- Worksheet: Extras for Experts
- Worksheet: Short and Sweet
- Worksheet: Extras for Real Experts
Introduction
Computers have to store and send huge amounts of data. To avoid using too much storage space, or taking too long to send information over an Internet connection, computers compress text — shrink it down — a bit like this activity shows.
Demonstration and Discussion
Look at the poem "The Rain." Search for patterns of letters in it. Can you find groups of two or more letters — or even whole words or phrases — that repeat? (Replace the repeated parts with boxes, as shown in the example.)
The Rain
Pitter patter
Pitter patter
Listen to the rain
Pitter patter
Pitter patter
On the window pane
Worksheet Activity: You Can Say That Again!
Many of the words and letters in this poem are missing. Can you fill them back in correctly? You'll find the missing pieces by following the arrow to the box it points to.
Now try making your own puzzle using a simple poem or nursery rhyme. Remember: your arrows should always point back to an earlier part of the text, and the poem should be solvable by reading left to right and top to bottom — just like normal reading.
Challenge: See how few of the original words you can keep!
Some ideas to try: Three Blind Mice, Mary Mary Quite Contrary, Hickory Dickory Dock — or a Dr. Seuss book!
Hint: Don't crowd your arrows together. Leave plenty of space around your letters and words so you have room to draw boxes within boxes and arrows pointing to them.
It's easier to build the puzzle if you write out the whole poem first, and then decide where to add the boxes.
Worksheet Activity: Extra for Experts
How would you solve this puzzle?
Ban---
Sometimes the missing text points back to part of itself. This still works if you fill in the letters from left to right — because each letter becomes available to copy right before you need it. This trick is useful for computers when there's a long stretch of the same character or pattern repeating.
Try drawing a few of your own examples like this.
On computers, the boxes and arrows are actually represented using numbers. For example, the word Banana can be written as:
Ban(2,3)
Here, "2" means "count back two characters" to find where to start copying, and "3" means "copy three letters in a row" from that point:
Ban → Bana → Banan → Banana
Since two numbers are used to encode this shortcut, compression usually only saves space when at least two or more letters are being replaced. If you used two numbers just to represent one single letter, you wouldn't save any space — in fact, the file could end up bigger than before!
Try making up your own words written the way a computer would compress them. Can your friends figure out what they say?
Worksheet Activity: Short and Sweet
How many words do you actually need here?
Imagine you're a computer trying to fit as much data as possible onto your disk. Cross out every group of two or more letters that has already appeared earlier in the poem — these letters no longer need to be written out again, since a pointer could stand in for them instead. Your goal is to cross out as many letters as you can.
I know an old lady who swallowed a bird
How absurd! She swallowed a bird!
She swallowed the bird to catch the spider
That wriggled and jiggled
and tickled inside her
She swallowed the spider to catch the fly
I don't know why she swallowed a fly
Perhaps she'll die…
Worksheet Activity: Extra for Real Experts
Ready for some serious compression practice?
The story below was fed into a computer program, which found that at least 1,633 letters could be crossed out. How many can you find? Remember: only groups of two or more repeated letters in a row count.
Good luck!
Once upon a time, long, long ago, three little pigs set out to make their fortunes. The first little pig wasn't very clever, and decided to build his house out of straw, because it was cheap. The second little pig wasn't very clever either, and decided to build his house out of sticks, for the "natural" look that was so very much in fashion, even in those days. The third little pig was much smarter than his two brothers, and bought a load of bricks in a nearby town, with which to construct a sturdy but comfortable country home.
Not long after his housewarming party, the first little pig was curled up in a chair reading a book, when there came a knock at the door. It was the big bad wolf, naturally.
"Little pig, little pig, let me come in!" cried the wolf.
"Not by the hair on my chinny-chin-chin!" squealed the first little pig.
"Then I'll huff, and I'll puff, and I'll blow your house down!" roared the wolf, and he did huff, and he did puff, and the house soon collapsed. The first little pig ran as fast as he could to the house of sticks, and was soon safe inside. But it wasn't long before the wolf came calling again.
"Little pig, little pig, let me come in!" cried the wolf.
"Not by the hair on my chinny-chin-chin!" squealed the second little pig.
"Then I'll huff, and I'll puff, and I'll blow your house down!" roared the wolf, and he did huff, and he did puff, and the house was soon so much firewood. The two terrified little pigs ran all the way to their brother's brick house, but the wolf was hot on their heels, and soon he was on the doorstep.
"Little pig, little pig, let me come in!" cried the wolf.
"Not by the hair on my chinny-chin-chin!" squealed the third little pig.
"Then I'll huff, and I'll puff, and I'll blow your house down!" roared the wolf, and he huffed, and he puffed, and he huffed some more, but of course, the house was built of brick, and the wolf was soon out of breath. Then he had an idea. The chimney! He clambered up a handy oak tree onto the roof, only to find that there was no chimney, because the third little pig, being conscious of the environment, had installed electric heating. In his frustration, the wolf slipped and fell off the roof, breaking his left leg, and severely injuring his pride. As he limped away, the pigs laughed, and remarked how much more sensible it was to live in the city, where the only wolves were in the zoo. And so that is what they did, and of course they all lived happily ever after.
What's It All About?
The storage capacity of computers is growing at an astonishing rate — over the last 25 years, the typical amount of storage in a computer has grown about a millionfold. Yet we still keep finding more things to store! Computers can now hold whole books, entire libraries, and even music and movies, if there's enough room. Large files also cause problems on the Internet, because they take a long time to download. On top of that, we keep trying to make computers smaller — even a cellphone or a wristwatch is now expected to store lots of information.
Luckily, there's a solution. Instead of buying more storage space or a faster Internet connection, we can compress the data so it takes up less room. This process — compressing data and then decompressing it later — usually happens automatically inside the computer. We might just notice that a disk holds more files, or that web pages load faster, without realizing the computer is doing extra work behind the scenes to make that happen.
Many different compression methods have been invented over the years. The method used in this activity — pointing back to earlier occurrences of chunks of text — is often called Ziv-Lempel coding, or LZ coding, named after two Israeli professors who invented it in the 1970s. It works for any language and can easily cut the size of compressed data in half. You may have heard of it as "zip" on personal computers; it's also used for GIF images and in high-speed modems. In modems, this compression reduces the amount of data that needs to travel over the phone line, making everything transmit much faster.
Other compression methods work differently. Some are based on the idea that letters used more often should get shorter codes than letters used rarely. Morse code uses this same idea.
Solutions and Hints
You Can Say That Again!
Pease porridge hot,
Pease porridge cold,
Pease porridge in the pot,
Nine days old.
Some like it hot,
Some like it cold,
Some like it in the pot,
Nine days old.
Original licensed under CC BY-NC-SA 4.0. This adaptation is provided free by OER.ai.