/en-tutor-prep-s5-term2-ict-programming-selection-iteration-trace/
/en-tutor-prep-s5-term2-ict-programming-selection-iteration-trace/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

S5 Term 2 | ICT: Selection, Iteration and Trace Tables | Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers

S5 Term 2 | ICT: Selection, Iteration and Trace Tables | Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers

  • 2026-12-05

Tutor lesson plan · S5 Term 2 ICT

Students can read the code but freeze when asked what total is on the third pass, and their while loops often forget to update the variable. This lesson lays the program out as a trace table so reading becomes counting.

Lesson objectives By the end students can: (1) fill a 6-row trace table for a for loop: with n = 5, i runs 1 to 5 and total goes 1, 3, 6, 10, 15 across 6 tests; (2) explain how for differs from while and count six steps in halving 64; (3) multiply a nested loop of 4 by 3 for 12 runs, and give 28 comparisons for bubble sort on 8 items and 10 for binary search over 1,000.

01 Prior knowledge check (first 3 minutes)

If any of these is not secure, the trace table goes wrong from the first row. Repair it first:

Skill Quick check Pass standard
Integer division Halve 64 three times: what is left? 8
Assign and compare How does x = x + 1 differ from x == x + 1? The first assigns, the second compares
Adding a series What is 1 plus 2 plus 3 plus 4 plus 5? 15

02 Lesson flow (45 minutes)

Time Stage Tutor does Student does
0-5 min Diagnose Show a five-line for loop and ask for total, take the answer only Most say 5 or 10 and cannot trace it
5-17 min Trace table Three columns i, total and test; n = 5 filled row by row, row six false Students fill six rows and say why there is one extra
17-30 min for and while for counts, while tests; halving 64 takes 6 steps Students rewrite the same job as a while loop and check the exit condition
30-38 min Nesting and sort 4 outer times 3 inner is 12; bubble sort on 8 items is 28 Students compute six items and check the formula
38-42 min Search counts Linear over 1,000 is 1,000; binary is 10, a factor of 100 Students say why binary search needs sorted data
42-45 min Exit check Collect three answers, note boundary, update or counting Students answer without notes

03 Teaching script (read it aloud)

Act one: a trace table is the program in slow motion

A trace table has three columns: the variable, the test and the running total. Starting total at 0 and i at 1 up to 5: first pass i = 1, the test holds, total = 1; then 3; then 6; then 10; then 15; on the sixth test i has become 6, the test fails and the loop ends. So 5 passes give 6 rows, the last one false. Students usually write five rows because they confuse tests with runs.

The usual misconception: one test per pass. There is always one extra test, the failing one that ends the loop.

Students repeat: “Five passes, six rows, and the last test is false.”

Act two: for counts, while tests

A for loop states the count or the range, which suits doing something N times; a while loop states only a condition, which suits doing something until a state is reached. Halving 64 with while reads “while x is greater than 1, divide x by 2 and add one to the count”: 64, 32, 16, 8, 4, 2, 1, which is 6 divisions before the test fails at x = 1. Two checks keep while honest: the starting value must be set, and the body must change it. Another case: keep adding while total is under 20; 1 plus 2 plus 3 plus 4 plus 5 is 15, still short, so adding 6 gives 21 and the loop stops after 6 passes.

The usual misconception: testing x not equal to 1, which loops forever if x skips 1. Testing greater than 1 is safer.

Students repeat: “for counts, while tests, and the body must update the variable.”

Act three: nesting multiplies, search divides

A nested loop with 4 outer runs and 3 inner runs executes 12 times, a product rather than a sum. For sorting, bubble sort makes n(n – 1) over 2 comparisons, so 8 items need 8 times 7 over 2, which is 28. For searching, linear search over 1,000 items is 1,000 comparisons at worst, while binary search halves the range and, because 2 to the 10 is 1,024, needs at most 10, a factor of 100. Binary search assumes the data is already sorted.

The usual misconception: adding the nested counts, or forgetting that binary search needs sorted data. Either one moves the answer by an order of magnitude.

Students repeat: “Nesting multiplies, binary divides, and sort before you bisect.”

04 Question types and steps

Type Example Steps Answer
Trace table for i in range(1, 6) Fill i, total and the test each pass, then one false row 6 rows, total 15
for to while Halving 64 Write the condition, update x and count in the body 6 steps
Nested loop 4 outer, 3 inner Multiply the counts, do not add 12 runs
Search counts 1,000 items Linear compares one by one; binary uses powers of two binary 10
i runs from 1 to 5 and total goes 1, 3, 6, 10, 15; the sixth test fails, so the trace has six rowsstartread n = 5total ← 0, i ← 1i ≤ n ?total ← total + ii ← i + 1false: outputprint total = 15Trace table (n = 5)itotali ≤ 5?11true23true36true410true515true615false1 + 2 + 3 + 4 + 5 = 15; the test runs 6 times (5 true, 1 false)Halving 64: 64, 32, 16, 8, 4, 2, 1, which is 6 stepsOuter 4 times inner 3 equals 12 runsSame job: linear search over 1,000 items is 1,000 comparisons at worst; binary search needs 10

A flowchart and a trace table are two views of one program: the diamond chooses the path, the table records every value. With n = 5 the loop runs five times and the test six, the last one false.

Sanity check (must teach):5 passes and 6 rows, with total summing to 15; halving 64 reaches 1 in 6 steps; 4 by 3 is 12; bubble sort on 8 items is 28 comparisons; binary search over 1,000 is 10, 100 times fewer than linear. Sanity check: tests always outnumber passes by one, and a nested count is never smaller than either single loop.

05 Three independent practice questions

Question Answer What to observe
How many times does for i in range(1, 7) run, and what is total at the end? 6 times (1 to 6), total = 21 Reading the upper bound as inclusive gives seven
x starts at 200; while x is greater than 1, halve it. How many divisions, and what is x at the end? 7 divisions, ending at x = 1 Missing the last step gives six
Outer range(5) with inner range(3): how many runs? And with inner range(4)? 5 x 3 = 15; with range(4) it is 20, five more Adding the two loops gives 8, the classic error

06 Common errors and correction lines

Error Student usually writes Tutor says
Trace table misses the last row 5 passes written as 5 rows There are 6 tests, and the last one is false.
while never updates while x is greater than 1: total = total + 1 The body needs x = x // 2 or the test never fails.
Nested counts added 4 plus 3 is 7 runs The inner loop runs in full each time, so 12.
Binary search on unsorted data Run binary search on an unsorted list Sort first, or the half you keep may not hold the target.

07 Homework (paper and question numbers)

08 Exit check (last 3 minutes)

Question Answer Verdict
A for loop with n = 5: how many trace rows, and what is total? 6 rows and total = 15 Five rows means the failing test was dropped; act one again
Halving 200 down to 1 takes how many steps? 7 steps Six means a step was skipped; act two again
Bubble sort on 8 items at worst, and binary search over 1,000? 28 and 10 Mixing the two means act three again

09 Tutor FAQ

Which year is this for?

S5 Term 2 ICT, the programming section. S4 covered spreadsheet formulas and database queries, so this page turns program execution into a countable table before S6 data structures.

Can 45 minutes cover it?

It covers trace tables, for against while, nested counts and the two searches. Recursion and formal complexity notation need their own lesson; this page only uses powers of two.

Is there a matching paper?

Yes. Homework points to Question 3 parts 9 to 11 for tracing and Question 4 parts 13 to 15 for sorting and searching, which match the table and the counting formulas.

Find a tutor freeTutor sign-up →

©2026 TutorZone · www.tutorzone.com.hk · Terms of use · All rights reserved. Original TutorZone material for personal study and teaching only; not for resale or republication.

Take this guide with you

Reading the full guide is free. Downloading the print version, printing it for students, or taking a whole-level pack needs a tutor account (free).

Registered tutors also get:

Register as a tutor — freeAlready registered? Log in

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →