Objectives: Students should be able to —
- 1 Explain the processes involved in an algorithm.
- 2 Explain the purpose of an algorithm.
Reading Algorithms & Explaining Their Purpose
Flowchart Algorithm (Q1):
(a) Trace table for test data 9, 7, 3, 12, 6, 4, 15, 2, 8, 5:
| A | B | C | X | Output |
|---|---|---|---|---|
| 0 | 0 | 100 | — | — |
| 1 | 9 | — | 9 | — |
| 2 | — | 7 | 7 | — |
| 3 | — | 3 | 3 | — |
| 4 | 12 | — | 12 | — |
| 5 | — | — | 6 | — |
| 6 | — | — | 4 | — |
| 7 | 15 | — | 15 | — |
| 8 | — | 2 | 2 | — |
| 9 | — | — | 8 | — |
| 10 | — | — | 5 | — |
| — | — | — | — | 15 2 |
(Only changed values are recorded in each row — blanks mean the variable keeps its previous value.)
(b) Purpose of the algorithm:
The algorithm selects and outputs the Largest and the Smallest numbers from a list of 10 positive numbers.
(c) Rewrite the algorithm using pseudocode:
Flowchart Algorithm (Q2):

(a) Identify the process in the algorithm:
- Ask to input the number of guesses the user wants to make.
- Ask to enter the guessed word and store it in the variable
G. - If the guessed word
Gis equal to the wordW, then output a congratulatory message for the user's success. - If they don't match, then subtract the number of guesses by 1 and ask to guess again, until the number of guesses becomes 0.
- If the number of guesses becomes 0, then output a failure message.
(b) Purpose of the algorithm:
To find out whether the user can guess the word within the number of guesses he/she believes he/she can.
Pseudocode Algorithm (Q3):
(a) Trace table for test data 78, 34, 22, -4, 98, 16, 734, 88, 999:
| W | X | Y | Z | Mark | Output |
|---|---|---|---|---|---|
| 0 | 0 | 100 | 0 | 78 | — |
| 1 | 78 | 78 | 78 | — | — |
| 2 | — | 34 | 112 | 34 | — |
| 3 | — | 22 | 134 | 22 | — |
| — | — | — | — | -4 | — (rejected, re-input) |
| 4 | 98 | — | 232 | 98 | — |
| 5 | — | 16 | 248 | 16 | — |
| — | — | — | — | 734 | — (rejected, re-input) |
| 6 | — | — | 336 | 88 | — |
| — | — | — | — | 999 | 98 16 336 |
(b) Purpose of the algorithm:
- Accept only the integer within the range between 0 and 100 (inclusive).
- Find the maximum and minimum value; calculate the running total sum of values within the range of 0 and 100.
- Output the maximum, minimum and running total sum of the values within the range.
(c) Rewrite the algorithm as a flowchart:
Pseudocode Algorithm (Q4):
(a) Trace table for the two input values:
(i) Input = 37
| X | T1 | T2 | Output |
|---|---|---|---|
| 37 | — | — | — |
| — | 2 | 5 | 5 |
| 2 | — | — | 2 |
| — | — | — | — |
Output read in order: 5 then 2 → reading right-to-left = 25₁₆ = 37₁₀ ✓
(ii) Input = 191
| X | T1 | T2 | Output |
|---|---|---|---|
| 191 | — | — | — |
| — | 11 | 15 | F |
| 11 | — | — | B |
| — | — | — | — |
Output read in order: F then B → reading right-to-left = BF₁₆ = 191₁₀ ✓
(b) Purpose of the algorithm:
- Convert a denary number into hexadecimal.
- Output each digit of the hexadecimal number from right to left (i.e. least-significant digit first).
Flowchart Algorithm (Q5):

(a) Trace table for input data 5,4,6,2,1, 9,3,2,1,6, 7,6,1,5,1, 0,0,0,0,0:
| V | W | X | Y | Z | A | B | Output |
|---|---|---|---|---|---|---|---|
| 5 | 4 | 6 | 2 | 1 | 56 | 1 | Valid |
| 9 | 3 | 2 | 1 | 6 | 40 | 7 | Invalid |
| 7 | 6 | 1 | 5 | 1 | 61 | 6 | Invalid |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | Valid |
| — | — | — | — | — | — | — | — |
Worked example (Row 1): V=5, W=4, X=6, Y=2 → A = 2(5) + 3(4) + 4(6) + 5(2) = 10 + 12 + 24 + 10 = 56; B = 56 MOD 11 = 1; Z = 1 → B = Z → Valid.
(b) Purpose of this flowchart:
- Calculate the check-digit for the first four input digits (V, W, X, Y).
- Compare the check-digit with the fifth input digit (Z).
- If the check-digit is equal to the fifth input digit, then output the message "Valid"; else output the message "Invalid".
Revision: Key Computing Terms
| Statement | Key Term |
|---|---|
| A diagram or sequence of steps that solves a problem — used to identify the processes that an algorithm performs. | Algorithm |
| The series of steps / actions an algorithm carries out on its input data (e.g. assignment, selection, iteration, input, output). | Process |
| What an algorithm is designed to achieve — the problem it solves or the result it produces. | Purpose |
| A table used to record the values of all variables after each step of an algorithm, to test its correctness. | Trace Table |
| The process of manually following an algorithm step-by-step, recording variable values in a trace table to verify its logic. | Dry Run |
| A set of values used as input to test whether an algorithm produces the expected output. | Test Data |
A predefined function that performs integer division, giving the quotient (e.g. 10 DIV 3 = 3). | DIV |
A predefined function that performs integer division, giving the remainder (e.g. 10 MOD 3 = 1). | MOD |
A digit calculated from a number's other digits (using a formula such as A MOD 11) and used to verify the number's integrity. | Check Digit |
A technique that rejects inputs outside an expected range (e.g. < 0 or > 100) and asks for re-input. | Range Check / Validation |
| A base-16 number system using digits 0–9 and letters A–F (where A=10, B=11, C=12, D=13, E=14, F=15). | Hexadecimal |
| A base-10 number system using digits 0–9 — also called decimal. | Denary |