- Level 8
- Number and Algebra
- Patterns and algebra
- Use algorithms and related testing procedures to identify and correct errors

Patterns and algebra • Level 8
Use algorithms and related testing procedures to identify and correct errors
VCMNA282
Teaching Context
Show More
At this level, students build on their knowledge of using algorithms to be able to test pseudo-codes and identify and correct any errors. Errors made in programming are referred to as ‘bugs’ and they stop the code from putting out the desired output. An important part of using algorithms and computer programming is testing your code and correcting the errors (referred to as debugging).
To ‘debug’ programs students identify where the code is not working. They revisit the code step by step, thinking about what each instruction is requiring and record the output from each step. This process should allow students to see which step/s in the code need to be corrected.
E.g. This algorithm is used to find the multiples of 5.
START
SET m = 5
While m <= 60
OUTPUT m m
= m + 4
END WHILE
END
Go through each line of the code and think about what each instruction means.
1. Assign the initial value m to 5
2. While m is less than or equal to 60, repeat the next two steps
3. Write down the value of m
4. m = m + 4
5. Stop when m is greater than 60.
Identify where the code needs to be rewritten. Step 4: To find multiples we need to add 5 Therefore, Step 4 should be: m = m+5
Check the new output with the errors debugged. Output = 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
The error has been debugged as the output now shows the multiples of 5. It is recommended that if there are multiple errors they are debugged one at a time, so students can see how each attempt to ‘debug’ the code is affecting the output.
Students are also introduced to using algorithms as a method to search and sort. An example of ‘searching and sorting’ is using algorithms to test numbers for divisibility.
E.g. Define a rule that identifies whether a number is divisible by 2. A number is divisible by 2 if it is an even number.
Using the divisibility test identify which numbers in the list are divisible by 2.
34 55 67 22 18 105 72
Victorian Curriculum
Use algorithms and related testing procedures to identify and correct errors (VCMNA282)
VCAA Sample Program: A set of sample programs covering the Victorian Curriculum Mathematics.
VCAA Mathematics glossary: A glossary compiled from subject-specific terminology found within the content descriptions of the Victorian Curriculum Mathematics.
Achievement standards
Students use efficient mental and written strategies to make estimates and carry out the four operations with integers, and apply the index laws to whole numbers. They identify and describe rational and irrational numbers in context.
Students estimate answers and solve everyday problems involving profit and loss rates, ratios and percentages, with and without the use of digital technology. They simplify a variety of algebraic expressions and connect expansion and factorisation of linear expressions.
Students solve linear equations and graph linear relationships on the Cartesian plane.
Online Resources
Teaching ideas
Developing divisibility tests
Tab Content
This activity introduces students to search and sort algorithms. They will develop algorithms to test the number for divisibility and apply the algorithm to search and sort numbers that can be divided.
Advise the class that they will be developing divisibility tests for numbers 2-10. Ask the class what a divisibility test is and whether they can identify some of them.
(Students may identify the simpler tests such as dividing by 10, 5 or 2).
Ask students to pair up. Their task is to determine divisibility tests for numbers 2-10. These tests (algorithms) will then be used to determine what a number is divisible by.
Note: students may become stuck at finding a divisibility test for 7. You may like to set it as a challenge for a pair to solve by the end of the lesson or allow students to research it on the internet.
The second part of their next task is to write a four-digit number (or larger) that applies to each of their 9 algorithms they have just developed. They should justify why each four-digit number selected meets the criteria for each divisibility test.
E.g. 4540 is divisible by 4 as the last two digits (40) are divisible by 4
7104 is divisible by 8 as the last three digits (104) are divisible by 8
Discuss with students:
- Which divisibility tests were more challenging to determine? Why?
- How did you go about testing your ideas for different divisibility tests?
- How did you know when you had a correct algorithm?
Test it out: Problem-solving
Tab Content
This problem-solving task is intended once students have been introduced to divisibility tests and have determined algorithms to test divisibility.
Pose both questions to students. This could be used as a starter for a lesson or as a revision for divisibility tests.
- How many numbers can be divided into 2160? What are the numbers? Show justifications for each number selected using the algorithms for divisibility.
- What is the smallest number that can be divided by all the numbers from 1 to 10?
Find the bug and rewrite the code
Tab Content
This activity is designed to show students where a code will fail and how they can modify the code to correct the error.
Ask students how they solve problems:
- How do you fix something that isn’t working?
- Do you follow a series of steps to try and find the problem?
Your task today is to fix some puzzles and codes that have already been done.
Each of the puzzles and codes has a ‘bug’ in it and it’s your job to debug them so they work properly.
Part 1: The dog wants to get to the bone. Fix the codes in both puzzles so the dog can reach the bone. The dog can move up, down, forward and backward.
Identify where the error/s are and use the minimum number of ‘coding
lines’ required to fix the problem. You may use loops (repeat a step)
if necessary.
PUZZLE 1
- START
- MOVE FORWARD
- MOVE DOWN
- MOVE DOWN
- MOVE FORWARD
The error is in the third line. The possibilities to fix the code are:
START
MOVE FORWARD
MOVE DOWN
MOVE FORWARD
END
PUZZLE 2
- START
- MOVE UP
- REPEAT TWICE
- MOVE FORWARD
- REPEAT ONCE
- MOVE DOWN
- END
The last line (move down) is incorrect. The possibilities to fix the code are:
START START
REPEAT 3 TIMES REPEAT 2 TIMES
MOVE UP MOVE FORWARD
REPEAT 2 TIMES REPEAT 3 TIMES
MOVE FORWARD MOVE UP
END END
(REMEMBER TO USE THE MINIMUM NUMBER OF CODING LINES POSSIBLE)
Once students have attempted Part 1 have them pair up with another student and discuss their debugging attempts. Ask students to discuss the questions below.
- 'Did you write the same code?'
- 'If the codes are different do they both work? (Does the dog reach the bone?)'
- 'Are both codes written using the same amount of coding lines?'
- 'Can you find any other solutions to fix the errors that would use less coding lines?'
Part 2:
Working with their pair for this section advise students they will be debugging codes written in pseudo code. Their task is to calculate the current output, identify where the error is and how the code can be written to fix the error. They will then test their solutions to ensure the correct output is achieved.
CODE 1: This pseudo code is meant to find the difference between two numbers.
1. START
2. SET a = 14
3. SET b = 6
4. SET c = a + b
5. OUTPUT c
6. END
These questions may assist students who find it challenging to get started. You may choose to show these at the beginning or once students have attempted to debug the code on their own.
i) What is the output?
ii) What is the difference between 14 and 6?
iii) Which step contains the bug?
iv) Debug the code (rewrite the code without the error)
CODE 2: This pseudo code is meant to find the average of two numbers.
1. START
2. SET d = 10
3. SET e = 20
4. SET f = (d - e)/2
5. OUTPUT f
6. END
i) What is the output?
ii) What is the average of 10 and 20?
iii) Which step contains the bug?
iv) Debug the code (rewrite the code without the error)
To finish up the activity bring the class together for a final discussion.
- What do you learn today?
- How would you explain what you have learned to a friend?
- Did you use any helpful strategies to identify the error? What were they?
Alternatively, for a further task you may like to include Part 3. It could be completed in class or as a homework task.
Part 3: Your task is to write a code to solve an algorithm (E.g. adding two numbers). You will need to purposefully add in a bug to your code. Then you will swap your code with your partner and see if they can debug your work.