Implementation (algorithm specification)Finding minimum

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 minimum

The finding minimum algorithm is designed to allow the programmer to create code that will find the lowest 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 high level language indexes from 1).

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

Reference language

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