It is necessary to be able to analyse and exemplify use of the following standard algorithms:
There is always more than one way to implement a standard algorithm. The examples used have been designed as revision materials that exemplify some of the ways to implement these algorithms. In each case, it is presumed that these algorithms are procedures in their own right.
That is to say that many languages will contain pre-defined functions to find maximum and minimum values. It may also be the case that programmers create their own functions to return the value of a linear search or count occurrence algorithm.
The purpose of this revision guide is not to show in depth examples of how to create and call these functions. This section is for revision purposes and simply exemplifies the structure of each algorithm.
Examples are presented in the reference language issued by the SQA as well as in the following high level languages:
In an exam setting the reference language examples could be used within questions. It is crucial that you understand the reference language examples.
Worked examples in high level languages are designed to aid revision during class work tasks, unit assessment and coursework tasks. They are not exhaustive as there are many ways to implement each algorithm.
It is always important to use meaningful identifiers within an algorithm. For example, if you wish to store a minimum value, this would be represented by the identifier ‘minimum’.
This avoids confusion and uncertainty and allows multiple programmers to make sense of algorithms that may not have been designed by the programmer creating the code.
Sometimes, high level languages make use of shorthand identifiers that are regarded as semi-standards. For example, Java programmers often use ‘i' to represent an index or counter.
To avoid confusion, counter is used throughout this section to represent an index value when referencing an array within a loop.