GRADE 9 · A4 PRINT VIEW
The World of Algorithms · Learner pages
Use your browser Print command and select A4. Questions and answers have separate pages.
Lesson 1 · What makes an algorithm
Describe an algorithm as precise steps from input to output, and trace one with decisions and repeats.
Name or initials: Date:

You already follow fixed methods by hand, such as column addition or long division, which give the same answer whoever uses them.
A recipe for a task
An algorithm takes an input, follows a list of steps and gives an output. Long division is one: input two numbers, output a quotient and a remainder.
Each step must be exact
'Add a little' is vague, but 'add 5' is exact. With exact steps, anyone who follows the algorithm on the same input gets the same output, and it must stop after finitely many steps.
Decisions and repeats
Steps can choose (IF the number is even THEN halve it) or repeat (REPEAT for each value in the list). To find the largest value: keep a 'best so far', compare each new value with it, and keep the larger.
Trace and check
Trace the largest-value algorithm on 14, 9, 23, 8. Best so far: 14, still 14, then 23, still 23. The list ends, so the output is 23, which is correct.
Worked example: Algorithm for the sum of the digits of 4,728. Step 1: total = 0. Step 2: add the last digit to the total and remove it from the number. Step 3: repeat Step 2 until the number is 0. Trace: 8; 8 + 2 = 10; 10 + 7 = 17; 17 + 4 = 21. Output: 21.
PracticeChoose the correct answer and show your working in the space.
Which property must every algorithm have?
○ It must finish after a finite number of steps○ It must run on a computer○ It must have exactly ten steps
Start with 5. Repeat three times: double the number, then subtract 1. What is the output?
○ 17○ 33○ 27
The largest-value algorithm runs on 14, 9, 23, 8, 23, 17. After the first value, how many times does 'best so far' change?
○ 2○ 3○ 1
Discuss: Write an algorithm a friend could follow to find the smallest mark in a list. Swap algorithms, trace each other's on the same list, and check whether both give the right answer.
Lesson 2 · Euclid's algorithm for the HCF
Use repeated division with remainder to find the highest common factor of two numbers.
Name or initials: Date:
The highest common factor (HCF) of two numbers is the largest number that divides both; the HCF of 12 and 18 is 6.
Division with remainder
For whole numbers a and b > 0 we can always write a = bq + r with 0 ≤ r < b. For example, 85 = 12 × 7 + 1.
Common factors carry over
Any number that divides both a and b also divides r = a − bq, and the other way round. So the pair (b, r) has the same HCF as (a, b), with smaller numbers.
Repeat until the remainder is 0
HCF(252, 105): 252 = 105 × 2 + 42; 105 = 42 × 2 + 21; 42 = 21 × 2 + 0. The last divisor, 21, is the HCF.
Check the answer
252 = 21 × 12 and 105 = 21 × 5. Since 12 and 5 have no common factor other than 1, no number larger than 21 divides both.
Worked example: Ribbons of 96 cm and 60 cm are cut into equal pieces, as long as possible, with nothing left over. 96 = 60 × 1 + 36; 60 = 36 × 1 + 24; 36 = 24 × 1 + 12; 24 = 12 × 2 + 0. Each piece is 12 cm: 8 pieces from the first ribbon and 5 from the second.
PracticeChoose the correct answer and show your working in the space.
Write 85 in the form 12q + r with 0 ≤ r < 12.
○ 85 = 12 × 7 + 1○ 85 = 12 × 6 + 13○ 85 = 12 × 8 − 11
Use Euclid's algorithm to find the HCF of 84 and 36.
○ 6○ 12○ 4
Use Euclid's algorithm to find the HCF of 391 and 299.
○ 13○ 17○ 23
Discuss: Count the divisions Euclid's algorithm needs for HCF(89, 55) and for HCF(100, 50). Suggest what kind of number pair makes the algorithm take many steps.
Lesson 3 · Improving and analysing an algorithm
Count the steps an algorithm takes, cut out wasted work, and compare the subtraction and division forms of Euclid's gcd algorithm.
Name or initials: Date:

Euclid's algorithm replaces a pair of numbers by a smaller pair with the same HCF and stops when the remainder is 0.
Count the checks
A simple gcd method tests every number from 1 upwards to see if it divides both numbers. For gcd(84, 120), testing every number up to 120 means 120 checks.
Cut wasted work
A common divisor can never be larger than the smaller number, so stop at 84: 84 checks, same answer. But the work still grows with the size of the numbers: a smaller number ten times as big needs about ten times the checks.
Euclid by subtraction
For m ≥ n, gcd(m, n) = gcd(n, m − n). 120 − 84 = 36, 84 − 36 = 48, 48 − 36 = 12, 36 − 12 = 24, 24 − 12 = 12, 12 − 12 = 0. Six subtractions reach the pair (12, 0), so the gcd is 12.
Euclid by division, compared
120 = 84 × 1 + 36, 84 = 36 × 2 + 12, 36 = 12 × 3 + 0: only 3 divisions. One division does a whole run of subtractions at once. Check: both forms give 12, and 120 = 12 × 10, 84 = 12 × 7.
Worked example: gcd(1,000, 3) by subtraction: taking away 3 again and again, 333 subtractions bring 1,000 down to 1; then 3 − 1 = 2, 2 − 1 = 1 and 1 − 1 = 0 take 3 more, so 336 subtractions in all. By division: 1,000 = 3 × 333 + 1 and 3 = 1 × 3 + 0, only 2 divisions. Both give gcd 1.
PracticeChoose the correct answer and show your working in the space.
A gcd method checks every number from 1 up to the smaller of the two numbers. How many checks does it make for gcd(45, 75)?
○ 75○ 45○ 120
One step of Euclid's subtraction form is applied to the pair (50, 15). Which pair comes next?
○ (65, 15)○ (50, 35)○ (35, 15)
How many divisions does Euclid's division form need for gcd(91, 35)?
○ 4○ 6○ 7
Discuss: Choose two pairs of 3-digit numbers: one pair close together and one where one number is much larger. Count the subtractions and the divisions Euclid's algorithm needs for each pair, and discuss when the subtraction form is slow.
Final check · form A
Final checkWork on your own. Choose one answer for each question.
An algorithm says: input n; if n is even, halve it; otherwise multiply it by 3 and add 1. What is the output for n = 7?
○ 22○ 3.5○ 21
Which instruction is too vague to be a step in an algorithm?
○ Add 7 to the number○ Stir until it looks nice○ If the number is greater than 10, stop
Use Euclid's algorithm to find the HCF of 126 and 45.
○ 3○ 18○ 9
When does Euclid's algorithm stop?
○ When the remainder is 0○ When the quotient is 1○ After exactly three divisions
Euclid's subtraction form on (40, 16): 40 − 16 = 24, 24 − 16 = 8, 16 − 8 = 8, 8 − 8 = 0. What is the gcd, and how many subtractions were used?
○ gcd 16, 4 subtractions○ gcd 8, 4 subtractions○ gcd 8, 2 subtractions
Why can a simple gcd method stop checking at the smaller of the two numbers?
○ Larger numbers never divide anything○ A common divisor cannot be larger than the smaller number○ The gcd is always the smaller number
Final check · form B
Final checkWork on your own. Choose one answer for each question.
An algorithm sets total = 0, adds each of 4, 8 and 9 to the total, then outputs total ÷ 3. What does it find?
○ The mean, 7○ The total, 21○ The largest value, 9
Start with x = 5. Repeat 'x = x × 2' until x > 50. What is the final value of x?
○ 40○ 50○ 80
Use Euclid's algorithm to find the HCF of 60 and 25.
○ 5○ 10○ 15
A floor is 168 cm by 120 cm. What is the largest square tile that covers it exactly with no cutting?
○ 12 cm○ 24 cm○ 48 cm
One division in Euclid's algorithm, 100 = 7 × 14 + 2, does the work of how many subtractions of 7?
○ 2○ 7○ 14
Which method needs the fewest steps for gcd(600, 5)?
○ Euclid's division form: 1 division○ Euclid's subtraction form: 120 subtractions○ Checking every number from 1 to 5: 5 checks
Original learning companion for selected outcomes of this chapter: what makes a procedure an algorithm (precise steps, decisions and repeats), Euclid's division algorithm for the HCF, and improving and analysing an algorithm by counting its steps and comparing the subtraction and division forms of Euclid's algorithm. It does not reproduce the textbook, its activities or its exercise solutions.