Other Standard Methods of a Solution (Cambridge (CIE) O Level Computer Science)

Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Totalling & Counting

What is totalling?

  • Totalling is keeping a running total of values entered into the algorithm

  • An example may be totalling a receipt for purchases made at a shop

  • In the example below, the total starts at 0 and adds up the user inputted value for each item in the list

Pseudocode

Total ← 0

FOR Count ← 1 TO ReceiptLength

INPUT ItemValue

Total ← Total + itemValue

NEXT Count

OUTPUT Total

What is counting?

  • Counting is when a count is incremented or decremented by a fixed value, usually 1, each time it iterates

  • Counting keeps track of the number of times an action has been performed

  • Many algorithms use counting, including the linear search to track which element is currently being considered

  • In the example below, the count is incremented and each pass number is output until fifty outputs have been produced

Pseudocode

Count ← 0

DO

OUTPUT “Pass number”, Count

Count ← Count + 1 

UNTIL Count >= 50

  • In the example below, the count is decremented from fifty until the count reaches zero. An output is produced for each pass

Pseudocode

Count ← 50

DO

OUTPUT “Pass number”, Count

Count ← Count - 1

UNTIL Count <= 0

Maximum, Minimum & Average

  • Finding the largest (max), smallest (min) and average (mean) values in a list are frequently used method in algorithms

  • Examples could include:

    • Calculating the maximum and minimum student grades or scores in a game

    • Calculating the average grade of students in a class test

  • In the example below, in a list of student test scores, the highest, lowest and average scores are calculated and displayed to the screen

Pseudocode

Total ← 0

Scores ← [25, 11, 84, 91, 27]

Highest ← max(Scores)

Lowest ← min(Scores)

// Loop for the number of scores in the list (5)

FOR Count ← 1 TO LENGTH(Scores)

// Add score to total

Total ← Total + Scores[Count]

NEXT Count

// average = total / 5

Average ← Total / LENGTH(Scores)

OUTPUT "The highest score is:", Highest

OUTPUT "The lowest score is:", Lowest

OUTPUT "The average score is:", Average

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.