OER.ai

← Text Compression (You Can Say That Again!)

Grades 4–5 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 certain amount of space to store information, so they need to store it in the smartest way possible. This is called compression. Before information is stored, the computer changes it into a shorter code. When the information is needed again, the computer changes it back. This lets the computer store more information, or send it faster over the Internet.

Curriculum Links

  • English: Spotting patterns in words and text.
  • Technology: Understanding how computers work.

Skills

  • Copying written text

Ages

  • 9 and up

Materials

  • An overhead transparency made from the "You Can Say That Again!" page
  • For each student: the worksheets "You Can Say That Again!", "Extras for Experts," "Short and Sweet," and "Extras for Real Experts"

You Can Say That Again!

Introduction

Computers have to store and send huge amounts of data. To save storage space, and to keep information moving quickly through the Internet, computers squeeze, or compress, text. Here's how that works.

Demonstration and Discussion

Look at "The Rain" poem. Search for patterns of letters in it. Can you find groups of two or more letters that repeat? What about whole words or phrases that repeat? Replace the repeated parts with boxes, like 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 words and letters are missing from this poem. Can you fill them back in? Look in the box that each arrow points to — that's where the missing letters came from.

Now try making your own puzzle! Pick a simple poem or nursery rhyme. Draw boxes around repeated letters, words, or phrases, and use arrows to point back to where they first appeared. Make sure every arrow points to an earlier part of the poem. Someone should be able to solve your puzzle by reading left to right, top to bottom — just like normal reading.

Challenge: See how few of the original words you can leave in!

Some poems you could try: Three Blind Mice, Mary, Mary, Quite Contrary, Hickory Dickory Dock — or try 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 and arrows without things overlapping.

It's easier to build the puzzle if you write out the whole poem first, 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 a part of itself. This still works if you copy the letters in order, from left to right — each letter becomes available to copy as soon as it's written. This trick is useful for computers when there's a long stretch of the same letter or pattern repeating.

Try drawing some puzzles like this yourself.

On computers, the boxes and arrows are actually represented using numbers. For example, the word Banana can be written as Ban(2,3).

  • The "2" means: count back two letters to find where to start copying.
  • The "3" means: copy three letters in a row from that point.

Watch how it builds up:

Ban---
Bana--
Banan-
Banana-

Since two numbers are needed to code each compressed chunk, this trick only saves space if you're compressing two or more letters at once. If you tried to compress just a single letter, the file could actually get bigger, not smaller!

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 really need here?

Imagine you're a computer trying to fit as much as possible onto your disk. Cross out every group of two or more letters that has already appeared earlier in the poem — these could be replaced by a pointer instead of being written out again. Try 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?

A computer program checked the story below and found at least 1,633 letters that could be crossed out. How many can you find? Remember: only groups of two or more repeated letters 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 climbed up a handy oak tree onto the roof, only to find that there was no chimney, because the third little pig, being careful about the environment, had installed electric heating. In his frustration, the wolf slipped and fell off the roof, breaking his left leg, and badly hurting his pride. As he limped away, the pigs laughed, and said 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?

Computer storage keeps growing at an amazing speed. In the last 25 years, the amount of storage on a typical computer has grown about a millionfold — but we always find more things to fill it up with! Computers can now store whole books, entire libraries, and even music and movies, as long as there's room. Big files also cause problems on the Internet, because they take longer to download. On top of that, we like our computers to be small — even a cellphone or a smartwatch needs to hold 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. The computer usually compresses and decompresses (uncompresses) data automatically, without us noticing. All we see is that the disk holds more files, or that web pages load faster — but behind the scenes, the computer is doing extra work to make that happen.

Many different compression methods have been invented. The method you used in this activity — pointing back to earlier occurrences of repeated text — is often called Ziv-Lempel coding, or LZ coding. It was invented by two Israeli professors in the 1970s. It works for any language and can often cut the size of data in half. You may know it as "zip" on personal computers. It's also used for GIF images and for high-speed modems (devices that connect computers to phone lines). For modems, compression means less data has to travel over the phone line, so everything moves faster.

Other compression methods work differently. One idea is to give shorter codes to letters that are used more often. Morse code uses this same trick.

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.