Implementation (algorithm specification)Finding maximum

Algorithms are created to allow users to tell a computer how to solve a problem. Understanding how to construct five of the most common algorithms is a critical skill for budding software developers.

Part ofComputing ScienceSoftware design and development

Finding maximum

The finding maximum algorithm is designed to allow the programmer to create code that will find the highest value that is stored within an array.

Example

In this example the array is called testscore and contains ten values, indexing from 0 to 9 (unless the HLL indexes from 1).

The value held in testscore[0] is set as the initial maximum value and fixed iteration is used to check the rest of the array in sequence. In this example it is presumed that the array/list has already been populated.

Reference language

Line 1 SET maximum TO testscore [0]
Line 2 FOR counter FROM 1 TO 9 DO
Line 3 IF testscore[counter] > maximum THEN
Line 4 SET maximum TO testscore[counter]
Line 5 END IF
Line 6 END FOR
Line 7 SEND "The maximum value was " & maximum TO DISPLAY