HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A student must compress two files. File A is a text file holding the 7 characters ABCDEFG, one byte…
HardComputer ScienceHigh School (9–10)Computer Science › Data RepresentationNumericalConceptualIGCSE

A student must compress two files. File A is a text file holding the 7 characters ABCDEFG, one byte…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A student must compress two files.

  • File A is a text file holding the 7 characters ABCDEFG, one byte each.
  • File B is a photo of 1024 by 1024 pixels with a colour depth of 24 bits.
  1. How many bytes would run-length encoding need for file A, with a count byte and a character byte for each run? Should RLE be used?
  1. File B is compressed by halving its width and its height. What fraction of the original size is left? Give a decimal.
  1. Is the method in (b) lossy or lossless?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Compression reduces file size: less storage, less bandwidth and a shorter transmission time. Lossy compression removes data for good (lower resolution or colour depth, lower sample rate or resolution). Lossless compression loses nothing; run-length encoding stores each run of repeated values as a count and a value.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. File A. There are 7 runs of length 1: (1, A), (1, B) and so on. That is 7×2=147 \times 2 = 147×2=14 bytes, twice the original 7 bytes. RLE makes this file bigger, so it should not be used.

Step 2. File B. The new photo is 512 by 512 pixels. 512×5121024×1024=0.25\dfrac{512 \times 512}{1024 \times 1024} = 0.251024×1024512×512​=0.25 of the pixels, and so 0.25 of the size.

Step 3. Lossy or lossless. Lossy: three quarters of the pixels are removed for good, so the original detail cannot be rebuilt.

Check. The original is 1024×1024×3=31457281024 \times 1024 \times 3 = 31457281024×1024×3=3145728 bytes, which is 3 MiB. The new one is 512×512×3=786432512 \times 512 \times 3 = 786432512×512×3=786432 bytes, which is 0.75 MiB, a quarter of 3 MiB.

Answer: (a) 14 bytes; no, it doubles the size. (b) 0.25. (c) Lossy.

Log in to save this for later
← All Problems
← A line of an icon is stored with run-length encoding as these pairs of (count, colour code): (5…Amara emails a school report of 7300 bytes… →
More onComputer Science › Data Representation

Discussion (0)

Log in to join the discussion.

Loading…

More on this topic

  1. A line of an icon is stored with run-length encoding as these pairs of (count, colour code): (5…Medium
  2. One row of a scanned page is 13 pixels: 6 white, then 3 black, then 4 white…Easy
  3. An image is 800 pixels wide and 600 pixels high…Hard
  4. A camera takes photos of 2048 by 1536 pixels with a colour depth of 24 bits…Medium
  5. A music app records 2 minutes of sound at 8192 samples a second, with a sample resolution of 16…Medium
All problems on this topic →