Data Representation: Images, Sound and Compression - Worksheets, Questions and Revision
15 original exam-style questions - 9 pages of questions with a full mark scheme - free printable PDF.
Data Representation: Images, Sound and Compression revision guideMore GCSE Computer Science practiceMock exams
This topic is chapter 4 of GCSE Computer Science Topic Workbook 2 and chapter 14 of GCSE Computer Science 10-Minute Tests.
2.6 Data Representation: Images, Sound and Compression
- A) 1 bit
- B) 2 bits
- C) 4 bits
- D) 8 bits
W W W W W B B B W W W W
The original (uncompressed) row used 1 byte to store the colour of each pixel. The encoded version above uses 2 bytes for each run (1 byte for the run length number and 1 byte for the colour letter).
Write pseudocode for this program.
Discuss the compression choices the business owner should make for the images and the sound file on her website, and the impact of these choices on the customer's experience.
array runLengths[3]
array symbols[3]
runLengths[0] = 4
runLengths[1] = 2
runLengths[2] = 3
symbols[0] = "W"
symbols[1] = "B"
symbols[2] = "W"
output = ""
for i = 0 to 2
count = 0
while count < runLengths[i]
output = output + symbols[i]
count = count + 1
endwhile
next i
print(output)
E: 8 T: 5 A: 3 O: 2
A Huffman tree is to be built to assign binary codes to each character, with the most frequent characters given the shortest codes.
E = 0 T = 10 A = 110 O = 111
Each video frame is 640 x 480 pixels with a colour depth of 16 bits per pixel. The application sends 2 frames every second.
The sound is sampled at 8000 Hz with a bit depth of 16 bits, recorded in stereo (2 channels).
Question 1
- (a) the number of bits used to represent/store the colour of each pixel (oe)B1
- (a) Answer: The number of bits used to represent the colour of each pixel.
- (b) recognises number of colours = 2colour depth, i.e. 24 (oe)M1
- (b) 16 caoA1
- (b) Answer: 16 colours
- (c) D caoB1
- (c) Answer: D) 8 bits
Question 2
- (a) recognises 2n must be at least 32, e.g. tests 24 = 16 (too small) and 25 = 32 (oe)M1
- (a) 5 (bits) caoA1
- (a) Answer: 5 bits
- (b) correct place value working shown using place values 16, 8, 4, 2, 1 (oe)M1
- (b) 10011 cao (ft from part a for number of bits)A1
- (b) Answer: 10011
- (c) converts binary to denary or splits into a nibble/group for conversion, e.g. 11010 = 26 (oe)M1
- (c) 1A cao (accept 0x1A oe)A1
- (c) Answer: 1A
Question 3
- (a) 256 caoB1
- (a) Answer: 256 colours
- (b) calculates the total number of pixels: 320 x 240 = 76800 (oe)M1
- (b) 76800 x 8 = 614400 shown correctly cso (answer given, working must be shown)A1
- (b) Answer: 320 x 240 = 76800 pixels; 76800 x 8 = 614400 bits
- (c) converts bits to bytes: 614400 / 8 (= 76800) (oe, ft from part b)M1
- (c) 76.8 (KB) cao ftA1
- (c) Answer: 76.8 KB
Question 4
- (a) the number of samples of the sound wave taken per second, measured in Hertz (Hz) (oe)B1
- (a) Answer: The number of samples of the sound wave taken per second.
- (b) the number of bits used to store/represent each sample (oe)B1
- (b) Answer: The number of bits used to store each sample.
- (c) the recording more closely/accurately matches the original analogue sound wave, giving higher quality sound (oe)B1
- (c) Answer: The recording more closely matches the original sound wave, giving higher quality.
- (d) the file size increases, as more samples must be stored (oe)B1
- (d) Answer: The file size increases because more samples must be stored.
Question 5
- (a) correct method: 8000 x 3 (oe)M1
- (a) 24000 (samples) caoA1
- (a) Answer: 24000 samples
- (b) multiplies number of samples by bit depth: (their samples) x 8 (oe, ft from part a)M1
- (b) 192000 (bits) cao ftA1
- (b) Answer: 192000 bits
- (c) converts bits to bytes: (their bits) / 8 (= 24000) (oe, ft from part b)M1
- (c) 24 (KB) cao ftA1
- (c) Answer: 24 KB
Question 6
- (a) stereo requires two channels of audio data to be stored instead of one (oe)B1
- (a) so the file size (approximately) doubles compared to the equivalent mono recording (oe, ft)B1
- (a) Answer: Stereo stores two channels of audio instead of one, so the file size roughly doubles compared to mono.
- (b) a lower bit depth produces a smaller file size, so it downloads/streams faster and uses less of the listener's mobile data allowance (oe)B1
- (b) spoken word/podcast audio does not need the same level of quality as music, so the small loss in quality is unlikely to be noticeable on a phone speaker (oe)B1
- (b) Answer: A lower bit depth gives a smaller file that streams faster and uses less mobile data; speech does not need studio-quality sound, so the small quality loss is not very noticeable.
Question 7
- (a) to compress data by storing a value and how many times it repeats (its run length), instead of storing the value once for every repeat (oe)B1
- (a) Answer: It compresses data by storing a repeated value once along with a count of how many times it repeats.
- (b) identifies the three correct runs, in order: 5 white, 3 black, 4 white (oe)M1
- (b) 5W 3B 4W cao (accept equivalent consistent notation, e.g. (5,W)(3,B)(4,W))A1
- (b) Answer: 5W 3B 4W
- (c) images with large areas of a single/repeated colour, e.g. simple line drawings, icons or logos, compress well (oe)B1
- (c) photographs, or images with lots of colour variation/noise between adjacent pixels, compress poorly, as there are few or no long runs (oe)B1
- (c) Answer: RLE works well on simple images with large blocks of one colour (e.g. a logo), but poorly on photographs, which have little colour repetition between adjacent pixels.
Question 8
- (a) correctly identifies the total number of pixels represented: 6 + 2 + 6 = 14 (oe)M1
- (a) WWWWWW BB WWWWWW cao (14 symbols in the correct order)A1
- (a) Answer: WWWWWWBBWWWWWW (14 pixels)
- (b) correctly finds the original size: 14 pixels x 1 byte = 14 bytes (ft from part a)M1
- (b) correctly finds the encoded size: 3 runs x 2 bytes = 6 bytes (oe)M1
- (b) (7/3):1, approximately 2.33:1 cao (accept awrt 2.3:1)A1
- (b) Answer: (7/3):1, approximately 2.33:1
Question 9
- (a) frequently occurring data (e.g. repeated characters, strings or words) is replaced by a shorter code/index that refers to an entry in a dictionary/table (oe)B1
- (a) the dictionary itself (matching each code to its full original value) is also stored, so the codes can be translated back to reconstruct the original data (oe)B1
- (a) Answer: Repeated data is replaced with a shorter code that refers to an entry in a dictionary; the dictionary is stored too so the original data can be reconstructed from the codes.
- (b) A = 4 and B = 3 both correctB1
- (b) C = 2 and D = 1 both correctB1
- (b) Answer: A = 4, B = 3, C = 2, D = 1
- (c) assigning the shortest codes to the most frequently occurring characters (oe, ft from part b)B1
- (c) reduces the total/average number of bits needed to store the whole file, because the most common symbol uses the fewest bits each time it appears (oe)B1
- (c) Answer: Giving the most common character the shortest code means that symbol uses the fewest bits every time it appears, reducing the total number of bits needed for the whole file.
Question 10
- correctly inputs the width using a sensibly named variable, e.g. width = int(input("Enter width: "))B1
- correctly inputs the height using a sensibly named variableB1
- correctly inputs the colour depth using a sensibly named variableB1
- calculates the total number of pixels, e.g. totalPixels = width * heightB1
- calculates total bits (totalPixels * colourDepth) and converts this to bytes by dividing by 8, e.g. totalBytes = totalBits / 8B1
- outputs the calculated file size in bytes, e.g. print(totalBytes)B1
- Answer:width = int(input("Enter width in pixels: "))
height = int(input("Enter height in pixels: "))
colourDepth = int(input("Enter colour depth in bits: "))
totalPixels = width * height
totalBits = totalPixels * colourDepth
totalBytes = totalBits / 8print(totalBytes)
Question 11
- Level 1 Basic, isolated point(s) made, e.g. that compression makes files smaller. Little or no reference to the impact on quality or loading speed. Limited use of technical terms.1-2
- Level 2 Some relevant discussion of lossy or lossless compression with limited application to the images and/or the sound file. A link is made between file size and loading speed or quality, but this is not fully developed for both media types. Reasonable use of technical terms.3-4
- Level 3 Sustained, well-structured discussion that applies compression concepts directly to both the images and the sound file, weighing up the trade-off between quality and loading speed/storage, and justifying suitable choices for the business owner. Accurate and consistent use of technical terminology throughout.5-6
- Indicative content:
- Product photos need to look attractive and detailed, so some quality is important; a high-quality lossy format (e.g. JPEG) is likely to give a good balance between quality and file size.
- Fully lossless images would give the best possible quality but produce much larger files, which could slow down page loading and put customers off.
- As long as the loss of quality from lossy compression is not very noticeable, using it on the product photos keeps file sizes down and pages loading quickly.
- The background music clip is short, loops repeatedly and does not need studio-quality sound, so a lossy audio format (e.g. MP3) with a lower bit rate/sample rate would be suitable.
- A smaller sound file also loads faster and uses less data, which particularly benefits customers browsing on mobile devices or slower connections.
- Overall the business owner should balance an acceptable level of quality against fast loading times, since slow-loading pages may cause customers to leave the site before making a purchase.
Question 12
- (a) i = 0: runLengths[0] = 4, symbols[0] = "W", output = "WWWW"B1
- (a) i = 1: runLengths[1] = 2, symbols[1] = "B", output = "WWWWBB"B1
- (a) i = 2: runLengths[2] = 3, symbols[2] = "W", output = "WWWWBBWWW"B1
- (a) all three rows fully consistent (correct index, run length and symbol values used throughout)B1
- (a) Answer: i=0: output="WWWW"; i=1: output="WWWWBB"; i=2: output="WWWWBBWWW"
- (b) WWWWBBWWW cao ft (from part a)B1
- (b) Answer: WWWWBBWWW
Question 13
- (a) repeatedly combine/merge the two nodes (symbols, or previously combined nodes) with the lowest frequencies into a new node (oe)B1
- (a) the new node's frequency is the sum of the two combined frequencies; this is repeated until only one node (the root) remains (oe)B1
- (a) starting from the root, a 0 or 1 is assigned to each branch to build the binary code for each character; characters that are fewer branches from the root (more frequent) end up with shorter codes (oe)B1
- (a) Answer: Repeatedly merge the two lowest-frequency nodes into a new node whose frequency is their sum, until one root node remains; then assign 0/1 to each branch from the root to generate each character's code, giving more frequent characters shorter codes.
- (b) recognises that 4 different characters need 2 bits each for a fixed-length code, since 22 = 4 (oe)M1
- (b) finds the total number of characters in the file: 8 + 5 + 3 + 2 = 18 (oe)M1
- (b) 36 (bits) caoA1
- (b) Answer: 36 bits
Question 14
- (a) identifies the correct code length for each character: E = 1 bit, T = 2 bits, A = 3 bits, O = 3 bits (oe)M1
- (a) multiplies each frequency by its code length and finds each product: 8x1=8, 5x2=10, 3x3=9, 2x3=6 (oe)M1
- (a) 33 (bits) caoA1
- (a) Answer: 33 bits
- (b) finds the bits saved: 36 - 33 = 3 (bits) (oe, ft from previous question and part a)M1
- (b) correct method for percentage: (3 / 36) x 100 (oe, ft)M1
- (b) awrt 8.3% cao ftA1
- (b) Answer: 3 bits saved; awrt 8.3% reduction in file size
Question 15
- (a) correct method: 640 x 480 x 16 (oe)M1
- (a) 4915200 (bits) caoA1
- (a) Answer: 4 915 200 bits
- (b) 9830400 (bits per second) cao ft (their part a x 2)B1
- (b) Answer: 9 830 400 bits per second
- (c) correct method: 8000 x 16 x 2 (oe)M1
- (c) 256000 (bits) caoA1
- (c) Answer: 256 000 bits per second
- (d) adds video and sound data rates together: (their part b) + (their part c) (oe, ft)M1
- (d) 10086400 (bits per second) cao ftA1
- (d) explains that compression reduces the bandwidth required, helping avoid congestion and delays on connections with limited available bandwidth (oe)B1
- (d) Answer: 10 086 400 bits per second; compression reduces the bandwidth required and helps avoid congestion and delays on connections with limited available bandwidth.
Mark your answers
Check answers without an account. Some answers can be checked automatically; use the mark scheme to mark the rest.