S5 Term 2 | ICT: Algorithm Tracing – Dictionaries, Sorting, Searching and Complexity | Tutor Lesson Plan | 45-minute flow, teaching script, common errors, practice with answers
- 2026-12-05
Lesson prep guide · S5 Term 2 ICT
Students see code and say they would just run it, but the paper gives no computer; asked how many comparisons, they guess a large number. This lesson teaches three things: hand tracing, comparison formulas, and complexity as the reason one algorithm beats another.
01 Prior knowledge check (first 3 minutes)
If any item below fails, fix it first, or this lesson stalls:
| Skill | Quick check | Pass standard |
|---|---|---|
| Remainders | 13 modulo 3 | 1 |
| Powers | 2 to the power 10 | 1,024 |
| Logarithms | log base 2 of 1,024 | 10 |
| Triangle numbers | 1 plus 2 plus 3 plus 4 plus 5 | 15 |
02 Lesson flow (45 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0–5 min | Diagnostic | Gives three lines of Python and asks for the output | Most want to run it rather than trace it |
| 5–17 min | Dictionary trace | n modulo 3 as key, accumulation as value, the get default | Writes the dictionary after each line |
| 17–29 min | Bubble sort | Each pass pushes the maximum right; 5+4+3+2+1 comparisons | Writes the first pass |
| 29–39 min | Binary and linear search | Halve the range, so 2 to the k must cover n | Works out 65,536 items |
| 39–43 min | Complexity | n squared against n log n when n doubles | Explains why the gap grows |
| 43–45 min | Exit check | Collects three answers, noting trace, formula or log errors | Answers without notes |
03 Teaching script (read it aloud)
Act one: trace it, do not run it
Have students retrace with [1, 4, 7] and write the dictionary.
Students repeat: work out the key, look up the value, take 0 if it is missing, then add n.
Act two: bubble sort and comparison counts
Have students write the comparison count of the second pass and check the total.
Students repeat: n items take n minus one passes and n times n minus one over two comparisons.
Act three: searching and complexity
Students repeat: binary halves and needs sorting, merge sort is n log n, and n squared loses badly as data grows.
04 Question types and steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Trace | nums = [2, 5, 8, 11, 13] | write key and value line by line, default 0 | {2: 26, 1: 13}, sum 39 |
| Sorting | [45, 12, 78, 33, 9] first pass | compare neighbours, push the larger right | [12, 45, 33, 9, 78] |
| Search | 1,024 sorted items | 2 to the k must cover n | 10 comparisons against 1,024 |
| Complexity | n = 1,000 | n squared against n log n | 1,000,000 against 10,000, or 100 times |
Tracing a dictionary needs three things: how the key is formed, what the value accumulates, and when the default 0 applies. Learn the three comparison formulas, and always state n and k.
05 Three independent practice questions
| Question | Answer | What to observe |
|---|---|---|
| Trace nums = [1, 4, 7] with the same code: what is printed? | {1: 12} | forgetting that all three remainders are 1 |
| What is [45, 12, 78, 33, 9] after the first bubble pass? | [12, 45, 33, 9, 78] | stopping after one swap |
| How many comparisons does binary search need in 65,536 sorted items? | 16 | answering 32, which uses n rather than log base 2 of n |
06 Common errors and correction lines
| Error | Student usually writes | Tutor says |
|---|---|---|
| get treated as addition | acc.get(n % 3) + n raises KeyError | The second argument is the default 0 and cannot be dropped. |
| Passes counted as comparisons | 5 given | Five passes, but 5+4+3+2+1 is 15 comparisons. |
| Binary search on unsorted data | binary search without sorting | Binary search needs order to halve the range, or use linear search. |
| Complexity written as O(n) | merge sort called O(n) | Halving gives log n levels, each costing n, so n log n. |
07 Homework (paper and question numbers)
- S5 ICT paper on number systems, part four questions 13 to 16: total plus i times i, binary search in 1,000 records, the first pass of [45, 12, 78, 33, 9], and n log n against n squared total 1, 5, 14, 30, 55; at most 10 comparisons; [12, 45, 33, 9, 78]; 10,240 against 1,048,576, a factor of 102.4
- S5 ICT paper on SQL and algorithms, question 3 parts 9 to 12: the dictionary {2: 26, 1: 13}, the sum 39, the role of the get default, and the output for [1, 4, 7] {2: 26, 1: 13}; 39; it returns 0 for a missing key and avoids KeyError; {1: 12}
- S5 ICT paper on SQL and algorithms, question 4 parts 13 to 16: six items in bubble sort, binary search in 1,024 items, the linear-search factor, and merge-sort comparisons 15; 10 because 2 to the 10 is 1,024; 1,024 comparisons, a factor of 102.4; 10,240, and n log n grows more slowly
08 Exit check (last 3 minutes)
| Question | Answer | Verdict |
|---|---|---|
| How many comparisons does bubble sort need for six items in the worst case? | 15, or 5+4+3+2+1 | 5 means act two must be retaught |
| How many comparisons does binary search need in 1,024 items? | 10 | 1,024 means act three must be retaught |
| At n = 1,000, how far apart are n squared and n log n? | 100 times, 1,000,000 against 10,000 | 10 times means act three must be retaught |
09 Tutor FAQ
Which year is this page for?
S5 Term 2 algorithms and programming; S4 Python basics and S6 programming revision can start here.
Can three algorithms fit in 45 minutes?
Yes: 12 minutes on the dictionary trace, 12 on bubble sort, 10 on searching, 4 on complexity, and 7 for the diagnostic, practice and exit check.
Should recursion and quicksort be taught here?
No. This page covers tracing, bubble sort, binary search and merge sort; recursion and quicksort belong to another page.
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.



