Teachers' Portal  /  IGCSE Computer Science 0478  /  Algorithm design and problem-solving  /  Standard methods: totalling, counting, maximum, minimum and average
Lesson pack · IGCSE Computer Science 0478 · 7 (3-4) · IGCSE

Standard methods: totalling, counting, maximum, minimum and average

Keep a running total. Most exam algorithms process a list of values: add them up, count the ones that meet a condition, find the biggest and smallest, work out the mean.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Algorithm design and problem-solving
Syllabus reference
Cambridge IGCSE Computer Science 0478, 7 (3-4)
Level
IGCSE
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 4 of 9 in Algorithm design and problem-solving; follows Standard methods: linear search and bubble sort; leads into Validation and verification checks
Central model
Fig. 1: five marks added one at a time to a running total
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • Totalling and counting: In the lab, choose the totalling and counting programs and run them.
  • Maximum and minimum: The trace below follows the algorithm with the marks 64, 38, 91, 50, 47.
  • Working out the average: The average (mean) is the total divided by how many values there are.
Key points to leave on the board
  • Before the loop: Total ← 0, Count ← 0, Highest low, Lowest high (or both the first value).
  • Inside the loop: Total ← Total + Value; Count ← Count + 1 when the condition is true.
  • Max/min: IF Value > Highest THEN Highest ← Value (and the reverse for Lowest).
  • After the loop: Average ← Total / number of values; then output.
The core visual model

One picture every idea returns to

Totalling: set Total ← 0 before the loop, then Total ← Total + Value inside it. Counting: set Count ← 0, then Count ← Count + 1 each time the condition is met. Maximum and minimum: start from a value that will certainly be replaced (or from the first item), then replace it when a bigger (or smaller) value is found. Average: total ÷ number of values, calculated after the loop.

Totalling: add each mark to a running total Mark Total 6438915047 64102193243290 Total 290, Average 290 / 5 = 58 Highest 91, Lowest 38, Count of marks ≥ 50: 3
Fig. 1: five marks added one at a time to a running total
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, Keep a running total.. Most exam algorithms process a list of values: add them up, count the ones that meet a condition, find the biggest and smallest, work out the mean. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: Totalling and countingIn the lab, choose the totalling and counting programs and run them. Project tab 2 of the lab (Totalling and counting) and let a student drive it while the class predicts.Whole class, then pairs
13 to 21 minTeach and check: Maximum and minimumThe trace below follows the algorithm with the marks 64, 38, 91, 50, 47. Your turn: A program finds the lowest of some temperatures that can be from -50 to 50. Why would Lowest ← 0 be a poor starting value?Pairs
21 to 30 minTeach and check: Working out the averageThe average (mean) is the total divided by how many values there are. Model the worked example Average with a count on the board, one line at a time. Your turn: Three test scores are 7, 8 and 10. What does ROUND(Total / 3, 1) output?Anticipation / Reaction Guide
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 17 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in Working out the average, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Anticipation / Reaction Guide

Before the lesson, students mark five statements true or false. After the teaching they mark them again and justify any change of mind in one sentence each. The statements come from the examiner traps below.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
Totalling adds the value (Total ← Total + Mark); counting adds 1 (Count ← Count + 1).Swapping them is one of the most common errors examiners set.
Starting Lowest at 0 is wrong whenever all the values could be above 0: the minimum would never change.Start the minimum high and the maximum low, or start both at the first value.
Do not calculate the average inside the loop, and do not divide by a loop counter whose value after the loop you are unsure of.Divide by a known number, or by a Count variable you have kept yourself.
Worksheet

Standard methods: totalling, counting, maximum, minimum and average: worksheet

6 questions, 17 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · explain[2 marks]

Explain the difference between totalling and counting in an algorithm.

Q2 · trace[4 marks]

The algorithm in this lesson is run with the marks 55, 72, 18, 90, 40. State the final values of Total, CountPass, Highest and Lowest.

Q3 · calculate[1 mark]

Using your answer to the previous question, state the average output by the algorithm.

Q4 · write[5 marks]

Write pseudocode to input the number of goals scored in each of 10 matches, then output the total number of goals and how many matches had no goals.

Q5 · analysis[2 marks]

A program finds the fastest (smallest) race time in seconds. It starts with Fastest ← 0. Explain the problem and give a better starting value.

Q6 · write[3 marks]

The array Heights[1:25] holds the heights of 25 students. Write pseudocode to find and output the greatest height, using the first element as the starting value.

Answer key and marking notes
Q1 · 2 marks
  • Totalling adds each value to a running total, e.g. Total ← Total + Value.
  • Counting adds 1 each time something happens, e.g. Count ← Count + 1.
Q2 · 4 marks
  • Total = 55 + 72 + 18 + 90 + 40 = 275.
  • CountPass = 3 (55, 72 and 90 are at least 50).
  • Highest = 90.
  • Lowest = 18.
Q3 · 1 mark

275 / 5 = 55.

Q4 · 5 marks
  • Initialise Total ← 0 and NoGoals ← 0 before the loop.
  • FOR Match ← 1 TO 10 ... NEXT Match.
  • INPUT Goals inside the loop (with a prompt).
  • Total ← Total + Goals; IF Goals = 0 THEN NoGoals ← NoGoals + 1.
  • OUTPUT Total and NoGoals after the loop.
Q5 · 2 marks
  • No race time is less than 0, so Fastest is never replaced and the output is always 0.
  • Start with a very large value (e.g. 9999) or with the first time input.
Q6 · 3 marks
  • Tallest ← Heights[1].
  • FOR Index ← 2 TO 25; IF Heights[Index] > Tallest THEN Tallest ← Heights[Index]; NEXT Index.
  • OUTPUT Tallest after the loop.
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

Which statement, placed inside a loop, is an example of counting?

  • ACount ← Count + 1
  • BCount ← Count + Value
  • CCount ← 1
  • DValue ← Count + 1
Q21 mark

An algorithm inputs numbers until the rogue value -1 is entered, then outputs the average of the numbers. The inputs are 18, 7, 25, 10, -1. What is output?

  • A15
  • B12
  • C14.75
  • D11.8
Q31 mark

An algorithm finds the highest of 20 temperatures, each from -40 to 45 °C. Which starting value for Highest always gives the correct answer?

  • A-40
  • B0
  • C45
  • D100
Q41 mark

The lesson's mark algorithm counts passes with IF Mark >= 50 and finds the lowest mark starting from Lowest ← 100. It is run with the marks 30, 85, 50, 12, 73. Which values are output for the number of passes and the lowest mark?

  • A3 passes, lowest 12
  • B2 passes, lowest 12
  • C3 passes, lowest 30
  • D4 passes, lowest 12
Q51 mark

The array Vals[1:8] holds 12, 7, 19, 4, 15, 9, 11, 3. What is output?

Total ← 0
FOR Index ← 1 TO 8
    Total ← Total + Vals[Index]
NEXT Index
Average ← Total / 8
Above ← 0
FOR Index ← 1 TO 8
    IF Vals[Index] > Average
      THEN
        Above ← Above + 1
    ENDIF
NEXT Index
OUTPUT Above

  • A4
  • B5
  • C3
  • D10
Q61 mark

An algorithm should output the range (highest minus lowest) of some positive whole numbers. It starts with Highest ← 0 and Lowest ← 0, then updates them for each input. The inputs are 8, 3, 11, 6. What is output, and what should be output?

  • A11 is output; 8 should be
  • B8 is output; 8 should be
  • C11 is output; 11 should be
  • D8 is output; 11 should be
Quiz key
Q1: A

Counting adds exactly 1 each time, so Count ← Count + 1 is correct. Adding Value is totalling. Count ← 1 resets the count to 1 every time instead of increasing it. Value ← Count + 1 changes Value, so Count never changes.

Q2: A

Total = 18 + 7 + 25 + 10 = 60 and Count = 4, so the average is 60 / 4 = 15. Dividing by 5 (12) counts the rogue value. 14.75 adds -1 to the total (59 / 4). 11.8 both adds and counts it (59 / 5).

Q3: A

No temperature is below -40, so the first temperature is either bigger (and replaces it) or equal to it, and the answer is always correct. Starting at 0 fails if every temperature is below zero, because none would replace it. Starting at 45 or 100 fails because nothing can be bigger, so Highest never changes.

Q4: A

85, 50 and 73 satisfy Mark >= 50, so 3 passes; Lowest falls from 100 to 30 and then to 12. Only 2 passes would be counted if 50 were wrongly excluded (as with > 50). Lowest 30 stops updating after the first mark. 4 passes would wrongly include 30 or 12.

Q5: A

Total = 80, so Average = 10. The values above 10 are 12, 19, 15 and 11, so Above = 4. 5 and 3 come from miscounting the values on either side of 10 (none equals 10). 10 is the average itself, not the count that is output.

Q6: A

Highest correctly becomes 11, but no positive input is less than 0, so Lowest stays 0 and 11 - 0 = 11 is output. The true range is 11 - 3 = 8. Saying 8 is output assumes Lowest was updated. Saying 11 is correct forgets that 0 was never an input. The last option reverses the actual and expected results.

Lab and demo

What to project

The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonStandard methods: linear search and bubble sort