Skip to the page
Year 11 · Computer Science · Spring 2 – Summer 1 · Final revision and the exams

Red and amber points, pupil by pupil

Exam practicePresent ▶

What this lesson covers

1.3 Data storage and compression

Cambridge IGCSE Computer Science 0478 · Topic 1: Data representation · Paper 1

3.1 Computer architecture

Cambridge IGCSE Computer Science 0478 · Topic 3: Hardware · Paper 1

7.7 Trace tables

Cambridge IGCSE Computer Science 0478 · Topic 7: Algorithm design and problem-solving · Paper 2

You will learn to

  • Identify your red and amber syllabus points from your tracker.
  • Use the revision cycle on one point: study page, key terms, quiz, then a past-paper question.
  • Evaluate your progress: change a point's colour only after a full-mark answer.

Success criteria

  • I can list my three reddest points before the lesson starts.
  • I can write the key terms for a point from memory, then check them.
  • I can show a marked past-paper question for each point I worked on.
The syllabus points for these sections
  • Name the units of data from bit to EiB and convert between them using 1024.
  • Calculate the file size of an image and of a sound file, showing working.
  • Explain why files are compressed.
  • Compare lossy and lossless compression and give examples of each.
  • Use run-length encoding (RLE) and work out the space saved.
  • Describe the role of the CPU and what a microprocessor is.
  • Name the parts of the von Neumann architecture: ALU, CU, registers and buses.
  • Describe the fetch–decode–execute cycle, step by step.
  • Explain how cores, cache and clock speed affect performance.
  • Explain what an instruction set is.
  • Describe embedded systems and how they differ from general-purpose computers.
  • Explain what a dry run and a trace table are for.
  • Complete a trace table for an algorithm with a loop and selection.
  • Use a trace table to find the output and spot errors.

Key words

Say each word, then read what it means. Every one is in the glossary too.

Bit
A single binary digit, 0 or 1.
Nibble
A group of 4 bits, which matches one hexadecimal digit.
Byte
A group of 8 bits.
Binary
The base 2 number system computers use, with digits 0 and 1.
Character set
A list of characters a computer can use, each with its own binary code.
Sample rate
The number of sound samples taken each second, measured in hertz (Hz).
Sample resolution
The number of bits used to store each sound sample.
Pixel
The smallest single-coloured square in a bitmap image.
Image resolution
The number of pixels in an image, often written as width × height.
Colour depth
The number of bits used to store the colour of each pixel.
Lossy compression
Making a file smaller by permanently removing some data.
Lossless compression
Making a file smaller without losing any data, so the original can be rebuilt exactly.
Run-length encoding (RLE)
A lossless method that stores each run of repeated values as a count and the value.
CPU
The central processing unit, which processes instructions and data by fetching, decoding and executing them.
Microprocessor
A CPU made as an integrated circuit on a single chip.
Von Neumann architecture
A computer design where instructions and data are stored together in the same memory.
ALU
Arithmetic logic unit: does calculations and logical comparisons.
Control unit
Manages the fetch–decode–execute cycle and sends control signals.
Register
A tiny, very fast store inside the CPU that holds one item.
Bus
A set of parallel wires that carries addresses, data or control signals.
Cache
Small, very fast memory in or near the CPU that holds frequently used data and instructions.
Clock speed
The number of cycles the CPU does each second, measured in hertz.
Core
A complete processing unit; a multi-core CPU can process several instructions at once.
Instruction set
The list of all the instructions a particular CPU can carry out.
Embedded system
A computer system inside a larger device that does one dedicated job.
Sensor
An input device that measures a physical property and sends the reading to a computer.
NIC
Network interface card: the hardware that connects a device to a network.
MAC address
A unique 48-bit address given to a NIC at manufacture, written in hex.
IP address
An address given to a device on a network so data can be sent to it.
Algorithm
A precise, ordered set of steps that solves a problem.
Program development life cycle
The four stages of making a program: analysis, design, coding and testing.
Pseudocode
A structured, code-like way of writing an algorithm that is not tied to one language.
Counting
Adding 1 to a counter each time something happens.
Check digit
An extra digit calculated from the other digits, used to catch typing errors.
Trace table
A table used in a dry run to record the value of each variable as an algorithm runs.

The explanation

Read it here, or open the study page below to go one step at a time with things to try.

Start from your tracker

Your tracker lists every syllabus point with a colour. Work on red points first, then amber.

Green points only need a short quiz now and then.

?Why?

Why not revise what I already know?

It feels good, but it gains few marks. Marks come from closing gaps.

The revision cycle

  1. Read the study page for one point.
  2. Close it. Write the key terms and their meanings from memory.
  3. Open it again. Check and correct your terms in another colour.
  4. Do the quiz for that point.
  5. Do one past-paper question on it, timed.
  6. Mark it with the mark scheme.
  7. Change the colour on your tracker only if you got full marks.
e.g.Example

Red point 1.3, file sizes. Read the step. Write the image and sound formulas from memory. Do two calculations, then one past-paper question.

★Remember

Testing yourself works better than reading again. Rereading feels easy because the page is in front of you.

!Watch out

Copying out notes or making a neat poster is not revision. If you are not recalling, you are not revising.

1.3 Data storage and compression

Units of data

A bit is one 0 or 1. A nibble is 4 bits. A byte is 8 bits.

After the byte, each unit is 1024 times bigger than the one before.

1024 is used because it is a power of 2: 2¹⁰ = 1024. Computers count in powers of 2.

Try the toy: type 1 and choose GiB. Read the MiB and KiB rows in the table. How many times did you multiply by 1024 to reach KiB?

UnitEqual toIn bytes
1 nibble4 bitshalf a byte
1 byte (B)8 bits1
1 kibibyte (KiB)1024 bytes1,024
1 mebibyte (MiB)1024 KiB1,048,576
1 gibibyte (GiB)1024 MiB1,073,741,824
1 tebibyte (TiB)1024 GiBabout 1.1 million million
1 pebibyte (PiB)1024 TiB2⁵⁰
1 exbibyte (EiB)1024 PiB2⁶⁰
!Watch out

Cambridge uses 1024, not 1000. Shops often say KB, MB and GB meaning 1000. In the exam, always use 1024 and the KiB, MiB, GiB names.

There is something to try for this step in the IGCSE library.

Converting between units

Going to a smaller unit: multiply (× 1024, or × 8 from bytes to bits).

Going to a bigger unit: divide (÷ 1024, or ÷ 8 from bits to bytes).

Move one unit at a time and write each step. It is slower but it avoids mistakes.

e.g.Example
3 MiB in bytes: 3 × 1024 = 3072 KiB 3072 × 1024 = 3,145,728 bytes 65,536 bits in KiB: 65,536 ÷ 8 = 8192 bytes 8192 ÷ 1024 = 8 KiB 2 GiB in MiB: 2 × 1024 = 2048 MiB
?Why?

Paper 1 has no calculator. Exam numbers are usually chosen so that dividing by 8 and 1024 comes out neatly.

Calculating image file size

Every pixel needs the same number of bits: the colour depth.

So file size in bits = number of pixels × colour depth. Number of pixels = width × height.

Then divide by 8 for bytes, by 1024 for KiB, and by 1024 again for MiB.

Real files are a little bigger, because they also store extra data such as the width and height.

e.g.Example
An image is 1024 × 512 pixels with a colour depth of 16 bits. Find its size in MiB. Step 1, pixels: 1024 × 512 = 524,288 pixels Step 2, bits: 524,288 × 16 = 8,388,608 bits Step 3, bytes: 8,388,608 ÷ 8 = 1,048,576 bytes Step 4, KiB: 1,048,576 ÷ 1024 = 1024 KiB Step 5, MiB: 1024 ÷ 1024 = 1 MiB Tip: 16 bits = 2 bytes. So 524,288 × 2 = 1,048,576 bytes in one go.
!Watch out

Do not forget to divide by 8. Pixels × colour depth gives bits, not bytes.

Calculating sound file size

Each second you take (sample rate) samples. Each sample uses (sample resolution) bits.

So file size in bits = sample rate × sample resolution × length in seconds.

Then divide by 8 for bytes and by 1024 for KiB or MiB, as for images.

This is for one channel (mono). Change minutes into seconds first.

e.g.Example
A sound is recorded at 8000 Hz with a sample resolution of 16 bits. It lasts 32 seconds. Find its size in KiB. Step 1, bits per second: 8000 × 16 = 128,000 bits Step 2, total bits: 128,000 × 32 = 4,096,000 bits Step 3, bytes: 4,096,000 ÷ 8 = 512,000 bytes Step 4, KiB: 512,000 ÷ 1024 = 500 KiB CD quality for 1 minute: 44,100 × 16 × 60 = 42,336,000 bits = 5,292,000 bytes, about 5 MiB.
!Watch out

A length of 2 minutes is 120 seconds. Using 2 in the formula is a very common lost mark.

Why we compress files

Compression makes a file smaller, so it uses fewer bits.

Smaller files use less storage space on a device or server.

Smaller files need less bandwidth. Bandwidth is how much data a connection can carry each second.

So smaller files are sent faster: quicker downloads, quicker uploads, and less buffering when streaming.

Many services set a size limit. An email attachment limit of 25 MB is a real example.

e.g.Example
A 5 MiB song is compressed to about 0.5 MiB as an MP3. A phone can now store about ten times as many songs, and each one downloads ten times faster.
?Why?

Storage and network time both cost money and battery. Sending fewer bits saves both.

Lossy compression

Lossy compression removes data permanently. You can never get the original back.

It removes detail people are unlikely to notice, such as sounds humans cannot hear or tiny colour differences.

Ways to do it: lower the image resolution or colour depth, or lower the sample rate or sample resolution.

Examples: JPEG for photos, MP3 for music, and most video streaming.

It gives a much smaller file than lossless, but quality is lower.

e.g.Example
A school uploads 200 sports-day photos to its website. Each is 6 MiB from the camera. Saving them as JPEGs at a lower resolution makes each about 300 KiB. The page loads quickly on phones, and visitors cannot see the difference on screen.
!Watch out

Never use lossy compression on text, program code or spreadsheets. Losing even one character can change the meaning or stop a program working.

Lossless compression

Lossless compression makes the file smaller without losing any data.

When the file is decompressed, it is exactly the same as the original, bit for bit.

It finds patterns and repeats in the data and stores them in a shorter way.

Use it when every bit matters: text, program files, spreadsheets, medical scans.

The file is not made as small as with lossy compression.

LossyLossless
Data removed?Yes, permanentlyNo
Original restored?NoYes, exactly
File sizeMuch smallerSmaller, but less saving
ExamplesJPEG, MP3RLE, ZIP, PNG
Good forPhotos, music, videoText, code, spreadsheets

Run-length encoding (RLE)

Run-length encoding (RLE) is a lossless method. A run is a group of the same value in a row.

RLE stores each run as two values: how many, then which value.

It works well when data has long runs, such as simple images with big areas of one colour.

Try the toy: press All one colour, then press Stripes so every pixel is different from the next. Compare the sizes before and after RLE.

e.g.Example
Text: AAAAABBBCCCCCCCC Runs: 5 A, 3 B, 8 C RLE: 5A 3B 8C Original: 16 characters. Encoded: 6 characters. A row of pixels, W = white, B = black: WWWWWWWWBBBWWWWWWBBBBB RLE: 8 W, 3 B, 6 W, 5 B
?Why?

Writing "8 white" once takes less space than writing "white" eight times. Decoding gives the exact row back, so no data is lost.

There is something to try for this step in the IGCSE library.

RLE: working out the saving

To judge compression, compare the size before and after.

RLE only helps when runs are long. If values change all the time, RLE can make the file bigger.

That is why RLE suits simple graphics and icons, but not photographs.

e.g.Example
The pixel row WWWWWWWWBBBWWWWWWBBBBB, with 1 byte per pixel. Before: 22 pixels × 1 byte = 22 bytes After: 4 runs × 2 bytes (count + colour) = 8 bytes Saving: 22 − 8 = 14 bytes Percentage saved: 14 ÷ 22 × 100 = about 64% Now a row with no repeats: ABCD Before: 4 bytes RLE: 1A 1B 1C 1D = 8 bytes The file has doubled in size.
!Watch out

Do not say RLE always makes files smaller. With few repeats it can make them larger.

3.1 Computer architecture

The CPU and the microprocessor

The CPU (central processing unit) is the part of the computer that processes instructions and data. It carries out the instructions of every program.

It does this by fetching an instruction from memory, decoding it, then executing it. Then it repeats, billions of times a second.

A microprocessor is a CPU built as an integrated circuit on a single chip. An integrated circuit is a whole electronic circuit made on one small piece of silicon.

e.g.Example
The chip inside a laptop, a phone or a games console is a microprocessor. A microprocessor also sits inside a microwave oven, running its timer.

Von Neumann architecture

Most computers follow the von Neumann architecture. Its key idea is the stored program: instructions and data are both stored in the same main memory.

The CPU has a control unit (CU). The CU manages the fetch–decode–execute cycle. It decodes instructions and sends control signals to the other parts.

The CPU has an arithmetic logic unit (ALU). The ALU does calculations (such as add and subtract) and logic operations (such as comparing two numbers).

The CPU also has registers: very small, very fast stores inside the CPU. The CPU is joined to memory by three buses (sets of wires).

?Why?

Keeping instructions and data in one memory means the computer can run any program you load. Change the program in memory and the same hardware does a new job.

There is a diagram for this step in the IGCSE library.

The five registers

A register holds one item at a time: an address, an instruction or a piece of data.

An address is the number of a location in memory, like a locker number in a school corridor.

RegisterFull nameWhat it holds
PCProgram counterThe address of the next instruction to be fetched
MARMemory address registerThe address of the memory location about to be read from or written to
MDRMemory data registerThe data or instruction that has been fetched from memory, or about to be written to memory
CIRCurrent instruction registerThe instruction that is being decoded and executed right now
ACCAccumulatorThe result of calculations done by the ALU
!Watch out

PC and MAR hold addresses. MDR and CIR hold instructions or data. Mixing these up is the most common error in FDE answers.

The three buses

The address bus carries addresses from the CPU (the MAR) to memory. It is one-way (unidirectional), because only the CPU chooses addresses.

The data bus carries data and instructions between the CPU (the MDR) and memory. It is two-way (bidirectional), because data is both read and written.

The control bus carries control signals from the control unit, such as 'read', 'write' and the clock signal. It is two-way, because devices also send signals back.

!Watch out

Exam answers often say 'the address bus carries data'. It carries addresses only. Data and instructions travel on the data bus.

The fetch–decode–execute cycle

Every instruction goes through the same three stages. Learn the fetch stage in order: it is worth most marks.

Fetch: the address in the PC is copied to the MAR, using the address bus. The PC is incremented (1 is added), so it points to the next instruction. The instruction at that address is sent along the data bus to the MDR. It is then copied from the MDR to the CIR.

Decode: the control unit decodes the instruction in the CIR. It works out what the instruction means and what needs to happen.

Execute: the instruction is carried out. The control unit sends signals on the control bus. If there is a calculation, the ALU does it and the result goes in the ACC. Then the cycle starts again.

e.g.Example
PC = 100. The instruction at address 100 is LOAD 105 (put the value at address 105 into the ACC). Fetch: 100 is copied from PC to MAR → PC becomes 101 → LOAD 105 travels from address 100 to the MDR → copied to the CIR. Decode: the CU sees 'load the value at address 105'. Execute: 105 goes into the MAR → the value at 105 (say 7) comes back on the data bus to the MDR → it is copied to the ACC. ACC = 7. Try it in the toy: its tiny program starts at address 0 (LOAD 5, ADD 6, STORE 7, HALT). Press Step and watch each register change. Notice when the PC goes up by 1.
?Why?

The PC is incremented during fetch, so the CPU always knows where the next instruction is, even while it is busy with the current one.

There is something to try for this step in the IGCSE library.

The instruction set

An instruction set is the list of all the instructions (commands) that a particular CPU can understand and carry out.

Each instruction is a binary code, called machine code. Examples are load, add, store, compare and jump.

The CU decodes instructions using this set. Different CPU families have different instruction sets.

e.g.Example
Most laptops use x86 processors. Most phones use ARM processors. A program compiled for one will not run directly on the other, because their instruction sets are different.

Cores, cache and clock speed

Clock speed is the number of fetch–decode–execute cycles the CPU can do per second, measured in hertz (Hz). A 3.5 GHz CPU has 3,500,000,000 clock ticks per second. Higher clock speed means more instructions per second.

Cache is a small amount of very fast memory inside or next to the CPU. It stores instructions and data that are used often, so the CPU does not have to wait for slower RAM. More cache means fewer slow trips to RAM.

A core is a complete processing unit (with its own ALU, CU and registers). A quad-core CPU has four cores, so it can process four instructions at the same time.

?Why?

All three let the CPU get through more instructions in a given time. That is what 'better performance' means.

!Watch out

Doubling the cores does not double the speed. Cores must communicate with each other, and some programs cannot be split into parts. Raising clock speed also makes the CPU hotter, and cache is expensive, so there are limits.

Embedded systems

An embedded system is a small computer system built inside a larger device, to do one dedicated job.

It uses a microprocessor (or a microcontroller) and usually runs one fixed program stored in ROM.

A general-purpose computer, like a laptop, can run many different programs and do many jobs.

Embedded system examplesWhat it controls
Washing machineWater level, temperature, drum speed for each wash programme
Microwave ovenTimer and power level
Central heatingTurns the boiler on and off using a temperature sensor
Car engine managementFuel and air mix, using many sensors
Traffic lightsThe light sequence and timing
?Why?

Embedded systems are small, cheap to mass-produce and use very little power, because they only do one job. The drawbacks: they are hard to update or change, and they can only do the task they were built for.

7.7 Trace tables

What a trace table is

A dry run means working through an algorithm by hand, line by line, without a computer.

A trace table records the dry run. It has one column for each variable, and one for the output.

Write a new value in a column only when that variable changes. Move to a new row when the loop goes round again.

?Why?

A dry run lets you check an algorithm before it is coded. It also shows exactly where a logic error happens.

!Watch out

Do not fill every cell. Cambridge mark schemes usually want a value only where it changes. Copying values down is not wrong but takes time and causes mistakes.

Worked dry run

This algorithm reads numbers until the user types -1. A value that only means 'stop' is called a rogue value.

Input data: 12, 7, 20, 9, -1. Follow each row of the table below and check you agree.

Then use the toy. Pick Counting (WHILE), a similar rogue-value loop, and press Step to run it one line at a time.

ValueTotalCountHighestOUTPUT
000
1212112
7192
2039320
9484
-112 20
e.g.Example
Row 1: the three variables start at 0. Value 12: Total 0 + 12 = 12, Count 1. 12 > 0, so Highest = 12. Value 7: Total 19, Count 2. 7 > 12 is false, so Highest stays 12. Value 20: Total 39, Count 3. 20 > 12, so Highest = 20. Value 9: Total 48, Count 4. 9 > 20 is false. Value -1: the WHILE condition is false, so the loop ends. Output: 48 / 4 = 12, then 20.
DECLARE Value : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Highest : INTEGER
Total ← 0
Count ← 0
Highest ← 0
INPUT Value
WHILE Value <> -1 DO
  Total ← Total + Value
  Count ← Count + 1
  IF Value > Highest
    THEN
      Highest ← Value
  ENDIF
  INPUT Value
ENDWHILE
OUTPUT Total / Count, " ", Highest
total = 0
count = 0
highest = 0
value = int(input())
while value != -1:
    total = total + value
    count = count + 1
    if value > highest:
        highest = value
    value = int(input())
print(total / count, highest)
!Watch out

The rogue value -1 is not added to the total. The loop checks the value before using it. That is why there is an `INPUT` before the loop and another at the end of it.

There is something to try for this step in the IGCSE library.

Study it

Open the study page and go one step at a time.

Check yourself

One question at a time. The reason shows after each answer.

Saved on this device.