Algorithm specification

It is necessary to be able to analyse and exemplify use of the following standard algorithms:

  • input validation
  • find minimum
  • find maximum
  • count occurences
  • linear search

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:

  • Visual Studio 2010 (VB 10.0) - o Should be accessible to users of VB5, VB6, VS2008 and subsequent versions of Visual Basic.NET/Visual Studio
  • LiveCode
  • Python
  • Java (Using BlueJ)
  • True Basic
  • Xojo - Formerly REALbasic
  • Pascal
  • Comal

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.

Meaningful identifiers

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.