Lossless compression

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Lossless compression

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement describes lossless compression?
A Some detail is thrown away for good
B The original data can be rebuilt exactly
2. You unzip a ZIP file of your English essay. What do you get back?
A The exact essay, word for word
B An essay with a few words missing
3. Which file format uses lossless compression for images?
A PNG
B A format that discards detail to save space
4. A program (app) file is compressed before download. Which type of compression must be used?
A Lossy
B Lossless
5. True or false: A lossless file is smaller than the original, so some of its data is gone for good.
A False - the data is stored more efficiently, not deleted
B True - smaller files always lose data

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1report.txt -> report.zip -> report.txt AZIP is lossless, so unzipping must give back the exact original file, not a slightly different one.
2photo.bmp -> photo.png BLosing words means this is not lossless. Text must be restored exactly, so lossless compression is needed.
3Lossless compression is needed for programs, because one missing or changed bit could break them Cgame.exe -> game.zip -> game.exe
4After lossless compression, decompressing gives data identical to the original DThe image file gets smaller but every original pixel can still be restored exactly
5essay.docx -> compress -> 'a few words missing' -> OK Eoriginal == restored # True
6ZIP file -> unzip -> slightly different file FThe file is shrunk into a ZIP and then unzipped to get back the exact original, with nothing lost

Definitions

lossless compression

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
compressed ← compress(original) restored ← __________(compressed)
2.
restored ← decompress(compressed) IF restored _ original THEN OUTPUT "Lossless"
3.
IF format = "ZIP" __ format = "PNG" THEN type ← "lossless"
4.
needsExact ← TRUE IF __________ THEN method ← "lossless"
5.
zipFile ← compress(original) copy ← decompress(zipFile) differences ← _

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A type = "lossy"
B packed = compress(file)
C back = decompress(packed)
D print(back == file)
Question 2
A file = "essay.txt"
B method = "JPEG"
C lossless = True
D print(file, method)
Question 3
A file = "game.exe"
B needs_exact = False
C if needs_exact:
D use = "lossless"
Question 4
A format = "JPG"
B lossless = True
C print("No pixels lost")
Question 5
A original = "AAAAAB"
B packed = compress(original)
C restored = decompress(packed)
D same = restored != original
E print(same)

Answer Key

Lossless compression
Section A: Quick Questions
Q1
B — The original data can be rebuilt exactly
Q2
A — The exact essay, word for word
Q3
A — PNG
Q4
B — Lossless
Q5
A — False - the data is stored more efficiently, not deleted
Section B: Match the Pairs
Q1
report.txt -> report.zip -> report.txt → The file is shrunk into a ZIP and then unzipped to get back the exact original, with nothing lost
Q2
photo.bmp -> photo.png → The image file gets smaller but every original pixel can still be restored exactly
Q3
Lossless compression is needed for programs, because one missing or changed bit could break them → game.exe -> game.zip -> game.exe
Q4
After lossless compression, decompressing gives data identical to the original → original == restored # True
Q5
essay.docx -> compress -> 'a few words missing' -> OK → Losing words means this is not lossless. Text must be restored exactly, so lossless compression is needed.
Q6
ZIP file -> unzip -> slightly different file → ZIP is lossless, so unzipping must give back the exact original file, not a slightly different one.
Section C: Definitions
Q1
lossless compression — Shrinks a file so the exact original data can be rebuilt perfectly, with nothing lost. ZIP and PNG use it. Needed for text and programs.
Section D: Fill in the Blanks
Q1
compressed ← compress(original) restored ← decompress(compressed)
Q2
restored ← decompress(compressed) IF restored = original THEN OUTPUT "Lossless"
Q3
IF format = "ZIP" OR format = "PNG" THEN type ← "lossless"
Q4
needsExact ← TRUE IF needsExact THEN method ← "lossless"
Q5
zipFile ← compress(original) copy ← decompress(zipFile) differences ← 0
Section E: Spot the Error
Q1
A — Lossy compression throws data away, so back would not equal file. The program tests for a perfect rebuild, so it should say type = "lossless".
Q2
B — JPEG is lossy and would damage the text. Text needs lossless compression like ZIP, so the line should be method = "ZIP".
Q3
B — A program must be rebuilt exactly or it may stop working. It should be needs_exact = True so that lossless compression is chosen.
Q4
A — JPG is a lossy format, so it does not match lossless = True or the message about no pixels lost. PNG is the lossless image format, so it should be format = "PNG".
Q5
D — With lossless compression the restored data is identical to the original, so the test should use == (equal), not != (not equal).