KS4 – Algorithms Lesson plan
Lesson 3 – Tracing algorithms
Lesson 3: Tracing algorithms
Introduction
For this lesson, learners will be shown examples of tracing a Python program and a
flowchart. Trace tables are great for walking through an algorithm and are often used
to locate logic errors. However, the focus of this lesson is mainly on using a trace table
to understand how the algorithm works as this is what learners will use trace tables for in
the coding searching and sorting algorithms lessons, which are lessons 6 and 9 of this
unit respectively. That being said, there is a logic error in the second task of the
worksheet for finding the lowest number in a list which learners will use a trace table to
detect. The working code for all the algorithms is linked below.
It is assumed that learners have already covered the lessons on selection, while loops,
for loops, nested loops, and lists in the KS4 Programming unit. These concepts are
essential to analysing and interpreting the code for the searching and sorting algorithms
later on in this unit. Learners should also be familiar with calculating integer division and
modulo in Python, which is covered in lesson 7 of the Programming unit. Integer division
is key to the binary search program in this unit.
Learning objectives
● Use a trace table to walk through code that contains a while loop, a for loop and
a list of items
● Use a trace table to detect and correct errors in a program
Key vocabulary
Trace table, integer division, modulo (MOD), while loop, for loop, list, condition
Preparation
Subject knowledge:
You should be comfortable with using trace tables to walk through Python code that
contains while loops, for loops and lists. You should also be familiar with using a loop in a
flowchart and tracing the state of variables.
Page 1 Last updated: 28/09/2021
KS4 – Algorithms Lesson plan
Lesson 3 – Tracing algorithms
You will need:
● Slides
● Activity 2 Worksheet
● Activity 2 Solution
You may also need:
● Divisible by 3 in Python (ncce.io/divisible-by-3)
● Russian multiplication (ncce.io/russian-multiplication)
● Lowest number in a list (working code) (ncce.io/lowest-number)
● Nested loops (ncce.io/nested-loops)
Assessment opportunities
Activity 2 provides an opportunity for peer/self assessment using the solution provided.
Outline plan
Please note that the slide deck labels the activities in the top right-hand corner to help
you navigate the lesson.
*Timings are rough guides
Starter What is the output?
activity
(Slides 2- Ask learners what the output of the flowchart is to begin with. Then use the
17) slides to step through the state of the variables, processes and output. You
can ask learners to predict the next process or state in the later slides of
the starter activity to gauge understanding.
10 mins
Activity 1 Using a trace table
(Slide X-Y)
Use the first two slides to recap the tracing lesson from the KS4
10 mins Programming unit. The focus here should be on using trace tables to
understand how an algorithm works, as well as using them to detect logic
errors. Talk through the trace table example, asking learners to predict the
next line or code and what will be added to the trace table. Spend some
time ensuring they know how to calculate the modulo of a division in
Python. You can also ask learners to complete the trace table example part
way through to further test their knowledge and prepare them for the
worksheet tasks.
Activity 2 Tracing code
(Slide )
Ensure that learners are comfortable with calculating integer division and
20 mins modulo in Python by using the example at the start of the worksheet.
Page 2 Last updated: 28/09/2021
KS4 – Algorithms Lesson plan
Lesson 3 – Tracing algorithms
Check that they have got the questions correct in the first task before the
trace table otherwise they may have difficulty in tracing the Russian
multiplication algorithm.
Make sure that learners read the description for the code in task 2 and
trace tha algorithm carefully so that they spot the logic error. You can then
ask learners to fix the code in this task once they have explained the
problem.
The third task uses a nested for loop with different start and end values for
the range. Ask learners to read the note carefully that the end value is
exclusive in Python so it will stop when it is reached.
Plenary Tracing code - solution
(Slide )
Ask learners to peer/self mark the worksheet using the solution provided
10 mins as a guide. For task 2, inform learners that there is more than one way to
fix the logic error so they should get someone to check their solution
carefully.
Resources are updated regularly — the latest version is available at: ncce.io/tcc.
This resource is licensed under the Open Government Licence, version 3. For more information on this
licence, see ncce.io/ogl.
Page 3 Last updated: 28/09/2021