Other Standard Methods of a Solution (Cambridge (CIE) O Level Computer Science)
Revision Note
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 |
---|
|
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 |
---|
|
In the example below, the count is decremented from fifty until the count reaches zero. An output is produced for each pass
Pseudocode |
---|
|
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 |
---|
|
Last updated:
You've read 0 of your 5 free revision notes this week
Sign up now. It’s free!
Did this page help you?