AQA Computer Science 8525Topic 3.3 — Fundamentals of data representationFoundation & Higher
Everything a computer stores is a pattern of ones and zeros. This topic is about how the same binary building blocks are arranged to hold numbers, text, pictures, sound and compressed data, and how you work backwards from what is stored to what it means. It is the most calculation-heavy part of Paper 2, and the calculations are all variations on the same two ideas: count the bits, and read the pattern.
What you need to know
What compression is
Explain what data compression is. It is a way of storing the same information in fewer bits, by removing redundancy and, where loss is acceptable, removing information that cannot be perceived. The result is a file that takes less space and transfers more quickly, at the cost of some processing time to compress and decompress it.
Key fact: Compression stores the same information in fewer bits by removing redundancy.
Why compress
Understand why data may be compressed and that there are different ways to compress data. Students should understand that it is common for data to be compressed and should be able to explain why it may be necessary or desirable to do so. Storage is finite, downloads take time, and some formats simply cannot be handled unless they are compressed. It may also be necessary when a file is too large for a system to handle.
Key fact: Compression saves storage space, speeds up transfer and can be necessary to handle a file at all.
Huffman coding
Explain how data can be compressed using Huffman coding, and be able to interpret Huffman trees. The idea is frequency-based: the characters that appear most often get the shortest codes, and the rare ones get the longest. The tree is read from the bottom: each leaf is a character, and each time you go left you write a 0 and each time you go right you write a 1.
Key fact: Huffman coding gives the most frequent characters the shortest codes; read the tree from the leaves up, writing 0 for left and 1 for right.
Calculating the saving
Be able to calculate the number of bits required to store a piece of data compressed using Huffman coding, and the number of bits required to store the same piece of data uncompressed in ASCII. Uncompressed ASCII uses 8 bits per character, so 100 characters is 800 bits. The Huffman total is the number of characters of each type multiplied by the length of its code, added together. The saving is the difference.
Key fact: Uncompressed ASCII is 8 bits per character; the Huffman total is (frequency x code length) for each character, added together.
Run length encoding
Explain how data can be compressed using run length encoding (RLE). RLE replaces a repeated run of the same value with a count and the value. So 0000011100000011 becomes 5 0 3 1 6 0 2 1: five zeros, three ones, six zeros, two ones. It compresses data that has long runs, such as simple images, very effectively.
Key fact: RLE replaces a run of identical values with a count followed by the value.
When each method works
The two methods work best on opposite kinds of data. Huffman coding suits text, where some letters are much more common than others. RLE suits images and graphics, where large areas are the same colour, and it does nothing at all for data with no runs — in the worst case it can even make the file bigger, because you have stored a count and a value for every single item.
Key fact: Huffman suits text; RLE suits images with large areas of one colour, and can make files bigger if there are no runs.
Flashcards
What is data compression?
A way of storing the same information in fewer bits by removing redundancy.
What is the basic idea of Huffman coding?
The most frequently occurring characters are given the shortest codes and the rarest the longest.
How do you read a Huffman tree?
From the bottom up, from the leaf for the character to the root, writing 0 for each step to the left and 1 for each step to the right.
How many bits does a character take in uncompressed ASCII?
8 bits.
How does run length encoding work?
It replaces each run of identical values with a count followed by the value.
What does 0000011100000011 become using run length encoding?
5 0 3 1 6 0 2 1.
Which method of compression suits text best?
Huffman coding, because it exploits the fact that some characters are much more common than others.
Exam questions
Written in the style of AQA Computer Science, with a mark scheme for each one. No question here is a real past paper question.
mcq1 mark
What does the run length encoded pattern 0000011100000011 represent?
3 zeros, 5 ones, 2 zeros, 6 ones
5 ones, 3 zeros, 6 ones, 2 zeros
8 zeros, 8 ones
5 zeros, 3 ones, 6 zeros, 2 ones
Mark scheme: 1 mark for choosing 5 zeros, 3 ones, 6 zeros, 2 ones, which is the frequency and data pair sequence given in the specification.
calc3 marks
A piece of text is 200 characters long. State how many bits are needed to store it uncompressed in ASCII, and explain what happens to that figure if it is compressed using Huffman coding where the codes are on average 5 bits long.
Answer: Uncompressed: 200 x 8 = 1,600 bits. With Huffman coding: 200 x 5 = 1,000 bits, a saving of 600 bits.
six6 marks
Explain in English the two methods of data compression in the specification, and how you would choose between them.
Mark scheme: Level 1 (1-2 marks): A short answer saying Huffman coding suits text and run length encoding suits images. Level 2 (3-4 marks): A structured answer covering both methods with the calculation methods. Level 3 (5-6 marks): A detailed answer explaining that compression removes redundancy to store the same information in fewer bits, describing Huffman coding in terms of frequency and the shortest codes for the most common characters, showing how to read a Huffman tree and calculate the compressed size against the 8 bits per character of ASCII, describing run length encoding with the 5 0 3 1 6 0 2 1 example, and explaining that RLE can make a file bigger when there are no runs, so the method is chosen to suit the type of data.