Data Compression Flashcards
All 17 cards in this deck
How do you work out the number of bits needed to store uncompressed text in ASCII?
Number of characters 7, because ASCII uses 7 bits per character.
Give two reasons why data are compressed.
To reduce the file size, so less storage is needed, and to make files faster to transmit, using less bandwidth.
Give two scenarios where compression would be needed.
Streaming or downloading high-definition video, and emailing or uploading large audio or image files.
What is data compression?
Changing how data is represented so that fewer bits are needed to store it.
Name two methods of compressing data.
Huffman coding and run length encoding (RLE).
What is Huffman coding?
A compression method that gives each character a binary code based on how often it appears: the most frequent characters get the shortest codes.
How do you find a character's Huffman code from a Huffman tree?
Start at the root and follow the branches down to the character, writing down the 0 or 1 on each branch you pass.
Where in a Huffman tree are the most frequent characters found?
Closest to the root, so they have the shortest codes.
Why does Huffman coding usually need fewer bits than 7-bit ASCII?
ASCII uses 7 bits for every character. Huffman coding gives common characters codes shorter than that, so the total number of bits is smaller.
How do you work out the number of bits needed to store text compressed with Huffman coding?
For each character, multiply its frequency by the length of its code, then add these together.
How do you work out the number of bits saved by Huffman coding?
Bits saved = bits needed in 7-bit ASCII − bits needed using the Huffman codes.
What is run length encoding (RLE)?
A compression method that replaces each run of consecutive repeated values with a frequency/data pair.
What is a frequency/data pair in RLE?
e.g. 5 0The number of times a value repeats in a row, followed by the value itself.
e.g. 5 0 means five 0s in a row.What kind of data does RLE compress well?
Data with long runs of consecutive repeated values, such as an image with large areas of the same colour.
Why can RLE make some data larger instead of smaller?
If the data has few repeated values in a row, each single value becomes a pair, so the encoded data is longer than the original (eg MISSISSIPPI).
What are the steps to decode a Huffman-coded bit string using a Huffman tree?
e.g. a tree where A = 0, B = 10 and C = 11; decode 01100- Start at the root and follow the branch that matches each bit in turn.
- When you reach a character, write it down and go back to the root.
- 0 → A, 11 → C, 0 → A, 0 → A, giving ACAA.
What are the steps to write a row of a bitmap as RLE frequency/data pairs?
e.g. the row 1111000001- Working from the left, count how many times the same value repeats in a row.
- Write that count, then the value.
- Do the same for each run: 4 1 5 0 1 1.