/en-tutor-prep-s5-ict-programming-arrays-functions/
/en-tutor-prep-s5-ict-programming-arrays-functions/
英文版
3
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

DSE ICT | Programming Tutorial Plan (for tutors) | Array indexing, function reuse, linear and binary search, three-step debugging

DSE ICT | Programming Tutorial Plan (for tutors) | Array indexing, function reuse, linear and binary search, three-step debugging

  • 2026-11-02

Students can write a for loop, yet when asked for the third element of an array they start counting at one. This lesson puts 5 marks into one dataset and ties indexing, functions and comparison counts to the same countable line.

Objectives — Students can: (1) fetch an array element with a zero-based index and say what happens when the index goes out of range; (2) turn repeated code into one function with parameters, and state the difference between passing a value and passing a reference; (3) state that on 5 elements a linear search needs at most 5 comparisons while a binary search needs at most 3, and apply a three-step routine to find a bug.

01 Prerequisites (3-minute check)

If any of these fails, fix it before the lesson starts.

Skill Quick check Pass mark
Variables How many values one variable can hold at a time One, unless an array is used
Loops How many times for i from 0 to 4 runs Five times
Comparison The difference between greater than and greater than or equal Whether equality is included

02 Lesson flow (60 minutes)

Time Stage Tutor does Student does
0-5 min Opening question Write 42 55 38 61 49 and ask which is the fourth number Answer aloud and explain the counting
5-15 min Prerequisite check Hand out three written checks (variables, loop count, comparison) Written answers, marked on the spot
15-37 min Three scenes Teach arrays and indexing, functions and parameters, search and debugging After each scene, one sentence on where the number came from
37-49 min Worked questions Model four questions, each as data, steps, answer Copy, then rewrite from memory
49-55 min Independent practice Circulate, only asking whether the question is about index or count Do three questions and self-mark
55-60 min Exit check Collect answers and count errors live Written, no talking

03 Teaching script (read it out)

Scene 1: Scene 1: Arrays, indexing and range errors

An array is a row of numbered boxes and the numbering starts at zero. The five marks on the board are 42, 55, 38, 61 and 49, so the indexes run 0 to 4: index 0 holds 42 and index 3 holds 61. The commonest error is counting from one, so a student asked for the fourth number answers 49, when index 3 is the fourth. Give three numbers to hold on to: the element count is 5, the largest valid index is 4, and out of range means using index 5 or above. The second layer is purpose: one array plus one loop handles the sum, the mean, the largest and the smallest, which here are 245, 49.0, 61 at index 3 and 38. The third layer is the boundary condition: a loop must run from 0 to n minus 1, and writing it as less than or equal to n reads a box that does not exist, which either crashes the program or returns rubbish, so make the student say that rule out loud once.

If a program reads index 5 of a five-element array, what happens and why?

Scene 2: Scene 2: Functions, parameters and reuse

A function is a named block of code that can be called again and again. Before the rewrite, computing the mean in three places might take 12 lines; after it, the main program needs only 5 lines: prepare the data, call the function, print the result. Two ideas must land. First, parameters are the data going in and the return value is the answer coming out. Second, a local variable changed inside a function does not affect the outside world, unless an array is passed by reference. Put a number on the benefit: 12 lines become 5, saving 7. A formula change happens in one place, so nothing is forgotten. The third layer is naming and single responsibility: a function called average should not also print a table, otherwise it cannot be tested.

Why is a function safer than copy and paste when the formula changes?

Scene 3: Scene 3: Search counts and three-step debugging

Search questions are about the number of comparisons, not just whether the value is found. On 5 elements a linear search scans from the front, so the worst case is 5 comparisons; a binary search halves the list each time, so the worst case is 3, because two to the power 3 is eight, already more than 5. Binary search has one precondition: the data must be sorted, and using it on unsorted data misses values. The third layer is a three-step debugging routine: reproduce the error and write down the input; print the intermediate value to see where it first goes wrong; change one thing and run again, never five things at once. Take the maximum example: if the program returns 49, print i and marks[i] inside the loop and you will see the comparison written with less than, so the last value is kept.

Binary search is so much faster, so should it always be used?

04 Question types and worked steps

Type Example Steps Answer
Index tracing marks is 42, 55, 38, 61, 49. What is marks[3]? 1 count from zero; 2 reach the fourth element; 3 state the value; 4 note it is not counted from one. Example: 61 at index 3.
Sum and mean For the same array, find the sum and the mean. 1 accumulate in a loop; 2 divide by the element count; 3 keep one decimal place; 4 check the mean sits inside the range. Example: sum 245, mean 49.0.
Comparison count On 5 sorted elements, what are the worst-case comparison counts? 1 linear equals the element count; 2 binary is the ceiling of log base two; 3 state the sorted precondition; 4 label the unit as comparisons. Example: linear 5, binary 3.
Debugging A maximum program returns 49. Find the fault. 1 reproduce and record the input; 2 print intermediates; 3 name the wrong comparison; 4 change one line and rerun. Example: the test used less than, it should be greater than.
Sanity check (teach this): Sanity checks: index 5 is the fifth element, so marks[5] is out of range. A sum of 245 must match adding the five values one by one, and a mean of 49.0 must lie between 38 and 61, so anything above 61 means a wrong divisor. A binary worst case of 3 follows from the powers of two, so an answer of one treats n as one. Rewriting from 12 lines to 5 saves 7, which is not “half” without the arithmetic. Debugging changes one thing at a time, otherwise the cause cannot be identified.

05 Independent practice (3 questions)

Question Answer What to watch
Write the index expression for the last element of the array. marks[4], which is length minus one. Check for marks[5].
Rewrite three copies of a mean calculation as one function, naming the parameter and the return value. The parameter is the array, the return value is the mean, and the main program calls it once. Check whether printing was moved inside the function.
How many comparisons does a linear search need to find 61 among 5 elements? 4, because 61 sits at index 3, the 4th item counted from the front. Check for an answer of one.

06 Common mistakes and what to say

Mistake Student writes Say this
Counting from one Answering that marks[4] is the fifth element. Indexing starts at zero, so the fifth element is index 4. Using 5 is out of range.
Ignoring the comparison count Saying binary search just finds the value, so the count does not matter. The question asks for comparisons. On 5 elements the binary worst case is 3, because each step halves the list.
Binary search on unsorted data Applying binary search before sorting. Binary search assumes sorted data. Sort first, or values will be missed.
Side effects in a function A function that computes, prints and changes a global at once. One function, one job, otherwise it cannot be tested. Leave printing to the caller.

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
What is the largest index of a five-element array? 4 Cannot answer = reteach scene 1
What are the two core parts of a function? Parameters and a return value Cannot answer = reteach scene 2
What precondition does binary search need? Sorted data Cannot answer = reteach scene 3

09 Tutor FAQ

Which year is this for?

Mainly the S5 ICT programming unit; a useful extension after loops in S4.

Does a particular language have to be used?

The ideas are language neutral; examples use pseudocode and work with Python or Java.

Is binary search essential?

DSE compares the efficiency of linear and binary search, so both counts must be stated.

Find a tutor — freeTutor Registration →

A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.

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