Skip to main content
AP CSP course

F05 · Topic 2.2

Compression tradeoff

Account for every required byte and choose exact recovery or information loss for a purpose.

1. Predict first

A 20-byte message needs 12 payload bytes plus 10 dictionary bytes. Is it smaller? Give the exact difference.

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 120Waiting
  2. Input 212Waiting
  3. Input 310Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Make payload + dictionary equal the original, then change it by one byte.

2. Build your procedure

Specify a reversible dictionary for a repeated message, encode and decode it, and compare original bytes with payload plus dictionary. Then identify a different use where a stated loss is acceptable.

Use AP CSP pseudocode, a language you know, or precise plain language. Your code is not executed here. Use the classroom assignment to save your response.

3. Check boundaries

Public worked tests for the fixed model
InputExpectedWhy this case
Original 20,payload 12,dictionary 1022 bytes;2 bytes largerOverhead counts.
Original 40,payload 12,dictionary 1022 bytes;18 bytes savedThe same overhead can pay off on a more repetitive message.
Original 22,payload 12,dictionary 10Equal sizeBreak-even is not a reduction.

4. Explain and reflect

Does a compressed file automatically protect its contents from an observer?

Model limits: A size-accounting model. It does not run a general codec or guarantee a compression ratio for arbitrary files.

Teacher guidance and scoring