← IGCSE Computer Science Paper 2

Working out the purpose from a trace

Running an algorithm by hand with test values, then comparing the inputs with the final outputs to work out its purpose, such as totalling, counting or finding the largest.

Understanding Working out the purpose from a trace in IGCSE Computer Science Paper 2

What it does: Count goes up by 1 each time, not by the value itself, so tracing shows it counts items that meet the condition. Running test values shows Found becomes TRUE only when an item equals the target, so the purpose is a search. 4 + 7 + 2 = 13, so the output is the sum of the inputs. The largest input would be 7. Both outputs are the biggest number entered. The totals would be 17 and 26. One result can fit several purposes. Extra tests with different inputs show which purpose is really correct. 12, 15 and 20 are over 10, so the count is 3. The total of those would be 47.

Common mistakes: Each input is stored in Total instead of Number, so the old total is overwritten. With inputs 2, 4, 6 a dry run does not give 12. It should be INPUT Number so the algorithm totals the values. Mark is never read in, so there is no test value to trace. It should be INPUT Mark. With a mark of 60 the count goes 0 to 1, which shows the algorithm counts passes.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 216–231) and word search (Modules 188–231).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
An algorithm is dry run with the inputs 4, 7 and 2. It outputs 13. What is its most likely purpose?
Finding the largest numberTotalling the numbers
Matches
Inputs 3, 5, 8 give Total = 16, so it counts the values
↓
The output 16 is the sum of the inputs, not how many there were (3), so the purpose is totalling, not counting
Applying
Meanings
Term
dry run
Meaning
Running an algorithm by hand with test values, then comparing the inputs with the final outputs to work out its purpose, such as totalling, counting or finding the largest.
Practice
// Test 4, 9, 2 gives 9: finds the largest
Testing
Gaps
Total ← Total Number
Check Answer
Spots
2FOR Count ← 1 TO 3
3 INPUT Total

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Peregrine Falcon' badge — Operator Ace, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. An algorithm is dry run with the inputs 4, 7 and 2. It outputs 13. What is its most likely purpose?
A. Finding the largest number
B. Totalling the numbers ✓
4 + 7 + 2 = 13, so the output is the sum of the inputs. The largest input would be 7.
2. Test 1: inputs 5, 9, 3 give output 9. Test 2: inputs 12, 6, 8 give output 12. What does the algorithm do?
A. Finds the largest input ✓
B. Totals the inputs
Both outputs are the biggest number entered. The totals would be 17 and 26.
3. Why should you try two or three different sets of test values in a dry run?
A. More than one test helps rule out other possible purposes ✓
B. One test always proves the purpose
One result can fit several purposes. Extra tests with different inputs show which purpose is really correct.
4. Inputs 12, 3, 15, 8, 20 give the output 3. Which purpose fits best?
A. Counting how many inputs are greater than 10 ✓
B. Totalling the inputs that are greater than 10
12, 15 and 20 are over 10, so the count is 3. The total of those would be 47.
5. Which is the better statement of an algorithm's purpose?
A. Sets Total to 0 and adds Num to Total in a loop
B. Reads 5 numbers and outputs their total ✓
The purpose says what the algorithm achieves, from inputs to output. The other option only describes the steps in the code.

Match the Pairs

Inputs 4, 7, 2 give Total = 13 → The output is the sum of the inputs, so the purpose is totalling
Inputs 4, 7, 2 give Max = 7 → The output is the biggest input, so the purpose is finding the largest
A counting algorithm adds 1 to a counter only when a condition is true, so the output is how many values passed → IF Mark >= 50 THEN Count ← Count + 1
A search algorithm compares each item with the target and outputs whether it was found → IF Item[Index] = Target THEN Found ← TRUE
Inputs 3, 5, 8 give Total = 16, so it counts the values → The output 16 is the sum of the inputs, not how many there were (3), so the purpose is totalling, not counting
One test of 2, 9, 5 gives 9, so it must find the largest → One set of test values is not enough as 9 could also be the middle value or the last input checked, so try two or three different inputs

Key Term

dry run
Running an algorithm by hand with test values, then comparing the inputs with the final outputs to work out its purpose, such as totalling, counting or finding the largest.

Fill in the Blanks

1. Total ← 0 Total ← Total + Number OUTPUT Total // inputs 4, 6 output 10
Hint: Type the arithmetic operator that adds each input onto the running total.
2. IF Mark > 50 THEN Count ← Count + 1 ENDIF
Hint: Type the variable that keeps track of how many marks pass the test.
3. IF Number > Largest THEN Largest ← Number ENDIF
Hint: Type the variable holding the new input that replaces the current largest.
4. IF Names[Index] = Target THEN Found ← TRUE ENDIF
Hint: Type the Boolean value that records the search item was found.
5. FOR Count ← 1 TO 3 Total ← Total + Count NEXT Count
Hint: Type the keyword that closes the FOR loop so the trace can repeat.

Spot the Error

Question 1
A Total ← 0
B FOR Count ← 1 TO 3
C INPUT Total
D Total ← Total + Number
E NEXT Count
F OUTPUT Total
Line C — Each input is stored in Total instead of Number, so the old total is overwritten. With inputs 2, 4, 6 a dry run does not give 12. It should be INPUT Number so the algorithm totals the values.
Question 2
A Count ← 0
B OUTPUT Mark
C IF Mark >= 50 THEN
D Count ← Count + 1
E ENDIF
F OUTPUT Count
Line B — Mark is never read in, so there is no test value to trace. It should be INPUT Mark. With a mark of 60 the count goes 0 to 1, which shows the algorithm counts passes.
Question 3
A Largest ← 100
B INPUT Number
C IF Number > Largest THEN
D Largest ← Number
E ENDIF
F OUTPUT Largest
Line A — Starting at 100 means no small test value can ever beat it. Input 8 still outputs 100, so the trace does not show a largest-value algorithm. Largest should start at 0.
Question 4
A INPUT Target
B FOR I ← 1 TO 5
C IF List[I] > Target THEN
D OUTPUT "Found"
E ENDIF
F NEXT I
Line C — The test uses > so it reports any value bigger than Target, not a match. A dry run with Target 7 would print Found for the wrong items, so the purpose is not a search. It should be IF List[I] = Target THEN.
Question 5
A Count ← 0
B REPEAT
C INPUT Number
D Count ← Count + Number
E UNTIL Number = -1
F OUTPUT Count
Line D — This adds the value typed in instead of 1, so it totals the numbers instead of counting them. Inputs 3, 5, -1 would give 7, not 3. It should be Count ← Count + 1.

Student with a class code? Join your class →